akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

#define HIGASHI 0
#define KITA 1

int w, h;
int memo[101][101][2][2];

//	(i, j), 前回の方向, 曲がったか
int getWay(int i, int j, int d, int turn)
{
	int ret = 0;
	
	if (memo[i][j][d][turn] != -1){
		return (memo[i][j][d][turn]);
	}
	
	if (i == w && j == h){
		return (1);
	}
	
	//	前回曲がってないなら曲がるのも含める
	if (turn == 0){
		
		//	東
		if (i + 1 <= w){
			ret += (getWay(i + 1, j, HIGASHI, (d != HIGASHI ? 1 : 0)) % 100000);
		}
		//	北
		if (j + 1 <= h){
			ret += (getWay(i, j + 1, KITA, (d != KITA ? 1 : 0)) % 100000);
		}
	}
	else {
		//	まっすぐだけ
		
		if (d == HIGASHI && i + 1 <= w){
			ret += (getWay(i + 1, j, HIGASHI, 0) % 100000);
		}
		else if (d == KITA && j + 1 <= h){
			ret += (getWay(i, j + 1, KITA, 0) % 100000);
		}
	}
	
	return (memo[i][j][d][turn] = (ret % 100000));
}

int main(void)
{
	int ret = 0;
	
	scanf("%d%d", &w, &h);
	while (w != 0){
		memset(memo, -1, sizeof(memo));
		
		ret += (getWay(2, 1, HIGASHI, 0) % 100000);
		ret += (getWay(1, 2, KITA, 0) % 100000);
		printf("%d\n", ret % 100000);
		scanf("%d%d", &w, &h);
		ret = 0;
	}
	
	return (0);
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N;

int main()
{
	scanf("%d",&N);
	vector<int> A(N);
	FOR(i,0,N){
		scanf("%d",&A [i]);
	}
	sort(A.begin(),A.end());

	printf("%d\n",A.back() - A.front());

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int n,k,i,j,t;
cin>>n>>k;
t=1;
for (i=1; i<=n; i++)
  {
    if (k>t) t*=2;
      else t+=k;
  }
cout<<t<<endl;  
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n,m,a[100],b[100],i,flag=0,bmax=0,cnt=0,bmax2;
  cin >> n >> m;
  for(i=0;i<m;i++){
    cin >> a[i] >> b[i];
    if(a[i]==1) flag=1;
    if(a[i]==1&&b[i]>bmax) bmax=b[i];
  }
  cnt=1;
  bmax2=0;
  if(flag==1){
    while(bmax!=n){
      if(cnt==m+10){
	flag=0;
	break;
      }
      for(i=0;i<m;i++){
        if(a[i]<=bmax+1&&bmax+1<=b[i]&&bmax2<b[i]){
	  bmax2=b[i];
	}
      }
      bmax=bmax2;
      cnt++;
    }
  }
  if(flag==0) cout << "Impossible" << endl;
  else cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

int main(void) {
    Int n;
    cin >> n;
    cout << pow(n, 3) << endl;
    return 0;
}



Measured memory_bytes: 4184
n,m = [int(x) for x in input().split()]
xy = []
for _ in range(m):
    tmp = [int(x)-1 for x in input().split()]
    xy.append(tmp)

num = [1 for _ in range(n)]
red = [False for _ in range(n)]
red[0] = True

for i in range(m):
    if red[xy[i][0]]:
        red[xy[i][1]] = True
    num[xy[i][0]] -= 1
    num[xy[i][1]] += 1
    if num[xy[i][0]] == 0:
        red[xy[i][0]] = False

print(sum([1 for x in red if x == True]))

Measured memory_bytes: 23560
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

using Float = double;
using Point = complex<Float>;
struct Line{ Point a,b; };
struct Circle{ Point center; Float r; };

inline bool eq(Float a,Float b) { return abs(a - b) < EPS; }
inline Float dot(const Point &p1,const Point &p2){ return real(conj(p1) * p2); }
inline Float cross(const Point &p1,const Point &p2){ return imag(conj(p1) * p2); }

namespace std{
	bool operator<(const Point &p1,const Point &p2){
		return eq(real(p1),real(p2)) ? imag(p1) < imag(p2) : real(p1) < real(p2);
	}
}

Point projection(const Line &l,const Point &p){
	Float t = dot(l.b - l.a,p - l.a) / norm(l.b - l.a);
	return l.a + (l.b - l.a) * t;
}

vector<Point> crosspoint(const Circle &c1,const Circle &c2){
	vector<Point> ret;
	Point d = c2.center - c1.center;
	Float rcosa = (c1.r * c1.r + norm(d) - c2.r * c2.r) / (abs(d) * 2);
	if(eq(0,abs(d)) || abs(rcosa) > c1.r) return ret;
	Float rsina = sqrt(c1.r * c1.r - rcosa * rcosa);
	ret.push_back(c1.center + d / abs(d) * Point(rcosa,rsina));
	if(!eq(rcosa,c1.r)) ret.push_back(c1.center + d / abs(d) * Point(rcosa,-rsina));
	return ret;
}

int n;
vector<Point> ps;

bool isOK(double r){
	vector<Circle> cs;
	for(int i = 0;i < n;i++) cs.push_back({ps[i],r});
	vector<Point> cand;
	for(int i = 0;i < n;i++){
		for(int j = i + 1;j < n;j++){
			auto cross = crosspoint(cs[i],cs[j]);
			for(auto p : cross) cand.push_back(p);
		}
	}
	for(auto p : cand){
		bool isCont = true;
		for(auto c : cs){
			if(!(abs(c.center - p) < r + EPS)) isCont = false;
		}
		if(isCont) return true;
	}
	return false;
}

signed main(){
	cin >> n;
	for(int i = 0;i < n;i++){
		double x,y;
		cin >> x >> y;
		ps.emplace_back(x,y);
	}
	double ng = 0,ok = 100000;
	for(int i = 0;i < 200;i++){
		double mid = (ng + ok) / 2.0;
		if(isOK(mid)) ok = mid;
		else ng = mid;
	}
	printf("%.15lf\n",ok);
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<double> numbers(n);
    for (int i=0;i<n;i++){
        cin >> numbers[i];
    }
    double divisor=0.0;
    for (auto &i : numbers){
        divisor += (1.0 / i);
    }
    cout << setprecision(10) << 1.0 / divisor << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;


int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  long long mod=1000000007;
  map<char,long long> mp;
  for(int i=0;i<n;++i){
    mp[s[i]]++;
  }
  long long ans=1;
  for(auto p : mp){
    ans=ans*(p.second+1)%mod;
  }
  ans=ans-1;
  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>

#define INF_LL 9000000000000000000
#define INF 2000000000

#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int senbei[10][10000];
int r, c;

int cnt(int *s[10]){
	int res = 0;
	REP(i, r){
		REP(j, c){
			if(s[i][j] == 0){
				res++;
			}
		}
	}
	return res;
}

int main(void){
	while(1){
		int s[10][10000];
		int flag;
		int res = INF;
		cin >> r >> c;
		if(r == 0 && c == 0) return 0;
		REP(i, r){
			REP(j, c){
				cin >> s[i][j];
				if(s[i][j] == 1){
				}
			}
		}
		for(int i = 0;i < pow(2, r);i++){
			int n[10000];
			fill(n, n+c, 0);
			REP(j, r){
				if((i & (int)pow(2, j)) == (int)pow(2, j)) flag = 1;
				else flag = 0;
				REP(k, c){
					if(s[j][k] == 1-flag){
						n[k]++;
					}
				}
			}
			int tmp = 0;
			REP(j, c){
				tmp += min(n[j], r-n[j]);
			}
			res = min(res, tmp);
		}
		cout << r*c-res << endl;
	}
}

Measured memory_bytes: 3552
#include<bits/stdc++.h>

#define ll long long

using namespace std;

int main(void){
    int N;
    ll K;
    cin >> N >> K;
    vector<ll> A(N);
    ll sum = 0;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        sum += A[i];
    }
    set<ll, greater<ll>> d;
    for(int i = 1; i * i <= sum; i++){
        if(sum % i == 0){
            d.insert(i);
            d.insert(sum / i);
        }
    }
    for(ll v : d){
        vector<ll> r(N);
        ll m = 0;
        for(int i = 0; i < N; i++){
            r[i] = A[i] % v;
            m += r[i];
        }
        sort(r.rbegin(), r.rend());
        ll p = 0;
        for(int i = 0; i < N; i++){
            m -= r[i];
            p += (v - r[i]);
            if(max(m, p) <= K){
                cout << v << endl;
                return 0;
            }
        }
    }
    cout << 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define X first
#define Y sevcond
#define pb emplace_back
#define eb pb
#define rep(X,Y) for(int X=0;X<(Y);++X)
#define reps(X,O,Y) for(int X=(O);X<(Y);++X)
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()

using namespace std;
using ll=long long;

using Cost=ll;
using Cap=ll;
struct Edge{int to,rev;Cap cap;Cost cost;};
using Edges=vector<Edge>;
using Graph=vector<Edges>;

void add_edge(Graph &g,int f,int t, ll cap){
	g[f].pb((Edge){t,(int)g[t].size(),cap,0});
	g[t].pb((Edge){f,(int)g[f].size()-1,0,0});
}
Cost INF=2e11;
vector<int> used;
Cap dfs(Graph &g,int v,int t,Cap f){
	if(v==t) return f;
	used[v]=1;
	for(Edge &e:g[v]){
		if(e.cap<=0 || used[e.to]) continue;
		Cap d=dfs(g,e.to,t,min(f,e.cap));
		if(d>0){
			e.cap-=d;
			g[e.to][e.rev].cap+=d;
			return d;
		}
	}
	return 0;
}

Cap max_flow(Graph &g,int s,int t){
	Cap sum=0,f;
	int V=g.size();
	while(1){
		used.resize(V);
		fill(all(used),0);
		sum+=f=dfs(g,s,t,INF);
		if(!f) return sum;
	}
}

int cnt[222][222];

int main(){
	int n;
	cin>>n;
	rep(i,n){
		string s;
		cin>>s;
		++cnt[s[0]][s[s.size()-1]];
	}
	vector<char> re;
	reps(c,'a','z'+1){
		Graph g(28);
		rep(i,26)if(i+'a'!=c)rep(j,26)if(i!=j && j+'a'!=c) add_edge(g,i,j,cnt[i+'a'][j+'a']);
		int sum=0,ok=cnt[c][c];
		rep(i,26)if(i+'a'!=c){
			sum+=cnt[c][i+'a'];
			add_edge(g,26,i,cnt[c][i+'a']);
			if(cnt[i+'a'][c]) ok=1;
			add_edge(g,i,27,cnt[i+'a'][c]);
		}
		if(ok && max_flow(g,26,27)==sum) re.pb(c);
	}
	for(char c:re) cout<<c<<endl;
}



Measured memory_bytes: 3272
H,W,A,B = map(int, input().split())
ans = [[0 for i in range(W)] for j in range(H)]

for i in range(H):
    if i<B:
        for j in range(A):
            ans[i][j] = 1
        for j in range(A,W):
            ans[i][j] = 0
    else:
        for j in range(A):
            ans[i][j] = 0
        for j in range(A,W):
            ans[i][j] = 1

for a in ans:
    print(*a, sep='')

Measured memory_bytes: 14324
#include <iostream>
#include <string>
 
#define MAX_LEN (100)
 
using namespace std;
 
class Dice {
      private:
              int value[6];
              int top;
      
      public:             
              Dice(int value[]) {             
                   for (int i = 0; i < 6; i++) {
                        this->value[i] = value[i];
                   }
                    
                   this->top = value[0];
              }
               
              void swap(int& a, int& b) {
                   int temp = a;
                   a = b;
                   b = temp;
              }
 
              void move_N(int value[]) {
                   this->swap(value[0], value[1]);
                   this->swap(value[1], value[5]);
                   this->swap(value[5], value[4]);
 
                   this->top = value[0];
              }
 
              void move_E(int value[]) {
                   this->swap(value[0], value[3]);
                   this->swap(value[3], value[5]);
                   this->swap(value[5], value[2]);
  
                   this->top = value[0];
              }
 
              void move_W(int value[]) {
                   this->swap(value[0], value[2]);
                   this->swap(value[2], value[5]);
                   this->swap(value[5], value[3]);
 
                   this->top = value[0];
              }
 
              void move_S(int value[]) {
                   this->swap(value[0], value[4]);
                   this->swap(value[4], value[5]);
                   this->swap(value[5], value[1]);
 
                   this->top = value[0];
              }
 
              int Get_top() {
                  return (this->top);
              }
};
 
int main()
{
    int    value[6];  
    string inst;
 
    for (int i = 0; i < 6; i++) {
         do {
             cin >> value[i];
         } while (value[i] < 0 || value[i] > 100);
    }
 
    Dice dice(value);
 
    do {
        cin >> inst;
    } while (inst.length() < 0 || inst.length() > MAX_LEN);
         
    for (int i = 0; inst[i] != '\0'; i++){
         if (inst[i] == 'N') {
             dice.move_N(value);
         } else if (inst[i] == 'E') {
             dice.move_E(value);
         } else if (inst[i] == 'W') {
             dice.move_W(value);
         } else if (inst[i] == 'S') {
             dice.move_S(value);
         }
    }
 
    cout << dice.Get_top() << endl;
 
    return (0);
}

Measured memory_bytes: 3160
#include <iostream>

using namespace std;

bool check(string s) {
    for(int i =0; i< s.size(); i++){
        if(s[i] != 'A' && s[i] != 'C' && s[i] != 'G' && s[i] != 'T') {
            return false;
        }
    }
    return true;
}

int main(){
    string s; cin >> s;
    int ans = 0;
    for(int l = 0; l < s.size(); l++) {
        for (int r = l; r < s.size(); r++) {
            if(check(s.substr(l,r-l+1)))
                ans = max(ans, r-l+1);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
 
using namespace std;
int main()
{
 
int a,b,x;
    
    cin >> a >> b >> x;
    if(x >= a && x <= a + b){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);

ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/
using namespace std;

const double PI = 2 * acos(0);

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<vector<ll>> matrix;

int main() {
  int t;
  scanf("%d", &t);
  if(t == 1) printf("Hello World\n");
  else {
    int a, b;
    scanf("%d%d", &a, &b);
    printf("%d\n", a+b);
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)

int n, k;
ll ans = 10000000000, len;
int main()
{
    cin >> n >> k;
    vector<ll> x(n);
    rep(i, 0, n)
    {
        cin >> x[i];
    }

    ll l, r, lr, rl;
    for (int i = 0; i <= (n - k); i++)
    {
        l = i;
        r = l + k - 1;
        rl = abs(x[r]) + abs(x[r] - x[l]);
        lr = abs(x[l]) + abs(x[r] - x[l]);
        len = min(lr, rl);
        // cout << ans << "," << len << endl;
        ans = min(ans, len);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4000
#include "bits/stdc++.h"
using namespace std;

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	if (s[0] == 'a') {
		if (s[1] == 'b') {
			if (s[2] == 'c') {
				cout << "Yes";
				return 0;
			}
		}
	}
	cout << "No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{

     char str[2000];
     scanf("%s",str);
     int n;
     scanf("%d",&n);
     int l = strlen(str);

     for(int i=0; i<l; i++)
     {
       if(i==0)
       {
         printf("%c",str[i]);
         continue;
       }
       if(i%n==0)
       {
         printf("%c",str[i]);
       }
     }
     printf("\n");

}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

int main() {
	int N, M;
	std::cin >> N;
	std::cin >> M;
	int case_100ms = N - M;
	double one_exe_time = case_100ms * 100 + M * 1900;
	double clear_prob = pow(1 / 2.0, M);
	double s, s_old = 1;
	double total_success_prob, total_success_prob_old = 0.0;
	int x = 1;
	s = 0.0;
	while (1) {
		total_success_prob = 1.0 - pow(1 - clear_prob, x);       
		s += (one_exe_time * x) * (total_success_prob - total_success_prob_old);
		x++;
		if (fabs(s - s_old) < (1e-20)){
			break;
		}
		s_old = s;
		total_success_prob_old = total_success_prob;
	}


	std::cout << int(s + 0.5) << "\n";
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<complex>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const double eps = 1e-10;

#define RIGHT 1
#define LEFT -1

typedef complex<double> P;
typedef vector<P> Polygon;
typedef pair<P,P> Line;

double cross(P a,P b){
  return a.real()*b.imag()-a.imag()*b.real();
}

P intersection_ll(P a1,P a2,P b1,P b2){
  P a=a2-a1,b=b2-b1;
  return a1+a*cross(b,b1-a1)/cross(b,a);
}


int ccw(P a,P b){
  if ( cross(a,b)<0)return RIGHT;
  else if ( cross(a,b)>0)return LEFT;
  return 2;
}

vector<P> Convex_Cut(Polygon in,int n,P a1,P a2,int cutpos){
  vector<P> ret;
  rep(i,n){
    P now = in[i],next=in[(i+1)%n];
    if( ccw(a1-a2,now-a2)==cutpos)ret.push_back(now);
    if ( ccw(a1-a2,now-a1)*ccw(a1-a2,next-a2)<0)
      ret.push_back(intersection_ll(a1,a2,now,next));
  }
  return ret;
}

//cutpos ha mondai izon. which side will remain
Line make_line(P ori,P b,int cutpos){
  P tmp=(ori+b);
  tmp.real()/=2;tmp.imag()/=2;
  P ret=b-tmp;
  swap(ret.real(),ret.imag());
  ret.real()*=-1;
  if ( ccw(ret,ori-tmp)!= cutpos)return make_pair(tmp,ret+tmp);
  return make_pair(ret+tmp,tmp);
}

double Polygon_Area(vector<P> a,int n){
  double sum=0;
  rep(i,n){
    sum+=(a[i%n].real()-a[(i+1)%n].real())*(a[i%n].imag()+a[(i+1)%n].imag());
  }
  if( sum<0)sum*=-1;
  return sum/2;
}


void solve(int n,int m,Polygon in,vector<P> CutLine){
  vector<Line> ver;
  rep(i,CutLine.size())
    if ( i == m)continue;
    else ver.push_back(make_line(CutLine[m],CutLine[i],LEFT));

  rep(i,ver.size())
    in=Convex_Cut(in,in.size(),ver[i].first,ver[i].second,LEFT);
  
  printf("%.4lf\n",Polygon_Area(in,in.size()));
}

main(){
  int n,m;
  while(cin>>n>>m&&n){
    Polygon a;
    vector<P> CutPoint;
    rep(i,n){
      P tmp;cin>>tmp.real()>>tmp.imag();a.push_back(tmp);
    }
    rep(i,m){
      P tmp;
      cin>>tmp.real()>>tmp.imag();
      CutPoint.push_back(tmp);
    }
    
    rep(i,m)
      solve(n,i,a,CutPoint);
    
  }
}

Measured memory_bytes: 0
def isPrime(n):
    i = 2
    while i*i <= n:
        if n % i == 0:
            return False
        i += 1
    return True
 
l = []
i = 2
while i < 55556:
    if isPrime(i) and i%5 == 1:
        l.append(i)
    i += 1
 
N = int(input())
print(*l[:N])

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 

int main()
{ 
    int n;
    cin>>n;
    int a[n];
    int b[n];
    int flg[n];
    int A=0;
    int B=0;
    int fac[n+1];
    for(int i=0;i<n+1;i++){
        if(i==0){fac[i]=1;}
        else{fac[i]=i*fac[i-1];}
    }

    for(int i=0;i<n;i++){
        cin>>a[i];
        flg[i]=0;
    }
    //判定
    for(int i=0;i<n;i++){
        flg[a[i]]=1;
        int cnt=0;
        for(int j=0;j<a[i];j++){
            if(flg[j]==0){cnt++;}
        }
        A=A+fac[n-i-1]*cnt;
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
        flg[i]=0;
    }
    //判定
    for(int i=0;i<n;i++){
        flg[b[i]]=1;
        int cnt=0;
        for(int j=0;j<b[i];j++){
            if(flg[j]==0){cnt++;}
        }
        B=B+fac[n-i-1]*cnt;
    }
    if(A<B){cout<<B-A<<endl;}
    else{cout<<A-B<<endl;}
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int sumOfDigit(int n)
{
    int sum = 0;
    while(n > 0)
    {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(void)
{
    int N, A, B;

    cin >> N >> A >> B;
    int sum = 0;

    for(int i = 1; i <= N; i++)
    {
        if((sumOfDigit(i) >= A) && (sumOfDigit(i)  <= B))
            sum += i;
    }
    
    cout << sum <<endl;


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<climits>
#include<math.h>

#define forn(e,n,s) for(int i = e; i < n;i += s)
#define forr(e,n,s) for(int i = e; i >= n; i -= s)
#define PI 3.14159265358979323846264338327950L
#define ll long long

using namespace std;

const int MOD = 1e9+7;

void go(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout<<fixed;
  cout<<setprecision(20);

  #ifndef ONLINE_JUDGE
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
  #endif
}
int main(){
    go(); 

    // code here
    int n;cin>>n;
    ll arr[n];
    forn(0,n,1) cin>>arr[i];
    vector<vector<ll>> dp(n,vector<ll>(n,0));
    for(int i = n-1; i >= 0; i--){
        for(int j = i; j < n; j++){
            if(i==j){
                dp[i][j] = arr[i];
            }else{
                dp[i][j] = max(arr[i] - dp[i+1][j], arr[j] - dp[i][j-1]);
            }
        }
    }
    cout<<dp[0][n-1];
  
}









Measured memory_bytes: 73620
let read_int_list () =
	read_line ()
	|> Str.split (Str.regexp " ")
	|> List.map int_of_string

let is_const_list l =
	match l with
		| [] -> false
		| e :: es -> List.for_all ((=) e) es

let diff l1 l2 = List.map2 (-) l1 l2

let () =
	let row1 = read_int_list () in
	let row2 = read_int_list () in
	let row3 = read_int_list () in
	if is_const_list (diff row1 row2) && is_const_list (diff row2 row3) then
		print_endline "Yes"
	else
		print_endline "No"


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long
#define INF 999999999
using namespace std;
int main() {
  ll X;
  std::cin >> X;
  for (ll i = 0; i < 300; i++) {
    for (ll j = 0; j < 300; j++) {
      ll a = pow(i-150,5)-pow(j-150,5);
      if (a == X) {
        std::cout << i-150 << " " <<  j-150 << '\n';
        goto label;
      }
    }
  }
  label:
  int nyaaaan;
}


Measured memory_bytes: 4064
#include<stdio.h>
int main(){ 
	int S;
	scanf("%d", &S);
	int i=0;
	int x[4];
	while (S){
		x[i] = S % 10;
		S /= 10;
		i++;
	}
	if (x[0] == x[1] || x[1] == x[2] || x[2] == x[3]){
		printf("Bad\n");
	}
	else{
		printf("Good\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define LARGE 100001

long long getAns(int a[],int n,long long s){
	int i=0,j=0;
	long long sum=0;
	long long ans=0;
	
	for(i=0;i<n;i++){
		if(i>0)
			sum-=a[i-1];
		
		while(sum <= s){
			if(j<=n-1){
				j++;
				sum+=a[j-1];
			}
			else if(j>=n){
				j=n;
			}
			
			
			if(j==n)
				if(sum <= s)
					break;
			
			if(sum > s){
				sum-=a[j-1];
				j--;
				break;
			}
		}
		ans+=(j-i);
	}
	
	return ans;
}


int main(){
	int a[LARGE];
	int n,q;
	long long s;
	int ans=0;
	
	scanf("%d %d",&n,&q);
	
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(int i=0;i<q;i++){
		scanf("%lld",&s);
		printf("%lld\n",getAns(a,n,s));
	}
	
	return 0;
	
}


Measured memory_bytes: 2252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define FOR(NAME, START, NUM) for (ll NAME = START; NAME < (NUM); NAME++)
#define REP(NAME, NUM) for (ll NAME = 0; NAME < (NUM); NAME++)
#define BREP(NAME, NUM) for (ll NAME = (NUM)-1; NAME >= 0; NAME--)
#define ALL(NAME) (NAME).begin(), (NAME).end()

int div_cnt(int x,int y)
{
	int sum = 0;
	if(x % y != 0){
		sum += 0;
	}

	else{
		sum++;
		x /= y;
		sum += div_cnt(x,y);
	}

	return sum;
}

int main(){
	int n;
	cin >> n;

	int div2 , div3 , div5 , div7 , div11 , div13 , div17 , div19 , div23 , div29 , div31 , div37 , div41 , div43 , div47;
	int cnt3 , cnt5 , cnt15 , cnt25 , cnt75;
	div2 = div3 = div5 = div7 = div11 = div13 = div17 = div19 = div23 = div29 = div31 = div37 = div41 = div43 = div47 = 0;
	cnt3 = cnt5 = cnt15 = cnt25 = cnt75 = 0;

//n!の中に#が含まれる個数
	REP(i,n) div2+=div_cnt(i+1,2);
	REP(i,n) div3+=div_cnt(i+1,3);
	REP(i,n) div5+=div_cnt(i+1,5);
	REP(i,n) div7+=div_cnt(i+1,7);
	REP(i,n) div11+=div_cnt(i+1,11);
	REP(i,n) div13+=div_cnt(i+1,13);
	REP(i,n) div17+=div_cnt(i+1,17);
	REP(i,n) div19+=div_cnt(i+1,19);
	REP(i,n) div23+=div_cnt(i+1,23);
	REP(i,n) div29+=div_cnt(i+1,29);
	REP(i,n) div31+=div_cnt(i+1,31);
	REP(i,n) div37+=div_cnt(i+1,37);
	REP(i,n) div41+=div_cnt(i+1,41);
	REP(i,n) div43+=div_cnt(i+1,43);
	REP(i,n) div47+=div_cnt(i+1,47);

//3越え判定
	if(div2 >= 2) cnt3++;
	if(div3 >= 2) cnt3++;
	if(div5 >= 2) cnt3++;
	if(div7 >= 2) cnt3++;
	if(div11 >= 2) cnt3++;
	if(div13 >= 2) cnt3++;
	if(div17 >= 2) cnt3++;
	if(div19 >= 2) cnt3++;
	if(div23 >= 2) cnt3++;
	if(div29 >= 2) cnt3++;
	if(div31 >= 2) cnt3++;
	if(div37 >= 2) cnt3++;
	if(div41 >= 2) cnt3++;
	if(div43 >= 2) cnt3++;
	if(div47 >= 2) cnt3++;

//5越え判定
	if(div2 >= 4) cnt5++;
	if(div3 >= 4) cnt5++;
	if(div5 >= 4) cnt5++;
	if(div7 >= 4) cnt5++;
	if(div11 >= 4) cnt5++;
	if(div13 >= 4) cnt5++;
	if(div17 >= 4) cnt5++;
	if(div19 >= 4) cnt5++;
	if(div23 >= 4) cnt5++;

//15越え判定
	if(div2 >= 14) cnt15++;
	if(div3 >= 14) cnt15++;
	if(div5 >= 14) cnt15++;
	if(div7 >= 14) cnt15++;

//25越え判定
	if(div2 >= 24) cnt25++;
	if(div3 >= 24) cnt25++;
	if(div5 >= 24) cnt25++;

//75越え判定
	if(div2 >= 74) cnt75++;

	int ans = 0;

	ans += cnt75;
	ans += (cnt3 - 1) * cnt25;
	ans += (cnt5 - 1) * cnt15;
	if(cnt5 != 0){
		ans +=((cnt3 - 2) * (cnt5 - 1) * cnt5) / 2;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

int main(int argc, char const* argv[])
{
  ll a, b, c;
  cin >> a >> b >> c;
  if(a % 2 == 0 || b % 2 == 0 || c % 2 == 0)cout << 0 << endl;
  else{
    cout << min(a * b, min(b * c, c * a)) << endl;
  }
	return 0;
}


Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using P = pair<int,int>;
using ll = long long;
const int INF = 100000;
const int MAX_N = 105;



int n;
int main(){
    cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
    }
    sort(a.rbegin(),a.rend());
    int c1 = 0;
    int c2 = 0;

    for(int i=0;i<n;i+=2){
        c1 += a[i];
        if(i+1<=n-1){
            c2 += a[i+1];
        }
    }

    cout << c1-c2 << endl;

}

Measured memory_bytes: 256
using System;

class MyClass
{
    static void Main(string[] args)
    {
        int n, t, e;
        string[] str = Console.ReadLine().Split(' ');
        n = int.Parse(str[0]);
        t = int.Parse(str[1]);
        e = int.Parse(str[2]);
        string[] str2 = Console.ReadLine().Split(' ');
        int ans = -1;
        for (int i = 0; i < n; i++)
        {
            int x = int.Parse(str2[i]);
            int rem1;
            int d1 = Math.DivRem((t - e), x, out rem1);
            int rem2;
            int d2 = Math.DivRem((t + e), x, out rem2);
            if (d1 != d2 || rem1 == 0 || rem2 == 0)
            {
                ans = i + 1;
                break;
            }
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 19960
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(void){
    string s, t;
    cin >> s >> t;

    int count1 = 0;
    int count2 = 0;
    map<char, int> c1;
    map<char, int> c2;
    rep(i, s.size()){
        if(c1[s[i]] == 0){
            count1++;
            c1[s[i]] = count1;
        }
        if(c2[t[i]] == 0){
            count2++;
            c2[t[i]] = count2;
        }

        if(c1[s[i]] != c2[t[i]]){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	int N; cin >> N;
	vector<int> a(N);
	for(int i = 0; i < N; i++) cin >> a[i];
	int ans = inf;
	for(int goal = -100; goal <= 100; goal++) {
		int sum = 0;
		for(int i = 0; i < N; i++) sum += pow(a[i] - goal, 2);
		ans = min(ans, sum);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3596
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
#define ALL(a)  (a).begin(),(a).end()
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int nCr(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
int per(int n, int r) {
	r = n - r;
	int sum = 1;
	int i;
	for (i = n; i >= r + 1; i--)sum *= i;
	return sum;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};
int keta(int a) {
	return to_string(a).size();
}
signed main() {
	int a;
	cin>>a;
	if(a%100>(a/100)*5)cout<<0<<endl;
	else cout<<1<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string w, ans = "Yes";
  int cnt;
  cin >> w;
 
  
  
  for(char c='a'; c <= 'z'; c++){
    for(int i=0; i<w.size();i++){
      if(w.at(i) == c){
        cnt++;
      }
    }
    if(cnt%2 == 1){
      ans = "No";
      break;
    }
    cnt = 0;
  }
  
  
  
  cout << ans << endl;
  
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
#define double long double
#define ll long long

int main(void){
    ll n,k;
    vector<bool> b(2000000);
    ll ans=1;
    ll count=0;
    cin>>n>>k;
    vector<ll> a(n+1);
    for(ll i=0;i<2000000;i++){
        b[i]=false;
    }
    for(ll i=1;i<=n;i++){
        cin>>a[i];
    }
    //代入および初期化
    for(ll i=0;i<=k;i++){
        if(ans==a[ans]){
            cout<<ans<<endl;
            return 0;
        }
        if(b[ans]){
        break;
        }else{
            b[ans]=true;
            ans=a[ans];
            count++;
        }
        if(i==(k-1)){
            cout<<ans<<endl;
            return 0;
        }
    }
    //一週目探す
    for(ll i=0;i<=2000000;i++){
        b[i]=false;
    }
    //初期化
    ll ans2=k-count+1;
    count=0;
    for(ll i=0;i<k;i++){
        if(b[ans]){
            break;
        }else{
            count++;
            b[ans]=true;
            ans=a[ans];
        }
    }
    ans2=ans2%count;
    if(ans2==1){
        cout<<ans<<endl;
    }else{
        if(ans2==0) ans2=count;
        for(ll i=1;i<ans2;i++){
            ans=a[ans];
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 5096
#include "bits/stdc++.h"
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long

#define MOD 1000000007
string s;
LL dp[100002][13];

int main(){
  cin>>s;
  int n = s.size();
  int mod = 1;
  REP(i,13)dp[0][i]=0;
  dp[0][0]=1;
  REP(i,n){
    if(s[n-1-i]=='?'){
      REP(j,13){
	REP(k,10){
	  dp[i+1][(j+mod*k)%13] += dp[i][j];
	  dp[i+1][(j+mod*k)%13] %= MOD;
	}
      }
    }else{
      REP(j,13){
	//cerr<<i<<" "<<j<<" "<<(s[n-1-i]-'0')<<" "<<endl;
	dp[i+1][(j+(s[n-1-i]-'0')*mod)%13] += dp[i][j];
	dp[i+1][(j+(s[n-1-i]-'0')*mod)%13] %= MOD;
      }
    }
    mod = mod*10%13;
  }

  /*
  REP(i,n+1){
    REP(j,13){
      cerr<<dp[i][j]<<" ";
    }
    cerr<<endl;
  }
  */
  
  cout<<dp[n][5]%MOD<<endl;
  return 0;
}


Measured memory_bytes: 10624
#include <stdio.h>
#include <string.h>
#define MAX 550

int N;
int c[MAX], s[MAX], f[MAX];

int goStation(int k)
{
	int reach,start, i,x,tmp;
	i = k; start = s[i];
	while (i + 1 <= N){
		//printf("start:%d\n", start);
		reach = start + c[i];
		//printf("reach=%d\n", reach);
		if (i + 1 == N) break;
		if (reach < s[i + 1]){
			start = s[i + 1];
		}
		else{
			x = 1;
			do{
				tmp = (s[i + 1] + (x*f[i + 1]));
				x++;
			} while (tmp < reach);
			start = tmp;
		}
		i++;
	}
	return reach;
}

int main(void)
{
	scanf("%d", &N);
	int i;
	for (i = 1; i < N; i++){
		scanf("%d%d%d", &c[i], &s[i], &f[i]);
	}
	for (i = 1; i < N; i++){
		printf("%d\n", goStation(i));
	}
	printf("0\n");
	return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline

# D - I hate Factorization
def meet_condition(i, j):
	pi = pows[i]
	pj = pows[j]
	
	if pi - pj == x:
		return i, j
	elif pi + pj == x:
		return i, -j


pows = []

for i in range(200):
	pows.append(pow(i, 5))

x = int(input())

for i in range(len(pows)):
	for j in range(len(pows)):
		if meet_condition(i, j) != None:
			a, b = meet_condition(i, j)
			print(a, b)
			exit()

Measured memory_bytes: 9204
package main

import "fmt"

func main() {
	var x int
	fmt.Scan(&x)
	for _, n := range sosuu() {
		if n >= x {
			fmt.Println(n)
			return
		}
	}
}

func sosuu() []int {
	sosuus := []int{2}
outer:
	for i := 3; i < 200000; i++ {
		for n := 0; n < len(sosuus); n++ {
			if i%sosuus[n] == 0 {
				continue outer
			}
		}
		sosuus = append(sosuus, i)
	}
	return sosuus
}


Measured memory_bytes: 1280
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <climits>
#include <algorithm>
using namespace std;




int main() 
{
	int n,m;
	cin>>n>>m;
	int a=0;
	for(int i=0;i<m;++i){
		int tmp;
		cin>>tmp;
		a+=tmp;
	}

	if(a<=n){
		cout<<n-a;
	}
	else
		cout<<-1;


}


Measured memory_bytes: 3596
def main ():
    N = int(input())
    A = list(map(int,input().split()))
    if 0 in A:
        print (0)
        return
    prod = 1 
    for a in A:
        prod *= a
        if prod > 1000000000000000000:
            print(-1) 
            return
    print(prod)

    
main ()

Measured memory_bytes: 21804
#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

ll Euclid(ll A, ll B){
    if(A<B) swap(A, B);
    ll C = B;
    while(C != 0){
        C = A%B;
        A = B;
        B = C;
    }
    return A;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    vector<ll> S(N+1, 0), T(N+1, 0);
    REP(i, N){
    	S[i+1] = Euclid(S[i], A[i]);
    	T[i+1] = Euclid(T[i], A[N-1-i]);
    }

    ll ma = 0;
    REP(i, N){
    	ll tmp = Euclid(S[i], T[N-1-i]);
    	chmax(ma, tmp);
    }
    cout << ma << endl;
    return 0;
}

Measured memory_bytes: 2560
# ABC145 D

X,Y=map(int,input().split())

a,b=-1,-1
if not (2*X-Y)%3:
    b=(2*X-Y)//3
if not (2*Y-X)%3:
    a=(2*Y-X)//3
    



N=10**6
p=10**9+7
f,finv,inv=[0]*N,[0]*N,[0]*N

def nCr_init(L,p):
    for i in range(L+1):
        if i<=1:
            f[i],finv[i],inv[i]=1,1,1
        else:
            f[i]=(f[i-1]*i)%p
            inv[i]=(p-inv[p%i]*(p//i))%p
            finv[i]=(finv[i-1]*inv[i])%p

def nCr(n,r,p):
    if 0<=r<=n and 0<=n:
        return (f[n]*finv[n-r]*finv[r])%p
    else:
        return 0
    
nCr_init(a+b+1,p)
if a>=0 and b>=0:
    print(nCr(a+b,b,p))
else:
    print(0)

Measured memory_bytes: 87340
#include<stdio.h>

int A[100010];

int main(){
	int N,c=0;
	scanf("%d",&N);
	
	for(int i=0;i<N;i++){
		int a;
		scanf("%d",&a);
		A[a]++;
	}
	
	int f=1;
	for(int i=1;i<=100000;i++){
	
		if(A[i]>=3){
			c+=(A[i]-1)/2;
			A[i]%=2;
			if(A[i]==0)A[i]=2;
		}
		if(A[i]==2){
			c+=f;
			f=(f+1)%2;
		}
	}
	printf("%d\n",N-c*2);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int n,a,b;
  cin >> n >> a >> b;
  cout << min(a,b) << " " << max(0,a+b-n) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;

typedef long long ll;
#define pa pair<int, int> 
#define pal pair<long long, long long>
#define pali pair<long long, int>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair 
#define COUT(v) for(int64_t i=0;i<(v).size();i++){ cout << v.at(i) << endl;}
#define REP(i, n) for(int64_t i=0;i<n;i++)
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}

typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pavec;
typedef vector<pali> palivec;
typedef vector<pal>palvec;


typedef vector< vector<bool> > bmat;
typedef vector< vector<int> > imat;
typedef vector< vector<long long> > lmat;

typedef vector<string> svec;
typedef vector< vector<string> > smat;
const ll infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;
const int MOD = 1000000007;


ll gcd(ll x, ll y){
    ll r = x%y;
    if(r == 0) return y;
    else return gcd(y, r);
} 

ll lcm(ll x, ll y){
    return x*y/gcd(x,y);
}

lvec mfactor(ll n){
    bvec ip(n, true);
    lvec mf(n, -1);
    ip[0]=false; ip[1]=false; mf[0]=0; mf[1]=1;
    REP(i, n){
        if(ip[i]){
            mf[i] = i;
            for(ll j=i*i; j<n; j+=i){
                ip[j] = false;
                if(mf[j] == -1) mf[j]=i;
            }
        }
    }
    return mf;
}

palivec get_prime(ll n, const lvec &mf){
    palivec plist;
    while(n != 1){
        int cnt=0;
        ll m=mf[n];
        while(mf[n] == m){
            cnt++;
            n/=m;
        }
        plist.pb(pali(m, cnt));
    }
    return plist;
}

void COMinit(int m, lvec &fac, lvec &finv){
    lvec inv(m);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < m; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll pow_mod(ll a, ll n){
  ll x = 1;
  while(n > 0){
    if(n&1){
      x = x*a % MOD;
    }
    a = a*a %MOD;
    n >>= 1;
  }
  return x;
}
ll COM(int n, int k, const lvec& fac, const lvec &finv){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll P(ll n, ll m){
    ll s = 1;
    ll cnt=n;
    REP(i, n-m){
        s*=cnt % MOD;
        s%=MOD;
        --cnt;
    }
    return s;
    
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    int d=0;
    while(n>0){
        n/=k;
        ++d;
    }
    cout << d << endl;
}


Measured memory_bytes: 256
N = int(input())

planes = {
  'U': [],
  'R': [],
  'D': [],
  'L': []
}

for _ in range(N):
  x, y, t = input().split()
  x, y = int(x), int(y)
  planes[t].append((x, y))
  
BIG = 10**18
  
def time(ps):
  ps.sort()
  ans = BIG
  for i in range(len(ps)-1):
    y1, x1, t1 = ps[i]
    y2, x2, t2 = ps[i+1]
    
    if y1 != y2:
      continue
    
    if t1 == 1 and t2 == -1:
      ans = min(ans, x2 - x1)
  return 5*ans


ud = [(x, y, 1) for x, y in planes['U']] + [(x, y, -1) for x, y in planes['D']]
lr = [(y, x, 1) for x, y in planes['R']] + [(y, x, -1) for x, y in planes['L']]

ur = [(x+y, y-x, 1) for x, y in planes['U']] + [(x+y, y-x, -1) for x, y in planes['R']]
ul = [(x-y, y+x, 1) for x, y in planes['U']] + [(x-y, y+x, -1) for x, y in planes['L']]
rd = [(x-y, y+x, 1) for x, y in planes['R']] + [(x-y, y+x, -1) for x, y in planes['D']]
ld = [(x+y, y-x, 1) for x, y in planes['L']] + [(x+y, y-x, -1) for x, y in planes['D']]

ans = min(time(ud), time(lr), time(ur), time(ul), time(rd), time(ld))
if ans >= BIG:
  print("SAFE")
else:
  print(ans)

  


Measured memory_bytes: 105820
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    ll x; cin >> x; (x == 3 || x == 5 || x == 7) ? YES() : NO();
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

int main(int argc, const char * argv[]) {
  
  ll N, X; cin >> N >> X;
  vector<ll> S(N);
  for (int i=0; i<N; i++)
    cin >> S[i];
  
  sort(S.begin(), S.end(), greater<ll>());
  
  vector<vector<ll>> dp(N+1, vector<ll>(X+1, 0));
  dp[0][X] = 1;
  for (ll n=0; n<N; n++) {
    for (ll x=0; x<X+1; x++) {
      dp[n+1][x%S[n]] += dp[n][x];
      dp[n+1][x%S[n]] %= MOD;
      dp[n+1][x] += (N-n-1)*dp[n][x]%MOD;
      dp[n+1][x] %= MOD;
    }
  }
  
  ll ans = 0;
  for (int i=0; i<X+1; i++){
    ans += dp[N][i]*i % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 158592
#include<bits/stdc++.h>
using namespace std;
string s;
int ans,n;
int main()
{
	cin>>n;
	getline(cin,s);
	getline(cin,s);
	for(int i=0;i<n-2;++i)
		 if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
def gcdf(a):
    a.sort()
    a0=a[0]
    a=[int(x%a0) for x in a if x%a0 != 0]
    if len(a)==0:
        return a0
    else:
        a.append(a0)
        a0=min(a)
        return gcdf(a) 

n=int(input())
a=list(map(int,input().split()))

gcdx=gcdf(a)
print(gcdx)



Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
const int inf = 0x3f3f3f3f;
const ll mod = 1000000007;
#define debug(x) cerr << #x << " = " << x << endl

ll dp[103][100010];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, w;
    cin >> n >> w;
    for(int i = 0; i < n; i++){
        ll c, v;
        cin >> c >> v;
        for(int j = 0; j < c; j++) dp[i+1][j] = dp[i][j];
        for(int j = 0; j+c <= w; j++){
            dp[i+1][j+c] = max(dp[i][j+c], dp[i][j] + v);
        }
    }
    ll ans = 0;
    for(int i = 0; i <= w; i++) ans = max(ans, dp[n][i]);
    cout << ans << "\n";
}

Measured memory_bytes: 79360