akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }

        int ans = a[0];
        for (int i = 1; i < n; i++) {
            ans = gcd(ans, a[i]);
        }

        System.out.println(ans);


    }

    private static int gcd(int a, int b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
using LL = long long;
using ULL = unsigned long long;


void solve() {
	int n; cin >> n;
	pair<char, int> cards[36];
	rep(i, n) {
		cin >> cards[i].first >> cards[i].second;
	}

	pair<char, int> s[36]; rep(i, n) s[i] = cards[i];
	pair<char, int> ns[36]; rep(i, n) ns[i] = cards[i];

	{
		int swaps = 0;
		for (int i = 0; i < n; i++) {
			for (int j = n - 1; j > i; j--) {
				if (s[j].second < s[j - 1].second) swap(s[j], s[j - 1]);
			}
		}

		bool stable = true;
		rep(i, n) {
			if (i != 0) cout << " ";
			cout << s[i].first << s[i].second;
			if (s[i].first != cards[i].first) stable = false;
		} cout << endl;

		cout << "Stable" << endl;
	}
	{
		for (int i = 0; i < n; i++) {
			int mIdx = i;
			for (int j = i; j < n; j++) {
				if (ns[j].second < ns[mIdx].second) mIdx = j;
			}
			swap(ns[i], ns[mIdx]);
		}
		bool stable = true;
		rep(i, n) {
			if (i != 0) cout << " ";
			cout << ns[i].first << ns[i].second;
			if (ns[i].first != s[i].first) stable = false;
		} cout << endl;

		cout << (stable ? "Stable" : "Not stable") << endl;
	}
}

int main() {

	solve();

	return 0;
}



Measured memory_bytes: 3080
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <string>
#include <iostream>
#include <complex>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <stack>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <set>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <array>
#include <forward_list>
#include <iomanip>
#include <utility>

#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int n, k;

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#else
	//freopen("river.in", "r", stdin);
	//freopen("river.out", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> k;
	if (n % k == 0)
		cout << 0;
	else
		cout << 1;
	return 0;
}

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

using namespace std;

const int inf = 1e9;
const int maxi = 1e3+10;

int dx[2] ={0, 1};
int dy[2] = {1, 0};
int a[maxi][maxi];
int d[maxi][maxi];
int ob[maxi][maxi];
int n, m;

int inside(int x, int y)
{
    return (x>0 && x<=n && y>0 && y<=m);
}

void bfs(int x, int y)
{
    for (int i =1;i<=n;i++)
        for (int j=1;j<=m;j++)
        d[i][j] = inf;
    d[x][y] = 0;

    deque<pair<int,int>> q;

    q.push_front({x,y});

    while(!q.empty())
    {
        pair<int,int> node = q.front();
        q.pop_front();
        int xi = node.first;
        int yi = node.second;

        if (ob[xi][yi]) continue;

        ob[xi][yi] = 1;

        for (int i = 0; i<2;i++)
            if (inside(xi + dx[i], yi + dy[i]) && d[xi + dx[i]][yi + dy[i]] > d[xi][yi] + abs(a[xi][yi] - a[xi + dx[i]][yi + dy[i]]))
            {
                d[xi + dx[i]][yi + dy[i]] = d[xi][yi] + abs(a[xi][yi] - a[xi + dx[i]][yi + dy[i]]);
                if (abs(a[xi][yi] - a[xi + dx[i]][yi + dy[i]]))
                q.push_back({xi + dx[i], yi + dy[i]}); else
                q.push_front({xi + dx[i], yi + dy[i]});
            }
    }
}
int main()
{
    cin>>n>>m;

    for (int i=1;i<=n;i++)
    {
        string s;
        cin>>s;

        for (int j= 0;j<m;j++)
            if (s[j]=='#') a[i][j+1]=1;
    }

    bfs(1, 1);


    if (a[1][1]) d[n][m]++;
   int ans = (d[n][m] + 1)/ 2;
   cout<<ans<<endl;
}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);	
	ll n, sum = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		if (i % 3 == 0 || i % 5 == 0) continue;
		else sum += i;
	}
	cout << sum << "\n";
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;

int sum(int l, int r){
	return (l+r)*(r-l+1)/2;
}

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;

	int ans = 0;

	for(int i=k;i<=n+1;i++){
		int l = sum(0,i-1);
		int r = sum(n-i+1,n);
		ans += r - l + 1;
	}

	ans = ans % MOD;

	cout << ans << endl;

}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    string s;
    cin >> s;
    int ans = 0;
    rep(i,s.size()/2){
        if(s[i] != s[s.size() - 1- i])ans++;
    }

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	string n;
	cin>> n;
	string X ="abcdefghijklmnopqrstuvwxyz";
	vector<int>Y(26);
	for(int i=0;i<26;i++){
		for(int j=0;j<n.size();j++){
			if (X[i]==n[j]){
				Y[i]++;
			}
		}
		
	}
	int Z =0;
	for(int i=0;i<26;i++){
		if(Y[i]%2==1){
			Z=1;
		}
		
	}
	if(Z==0){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	
	

}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vl = vector<ll>; using vvl = vector<vl>;
using vp = vector<pair<int,int>>;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
const ll INF = 9223372036854775807;

int main() {
    int n,m;cin >> n >> m;
    vector<pair<int,string>> in(m);
    vector<bool> TF(n+1,false);
    rep(i,m){
        int a;string s;
        cin >> a >> s;
        pair<int,string> p;
        p.first = a;
        p.second = s;
        in[i]=p;
    }
    int wa = 0;
    int ac = 0;
    vector<int> numwa(n+1,0);
    rep(i,m){
        if(TF[in[i].first]) continue;
        if(in[i].second == "WA") numwa[in[i].first]++;
        if(in[i].second == "AC") {
            ac++;
            TF[in[i].first] = true;
            wa += numwa[in[i].first];
        }
    }
    cout << ac << " " << wa << endl;
}

Measured memory_bytes: 7464
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>

#define ABS(x) ( (x)>0 ? x : -(x) )
#define MIN(x,y) ( (x) < (y) ? (x) : (y) )
#define MAX(x,y) ( (x) > (y) ? (x) : (y) )

#define INF 1000000000

void swap(int* x, int *y)
{
	int t;

	t = *x;
	*x = *y;
	*y = t;
}

int binary_search(int p[], int n, int key)
{
	int left, right, middle;

	left = 0;
	right = n-1;


	while (left <= right)
	{
		middle = (left + right) / 2;

		if (p[middle] == key)
			return middle;
		else if (p[middle] > key)
		{
			right = middle - 1;
		}
		else if (p[middle] < key)
		{
			left = middle + 1;
		}
	}

	return -1;

}

void bubble_sort(int p[], int n)
{
	int i, j;

	for (i = 0; i < n-1; i++)
	{
		for (j = 0; j < n - i - 1; j++)
		{
			if (p[j] > p[j + 1])
				swap(&p[i], &p[i + 1]);
		}
	}
}

int main()
{
	int H[10000], W[10000];
	int i, j,k,count = 0;

	for (i = 0;; i++)
	{
		scanf("%d%d", &H[i], &W[i]);

		if (H[i] == 0 && W[i] == 0)
			break;

		count++;
	}

	for (i = 0; i < count; i++)
	{
		for (j = 0; j < H[i]; j++)
		{
			for (k = 0; k < W[i]; k++)
			{
				if ((j+k)%2==0)
					printf("#");
				else
					printf(".");
			}

			printf("\n");
		}
		printf("\n");
	}
}


Measured memory_bytes: 2060
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb emplace_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define vll vector<ll>
#define fast ios:: sync_with_stdio(false),cin.tie(0);
#define COUT cout<<fixed<<setprecision(9)
#define SET set<ll,greater<ll>>gquiz
#define ITERATOR set<ll,greater<ll>> :: iterator itr
#define V vector<ll>vector
#define sz size()
#define A vector<pair<ll,ll>>vect
ll N=100000,M=100000;
#define B vect.push_back(make_pair(N,M));
 
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 
ll pow1(ll n,ll k,ll mm){
    if(k==0)return 1;
    if(k%2==0)return (pow1((n%mm)*(n%mm),k/2,mm))%mm;
    return ((n%mm)*(pow1((n%mm)*(n%mm),k/2,mm)%mm))%mm;
}
ll pow2(ll n,ll k){ll ans=1;
	while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;
}
ll ncr(ll n,ll r){if(n==1 || r==0)return 1;if(r>n/2)r=n-r;
	ll ans=1;for(ll i=1;i<=r;i++){ans=((ans * n )/i);n--;}return ans;
}
ll ncrsum(ll n,ll r, ll mod){
	if(n==1 || r==0)return 1;
	ll ans=1,sum=1;for(ll i=1;i<=r;i++){ans=(((ans * n )/i)%mod);n--;sum+=ans;sum%=mod;}return sum;
}
bool isprime(ll n){if(n==1 || (n!=2 && n%2==0))return false; if(n==2)return true; 
		for(ll i=3;i<=sqrt(n);i+=2)if(n%i==0)return false; return true; }
		
vll factor(ll n){
	vll ans;
	if(n>0)ans.pb(1);if(n==2)ans.pb(2);
	for(ll i=2;i*i<=n;i++){if(n%i==0){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}if(n>2)ans.pb(n);
	return ans;
}
ll numoffactor(ll n){ return factor(n).sz;}
ll gcd(ll a,ll b) 
{ 
	if (a == 0) 
		return b; 
	return gcd(b%a, a); 
} 
 
int main()
{
	ll n,m,k;
	cin>>n;
	ll a[n+1];
	for(ll i=0;i<n;i++)
	cin>>a[i];
	
	ll dp[n+1];
	dp[0]=1;
	k=a[0];
	for(ll i=1;i<n;i++)
	{
		if(a[i]<a[i-1] && a[i]<k)
		{
		   dp[i]=1;
		   k=a[i];
		}
		else
		dp[i]=0;
	}
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
		//cout<<dp[i]<<" ";
		if(dp[i]==1)
		ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 3328
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr ll INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld PI = acos(-1);
constexpr ld EPS = 1e-11;

int main(void){
	ll n;
	cin >> n;
	ld d = (ld)n / 3;

	ld ans = pow(d, 3);
	setp(10);
	co(ans);

	return 0;
}


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


/* macro */
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define sec second
#define fir first
#define pb push_back



/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
const int inf = pow(2, 62);
const int mod = 1e9 + 7;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};



/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
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; }




/* main */



signed main(){

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

    int n = input();

    if(n == 7 or n == 5 or n == 3){
        print("YES");
    }else{
        print("NO");
    }


    




    
    
    
    
    








    

    
    




    
    



    
    

    







   




    

    

    




    



    



    

 
    
    


    

    
   
    













}






    










    




    










Measured memory_bytes: 256
def dev(n):
    return int(n / 2)

N = int(input())
li = list(map(int, input().split()))
flag = True
an = 0
while True:
 for i in range(N):
    if li[i] % 2 != 0:
      flag = False
 if flag:
  li = list(map(dev, li))
  an += 1
 else:
     break
print(an)

Measured memory_bytes: 9116
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<P>> Graph;


int main(){

  string s;
  cin >> s;
  
  int ans = (s.size()-1)/2;
  while(1){
    bool f = true;
    REP(i,ans){
      if(s[i] != s[i+ans]){
        f = false; break;
      }
    }
    if(f) break;
    ans--;
  }

  cout << ans*2 << endl;

 return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
H = tuple(map(int,input().split()))

dp = [0]

for i in range(1,N):
  h = H[i]
  dp.append(min(dp[j]+abs(H[j]-h) for j in range(max(i-K,0),i)))

print(dp[-1])


Measured memory_bytes: 62176
/*{{{*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
char s[SIZE];
int main(){
    int n;
    R(n);
    RS(s);
    REP(i,n-1)s[i]=abs(s[i]-s[i+1]);
    n--;
    if(n==1)W((int)s[0]);
    else{
        int ret=0;
        FOR(i,0,n-1){
            if((i&(n-1))==i)ret^=s[i]&1;
        }
        if(ret)W(ret);
        else{
            if(count(s,s+n,1))W(0);
            else{
                ret=0;
                FOR(i,0,n-1){
                    if((i&(n-1))==i)ret^=s[i]&2;
                }
                W(ret);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define fi first
#define se second
#define pt(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll N;
ll mem[404][404]={};
ll a[MAX];

ll rec(ll l, ll r) {
    if(r-l==1) return 0;
    if(mem[l][r]!=-1) return mem[l][r];
    
    ll res=INF;
    ll sum=0;
    
    for(ll i=l; i<r; i++) sum+=a[i];
    
    for(ll mid=l+1; mid<r; mid++) {
        res=min(res, rec(l, mid)+rec(mid, r)+sum);
    }
    
    return mem[l][r]=res;
}

int main(void) {
    cin >> N;
    ll i;
    
    for(i=0; i<N; i++) cin >> a[i];
    
    memset(mem, -1, sizeof(mem));
    pt(rec(0, N));
    
}



Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std ; 
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int 
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second


int main(){
    fast;
    int n; cin >> n;
    vector <int> a(n);
    sort(all(a));
    cin >> a[0];
    int val =a[0];
    for(int i=1 ; i<n ; i++){
        cin >> a[i];
        val = __gcd(val,a[i]);
    }
    cout << val << endl;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        boolean[][] b = new boolean[n][m];
        for(int i=0; i<n; i++) {
            char[] line = sc.next().toCharArray();
            for(int j=0; j<m; j++) {
                b[i][j] = line[j] == '#';
            }
        }

        int row[][] = new int[n][m];
        int col[][] = new int[n][m];

        for(int i=0; i<n; i++) {
            for(int j=0; j<m; j++) {
                if(j==0) {
                    if(!b[i][j]) {
                        row[i][0] = 1;
                    }
                    continue;
                }
                if(b[i][j]) {
                    continue;
                }
                row[i][j] = row[i][j-1]+1;
            }
            for(int j=m-2; j>=0; j--) {
                if(row[i][j] > 0 && row[i][j+1] > 0) {
                    row[i][j] = row[i][j+1];
                }
            }
        }
        for(int j=0; j<m; j++) {
            for(int i=0; i<n; i++) {
                if(i==0) {
                    if(!b[i][j]) {
                        col[0][j] = 1;
                    }
                    continue;
                }
                if(b[i][j]) {
                    continue;
                }
                col[i][j] = col[i-1][j]+1;
            }
            for(int i=n-2; i>=0; i--) {
                if(col[i][j] > 0 && col[i+1][j] > 0) {
                    col[i][j] = col[i+1][j];
                }
            }
        }


        int res = 0;
        for(int j=0; j<m; j++) {
            for (int i = 0; i < n; i++) {
                res = Math.max(res, row[i][j]+col[i][j]-1);
            }
        }

        System.out.println(res);


    }

}


Measured memory_bytes: 67940
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define inf 1e10
#define mod 1000000007
#define mii map<int,int>
#define pii pair<int,int>
#define setbits(x) __builtin_popcountll(x)
#define lcm(x,y)  (x*y)/__gcd(x,y)

int fact(int k)
{
	if (k == 0 || k == 1)
		return 1;
	else
		return k * fact(k - 1);
}
bool checkfact(int k)
{
	int temp = k;
	int sum = 0;
	while (k != 0)
	{
		sum += fact(k % 10);
		k /= 10;
	}
	if (sum == temp)
		return 1;
	else
		return 0;
}
int32_t main()
{
//	c_p_c();


	int k, a, b;
	cin >> k >> a >> b;
	int i;
	for (i = a; i <= b; i++)
	{
		if (i % k == 0)
		{
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;


}

Measured memory_bytes: 3608
H, W = map(int, input().split())
S = [None] * H
for i in range(H):
    S[i] = input()

up = [[0 for w in range(W)] for h in range(H)]
down = [[0 for w in range(W)] for h in range(H)]
left = [[0 for w in range(W)] for h in range(H)]
right = [[0 for w in range(W)] for h in range(H)]

# up and left
for h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            up[h][w] = 0
            left[h][w] = 0
        else:
            # up
            if h == 0:
                up[h][w] = 1
            else:
                up[h][w] = up[h - 1][w] + 1
            # left
            if w == 0:
                left[h][w] = 1
            else:
                left[h][w] = left[h][w - 1] + 1

# down and right
for h in reversed(range(H)):
    for w in reversed(range(W)):
        if S[h][w] == "#":
            down[h][w] = 0
            right[h][w] = 0
        else:
            # down
            if h == H - 1:
                down[h][w] = 1
            else:
                down[h][w] = down[h + 1][w] + 1
            # right
            if w == W - 1:
                right[h][w] = 1
            else:
                right[h][w] = right[h][w + 1] + 1


ans = 0
for h in range(H):
    for w in range(W):
        masu = -3
        masu += up[h][w]
        masu += down[h][w]
        masu += left[h][w]
        masu += right[h][w]
        if masu > ans:
            ans = masu

print(ans)


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

struct UnionFind {
    int n, cnt;
    vector<int> par, rank, sz;

    UnionFind(int n) : n(n), cnt(n), par(n), rank(n), sz(n, 1) { iota(par.begin(), par.end(), 0); }

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

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

    int size(int x) { return sz[find(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;
            sz[y] += sz[x];
        } else {
            par[y] = x;
            sz[x] += sz[y];
            if (rank[x] == rank[y]) {
                rank[x]++;
            }
        }
        cnt--;
    }
};

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

    int n, m, k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    vector<vector<int>> block(n);
    vector<vector<int>> fr(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf.unite(a, b);
        fr[a].push_back(b);
        fr[b].push_back(a);
    }

    for (int i = 0; i < k; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        block[a].push_back(b);
        block[b].push_back(a);
    }

    long long ans = 0;
    map<int, int> cnt;
    for (int i = 0; i < n; i++) {
        cnt[uf.find(i)]++;
    }
    for (int i = 0; i < n; i++) {
        int ans = cnt[uf.find(i)] - 1;
        for (int a : fr[i]) {
            ans--;
        }
        for (int a : block[i]) {
            if (uf.same(i, a)) ans--;
        }
        cout << ans << ' ';
    }
}


Measured memory_bytes: 13568
#[allow(dead_code)]
fn getline() -> String {
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

#[allow(unused_macros)]
macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

#[allow(unused_macros)]
macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

#[allow(unused_macros)]
macro_rules! debug { ($x: expr) => { println!("{}: {:?}", stringify!($x), $x) } }
// macro_rules! debug { ($x: expr) => () }

#[allow(dead_code)]
fn show<T>(iter: T) -> String
where
    T: Iterator,
    T::Item: std::fmt::Display
{
    let mut res = iter.fold(String::new(), |sum, e| sum + &format!("{} ", e));
    res.pop();
    res
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::collections::btree_map::Entry::{Occupied, Vacant};

fn main() {
    use std::io::Write;
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    macro_rules! printf { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); }
    macro_rules! printfln { () => (writeln!(out).unwrap()); ($($arg:tt)*) => (writeln!(out, $($arg)*).unwrap()); }
    
    let n = readl!(usize);
    let (a, b): (Vec<_>, Vec<_>) = (0..n).map(|_| readl!(i64, i64)).into_iter().unzip();

    if a == b {
        printfln!("0");
        return;
    }
    let sum: i64 = a.iter().cloned().sum();

    let ma = a.iter().cloned().zip(b.iter().cloned())
        .filter(|&(x, y)| x > y)
        .map(|(_, y)| y)
        .min().unwrap();
    printfln!("{}", sum-ma);
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
using namespace std;

int main(){
    string S;
    cin >> S;
    int N = S.size();

    long long res = 0;
    for(int bit=0; bit<(1<<(N-1)); bit++){
        long long temp = 0;
        for(int i=0; i<(N-1); i++){
            temp *= 10;
            temp += S[i]-'0';
            if(bit & (1<<i)) res += temp, temp = 0;
        }
        temp *= 10;
        temp += S.back()-'0';
        res += temp;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
long double pi = 2 * acos(0.0);
const ll mod = 998244353;

void solve() {
    ll a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    if(a == 0) cout << "1";
    else if(b == 0) cout << "2";
    else if(c == 0) cout << "3";
    else if(d == 0) cout << "4";
    else cout << "5";    
}

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(nullptr);   
    ll t = 1;   
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

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

int main()
{
    int N, K;
    cin >> N >> K;

    vector<bool> sunuke(N);
    for (int i = 0; i < N; i++) sunuke[i] = true;

    int d, a;
    for (int i = 0; i < K; i++) {   
        cin >> d;
        for (int j = 0; j < d; j++) {
            cin >> a;
            sunuke[a-1] = false;
        }
    }

    int zannnen_na_sunuke = 0;
    for (int i = 0; i < N; i++) if (sunuke[i]) zannnen_na_sunuke++;

    cout << zannnen_na_sunuke;

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
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 ll INF = 1e9;
const ll MOD = 1e9 + 7;


int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(a!=c) cout << 1 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int N, T;
	cin >> N >> T;
	vector<pair<int, int>> AB(N);
	for (auto i = 0; i < N; ++i)
	{
		int A, B;
		cin >> A >> B;
		AB[i] = { A, B };
	}

	sort(AB.begin(), AB.end());

	vector<vector<int>> dp(N + 1, vector<int>(T + 3001));
	for (auto i = 0; i < N; ++i)
	{
		auto p = AB[i];
		for (auto j = 0; j < dp[i].size(); ++j)
		{
			dp[i + 1][j] = dp[i][j];
			if (j >= p.first && j - p.first < T)
			{
				dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - p.first] + p.second);
			}
		}
	}

	auto result = 0;
	for (auto i = 0; i < dp[N].size(); ++i)
	{
		result = max(result, dp[N][i]);
	}

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 70784
import java.util.Scanner;
import java.lang.Math;
import java.math.BigDecimal;

class Main{

    public static void main(String[] args){

        Scanner scanner = new Scanner(System.in);
        int r = scanner.nextInt();
        scanner.close();
        BigDecimal bd1 = new BigDecimal(2.0 * r);
        BigDecimal bd2 = new BigDecimal(Math.PI);
        BigDecimal result = bd1.multiply(bd2);
        System.out.println(result.setScale(2, BigDecimal.ROUND_HALF_UP));

    }

}

Measured memory_bytes: 27348
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;

int main(){
	string str;

	map<string,string> encode;
	map<string,string> decode;

	encode[" "] = "101";
	encode["'"] = "000000";
	encode[","] = "000011";
	encode["-"] = "10010001";
	encode["."] = "010001";

	encode["?"] = "000001";
	encode["A"] = "100101";
	encode["B"] = "10011010";
	encode["C"] = "0101";
	encode["D"] = "0001";
	encode["E"] = "110";
	encode["F"] = "01001";
	encode["G"] = "10011011";

	encode["H"] = "010000";
	encode["I"] = "0111";
	encode["J"] = "10011000";
	encode["K"] = "0110";
	encode["L"] = "00100";
	encode["M"] = "10011001";
	encode["N"] = "10011110";

	encode["O"] = "00101";
	encode["P"] = "111";
	encode["Q"] = "10011111";
	encode["R"] = "1000";
	encode["S"] = "00110";
	encode["T"] = "00111";
	encode["U"] = "10011100";

	encode["V"] = "10011101";
	encode["W"] = "000010";
	encode["X"] = "10010010";
	encode["Y"] = "10010011";
	encode["Z"] = "10010000";

	decode["00000"] = "A";
	decode["00001"] = "B";
	decode["00010"] = "C";
	decode["00011"] = "D";
	decode["00100"] = "E";
	decode["00101"] = "F";
	decode["00110"] = "G";

	decode["00111"] = "H";
	decode["01000"] = "I";
	decode["01001"] = "J";
	decode["01010"] = "K";
	decode["01011"] = "L";
	decode["01100"] = "M";
	decode["01101"] = "N";

	decode["01110"] = "O";
	decode["01111"] = "P";
	decode["10000"] = "Q";
	decode["10001"] = "R";
	decode["10010"] = "S";
	decode["10011"] = "T";
	decode["10100"] = "U";

	decode["10101"] = "V";
	decode["10110"] = "W";
	decode["10111"] = "X";
	decode["11000"] = "Y";
	decode["11001"] = "Z";

	decode["11010"] = " ";
	decode["11011"] = ".";
	decode["11100"] = ",";
	decode["11101"] = "-";
	decode["11110"] = "'";
	decode["11111"] = "?";

	while(getline(cin,str)){

		string enc="";
		for(int i=0;i<str.size();i++){
			enc+=encode[str.substr(i,1)];
		}

		enc+="0000";

		string dec="";
		for(int i=0;i+5<=enc.size();i+=5){
			dec+=decode[enc.substr(i,5)];
		}

		cout << dec << endl;
	}

}

Measured memory_bytes: 1212
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <string>
using namespace std;

int main(void){
    char n[5];
    cin >> n;
    for (int i = 0; i <=2; i++) {
        if (n[i] == '9') n[i] = '1';
        else if (n[i] == '1') n[i] = '9';
    }
    
    cout << n[0] << n[1] << n[2];
    
    
    return 0;
}


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

using namespace std;

const string R[10] = { ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };

int main()
{
	int n; scanf("%d", &n);

	for (int i = 0; i < n; i++)
	{
		string S; cin >> S;

		int count_ = 0;

		for (int i = 0; i < S.size(); i++)
		{
			if (S[i] == '0')
			{
				if (count_ != 0)
				{
					cout << R[S[i - 1] - 49][(count_ - 1) % R[S[i - 1] - 49].size()]; count_ = 0;
				}
			}
			else
			{
				count_++;
			}
		}

		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3208
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int n,m,R;

int main(){
    cin >> n >> m >> R;
    vector<int> r(R);
    REP(i,R){
        cin >> r[i];
        r[i]--;
    }
    vector<vector<int>> e(n,vector<int>(n,1e8));//infで初期化
    vector<int> a(m);
    vector<int> b(m);
    vector<int> c(m);
    REP(i,m){
        cin >> a[i] >> b[i] >> c[i];
        --a[i];
        --b[i];
        e[a[i]][b[i]] = c[i];
        e[b[i]][a[i]] = c[i];//無向グラフ
    }
    REP(i,n){
        e[i][i]=0;
    }
    
    vector<vector<int>> next(n,vector<int>(n,0));//頂点の遷移情報を記録
    REP(i,n){
        REP(j,n){
            next[i][j] = j;
        }
    }
    //ワーシャルフロイド法
    REP(k,n){
        REP(i,n){
            REP(j,n){
                if(chmin(e[i][j],e[i][k]+e[k][j])){
                    next[i][j]=next[i][k];
                }
            }
        }
    }
    int res = INT_MAX;
    vector<int> con;
    Rep(i,R){
        con.push_back(i);
    }
    do{
        int temp = 0;
        REP(i,R-1){
            temp+=e[r[con[i]]][r[con[i+1]]];
        }
        chmin(res,temp);
    }while(next_permutation(all(con)));
    put(res);
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

vector<int> min_primefactor(10000000, inf);

void calc(){
	min_primefactor[0] = 0;
	min_primefactor[1] = 1;
	for(int i = 2; i < 10000000; ++i){
		if(min_primefactor[i] == inf){
			for(int k = 1; i * k < 10000000; ++k){
				min_primefactor[i * k] = i;
			}
		}
	}
}

map<int,int> prime_factor(int N){
	map<int, int> res;
	while(N > 1){
		res[min_primefactor[N]]++;
		N /= min_primefactor[N];
	}
	return res;
}

int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> used(1000100,false);
	rep(i,N)cin >> A[i];
	calc();
	bool is_setwise = false;
	bool is_pairwise = true;
	int g = A[0];
	for(int i = 1; i < N; ++i)g = gcd(g, A[i]);
	if(g == 1)is_setwise = true;
	set<int> exist;
	rep(i,N){
		map<int,int> m = prime_factor(A[i]);
		for(auto x:m){
			if(exist.count(x.first) != 0){
				is_pairwise = false;
				break;
			}else{
				exist.insert(x.first);
			}
		}
	}
	if(is_pairwise)cout << "pairwise coprime" << endl;
	else if(is_setwise)cout << "setwise coprime" << endl;
	else cout << "not coprime" << endl;
	return 0;
}


Measured memory_bytes: 53812
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll a, b;
    cin >>a>>b;
    if (a>8 || b>8) cout << ":(" <<endl;
    else cout<<"Yay!"<<endl;
    return 0;
}


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

  #define vi vector<int>
  #define all(v) v.begin(),v.end()
  #define ll long long int
  #define  IOS    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define D1(x) {cerr<<" [" <<#x<<": "<<x<<"]";cout << endl;}
  #define D2(x) {cerr<<" [" <<#x<<": ";for(auto it:x)cerr<<it<< " ";cerr<<"] ";cout << endl;}

  const ll MOD=1e9+7;

  int check(ll n){
    int cnt=0;
    while(n){
      cnt++;
      n/=10;
    }
    return cnt;
  }

  void solve(){
     ll n;
     cin >> n;
     int ans = INT_MAX;
     for(ll i=1;i*i<=n;i++){
        if(n%i==0){
           ans = min(ans,max(check(n/i),check(i)));
        }
     }
     cout << ans;
  }


  int main(){
    IOS
       solve();
       cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }
// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;

class Main {
	public static Scanner sc = new Scanner(in);
	public static Random rand=new Random();

	class D{
		int d;
		int x;
		D(int d,int x){
			this.d=d;
			this.x=x;
		}
	}

	public void run() {
		while(true){
			int n=sc.nextInt(),m=sc.nextInt();
			if(n==0 && m==0)return;
			D[] dlist=new D[n];
			for(int i=0;i<n;i++){
				dlist[i]=new D(sc.nextInt(),sc.nextInt());
			}

			Arrays.sort(dlist,new Comparator<D>(){
				@Override
				public int compare(D o1, D o2) {
					return o2.x-o1.x;
				}
			});
			for(int i=0;i<n;i++){
				if(m>=dlist[i].d){
					m-=dlist[i].d;
					dlist[i].d=0;
				}else{
					dlist[i].d-=m;
					m=0;
				}
			}

			int sum=0;
			for(int i=0;i<n;i++){
				sum+=dlist[i].d*dlist[i].x;
			}
			ln(sum);
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}

	public int[] nextIntArray(int n){
		int[] res=new int[n];
		for(int i=0;i<n;i++){
			res[i]=sc.nextInt();
		}
		return res;
	}
	public static void pr(Object o) {
		out.print(o);
	}
	public static void ln(Object o) {
		out.println(o);
	}
	public static void ln() {
		out.println();
	}
}

Measured memory_bytes: 107716
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = [0] + A
# Dに何回目の移動で到達したか記録してみるか
D = [[] for _ in range(N+1)]

def judge(idx, now):
    cnt = 1
    n = A[now]
    while n != now:
        n = A[n]
        cnt += 1
    t = K - idx - 1
    t %= cnt
    return t

now = 1
i = 0
j = True
while i < K:
    now = A[now]
    D[now].append(i)
    if j and len(D[now]) > 2:
        i = K - judge(i, now) - 1
        j = False
    i += 1
   
print(now)


Measured memory_bytes: 107104
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d);
	
	printf("%d\n", (a - c) * (b - d));
	return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
 
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String s = sc.next();
 
		int[] sum = new int[N + 1];
		Arrays.fill(sum, 0);
		for (int i = 0; i < N; i++) {
			if(i + 1 < N && s.charAt(i) == 'A' && s.charAt(i + 1) == 'C')
				sum[i + 1] = sum[i] + 1;
			else
				sum[i + 1] = sum[i];
		}
 
		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
 
			int ans = sum[r - 1] - sum[l - 1];
			System.out.println(ans);
		}
	}
 
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v),end()
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;

template<typename A,typename B> inline void chmin(A &a,B b){if(a>b) a=b;}
template<typename A,typename B> inline void chmax(A &a,B b){if(a<b) a=b;}
//-----------------------------------------------------------------------

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

    while(true)
    {
        int n,m,p,X[100]={0};
        cin>>n>>m>>p;
        if(n+m+p==0) break;
     
        int num=0;
        REP(i,n) cin>>X[i],num+=X[i];
        if(X[m-1]==0) cout<<0<<endl;
        else cout<<(100-p)*num/X[m-1]<<endl;
    }
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
using ll = long long;
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    vector<vector<int>> x(n,vector<int>(n)),y(n,vector<int>(n));
    rep(i,n){
        cin>>a[i];
        rep(j,a[i]){
            int X,Y; cin>>X>>Y;
            X--;
            x[i][j]=X;
            y[i][j]=Y;
        }
    }
    int ans=0;
    
    rep(i,(1<<n)){
        vector<bool> tf(n,false);
        int cnt=0;
        rep(j,n){
            if(i & (1<<j)){
                tf[j]=true;
                cnt++;
            }
        }
        bool mujun=false;
        rep(j,n){
            if(!tf[j]) continue;
            rep(k,a[j]){
                //正直者は嘘を言ってはいけない
                if(tf[x[j][k]]&&y[j][k]==0){ mujun=true;}
                else if((!tf[x[j][k]])&&y[j][k]==1){ mujun=true; }
            }
        }
        if(!mujun) ans=max(ans,cnt);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
//ABC132E
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
typedef vector<ll> V;
const ll INF = 1145141919;

V g[101010];
ll cost[101010][3];

int main(){
    
    ll N, M, S, T;
    cin >> N >> M;
    rep(i, M){
        ll a, b;
        cin >> a >> b;
        g[a].push_back(b);
    }
    cin >> S >> T;
    
    rep(i, 101010)rep(j, 3)cost[i][j] = INF;
    cost[S][0] = 0;
    queue<P>Q;
    Q.push(P(S, 0));
    while(!Q.empty()){
        ll pos = Q.front().first;
        ll step = Q.front().second;
        Q.pop();
        if(pos == T && step == 0){
            cout << cost[pos][step] / 3 << endl;
            return 0;
        }
        for(auto to : g[pos]){
            ll next_step = (step + 1) % 3;
            if(cost[to][next_step] < INF)continue;
            cost[to][next_step] = cost[pos][step] + 1;
            Q.push(P(to, next_step));
        }
    }
    
    cout << -1 << endl;
    
    return 0;
}

Measured memory_bytes: 8064
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef long long ll;

int str_cmp(const void *a, const void *b)
{
	return strcmp(*(char **)a, *(char **)b);
}

int not_double(char **s, int n)
{
	int i = 0;
	while (i < n)
	{
		if (strcmp(s[i], s[n]) == 0)
			return 0;
		i++;
	}
	return 1;
}

int main()
{
	int N;
	scanf("%d", &N);
	char str[N + 1][11];
	char **sort;
	sort = (char**)malloc(sizeof(char*) * N);
	int i = 0;
	int len;
	while (i < N)
	{
		scanf("%s", str[i]);
		len = strlen(str[i]);
		sort[i] = (char*)malloc(sizeof(char) * (len + 1));
		strcpy(sort[i], str[i]);
		i++;
	}
	qsort(sort, N, sizeof *sort, str_cmp);
	i = 0;
	int j;
	int max[N];
	max[N - 1] = 1;
	int top = -1;
	int n = 1;
	while (i < N)
	{
		max[i] = 0;
		if (i != N - 1)
		{
			if (strcmp(sort[i], sort[i + 1]) == 0)
				n++;
			else if (strcmp(sort[i], sort[i + 1]))
			{
				max[i] = n;
				if (max[i] >= top)
				{
					top = max[i];
				}
				n = 1;
			}
		}
		if (i == N - 1)
		{
			max[i] = n;
			if (max[i] >= top)
				{
					top = max[i];
				}
		}
		i++;
	}
	// printf("--------------\n");
	i = 0;
	while (i < N)
	{
		// printf("%d %s %d\n", i, sort[i], max[i]);
		if (max[i] == top)
		{
			printf("%s\n", sort[i]);
		}
		i++;
	}
	return (0);
}


Measured memory_bytes: 12652
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int K = sc.nextInt();
		
		int ans = 0;
		for(int i = K - 1; i < N; i++) ans++;
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define MOD 10000
int n,m,dp[150][4][4],plan[150];
int rec(int n,int a,int b)
{
	if(n==0)return 1;
	if(dp[n][a][b]>=0)return dp[n][a][b];
	int res=0;
	if(plan[n]!=0)
	{
		if(a==b&&b==plan[n])return 0;
		else return rec(n-1,b,plan[n]);
	}
	if(a==b&&a!=0)
	{
		for(int i=1;i<=3;i++)
		{
			if(a!=i)
			{
				res+=rec(n-1,b,i);
				res%=MOD;
			}
		}
		return dp[n][a][b]=res;
	}
	else
	{
		for(int i=1;i<=3;i++)
		{
			res+=rec(n-1,b,i);
			res%=MOD;
		}
		return dp[n][a][b]=res;
	}
}
int main()
{
	cin >> n >> m;
	for(int i=0;i<m;i++)
	{
		int d,k;
		cin >> d >> k;
		plan[d]=k;
	}
	memset(dp,-1,sizeof(dp));
	cout << rec(n,0,0) << endl;
	return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	int ans = 0, now;
	for (int i = 1; i <= n; ++i)
	{
		now = 0;
		int t = i;
		for (int j = 0; j < 5; ++j)
		{
			now += t % 10;
			t /= 10;
		}
		ans += (a <= now && now <= b?i:0);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
while 1:
    n,m = map(int,input().split())
    if n==0:break
    a = list(map(int,input().split()))
    c = []
    for i in range(n-1):
        for j in range(i+1, n):
            if a[i]+a[j] <= m:
                c.append(a[i]+a[j])
    if len(c) == 0:
        print('NONE')
    else:
        print(max(c))



Measured memory_bytes: 25388