akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

vector<ll> p(1'000'100);

//エラトステネスの篩,n以下の素数の列挙の時に
//primeはi番目の素数、適当に返却を変えて
template <class T>
void sieve(T n){
	vector<bool> is_prime(n+1,true);
	vector<ll> prime;
	is_prime[0]=false;
	is_prime[1]=false;
	T ret=0;
	FOR(i,2,n+1){
		if(is_prime[i]){
			prime.push_back(i);
			p[i]=i;
			for(T j=2*i;j<=n;j+=i){
				is_prime[j]=false;
				p[j]=i;
			}
		}
	}
}

//素因数分解
template <class T>
map<T,T> prime_factor(T x){
	map<T,T> ans;
	while(x!=1){
		ll tmp=p[x];
		ans[tmp]++;
		while(x%tmp==0){
			x/=tmp;
		}
	}
	return ans;
}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	ll g=0;
	sieve(1'000'010);
	map<ll,ll> mp;
	rep(i,n){
		ll a;
		cin>>a;
		g=gcd(g,a);
		map<ll,ll> ret=prime_factor(a);
		for(auto [x,y]:ret){
			mp[x]++;
		}
	}
	if(g!=1){
		cout<<"not coprime"<<endl;
		return 0;
	}
	for(auto [x,y]:mp){
		if(y>=2){
			cout<<"setwise coprime"<<endl;
			return 0;
		}
	}
	cout<<"pairwise coprime"<<endl;
}

Measured memory_bytes: 15800
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		String t = scan.next();

		int ans = t.length();

		for (int i = 0; i <= s.length()-t.length(); i++) {
			int diff=0;
			for (int j = 0; j < t.length(); j++) {
				if(s.charAt(i+j) != t.charAt(j) ) {
					diff++;
				}
			}
			ans = Math.min(ans,diff);
		}

		System.out.println(ans);


	}

}

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

using namespace std;

#define ll long long
#define ull unsigned long long

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

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

    int k;
    cin >> k;
    int ans=  0;
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            for (int c = 1; c <= k; c++) {
                ans += gcd(a, gcd(b, c));
            }
        }
    }
    cout << ans << '\n';
}


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

int powmod(int64_t a){
  vector<int64_t> v(50);
  for(int i = 0; i < 50; ++i){
    v.at(i) = a;
    a *= a;
    a %= 1000000007;
  }
  int64_t s = 1;
  string mod = "111011100110101100101000000101";
  for(int i = 1; i <= mod.size(); ++i){
    if(mod.at(mod.size()-i) == '1'){
      s *= v.at(i-1);
      s %= 1000000007;
    }
  }
  return s;
}

int main() {
  int64_t x, y, a, b, n = 0;
  cin >> x >> y;
  if((x + y) % 3 == 0){
    a = (2*y - x)/3;
    b = (2*x - y)/3;
    if(a >= 0 && b >= 0){
      int64_t s = a + b, r = min(a, b);
      n = 1;
      for(int64_t i = 0; i < r; ++i){
        int64_t d = max(a, b) + i + 1;
        n *= d;
        n %= 1000000007;
      }
      for(int64_t i = 2; i <= r; ++i){
        n *= powmod(i);
        n %= 1000000007;
      }
    }
  }
  cout << n << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {

		// 入力
		Scanner sc = new Scanner(System.in);
		int x[] = new int[6];
		x[1] = Integer.parseInt(sc.next());
		x[2] = Integer.parseInt(sc.next());
		x[3] = Integer.parseInt(sc.next());
		x[4] = Integer.parseInt(sc.next());
		x[5] = Integer.parseInt(sc.next());

		// 0になっているのを見つける
		for (int i = 1; i <= 5; i++) {
			if (x[i] == 0) {
				System.out.println(i);
			}
		}
	}

}

Measured memory_bytes: 35648
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
   //   freopen("q.gir","r",stdin);
   //   freopen("q.cik","w",stdout);
      int n;
      cin>>n;
      vector<long double>dp(2*n+1,0);///i>n + average i<n - average
      dp[n]=1;
      for(int i=0;i<n;i++){
            long double win,lose;
            cin>>win;
            lose=1-win;
            vector<long double>temp(2*n+1,0);
            temp[0]=dp[1]*lose;
            temp[2*n]=dp[2*n-1]*win;
            for(int i=1;i<2*n;i++){
                  temp[i]=dp[i+1]*lose+dp[i-1]*win;
            }
            dp=temp;
      }
      long double ans=0;
      for(int i=n+1;i<=2*n;i++)ans+=dp[i];
      cout<<setprecision(20)<<ans;
}


Measured memory_bytes: 580
using System;

namespace _120_ABC
{
    class Program03
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            int Count_Zero = CountChar(S, '0');
            int Count_One = CountChar(S, '1');

            Console.WriteLine(Math.Min(Count_Zero, Count_One) * 2);

        }


        static int CountChar(string s, char c)
        {
            return s.Length - s.Replace(c.ToString(), "").Length;
        }
    }
}


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

int main () {

    map<char,int> op;
    map<int,char> re;
    op['m'] = 1000;
    op['c'] = 100;
    op['x'] = 10;
    op['i'] = 1;
    re[1000] = 'm';
    re[100] = 'c';
    re[10] = 'x';
    re[1] = 'i';
    int n;
    cin >> n;
    while (n--) {
        string s, t;
        cin >> s >> t;
        int ss = 0, tt = 0;

        for (int i = 0; i < s.size(); i++) {
            if ('2' <= s[i] && s[i] <= '9') {
                int c = s[i] - '0';
                i++;
                ss += c * op[s[i]];
            } else {
                ss += op[s[i]];
            }
        }

        for (int i = 0; i < t.size(); i++) {
            if ('2' <= t[i] && t[i] <= '9') {
                int c = t[i] - '0';
                i++;
                tt += c * op[t[i]];
            } else {
                tt += op[t[i]];
            }
        }

        ss += tt;
        int k = 1;
        string res;
        while (ss) {
            int c = ss % 10;
            ss /= 10;

            if (c == 1) {
                res = re[k] + res;
            } else if (c > 1) {
                res = re[k] + res;
                char tmp = '0' + c;
                res = tmp + res;
            }
            k *= 10;
        }

        cout << res << endl;
    }
}

Measured memory_bytes: 1208
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int a,b,c;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	in(a);in(b);
	printf("%d\n",(a+b)%24);
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  int64_t S = 0;
  for(int i = 1; i < N + 1; i++) {
    if(i % 3 != 0 && i % 5 != 0) S += i;
  }
  cout << S << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
int h[N], f[N];

int main(){
	int n,k;
	cin >> n>>k;
	for(int i = 0; i < n; i++) cin >> h[i];
	for(int i = 0; i < n; i++) f[i]=1000000000;
	f[0] = 0;
	f[1] = abs(h[0] - h[1]);
	for(int i = 2; i < n; i++){
      for(int j = i-1;j>=max(i-k,0);j--)
      //for(int j = max(0,i-k); j < i; j++) 
      {
		f[i] = min(f[j]+abs(h[i]-h[j]),f[i]);
      }
	}
	cout << f[n-1];
}


Measured memory_bytes: 4400
#include <stdio.h>
int main()
{
    int a,b,c,d,j,k;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    j=a*b;
    k=c*d;
    if(j>=k)
        printf("%d",j);
    else
        printf("%d",k);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
using ll = long long;
using namespace std;
ll N, H;
int main(void)
{
    ll P;
    cin >> N >> P;
    ll t = P;
    if (N == 1)
    {
        cout << P << endl;
        return 0;
    }
    ll ans = 1;
    for (ll i = 2; i * i <= P; ++i)
    {
        int cnt = 0;
        while (t % i == 0)
        {
            cnt++;
            t /= i;
        }
        ans *= pow(i, cnt / N);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    long long a, b, c, ret;
    cin >>a >>b >>c;
    if (a%2 * b%2 * c%2 == 0) {
        ret = 0;
    }
    else {
        if (max({a,b,c}) == a) {
            ret = b*c;
        } else if (max({a,b,c}) == b) {
            ret = c*a;
        } else {
            ret = a*b;
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt() - 1;
    boolean bl = false;
    do{
      n++;
      bl = isPrime(n);
    }while(!bl);
    System.out.println(n);
  }
  public static boolean isPrime(int n){
    int[] prime = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313};
    for(int i = 0; i < 65; i++){
      if(n % prime[i] == 0 && n / prime[i] != 1){
        return false;
      }
    }
    return true;
  }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define cinf(x,n) for(int i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(int i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

ll ans[2000];

int main(){
	arep(400,i,600){
		ans[i]=8;
	}
	arep(600,i,800){
		ans[i]=7;
	}
	arep(800,i,1000){
		ans[i]=6;
	}
	arep(1000,i,1200){
		ans[i]=5;
	}
	arep(1200,i,1400){
		ans[i]=4;
	}
	arep(1400,i,1600){
		ans[i]=3;
	}
	arep(1600,i,1800){
		ans[i]=2;
	}
	arep(1800,i,2000){
		ans[i]=1;
	}
	ll x;
	cin >> x;
	cout << ans[x] << endl;
}

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

using namespace std;
#define ull unsigned long long
#define si short int
#define ll long long
#define pii pair<int, int>

/*-----------------------------------------------------MATH------------------------------------------------*/
inline ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

inline int pwm(ll xx, ll pow, int MD) {
    if (pow < 0) { pow = pow % (MD - 1) + MD - 1; }
    ll mlt = 1;
    while (pow) {
        if (pow & 1) {
            mlt *= xx;
            mlt %= MD;
        }
        xx *= xx;
        pow >>= 1;
        xx %= MD;
    }
    return (int) mlt;
}

inline ll gcdex(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll xx, yy;
    ll gc = gcdex(b, a % b, yy, xx);
    x = xx;
    y = yy - (a / b) * xx;
    return gc;
}

inline int inv(ll r, int _mod) { return pwm(r % _mod, _mod - 2, _mod); }

/*-----------------------------------------------------MATH------------------------------------------------*/

const int inf = 1e9;
const int MAXN = 2e5 + 10;
ll mod = 1e9;
vector<int> c(18, 0);
vector<int> ans;

void solve() {
    int n,k;
    cin>>k>>n;
    if(k*500>=n) cout<<"Yes";
    else cout<<"No";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n = 1;
    for (int i = 0; i < n; i++) solve();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int a,b,x,y;
  int i,j,k;

  while(scanf("%d %d", &a, &b) != EOF) {
    if(a > b) k = a % b;
    else      k = b % a;

    if(k == 0) {
      if(a > b) x = b;
      else x = a;
    }else {
      for(i = 1; i <= k; i++) {
	if(k % i == 0) {
	  j = k / i;
	  if(a % j == 0 && b % j == 0) {
	    x = j;
	    break;
	  }
	}
      }
    }

    y = a * (b / x);
    printf("%d %d\n", x, y);
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
typedef long long ll;

using namespace std;

int main(){
    ll x,bud = 100,year = 0;

    cin >> x;
    while(1){
        year++;
        bud *= 1.01;
        if(bud >= x)break;
    }
    cout << year << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int conv(int n, vector<int> &a){
    vector<int>::iterator it = lower_bound(a.begin(), a.end(), n);
    if(*it == n){
        return 2*(it -a.begin()) +1;
    }
    return 2*(it -a.begin());
}

int main(){
    int n,k;
    cin >> n >> k;
    vector<vector<int> > x(n, vector<int>(2)), y(n, vector<int>(2)), d(n, vector<int>(2));
    vector<int> xr(2*n), yr(2*n), dr(2*n);
    for(int i=0; i<n; i++){
        cin >> x[i][0] >> y[i][0] >> d[i][0];
        cin >> x[i][1] >> y[i][1] >> d[i][1];
        xr[2*i] = x[i][0];
        xr[2*i+1] = x[i][1];
        yr[2*i] = y[i][0];
        yr[2*i+1] = y[i][1];
        dr[2*i] = d[i][0];
        dr[2*i+1] = d[i][1];
    }
    sort(xr.begin(), xr.end());
    xr.erase(unique(xr.begin(), xr.end()), xr.end());
    sort(yr.begin(), yr.end());
    yr.erase(unique(yr.begin(), yr.end()), yr.end());
    sort(dr.begin(), dr.end());
    dr.erase(unique(dr.begin(), dr.end()), dr.end());

    vector<vector<vector<int> > > field(2*xr.size()+1, vector<vector<int> >(2*yr.size()+1, vector<int>(2*dr.size()+1, 0)));
    for(int i=0; i<n; i++){
        for(int j=conv(x[i][0], xr); j<=conv(x[i][1], xr); j++){
            for(int k=conv(y[i][0], yr); k<=conv(y[i][1], yr); k++){
                for(int l=conv(d[i][0], dr); l<=conv(d[i][1], dr); l++){
                    field[j][k][l]++;
                }
            }
        }
    }

    lli ans = 0;
    for(int i=2; i<(int)field.size()-2; i+=2){
        for(int j=2; j<(int)field[0].size()-2; j+=2){
            for(int l=2; l<(int)field[0][0].size()-2; l+=2){
                if(field[i][j][l] >= k){
                    ans += (lli)(xr[i/2] -xr[i/2-1]) *(yr[j/2] -yr[j/2-1]) *(dr[l/2] -dr[l/2-1]);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 36332
N, M = map(int, input().split())
A = [[] for i in range(N)]
for i in range(M):
  a, b = map(int, input().split())
  A[a-1].append(b)
  A[b-1].append(a)
ans = 'IMPOSSIBLE'
for aa in A[0]:
  if N in A[aa-1]:
    ans = 'POSSIBLE'
    break
print(ans)


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

int main(){
  int h,w;
  cin>>h>>w;
  char s[101][101];
  bool atx[101], aty[101];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>s[i][j];
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#'){
        atx[i]=true;
        aty[j]=true;
      }
    }
  }
  for(int i=0;i<h;i++){
    if(atx[i]){
      for(int j=0;j<w;j++){
        if(aty[j]){
          cout<<s[i][j];
        }
      }
      cout<<endl;
    }
  }
}
    
      
    
    
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define REPE(i, a, b) for (int i = (a); i <= int(b); ++i)
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(), x.end()
#define PB push_back
#define EB emplace_back
using LL = long long;
using PII = pair<int, int>;
#define F first
#define S second

LL x[100010];
int main() {
  int n;
  LL a, b;
  cin >> n >> a >> b;
  REP(i, n) cin >> x[i];
  LL ans = 0;
  REPE(i, 1, n - 1) {
    ans += min(b, a * (x[i] - x[i - 1]));
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <map>


using namespace std;

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



class Rec{
public:
	int prodI;
	vector<int> ingIS;
};


int main(){
	while(true){
		int itemL;
		cin >> itemL;					if(!itemL)break;
		map<string,int> itemX2I;
		map<int,string> itemI2X;
		vector<int> priceS;

		REP(itemI,itemL){
			string itemX;
			int itemPrice;
			cin >> itemX >> itemPrice;
			itemX2I[itemX] = itemI;
			itemI2X[itemI] = itemX;
			priceS.push_back(itemPrice);
		}

		int recL;
		cin >> recL;
		vector<Rec> recS;

		REP(recI,recL){
			Rec rec;
			string prodX;
			cin >> prodX;
			rec.prodI = itemX2I[prodX];
			int ingL;
			cin >> ingL;
			REP(gomi,ingL){
				string ingX;
				cin >> ingX;
				rec.ingIS.push_back(itemX2I[ingX]);
			}
			recS.push_back(rec);
		}

		REP(gomi,recL+1){
			REP(recI,recL){
				Rec rec = recS[recI];
				int prodI = rec.prodI;
				int nPrice = 0;
				REP(ingII,rec.ingIS.size()){
					int ingI = rec.ingIS[ingII];
					nPrice += priceS[ingI];
				}
				priceS[prodI] = min(priceS[prodI],nPrice);
			}
		}

		string prodX;
		cin >> prodX;
		int prodI = itemX2I[prodX];
		int price = priceS[prodI];
		cout << price << endl;


	}
}

Measured memory_bytes: 1252
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, p;
string s;
multiset<pair<pair<string, int>, int> > mst;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s >> p;
		mst.insert(make_pair(make_pair(s, -p), i));
	}
	for (auto x : mst) {
		cout << x.second + 1 << "\n";
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

    ll k;
    cin >> k;

    vector<int> a(n), c(n, -1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }

    int i = 0;
    for (int j = 0; k > 0; j++, k--, c[i] >= 0 && (k %= j - c[i])) {
        c[i] = j;
        i = a[i];
    }

    cout << i + 1 << endl;

    return 0;
}

Measured memory_bytes: 4800
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	a := intScanner()
	b := intScanner()
	_ = intScanner()
	k := intScanner()
	if k <= a {
		fmt.Println(k)
	} else if k <= a+b {
		fmt.Println(a)
	} else {
		fmt.Println(a - (k - a - b))
	}
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

const ll MOD = 1e9 + 7;
const ld PI = acos(-1);
const ll MAX = 1e12;
const ll INF = 1e17;
const ld EPS = 1e-9;
const int M = 1e2 + 12;
const int N = 3e5 + 10;

int main() {
    //freopen("a.in", "r", stdin);
    //freopen("mines.in", "r", stdin);
    //freopen("mines.out", "w", stdout);
    string s = "999999999999999999";

    string N = "";

    fr(i, 11) {
        int l = -1, r = 10;
        if (i == 0)
            l = 0;
        while (r - l > 1) {
            int m = (l + r) / 2;
            string t = s;
            t[i] = (char)('0' + m);
            cout << "? " << t << endl;
            string answer;
            cin >> answer;
            if (answer == "Y")
                r = m;
            else
                l = m;
        }
        N += (char)('0' + r);
        s[i] = (char)('0' + r);

        if (i && r == 0) {
            if (s[i - 1] != '9') {
                string q = s.substr(0, i - 1) + '9';
                cout << "? " << q << endl;
                string answer;
                cin >> answer;
                if (answer == "Y") {
                    cout << "! " << N.substr(0, (int)N.size() - 1) << endl;
                    return 0;
                }
            }
            else if (N != "90") {
                string q = s.substr(0, i - 1) + "00";
                cout << "? " << q << endl;
                string answer;
                cin >> answer;
                if (answer == "N") {
                    cout << "! " << N.substr(0, (int)N.size() - 1) << endl;
                    return 0;
                }
            }
            else {
                string q = "10";
                cout << "? " << q << endl;
                string answer;
                cin >> answer;
                if (answer == "N") {
                    cout << "! " << N.substr(0, (int)N.size() - 1) << endl;
                    return 0;
                }
            }

        }
    }
}


Measured memory_bytes: 596
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    string s;
    cin >> s;
    int res = 0;
    rep(i, 3) {
        if (s[i] == '1') ++res;
    }
    cout << res << endl;

    return 0;
}

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

#define DIV 1000000007

using namespace std;

long long int vet[212345], sm[212345];

int main(){
    int n;

    scanf(" %d", &n);

    for(int i = 0; i < n; i++)
        scanf(" %lld", vet + i);

    for(int i = n - 1; i >= 0; i--)
        sm[i] = (sm[i + 1] + vet[i]) % DIV;
    
    long long int resp = 0;
    for(int i = 0; i < n - 1; i++)
        resp = (resp + sm[i + 1] * vet[i]) % DIV;

    printf("%lld\n", resp);
    return 0;
}

Measured memory_bytes: 6840
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long S[] = new long[50000];
    for(int i=1;i<50000;i++){
      S[i]=(long)i*i;
    }
    int tmp=0;
    while(1==1){
      if(N<S[tmp]){
        System.out.println(S[tmp-1]);
        return;
      }else{
        tmp=tmp+1;
      }
    }
    
  }
  

  
}

Measured memory_bytes: 23764
N, M, C = map(int, input().split())
B = list(map(int, input().split()))

ans = 0
for i in range(N):
  A = list(map(int, input().split()))
  t = sum([a*b for a, b in zip(A, B)])
  if t + C > 0:
    ans += 1

print(ans)

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

string S;
int result(void){
	sort(S.begin(),S.end());
	int min=atoi(S.c_str());
	reverse(S.begin(),S.end());
	int max=atoi(S.c_str());
	return max-min;

}

int main(void){
	int n;
	cin >>n;
	for(int i=0;i<n;i++){
		cin >> S;
		cout << result() << endl; 
	}
	return 0;
}

Measured memory_bytes: 1228
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<numeric>
#include<set>
#include<map>
#include<list>
#include<valarray>
#define ll long long 
#define d double
using namespace std;

int main()
{
	ll x;
	cin >> x;
	if (x % 10 == 3)
		cout << "bon" << endl;
	else if (x % 10 == 0 || x % 10 == 1 || x % 10 == 6 || x % 10 == 8)
		cout << "pon" << endl;
	else
		cout << "hon" << endl;

}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;
 
typedef long long LL;
typedef pair < int, int > pii;
 
inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}
 
const int MAXN = 200005;
 
int n, m, ret, a[MAXN], b[MAXN], c[MAXN];
 
int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	ret = n = Read(), m = Read();
	for (int i = 1; i <= n; i ++)
	{
		a[i] = Read(), c[a[i]] ++;
		if (a[i] - c[a[i]] >= 0 && ++ b[a[i] - c[a[i]]] == 1)
			ret --;
	}
	while (m --)
	{
		int x = Read(), y = Read();
		if (a[x] - c[a[x]] >= 0 && !-- b[a[x] - c[a[x]]])
			ret ++;
		c[a[x]] --;
		a[x] = y;
		c[a[x]] ++;
		if (a[x] - c[a[x]] >= 0 && ++ b[a[x] - c[a[x]]] == 1)
			ret --;
		printf("%d\n", ret);
	}
}

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

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

long long int LCM(long long int a, long long int b) {
    return (a / GCD(a, b)) * b;
}

int main() {
    long long int a, b;
    while (cin >> a >> b) {
        cout << GCD(a, b) << " " << LCM(a, b) << endl;
    }    
    return 0;
}


Measured memory_bytes: 3096
// 標準入力
var fs = require('fs'),
length = fs.fstatSync(process.stdin.fd).size,
buffer = new Buffer(length),
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
input = buffer.toString('utf8', 0, bytesRead).split('\n');
main();
 
function main(){
  var read = 0;
  var resultCase = 1;
  while(true){
    var maxWeight = +input[read++];
    if(!maxWeight){
      break;
    }
     
    var treasures = +input[read++];
    var pdp = new Int32Array(maxWeight + 1);
    for(var i = treasures; i--;){
      var c = input[read++].split(",");
      var tv = +c[0];
      var tw = +c[1];
 
      var dp = new Int32Array(maxWeight + 1);
 
      for(var w = 1; w < tw; w++){
        dp[w] = pdp[w];
      }
       
      for(var w = tw; w <= maxWeight; w++){
        dp[w] = max(pdp[w-tw] + tv, pdp[w]);
      }
      pdp = dp;
    }
 
    var resultWeight = 1001;
    var resultCost = 0;
    for(var i = 0; i <= maxWeight; i++){
      var pdpi = pdp[i]
      if(pdpi > resultCost){
        resultCost = pdpi;
        resultWeight = i;
      }
    }
     
    console.log("Case " + resultCase++ + ":\n" + resultCost + "\n" + resultWeight);
  }
}
 
function max(a, b) {
  var t = a - b;
  return a - (t & (t >> 31));
}

Measured memory_bytes: 14396
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<a.size();i++)
    {
        cin>>a[i];
    }
    int index=a.size()-1;
    while(index>=0){
        cout<<a[index]<<" ";
        index-=2;
    }
    index=1;
    if(a.size()%2==0)
        index=0;
    while(index<a.size()){
        cout<<a[index]<<" ";
        index+=2;
    }
    
}

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

int main() {
  long long n;
  cin >> n;
  vector<long long> a(5);
  for (int i = 0; i < 5; i++) {
    cin >> a[i];
  }
  long long x = *min_element(a.begin(), a.end());
  long long ans = (n + x - 1)/x + 4;
  cout << ans << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef pair<int, int> pii;

#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define REP(i, n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define CHMIN(a, b) a = min((a),(b))
#define CHMAX(a, b) a = max((a),(b))
#define ZP(a, len) cout << setfill('0') << setw(len) << right << a << endl;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

signed main() {
    string s;
    cin >> s;
    int ans = 0, c = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G') {
            c++;
        } else {
            ans = max(ans, c);
            c = 0;
        }
    }
    ans = max(ans, c);

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

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int N = int.Parse(s[0]);
            int M = int.Parse(s[1]);
            int C = int.Parse(s[2]);
            var B = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            int ans = 0;
            for (int i = 0; i < N; i++)
            {
                var A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

                int judge = 0;
                for (int j = 0; j < M; j++)
                {
                    judge += A[j]*B[j];   
                }
                if (judge + C > 0)
                {
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define endl 		"\n"
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define trace(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1) {std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " : " << arg1;
	ZZ(comma, args...);
}

void solve() {
	string s;
	int n, m;
	cin >> n >> m;
	cin >> s;
	vi a(n + 1, 0);
	s = "*" + s;
	for (int i = 1; i < n; i++) {
		string str = s.substr(i, 2);
		if (str == "AC")a[i] += 1;
	}
	vi pre(n + 1, 0);
	int rs = 0;
	rep(i, 1, n + 1) {
		rs += a[i];
		pre[i] = rs;
	}
	rep(i, 0, m) {
		int l, r;
		cin >> l >> r;
		int ans = pre[r] - pre[l - 1];
		if (a[r] == 1)ans--;
		cout << ans << endl;
	}
}
int main() {
	fast_io;
	int t = 1;
	// cin>>t;
	while (t--) {
		solve();
	}
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 4180
// g++ hello.cpp -o hello & hello
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define MP make_pair
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
void test();

int main()
{
//freopen("input.in","r",stdin);freopen("output.in","w",stdout);
int t=1;
//   cin>>t;
for(int i=1;i<=t;i++)
{    
//	cout<<"Case #"<<i<<": ";
	test();
cout<<endl;
}
return 0;
}
void test() 
{ll n;
cin>>n;
ll arr[n]={};
for(int i=0;i<n;i++)
cin>>arr[i];
ll ans[n]={};
ans[0]=0;
ans[1]=abs(arr[1]-arr[0]);
for(int i=2;i<n;i++)
{
ans[i]=min(abs(arr[i]-arr[i-1])+ans[i-1],abs(arr[i]-arr[i-2])+ans[i-2]);

}

cout<<ans[n-1];
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int W,H,x,y,r;
    cin >> W >> H>> x>>y>>r;
   if(x-r>=0 && x+r<=W&&y-r>=0&&y+r<=H)
       cout<< "Yes"<< endl;
    else
        cout<< "No"<<endl;
    return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;
const long long INF = 1LL << 60;    // 1.15x10^18
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using edge = pair<int, long long>;
using Graph = vector<vector<edge>>;

vector<long long> dijkstra(const Graph &g, int s) {
    vector<long long> dist(g.size(), INF);
    using Pi = pair<long long, int>;
    priority_queue<Pi, vector<Pi>, greater<Pi>> que;
    dist[s] = 0; que.emplace(dist[s], s);
    while (!que.empty()) {
        long long cost; int u; tie(cost, u) = que.top(); que.pop();
        if (dist[u] < cost) continue;
        for (auto &e: g[u]) {
            int v; long long nc; tie(v, nc) = e;
            if (chmin(dist[v], dist[u] + nc)) que.emplace(dist[v], v);
        }
    }
    return dist;
}

int main() {
    int n, m, r; cin >> n >> m >> r;
    Graph g(n);
    while (m--) {
        int s, t, d; cin >> s >> t >> d;
        g[s].emplace_back(t, d);
    }
    for (auto dist: dijkstra(g, r)) {
        if (dist == INF) cout << "INF" << endl;
        else cout << dist << endl;
    }
    return 0;
}


Measured memory_bytes: 19364
X,Y = list(map(int,input().split()))

mod = 10**9 + 7

def comb(n,k):
    k=min(k,n-k)
    a=1
    b=1
    for i in range(k):
        a*=n-i
        b*=i+1
        a%=mod
        b%=mod
    return (a * pow(b,mod-2,mod))%mod


if (2*X-Y)%3!=0 or (2*Y-X)%3!=0 or 2*X-Y<0 or 2*Y-X<0:
    print(0)
else:
    a = (2*X-Y)//3
    b = (2*Y-X)//3
    print(comb(a+b,a))

Measured memory_bytes: 39152
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  ll H; cin >> H;
  ll ans = 0;
  ll num_monster = 1;
  while (H > 0) {
    if (H == 1) {
      ans += num_monster;
      H = 0;
    }
    else {
      ans += num_monster;
      H /= 2;
      num_monster *= 2;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int aoki = (a - 1) / d + 1;
  int takahashi = (c - 1) / b + 1;
  if (takahashi > aoki) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    return 0;
  }
}


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

int main(){
  int N;
  cin >> N;
  long sum = 0;
  for(int i =1; i <= N;i++){
    if(i % 3 == 0){
      if(i % 5 == 0){
      }
    }else if(!(i % 5 == 0)){
      sum += i;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 3640
h,w = gets.split.map(&:to_i)
a = Array.new(h+2).map{Array.new(w+2,".")}
x = [1,1,0,-1,-1,-1,0,1]
y = [0,1,1,1,0,-1,-1,-1,]
cnt = 0
for i in 1..h
    str = gets.chomp
    for j in 1..w
        a[i][j] = str[j-1]
    end
end
for i in 1..h
for j in 1..w
if a[i][j] == "#"
    print "#"
else 
    8.times{|d|
     if a[i+x[d]][j+y[d]] == "#"
         cnt += 1
     end
    }
    print cnt
    cnt = 0
end
end
puts ""
end


Measured memory_bytes: 2044
import Control.Applicative
import Data.List (transpose)

main :: IO ()
main = do
  [n, _, _] <- map read . words <$> getLine
  (a, b) <- splitAt n . map (map read . words) . lines <$> getContents
  mapM_ (putStrLn . unwords . map show) $ a |*| b

--
-- Vector * Vector (inner product)
--
type Vector a = [a]

(/*/) :: Num a => Vector a -> Vector a -> a
(/*/) xs ys = sum $ zipWith (*) xs ys
infixl 7 /*/

--
-- Matrix * Matrix
--
type Matrix a = [Vector a]

(|*|) :: Num a => Matrix a -> Matrix a -> Matrix a
(|*|) xss yss = [[xs /*/ ys | ys <- yss'] | xs <- xss]
    where yss' = transpose yss
infixl 7 |*|



Measured memory_bytes: 12412
#include <stdio.h>

int main()
{
    int n,m,a[100],i,j,sum = 0;

    scanf("%d %d",&n,&m);
    for (i = 0; i < n; i++)
    {
        scanf("%d",&a[i]);
        sum += a[i];
    }
    int ans = 0;
    for (i = 0; i < n; i++)
    {
        if(a[i] * 4 * m >= sum)
        {
            ans++;
        }
    }

    if(m <= ans)printf("Yes");
    else printf("No");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vl = vector<ll>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using vs = vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.141592653589793

template<class S, class T>ostream&operator<<(ostream&os, pair<S, T>p)
{
	os << "[" << p.first << "," << p.second << "]"; return os;
}
template<class S>auto&operator<<(ostream&os, vector<S>t)
{
	bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; }
	return os;
}


void solve(int n, int m) {
	if (m <= 50) {
		vl v;
		ll ok = 0;
		map<ll, int> mp;
		rep(i, n) {
			string s;
			cin >> s;
			ll tmp = 0;
			rep(j, s.size()) {
				if (s[j] == '1')tmp += 2;
				tmp *= 2;
			}
			ok ^= tmp;
			v.push_back(tmp);
		}
		mp[0] = 0;
		rep(i, n) {
			for (auto x : mp) {
				ll ter = x.fs^v[i];
				if (mp.find(ter) == mp.end() || mp[ter]>x.sc+1) {
					mp[ter] = x.sc + 1;
				}
			}
		}
		if (mp.find(ok) == mp.end()) {
			cout << 0 << endl;
		}
		else {
			cout << n - mp[ok] << endl;
		}
	}
	else {
		int ans = 0;
		vector<vector<bool>> v;
		rep(i, n) {
			string s;
			cin >> s;
			vector<bool> z;
			rep(j, s.size()) {
				if (s[j] == '1')z.push_back(true);
				else z.push_back(false);
			}
			v.push_back(z);
		}
		rep(i, 1 << n) {
			vector < bool >  vec(m,false);
			int cnt = 0;
			rep(j, n) {
				if (i&(1 << j)) {
					rep(k, m) {
						vec[k]= vec[k] ^ v[j][k];
					}
				}
			}
			rep(j, n) {
				if (i&(1 << j)) cnt++;
			}
			bool check = true;
			rep(j, m) {
				if (vec[j])check = false;
			}
			if (check)ans = max(ans, cnt);
		}
		cout << ans<<endl;
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	while (cin >> n >> m, n) {
		solve(n, m);
	}
	return 0;
}


Measured memory_bytes: 68428
import java.util.Scanner;

public class Main {
    public static void trace(int[] a,int n){
        for (int i = 0;i < n;i++){
            if(i > 0)
                System.out.print(" ");
            System.out.print(a[i]);
        }
        System.out.print("\n");
    }
    public static void insertionSort(int[] a,int n){
        for(int i = 1;i < n;i++){
            int v = a[i];
            int j = i - 1;
            while (j >= 0 && a[j] > v){
                a[j + 1] = a[j];
                j--;
            }
            a[j + 1] = v;
            trace(a,n);
        }
    }

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


Measured memory_bytes: 34176
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			List<long> a = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
			long minusCount = a.Where(x => x < 0).Count();

			List<long> aa = a.Select(x => Math.Abs(x)).ToList();
			if (minusCount % 2 == 0) {
				Console.WriteLine(aa.Sum());
			} else {
				aa.Sort();
				long first = aa[0] * -1;
				aa.RemoveAt(0);
				Console.WriteLine(aa.Sum() + first);
			}
		}

		
	}
}


Measured memory_bytes: 29660
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
using namespace __gnu_pbds; 
#define mod 1000000007
#define int long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inp(n) for(i=0;i<n;i++) cin>>A[i];
#define inz(A) memset(A,0,sizeof(A))
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define T 1000000
#define F first
#define S second
#define pi pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define vp vector<pair< int,int> >
#define mpi map<pair<int,int> ,int>
#define lower(s) transform(all(s),s.begin(),::tolower)
#define endl "\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, 
         tree_order_statistics_node_update> pbds;
int add(int a, int b) {a=(a%mod + b%mod)%mod;return a;}
int sub(int a, int b) {a =(a%mod - b%mod + mod)%mod ;return a;}
int mul(int a, int b) {return (a%mod * b%mod) % mod;}
 
/* brownsands :Arpit */			

void solve()
{ 
  int i,j,x,k,flag=0,ans[100005];mii m;vi v;
   j=1;
   int digit[]={0,1,2,3,4,5,6,7,8,9};
   int ten=0,dig=1;
  for(i=1;i<=100000;i++)
  { 
    for(j=0;j<=20;j++)
    {
      if(abs((ten%10)-dig)<=1 || ten==0)
      { v.pb(ten*10 + dig);
        m[ten*10 + dig]=i;
        ans[i]=(ten*10 + dig);
        dig++;
         if(dig==10)
      {ten=ans[m[ten]+1];}
        dig%=10;
        break;
      }
      dig++;
      // if(dig==10)ten++;
      // dig%=10;
      if(dig==10)
      {ten=ans[m[ten]+1];}
      dig%=10;
    }
  }
  cin >> x;cout << ans[x];
}
signed main()
{ 
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int test=0,t;
  //cin>>t;
    t=1;
   while(test++ <t){         
   	//cout<<"Case# "<<test<<": ";
        solve();}
  //cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
} 
               
			
 

				
		
		




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

using ll = long long;
#define repi(n) for (int i = 0; i < (n); i++)
#define repj(n) for (int j = 0; j < (n); j++)
#define repk(n) for (int k = 0; j < (n); k++)
#define rep(i, n) for (int i = 0; (i) < (n); i++)
#define repr(i, a, b) for (auto i = (a); i < (b); i++)
#define repv(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = max((t), (v)))
#define updatemin(t, v) (t = min((t), (v)))
const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, -1, 1, -1, 1};
template <typename T>
T minptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i < *re) re = i;
  }
  return re;
}
template <typename T>
T maxptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i > *re) re = i;
  }
  return re;
}
int __vmax(int x) {
  return INT_MAX;
}
double __vmax(double x) {
  return 1e+300;
}
ll __vmax(ll x) {
  return LLONG_MAX;
}
int __vmin(int x) {
  return INT_MIN;
}
double __vmin(double x) {
  return -1e+300;
}
ll __vmin(ll x) {
  return LLONG_MIN;
}
template <typename T>
vector<T> lis(T begin, T end, bool allowequal = false, bool lds = false) {
  using V = typename iterator_traits<T>::value_type;
  int n = end - begin;
  vector<V> a(n, lds ? __vmin(*begin) : __vmax(*begin));
  vector<int> id(n);
  if (lds && allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (lower_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (lds) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (upper_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = upper_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  } else {
    for (int i = 0; i < n; i++) {
      id[i] = lower_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  }
  int m = *maxptr(id.begin(), id.end());
  vector<T> re(m + 1);
  for (int i = n - 1; i >= 0; i--) {
    if (id[i] == m) re[m--] = begin + i;
  }
  return re;
}

ll a[100100];
int main() {
  ll n, k;
  cin >> n >> k;
  repi(n) cin >> a[i];

  // Xの各bitを立てるとどれだけ得をするか
  ll toku[42] = {};
  repi(n) repj(42) {
    if (a[i] & (1ll << j)) toku[j]++;
  }
  repi(42) toku[i] = ((n - toku[i]) - toku[i]) << i;

  ll sum = 0;
  repi(n) sum += a[i];
  ll dp[43][2] = {};
  repi(43) repj(2) dp[i][j] = -1;
  dp[0][1] = 0;
  ll klen = k ? log2(k) + 1 : 0;
  repi(klen) {
    ll tk = klen - i - 1, kbit = (k >> tk) & 1;
    repj(2) {
      if (dp[i][j] == -1) continue;
      rep(t, j ? kbit + 1 : 2) {
        updatemax(dp[i + 1][j && t == kbit], dp[i][j] + max(0ll, toku[tk] * t));
      }
    }
  }
  cout << sum + max(dp[klen][0], dp[klen][1]) << endl;
}


Measured memory_bytes: 1024
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = Long.parseLong(sc.next());
        String name = "";
        long n = 0;
        String[] alphabet = { "z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q",
                "r", "s", "t", "u", "v", "w", "x", "y" };

        while (0 < N) {
            n = N % 26;
            name = alphabet[(int) (n)] + name;
            N = N / 26;
            if (n == 0) {
                N -= 1;
            }
        }

        PrintWriter out = new PrintWriter(System.out);
        out.println(name);

        sc.close();
        out.flush();
    }
}

Measured memory_bytes: 39564
#include<stdio.h>
#include<algorithm>

using namespace std;

int main(){
	int n,a,b,c;
	int m=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int a[3];
		for(int j=0;j<3;j++)scanf("%d",&a[j]);
		std::sort(a,a+3);
		
		int d = 100;
		if(a[0]>d || a[1]>d || a[2]>d)puts("hogehogehoge");
		
		if(a[0]*a[0]+a[1]*a[1] == a[2]*a[2]){
			puts("YES");
		}else{
			puts("NO");
		}
	}
}

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

int main() {
  ll s; cin >> s;
  ll a = s/500;
  ll b = s%500;
  ll c = b/5;
  ll ans = a*1000 + c*5;
  cout << ans << endl;
    
  return 0;
}



Measured memory_bytes: 256
import sys, math, re
from functools import lru_cache
from collections import defaultdict
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    S = input()
    l = [0, 4, 6, 8]
    ok = []

    for i in range(2**4):
        w = ['', 'K', 'I', 'H', '', 'B', '', 'R', '']
        for j in range(4):
            if (i>>j)&1:
                w[l[j]] = 'A'
        ok.append(''.join(w))

    print('YES' if S in ok else 'NO')

if __name__ == '__main__':
    main()

Measured memory_bytes: 9824