Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1.
- #include <vector>
- 2.
- #include <list>
- 3.
- #include <map>
- 4.
- #include <set>
- 5.
- #include <deque>
- 6.
- #include <queue>
- 7.
- #include <stack>
- 8.
- #include <bitset>
- 9.
- #include <algorithm>
- 10.
- #include <functional>
- 11.
- #include <numeric>
- 12.
- #include <utility>
- 13.
- #include <sstream>
- 14.
- #include <iostream>
- 15.
- #include <iomanip>
- 16.
- #include <cstdio>
- 17.
- #include <cmath>
- 18.
- #include <cstdlib>
- 19.
- #include <cctype>
- 20.
- #include <string>
- 21.
- #include <cstring>
- 22.
- #include <cstdio>
- 23.
- #include <cmath>
- 24.
- #include <cstdlib>
- 25.
- #include <ctime>
- 26.
- 27.
- using namespace std;
- 28.
- 29.
- //BEGINTEMPLATE_BY_ACRUSH_TOPCODER
- 30.
- #define SIZE(X) ((int)(X.size()))//NOTES:SIZE(
- 31.
- #define LENGTH(X) ((int)(X.length()))//NOTES:LENGTH(
- 32.
- #define MP(X,Y) make_pair(X,Y)//NOTES:MP(
- 33.
- typedef long long int64;//NOTES:int64
- 34.
- typedef unsigned long long uint64;//NOTES:uint64
- 35.
- #define two(X) (1<<(X))//NOTES:two(
- 36.
- #define twoL(X) (((int64)(1))<<(X))//NOTES:twoL(
- 37.
- #define contain(S,X) (((S)&two(X))!=0)//NOTES:contain(
- 38.
- #define containL(S,X) (((S)&twoL(X))!=0)//NOTES:containL(
- 39.
- const double pi=acos(-1.0);//NOTES:pi
- 40.
- const double eps=1e-11;//NOTES:eps
- 41.
- template<class T> inline void checkmin(T &a,T b){if(b<a) a=b;}//NOTES:checkmin(
- 42.
- template<class T> inline void checkmax(T &a,T b){if(b>a) a=b;}//NOTES:checkmax(
- 43.
- template<class T> inline T sqr(T x){return x*x;}//NOTES:sqr
- 44.
- typedef pair<int,int> ipair;//NOTES:ipair
- 45.
- template<class T> inline T lowbit(T n){return (n^(n-1))&n;}//NOTES:lowbit(
- 46.
- template<class T> inline int countbit(T n){return (n==0)?0:(1+countbit(n&(n-1)));}//NOTES:countbit(
- 47.
- //Numberic Functions
- 48.
- template<class T> inline T gcd(T a,T b)//NOTES:gcd(
- 49.
- {if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
- 50.
- template<class T> inline T lcm(T a,T b)//NOTES:lcm(
- 51.
- {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
- 52.
- template<class T> inline T euclide(T a,T b,T &x,T &y)//NOTES:euclide(
- 53.
- {if(a<0){T d=euclide(-a,b,x,y);x=-x;return d;}
- 54.
- if(b<0){T d=euclide(a,-b,x,y);y=-y;return d;}
- 55.
- if(b==0){x=1;y=0;return a;}else{T d=euclide(b,a%b,x,y);T t=x;x=y;y=t-(a/b)*y;return d;}}
- 56.
- template<class T> inline vector<pair<T,int> > factorize(T n)//NOTES:factorize(
- 57.
- {vector<pair<T,int> > R;for (T i=2;n>1;){if (n%i==0){int C=0;for (;n%i==0;C++,n/=i);R.push_back(make_pair(i,C));}
- 58.
- i++;if (i>n/i) i=n;}if (n>1) R.push_back(make_pair(n,1));return R;}
- 59.
- template<class T> inline bool isPrimeNumber(T n)//NOTES:isPrimeNumber(
- 60.
- {if(n<=1)return false;for (T i=2;i*i<=n;i++) if (n%i==0) return false;return true;}
- 61.
- template<class T> inline T eularFunction(T n)//NOTES:eularFunction(
- 62.
- {vector<pair<T,int> > R=factorize(n);T r=n;for (int i=0;i<R.size();i++)r=r/R[i].first*(R[i].first-1);return r;}
- 63.
- //Matrix Operations
- 64.
- const int MaxMatrixSize=40;//NOTES:MaxMatrixSize
- 65.
- template<class T> inline void showMatrix(int n,T A[MaxMatrixSize][MaxMatrixSize])//NOTES:showMatrix(
- 66.
- {for (int i=0;i<n;i++){for (int j=0;j<n;j++)cout<<A[i][j];cout<<endl;}}
- 67.
- template<class T> inline T checkMod(T n,T m) {return (n%m+m)%m;}//NOTES:checkMod(
- 68.
- template<class T> inline void identityMatrix(int n,T A[MaxMatrixSize][MaxMatrixSize])//NOTES:identityMatrix(
- 69.
- {for (int i=0;i<n;i++) for (int j=0;j<n;j++) A[i][j]=(i==j)?1:0;}
- 70.
- template<class T> inline void addMatrix(int n,T C[MaxMatrixSize][MaxMatrixSize],T A[MaxMatrixSize][MaxMatrixSize],T B[MaxMatrixSize][MaxMatrixSize])//NOTES:addMatrix(
- 71.
- {for (int i=0;i<n;i++) for (int j=0;j<n;j++) C[i][j]=A[i][j]+B[i][j];}
- 72.
- template<class T> inline void subMatrix(int n,T C[MaxMatrixSize][MaxMatrixSize],T A[MaxMatrixSize][MaxMatrixSize],T B[MaxMatrixSize][MaxMatrixSize])//NOTES:subMatrix(
- 73.
- {for (int i=0;i<n;i++) for (int j=0;j<n;j++) C[i][j]=A[i][j]-B[i][j];}
- 74.
- template<class T> inline void mulMatrix(int n,T C[MaxMatrixSize][MaxMatrixSize],T _A[MaxMatrixSize][MaxMatrixSize],T _B[MaxMatrixSize][MaxMatrixSize])//NOTES:mulMatrix(
- 75.
- { T A[MaxMatrixSize][MaxMatrixSize],B[MaxMatrixSize][MaxMatrixSize];
- 76.
- for (int i=0;i<n;i++) for (int j=0;j<n;j++) A[i][j]=_A[i][j],B[i][j]=_B[i][j],C[i][j]=0;
- 77.
- for (int i=0;i<n;i++) for (int j=0;j<n;j++) for (int k=0;k<n;k++) C[i][j]+=A[i][k]*B[k][j];}
- 78.
- template<class T> inline void addModMatrix(int n,T m,T C[MaxMatrixSize][MaxMatrixSize],T A[MaxMatrixSize][MaxMatrixSize],T B[MaxMatrixSize][MaxMatrixSize])//NOTES:addModMatrix(
- 79.
- {for (int i=0;i<n;i++) for (int j=0;j<n;j++) C[i][j]=checkMod(A[i][j]+B[i][j],m);}
- 80.
- template<class T> inline void subModMatrix(int n,T m,T C[MaxMatrixSize][MaxMatrixSize],T A[MaxMatrixSize][MaxMatrixSize],T B[MaxMatrixSize][MaxMatrixSize])//NOTES:subModMatrix(
- 81.
- {for (int i=0;i<n;i++) for (int j=0;j<n;j++) C[i][j]=checkMod(A[i][j]-B[i][j],m);}
- 82.
- template<class T> inline T multiplyMod(T a,T b,T m) {return (T)((((int64)(a)*(int64)(b)%(int64)(m))+(int64)(m))%(int64)(m));}//NOTES:multiplyMod(
- 83.
- template<class T> inline void mulModMatrix(int n,T m,T C[MaxMatrixSize][MaxMatrixSize],T _A[MaxMatrixSize][MaxMatrixSize],T _B[MaxMatrixSize][MaxMatrixSize])//NOTES:mulModMatrix(
- 84.
- { T A[MaxMatrixSize][MaxMatrixSize],B[MaxMatrixSize][MaxMatrixSize];
- 85.
- for (int i=0;i<n;i++) for (int j=0;j<n;j++) A[i][j]=_A[i][j],B[i][j]=_B[i][j],C[i][j]=0;
- 86.
- for (int i=0;i<n;i++) for (int j=0;j<n;j++) for (int k=0;k<n;k++) C[i][j]=(C[i][j]+multiplyMod(A[i][k],B[k][j],m))%m;}
- 87.
- template<class T> inline T powerMod(T p,int e,T m)//NOTES:powerMod(
- 88.
- {if(e==0)return 1%m;else if(e%2==0){T t=powerMod(p,e/2,m);return multiplyMod(t,t,m);}else return multiplyMod(powerMod(p,e-1,m),p,m);}
- 89.
- //Point&Line
- 90.
- double dist(double x1,double y1,double x2,double y2){return sqrt(sqr(x1-x2)+sqr(y1-y2));}//NOTES:dist(
- 91.
- double distR(double x1,double y1,double x2,double y2){return sqr(x1-x2)+sqr(y1-y2);}//NOTES:distR(
- 92.
- template<class T> T cross(T x0,T y0,T x1,T y1,T x2,T y2){return (x1-x0)*(y2-y0)-(x2-x0)*(y1-y0);}//NOTES:cross(
- 93.
- int crossOper(double x0,double y0,double x1,double y1,double x2,double y2)//NOTES:crossOper(
- 94.
- {double t=(x1-x0)*(y2-y0)-(x2-x0)*(y1-y0);if (fabs(t)<=eps) return 0;return (t<0)?-1:1;}
- 95.
- bool isIntersect(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4)//NOTES:isIntersect(
- 96.
- {return crossOper(x1,y1,x2,y2,x3,y3)*crossOper(x1,y1,x2,y2,x4,y4)<0 && crossOper(x3,y3,x4,y4,x1,y1)*crossOper(x3,y3,x4,y4,x2,y2)<0;}
- 97.
- bool isMiddle(double s,double m,double t){return fabs(s-m)<=eps || fabs(t-m)<=eps || (s<m)!=(t<m);}//NOTES:isMiddle(
- 98.
- //Translator
- 99.
- bool isUpperCase(char c){return c>='A' && c<='Z';}//NOTES:isUpperCase(
- 100.
- bool isLowerCase(char c){return c>='a' && c<='z';}//NOTES:isLowerCase(
- 101.
- bool isLetter(char c){return c>='A' && c<='Z' || c>='a' && c<='z';}//NOTES:isLetter(
- 102.
- bool isDigit(char c){return c>='0' && c<='9';}//NOTES:isDigit(
- 103.
- char toLowerCase(char c){return (isUpperCase(c))?(c+32):c;}//NOTES:toLowerCase(
- 104.
- char toUpperCase(char c){return (isLowerCase(c))?(c-32):c;}//NOTES:toUpperCase(
- 105.
- template<class T> string toString(T n){ostringstream ost;ost<<n;ost.flush();return ost.str();}//NOTES:toString(
- 106.
- int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}//NOTES:toInt(
- 107.
- int64 toInt64(string s){int64 r=0;istringstream sin(s);sin>>r;return r;}//NOTES:toInt64(
- 108.
- double toDouble(string s){double r=0;istringstream sin(s);sin>>r;return r;}//NOTES:toDouble(
- 109.
- template<class T> void stoa(string s,int &n,T A[]){n=0;istringstream sin(s);for(T v;sin>>v;A[n++]=v);}//NOTES:stoa(
- 110.
- template<class T> void atos(int n,T A[],string &s){ostringstream sout;for(int i=0;i<n;i++){if(i>0)sout<<' ';sout<<A[i];}s=sout.str();}//NOTES:atos(
- 111.
- template<class T> void atov(int n,T A[],vector<T> &vi){vi.clear();for (int i=0;i<n;i++) vi.push_back(A[i]);}//NOTES:atov(
- 112.
- template<class T> void vtoa(vector<T> vi,int &n,T A[]){n=vi.size();for (int i=0;i<n;i++)A[i]=vi[i];}//NOTES:vtoa(
- 113.
- template<class T> void stov(string s,vector<T> &vi){vi.clear();istringstream sin(s);for(T v;sin>>v;vi.push_bakc(v));}//NOTES:stov(
- 114.
- template<class T> void vtos(vector<T> vi,string &s){ostringstream sout;for (int i=0;i<vi.size();i++){if(i>0)sout<<' ';sout<<vi[i];}s=sout.str();}//NOTES:vtos(
- 115.
- //Fraction
- 116.
- template<class T> struct Fraction{T a,b;Fraction(T a=0,T b=1);string toString();};//NOTES:Fraction
- 117.
- template<class T> Fraction<T>::Fraction(T a,T b){T d=gcd(a,b);a/=d;b/=d;if (b<0) a=-a,b=-b;this->a=a;this->b=b;}
- 118.
- template<class T> string Fraction<T>::toString(){ostringstream sout;sout<<a<<"/"<<b;return sout.str();}
- 119.
- template<class T> Fraction<T> operator+(Fraction<T> p,Fraction<T> q){return Fraction<T>(p.a*q.b+q.a*p.b,p.b*q.b);}
- 120.
- template<class T> Fraction<T> operator-(Fraction<T> p,Fraction<T> q){return Fraction<T>(p.a*q.b-q.a*p.b,p.b*q.b);}
- 121.
- template<class T> Fraction<T> operator*(Fraction<T> p,Fraction<T> q){return Fraction<T>(p.a*q.a,p.b*q.b);}
- 122.
- template<class T> Fraction<T> operator/(Fraction<T> p,Fraction<T> q){return Fraction<T>(p.a*q.b,p.b*q.a);}
- 123.
- //ENDTEMPLATE_BY_ACRUSH_TOPCODER
- 124.
- 125.
- int main()
- 126.
- {
- 127.
- #ifdef _MSC_VER
- 128.
- freopen("input.txt","r",stdin);
- 129.
- #endif
- 130.
- int v;
- 131.
- while (scanf("%d",&v)!=-1 && v!=42)
- 132.
- printf("%d\n",v);
- 133.
- return 0;
- 134.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement