akhauriyash/Code-Regression huggingface dataset:
def main():
    n,m,k = input().split()
    n=int(n)
    m=int(m)
    k=int(k)

    n_list = list(map(int,input().split()))
    m_list = list(map(int,input().split()))
    a, b =[0],[0]
    for i in range(n):
        a.append(a[i]+n_list[i])
    for j in range(m):
        b.append(b[j]+m_list[j])
    
    j=m
    ans = 0
    for i in range(n+1):
        if a[i]>k:
            break
        while b[j]+a[i]>k:
            j -= 1
        ans = max(ans,i+j)
    print(ans)
main()

Measured memory_bytes: 47524
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {

		int N = nextInt();
		long[] A = nextLongs();

		long sum = 0;
		int idx=0;
		for(int i=0;i<N;i++){
			sum+=A[i];
		}
		long sl = A[0]*2;
		long sr = A[N-1]*2;
		for(int i=1;i<N-1;i++){
			if(sl<sum){
				sl+=A[i]*2;
				idx=i;
			}else{
				sr+=A[i]*2;
			}
		}
		long x=Math.abs(sl-sr)/2;
		long y= Math.abs(sl-4*A[idx]-sr)/2;
		System.out.println(Math.min(x,y));
	}

	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


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

const int MAXN = 2e3+5;
const int INF = 1e9+7;
#define ll long long
#define pb push_back
#define endl '\n'
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

ll MOD(ll a){
    return ((a%INF)+INF)%INF;
}

ll inv(ll a){
    return poww(a,INF-2,INF);
}

char a[MAXN][MAXN];
ll dp[MAXN][MAXN];

int main()
{
    fast_io;
    //cout << fixed << setprecision(15);

    int n,m;cin >> n >> m;
    for(int i=1;i<=n;++i){
        for(int j=1;j<=m;++j){
            cin >> a[i][j];
        }
    }

    dp[1][1] = 1;
    for(int i=1;i<=n;++i){
        for(int j=1;j<=m;++j){
            if((i!=1 || j!=1) && a[i][j] != '#') dp[i][j] = MOD(dp[i-1][j] + dp[i][j-1]);
        }
    }
    cout << dp[n][m];
}


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

typedef long long ll;

int popcount(int n) {
    int ret = 0;
    while (n > 0) {
        ret += n % 2;
        n /= 2;
    }
    return ret;
}

int main() {
    int N;
    string X;
    cin >> N >> X;
    vector<int> f(200000, 0);
    for (int i = 1; i < 200000; i++) {
        f[i] = f[i % popcount(i)] + 1;
    }
    //rep(i, 10) cout << f[i] << "\n";
    ll p = 0;
    rep(i, N) if (X[i] == '1') p++;
    vector<int> ans(N);
    if (p == 0) {
        rep(i, N) ans[i] = 1;
    } else if (p == 1) {
        rep(i, N) {
            if (X[i] == '0') {
                if (i == N - 1) ans[i] = 2;
                else ans[i] = 1;
            } else {
                ans[i] = 0;
            }
        }
    } else {
        ll q = (p - 1) * (p + 1), r = 0;
        rep(i, N) {
            r = r * 2 + X[i] - '0';
            r = r % q;
        }
        ll d = 1;
        for (int i = N - 1; i >= 0; i--) {
            if (X[i] == '1') {
                ll s = (r + q - d) % (p - 1);
                ans[i] = f[s] + 1;
            } else {
                ll s = (r + d) % (p + 1);
                ans[i] = f[s] + 1;
            }
            d = (d * 2) % q;
        }
    }
    rep(i, N) cout << ans[i] << "\n";
}

Measured memory_bytes: 5180
/*..............................................*\
Author:Kishor Kumar Paroi
Dept:CSE-1703053
email.kishor.josephite@gmail.com
RUET,BANGLADESH
\*---------------------------*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <sstream>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include<bits/stdc++.h>
#include<iostream>
#include<iterator>

#define max(a,b) ((a>b)?a:b)                        //finding max
#define min(a,b) ((a<b)?a:b)                        //finding min
#define Max(a,b,c) max(a,max(b,c))                  //finding max between 3 numbers
#define Min(a,b,c) min(a,min(b,c))                  //finding min between 3 numbers
#define Pi acos(-1.0)                               //defining Pi for mathematical uses
#define Clear(a) memset(a,0,sizeof(a))              //clearing memory of an array
#define setfalse(a) memset(a,false,sizeof(a))       //setting the array into false
#define settrue(a) memset(a,true,sizeof(a))         //setting the array into true
#define clrstr(a) memset(a,'\0',sizeof(a))          //setting string array to null
#define open freopen("input.txt","r",stdin)         //opening input file
#define close freopen ("output.txt","w",stdout)     //opening output file
#define Case(a) printf("Case %d: ",a)               //printing case number
#define caseh(a) printf("Case #%d: ",a)             //printing case number having '#'
#define getcase(a) scanf("%d",&a)                   //scanning case number
#define caseloop(a,b) for(a=1;a<=b;a++)             //making case loop
#define EPS 1e-9                                    //small value for avoiding preccesion error
#define LL long long                                //long long short form
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

//const int N=100*1000;
//const int mod=1e9+7;

//# define int min3(int a,int b,int c){return min(a,min(b,c));}
//#define int max3(int a,int b,int c){return max(a,max(b,c));}
//#define int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
//#define int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    char s[101];
    int n,k,i;
    cin>>n>>k;
    for(i=0; i<n; i++)
        cin>>s[i];
    for(i=0; i<n; i++)
    {
        if(i==k-1)
        {
            s[i]=tolower(s[i]);
            cout<<s[i];
        }
        else
            cout<<s[i];

    }
    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
AS = list(map(int, input().split()))
FS = list(map(int, input().split()))
AS.sort(); FS.sort(reverse=True)

def isValid(x):
    import math
    trains = 0
    for i in range(N):
        num = AS[i] * FS[i]
        if num <= x: continue
        trains += math.ceil((num - x) / FS[i])
    return trains <= K

def binarySearch(lo, hi):
    if lo >= hi:
        return lo
    mid = lo + (hi - lo) // 2
    if isValid(mid):
        return binarySearch(lo, mid)
    else:
        return binarySearch(mid + 1, hi)
            
print(binarySearch(0, max(AS[i] * FS[i] for i in range(N))))


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

void solve(){
    string s;
    cin >> s;

    for (int i = 0; i < (int)s.size()-8; i++) {
        cout << s[i];
    }
    cout << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


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

int main(){
int a,b,c,data[3],yojo1,yojo2,sho1,sho2,cnt=0,m;
cin >> a >> b >> c;
data[0]=a;
data[1]=b;
data[2]=c;

sort(data,data+3);

if((data[2]*3)%2 == (data[0]+data[1]+data[2])%2)
    m = data[2];
else 
    m = data[2]+1;

if (m == data[2]){
yojo1 = (data[2]-data[0])%2;
sho1 = (data[2]-data[0])/2;
yojo2 = (data[2]-data[1])%2;
sho2 = (data[2]-data[1])/2;
cnt = sho1+sho2+yojo1;
}
if (m == data[2]+1){
yojo1 = (m-data[0])%2;
sho1 = (m-data[0])/2;
yojo2 = (m-data[1])%2;
sho2 = (m-data[1])/2;
cnt = sho1+sho2+yojo1+yojo2;
}
cout << cnt << endl;


}

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

long long n, k, s;
vector<long long> a;

void solve();

int main() {
  cin >> n >> k >> s;
  solve();
  for(int i = 0; i < n; ++i) {
    if(i != 0) cout << " ";
    cout << a[i];
  }
  cout << endl;
  return 0;
}

void solve() {
  for(int i = 0; i < k; ++i) a.push_back(s);
  while(a.size() < n) {
    if(s == (long long)1e9)
      a.push_back(1);
    else
      a.push_back(1e9);
  }
}

Measured memory_bytes: 2292
# include<bits/stdc++.h> 
#define ll long long 
#define pb push_back 
#define mk make_pair
#define vi vector<int> 
#define loop(i,j, k ) for(int i =j ;i < k ; ++i)
using namespace std ; 


int main() {
	int n ; 
	cin >> n; 
	int a[n] ; 
	loop(i,0,n) cin >> a[i] ; 
	ll dp[n] ; 
	dp[0]=0 ; 
	dp[1] = abs(a[1]-a[0]); 
	for(int i = 2; i < n ; ++i)
	dp[i]  = min(abs(a[i] - a[i-1]) + dp[i-1], abs(a[i]-a[i-2])+ dp[i-2])  ; 
	cout <<  dp[n-1] ; 
}

Measured memory_bytes: 1408
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int a[N];
int main()
{
    int n;scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int l=1,r=1,tmp=0;ll sum=0;
    while(r<=n)//枚举l,找到最优的r.
    {
        while((a[r]^tmp)==(a[r]+tmp)&&r<=n)
            tmp^=a[r],r++;
        if(r!=n+1)
            sum+=r-l;//分别指区间[l,r-1],[l+1,r-1],[l+2,r-1]....[r-1,r-1].
        else
            sum+=(ll)(r-l)*(ll)(r-l+1)/(ll)2;//因为r==n+,要break了,所以不能只加以l为起点向r-1扩展的,还应加从l+1,l+2...r-1出发的,故sum+=r-l+r-(l+1)+r-(l+2)+...+r-(r-1).
        tmp^=a[l],l++;//tmp的值把异或的a[l]去掉,l右移.
    }
    printf("%lld\n",sum);
}

Measured memory_bytes: 1024
using System;

namespace ITP1_4_A
{
    class Program
    {
        static void Main()
        {
            string[] x = Console.ReadLine().Split(' ');
            int a = int.Parse(x[0]);
            int b = int.Parse(x[1]);
            
            int d = a / b;
            int r = a % b;
        
            decimal f = (decimal)a / (decimal)b;
        
            Console.WriteLine("{0} {1} {2}", d, r, f);
        }
    }
}


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

int h,w;
int nx[4] = {1,-1,0,0};
int ny[4] = {0,0,1,-1};
char memo[51][51];
bool ch=0;

int main(){
  int i,j,k,xx,yy;
  cin >> h >> w;
  for(i=1;i<=h;i++)for(j=1;j<=w;j++)cin >> memo[i][j];

  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      int bl=0;
      if(memo[i][j]=='#'){
	for(k=0;k<4;k++){
	  xx = i + nx[k];
	  yy = j + ny[k];
	  if(xx>=1&&xx<=h&&yy>=1&&yy<=w&&memo[xx][yy]=='#')bl++;
	}
	if(bl==0)ch++;
      }
    }
  }
  if(ch==0)cout << "Yes" << endl;
  else cout <<"No" << endl;

  return 0;
}


Measured memory_bytes: 256
def main():
  x,n = map(int,input().split())
  if(n==0):
    print(x)
    return 0
  p = list(map(int,input().split()))
  if(not x in p):
    print(x)
    return 0
  d=1
  while(True):
    if(not x-d in p):
      print(x-d)
      return 0
    elif(not x+d in p):
      print(x+d)
      return 0
    d+=1

main()

Measured memory_bytes: 9192
#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 all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w;
	cin >> h >> w;
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	int pos = 0;
	vector<vector<int>> mp(h, vector<int>(w));
	rep(i, h) {
		if (i % 2 == 0) {
			for (int j = 0; j < w; ++j) {
				mp[i][j] = pos + 1;
				a[pos]--;
				if (a[pos] == 0) pos++;
			}
		}
		else {
			for (int j = w - 1; j >= 0; --j) {
				mp[i][j] = pos + 1;
				a[pos]--;
				if (a[pos] == 0) pos++;
			}
		}
	}
	rep(i, h) {
		rep(j, w) cout << mp[i][j] << (j == w - 1 ? "\n" : " ");
	}
	return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    string s; cin >> s;
    cout << s.substr(0, s.size()-8) << endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);

        final String line = scanner.nextLine();
        System.out.println(
                line.charAt(0) == line.charAt(1) ||
                        line.charAt(1) == line.charAt(2) ||
                        line.charAt(2) == line.charAt(3)
                        ? "Bad" : "Good");
    }
}

Measured memory_bytes: 23248
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<map>

using namespace std;
#define mod 1000000007
#define ll long long 


ll n,w, a[100009], b[100009];
ll dp[109][100009];

// map<int, map<ll, ll> > dp;
 
ll solve(int r, int idx) {
    if(idx == n)
        return r == 0 ? 0 : INT_MAX;

    if(dp[idx][r] != -1)
    	return dp[idx][r];

    ll ans = solve(r, idx + 1);
    if(b[idx] <= r)
    	ans = min(ans, a[idx] + solve(r - b[idx], idx + 1));
     
    return dp[idx][r] = ans;
}

int s(int v_max) {

	for(int i = v_max; i >= 0; i--) {
		if(solve(i, 0) <= w)
			return i;
	}
	return 0;
}
 
int main() {
 
    // int t;
    // cin>>t;
    // while(t--) {
        cin>>n>>w;
        memset(dp, -1, sizeof(dp));

        int v_max = 0;

        for(int i = 0; i < n; i++) {
            cin>>a[i]>>b[i];
            v_max += b[i];
        }

        cout<<s(v_max)<<endl;

}


Measured memory_bytes: 88796
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int op(int a,int b){
	return a+b;
}

int e(){return 0;}

bool f(int x){return (x==0);}

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	vector<P> v1,v2,vt;
	cin>>n;
	dsu ua(n);
	segtree<int,op,e> seg(n);
	for(i=0;i<n;i++){
		cin>>a>>b;
		a--,b--;
		vt.push_back(make_pair(a,b));
		v1.push_back(make_pair(a,i));
		v2.push_back(make_pair(b,i));
	}
	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());
	
	for(i=0;i<n;i++){
		j=v1[i].second;
		a=vt[j].second;
		while(1){
			b=seg.min_left<f>(a);
			if(b==0)break;
			b--;
			seg.set(b,0),a=b;
			ua.merge(j,v2[b].second);
		}
		seg.set(a,1);
	}
	for(i=0;i<n;i++){
		cout<<ua.size(i)<<endl;
	}
}

Measured memory_bytes: 11204
#include <iostream>
#include <vector>

using namespace std;

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

    string S;
    cin >> S;

    int now = N;
    vector<int> ans;
    bool pos = true;
    while(now != 0){
        bool fl = false;
        for(int i=M; i>0; i--){
            int next = now - i;
            if(next < 0) continue;
            if(S[next] == '1') continue;
            fl = true;
            ans.push_back(i);
            now = next;
            break;
        }
        if(!fl){
            pos = false;
            break;
        }
    }

    if(!pos){
        cout << -1 << endl;
    }else{
        for(int i=ans.size()-1; i>=0; i--){
            cout << ans[i] << " ";
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1144
#include <cstdio>

char s[304];
int _a[608][608], (*const a)[608] = _a + 304;
int _b[608][608], (*const b)[608] = _b + 304;

int main() {
	int n, m;
	scanf("%d%d",&n,&m);
	for (int i = 0; i < n; i++) {
		scanf("%s",s);
		for (int j = 0; j < m; j++)
			a[i-j][i+j] = s[j] == '#';
	}
	for (int i = 1-m; i < n; i++) {
		b[i][0] = 0;
		for (int j = 0; j < n+m-1; j++)
			b[i][j+1] = b[i][j] + a[i][j];
	}
	long long ans = 0;
	for (int i = 1-m; i < n; i++)
		for (int j = 1; j < n+m-1; j++) if (a[i][j])
			for (int k = 0; k < j; k++) if (a[i][k]) {
				int d = j-k;
				if (i+d < n) ans += b[i+d][j+1] - b[i+d][k];
				if (i-d > -m) ans += b[i-d][j+1] - b[i-d][k];
			}
	for (int j = 0; j < n+m-1; j++) {
		b[0][j] = 0;
		for (int i = 1-m; i < n; i++)
			b[i+1][j] = b[i][j] + a[i][j];
	}
	for (int i = 0; i < n+m-1; i++)
		for (int j = 2-m; j < n; j++) if (a[j][i])
			for (int k = 1-m; k < j; k++) if (a[k][i]) {
				int d = j-k;
				if (i+d < n+m-1) ans += b[j][i+d] - b[k+1][i+d];
				if (i-d >= 0) ans += b[j][i-d] - b[k+1][i-d];
			}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3072
let rec gcd n m =
  if m = 0 then n else gcd m (n mod m)

let m = 1000000007
let ( +^ ) x y = (x + y) mod m
let ( -^ ) x y = x +^ (m - y)
let ( *^ ) x y = (x * y) mod m

let rec power ( * ) e m n =
  if n <= 0 then e
  else power ( * ) (if n land 1 = 0 then e else m * e) (m * m) (n lsr 1)

type quotient = Nan | Zero | Inf | Quotient of int * int

let quotient_of_intpair = function
  | (0, 0) -> Nan
  | (0, _) -> Zero
  | (_, 0) -> Inf
  | (a, b) ->
      let d = gcd (abs a) (abs b) in
      if b < 0
      then Quotient (~- a / d, ~-b / d)
      else Quotient (a / d, b / d)

let inv = function
  | Zero -> Inf
  | Inf -> Zero
  | Quotient (a, b) -> Quotient (b * compare 0 a, abs a)

module QuotientMap = Map.Make (struct
  type t = quotient
  let compare = compare
end)

let () = Scanf.scanf "%d\n" @@ fun n ->
  let abs = List.init n @@ fun _ -> Scanf.scanf "%d %d\n" @@ fun a b -> quotient_of_intpair (a, b) in
  let zeros, m =
    List.fold_left (fun (zeros, m) -> function
      | Nan -> (zeros + 1, m)
      | q ->
          zeros,
          QuotientMap.update q (fun o -> Some (1 + Option.value ~default:0 o)) @@
          QuotientMap.update (inv q) (fun o -> Some (Option.value ~default:0 o)) m) (0, QuotientMap.empty) abs in
  Printf.printf "%d\n" @@
  ( +^ ) (zeros -^ 1) @@
  QuotientMap.fold (fun q n acc ->
    match q with
    | Zero -> acc
    | Quotient (a, _) when a < 0 -> acc
    | _ ->
        let n' = QuotientMap.find (inv q) m in
        acc *^ (power ( *^ ) 1 2 n +^ power ( *^ ) 1 2 n' -^ 1)) m 1


Measured memory_bytes: 63100
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}

const int MAX_N = 1e5 + 10;
int N;
int128_t A[MAX_N];
int128_t ret[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N;

    for (int i = 1; i <= N; i++) {
        std::cin >> A[i];
    }

    int128_t tmp = 0;
    for (int i = 1; i <= N; i++) {
        if (i % 2 == 1) {
            tmp += A[i] * 2;
        } else {
            tmp -= A[i] * 2;
        }
    }
    ret[1] = tmp / 2;

    for (int i = 2; i <= N; i++) {
        ret[i] = A[i-1]*2 - ret[i-1];
    }

    for (int i = 1; i <= N; i++) {
        std::cout << ret[i] << " ";
    }
    std::cout << std::endl;

    return 0;
}

Measured memory_bytes: 4480
//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<bits/stdc++.h>
#define MAX 1000000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3F3F3F3F
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
	if(x==0)
	return "0";
	string ret="";
	while(x){
		ret=ret+(char)(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
string add(string a,string b){
	if(a=="")
	a="0";
	if(b=="")
	b="0";
	if(a.length()<b.length())
	swap(a,b);
	while(b.length()<a.length()){
		b='0'+b;
	}
	for(int i=0;i<a.length();i++){
		a[i]=a[i]+(b[i]-'0');
	}
	bool big=false;
	for(int i=a.length()-1;i>=0;i--){
		if(big){
			a[i]++;
		}
		big=false;
		if(a[i]>'9'){
			a[i]=a[i]-10;
			big=true;
		}
	}
	if(big)
	a='1'+a;
	return a;
}
string mul(string a,string b){
	vector<int> va,vb;
	if(a=="0" || b=="0")
	return "0";
	string ans;
	for(int i=0;i<a.length();i++){
		va.push_back(a[i]-'0');
	}
	for(int i=0;i<b.length();i++){
		vb.push_back(b[i]-'0');
	}
	reverse(va.begin(),va.end());
	reverse(vb.begin(),vb.end());
	vector<int> res;
	res.clear();
	res.resize(1005);
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			res[i+j]+=(va[i]*vb[j]);
		}
	}
	for(int i=0;i<1005;i++){
		if(res[i]>9){
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	for(int i=0;i<1005;i++){
		ans+=(res[i]+'0');
	}
	reverse(ans.begin(),ans.end());
	int k=0;
	while(ans[k]=='0'){
		k++;
	}
	ans=ans.substr(k);
	return ans;
}
bool is_prime(int n){
	if(n<2)
    return false;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
    return false;
    return true;
}
int n; 
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin>>n;
	if(n%2==0){
		cout<<(n/2)*(n/2);
	}
	else{
		cout<<(n/2)*(n/2+1);
	}
	//system("pause");
	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll h,n,tong;
int main()
{
    cin >> h >> n;
    for(ll i = 1;i <= n;i ++)
    {
        ll u;
        cin>>u;
        tong+=u;
    }
    tong >= h ? cout << "Yes" : cout << "No" ;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)

/*unsigned int xor128(void)
{
    static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned int t = (x ^ (x << 11));
    x = y;
    y = z;
    z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
unsigned int xor128rnd(unsigned int m)
{
    return xor128() % m;
}*/

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll a[110];
ll a1[110][12];

int getidx[110];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    //cout << fixed << setprecision(15);

    int N;
    cin >> N;
    string s, t;
    cin >> s >> t;

    int ans = 0;
    for (int i = N - 1; i >= 0; --i)
    {
        for (int j = 0; j < N - i; ++j)
        {
            if (s[i + j] != t[j])
                break;

            if (j == N - i - 1)
            {
                ans = 2 * N - N + i;
            }
        }
    }
    if (ans == 0)
        ans = 2 * N;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
ans = [0,0,0,0]
for i in range(N):
    S = input()
    if S == "AC" :
        ans[0] += 1 
    elif S == "WA" :
        ans[1] += 1
    elif S == "TLE" :
        ans[2] += 1
    else :
        ans[3] += 1

print("AC x " + str(ans[0]))
print("WA x " + str(ans[1]))
print("TLE x " + str(ans[2]))
print("RE x " + str(ans[3]))




Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
void solve() {
    int n,cnt=0,ans=0;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++) cin>>v[i];
    for(int i=0;i<n-1;i++) {
        if(v[i]>=v[i+1])
            v[i]=1;
        else
            v[i]=0;
    }
    for(int i=0;i<n-1;i++) {
        if(v[i]) {
            cnt++;
            ans=max(ans,cnt);
        }
        else {
            ans=max(ans,cnt);
            cnt=0;
        }
    }
    cout<<ans<<endl;
}
int main(int argc, char const *argv[]) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    solve();
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vel;
typedef vector<string> ves;
typedef vector<int> vei;
typedef vector<vector<ll>> vvel;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main() {
    string s;
    cin >>s;
    int a=s.size();
    rep(i,a) {
        if(s[i]=='?'&&s[i-1]=='P') s[i]='D';
        else if(s[i]=='?') s[i]='D';
    }
    cout <<s<<endl;
}

Measured memory_bytes: 3716
N,M,C = map(int,input().split())
#N = int(input())
B = list(map(int,input().split()))
A=[]
for i in range(N):
    a = list(map(int,input().split()))
    A.append(a)
c=0

for i in range(N):
    ans=0
    for j in range(M):
        ans += A[i][j] * B[j]

    if ans + C > 0:
        c+=1
print(c)


Measured memory_bytes: 3064
macro_rules !read_value {($iter :expr ,($($t :tt ) ,*) ) =>{($(read_value !($iter ,$t ) ) ,*) } ;($iter :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($iter ,$t ) ) .collect ::<Vec <_ >>() } ;($iter :expr ,{chars :$base :expr } ) =>{read_value !($iter ,String ) .chars () .map (|c |(c as u8 -$base as u8 ) as usize ) .collect ::<Vec <usize >>() } ;($iter :expr ,{char :$base :expr } ) =>{read_value !($iter ,{chars :$base } ) [0 ] } ;($iter :expr ,chars ) =>{read_value !($iter ,String ) .chars () .collect ::<Vec <char >>() } ;($iter :expr ,char ) =>{read_value !($iter ,chars ) [0 ] } ;($iter :expr ,usize1 ) =>{read_value !($iter ,usize ) -1 } ;($iter :expr ,$t :ty ) =>{$iter .next () .unwrap () .parse ::<$t >() .unwrap () } ;}
macro_rules !input_inner {($iter :expr ) =>{} ;($iter :expr ,) =>{} ;($iter :expr ,mut $var :ident :$t :tt $($r :tt ) *) =>{let mut $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,mut $var :ident $($r :tt ) *) =>{input_inner !{$iter ,mut $var :usize $($r ) *} } ;($iter :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,$var :ident $($r :tt ) *) =>{input_inner !{$iter ,$var :usize $($r ) *} } ;}
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;(iter =$iter :ident ,$($r :tt ) *) =>{let s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut $iter =s .split_whitespace () ;input_inner !{$iter ,$($r ) *} } ;($($r :tt ) *) =>{let s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut iter =s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;}
fn subabs(x: usize, y: usize) -> usize {
    if x > y {
        x - y
    } else {
        y - x
    }
}
use std::cmp::max;
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);
impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<std::cmp::Ordering> {
        other.0.partial_cmp(&self.0)
    }
}
impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> std::cmp::Ordering {
        other.0.cmp(&self.0)
    }
}
fn main() {
    input! { n, a: [usize; n] };
    let mut idx = (0..n).collect::<Vec<_>>();
    idx.sort_by_key(|&i| Rev(a[i]));
    let mut dp = vec![vec![0; n + 1]; n + 1];
    for i in 0..n {
        let ii = idx[i];
        for j in 0..i + 1 {
            let d = dp[j][i - j];
            dp[j + 1][i - j] = max(dp[j + 1][i - j], d + a[ii] * subabs(ii, j));
            dp[j][i + 1 - j] = max(dp[j][i + 1 - j], d + a[ii] * subabs(ii, n - 1 - (i - j)));
        }
    }
    let mut ans = 0;
    for i in 0..n + 1 {
        ans = max(ans, dp[i][n - i]);
    }
    println!("{}", ans);
}


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

int main(){
  int a,b,i;cin>>a>>b;char c;bool f=1;
  for(i=0;i<a+b+1;i++){
    cin>>c;
    if((i<a&&c=='-')||(i==a&&c!='-')||(i>a&&c=='-')) f=0;
  }
  cout<<(f?"Yes":"No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

i64 N, M;
vector<vector<pair<i64, i64>>> G;
vector<i64> D;
vector<i64> cost;
vector<i64> C;
vector<i64> R;

int main() {
  cin >> N >> M;
  G.resize(N);
  D.resize(N);
  C.resize(N, -1);
  R.resize(N);
  cost.resize(M, 1e9);
  rep(i,0,N) {
    cin >> D[i];
  }
  rep(i,0,M) {
    i64 a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back({b, i});
    G[b].push_back({a, i});
  }
  rep(i,0,N) {
    if(C[i] == -1) {
      queue<i64> que;
      que.push(i);
      while(!que.empty()) {
        i64 v = que.front();
        que.pop();
        for(auto e: G[v]) {
          i64 to = e.first;
          i64 ei = e.second;
          if(C[to] == -1 && D[v] == D[to]) {
            C[i] = 0;
            C[to] = C[v] ^ 1;
            cost[ei] = D[v];
            que.push(to);
          }
        }
      }
    }
  }
  rep(i,0,N) {
    if(C[i] != -1) {
      queue<i64> que;
      i64 color = C[i];
      que.push(i);
      while(!que.empty()) {
        i64 v = que.front();
        que.pop();
        for(auto e: G[v]) {
          i64 to = e.first;
          i64 ei = e.second;
          if(C[to] == -1 && D[v] < D[to]) {
            C[to] = color;
            cost[ei] = D[to] - D[v];
            que.push(to);
          }
        }
      }
    }
  }

  i64 OK = true;
  rep(i,0,N) {
    if(C[i] == -1) OK = false;
  }
  if(!OK) {
    cout << -1 << endl;
    return 0;
  }
  rep(i,0,N) {
    if(C[i] == 0) cout << "B";
    else cout << "W";
  }
  cout << endl;
  rep(i,0,M) {
    cout << cost[i] << endl;
  }
}



Measured memory_bytes: 18304
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N;
  cin >> N;
  long odd = N / 2;
  if (N % 2 != 0) odd++;

  double ans = (1.0 * odd) / N;

  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  if (n <= k) {
    cout << s << endl;
  } else {
    cout << s.substr(0, k) << "..." << endl;
  }
  return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

class mint {
    long long x;
public:
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};
/* -- template -- */

ll ans = LLINF;

void solve(ll x, ll y) {
    ll maxS, minS;
    for(ll i = 1; i < x; ++i) {
        maxS = max(y * i, (x - i) * (y + y % 2) / 2);
        minS = min(y * i, (x - i) * (y / 2));
        ans = min(ans, maxS - minS);
    }
    for(ll i = 1; i < x - 1; ++i) {
        maxS = max(y * i, y * (x - i + (x - i) % 2) / 2);
        minS = min(y * i, y * ((x - i)/ 2));
        ans = min(ans, maxS - minS);
    }
}


int main() {
    ll H, W; cin >> H >> W;
    solve(H, W);
    solve(W, H);
    cout << ans << endl;
}


Measured memory_bytes: 256
N=int(input())
S=input()
r=S.count('R')
b=S.count('B')
g=S.count('G')
ans=r*b*g
for i in range(N):
    for s in range(N):
        j=i+s
        k=j+s
        if k>=N:
            break
        if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans-=1
print(ans)

Measured memory_bytes: 9240
#include <stdio.h>

int main(void) {
	long a,b;
	long d,r;
	double f;
	
	scanf("%ld %ld", &a, &b);
	
	d=a/b;
	r=a%b;
	f = (double)a/b;
	
	printf("%ld %ld %.5lf\n", d, r, f);
	
	return 0;
}

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

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	std::string s; cin >> s;

	for(int i = 0; i < s.size(); i++) {
		for(int j = i; j <= s.size(); j++) {
			std::string t = s.substr(0, i) + s.substr(j, s.size() - i);
			if(t != "keyence") continue;
			printf("YES\n");
			return 0;
		}
	}
	
	printf("NO\n");
	return 0;
}


Measured memory_bytes: 256
import itertools


def main():
    N = int(input())
    d = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for _ in range(N):
        S = input()
        if S[0] in d:
            d[S[0]] += 1
    print(sum(d[a] * d[b] * d[c]
              for a, b, c in list(itertools.combinations(d.keys(), 3))))


main()


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder
{
    class AC
    {
        const int MOD = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;
        const double EPS = 1e-8;
        static readonly int[] dx = { 0, 1, 0, -1 };
        static readonly int[] dy = { 1, 0, -1, 0 };
        static int N, X, Y, Z;
        
        static void Main(string[] args)
        {
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
            var cin = new Scanner();
            
            var input = cin.SplitRead();
            N = input[0];
            X = input[1];
            Y = input[2];
            Z = input[3];


            var pow10 = new long[N + 1];
            pow10[0] = 1;
            for (var i = 1; i <= N; i++)
            {
                pow10[i] = (pow10[i - 1] * 10) % MOD;
            }

            long bit = 1 << (X + Y + Z);
            

            var dp = new long[N + 1, bit];
            for(var i = 0; i <= N; i++)
            {
                for(var j = 0; j < bit; j++)
                {
                    dp[i, j] = 0;
                }
            }
            dp[0, 0] = 1;

            for(var i = 0; i < N; i++)
            {
                for(var b = 0; b < bit; b++)
                {
                    for(var j = 1; j <= 10; j++)
                    {
                        long next = Bshift(b, j, bit);
                        if (BitCheck(next)){ continue; }

                        dp[i + 1, next] = (dp[i + 1, next] + dp[i, b]) % MOD;
                    }
                }
            }

            long ans = pow10[N];
            for(var s = 0; s < bit; s++)
            {
                ans = (ans - dp[N, s] + MOD) % MOD;
            }

            Console.WriteLine(ans);

            //Console.Out.Flush();
        }

        static long Bshift(long bit, int shift, long max)
        {
            return ((bit << shift) + (1 << (shift - 1))) % max;
        }
         static bool BitCheck(long bit)
        {
            long XYZ = (1 << (X + Y + Z - 1)) + (1 << (X + Y - 1)) + (1 << (X - 1));
            return (bit ^ XYZ) == (bit - XYZ);
        }
        
    }
    

    public class Scanner
    {
        public int[] SplitRead()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReadL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }

    public static class Tool
    {
        static public void Initialize<T>(ref T[] array, T initialvalue)
        {
            for (var i = 0; i < array.Length; i++)
            {
                array[i] = initialvalue;
            }
        }
    }
}


Measured memory_bytes: 53088
N, K = map(int, input().split())

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

now = 1
B = [0] * N
cycle = -1
bC = -1

if K < N:
    for _ in range(K):
        now = A[now - 1]
    print(now)
    exit()
else:
    for i in range(N+1):
        now = A[now - 1]
        if B[now - 1] == 0:
            B[now - 1] = i
        else:
            cycle = i - B[now - 1]
            bC = B[now - 1] + 1
            break
    last = (K - bC)%cycle
    for _ in range(last):
        now = A[now - 1]
    print(now)
    exit()



Measured memory_bytes: 32180
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[][] hap= new int[N][3];
        for(int i=0;i<N;i++){
            hap[i][0] = sc.nextInt();
            hap[i][1] = sc.nextInt();
            hap[i][2] = sc.nextInt();
        }
        System.out.println(vacation(N,hap));
    }
    static int vacation(int N, int[][] happineses){

        int[][] dp = new int[3][N];
        dp[0][0] =happineses[0][0];
        dp[1][0] =happineses[0][1];
        dp[2][0] =happineses[0][2];

        for(int i=1 ; i<N ; i++){//next day
            for(int k=0;k<3;k++) { // combination (k,i) &
                for (int j = 0; j < 3; j++) { //  (j, i-1)
                    if (j == k ) continue;
                     int   happiness = dp[j][i-1] + happineses[i][k];
                     if(happiness > dp[k][i]){
                         dp[k][i]= happiness;
                     }
                }
            }
        }

        return Math.max(dp[0][N-1],Math.max(dp[1][N-1],dp[2][N-1]));
    }
}

Measured memory_bytes: 94112
#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pi pair<int,int>
#define vp vector<pi>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define f(i,x,z) for(int i=x;i<z;i++)
#define debug(x) cout<<"DEBUG------> "<<x<<endl
#define endl "\n"
#define srt(v) sort(v.begin(), v.end())

int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 	int a,ac=0,wa=0,tle=0,re=0;
 	cin>>a;
 	while(a--)
 	{
 		string aa;
 		cin>>aa;
 		if(aa=="AC")
 		{
 			ac++;
 		}
 		else if(aa=="WA")
 		{
 			wa++;
 		}
 		else if(aa=="TLE")
 		{
 			tle++;
 		}
 		else if(aa=="RE")
 		{
 			re++;
 		}
 	}
 	cout<<"AC x "<<ac<<"\n";
 	cout<<"WA x "<<wa<<"\n";
 	cout<<"TLE x "<<tle<<"\n";
 	cout<<"RE x "<<re;
   	return 0;		
}

Measured memory_bytes: 3616
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;


int main(){
    int N;
    cin >> N;
    vector<pair<int, pair<int, int>>> txy(N + 1);
    for(int i = 1; i < N + 1; i++) cin >> txy[i].fi >> txy[i].se.fi >> txy[i].se.se;
    bool flag = true;
    for(int i = 0; i < N; i++){
        int dist = abs(txy[i + 1].se.fi - txy[i].se.fi) + abs(txy[i + 1].se.se  - txy[i].se.se);
        int dt = txy[i + 1].fi - txy[i].fi;
        if(dist > dt) {
            flag = false;
            break;
        }
        if((dt - dist) % 2 != 0){
            flag = false;
            break;
        }
    }
    if(flag) puts("Yes");
    else puts("No");
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

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

int main() {
  ll N;cin>>N;
  vector<P> ps;
  REP(i,N) {
    int x,y;cin>>x>>y;
    ps.push_back({x,y});
  }

  sort(ALL(ps));
  double total = 0;
  do {
    double tmp = 0;
    P prevp = ps[0];
    FOR(i,1,N) {
      P curp = ps[i];
      tmp += sqrt(pow(abs(curp.first-prevp.first),2)+pow(abs(curp.second-prevp.second),2));
      prevp = curp;
    }
    total += tmp;
  } while (next_permutation(ALL(ps)));

  ll divider = 1;
  FOR(i,1,N+1) divider *= i;
  cout<<setprecision(10)<<total/divider<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define ll long long

int mod = 998244353;

signed main() {
  int K; cin >> K;
  rep(i, K) cout << "ACL";
  cout << endl;

  

}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define plll pair<ll,pll>
#define ppll pair<pll, pll>
#define pii pair<int, int> 
#define pb push_back
#define mod 1000000007
#define N 2000007
ll power(ll a,ll b){
    ll res=1ll;
    while(b>0){
        if(b%2!=0) res=(res*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return res%mod;
}
ll ncr(ll n,ll k){
    if(k>n-k) k=n-k;
    ll pro=1;
    for(ll i=0;i<k;i++){
        pro=(pro*(n-i))%mod;
        pro/=(i+1);
    }
    return (pro)%mod;
}

void swap(ll *a,ll *b) {
    ll temp=*a;
    *a=*b;
    *b=temp;
}
vector<ll> prime;
void seive(){
    vector<bool > isprime(1000001,true);
    for(int i=2;i*i<=1000000;i++){
        if(isprime[i]){
            for(int j=i*i;j<=1000000;j+=i){
                isprime[j]=false;
            }
        }
    }
    for(int i=2;i<=1000000;i++){
        if(isprime[i]) prime.push_back(i);
    }
}
vector<ll> parent;
ll find(ll p) {
    if(parent[p]==p) return parent[p];
    return parent[p]=find(parent[p]); 
}
void unun(ll a,ll b) {
    ll r1=find(a);
    ll r2=find(b);
    if(r1!=r2) parent[r2]=r1;
}
void solve() {
    ll n;
    cin>>n;
    vector<ll> arr(n);
    for(int i=0;i<n;i++) {
        cin>>arr[i];
    }
    ll cnt=0;
    map<ll,ll> mp;
    mp[arr[0]]++;
    for(int i=1;i<n;i++) {
        if(mp.find(i-arr[i])!=mp.end()) cnt+=mp[i-arr[i]];
        mp[i+arr[i]]++;
    }
    cout<<cnt;
}   


int main(void){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    t=1;
    // cin>>t;
    while(t--) {
        solve();
        // cout<<endl;
    }
    return 0; 

}


Measured memory_bytes: 17192
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a<b+c) cout << c-a+b << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 256
def dist(slst, plst):
	return abs(slst[0]-plst[0]) + abs(slst[1]-plst[1])

N, M = map(int, input().split())
students = []
for i in range(0, N):
	students.append(list(map(int, input().split())))
points = []
for i in range(0, M):
	points.append([i+1, list(map(int, input().split()))])
for i in range(0, N):
	ans = -1
	min = 5000000000000000
	for j in range(0, M):
		d = dist(students[i], points[j][1])
		if d < min:
			min = d
			ans = points[j][0]
	print(ans)

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

int main() {
  int n;
  cin >> n;
  int sum_length = 0;
  vector<int> arr(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    sum_length += arr[i];
  }
  sort(arr.rbegin(), arr.rend());
  cout << (arr[0] < sum_length - arr[0] ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256