akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

map<vector<int> , int> mp;

bool solve(){
	vector<int> p(8);
	for(int i=0; i<8; ++i){
		if(scanf(" %d", &p[i]) == EOF) return false;	
	}
	
	cout << mp[p] << endl;

	return true;
}

int main(){
	int dir[4]={1,-1,4,-4};
	queue< vector<int> > que;
	
	vector<int> start(8);
	for(int i=0; i<8; ++i) start[i]=i;
	
	que.push(start);
	mp[start]=0;
	
	while(!que.empty()){
		vector<int> v=que.front();
		que.pop();
		
		int z;
		for(int i=0; i<8; ++i){
			if(v[i]==0){
				z=i;
				break;	
			}	
		}
		
		for(int i=0; i<4; ++i){
			int nz=z+dir[i];
			if(nz>=0 && nz<=7 && !(z==3&&nz==4) && !(z==4&&nz==3)){
				vector<int> tmp=v;	
				swap(tmp[z], tmp[nz]);
				
				if(mp.find(tmp) == mp.end()){
					que.push(tmp);
					mp[tmp]=mp[v]+1;	
				}
				
			}		
		}
			
	}
	
	while(solve());
}


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

using namespace std;

inline int read()
{
    int ret=0,flag=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')flag=-1;c=getchar();}
    while(c>='0'&&c<='9')ret=ret*10+(c^'0'),c=getchar();
    return flag*ret;
}

struct use
{
    int val,col,ha;
};

const int N=1e5+5;
int a,b,c,x,y;
use s[N*3];

bool cmp(use a,use b)
{
    if(a.val!=b.val)return a.val>b.val;
    return a.ha>b.ha;
}

int main()
{
    x=read(),y=read(),a=read(),b=read(),c=read();
    for(int i=1;i<=a;i++)s[i].val=read(),s[i].col=1,s[i].ha=0;
    for(int i=1;i<=b;i++)s[i+a].val=read(),s[i+a].col=2,s[i].ha=0;
    for(int i=1;i<=c;i++)s[i+a+b].val=read(),s[i+a+b].col=3,s[i].ha=1;
    sort(s+1,s+a+b+c+1,cmp);
    int sum1=0,sum2=0,sum3=0;
    long long ans=0;
    for(int i=1;i<=a+b+c;i++)
    {
        if(s[i].col==1)
        {
            if(sum1<x)
            {
                ans+=s[i].val;
                ++sum1;
            }
        }
        else if(s[i].col==2)
        {
            if(sum2<y)
            {
                ans+=s[i].val;
                ++sum2;
            }
        }
        else ans+=s[i].val,++sum3;
        if(sum1+sum2+sum3==x+y)break;
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 3712
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
int dp[6][20][20]={0};
int n,a,b;
int kouzi[2];
int main(void){
	for(int i=1;i<=5;i++){
		cin>>a>>b;
		if(a==0&&b==0){
			break;
		}
		cin>>n;
		for(int j=0;j<n;j++){
			cin>>kouzi[0]>>kouzi[1];
			dp[i][kouzi[0]][kouzi[1]]=-1;
		}
		dp[i][0][1]=1;
		for(int j=1;j<=a;j++){
			for(int k=1;k<=b;k++){
					if(dp[i][j][k]!=-1&&dp[i][j-1][k]!=-1&&dp[i][j][k-1]!=-1)dp[i][j][k]=dp[i][j-1][k]+dp[i][j][k-1];
					else if(dp[i][j-1][k]!=-1&&dp[i][j][k]!=-1){dp[i][j][k]=dp[i][j-1][k];}
					else if(dp[i][j][k-1]!=-1&&dp[i][j][k]!=-1){dp[i][j][k]=dp[i][j][k-1];}
				}
			}
			cout<<dp[i][a][b]<<endl;
		}
	return 0;
}



Measured memory_bytes: 3008
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll M = 1e9 + 7;
int si[8] = {-1,0,1,-1,1,-1,0,1};
int sj[8] = {-1,-1,-1,0,0,1,1,1};

struct UnionFind {
  vector<int> d;
  // 子は親のIDを，根は木のサイズ*-1を持つ
  UnionFind(int n = 0): d(n,-1){}
  // rootを探索する
  int find(int x){
    if(d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  // 集合を統合する
  bool unite(int x, int y){
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  // 同じ集合に属しているか判定
  bool same(int x, int y) {return find(x) == find(y);}
  // xの属している集合のサイズを返す
  int size(int x) {return -d[find(x)];}
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(n);
  rep(i,n) {
    cin >> p[i];
    p[i]--;
  }
  UnionFind uf(n);
  rep(i,m){
    int x, y;
    cin >> x >> y;
    x--; y--;
    uf.unite(x, y);
  }

  int ans = 0;
  rep(i,n){
    if(p[i] == i) {
      ans++;
      continue;
    }
    if(uf.same(p[i], i)) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3972
#include<bits/stdc++.h>
using namespace std;
#define l long long
int main()
{
   int n,x,y;
     cin>>n;
   if(n==1) cout<<"Hello World"<<endl;
   else if(n==2){
    cin>>x>>y;
    cout<<x+y<<endl;
}
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define debug_array(a,n) for (ll bccc=(0); bccc<(n); bccc++) cout<<a[bccc]<<" "<<"\n"
#define debug_vector(a) for(ll bccc=(0); bccc<(a.size());bccc++) cout<<a[bccc]<<" "<<"\n"
#define F           first
#define S           second
#define debug_set(s) for(auto p:s) cout<<p<<" "
#define debug_map(m) for(auto p:m) cout<<p.F<<" "<<p.S<<"\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
/* ll t = 0;
ordered_multiset me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

///////////   t is insertion time
*/
// #pragma GCC optimize("Ofast")  // works very well
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long double lld;
lld pi=3.14159265358;
ll powr(ll a,ll b)
{
    ll c=1;
    ll kjk;
    for(kjk=0;kjk<b;kjk++)
        c*=a;
    return c;
}
ll hell=1000000007;
//ll hell=998244353   ;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// to generate random number , use rng() ... eg cout<<rng();
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    ll n;
    cin>>n;
    if(n%2)
    {
        cout<<0;
        return 0;
    }
    n/=2LL;
    ll c=0;
    while(n)
    {
        c+=n/5LL;
        n/=5LL;
    }
    cout<<c;


}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast") 

////////////////////////////////////////////////////////////////////////////////

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define bew ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) x.begin(),x.end()
#define pb push_back
#define fi first
#define se second
#define mod (long)(1e9+7)
#define ip(ar,n) for(int i=0;i<n;++i)cin>>ar[i];
#define op(ar,n) for(int i=0;i<n;++i)cout<<ar[i]<<" ";
#define test int t;cin>>t;while(t--)
#define tar(x) int x;cin>>x;
#define fil(ar,val) memset(ar,val,sizeof ar)
#define loop(n) for(int i=0;i<n;++i)

////////////////////////////////////////////////////////////////////////////////

typedef vector<int> vi; 
typedef pair<int, int> ii; 
typedef vector<ii> vii; 
typedef set<int> si;
typedef map<int,int> mi;

////////////////////////////////////////////////////////////////////////////////






signed main() {
bew;
    tar(n);
    tar(k);
    int ar[n];
    ip(ar,n);
    int dp[k+1];
    memset(dp,0,sizeof dp);
    
    for(int i=ar[0];i<=k;++i)
    {
        bool flag=false;
        for(int j=0;j<n&&i-ar[j]>=0;++j)
        if(dp[i-ar[j]]==0)
        {
            flag=true;
            break;
        }
        
        dp[i]=flag?1:0;        
    }

    cout<<(dp[k]?"First":"Second");
return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <array>
#include <algorithm>

using namespace std;

using ll = long long int;

int main(){
    
    ll N;
    array<ll, 300000> T;
    
    cin >> N;
    for(ll i = 0; i < N * 3; ++i){
        cin >> T[i];
    }
    
    sort(T.begin(), T.begin() + N * 3, greater<ll>());
    
    ll sum = 0;
    for(ll i = 1; i < 2 * N; i += 2){
        sum += T[i];
    }

    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
typedef pair<int,int>P;
#define F first
#define S second

main(){
	int n;
	cin>>n;
	int N = n;
	if(__builtin_popcount(n)==1){
		cout<<"No"<<endl;
		return 0;
	}

	cout<<"Yes"<<endl;

	int p=0,cnt=0;
	if(N%2==0)p=1,N--;

	while(N!=1){
		cnt+=4;
		cout<<1<<' '<<N-1<<endl;
		cout<<N-1<<' '<<N<<endl;
		cout<<1<<' '<<n+N<<endl;
		cout<<n+N<<' '<<n+N-1<<endl;
		N-=2;
	}
	cout<<n+1<<' '<<3<<endl;cnt++;
	if(p){
		cout<<n+n-1<<' '<<n+n<<endl;cnt+=2;
		cout<<n<<' '<<((n-1)^n^1)<<endl;
	}
	//cout<<cnt<<endl;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 10000000;
typedef pair<int,int> P;
typedef long long ll;
/*
*/

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i,N){
    cin >> A[i];
  }
  sort(A.begin(),A.end());
  int count = 1;
  rep(i,N-1){
    if(A[i] != A[i+1]) count++;
  }
  
  if(count == N) cout << "YES" << endl;
  else cout << "NO" << endl;
  
}


Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func exec(stdin *Stdin, stdout *Stdout) {
	a := stdin.ReadInt()
	b := stdin.ReadInt()

	x := Min(a, b)
	y := Max(a, b)
	s := ""
	for i := 0; i < y; i++ {
		s += strconv.Itoa(x)
	}
	stdout.Println(s)
}

func Min(a ...int) int {
	v := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] < v {
			v = a[i]
		}
	}
	return v
}

func Max(a ...int) int {
	v := a[0]
	for i := 1; i < len(a); i++ {
		if v < a[i] {
			v = a[i]
		}
	}
	return v
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), int(math.MaxInt32))
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}


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

int even(int n) { return n / 2; };
int odd(int n) { return 3 * n + 1; };

int main() {
    int s; cin >> s;
    vector<int> a;
    int ans = 0, tmp = s;
    bool end = 1;

    while (end) {
        a.push_back(tmp);
        if (tmp & 1) tmp = odd(tmp);
        else tmp = even(tmp);
        for (int i = 0; i < a.size(); i++) {
            for (int j = i+1; j < a.size(); j++) {
                if (a[i] == a[j]) ans = j+1, end = 0;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  ll maxVal = a * c;
  maxVal = max(maxVal, max(a * d, max(b * c, b * d)));
  if (a <= 0 && 0 <= b) {
    ll z = 0;
    maxVal = max(z, maxVal);
  }
  if (c <= 0 && 0 <= d) {
    ll z = 0;
    maxVal = max(z, maxVal);
  }

  cout << maxVal << endl;
}


Measured memory_bytes: 3644
function rotate(arr){
   var L=arr.length-1;
   var yx=arr.map(function(v){return v.slice();});
   for(var i=0;i<=L;i++){
      for(var j=0;j<=L;j++){
         yx[i][j]=arr[L-j][i];
      }
   }
   return yx;
}
function check(a,b){
   var re=false;
   for(var y=0;y<m;y++){
      for(var x=0;x<m;x++){
         if(yxM[y][x]==-1)continue;
         if(re===false)re=[a+y,b+x];
         if(yxN[a+y][b+x]!=yxM[y][x])return false;
      }
   }
   return re;
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=input.trim().split("\n");
while(true){
   var nm=Arr.shift().split(" ").map(Number);
   var n=nm[0];
   var m=nm[1];
   if(n==0 && m==0)break;
   var yxN=[];
   for(var i=0;i<n;i++){
      var v=Arr.shift().split(" ").map(Number);
      yxN.push(v);
   }
   var yxM=[];
   for(var i=0;i<m;i++){
      var v=Arr.shift().split(" ").map(Number);
      yxM.push(v);
   }
   var min=[101,101];
   for(var k=0;k<4;k++){
      for(var i=0;i<=n-m;i++){
         for(var j=0;j<=n-m;j++){
            var flag=check(i,j);
            if(flag!==false){
               if(min[0]>flag[0]+1)min=[flag[0]+1,flag[1]+1];
               if(min[0]==flag[0]+1 && min[1]>flag[1])min=[flag[0]+1,flag[1]+1];
            }
         }
      }
      yxM=rotate(yxM);
   }
   console.log((min.join("")=="101101")?"NA":min[1]+" "+min[0]);
}

Measured memory_bytes: 17692
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;

int main(){
    int h, w, d; cin >> h >> w >> d;
    vector<vector<pair<int, pair<int, int>>>> mp(d);
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            int a; cin >> a;
            mp[a % d].push_back({a, make_pair(i,j)});
        }
    }
    for(int i = 0; i < d; i++){
        sort(mp[i].begin(), mp[i].end());
    }
    vector<vector<int>> sum(d);
    for(int i = 0; i < d; i++){
        sum[i].push_back(0);
        int x = mp[i][0].second.first, y = mp[i][0].second.second;
        for(int j = 1; j < mp[i].size(); j++){
            int nx = mp[i][j].second.first, ny = mp[i][j].second.second;
            sum[i].push_back(abs(nx - x) + abs(ny - y) + sum[i][j-1]);
            x = nx; y = ny;
        }
    }
    int q; cin >> q;
    for(int i = 0; i < q; i++){
        int l, r; cin >> l >> r;
        cout << sum[r%d][(r-1)/d] - sum[l%d][(l-1)/d]  << endl;
    }
}

Measured memory_bytes: 12824
#include <cstdio>

using namespace std;

int main() {
    int a, b;
    scanf("%d%d", &a, &b);
    if(1 <= a && a <= 9 && 1 <= b && b <= 9) {
        printf("%d\n", a*b);
    } else {
        puts("-1");
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int t;cin>>t;while(t--)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define MOD 1000000007
#define ll long long
#define ld long double
#define int ll
#define pb push_back
#define ii pair<int,int>
#define llll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<ii>
#define vllll vector<llll>
#define ff first
#define ss second
#define INF 1000000000
#define HINF 1000000000000000
#define mem(a,b) memset(a,b,sizeof(a))
#define arrin(x,n) int x[n]; for(int o=0;o<n;o++) cin>>x[o]
#define arrout(x,n) for(int o=0;o<n;o++) cout<<x[o]<<" "; cout<<endl
#define vecin(x,n); vi x;int hool; for(int o=0;o<n;o++) {cin>>hool; x.pb(hool);}
#define vecout(x,n) for(int o=0;o<n;o++) cout<<x[o]<<" "; cout<<endl
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<'='<<x<<endl
#define deb2(x,y) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<endl
#define deb3(x,y,z) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<" "<<#z<<'='<<z<<endl
#define debarr(arr,n) for(int o=0;o<n;o++) deb2(o,arr[o])
#define IO freopen("input.txt", "r", stdin); freopen("output.txt", "w+", stdout)
const double pi = 3.14159265358979323846;

int powersimple(int a, int b){//a^b
    int res=1;
    while(b>0){
        if(b&1)
		{res=(res*a);
		b--;}
        a=(a*a);
        b>>=1;
    }
    return res;
}

int ncr(int n,int k)
{
	int ans=1;
	if(k>n-k)
	k=n-k;
	for(int i=1;i<=k;i++)
	ans*=(n-i+1),ans/=i;
	return ans;
}


int power(int x,int y,int p) 
{ 
    int res = 1;  
    x = x % p;   
    while (y > 0) { 
        if (y & 1) 
            res = (res * x) % p;  
        y = y >> 1; 
        x = (x * x) % p; 
    } 
    return res; 
} 

int modInverse(int n, int p) 
{ 
    return power(n, p - 2, p); 
} 

int ncrModPFermat(int n,int r, int p) 
{ 

    if (r == 0) 
		return 1; 
    
    int fac[n + 1]; 
    fac[0] = 1; 
    for (int i = 1; i <= n; i++) 
        fac[i] = (fac[i - 1] * i) % p; 
  
    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
} 

int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}



void solve()
{

	int i=0,j=0,k=0,m,n,p,sum=0,cnt=0;
	cin>>n;
	for(i=1;i<n;i++)
	{
	    sum+=(n-1)/i;
	}
	cout<<sum;
	
	
	 
}
int32_t main() {
    fast
    //IO;
	//cout<<fixed<<setprecision(6);
    //test
    {
        
        solve();
		
		      
    }
    return 0;
}
  




Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;

const int MAX_N = (int) 1e5 + 5;
lint S[MAX_N], T[MAX_N];

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int A, B, Q; cin>>A>>B>>Q;
    for(int i=1;i<=A;i++) cin>>S[i];
    for(int i=1;i<=B;i++) cin>>T[i];

    S[0] = (lint)-1e12; S[A+1] = (lint)1e12;
    T[0] = (lint)-1e12; T[B+1] = (lint)1e12;

    while(Q--){
        lint x, ans = (lint)1e12; cin>>x;
        for(int i=0;i<2;i++){
            for(int j=0;j<2;j++){
                lint p1, p2, cur;
                if(i) p1 = *lower_bound(S, S+A+2, x);
                else p1 = *(next(lower_bound(S, S+A+2, x), -1));
                if(j) p2 = *lower_bound(T, T+B+2, x);
                else p2 = *(next(lower_bound(T, T+B+2, x), -1));
                if(i!=j){
                    cur = abs(p1-x) + abs(p2-x) + min(abs(p1-x), abs(p2-x));
                }
                else{
                    cur = max(abs(p1-x), abs(p2-x));
                }
                ans = min(ans, cur);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
#include <list>
#include <deque>
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const ll INF = 1LL << 60;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) {return a / GCD(a, b) * b;}

ll dp[110][100010];

int main()
{
	int H1,M1,H2,M2,K;
	cin >> H1 >> M1 >> H2 >> M2 >> K;
	int time = 60 * (H2 - H1) + (M2 - M1);
	cout << time - K << endl;
}


Measured memory_bytes: 3160
import java.util.*;
 
public class Main{
	
	static int gcd(int a, int b){
		if(a<b){
			int temp= a;
			a=b;
			b=temp;
		}
		if(b==0) return a;
		return gcd(a%b,b);
	}
	
	
	public static void main(String []args){
	    Scanner sc= new Scanner(System.in);
	    
		int n=sc.nextInt();
		int[] A = new int [n];
		int[] L = new int [n];
		int[] R = new int [n];
		
		for(int i=0;i<n; i++){
		    A[i]=sc.nextInt();
		}
		
		L[0]=0;
		R[0]=0;
		
		for (int i=1; i<n; i++){
		    L[i]=gcd(L[i-1],A[i-1]);
		    R[i]=gcd(R[i-1],A[n-i]);
		    
		}
		
		int gcd=0;
		
		for (int i=0; i<n; i++){
		    int temp=gcd(L[i], R[n-i-1]);
		    
		    if(gcd<temp){
		        gcd=temp;
		    }
		    
		}
		System.out.println(gcd);
		
    }
}

Measured memory_bytes: 52000
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    a = f()
    if sum(a) - max(a) == max(a):
        print('Yes')
    else:
        print('No')

solve()


Measured memory_bytes: 2940
import random
import time

def down_score(d, c, last_d, score):
    sum = 0
    for i in range(26):
        sum = sum + c[i]*(d-last_d[i])
        
    return int(score - sum)


def main():
    D = int(input())

    c = list(map(int, input().split()))

    s = [list(map(int, input().split())) for i in range(D)]

    start = time.time()
    
    last_d = [0 for i in range(26)]
    
    ans = []
    
    score1 = 0
    
    for i in range(D):
        max = 0
        idx = 0
        for j in range(26):
            if max < (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] != 0:
                max = s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2
                idx = j
            elif max == (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] * (i-last_d[j])*(i-last_d[j]+1)/2 > c[idx]* (i-last_d[idx])*(i-last_d[idx]+1)/2 and c[j] != 0:
                idx = j
            
        last_d[idx] = i+1
        score1 += s[i][idx]
        score1 = down_score(i+1,c,last_d,score1)
        
        ans.append(idx)

    while time.time() - start < 1.9:
        d1 = random.randint(0,D-19)
        d2 = random.randint(d1+1,d1+18)
        if d1 == d2:
            continue
        tmp_d1 = ans[d1]
        tmp_d2 = ans[d2]
        ans[d1] = tmp_d2
        ans[d2] = tmp_d1
        last_d = [0 for i in range(26)]
        score2 = 0    
        for i in range(D):
            score2 += s[i][ans[i]]
            last_d[ans[i]] = i+1
            score2 = down_score(i+1, c, last_d, score2)
        
        if score1 > score2:
            ans[d1] = tmp_d1
            ans[d2] = tmp_d2
        else:
            score1 = score2
    
    for i in range(D):
        print(ans[i]+1)  

if __name__ == "__main__":
    main()


Measured memory_bytes: 9804
N, M = list(map(int, input().split()))

MOD = 10**9+7

class Comb:
    def __init__(self, N):
        self.fac = [1] * (N+1)
        for i in range(2, N+1): self.fac[i] = self.fac[i-1] * i % MOD

    def pow(self, a, b):
        res = 1
        while b:
            if b & 1: res = res * a % MOD
            a = a**2 % MOD
            b >>= 1
        return res

    def comb(self, n, r):
        if r < 0 or r > n: return 0
        return (self.fac[n] * self.pow(self.fac[r], MOD-2)) % MOD * self.pow(self.fac[n-r], MOD-2) % MOD

    def permutation(self, n, r):
        if r == 0: return 1
        return self.fac[n] * self.pow(self.fac[n-r], MOD-2) % MOD

from collections import *
import sys
def get_prime(n):
    c = Counter()

    while not n % 2:
        c[2] += 1
        n //= 2
    i = 3

    while i**2 <= n:
        while not n % i:
            c[i] += 1
            n //= i
        i += 2

    if n > 1: 
        c[n] += 1

    return c

prime = get_prime(M)
if not prime: print(1); sys.exit()

comb = Comb(N+max([m for m in prime.values()]))

ans = 1

for n in prime.values():
    ans = ans * comb.comb(N+n-1, n) % MOD
print(ans % MOD)

Measured memory_bytes: 7284
#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define frab(i, a, b) for (int i = a; i < b; i++)
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const ll MOD = 1e9 + 7;
const ll INF = 2e15 + 10;
const ll MAX = 1e14 + 10;
const ld EPS = 1e-9;
const int N = 2e5 + 10;
const int M = 1e5 + 10;

int h[N], a[N];
ll t[4 * N];

ll getMax(int v, int tl, int tr, int l, int r) {
    if (tl > r || l > tr) return -INF;
    if (l <= tl && tr <= r) return t[v];
    int tm = (tl + tr) / 2;
    return max(getMax(2 * v, tl, tm, l, r), getMax(2 * v + 1, tm + 1, tr, l, r));
}

void setEl(int v, int tl, int tr, int pos, ll val) {
    if (tl == tr) {
        t[v] = val;
        return;
    }
    int tm = (tl + tr) / 2;
    if (pos <= tm)
        setEl(2 * v, tl, tm, pos, val);
    else
        setEl(2 * v + 1, tm + 1, tr, pos, val);
    t[v] = max(t[2 * v], t[2 * v + 1]);
}

void solve() {
    int n;
    cin >> n;
    fr(i, n)
        cin >> h[i];
    fr(i, n)
        cin >> a[i];
    fr(i, n) {
        ll m = getMax(1, 0, n, 0, h[i]);
        setEl(1, 0, n, h[i], a[i] + m);
    }

    cout << getMax(1, 0, n, 0, n);
}



int main() {
    //freopen("a.in", "r", stdin);
    ios_base::sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 7936
#!/usr/bin/perl
my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);
( my $a = <STDIN> ) =~ s/[\x0a\x0d]+$//ios;
( my $b = <STDIN> ) =~ s/[\x0a\x0d]+$//ios;
( my $c = <STDIN> ) =~ s/[\x0a\x0d]+$//ios;

my $tot = 0;
for(my $i=0;$i<$n;$i++){
  my $x = substr($a,$i,1);
  my $y = substr($b,$i,1);
  my $z = substr($c,$i,1);
  if( $x eq $y and $x eq $z ){
    $tot += 0;
  } elsif ( $x eq $y or $y eq $z or $z eq $x ){
    $tot += 1;
  } else {
    $tot += 2;
  }
}
print "$tot\n";


Measured memory_bytes: 512
n=int(input())
ass=list(map(int,input().split()))
bs=list(map(int,input().split()))
cs=list(map(int, input().split()))
ans=sum(bs)

for i in range(n-1):
    if ass[i+1]==ass[i]+1:
        ans+=cs[ass[i]-1]

print(ans)

Measured memory_bytes: 3064
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 10e9;

int t[9];
int thisRate(int v) {
	if (v < 400) {
		return 0;
	}
	else if (v < 800) {
		return 1;
	}
	else if (v < 1200) {
		return 2;
	}
	else if (v < 1600) {
		return 3;
	}
	else if (v < 2000) {
		return 4;
	}
	else if (v < 2400) {
		return 5;
	}
	else if (v < 2800) {
		return 6;
	}
	else if (v < 3200) {
		return 7;
	}
	else return 8;
}
void ColorfulLeaderboard(){
	int n;
	cin >> n;
	int res = 0;
	for (size_t i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		int rate = thisRate(a);
		t[rate]++;
		
		if (rate != 8 && t[rate] == 1) {
			res++;
		}
	}

	int rate8 = t[8];
	if (res == 0) {
		cout << (rate8 > 0 ? 1 : 0) << " " << rate8 << endl;
	}
	else {
		cout << res << " " << (res + rate8) << endl;
	}
}

int main() {
	ColorfulLeaderboard();
	return 0;
}



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

using namespace std;

struct S{
	L x,ord;
}a[100010];
L n;

struct P{
	L val,num,mi;
};

L ans[100010];
L stair[100010],stop;
L stairval[100010];
L stairsum[100010];
L stairsum2[100010];

int main()
{
	scanf("%lld",&n);
	L i;
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&a[i].x);
		a[i].ord=i;
	}
	L ma=0;
	for(i=1;i<=n;i++)
	{
		if(a[i].x>ma)
		{
			ma=a[i].x;
			stair[++stop]=i;
			stairval[stop]=a[i].x;
		}
	}
	/*for(i=1;i<=stop;i++)
	{
		printf("%lld ",stairval[i]);
	}
	puts("");*/
	for(i=1;i<=n;i++)
	{
		L temp=upper_bound(stairval+1,stairval+stop+1,a[i].x)-stairval;
		stairsum[temp-1]++;
		stairsum2[temp]+=a[i].x-stairval[temp-1];
	}
	/*for(i=1;i<=stop;i++)
	{
		printf("%lld ",stairsum[i]);
	}
	puts("");*/
	for(i=stop;i>1;i--)
	{
		stairsum[i-1]+=stairsum[i];
	}
	for(i=1;i<=stop;i++)
	{
		ans[stair[i]]+=(stairval[i]-stairval[i-1])*stairsum[i]+stairsum2[i];
	}
	for(i=1;i<=n;i++)
	{
		printf("%lld ",ans[i]);
	}
}

Measured memory_bytes: 6528
#include <cstdio>
#include <cstring>
#define MAXN 200005
#define M 2019

using ll = long long;

char s[MAXN];
int cnt[M + 3];

int main() {
  ll res = 0;
  scanf("%s", s);
  int len = strlen(s), t = 0, p = 1;
  for (int i = len - 1; i >= 0; --i) {
    ++cnt[t];
    t += (s[i] - 48) * p;
    t %= M;
    res += cnt[t];
    p = p * 10 % M;
  }
  printf("%lld\n", res);
  return 0;
}


Measured memory_bytes: 1860
#include <stdio.h>

int days[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31};

int main(void)
{
	int month, day;
	int day_num, i;
	char week[8][10]= {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
	
	while (scanf("%d %d", &month, &day), month != 0){
		day_num = 0;
		
		day_num += day;
		for(i = 0; i < month-1; i++){
			day_num += days[i];
		}
		
		day_num = (day_num + 2) % 7;
		
		puts(week[day_num]);
		
	}
	return(0);
	
}

Measured memory_bytes: 584
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val N = rd.readInt()
    val P = IntArray(N)
    val idx = IntArray(N+1){0}
    for (i in 0 until N) {
        P[i] = rd.readInt()
        idx[P[i]] = i
    }

    var len = 1
    var ln = 1
    for (n in 1 .. N-1) {
        if (idx[n] < idx[n+1]) {
            ln++
            len = max(len, ln)
        } else {
            ln = 1
        }
    }

    val ans = N - len
    println(ans)
}


//val rd = debug.Reader("agc", "023", "b", "sample-2")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!!
    } catch (e: Exception) { throw e }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int); data class LongPair(val first: Long, val second: Long)
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


Measured memory_bytes: 52588
x = int(input())
ls = []
for i in range(-100000,100000):
  ls.append(i**5)
import bisect
for i in range(len(ls)):
  b = ls[i]
  ai = bisect.bisect_left(ls,x+b)
  if ai < len(ls) and ls[ai]-b == x:
    print(ai-100000,i-100000)
    break

Measured memory_bytes: 97888
import java.util.Scanner;
import java.util.Stack;
 
public class Main{
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        String st;
        char a,b='a';
        Stack<Character> sta = new Stack<Character>();
        int i,j;
        boolean ch =true;
        while(true){
            st = s.nextLine();
            if(st.equals("."))break;
            for(i=0;i<st.length();i++){
                if(ch==false)break;
                a = st.charAt(i);
                if(a=='(')sta.push(a);
                if(a=='[')sta.push(a);
                if((a==')'||a==']')&&sta.empty())ch=false;
                if((a==')'||a==']')&&sta.size()>0)b = sta.pop();
                if(a==')'&&b!='(')ch=false;
                if(a==']'&&b!='[')ch=false;
            }
            if(sta.size()>0)ch = false;
            if(ch==true)System.out.println("yes");
            else System.out.println("no");
            ch=true;
            while(sta.size()>0)sta.pop();
        }
    }
}



Measured memory_bytes: 46460
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    cout<<(s=="ABC"?"ARC":"ABC")<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

class UnionFind
{   
public:
    static const int N_MAX = 1000000;
    int par[N_MAX];
    int sz[N_MAX];
    int n;
    
    UnionFind(int n)
        : n{n}
    {
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            sz[i] = 1;
        }
    }
    
    void init()
    {
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            sz[i] = 1;
        }
    }

    int root(int x)
    {
        if (par[x] == x) {
            return x;
        }
        return par[x] = root(par[x]);
    }
    
    bool same(int x, int y)
    {
        return root(x) == root(y);
    }
    
    void unite(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) {
            return;
        }
        if (sz[rx] > sz[ry]) {
            par[ry] = rx;
            sz[rx] += sz[ry];
        } else {
            par[rx] = ry;
            sz[ry] += sz[rx];
        }
        return;
    }

    int size(int x)
    {
        return sz[root(x)];
    }
    
    int groups()
    {
        int cnt = 0;
        for (int i = 0; i < n; ++i) {
            if (root(i) == i)
            ++cnt;
        }
        return cnt;
    }
};


int main()
{
        ll N, M;
        cin >> N >> M;
        vll A(M), B(M);
        rep(i, 0, M) cin >> A[i] >> B[i];

        UnionFind uf(N);
        rep(i, 0, M) uf.unite(A[i], B[i]);

        ll ans = 1;
        rep(i, 0, M) chmax(ans, (ll)uf.size(i));

        cout << ans << endl;
}


Measured memory_bytes: 8008
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    int N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<int> l(N);
    rep(i, N) cin >> l[i];

    int minMP = 1e9;
    for(int bit = 0; bit < (1<<(2*N)); bit++){
        int MP = 0, la = 0, lb = 0, lc = 0;
        int cnta = 0, cntb = 0, cntc = 0;
        for(int i = 0; i < N; i++){
            if( ( ( bit>>(i*2) )&3 ) == 0 ){
                la += l[i];
                if(0 < cnta) MP += 10;
                cnta++;
            }
            if( ( ( bit>>(i*2) )&3 ) == 1 ){
                lb += l[i];
                if(0 < cntb) MP += 10;
                cntb++;
            }
            if( ( ( bit>>(i*2) )&3 ) == 2 ){
                lc += l[i];
                if(0 < cntc) MP += 10;
                cntc++;
            }
            if( ( ( bit>>(i*2) )&3 ) == 3 ){
            }

        }
        if(la == 0 || lb == 0 || lc == 0) continue;
        MP += abs(A - la) + abs(B - lb) + abs(C - lc);
        minMP = min(minMP, MP);
    }

    cout << minMP << endl;

    return 0;
}


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

long long mod=1e9+7;
long long INF=1e7;
double EPS = 1e-12;
const long long lim = 1e6+100;
typedef long long int lld;
typedef long long ll;
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define repD(i,a,n) for(long long int i = (a); i >= (n); i--)
#define mset(a, v) memset(a, v, sizeof(a))
#define Error(x...) { cout << "(" << #x << ")" << " = ( "; printIt(x); }
template <typename T1> void printIt(T1 t1) { cout << t1 << " )" << endl; }
template <typename T1, typename... T2>
void printIt(T1 t1, T2... t2) { cout << t1 << " , "; printIt(t2...); }
 
 
#define popcount __builtin_popcountll
 
ll powP(ll x, ll y) {
    ll ans = 1, po = x % mod;
    while(y > 0) {
        if(y & 1) ans = ans * po % mod;
        y >>= 1; po = po * po % mod;
    }
    return ans;
}

ll findGcd(ll a, ll b){
    while(a != 0) { ll temp = b % a; b = a; a = temp; }
    return b;
}

vector<ll> Adj[lim], Set, Query[lim];
ll Array[lim], BArray[lim], dp[lim];
pair<ll,ll> P[lim];

int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);

    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    
    lld T,i,p,j,l,e,r,b,c,k,m,q,a,d,w,x,y,u,v,z,t,curr,prev,sum=0,val,temp,countA=0,indicator=0,pos,h,minA,maxA,type,n,ans=0,left,right;
    string A,B,C;
    A = "Yes", B="No";
    // cin>>T;
    // rep(tt,1,T) {
    // }
    cin>>n>>k;
    rep(i,1,k) cin>>P[i].first>>P[i].second;
    Array[0]=0;Array[1]=1;
    mod = 998244353;
    rep(i,2,n) {
        Array[i]=0;
        rep(j,1,k) {
            l = i-P[j].second;
            r = i-P[j].first;

            if(l<1 and r<1) Array[i]+=0;
            else if(l<1) Array[i]+=Array[r];
            else Array[i]+=(Array[r]-Array[l-1]+mod)%mod;
        }

        // Error(i,Array[i]);

        Array[i]=(Array[i]+Array[i-1])%mod;
    }

    cout<<(Array[n]-Array[n-1]+mod)%mod<<endl;

    return 0;
}


Measured memory_bytes: 52092
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <bitset>
#include <functional>
#include <queue>
#include <utility>
#include <map>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;
const int INF = 1 << 29;	// 十分大きい値にする, INT_MAX にしないのはオーバーフロー対策

void solve()
{
	int A, P;
	cin >> A >> P;

	cout << (A * 3 + P) / 2 << endl;
}

int main(void)
{
	solve();

	return 0;
}


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

#define INF 2222147483647

struct data{
	long long from;
	long long to;
	long long val;
};

struct point{
	vector<long long> to;
	vector<long long> val;
};

void init(point p[],data a[],long long w[],long long n){
	for(long long i=1;i<=n;i++){
		w[i] = -INF;
		p[i].to.clear();
		p[i].val.clear();
		a[i].from = a[i].to = a[i].val = 0;
	}
}

void search(point p[],long long x,point tmp[],bool order,bool vis[]){
	vis[x] = true;
	for(long long i=0;i<p[x].to.size();i++){
		if(order){
			tmp[x].to.push_back(p[x].to[i]);
			tmp[x].val.push_back(p[x].val[i]);
		}
		else{
			tmp[p[x].to[i]].to.push_back(x);
			tmp[p[x].to[i]].val.push_back(p[x].val[i]);
		}
		if(vis[p[x].to[i]] == false)
			search(p,p[x].to[i],tmp,order,vis);
	}
}

void make_edge(point p[],data a[],long long x,long long &index,bool vis[]){
	vis[x] = true;
	for(long long i=0;i<p[x].to.size();i++){
		index++;
		a[index].from = x;
		a[index].to = p[x].to[i];
		a[index].val = p[x].val[i];
		if(vis[p[x].to[i]] == false)
			make_edge(p,a,p[x].to[i],index,vis);
	}
	
}

main(){
	long long n,m,k,index,ifrom,ito,ival;
	long long w[2510];
	bool b,vis[2510];
	data a[5010];
	point p[2510],tmp[2510];
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cin>>n>>m>>k;
	for(long long i=1;i<=m;i++){
		cin>>ifrom>>ito>>ival;
		p[ito].to.push_back(ifrom);
		p[ito].val.push_back(ival);
	}
	
	index = 0;
	memset(vis,0,sizeof(vis));
	search(p,n,tmp,0,vis);
	init(p,a,w,n);
	memset(vis,0,sizeof(vis));
	search(tmp,1,p,1,vis);
	memset(vis,0,sizeof(vis));
	make_edge(p,a,1,index,vis);
	
	/*
	cout<<index<<endl;
	for(long long i=1;i<=index;i++){
		cout<<a[i].from<<" "<<a[i].to<<" "<<a[i].val<<endl;
	}
	*/
	
	w[1] = 0;
		
	for(long long i=1;i<=n+1;i++){
		b = false;
		for(long long j=1;j<=index;j++){
			if(w[a[j].to] < w[a[j].from] + a[j].val - k){
				b = true;
				w[a[j].to] = w[a[j].from] + a[j].val - k;
			}
		}
		if(b == false)
			break;
	}
	if(b)			cout<<-1;
	else if(w[n]<0)	cout<<0;
	else			cout<<w[n];
	
}
/*
2 2 10
1 2 100
2 1 100
*/


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

int main(){
  int N,M,C;
  cin >> N >> M >> C;
  
  vector<int> B(M);
  for(int i=0; i<M; i++){
    cin >> B.at(i);
  }
  
  int ans = 0;
  vector<int> A(M);
  int i=0;
  while(i<N){
    for(int j=0; j<M; j++){
      cin >> A.at(j);
    }
    int sum = 0;
    for(int j=0; j<M; j++){
      sum += A.at(j)*B.at(j);
    }
    sum += C;
    if(sum>0){
      ans++;
    }
    i++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys

N, M = map(int, sys.stdin.readline().rstrip().split())
edges = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, sys.stdin.readline().rstrip().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

# N, Mが十分小さいため、全探索
ans = 0
visited = set()
def dfs(s, count):
    global ans;
    # print(s, visited)
    if count == N:
       ans += 1
       return
    visited.add(s)
    for e in edges[s]:
        if e not in visited:
            dfs(e, count+1)
    visited.remove(s)

dfs(0, 1)
print(ans)

Measured memory_bytes: 41436
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
using namespace std;
using ll = long long;
using pii = pair<int,int>;
template<typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a){
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os, vector<T> v){
    for(auto x:v)os << x << ' ';
    return os;
}
void debug(){cerr << '\n';}
template<typename H, typename... T>
void debug(H a, T... b){
    cerr << a;
    if(sizeof...(b))cerr << ", ";
    debug(b...);
}
ll f(ll b, ll n){
    show(b);
    ll ans = 0;
    while(n){
        ans += n % b;
        n /= b;
    }
    return ans;
}
int main(){
    ll n , s;
    cin >> n >> s;
    bool flag = false;
    if(s == n){
        cout << n + 1 << endl;
        return 0;
    }
    for(ll i = 2; i * i <= n; i++){
        if(f(i, n) == s){
            cout << i << endl;
            return 0;
        }
    }
    ll ans = 1LL<<60;
    for(ll i = 1; i * i <= n; i++){
        ll j = s - i;
        ll b = (n - j) / i;
        if(b < 2)continue;
        if(f(b,n) == s){
            flag = true;
            ans = min(ans, b);
        }
    }
    if(!flag){
        cout << - 1<< endl;
    }else{
        cout << ans << endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <string>

using namespace std;

class DICE {
public:
	int top;
	int bottom;
	int right;
	int left;
	int front;
	int back;
	void South();
	void North();
	void East();
	void West();
	void RF();
	void LF();
	bool HANTEI(DICE d2);
};

void DICE::South() {
	int kari = front;
	front = top;
	top = back;
	back = bottom;
	bottom = kari;
}

void DICE::North() {
	int kari = front;
	front = bottom;
	bottom = back;
	back = top;
	top = kari;
}

void DICE::West() {
	int kari = top;
	top = left;
	left = bottom;
	bottom = right;
	right = kari;
}

void DICE::East() {
	int kari = top;
	top = right;
	right = bottom;
	bottom = left;
	left = kari;
}

void DICE::RF() {
	int kari = right;
	right = back;
	back = left;
	left = front;
	front = kari;
}

void DICE::LF() {
	int kari = left;
	left = back;
	back = right;
	right = front;
	front = kari;
}

bool DICE::HANTEI(DICE d2) {
	bool hantei = false;
	if ((top == d2.top)&&(bottom == d2.bottom)&&(front == d2.front)&&(back == d2.back)&&(right == d2.right)&&(left == d2.left)) {
		hantei = true;
	}
	return hantei;
}

int main() {
	DICE d, d2;
	cin >> d.top >> d.front >> d.left >> d.right >> d.back >> d.bottom;
	cin >> d2.top >> d2.front >> d2.left >> d2.right >> d2.back >> d2.bottom;
	bool hantei = false;
	if (d2.top != d.top) {
		d2.South();
	} else {
		for (int i = 0; i < 4; i++) {
			d2.RF();
			hantei = hantei || d.HANTEI(d2);
		}
		if (!hantei) {
			d2.South();
		}
	}
	if (!hantei) {
		if (d2.top != d.top) {
			d2.South();
		} else {
			for (int i = 0; i < 4; i++) {
				d2.RF();
				hantei = hantei || d.HANTEI(d2);
			}
			if (!hantei) {
				d2.South();
			}
		}
	}
	if (!hantei) {
		if (d2.top != d.top) {
			d2.South();
		} else {
			for (int i = 0; i < 4; i++) {
				d2.RF();
				hantei = hantei || d.HANTEI(d2);
			}
			if (!hantei) {
				d2.South();
			}
		}
	}
	if (!hantei) {
		if (d2.top != d.top) {
			d2.East();
		} else {
			for (int i = 0; i < 4; i++) {
				d2.RF();
				hantei = hantei || d.HANTEI(d2);
			}
			if (!hantei) {
				d2.East();
			}
		}
	}
	if (!hantei) {
		if (d2.top != d.top) {
			d2.East();
			d2.East();
		} else {
			for (int i = 0; i < 4; i++) {
				d2.RF();
				hantei = hantei || d.HANTEI(d2);
			}
			if (!hantei) {
				d2.East();
				d2.East();
			}
		}
	}
	if (!hantei) {
		for (int i = 0; i < 4; i++) {
			d2.RF();
			hantei = hantei || d.HANTEI(d2);
		}
	}
	if (hantei) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n,s,t,u;
    cin >> n >> s >> t;
    vector<P> ans;
    cout << "? " << s << " " << t << "\n";
    cout.flush();
    cin >> u;
    ans.push_back(P(0,s));
    ans.push_back(P(u,t));
    for (int i = 1;i < n+1;++i) {
        if (i == s || i == t) continue;
        int x,y;
        cout << "? " << s << " " << i << "\n";
        cout.flush();
        cin >> x;
        cout << "? " << t << " " << i << "\n";
        cout.flush();
        cin >> y;
        if (x+y == u) ans.push_back(P(x,i));
    }
    sort(ans.begin(),ans.end());
    int m = ans.size();
    cout << "! ";
    for (int i = 0;i < m;++i) cout << ans[i].second << " \n"[i == m-1];
    cout << endl;
    cout.flush();
    return 0;
}


Measured memory_bytes: 4684
#include<stdio.h>
#include<vector>
#include<iostream>
using namespace std;
int main()
{
	int x,y,u,v;
	vector<char> ans;
	scanf("%d %d %d %d",&x,&y,&u,&v);
	int i=x;
	int j=y;
	while(j<v)
	{
		ans.push_back('U');
		j++;
	}
	while(i<u)
	{
		ans.push_back('R');
		i++;
	}
	int sz=ans.size();
//	for(int k=0;k<sz;k++)
//	{
//		printf("%c",ans[k]);
//	}
//	printf("\n");
	for(int k=0;k<sz;k++)
	{
//		printf("%c\n",ans[k]);
		if(ans[k]=='U')
		ans.push_back('D');
		if(ans[k]=='R')
		ans.push_back('L');
	}
//	sz=ans.size();
//	for(int k=0;k<sz;k++)
//	{
//		printf("%c",ans[k]);
//	}
//	printf("\n");
	ans.push_back('L');
	i=x;
	j=y;
	v++;
	u++;
	while(j<v)
	{
		ans.push_back('U');
		j++;
	}
	while(i<u)
	{
		ans.push_back('R');
		i++;
	}
	ans.push_back('D');
	ans.push_back('R');
	i=u-1;
	j=v-1;
	x--;
	y--;
	while(j>y)
	{
		ans.push_back('D');
		j--;
	}
	while(i>x)
	{
		ans.push_back('L');
		i--;
	}
	ans.push_back('U');
	sz=ans.size();
	for(int k=0;k<sz;k++)
	{
		printf("%c",ans[k]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 256