akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>

using namespace std;

void pp_seg(int *a,int a_size){
    for(int i=0;i<a_size;i++){
        cout << a[i];
        if(i!=a_size-1){
            cout << " ";
        }
    }
    cout << endl;
}

int maxSegment(int *a, int a_size){
    int ans = a[0];
    for(int i=0;i<a_size;i++){
        if(ans < a[i]){
            ans = a[i];
        }
    }
    return ans;
}

void countingSort(int *a, int a_size, int *b){
    int max_a = maxSegment(a,a_size);
    int *c = new int[max_a+1];
    for(int i=0;i<max_a+1;i++) c[i] = 0;
    for(int i=0;i<a_size;i++) c[a[i]]++;
    for(int i=1;i<max_a+1;i++) c[i] = c[i] + c[i-1];
    for(int j=a_size-1;j>=0;j--){
        b[c[a[j]]-1] = a[j];
        c[a[j]]--;
    }
}

int main(){
    int n;
    cin >> n;
    int *a = new int[n];
    for(int i=0;i<n;i++) cin >> a[i];
    int *b = new int[n];
    countingSort(a,n,b);
    for(int i=0; i<n;i++){
        cout << b[i];
        if(i!=n-1){
            cout << " ";
        }
    }
    cout << endl;
    delete [] a;
    delete [] b;
    return 0;
}



Measured memory_bytes: 18344
a, b, k = map(int, input().split())
c = a + k
d = b - k + 1
number = []

for i in range(a, c):
    if i > b:
        continue

    else:
        number.append(i)

for j in range(d, b + 1):
    if j in number:
        continue

    if j < a:
        continue

    else:
        number.append(j)

for i in number:
    print(i)


Measured memory_bytes: 3060
home = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
N = int(input())
for i in range(N):
    a, b, c, d = map(int, input().split())
    home[a - 1][b - 1][c - 1] += d
for i in range(3):
    for j in range(3):
        for k in range(10):
            print(' ' + str(home[i][j][k]), end ='')
        print()
    print('####################')
for j in range(3):
    for k in range(10):
        print(' ' + str(home[3][j][k]), end ='')
    print()


Measured memory_bytes: 5624
#include <iostream>
using namespace std;
int main(void){
    int a,b,c;
    int cnt=0;
    
    cin>>a;
    cin>>b;
    cin>>c;
    
    for(int i=a;i<=b;i++){
        if(c%i==0)cnt++;
    }
    
    cout<<cnt<<endl;
    
    return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define M 100007
using namespace std;

int n,h[M];

int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&h[i]);
	int p=0,ans=0;
	for(int i=n;i>=1;i--){
		if(h[i]<=h[i-1])p++,ans=max(ans,p);
		else p=0;
	}
	printf("%d\n",ans);
	return 0;
}

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

#define ll long long

// 入力
int n, W;
ll weight[1001], value[1001];

// DPテーブル
ll dp[1001][100001];

int main() {
  cin >> n >> W;
  for (int i = 0; i < n; ++i) cin >> weight[i] >> value[i];

  // DP初期条件: dp[0][w] = 0
  for (int w = 0; w <= W; ++w) dp[0][w] = 0;

  // DPループ
  for (int i = 0; i < n; ++i) {
    for (int w = 0; w <= W; ++w) {
      if (w >= weight[i]) dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]);
      else dp[i+1][w] = dp[i][w];
    }
  }

  cout << dp[n][W] << endl;
}


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

using System.Collections;

class Program
{
    static void Main()
    {
        int[] nq = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int N = nq[0];
        int Q = nq[1];
        var S = Console.ReadLine();

        var lrList = Enumerable.Range(0, Q)
            .Select(n => Console.ReadLine().Split(' ').Select(s => int.Parse(s) - 1).ToArray())
            .ToList();

        var ruisekiA = new int[N + 1];
        var ruisekiC = new int[N + 1];

        //ruisekiA[i]は、S[i]よりも左がわにACのAが何回登場するかを表すこととする。
        //ruisekiC[i]は、S[i]よりも左側にACのCが何回登場するかを表すこととする。

        for(int i = 1; i <= N; i++)
        {
            if (i == N)
                ruisekiA[i] = ruisekiA[i - 1];
            else
                ruisekiA[i] = ruisekiA[i - 1] + ((S[i - 1] == 'A' && S[i] == 'C') ? 1 : 0);            
        }
        for (int i = 2; i <= N; i++)
        {
            ruisekiC[i] = ruisekiC[i - 1] + ((S[i - 2] == 'A' && S[i - 1] == 'C') ? 1 : 0);
        }
        
        foreach (var lr in lrList)
        {
            //区間内のACのAの数
            var aCount = ruisekiA[lr[1] + 1] - ruisekiA[lr[0]];

            //区間内のACのCの数
            var cCount = ruisekiC[lr[1] + 1] - ruisekiC[lr[0]];

            //ただし、Cから始まる場合は区間内のCの数をマイナス補正する。
            if (ruisekiC[lr[0] + 1] - ruisekiC[lr[0]] == 1) cCount--;

            //区間内のACの数は、これらの小さい方
            
            Console.WriteLine(Math.Min(aCount, cCount));
        }
    }
}


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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vii = vector<pair<int, int>>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

// 素因数分解; 返り値は(素数, 乗数)のvector配列
vector<pair<ll, int>> factorize(ll n) {
	vector<pair<ll, int>> res;
	for (ll i = 2; i * i <= n; ++i) {
		if (n % i) continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1) res.emplace_back(n, 1);
	return res;
}

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };
constexpr auto MAX = 100010;

// ──────────────────────────────────────────────────────────────────────────────

int main() {
	int n, k, r, s, p;
	string t;
	cin >> n >> k >> r >> s >> p >> t;

	map<char, char> best = { {'r', 'p'},{'s','r'},{'p','s'} };
	map<char, int> point = { {'r', r},{'s', s},{'p', p} };

	string defo = "rsp";
	string h;
	int ans = 0;
	rep(i, n) {
		bool f = true;

		if (i - k >= 0 && t[i] == t[i - k] && best[t[i]] == h[i - k]) {
			f = false;
			rep(j, 3) {
				if (defo[j] == h[i - k]) continue;
				else if (i + k < n && defo[j] == best[t[i + k]]) continue;
				else {
					h += defo[j];
					break;
				}
			}
		}

		if (f) {
			h += best[t[i]];
			ans += point[best[t[i]]];
			//cout << ans << " : " << h[i] << endl;
		}
		
	}
	cout << ans << endl;
	//cout << h << endl;
}

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

using namespace std;

const int M=26;

int arr[404];
int n;
int c[26];
int s[404][26];
int las[26];

long long calc()
{
	for(int i=0;i<M;i++) las[i]=0;
	long long ans=0;
	for(int i=0;i<n;i++)
	{
		las[arr[i]-1]=i+1;
		ans+=s[i][arr[i]-1];
		for(int j=0;j<M;j++)
			ans-=c[j]*(i+1-las[j]);
		//cout << ans << endl;
	}
	return ans;
}

int main()
{
	//auto start = std::chrono::system_clock::now();
	mt19937 rng(12342);
	cin >> n;
	for(int i=0;i<M;i++) cin >> c[i];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<M;j++) cin >> s[i][j];
	}
	for(int i=0;i<n;i++)
	{
		/*int ans=0;
		for(int j=0;j<26;j++)
			if(s[i][j]>s[i][ans]) ans=j;*/
		arr[i]=i%26+1;
	}
	//std::chrono::duration<double> elp=std::chrono::system_clock::now()-start;
	int t=4;
	long long curs=calc();
	while(t--)
	{
		int perm[n];
		for(int i=0;i<n;i++) perm[i]=i;
		for(int i=1;i<n;i++) swap(perm[i],perm[uniform_int_distribution<int>(0, i)(rng)]);
		for(int xx=0;xx<n;xx++)
		{
			for(int y=0;y<M;y++)
			{
				int x=perm[xx];
				int oldx=arr[x];
				arr[x]=y+1;
				if(calc()<curs)
				{
					arr[x]=oldx;
				}
			}
		}
	}
	for(int i=0;i<n;i++)
		cout << arr[i] << endl;
}

Measured memory_bytes: 3684
def insertionSort(A,input_num):
    for i in range(input_num):
        v = A[i]
        j = i - 1
        while(j >= 0 and A[j] > v):
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v
        print(*A)
        
input_num = int(input())
A = list(map(int, input().split()))

insertionSort(A,input_num)


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

int main() {
  int n, x, y, z;
  bool a[100] = {}, b[100] = {}, c[100] = {};
  cin >> n;
  cin >> x;
  for (int i = 0; i < x; ++i) {
    int t;
    cin >> t;
    a[t - 1] = true;
  }
  cin >> y;
  for (int i = 0; i < y; ++i) {
    int t;
    cin >> t;
    b[t - 1] = true;
  }
  cin >> z;
  for (int i = 0; i < z; ++i) {
    int t;
    cin >> t;
    c[t - 1]= true;
  }

  int res[100];
  for (int i = 0; i < 100; ++i) {
    res[i] = (!a[i] & c[i]) | (b[i] & c[i]);
  }
  cout << std::count(begin(res), end(res), true) << endl;
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int N, P;
	cin >> N >> P;
	string S;
	cin >> S;

	if(P==2 || P==5){
		ll ans = 0;
		for(int i=0; i<N; i++){
			if((S[i]-'0')%P==0){
				ans += (i+1);
			}
		}
		cout << ans << endl;
		return 0;
	}

	vector<int> rem(N);
	int d = 1;
	for(int i=N-1; i>=0; i--){
		rem[i] = (S[i]-'0') * d % P;
		d = (10 * d) % P;
	}

	vector<int> cum(N+1);
	for(int i=1; i<=N; i++){
		cum[i] = (cum[i-1] + rem[i-1]) % P;
	}

	vector<int> cnt(10005);
	for(int i=0; i<=N; i++){
		cnt[cum[i]]++;
	}

	ll ans = 0;
	for(int i=0; i<N; i++){
		cnt[cum[i]]--;
		ans += cnt[cum[i]];
	}
	cout << ans << endl;

	return 0;
}


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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

typedef pair<int, int> P;

const int N = 1e6+5;
string s;
ll n,m;
ll a,b,x,pp,qq;
int p[8],q[8],c[8],d[8];
int kaijo(int a) {
  if(a == 0) return 1;
  return a * kaijo(a-1);
}

int main () {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin >> n;
  rep(i,n) {
    cin >> p[i];
    rep(j,i) {
      if(p[j] < p[i]) c[i]++;
    }
    c[i] = p[i] - 1 - c[i];
    pp += pow(10,n-i-1) * p[i];
  }
  rep(i,n) {
    cin >> q[i];
    rep(j,i) {
      if(q[j] < q[i]) d[i]++;
    }
    d[i] = q[i] - 1 - d[i];
    qq += pow(10,n-i-1) * q[i];
  }  
  rep(i,n) {
    a += c[i] * kaijo(n-i-1);
    b += d[i] * kaijo(n-i-1);
  }
  cout << abs(a - b) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(void) {
	int x,y,data,lcm;
	double cpx,cpy;
	while(scanf("%d %d",&x,&y) != EOF){
		cpx = x,cpy = y;
		if (x < y){
			data = x,x = y,y = data;
		}
		while(y != 0){
			x = x % y;
			data = x,x = y,y = data;
		}
		if (cpx >= 1000000){
			lcm = (((cpx / 1000000) * cpy) / x) * 1000000;
		}
		else {
			if (cpy >= 1000000){
				lcm = ((cpx * (cpy / 1000000)) / x) * 1000000;
			}
			else {
			lcm = (cpx * cpy) / x;
			}
	    }
		printf("%d %d\n",x,lcm);
	}
	return 0;
}

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

int keta(int aka){
  int count=0;
    while(aka!=0){
        aka /= 10;
        count++;
    }
    return count;
}
int sentou(int aka){
  int kiiro=1;
    rep(i,keta(aka)-1){
    kiiro=kiiro*10;
  }
  return aka/kiiro;
}
int main() {
  int count=0,N,nketa,sen;
  int hyou[11][11];
  cin>>N;
  sen=sentou(N);
  nketa=keta(N);

  for(int j=1;j<10;j++){
      for(int k=1;k<10;k++){
        hyou[j][k]=0;
      }
  }
  
  rep(i,N+1){
    hyou[i%10][sentou(i)]++;
  }
    for(int j=1;j<10;j++){
      for(int k=1;k<10;k++){
        count+=hyou[j][k]*hyou[k][j];
      }
    }
  cout<<count;
    
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b==c+d)cout<<"Balanced"<<endl;
  else if(a+b>c+d)cout<<"Left"<<endl;
  else cout<<"Right"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;

const int N = 2e5+50;
const int P = 924844033;

struct Graph {
	struct Edge {
		int to, nxt;
	} e[N<<1];
	int top, head[N];
	
	Graph(): top(0) {
		memset(head, -1, sizeof head);
	}
	
	void add(int u, int v) {
		e[top] = (Edge){v, head[u]};
		head[u] = top++;
	}
	
	void add2(int u, int v) {
		add(u, v);
		add(v, u);
	}
} G;

int n, a[N];
int siz[N];
int fac[N], ifac[N];
int g[N], h[N], s[N<<1];

int qPow(int x, int k) {
	int rtn = 1;
	for (; k; k >>= 1, x = (ll)x * x % P)
		if (k & 1) rtn = (ll)rtn * x % P;
	return rtn;
}

void dfs(int u, int fa) {
	siz[u] = 1;
	for (int i = G.head[u]; ~i; i = G.e[i].nxt) {
		int v = G.e[i].to;
		if (v == fa) continue;
		dfs(v, u);
		siz[u] += siz[v];
		a[siz[v]]--;
	}
	a[n]++;
	a[n-siz[u]]--;
}

void initFac() {
	fac[0] = 1;
	for (int i = 1; i <= n; i++)
		fac[i] = (ll)fac[i-1] * i % P;
	ifac[n] = qPow(fac[n], P-2);
	for (int i = n-1; i >= 0; i--)
		ifac[i] = (ll)ifac[i+1] * (i+1) % P;
}

namespace NTT {
	const int G = 5;
	
	int n;
	int rev[N<<2];
	int a[N<<2], b[N<<2], t[N<<2];
	
	void init(int m) {
		int len = 0;
		for (n = 1; n < m; n <<= 1)
			len++;
		for (int i = 0; i < n; i++)
			rev[i] = rev[i>>1] >> 1 | (i&1) << len-1;
	}
	
	void NTT(int f[], int sgn) {
		for (int i = 0; i < n; i++)
			if (rev[i] > i) std::swap(f[rev[i]], f[i]);
		for (int i = 1; i < n; i <<= 1) {
			int gn = qPow(G, (P-1)/(i*2));
			if (sgn == -1) gn = qPow(gn, P-2);
			for (int j = 0; j < n; j += i*2) {
				int g = 1;
				for (int k = 0; k < i; k++, g = (ll)g * gn % P) {
					int x = f[j+k], y = (ll)g * f[j+i+k] % P;
					f[j+k] = (x + y) % P;
					f[j+i+k] = (x - y) % P;
				}
			}
		}
		if (sgn == -1) {
			int invn = qPow(n, P-2);
			for (int i = 0; i < n; i++)
				f[i] = (ll)f[i] * invn % P;
		}
		for (int i = 0; i < n; i++)
			f[i] = (f[i] + P) % P;
	}
	
	void mul(int la, int ta[], int lb, int tb[], int res[]) {
		init(la+lb-1);
		memset(a, 0, sizeof a);
		memset(b, 0, sizeof b);
		for (int i = 0; i < la; i++)
			a[i] = ta[i];
		for (int i = 0; i < lb; i++)
			b[i] = tb[i];
		NTT(a, 1);
		NTT(b, 1);
		for (int i = 0; i < n; i++)
			t[i] = (ll)a[i] * b[i] % P;
		NTT(t, -1);
		for (int i = 0; i < la+lb-1; i++)
			res[i] = t[i];
	}
}

int main() {
	scanf("%d", &n);
	initFac();
	for (int i = 1, u, v; i < n; i++) {
		scanf("%d%d", &u, &v);
		G.add2(u, v);
	}
	dfs(1, 0);
	for (int i = 0; i < n; i++) {
		g[i] = ifac[i];
		h[i] = (ll)fac[n-i] * a[n-i] % P;
	}
	NTT::init(n);
	NTT::mul(n, g, n, h, s);
	for (int i = 1; i <= n; i++)
		printf("%d\n", (int)((ll)s[n-i] * ifac[i] % P));
	return 0;
}


Measured memory_bytes: 32768
a, b, x = gets.chomp.split(" ").map(&:to_i)
h = x.to_f / (a * a).to_f

if h > b / 2
  rad = Math.atan2(2.0*(b-h).to_f, a)
  puts rad * 180.0 / Math::PI
else
  rad = Math.atan2(b, 2.0*(a*h).to_f/b.to_f)
  puts rad * 180.0 / Math::PI
end

Measured memory_bytes: 1788
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

int[] compact(int[] xs) {
    auto ys = xs.dup;
    ys.sort;

    int[int] m;
    foreach (i, y; ys) {
        m[y] = cast(int) i + 1;
    }

    auto ret = new int[xs.length];
    for (int i = 0; i < xs.length; i++)
        ret[i] = m[xs[i]];
    return ret;
}

long calc(int[] xs) {
    // auto n = xs.maxElement;
    auto n = xs.reduce!max;
    auto bit = new BinaryIndexedTree(n);
    long ans = 0;
    for (int i = 0; i < xs.length; i++) {
        ans += i - bit.sum(xs[i]);
        bit.add(xs[i], 1);
    }
    return ans;
}

void main() {
    readln;
    auto xs = readints;

    auto ans = calc(compact(xs));
    writeln(ans);
}

class BinaryIndexedTree {
    private int[] _data;

    this(int n) {
        _data = new int[n + 1];
    }

    /// [1, p] ??????(1 based)
    int sum(int p) {
        assert(0 < p && p < _data.length);

        int s = 0;
        while (p > 0) {
            s += _data[p];
            p -= p & -p;
        }
        return s;
    }

    /// p ????????? x ????????????(1 based)
    void add(int p, int x) {
        assert(0 < p && p < _data.length);

        while (p < _data.length) {
            _data[p] += x;
            p += p & -p;
        }
    }
}

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

#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) ALL(v)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
#define CININIT cin.tie(0),ios::sync_with_stdio(false)
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
ll gcd(ll a,ll b){
    if(b==0) return a;
    else return gcd(b,a%b);
}

constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};

int main(){
    int N;cin>>N;
    vll T(N),A(N);
    rep(i,N) cin>>T[i];
   // for(int i=N-1;i>=0;i--) cin>>A[i];
    rep(i,N) cin>>A[i];

    vi h(N,-1);

    if(T[N-1]!=A[0]){
        cout << 0 << endl;
        return 0;
    }

    h[0] = T[0];
    h[N-1] = A[N-1];
    for(int i=0;i<N-1;i++){
        if(T[i]<T[i+1]){
            h[i+1] = T[i+1];
        }
    }
    for(int i=N-1;i>=1;i--){
        if(A[i-1]>A[i]){
            h[i-1] = max<ll>(h[i-1],A[i-1]);
        }

    }
    
    for(int i=1;i<N-1;i++){
        if(h[i]==-1) continue;
        if(T[i]<h[i] or A[i]<h[i]){
            cout << 0 << endl;
            return 0;
        }
    }

    ll ans = 1;

    //cout << h << endl;

    for(int i=1;i<N-1;i++){
        if(h[i]==-1){
            int id=i;
            while(h[id]==-1){
                id++;
            }
            int num = id-i;
            int mini = min(h[i-1],h[id]);
            ll tmp = 1;
            for(int j=0;j<num;j++){
                tmp = (tmp * mini) % mod;
            }
            //cout << tmp << endl;
            ans = (ans * tmp ) % mod;
            i = id-1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 2176
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

void main()
{
    for(int n; 0!=(n=readln().chomp().to!int()); )
    {
        immutable a = iota(n).map!(_=>readln().chomp().to!int()).array().idup;
        int m=int.min;
        auto dp = new int[][](n,n);
        foreach(i;0..n)
            foreach(j;i..n)
                m=max(m,dp[i][j]=(i<j?dp[i][j-1]:0)+a[j]);
        writeln(m);
    }
}

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

int w, h, n;
int x[100], y[100], a[100];
int cnt[100][100];	//cnt[x0][y0]

int main() {
	int i, px, py;
	
	cin >> w >> h >> n;
	for (i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> a[i];
		if (a[i] == 1) {
			for (px = 0; px < x[i]; px++) {
				for (py = 0; py < h; py++) {
					cnt[px][py]++;
				}
			}
		}
		if (a[i] == 2) {
			for (px = x[i]; px < w; px++) {
				for (py = 0; py < h; py++) {
					cnt[px][py]++;
				}
			}
		}
		if (a[i] == 3) {
			for (py = 0; py < y[i]; py++) {
				for (px = 0; px < w; px++) {
					cnt[px][py]++;
				}
			}
		}
		if (a[i] == 4) {
			for (py = y[i]; py < h; py++) {
				for (px = 0; px < w; px++) {
					cnt[px][py]++;
				}
			}
		}
	}
	
	int ans = 0;
	for (px = 0; px < w; px++)
		for (py = 0; py < h; py++)
			if (cnt[px][py] == 0) ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b;
  cin >> n >> a >> b;
  bool f=0;
  for(int i=1;i<=a;i++){
    if(i*n%a==b)f=1;
  }
  if(f)cout << "YES";
  else cout << "NO";
}

Measured memory_bytes: 256
// Don't place your source in a package
import java.util.*;
import java.lang.*;
import java.io.*;

// Please name your class Main
class Main {
	public static void main (String[] args) throws java.lang.Exception {
	    Scanner input = new Scanner(System.in);
	    int n = input.nextInt();
	    String s = input.next();
	    String[] str = s.split("ABC");
	    int sum = 0;
	    for(int i=0;i<str.length;i++)
	        sum+=str[i].length();
	    System.out.println((n-sum)/3);
	}
}

Measured memory_bytes: 23764
#include <stdio.h>
int main(void)
{
	long int n, a, b;
	long int ans;
	scanf ("%ld %ld %ld", &n, &a, &b);
	if (a > b) ans = 0;
	else ans = (b - a) * (n - 2) + 1;
	if (n == 1 && a == b) ans = 1;
	else if (n == 1) ans = 0;
	printf("%ld\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <functional>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <string>

using namespace std;

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)

ll const INF = 1000000000000000000;
int const I_MAX = 2147483647;
ll const MOD = 1e9 + 7;
int const POW_MAX = 1e5;

// nCr
ll po[POW_MAX + 2];
ll mod_pow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}
ll mod_inv (ll x) {
  return mod_pow(x, MOD - 2) % MOD;
}
ll comb(int n, int r) {
  return (((po[n] * mod_inv(po[r])) % MOD) * mod_inv(po[n - r])) % MOD;
}
// greatest common divisor
ll gcd(ll a, ll b) {
  while (a % b != 0) {
    ll tmp = a;
    a = b;
    b = tmp % b;
  }
  return b;
}

struct UnionFind {
    vector<int> par;

    UnionFind(int N) : par(N) {
        for(int i = 0; i < N; i++) par[i] = i;
    }

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

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int N, M;
map<int, int> used;

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

  UnionFind tree(N + 1);

  rep(i, M) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    tree.unite(x, y);
  }
  int count = 0;
  for(int i = 1; i < N + 1; i++) {
    int root = tree.root(i);
    if (used[root]) continue;

    used[root]++;
    count++;
  }
  printf("%d\n", count);
}


Measured memory_bytes: 5376
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a == 5 && b == 7 && c == 5)
        cout << "YES";
    else if(a == 7 && b == 5 && c == 5)
            cout << "YES";
    else if(a == 5 && b == 5 && c == 7)
            cout << "YES";

    else
    cout << "NO";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.length()-1;i++)
    {
        set<char>q;
        string pos=s.substr(i,2);
        q.insert(pos[0]);
        q.insert(pos[1]);
        if(q.size()==1)
        {
            cout<<i+1<<" "<<i+2<<endl;
            return 0;
        }
        q.clear();
        //cout<<s.substr(i,2)<<endl;
    }
    for(int i=0;i<s.length()-2;i++)
    {
        set<char>q;
        string pos=s.substr(i,3);
        q.insert(pos[0]);
        q.insert(pos[1]);
        q.insert(pos[2]);
        if(q.size()!=3)
        {
            cout<<i+1<<" "<<i+3<<endl;
            return 0;
        }
        q.clear();
        //cout<<s.substr(i,2)<<endl;
    }
    cout<<"-1 -1"<<endl;
    return 0;
}


Measured memory_bytes: 512
using System;
class p
{
  static void Main()
  {
    int N = int.Parse(Console.ReadLine());
    long pp = 2, p = 1;
    for (int i = 1; i < N; i++) {
      long l = p + pp;
      pp = p;
      p = l;
    }
    Console.WriteLine(p);
  }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	while(cin>>a>>b){
		int c = a+b;
		if(c%2==0)
			cout<<c/2<<endl;
		else
			cout<<c/2+1<<endl;
	}
	
	return 0;	
}

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


using namespace std;

int main(){

	int N,L;

	cin >> N >> L;

    vector<string> v;

    string ret;

    string s;
	for(int i = 0;i < N;i++){
	   cin  >>	s;
	   v.push_back(s);
	}

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

    for(vector<string>::iterator it = v.begin() ;it != v.end();it++){
    	ret += *it;
    }

    cout << ret << endl;

    return 0;

}


Measured memory_bytes: 256
N,*A = $<.read.split.map(&:to_i)

q = A.uniq.sort
while 0
	a = q[0]
	z,m = q.partition{|_| _%a == 0 }
	break if m.empty?
	q = m.map{|_|_%a}.sort + z
end
p q[0]


Measured memory_bytes: 16508
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 1000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

signed main(void) {
    string N;
    cin>>N;
    cout << ((N[0]=='9'||N[1]=='9')?"Yes":"No")<<endl;


    return 0;
}

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

struct Point {
    double x, y;
};

int n;

double averege(vector<Point> &T) {
    vector<int> O(n);
    for (int i = 0; i < n; i++) {
        O.at(i) = i + 1;
    }
    
    double sum = 0;
    double count = 0;
    do {
        count++;
        for (int k = 0; k < n - 1; k++) {
            int i = O.at(k) - 1;
            int j = O.at(k + 1) - 1;
            sum += sqrt(pow(abs(T.at(i).x - T.at(j).x), 2.0) + pow(abs(T.at(i).y - T.at(j).y), 2.0));
        }
    } while (next_permutation(O.begin(), O.end()));

    double ave = sum / count;

    return ave;
}

int main() {
    cin >> n;
    vector<Point> T(n);
    for (int i = 0; i < n; i++) {
        scanf("%lf%lf", &T.at(i).x, &T.at(i).y);
    }

    double ans = averege(T);

    printf("%.10lf\n", ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int N;
int L[101];
int ans = 0;
int main(){
	cin >> N;
	for(int i=0;i<N;i++)cin >> L[i];
	sort(L,L+N);
	for(int i=0;i<N-2;i++){
		for(int j=i+1;j<N-1;j++){
			for(int k=j+1;k<N;k++){
				if(L[i] != L[j] && L[j] != L[k] ){
					if(L[i]+L[j] > L[k] && L[j]+L[k] > L[i] && L[i] + L[k] > L[j]){
						ans++;
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        int N=cin.nextInt();
        int K=cin.nextInt();
        if(N<11)K+=(100*(10-N));
      Console.WriteLine(K);
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}


Measured memory_bytes: 11092
#include<cstdio>
#include<iostream>
#include<vector>
#include<map>
#include<cstring>
#include<algorithm>
using namespace std;
typedef pair<int, int> pii;
#define IOS ios::sync_with_stdio(false)
const int maxn = 3e5 + 5;
int r[maxn], c[maxn];
map<pii, bool> mp;
vector<int> vr, vc;
void solve() {
	int h, w, m;
	scanf("%d%d%d", &h, &w, &m);
	int mr = 0, mc = 0;
	while (m--) {
		int x, y;
		scanf("%d%d", &x, &y);
		r[x]++;
		c[y]++;
		mr = max(mr, r[x]);
		mc = max(mc, c[y]);
		mp[pii(x, y)] = true;
	}
	for (int i = 1; i <= h; ++i) {
		if (mr == r[i])	vr.push_back(i); 
	}
	for (int i = 1; i <= w; ++i) {
		if (mc == c[i])	vc.push_back(i); 
	}
	for (int i : vr) {
		for (int j : vc) {
			if (!mp[pii(i, j)]) {
				//点爆方格中没有炸弹 
				printf("%d\n", mr + mc);
				return;
			}
		}
	}
	//点爆方格中面有炸弹 
	printf("%d\n", mr + mc - 1);
}
int main() {
	solve();
	return 0;
}


Measured memory_bytes: 28460
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << endl
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define rrep(i,n) for(int i=(n); (i)>=0; --(i))
#define reps(i,s,n) for(int i=(s); (i)<(n); ++(i))
#define maxi(v) distance(v.begin(), max_element(v.begin(), v.end()))
#define mini(v) distance(v.begin(), min_element(v.begin(), v.end()))
#define maxemt(v) *max_element(v.begin(), v.end())
#define minemt(v) *min_element(v.begin(), v.end())
#define lb(v,x) v[lower_bound(v.begin(), v.end(), x) - v.begin()]
#define ub(v,x) v[upper_bound(v.begin(), v.end(), x) - v.begin()]
template<class T> inline bool print(T& x){ cout << x << endl; return true; }
template<class T> inline bool print_(T& x){ cout << x << " "; return true; }
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; }
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
  }
ll lcm(ll x, ll y){
  return x / gcd(x,y) * y;
}
const int INF = 1e9;
const ll llINF = 1LL<<60;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int main(){
  int n; cin >> n;
  vector<string> s(n); rep(i,n) cin >> s[i];
  vector<ll> v(5,0);
  rep(i,n){
    switch(s[i][0]){
      case 'M': v[0]++; break;
      case 'A': v[1]++; break;
      case 'R': v[2]++; break;
      case 'C': v[3]++; break;
      case 'H': v[4]++; break;
    }
  }
  ll ans=0;
  rep(i,3){
    reps(j,i+1,4){
      reps(k,j+1,5){
        ans += v[i]*v[j]*v[k];
      }
    }
  }
  cout << ans;
  
  return 0;
}


Measured memory_bytes: 6144
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
	// AtCoder Beginner Contest 120
	// https://atcoder.jp/contests/abc120/tasks
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();
		int n = Math.min(a, b);
		int res = 0;
		
		for (int i = n; i >= 1; i--) {
			if (a%i == 0 && b%i == 0) {
				k--;
				res = i;
				if (k == 0) {
					break;
				}
			}
		}
		
		System.out.println(res);
	}
	
	static class FastReader { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine()); 
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() { 
            String str = ""; 
            try{ 
                str = br.readLine(); 
            } catch (IOException e) { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
}

class Point {
	int x;
	int y;
	public Point(int x, int y) {
		this.x = x;
		this.y = y;
	}
}

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

int main()
{
  int N; cin >> N;
  string S, T; cin >> S >> T;
  rep(i,N) cout << S.at(i) << T.at(i);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  ll N;
  cin>>N;
  ll Z=(ll)sqrt(2*N);
  if(2*N!=Z*(Z+1)){
    cout<<"No"<<endl;
  }else{
    VVI X(Z+1);
    X[0].push_back(1);
    X[1].push_back(1);
    int tmp=2;
    rep(i,Z-1){
      rep(j,2+i){
        X[j].push_back(tmp);
        X[2+i].push_back(tmp++);
      }
    }
    cout<<"Yes"<<endl;
    cout<<Z+1<<endl;
    rep(i,Z+1){
      cout<<Z;
      rep(j,Z) cout<<" "<<X[i][j];
      cout<<endl;
    }
  }
}

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

#define INF 999999999
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define all(v) v.begin(), v.end()
#define pub push_back
#define pob pop_back
#ifdef LOCAL
  #define de(e) cout << "L" << __LINE__ << ": " << e << "\n" // debug echo
  #define dr(e) cout << "L" << __LINE__ << ": " << #e << " -> " << e << "\n" // debug repr
#else
  #define de(e)
  #define dr(e)
#endif
#define out(fmt, ...) printf(fmt, __VA_ARGS__); printf("\n")
int gcd(int m, int n) { if((0 == m) || (0 == n)){return 0;} while(m != n){ if(m > n){m -= n;}else{n -= m;} } return m; }
int lcm(int m, int n) { if((0 == m) || (0 == n)){return 0;} return (m / gcd(m, n)) * n; }

//
// Implementation
//

int main() {
  int N;
  int M;
  scanf("%d %d", &N, &M);
  vector<string> flag(N);
  rep(i, N) cin >> flag[i];

  int ans = INF;

  for (int i=1; i<=N-2; i++) {

    for (int j=i+1; j<=N-1; j++) {
      dr(i << ":" << j);

      int acc = 0;
      
      for (int y=0; y<i; y++) {
        rep(x, M) {
          if (flag[y][x] != 'W') {
            acc++;
          }
        }
      }
  
      for (int y=i; y<j; y++) {
        rep(x, M) {
          if (flag[y][x] != 'B') {
            acc++;
          }
        }
      }

      for (int y=j; y<N; y++) {
        rep(x, M) {
          if (flag[y][x] != 'R') {
            acc++;
          }
        }
      }

      ans = min(ans, acc);
    }
  }

  out("%d", ans);
}

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

using namespace std;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    long long n, k;
    cin >> n >> k;
    int arr[n + 1];
    for (int i = 1; i <= n; i++)
        cin >> arr[i];
    int visit[200005] = {};
    visit[1] = 1;
    int time = 2;
    int next = arr[1];
    while (!visit[next]) {
        visit[next] = time;
        time++;
        next = arr[next];
    }
    int cycle_size = time - visit[next];
    int beg = visit[next] - 1;
    if (k > beg) {
        k -= beg;
        long long rem = k % cycle_size;
        k = beg + rem;
    }
    int res = 1;
    while (k--) {
        res = arr[res];
    }
    cout << res;

    return 0;
}

Measured memory_bytes: 5204
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;++i)
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	vector<long long>lengths;
	long long n;
	cin >> n;
	vector<long long>sums;
	long long ans =0;
	rep(i,n){
		long long temp;
		cin >> temp;
		lengths.push_back(temp);
		if(i==0)sums.push_back(temp);
		else sums.push_back(sums[i-1]+temp);
	}
	rep(i,n){
		if(sums[i]>sums[n-1]/2){
			ans = min(abs(sums[n-1]-2*sums[i-1]),abs(sums[n-1]-2*sums[i]));
			break;
		}
	}
	cout <<ans<<endl;
	return 0;
}


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

//template
typedef long long int ll;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define repr(i,n) for(ll i=n;i>0;i--)
#define all(v) v.begin(),v.end()
#define in cin>>
#define out cout<<
#define en <<endl
const ll INF = 10000000000000;

int main()
{
	//ll n, ans;
	vector<vector<ll>> A(3, vector<ll>(3));
	rep(i, 3)
	{
		rep(j, 3)
		{
			in A.at(i).at(j);
		}
	}
	ll n;
	in n;
	rep(i, n)
	{
		ll x;
		in x;
		rep(j, 3)
		{
			rep(k, 3)
			{
				if (A.at(j).at(k) == x)
				{
					A.at(j).at(k) = 0;
				}
			}
		}
	}
	bool ans = false;
	rep(i, 3)
	{
		if (A.at(i).at(0) == 0 && A.at(i).at(1) == 0 && A.at(i).at(2) == 0)
		{
			ans = true;
			break;
		}
		if (A.at(0).at(i) == 0 && A.at(1).at(i) == 0 && A.at(2).at(i) == 0)
		{
			ans = true;
			break;
		}
	}
	if (A.at(0).at(0) == 0 && A.at(1).at(1) == 0 && A.at(2).at(2) == 0)
		ans = true;
	if (A.at(0).at(2) == 0 && A.at(1).at(1) == 0 && A.at(2).at(0) == 0)
		ans = true;
	if (ans)
		out "Yes" en;
	else
		out "No" en;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
int N, M, ans;
vector<int> v[100001];
priority_queue<int> q;
int main() {
  scanf("%d %d", &N, &M);
  for(int i = 0, A, B; i < N; ++i) {
    scanf("%d %d", &A, &B);
    v[A].push_back(B);
  }
  for(int i = 1; i <= M; ++i) {
    for(int j = 0; j < v[i].size(); ++j) q.push(v[i][j]);
    if(q.empty()) continue;
    ans += q.top(), q.pop();
  }
  printf("%d\n", ans);
}

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

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    if(s.length()<=n)
    {
        cout<<s<<endl;
    }else{
        string temp=s.substr(0,n);
        temp+="...";
        cout<<temp<<endl;
    }
}

Measured memory_bytes: 3620
package main

import (
	"fmt"
	"sort"
)

func main() {
	var s, t string
	fmt.Scan(&s, &t)

	ss := s + s
	cs := make(map[string][]int)
	for i := 0; i < len(ss); i++ {
		c := string(ss[i])
		cs[c] = append(cs[c], i)
	}

	n := len(s)
	ans := 0
	p := 0
	for i := 0; i < len(t); i++ {
		c := string(t[i])
		a := cs[c]
		if len(a) == 0 {
			fmt.Println(-1)
			return
		}

		x := sort.Search(len(a), func(i int) bool {
			return p <= a[i]
		})
		p = a[x] + 1
		if n <= p {
			p -= n
			ans += n
		}
	}
	ans += p

	fmt.Println(ans)
}


Measured memory_bytes: 10624
#include <bits/stdc++.h>
#include <math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define PI 3.14159265359
using namespace std;
using ll = long long;
using P = pair<int, int>;

int hist[100000];

int main() {
  int n;
  cin >> n;
  rep(i, 100000) hist[i] = 0;
  ll sum = 0;
  rep(i, n) {
    int a;
    cin >> a;
    hist[a - 1]++;
    sum += a;
  }

  int q;
  cin >> q;
  vector<P> query(q);
  rep(i, q) {
    cin >> query[i].first >> query[i].second;
  }

  rep(i, q) {
    ll b = query[i].first - 1, c = query[i].second - 1;
    sum += (c - b) * hist[b];
    hist[c] += hist[b];
    hist[b] = 0;
    cout << sum << endl;
  }

  return 0;
}

/*
*/


Measured memory_bytes: 4228
#include<iostream>
using namespace std;
int main(){
	int n, x, count;
	while (1){
		count = 0;
		cin >> n >> x;
		if (n == 0 && x == 0)break;
		for (int i = 1; i <= n-2; i++){
			for (int j = i+1; j <= n-1; j++){
				for (int k = j+1; k <= n; k++){

					if (i + j + k == x){
						count++;
					}
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}


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

#include <bits/stdc++.h>

#include <atcoder/math>
using namespace std;
using ll = long long int;

int main(int, char **) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;

    for (int i = 0; i < t; i++) {
        int n, m, a, b;
        cin >> n >> m >> a >> b;
        cout << atcoder::floor_sum(n, m, a, b) << "\n";
    }

    fflush(stdout);
}


Measured memory_bytes: 3620
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
    out << '(' << p.first << ',' << p.second << ')';
    return out;
}

template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
    in >> p.first >> p.second;
    return in;
}

template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
    for (T &x : v)
        in >> x;
    return in;
}

template <class T>
ostream& operator << (ostream& out, const vector<vector<T>> &v)
{
    for (const vector<T> &x : v)
        out << x << '\n';
    return out;
}

template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
    for (const T &x : v)
        out << x << ' ';
    return out;
}

long long gcd (long long a, long long b)
{
    if (b > a)
        swap(a, b);
    return (b ? gcd(b, a % b) : a);
}

using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define F          first
#define S          second
#define First      first.first
#define Second     first.second
#define Third      second
#define mp         make_pair
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define per(i,b,a) for (int i = (b); i > (a); i--)
#define all(x)     x.begin(), x.end()
#define ret(x)     return cout << x, 0;
#define throwex    throw runtime_error ("Found the error.");

const int h = 1000000007;

signed main()
{
    ios::sync_with_stdio(false);
    #ifdef ONLINE_JUDGE
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.setstate(ios::failbit);
    #endif

    int n;
    cin >> n;
    vl v(n);
    cin >> v; 
    rep(i,0,n)
        v[i] -= i;
    sort(all(v));
    ll p = 0, s = accumulate(all(v), 0LL);
    ll mn = LLONG_MAX;
    rep(i,0,n)
    {
        mn = min(mn, i * v[i] - p + s - (n - i) * v[i]);
        s -= v[i];
        p += v[i];
    }
    cout << mn;
}


Measured memory_bytes: 4728
t = list(map(int, input().split()))
k = list(map(int, input().split()))

h = 0
for i in range(0,len(k)-1):
    if (k[i+1]-k[i])*t[1] > t[2]:
        h += t[2]
    else:
        h += (k[i+1]-k[i])*t[1]
print(h)

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

typedef long long ll;

 
int main(){
  int a, b;
  cin >> a >> b;
  string ans;
  if(a%3==0 || b%3==0 || (a+b)%3==0) ans = "Possible";
  else ans = "Impossible";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		long a = scanner.nextInt();
		long b = scanner.nextInt();
		long c = scanner.nextInt();
		
		if(4*a*b<(c-a-b)*(c-a-b) && c - a - b > 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 22612
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

void Main()
{
	int A, B;
	std::cin >> A >> B;
	auto c = std::abs(B - A);
	if (c % 2 == 1)
	{
		std::cout << "IMPOSSIBLE" << std::endl;
	}
	else
	{
		std::cout << std::min(A, B) + c / 2 << std::endl;
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 256