akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int T1, T2;
int A1, A2;
int B1, B2;
signed main() {
    cin >> T1 >> T2;
    cin >> A1 >> A2;
    cin >> B1 >> B2;
    if (A1 < B1) { swap(A1, B1), swap(A2, B2); }
    if (A1 * T1 + A2 * T2 == B1 * T1 + B2 * T2) { fin("infinity"); }
    int a = A1 * T1 - B1 * T1;
    int b = B2 * T2 - A2 * T2 - a;
    if (b < 0) { fin(0); }
    if (a % b == 0) {
        cout << 1 + (a / b) * 2 - 1 << endl;
    } else {
        cout << 1 + (a / b) * 2 << endl;
    }
}


Measured memory_bytes: 256
import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str;
		while((str=br.readLine())!=null){
			String[] num=str.split(" ");
			
			double[] changeNum=new double[num.length];
			for(int i=0;i<changeNum.length;i++){
				changeNum[i]=Double.parseDouble(num[i]);
			}
			
			double[] AP={changeNum[6]-changeNum[0],changeNum[7]-changeNum[1]};
			double[] AC={changeNum[4]-changeNum[0],changeNum[5]-changeNum[1]};
			double[] AB={changeNum[2]-changeNum[0],changeNum[3]-changeNum[1]};
			
			double u=(AP[0]*AB[1]-AB[0]*AP[1])/(AC[0]*AB[1]-AB[0]*AC[1]);
			double v=(AP[0]*AC[1]-AC[0]*AP[1])/(AB[0]*AC[1]-AC[0]*AB[1]);
			
			if(u>0 && v>0 && u+v<1){
				System.out.println("YES");
			}
			else if(u<0 || v<0 || u+v>1){
				System.out.println("NO");
			}
		}
	}

}

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

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

rep(i,N) 
{
    int x;
    cin >> x;
    if (x <= 0 ) break;
   else  if (K-x > x) res +=  2*x; 
    else res += 2*(K-x);
}
cout << res  << endl; 
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int D; cin >> D;
  vector<int> c(26); rep(i,26) cin >> c[i];
  vector<vector<ll>> s(D, vector<ll>(26));
  rep(y,D) rep(x,26) cin >> s[y][x];
  vector<int> t(D); rep(i,D) cin >> t[i];
  int M; cin >> M;
  rep(i,M){
    int d,q; cin >> d >> q;
    t[d-1]=q;

    ll ans = 0;
    vector<int> lst(26,-1);
    rep(i,D){
      ans += s[i][t[i]-1];
      lst[t[i]-1] = i;
      rep(j,26){
        ans -= c[j]*(i-lst[j]);
      }
      
    }
    cout << ans << endl;

  }
  return 0;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
#define pii             pair<int , int >
#define inf             1000000011
#define in(a)           scanf("%d", &a)
#define ins(a)          scanf("%s", a)
#define in2(a, b)       scanf("%d%d", &a, &b)
#define in3(a, b, c)    scanf("%d%d%d", &a, &b, &c)
#define pn              printf("\n")
#define pr(a)           printf("%d\n", a)
#define prs(a)          printf("%d ", a)
#define pr2(a, b)       printf("%d %d\n", a, b)
#define pr3(a, b, c)    printf("%d %d %d\n", a, b, c)
#define pcs(a)          printf("Case %d: ", a)
#define mp              make_pair
#define vi              vector<int >
#define _ceil(n, a)     ((n)%(a)==0?((n)/(a)):((n)/(a)+1))
#define pb              push_back
#define mem(a, b)       memset((a), (b), sizeof(a))
#define all(X)          (X).begin(), (X).end ()
#define lg2(n)          (31-__builtin_clz(n))
#define ext(a)          {printf("%s\n", a); return 0;}
#define oka(x, y)       ((x)>=0&&(x)<row&&(y)>=0&&(y)<col)
#define x               first
#define y               second
#define lc              (2*i)
#define rc              (2*i+1)

typedef long long LL;
//int  dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int  dx[]={1,1,0,-1,-1,-1,0,1,0};int dy[]={0,1,1,1,0,-1,-1,-1,0};//8 direction
//int  dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//bool check(int n, int pos) {return (n & (1<<pos))>>pos;} //typecast 1 in case of int
//int  on(int n, int pos) {return n | (1<<pos);} //typecast 1 in case of int
//int  off(int n, int pos) {return n & ~(1<<pos);} //typecast 1 in case of int
//bool operator < (const data &d) const{return cost<d.cost;} //reverse in priority queue

const int M = 400010, mod = 1000000007;


int main()
{

    ios_base::sync_with_stdio(false);

    int a, b;
    cin>>a>>a>>b;
    cout<<((b-a)%2==0?"Alice":"Borys")<<endl;



    return 0;
}


Measured memory_bytes: 256
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
		int c=sc.nextInt();
		int d=sc.nextInt();
  		long ans=0;
  		long ansa=0;
  		long ansb=0;
        long divide=lcm(c,d);
		ansb=b-(b/c+b/d-b/divide);
        ansa=a-1-((a-1)/c+(a-1)/d-(a-1)/divide);
  		ans=ansb-ansa;
    	System.out.println(ans);
    }
  private static long lcm(long a, long b){
  return a*b/gcd(a,b);
}
  private static long gcd(long a,long b){
   if(b==0){
   	return a;
   }
	return gcd(b, a%b);
}
}

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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

class UnionFind {
 private:
    vector<int> parent;  // 親
    vector<int> rank;    // 木の深さ
 public:
    explicit UnionFind(int n);  // n要素で初期化
    int Find(int x);            // 木の根を返す
    void Unite(int x, int y);   // xとyの属する集合を併合
    bool Same(int x, int y);    // xとyが同じ集合に属するか否か
};

UnionFind::UnionFind(int n) : parent(n), rank(n) {
    for (int i = 0; i < n; i++) {
        parent[i] = i;
        rank[i] = 0;
    }
}

int UnionFind::Find(int x) {
    if (parent[x] == x) {
        return x;
    } else {
        return parent[x] = Find(parent[x]);
    }
}

void UnionFind::Unite(int x, int y) {
    x = Find(x);
    y = Find(y);
    if (x == y) return;

    if (rank[x] < rank[y]) {
        parent[x] = y;
    } else {
        parent[y] = x;
        if (rank[x] == rank[y]) rank[x]++;
    }
}

bool UnionFind::Same(int x, int y) { return Find(x) == Find(y); }

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> p(N);
    UnionFind uf(N);
    rep(i, N) cin >> p[i];
    rep(i, N) p[i]--;
    rep(i, M) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        uf.Unite(x, y);
    }
    int ans = 0;
    rep(i, N) ans += p[i] == i;
    int cnt = 0;

    map<int, set<int>> S;
    rep(i, N) {
        int v = uf.Find(i);
        S[v].insert(i);
    }
    for (const auto &e : S) {
        auto vs = e.second;
        /*
        cout << e.first << ": ";
        for(auto x : vs) cout << x <<  ", ";
        cout << endl;
        */
        for (auto x : vs)
            if (vs.count(p[x])) cnt++;
    }
    cout << max(ans, cnt) << endl;
    return 0;
}


Measured memory_bytes: 15488
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(int i = a;i < n;i++)
#define LINF (ll)1e17
#define INF 1e9
#define MOD 1e9+7
#define sMOD 1e5
#define fs first
#define sc second


signed main(){
	
	ll a,b,k,memo = 0,ans = 0;
	cin >> a >> b;
	
	ll cnt[b] ={};
	
	rep(i,0,a){
		cin >> k;
		
		rep(j,0,k){
			cin >> memo;
			cnt[memo-1]++;
		}
	}
	
	rep(i,0,b){
		if(cnt[i] == a)ans++;
	}
	
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, M = map(int, readline().split())
    if abs(N-M)>1:
        print('0')
    elif N==M:
        fact=[1]*(N+1)
        for i in range(N):
            fact[i+1] = fact[i]*(i+1)%MOD
        ans = 2*fact[N]*fact[M]%MOD
        print(ans)
    else:
        fact = [1] * (N + 3)
        for i in range(N+2):
            fact[i + 1] = fact[i] * (i + 1)%MOD
        ans = fact[N] * fact[M]%MOD
        print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 6900
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Khela ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll, ll>

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int Max=1e9+100;
const int sz=1e5+100;
ll last[sz];
bool cmp(PII a,PII b)
{
    return (a.f<b.f);
}
ll Find(ll p)
{
    if(last[p]==p) return p;
    else return (last[p]=Find(last[p])) ;
}
int main()
{
    Khela
    ll a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    while(cin>>m>>n)
    {
        PII ara[m];
        for(i=0;i<m;i++) cin>>ara[i].f>>ara[i].s;
        sort(ara,ara+m,cmp);
        priority_queue<ll> pq;
        ll time=n-1;
        i=0;
        ll sum=0;
        while(time>=0)
        {
             while(i<m && ara[i].first+time<=n) {
                 pq.push(ara[i].s);
                 ++i;
             }
             if(!pq.empty()){
                 sum+=pq.top();
                 pq.pop();
             }
             --time;
        }
        cout<<sum<<endl;
    }

}

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

using namespace std;

const int maxn=1e5+5;
int n,x;
int m[105];

int main()
{
    cin>>n>>x;
    for(int i=1;i<=n;i++)
       {
           cin>>m[i];
           x-=m[i];
       }
    sort(m+1,m+1+n);
    int ans=n+x/m[1];
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
using namespace std;
int main(void){

    int a, b, d, r;
    double f;
    
    cin >> a >> b;
    d = a / b;
    r = a % b;
    f = 1.0000 * a / b;
    cout << d << " " << r << " " << setprecision(8) << setiosflags(ios::fixed) << f << endl;
    return 0;
}


Measured memory_bytes: 3260
N = int(input())
L = list(map(int, input().split()))
cnt = 0
for i in range(N):
    for j in range(N):
        for k in range(N):
            if i!=j!=k!=i and L[i]+L[j]>L[k] and L[j]+L[k]>L[i] and L[k]+L[i]>L[j] and L[i]!=L[j]!=L[k]!=L[i]:
                cnt += 1
print(cnt//6)

Measured memory_bytes: 9212
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll N=1e6+5,inf=1e18,mod=1e9+7;
#define test ll testcases;cin>>testcases; while(testcases--)
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define vld vector<ld>
#define pll pair<ll,ll> 
#define pld pair<ld,ld> 
#define vpll vector<pll>
#define vpld vector<pld>
#define all(X) X.begin(),X.end()
#define sz(x) ((ll)((x).size()))
const ld pi=3.141592653589793238;

bool check_prime(ll n)
{
	ll flag=0,i;
	for(i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			flag=1;
			break;
		}
	}
	if(n==1)
	{
		return false;
	}
	else if(flag==0 || n==2 || n==3)
	{
		return true;
	}
	else
	{
		return false;
	}
}

ll fastexpo(ll a,ll b,ll MOD) 
{
	ll result=1;
	while(b>0)
	{
		if(b%2==1)
		{
			result=(result*a)%MOD;
		}
		a=(a*a)%MOD;
		b=b/2;
	}
	return result;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,k,j;
    cin>>n>>k;
    ll dp[n+1],h[n+1];
    for(i=1;i<=n;i++)
    {
    	cin>>h[i];
    	dp[i]=inf;
    }
    dp[1]=0;
    dp[2]=fabs(h[2]-h[1]);
    for(i=3;i<=n;i++)
    {
    	for(j=1;j<=k;j++)
    	{
    		if(i>j)
    		{
    			dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
    		}
    	}
    }
    cout<<dp[n]<<"\n";
	return 0;
}

Measured memory_bytes: 5172
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    int n; cin>>n;
    if(n<1200) cout<<"ABC"<<endl;
    else cout<<"ARC"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
int main()
{
	int n,m;
	cin>>n>>m;
	string a[n];
	long long int dp[n][m];
	dp[0][0]=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<n;i++)
	{
		if(a[i][0]=='.')
		dp[i][0]=1;
		else
		{
			while(i<n)
			{
				dp[i][0]=0;
				i++;
			}
		}
	}
	for(int i=1;i<m;i++)
	{
		if(a[0][i]=='.')
		dp[0][i]=1;
		else
		{
			while(i<m)
			{
				dp[0][i]=0;
				i++;
			}
		}
	}
	for(int i=1;i<n;i++)
	{
		for(int j=1;j<m;j++)
		dp[i][j]=0;
	}
	for(int i=1;i<n;i++)
	{
		for(int j=1;j<m;j++)
		{
			if(a[i][j]=='.')
			dp[i][j]=(dp[i-1][j]%M+dp[i][j-1]%M)%M;
		}
	}
	cout<<dp[n-1][m-1]<<endl;
}

Measured memory_bytes: 9088
N = int(input())
A = [input() for i in range(N)]
alr = []
flag = True
for i in range(N):
    if alr:
        if alr[-1][-1] != A[i][0] or A[i] in alr:
            flag = False
            break
    alr.append(A[i])
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b,ll mod){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

ll r,c,n;
ll getid(ll x,ll y){
    ll res=-1;
    if(x==0)res=y;
    else if(y==c)res=c+x;
    else if(x==r)res=c*2+r-y;
    else if(y==0)res=c*2+r*2-x;
    return res;
}
int main(){
    cin>>r>>c>>n;
    vp v;
    rep(i,n){
        ll a,b,c,d;cin>>a>>b>>c>>d;
        ll x=getid(a,b),y=getid(c,d);
        if(x==-1||y==-1)continue;
        v.pb(min(x,y),max(x,y));
    }
    sort(all(v));
    vp s;
    rep(i,v.size()){
        while(!s.empty()){
            if(s.back().se<v[i].fi)s.pop_back();
            else break;
        }
        if(!s.empty()&&s.back().se<v[i].se)dame("NO");
        s.pb(v[i]);
    }
    out("YES");
}

Measured memory_bytes: 6576
// luogu-judger-enable-o2
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#define maxn 1000010
using namespace std;
int n;
char s[maxn],t[maxn];
bool check()
{
    for(int i=1;i<=n;i++)
    {
        if(s[i]!=t[i])  return false;
    }
    return true;
}
queue<int>q;
int ans;
int main()
{
    cin>>n;
    scanf("%s",s+1);
    scanf("%s",t+1);
    if(check())
    {
        puts("0");
        return 0;
    }
    int pos=n;
    for(int i=n;i>=1;i--)
    {
        if(t[i]==t[i-1])  continue;
        pos=min(pos,i);
        while(pos&&s[pos]!=t[i])  pos--;
        if(!pos)
        {
            puts("-1");
            return 0;
        }
        while(q.size()&&q.front()-q.size()+1>i)  q.pop();
        q.push(pos);
        if(i!=pos)  ans=max(ans,(int)q.size());
    }
    printf("%d\n",ans+1);
    return 0;   
}

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

int main(){
    double pai=3.141592653589;
    char w;
    for(;;){
        scanf("%c",&w);
        if(w=='\n'){
            break;
        }else if(isupper(w)){
            w=tolower(w);
            printf("%c",w);
        }else if(islower(w)){
            w=toupper(w);
            printf("%c",w);
        }else{
            printf("%c",w);
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 3144
line = list(map(str,input().split()))
s = []
operand_list = ['+','-', '*']
for i in range(len(line)):
    if line[i] not in operand_list:
        s.append(int(line[i]))
    elif line[i] is '+':
        ans = s[-1] + s[-2]
        s.pop()
        s.pop()
        s.append(ans)
    elif line[i] is '-':
        ans = s[-2] - s[-1]
        s.pop()
        s.pop()
        s.append(ans)
    elif line[i] is '*':
        ans = s[-1] * s[-2]
        s.pop()
        s.pop()
        s.append(ans)
print(s[0])    


Measured memory_bytes: 5604
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
  int H,W;
  char c[101][101], ans[201][101];
  cin >> H >> W;
  rep(i,0,H){
    rep(j,0,W){
      cin >> c[i][j];
    }
  }
  rep(i,0,2*H){
    rep(j,0,W){
      ans[i][j] = c[i/2][j];
    }
  }

  cout << endl;
  rep(i,0,2*H){
    rep(j,0,W){
      cout << ans[i][j];
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
using namespace std;
int main(void)
{
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int gokei = 0;
    if (A + B <= 2 * C)
    {
        gokei = X * A + Y * B;
    }
    else
    {
        int toriaezu = min(X, Y);
        gokei = 2 * C * toriaezu;
        int husoku = max(X, Y) - toriaezu;
        int sukunai = A;
        if (toriaezu == X)
        {
            sukunai = B;
        }
        if (2 * C < sukunai)
        {
            gokei += 2 * C * husoku;
        }
        else
        {
            gokei += husoku * sukunai;
        }
    }
    cout << gokei << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define F first
#define S second
map<pii, int> edges;
int mx = 0;
void dfs(vector<vector<int>> &graph, vector<bool> &flg, int node, int prv_col)
{
    flg[node] = 1;
    int col = 1;
    for (auto it : graph[node])
    {
        if (!flg[it])
        {
            if (col == prv_col)
                col++;
            dfs(graph, flg, it, col);
            edges[{node, it}] = col;
            col++;
        }
    }
    mx = max(mx, col - 1);
}
int main()
{
    int n, a, b;
    cin >> n;
    vector<vector<int>> graph(n + 1);
    vector<bool> flg(n + 1, 0);
    vector<pii> hlp;
    for (int i = 0; i < n - 1; i++)
    {
        cin >> a >> b;
        hlp.pb({a, b});
        graph[a].pb(b);
        graph[b].pb(a);
    }
    dfs(graph, flg, 1, 0);
    cout << mx << "\n";
    for(auto it: hlp)
    {
        if (edges[it] > 0)
            cout << edges[it] << '\n';
        else
            cout << edges[{it.S, it.F}] << '\n';
    }
    return 0;
}

Measured memory_bytes: 14968
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val a = scanner.nextInt()
    val b = scanner.nextInt()
    val c = scanner.nextInt()
    val yesNo = if (a < b && b < c) "Yes" else "No"
    println("${yesNo}")
}


Measured memory_bytes: 25424
#include<iostream>
#include<vector>
#include<algorithm>
int ans;
int N, A, B;
int main() {
	std::cin >> N >> A >> B;
	for (int i = 1; i <= N; i++) {
		int now = i;
		int  mod = 10000;
		int sum = 0;
		for (int j = 0; j < 5; j++) {
			sum += now/mod;
			now %= mod;
			mod /= 10;
		}
		if (A <= sum&&sum <= B)ans += i;
	}
	std::cout << ans << std::endl;
	return 0;
}

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

int a[100000];

int main()
{

    int N;
    cin >> N;
    for (int i = 0; i < N; ++i)
    {
        cin >> a[i];
    }
    sort(a, a + N);

    int m = 0;
    int n, r;
    int b = 1000000000;
    n = a[N - 1];
    for (int i = 0; i < N; ++i)
    {
        if (a[i] <= n / 2)
        {
            if (n / 2 - a[i] < b)
            {
                b = n / 2 - a[i];
                r = a[i];
            }
        }
        else{
            if(n/2-(n-a[i])<b){
                b = n / 2 - (n - a[i]);
                r = a[i];
            }
        }
            
    }
    cout << n << " " << r << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define Size 1e5
using namespace std;
//スタックでやってみる

int main(){

    vector<char>sta(Size);

    string s; cin>>s;

    int ans =0,top =0;

    for(int i=0; i<s.size(); i++){
        if( top==0 || sta[top] == s[i])sta[++top] = s[i];
        else{
            ans += 2;
            top--;
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 512
#pragma GCC optimize ("O2")
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"

#define DEBUG 0
#define dd if (DEBUG)

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, A) for (auto & a : A)
#define all(a) (a).begin (), (a).end ()
#define rall(a) (a).rbegin (), (a).rend ()
#define sz(a) (int) (a).size ()
#define szl(a) (int) (a).length ()
#define FASTIO cin.sync_with_stdio (0); cin.tie (0); cin.exceptions (cin.failbit);

typedef long long ll;
typedef pair <int, int> pii;
#define f first
#define s second
#define mp(a, b) make_pair((a), (b))
typedef vector <int> vi;
#define pb(a) push_back ((a))

const ll MOD = 1e+9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int INFi = 0x3f3f3f3f;
const ll MAXN = 1e+5+7;

int main ()
{
    FASTIO;
    int i, j, n, w;
    cin >> n >> w;
    vector <ll> V (n), W (n), dp (w + 7);
    for (i = 0; i < n; i++)
    {
        cin >> W[i];
        cin >> V[i];
    }
    for (i = 0; i < n; i++)
    {
        dd trav (a, dp)
            cout << a << " ";
        dd cout << "\n";
        for (j = sz (dp) - W[i] - 1; j >= 0; j--)
        {
            dp[j + W[i]] = max (dp[j + W[i]], dp[j] + V[i]);
        }
    }
    dd trav (a, dp)
        cout << a << " ";
    dd cout << "\n";
    cout << dp[w] << "\n";

    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int n,a[10005];
  long long ans=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    ans+=a[i];
  }
  sort(a,a+n);
  cout<<a[0]<<" "<<a[n-1]<<" "<<ans<<"\n";
  return 0;
}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll t = 1;
	// cin>>t;

	while(t--){
		ll n;
		cin>>n;

		ll ans = 0;
		for(ll i=1;i<=n;++i){
			ll m = n/i;
			m = (m*(m+1))/2;
			ans  += m*i;
		}

		cout<<ans<<'\n';
	}

	return 0;

}

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

using namespace std;

const int MAXN=1e5+5;
int n;
int pos[MAXN];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d",&pos[i]);
	long long sum=0;
	for(int i=1;i<=n+1;++i)
		sum+=abs(pos[i]-pos[i-1]);
	for(int i=1;i<=n;++i){
		printf("%lld\n",sum-abs(pos[i]-pos[i-1])-abs(pos[i]-pos[i+1])+abs(pos[i+1]-pos[i-1]));
	}
	return 0;
}


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

int main() {
  int s;
  cin >> s;
  int s1 = s/100;
  int s3 = s%10;
  int s2 = s /10 - s1*10;
 
  cout << s1 + s2 + s3 << endl;
 
  
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

// mint
#include<cstdint>
int64_t const MOD = 1e9+7;

template<int64_t Prime>
struct mod_int {
  int64_t v_;
  mod_int(int64_t x=0) : v_(x) { normalize(); }
  void normalize() { ((v_ %= Prime) += Prime) %= Prime; }
  mod_int operator+=(mod_int const& r){ (v_ += r.v_) %= Prime; return *this; }
  mod_int operator-=(mod_int const& r){ (v_ += Prime - r.v_) %= Prime; return *this; }
  mod_int operator*=(mod_int const& r){ (v_ *= r.v_) %= Prime; return *this; }
  mod_int operator+(mod_int const& r) { mod_int res(*this); return res += r; }
  mod_int operator-(mod_int const& r) { mod_int res(*this); return res -= r; }
  mod_int operator*(mod_int const& r) { mod_int res(*this); return res *= r; }
  mod_int pow(int x) const {
    int64_t res = 1, v = v_;
    while(x > 0) {
      if(x&1) (res *= v) %= Prime;
      x/=2; (v *= v) %= Prime;
    }
    return mod_int(res);
  }
  mod_int inv() const { return pow(Prime-2); }
};
typedef mod_int<MOD> mint;

int main() {
  int N, K; std::cin >> N >> K;
  int L = N/31630; // >= sqrt(1e9)
  while(L*L <= N) ++L;
  std::vector<mint> dp1(L+1), dp2(L+1);
  std::fill_n(dp1.begin()+1, std::min(L, N), mint(1));
  std::fill_n(dp2.begin()+1, L, mint(1));
  
  mint sum; 
  while(K--) {
    std::swap(dp1, dp2);
    // sum up previous dp1[] to current dp2[]
    for(int i = 1; i <= L; ++i) dp2[i] += dp2[i-1];
    //
    sum = dp2[N/(L+1)];
    // sum up previous dp2[] to current dp1[]
    for(int i = L; i > 0; --i) {
      sum += dp1[i]*mint(N/i - N/(i+1));
      dp1[i] = sum;
    }
  }
  fin(sum.v_);
  return 0;
}


Measured memory_bytes: 768
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

int N;

int main()
{
	scanf ("%d", &N);
	vector<int> r; int mx = -1;
	for (int i = 0; i < (1 << N); i++){
		int x; scanf ("%d", &x);
		if (mx < x){
			if (mx != -1) r.push_back(mx);
			mx = x;
		}
		else r.push_back(x);
	}

	vector<int> h = { mx };
	sort(r.rbegin(), r.rend());
	while (!r.empty()){
		vector<int> p, q;
		sort(h.rbegin(), h.rend());

		int i = 0, j = 0;
		while (i <= h.size() && j < r.size()){
			if (i < h.size() && h[i] > r[j]){
				p.push_back(r[j]);
				i++; j++;
			}
			else{
				q.push_back(r[j]);
				j++;
			}
		}

		if (h.size() != p.size()){
			puts("No");
			return 0;
		}

		h.insert(h.end(), p.begin(), p.end());
		r = move(q);
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 4336
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
#include <climits>
using namespace std; 


int main(){
    string s;
    cin >> s;
    long long g = 0, p = 0, ans = 0;
    for(int i = 0; i < s.size(); ++i){
        if(s[i] == 'p'){
            if(p + 1 <= g){
                p++;
            }
            else{
                ans--;
                g++;
            }
        }
        else{
            if(p + 1 <= g){
                p++;
                ans++;
            }
            else{
                g++;
            }
        }
    }
    cout << ans;
}


Measured memory_bytes: 512
#include <iostream>
#include <bitset>
using namespace std;
const int MOD=998244353;
bitset<302> p[302],b[302],zero;
void insert(bitset<302> x) {
    for (int i = 301; i >= 0; i --) if (x[i]==1) {
        if ( p[i] != zero ) {
            x ^= p[i];
        } else {
            p[i] = x; 
            break;
        }
    }
} 
int n,m;
int main() {
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            int x; scanf("%d",&x);
            if(x) b[i][j]=1;
        }
        insert(b[i]);
    }

    int pivot=0;
    for(int i=0;i<302;i++){
        if(p[i] != zero) pivot ++;
    }
    int fre = n - pivot;
    int ans = 1, sub = 1;

    for(int i=1;i<=n;i++){
        ans=ans*2LL%MOD;
    }
    for(int i=1;i<=fre;i++){
        sub=sub*2LL%MOD;
    }
    ans = (ans-sub+MOD)%MOD;

    int mul=1;
    for(int i=1;i<m;i++){
        mul=mul*2%MOD;
    }

    ans=1LL*ans*mul%MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI=acos(-1);
const int INF = numeric_limits<int>::max();

int main(){
    string s, t;
    cin >> s >> t;

    int n = s.length();

    int cnt = 0;

    rep(i,n){
        if(s[i] == t[i]) continue;
        else cnt++;
    }

    cout << cnt << endl;

    return 0;
    
}

Measured memory_bytes: 3888
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	string s;
	cin>>s;
	int x = 0;
	int y1 = count(s.begin(),s.end(),'(')-count(s.begin(), s.end(),')');
	if(y1!=0)
	for(int i = 0;i<abs(y1); i++)
			if(y1>0)
				s += ')';
			else
				s = '('+s;
	int a[s.length()];
	for(int i = 0;i <s.length(); i++)
	{
		if(s[i]=='(')
			x++;
		else
			x--;
		a[i] = x;
	}
	int y = *min_element(a,a+s.length());
	// int r = a[n-1];
	if(y<0)
		for(int i = 0; i<abs(y); i++)
			s = '('+s+')';
	cout<<s<<endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int i = 0;
  
  while (i < N){
    string S;
    cin >> S;
    if (S == "Y"){
      cout << "Four" << endl;
      break;
    }
    i++;
  }
  if (i == N){
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
 public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);

      long A = sc.nextLong();
      long B = sc.nextLong();
      long K = sc.nextLong();

      if(A >= K){
        A -= K;
       

      }else if(A + B >= K){
        K -= A;
        A = 0;
        B -= K;
      

      }else{
        A = 0;B = 0;
       
      }
        System.out.println(A + " " + B);
   }
 }

Measured memory_bytes: 38712
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<29
lINF = 1<<35

def readInt():
    return list(map(int,input().split()))

def prime_fact(a): # 素因数分解
    fact = {}
    prime = set()
    for i in range(2,int(a**(1/2)+1)):
        if a%i==0:
            fact[i] = 0
            while a%i==0:
                a //= i
                fact[i] += 1
    if a!=1:
        fact[a] = 1
    return fact

def main():
    n = int(input())
    if n==1:
        print(0)
        return
    fact = prime_fact(n)
    ans = 0
    for x in fact.keys():
        i = 1
        while i<=fact[x]:
            fact[x] -= i
            i += 1
            ans += 1
    print(ans)
    return

if __name__=='__main__':
    main()


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

int main(){
    string s;
    int c = 0,o = 0;
    cin >> s;
    for (int i = 0;i < s.size();i++){
        if(c == 0 && s[i] == 'R'){
            c = 1;
            if(c > o)
             o =c;
        }
        else{
    	    if(s[i] == 'S')
                c = 0;
      	    else{
                c++;
                if(c > o)
                    o =c;
            }  
        }
    } 
    cout <<  o <<endl;
}

Measured memory_bytes: 3620
import java.io.*;
class Main{
	public static void main(String[] args){
		
		try{
		
			BufferedReader in = new BufferedReader(new InputStreamReader(System.in));


			String c = in.readLine();
			String[] str = c.split(" ");
			int[] num = new int[str.length];
			for(int i=0;i<str.length;i++){
				num[i] = Integer.parseInt(str[i]);
			}
			if(num.length == 2){
				System.out.print(num[0]*num[1] + " " );
				System.out.println(2*(num[0]+num[1]));
			}
		}catch(IOException e){
			e.printStackTrace();
		}

	}
}

Measured memory_bytes: 24264
///#pragma GCC optimize ("O2") ///G++ÓÃ£¬
///#pragma comment(linker, "/STACK:36777216")///C++ÓÃ
///#pragma comment(linker, "/STACK:102400000,102400000")///C++ÓÃ£¬·ÀÖ¹Õ»Òç³ö
#include <bits/stdc++.h>
//#include <unordered_map>
//#include <unordered_set>
using namespace std;
 
 
#define debug       cout << "***********************" << endl
#define Bug(s)      cout << "s = " << s << endl
#define mem(a,b)    memset(a, b, sizeof(a))
#define lson        l, mid, rt<<1
#define rson        mid + 1, r, rt<<1|1
#define For(i, x, n)  for(int i = (x) ; i < (n) ; ++i)
#define Forr(i, x, n) for(int i = (x) ; i <= (n) ; ++i)
#define Rep(i, x, n)  for(int i = (x) ; i > (n) ; --i)
#define Repp(i, x, n) for(int i = (x) ; i >= (n) ; --i)
#define highint( n )  ceil( n )
#define lowint( n )   floor( n )
#define SERU(x)       floor((double) x + 0.5 )
#define lowbit(x)     (x & (-x))
 
#define all(x)      (x).begin(), (x).end()
#define SZ(x)       (int)(x).size()
#define FA(i, a, x) for (__typeof((x).begin()) i=(a); i!=(x).end(); ++i)
#define RA(i, x)    FA(i, (x).begin(), x)
#define FDA(i, a, x)  for (__typeof((x).rbegin()) i=(x).rbegin(); i!=(a); ++i)
#define RDA(i, x)   FDA(i, (x).rend(), x)
#define P(v, x)     (v.find(x) != v.end())
#define Pos(v, x)   (find(all(v), x) != v.end())
#define UN(a)       sort(all(a)), a.erase(unique(all(a)), a.end())
#define REV(a)      reverse(all(a))
#define mp(a, b)    make_pair(a, b)
#define p(a, b)     pair<int, int>(a, b)
#define sf1i(x)     scanf("%d", &x)
#define sf1l(x)     scanf("%I64d", &x)
#define sf2i(x, y)  scanf("%d%d", &x, &y)
#define sf2l(x, y)  scanf("%I64d%I64d", &x, &y)
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ll long long
#define eps 1e-8
 
int a[101];
 
int main(){
    int T, n;
    cin >> n;
    int res = 0;
    For(i, 0, n){
        cin >> a[i];
        res += a[i];
    }
    if(res % 10 != 0){
        cout << res << endl;
        return 0;
    }
    int ans = 0;
    sort(a, a + n);
    int i = 0;
    For(i,0,n){
        if(a[i] % 10 != 0){
            res -= a[i];
            break;
        }
    }
    if(res % 10 == 0)cout << 0 << endl;
    else
    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  ll K, N; cin >> K >> N;
  vector<ll> A(N); rep(i,N) cin >> A[i];
  ll ans = K;
  ll maxd=  0;
  rep(i,N-1){
    maxd = max(maxd, A[i+1]-A[i]);
  }
  maxd = max(maxd, K-A[N-1]+A[0]);
  cout << ans-maxd << endl;
  return 0;
}


Measured memory_bytes: 1920
/*
AUTHOR:

'|.   '|'     |     '||    ||'     |     '|.   '|'
 |'|   |     |||     |||  |||     |||     |'|   | 
 | '|. |    |  ||    |'|..'||    |  ||    | '|. | 
 |   |||   .''''|.   | '|' ||   .''''|.   |   ||| 
.|.   '|  .|.  .||. .|. | .||. .|.  .||. .|.   '| 

*/



#include <bits/stdc++.h>

using namespace std;
#define endl "\n"
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define all(x) x.begin(),x.end()
#define pb push_back
#define Fo(i,k,n) for(ll i=k;i<=n;i+=1)
#define deb(x) cout << #x << "=" << x << endl
#define in(a,n) Fo( i,0,n-1)cin>>a[i]
#define out(a,n) Fo( i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define IOS     ios_base::sync_with_stdio(0); cin.tie(NULL);
const ll N=2*1e6+1;


int main() {
	IOS
    ll t=1;
	//cin>>t;	
	
	Fo(_,1,t)
	{
	   //cout<<"Case #"<<_<<": ";
	   
	   ll n,k;
	   cin>>n>>k;
	   ll ar[n+1];
	   Fo(i,1,n)cin>>ar[i];
	   ll cur=1;
	   
	   bool vis[n+1];
	   memset(vis,0,sizeof vis);
	   ll cy=1,before=0;
	   while(k>0)
	   {
	       
	      // deb(cur);
	       if(vis[cur])
	       {
	           cy=cur;
	           break;
	       }
	       else {vis[cur]=1;k--;}
	       cur=ar[cur];
	   } 
	   //deb(cy);
	   if(k<=0)
	   {
	       cout<<cur;
	       continue;
	   }
	   
	   ll sz=1;
	   cur=ar[cy];
	   while(cur!=cy)
	   {
	       sz++;
	       cur=ar[cur];
	   }
	   //deb(sz);
	   k=k%sz;
	   cur=cy;
	   while(k>0)
	   {
	       k--;
	       cur=ar[cur];
	       
	   }
	   
	   cout<<cur;
	 
	 
	  
	   
	   
	   
	   
	   
	   cout<<endl;
	  
	}
	
    
}

Measured memory_bytes: 5348
def main():
    h,w = map(int,input().split())
    ls = [list(input()) for _ in range(h)]
    r = [[0 for _ in range(w)]  for _ in range(h)]
    l = [[0 for _ in range(w)]  for _ in range(h)]
    o = [[0 for _ in range(w)]  for _ in range(h)]
    u = [[0 for _ in range(w)]  for _ in range(h)]

    for i in range(h):
        for j in reversed(range(w)):
            if j == w-1:
                if ls[i][j]=='#':
                    r[i][j] = 0   
                else:
                    r[i][j] = 1
                    
            else:
                if ls[i][j]=='#':
                    r[i][j] = 0
                else:
                    r[i][j] = r[i][j+1]+1

    for i in range(h):
        for j in range(w):
            if j == 0:
                if ls[i][j]=='#':
                    pass
                else:
                    l[i][j]=1
            else:
                if ls[i][j]=='#':
                    pass
                else:
                    l[i][j] = l[i][j-1]+1
    for j in range(w):
        for i in range(h):
            if i == 0:
                if ls[i][j]=='#':
                    pass
                else:
                    o[i][j]=1
            else:
                if ls[i][j]=="#":
                    pass
                else:
                    o[i][j] = o[i-1][j] + 1
    for j in range(w):
        for i in reversed(range(h)):
            if i == h-1:
                if ls[i][j]=='#':
                    pass
                else:
                    u[i][j]=1
            else:
                if ls[i][j]=='#':
                    pass
                else:
                    u[i][j] = u[i+1][j] + 1

    ans = 0
    for i in range(h):
        for j in range(w):
            can = r[i][j] + l[i][j] + o[i][j] + u[i][j]
            ans = max(ans,can)
    print(ans-3)
if __name__ == "__main__":
    main()

Measured memory_bytes: 312968
h,w = map(int,input().split())
a1 = [[5000] * (w+2) for i in range(h+2)]
a2 = [['.'] * (w+2) for i in range(h+2)]
for i in range(h):
  a2[i+1][1:-1] = list(input())
for i in range(h):
  for j in range(w):
    if a2[i+1][j+1] == '#':
      a1[i+1][j+1] = 0
for i in range(w):
  for j in range(h):
    a1[j+1][i+1] = min(a1[j][i+1]+1,a1[j+1][i+1])
for i in range(w):
  for j in range(h):
    a1[h-j][i+1] = min(a1[h-j+1][i+1]+1,a1[h-j][i+1])
for i in range(h):
  for j in range(w):
    a1[i+1][j+1] = min(a1[i+1][j]+1,a1[i+1][j+1])
for i in range(h):
  for j in range(w):
    a1[i+1][w-j] = min(a1[i+1][w-j+1]+1,a1[i+1][w-j])
m = 0
for i in range(h):
  for j in range(w):
    m = max(m,a1[i+1][j+1])
print(m)


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x, a, b;
  cin >> x >> a >> b;
  if (b <= a) {
    cout << "delicious" << endl;
  } else if ((b - a) <= x) {
    cout << "safe" << endl;
  } else {
    cout << "dangerous" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n = input()
n = int(n)
s_1 = input()
s_2 = input()
s_list = []

nagasa = len(s_1)
i = 0
while i < nagasa:
    if s_1[i] == s_2[i]:
        s_list.append(0)
        i += 1
    else:
        s_list.append(1)
        i += 2

if s_list[0]==0:
    kotae = 3
else:
    kotae = 3*2
    
mod = 1000000007
mod = 1000000007
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

for i in range(len(s_list)-1):
    if s_list[i]==0:
        kotae = mul(kotae,2)
    elif s_list[i]==1 and s_list[i+1]==0:
        pass
    else:
        kotae = mul(kotae,3)
print(kotae)
        

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

int main(){
  int a,b,c,d,e,f,g,h,i,j,k,array[100001];
  string s;
  cin>>a>>b;
  if(a+b==15){
    cout<<"+"<<endl;
  }else if(a*b==15){
    cout<<"*"<<endl;
  }else{
    cout<<"x"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct point{
	string s;
	int k,i;
	int h;
	bool operator<(const point&p)const{
		return h>p.h;
	}
};
string s;
int jb;
unordered_map<string,int> vis;
int geth(string &t,int k){
	for(int i=0;i<4;i++){
		for(int j=0;j<4;j++){
			if(t[i*4+j]!='0'){
				char c=t[i*4+j];
				int a=(c>='a'?(c-'a'+10):c-'0');
				int x=(a-1)/4,y=(a-1)%4;
				k+=abs(x-i)+abs(y-j);
			}
		}
	}
	return k;
}
void solve(){
	priority_queue<point> q;
	point p={s,0,jb};
	p.h=geth(p.s,p.k);
	q.push(p);
	while(!q.empty()){
		p=q.top();q.pop();
		if(vis[p.s])continue;
		vis[p.s]=1;
//		cout<<p.k<<" "<<p.s<<"\n";
		if(p.s=="123456789abcdef0")cout<<p.k<<"\n",exit(0);
		int i=p.i;
		p.k++;
		if(i-4>=0){
			p.i=i-4;
			swap(p.s[p.i],p.s[i]);
			p.h=geth(p.s,p.k);
			if(p.h<=45)q.push(p);
			swap(p.s[p.i],p.s[i]);
		}
		if(i+4<16){
			p.i=i+4;
			swap(p.s[p.i],p.s[i]);
			p.h=geth(p.s,p.k);
			if(p.h<=45)q.push(p);
			swap(p.s[p.i],p.s[i]);
		}
		if(i-1>=0&&i%4!=0){
			p.i=i-1;
			swap(p.s[p.i],p.s[i]);
			p.h=geth(p.s,p.k);
			if(p.h<=45)q.push(p);
			swap(p.s[p.i],p.s[i]);
		}
		if(i+1<16&&(i+1)%4!=0){
			p.i=i+1;
			swap(p.s[p.i],p.s[i]);
			p.h=geth(p.s,p.k);
			if(p.h<=45)q.push(p);
			swap(p.s[p.i],p.s[i]);
		}
	}
}
int main(){
//	freopen("a.txt","r",stdin);
//	freopen("b.txt","w",stdout);
	int ta;
	for(int i=0;i<16;i++){
		cin>>ta;
		if(ta<=9)s+=('0'+ta);
		else s+='a'+(ta-10);
		if(ta==0)jb=i;
	}
	solve();
	return 0;
}


Measured memory_bytes: 137712
#include <cstdio>
using namespace std;
 
#define INF 1234567890;
int L[300000], R[300000];
int cnt;
 
void merge(int A[], int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; i++) L[i] = A[left + i];
    for (int i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1] = INF;
    R[n2] = INF;
 
    int i = 0;
    int j = 0;
 
    for (int k = left; k < right; k++) {
        cnt++;
        if (L[i] <= R[j]) A[k] = L[i++];
        else A[k] = R[j++];
    }
}
 
void mergeSort(int A[], int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}
 
int main(void) {
    int n, A[600000];
    cnt = 0;
 
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &A[i]);
 
    mergeSort(A, 0, n);
 
    for (int i = 0; i < n; i++) {
        if (i > 0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n%d\n", cnt);
 
    return 0;
}

Measured memory_bytes: 4948
// writer: w33z8kqrqk8zzzx33
#include <bits/stdc++.h>
using namespace std;
 
#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    vector<int> v;
    rep(i, 3) { int t; cin >> t; v.pb(t); }
    sort(all(v));
    if(v[0] == v[1] && v[1] != v[2]) cout << "Yes" << endl;
    else if(v[0] != v[1] && v[1] == v[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 256