akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

const int INF = INT_MAX / 2;

vector<int> as;

int main(void) {
    int N;
    cin >> N;

    as.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> as[i];
    }
    sort(as.begin(), as.end());

    {
        int n = as.back();

        /* solution 1 */
        // int k = -INF;
        // for (int i = 0; i < N - 1; i++) {
        //     if (n % 2 == 0 &&
        //             (abs(n / 2 - as[i]) < abs(n / 2 - k))) {
        //         k = as[i];
        //     }
        //     if (n % 2 == 1 &&
        //             (abs(n / 2 - as[i]) < abs(n / 2 - k) || abs(n / 2 + 1 - as[i]) < abs(n / 2 + 1 - k))) {
        //         k = as[i];
        //     }
        // }

        /* solution 2 */
        auto it = lower_bound(as.begin(), as.end() - 1, n / 2);
        assert(it != as.end());
        int cand1 = *it;
        int cand2 = *(--it);
        int k = (cand1 < n - cand2) ? cand1 : cand2;

        cout << n << " " << k << endl;
    }

    return 0;
}


Measured memory_bytes: 3688
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <complex>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  string S;
  static int F[1000];
  F[0] = 1;
  for (auto i = 0; i < N; ++i) {
    cin >> S;
    if (S[0] == '#')
      F[0] = 0;
    for (auto j = 1; j < M; ++j)
      F[j] = S[j] == '#' ? 0 : (F[j - 1] + F[j]) % 1000000007;
  }
  cout << F[M - 1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <utility>
#include <set>

using namespace std;

typedef pair <int, int> ii;

//#define DEBUG

int N;
vector <ii> incidentEdges[100005];
set <int> colourVertex[100005];
int colourAns[100005];
int K;

int main()
{
    scanf("%d", &N);
    for (int i = 1; i < N; i++)
    {
        int a, b; scanf("%d%d", &a, &b);
        incidentEdges[a].emplace_back(i, b); incidentEdges[b].emplace_back(i, a);
    }

    K = 1;
    for (int i = 1; i <= N; i++)
    {
        #ifdef DEBUG
        printf("i: %d\n", i);
        #endif // DEBUG

        int curColour = 1;
        for (ii edge : incidentEdges[i])
        {
            if (colourAns[edge.first] != 0) continue;

            #ifdef DEBUG
            printf("Current edge: From %d to %d; Edge number %d\n", i, edge.second, edge.first);
            printf("Current colour: %d; ", curColour);
            #endif // DEBUG

            while (*colourVertex[i].lower_bound(curColour) == curColour) curColour++;

            #ifdef DEBUG
            printf("Correct colour: %d\n", curColour);
            #endif // DEBUG

            colourAns[edge.first] = curColour;
            K = max(K, curColour);
            colourVertex[i].insert(curColour); colourVertex[edge.second].insert(curColour);
            curColour++;
        }
    }

    printf("%d\n", K);
    for (int i = 1; i < N; i++)
    {
        printf("%d\n", colourAns[i]);
    }
    return 0;
}


Measured memory_bytes: 20992
<?php
/*
    Problem URL : http://abc044.contest.atcoder.jp/tasks/abc044_a

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

ini_set('error_reporting', E_ALL & ~E_NOTICE);

fscanf(STDIN, "%s", $S['a']);
fscanf(STDIN, "%s", $S['b']);
fscanf(STDIN, "%s", $S['c']);

$turn = "a";

while (true) {
    $len = strlen($S[$turn]);
    if ($len === 0) {
        echo strtoupper($turn) . PHP_EOL;
        exit;
    } else {
        $org = $S[$turn];
        $S[$turn] = substr($S[$turn], 1);
        $turn = substr($org, 0, 1);
    }
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define debug cerr << "-- " << __LINE__ << " --" << endl
#define MOD 1000000007
#define ALL(o) (o).begin(), (o).end()
typedef long long int ll;

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template <typename T> string to_string(const vector<T> &xs) {string s="["; for(int i=0;i<xs.size();i++) s += (i>0 ? " " : "") + to_string(xs[i]); return s + "]";}
template <typename T> ll argmax(const T &xs) {return distance(xs.begin(), max_element(xs.begin(), xs.end()));}
template <typename T> ll argmin(const T &xs) {return distance(xs.begin(), min_element(xs.begin(), xs.end()));}
ll nextLL(){ll x; scanf("%lld", &x); return x;}
int nextInt(){int x; scanf("%d", &x); return x;}
string nextString(){string s; cin >> s; return s;}


ll extgcd(ll a, ll b, ll &x, ll &y) {
    /* g を返す時点で ax + by == g となる */
    ll g = a; x = 1; y = 0;
    if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
    return g;
}
ll gcd(ll a, ll b) { ll x, y; return extgcd(a, b, x, y); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll remainder(ll x, ll y) {assert(y > 0); ll r = x % y; if (r < 0) r += y; return r;}
ll quotient(ll x, ll y) {assert(y > 0); return (x - remainder(x, y)) / y;}

class llm{
	ll n;
public:
	llm(){n = 0;}
	llm(ll n){this->n = (n >= 0) ? (n % MOD) : (MOD - 1 - (-n-1 % MOD));}
	operator ll() const {return n;}
	llm operator+(const llm &y) const{ return llm((ll)*this + (ll)y);}
	llm operator+=(const llm &y) { *this = *this + y; return *this;}
	llm operator-(const llm &y) const{ return llm((ll)*this - (ll)y);}
	llm operator-=(const llm &y) { *this = *this - y; return *this;}
	llm operator-() const{ return llm(0) - *this;}
	llm operator*(const llm &y) const{ return llm((ll)*this * (ll)y);}
	llm operator*=(const llm &y) { *this = *this * y; return *this;}
	llm operator/(const llm &y) const{ return *this * y.inv();}
	llm operator/=(const llm &y) { *this = *this / y; return *this;}
	llm inv() const{
		ll x, y;
		if (extgcd(n, MOD, x, y) == 1) return llm(x);
  		return llm(0); // unsolvable
	}
	friend istream& operator >> (istream& os, llm& x);
	friend ostream& operator << (ostream& os, const llm& x);
};
istream& operator >> (istream& is, llm& x){ll n; is >> n; x = llm(n); return is;}
ostream& operator << (ostream& os, const llm& x){os << (ll)x; return os;}

template<typename T> T comb(ll n, ll k){
	T ret = 1;
	for(ll i=1;i<=k;i++) ret = ret * T(n - k + i) / T(i);
	return ret;
}

ll a, b, n;

int main(void){
	cin >> a >> b >> n;
	ll x = min(b-1, n);
	ll ans = a * x / b - a * (x / b);
	cout << ans << endl;
	


    return 0;
}




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

bool f(int a, int b, int c) {
  if (a == 1) {
    return true;
  }

  for (int i = 1; i < b; ++i) {
    if (a*i%b == c) {
      return true;
    }
  }
  return false;
}
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    a /= 2;
    b /= 2;
    c /= 2;
  }
  for (int i = 3; i * i <= min(min(a, b), c); i += 2) {
    while (a%i == 0 && b%i == 0 && c%i == 0) {
      a /= i;
      b /= i;
      c /= i;
    }
  }

  if (f(a, b, c)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


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

using namespace std;
using ll=long long;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const long long INF = 1LL<<60;
const int MOD = 1000000007;

int dp[1005][1005];
char a[1005][1005];

int main() {

int h,w; cin >> h >> w;


for (int i = 1; i < h+1; ++i)
{
    for (int j = 1; j < w+1; ++j)
    {
        cin >> a[i][j];
    }
}

for (int i = 0; i < h+1; ++i)
{
    for (int j = 0; j < w+1; ++j)
    {
        dp[i][j] = 0;
    }
}
dp[0][1] = 1;

for (int i = 0; i < h+1; ++i)
{
   for (int j = 0; j < w+1; ++j)
   {
        if(a[i][j]=='#') continue;
        if(i<h&&a[i+1][j]=='.') dp[i+1][j] += dp[i][j];
        if(j<w&&a[i][j+1]=='.') dp[i][j+1] += dp[i][j];
        if(dp[i+1][j]>=MOD) dp[i+1][j] -= MOD;
        if(dp[i][j+1]>=MOD) dp[i][j+1] -= MOD;
   }
}


cout << dp[h][w];

return 0;
}




Measured memory_bytes: 5120
#include <bits/stdc++.h>
//#include <vector>
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
 

 
int main(){
    
   ll n,k;
   double kitai_k=0.0,kitai_max=0;
   cin>>n>>k;
   
  vector<int> p(n);
  vector<double> kitai(n);
  cout << fixed << setprecision(8);
  rep(i,n){
      cin>>p.at(i);
      kitai.at(i)=(p.at(i)+1)/2.0;
  }
  
  for(int i=0;i<k;i++){
      kitai_k+=kitai.at(i);
  }
  kitai_max=kitai_k;
  
  for(int i=k;i<n;i++){
      kitai_k=kitai_k+kitai.at(i)-kitai.at(i-k);
      if(kitai_max < kitai_k){
          kitai_max=kitai_k;
         // cout<<i<<endl;
      }
  }
  cout<<kitai_max<<endl;
  
  
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<iomanip>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;

using namespace std;
int main() {
	int a, b, c, d, e, k;
	cin >> a >> b >> c >> d >> e >> k;
	int f = max(a, max(b, max(c, max(d, e))));
	int g = min(a, min(b, min(c, min(d, e))));
	if (f - g > k) cout << ":(" << endl;
	else cout << "Yay!" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
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; }
//https://www.creativ.xyz/dump-cpp-652/
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
 
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

#ifdef DEBUG_
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

signed main(void) { cin.tie(0); ios::sync_with_stdio(false);
    int n; cin>>n;
    int cnt = 0;
    vector <int> a(n);
    rep(i,n) cin>>a[i];
    rep(i,n){
        if(cnt + 1 == a[i]) cnt++;
    }
    if(n - cnt == n) cout<<-1<<endl;
    else cout<<n - cnt<<endl;
}

Measured memory_bytes: 1920
import sys
sys.setrecursionlimit(2*10**5)
N = int(input())
edges = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = map(int,input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
visited = [False for _ in range(N)]
fennec = [-1 for _ in range(N)]
snuke = [-1 for _ in range(N)]
def dfs(start,visited,distance,d):
    visited[start] = True
    d[start] = distance
    for term in edges[start]:
        if visited[term]:
            continue
        dfs(term,visited,distance + 1,d)
dfs(0,visited,0,fennec)

visited = [False for _ in range(N)]
    
dfs(N-1,visited,0,snuke)
F = S = 0
for i in range(N):
    if fennec[i] <= snuke[i]:
        F+=1
    else:
        S+=1
if F>S:
    print("Fennec")
else:
    print("Snuke")



Measured memory_bytes: 118272
#include <stdio.h>
#define INF 10000000
#define NIL -1
void dijkstra();
void func();
int g[100][100]={},n;
int d[100],pi[100],Adj[100],flag[100]={};
int main(){
    int i,j,tmp,u,k;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d",&tmp);
            scanf("%d",&g[u][tmp]);
        }     
    }
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            if(g[i][j]==0) g[i][j]=INF;
        }     
    }
    dijkstra();
    for(i=0;i<n;i++){
        printf("%d %d\n",i,d[i]);
    }
    return 0;
}
void dijkstra(){
    int mincost,i,u,v;
    func();
    while(1){
        mincost=INF;
        for(i=0;i<n;i++){
            if(flag[i]!=1 && d[i]<mincost){
                mincost=d[i];
                u=i;
            }
        }
        if(mincost==INF) break;
        flag[u]=1;
        for(v=0;v<n;v++){
            if(flag[v]!=1 && (d[u]+g[u][v])<d[v]){
                pi[v]=u;
                d[v]=d[u]+g[u][v];
            }
        }
    }
}
void func(){
    int i;
    for(i=0;i<n;i++){
        d[i]=INF;
        pi[i]=NIL;
    }
    d[0]=0;
}



Measured memory_bytes: 2004
/*

    author : s@if

*/

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

#define 		NIL 			-1
#define		 	fi	 		    first
#define 		sec 			second
#define 		MAX 			INT_MAX
#define			INF 			99999999
#define 		ll 			    long long
#define 		PI 			    acos(-1.0)
#define			MOD 			1000000007
#define 		PLL 			pair<ll,ll>
#define 		PII			    pair<int,int>
#define 		ull 			unsigned long long
#define 		For(i,a,b) 		for(int i=a;i<=(int)b;i++)


bool Check(int N , int pos)	{	return (bool) (N & (1<<pos));}
int Set(int N, int pos) {	return N = N | (1<<pos);}

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hr[]={-2,-2,-1,+1,+2,+2,-1,+1};
int hc[]={+1,-1,+2,+2,-1,+1,-2,-2};
int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};

const int MAXN = (int)1e5+9;

int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */

    ll i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;

    cin>>n;

    vector<PLL>vv;

    For(i,1,n)
    {
        cin>>u>>v;

        vv.push_back(PLL(v,u));
    }

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

    t = 0;

    bool flag = true;
    For(i,0,n-1)
    {
        t+=vv[i].sec;

       // cout<<vv[i].sec<<" "<<vv[i].fi<<" "<<t<<endl;

        if(t>vv[i].fi)
        {
            flag = false;
            break;
        }
    }

    if(flag)
        cout<<"Yes\n";
    else
        cout<<"No\n";

   // main();

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll Q; cin >> Q;
    while ( Q-- ) {
        ll rest = 3;
        vector<bool> state(3, false);
        ll ans = 0;
        while (rest) {
            string s; cin >> s;
            if (s == "HIT") {
                ans += state[2];
                RREP(i, 2) state[i+1] = state[i];
                state[0] = true;
            }
            else if (s == "OUT") {
                --rest;
            }
            else {
                REP(i, 3) {
                    ans += state[i];
                    state[i] = false;
                }
                ++ans;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3128
n=int(input())
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
p=[a+b for a,b in l]
q=[a-b for a,b in l]
p.sort()
q.sort()
print(max(p[-1]-p[0],q[-1]-q[0]))


Measured memory_bytes: 62108
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;



int main(){
    int n,m;
    cin >> n >> m;
    Graph g(n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int> dist(n, -1);
    vector<int> pa(n,-1);
    queue<int> que;
    dist[0] = 0, que.push(0);
    while (!que.empty()) {
        int v = que.front(); que.pop();
        for (auto nv : g[v]) {
            if (dist[nv] == -1) {
                dist[nv] = dist[v] + 1;
                pa[nv] = v;
                que.push(nv);
            }
        }
    }
    cout << "Yes" << endl;
    rep(i,n-1){
        cout << pa[i+1]+1 << endl;
    }


    return 0;
}

Measured memory_bytes: 12760
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe

readInt = fst . fromJust . BS.readInt

readString = map BS.unpack . BS.words

getInt = readInt <$> BS.getLine

getNString n = concat . map readString <$> replicateM n BS.getLine

getS :: [String] -> Integer
getS [] = 0
getS (s : ss) = n + getS ts
  where
    (ss', ts) = span (== s) ss
    k = fromIntegral (length ss') :: Integer
    n = (k * (k + 1)) `div` 2

main = do
  n <- getInt
  ss <- getNString n
  let ss' = sort (map (\x -> sort x) ss)
  print $ getS ss'


Measured memory_bytes: 91780
N = int(input())
memo = {}

def lucas(n):
    if n == 0:
        return 2
    elif n == 1:
        return 1
    elif n in memo:
        return memo[n]
    result = lucas(n - 1) + lucas(n - 2)
    memo[n] = result
    return result

print(lucas(N))

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

using namespace std;
using ll = long long;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount


int main() {
    string S;
    cin >> S;
    int N = (int) S.size();
    long long ans = 0LL;

    for (int b = 0; b < (1 << N - 1); ++b) {
        long long tmp_sum = 0LL;
        int p_b = 0, cnt = 0;
        for (int i = 0; i < N - 1; i++) {
            cnt++;
            if (b >> i & 1) {
                tmp_sum += stoll(S.substr(p_b, cnt));
                p_b = i + 1;
                cnt = 0;
            }
        }
        ans += (tmp_sum + stoll(S.substr(p_b)));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
        Scanner scan = new Scanner(System.in);
        int str = scan.nextInt();
 
      int input=str+2;
      
      int output=0;
      
      if(input%2==0){
        output=1;
      }
      
        System.out.println(output);
        scan.close();
	}
}

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

typedef long long ll;
typedef vector<ll> vl;

const int MOD = (int)(1e+9) + 7;
int S, N;
vector<vl> dp;

int main(void) {
	cin >> S;
	N = S / 3;
	dp.resize(N + 1, vl(S + 1, (ll)0));
	for (int j = 3; j <= S; ++j)
		dp[1][j] = 1;
	for (int i = 1; i < N; ++i) {
		for (int j = 3 * i; j <= S; ++j) {
			for (int k = 3; k <= S; ++k) {
				int sum = j + k;
				if (sum > S)
					break;
				dp[i + 1][sum] += dp[i][j];
				dp[i + 1][sum] %= MOD;
			}
		}
	}
	ll ans = (ll)0;
	for (int i = 1; i <= N; ++i) {
		ans += dp[i][S];
		ans %= MOD;
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 13728
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N);
    for (auto& a : A) {
        cin >> a;
    }
    ll ans = A.front() - 1;
    ll now = 2;
    rep(i, 1, N) {
        if (A[i] == now) {
            ++now;
        }
        if (A[i] % now == 0) {
            A[i] -= now + 1;
            ++ans;
        }
        ans += A[i] / now;
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int N, M;
    cin >> N;
    map<string, int> m;
    for (int i = 0; i < N; i++)
    {
        string s;
        cin >> s;
        m[s]++;
    }
    cin >> M;
    for (int i = 0; i < M; i++)
    {
        string s;
        cin >> s;
        m[s]--;
    }

    int max = 1 << 31;
    for (auto i = m.begin(); i != m.end(); i++)
    {
        max = std::max(max, i->second);
    }

    if (max < 0)
    {
        max = 0;
    }
    cout << max << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>

#define N_MAX 20
#define INF 100000000

int f[N_MAX][N_MAX];

using namespace std;


int main(void)
{
	int n;
	int t;
	int i1,i2,i3;

	while(1){
		cin>>n;
		if(n==0) break;

		
		for(i1=0;i1<n;i1++){
			for(i2=0;i2<n+1;i2++){
				cin>>f[i1][i2];
			}
		}

		int dp[1<<n];
		int minn;
		for(i1=0;i1<(1<<n);i1++) dp[i1]=INF;

		dp[(1<<n)-1]=0;
		for(i1=(1<<n)-2;i1>=0;i1--){
			for(i2=0;i2<n;i2++){

				
				if(((i1>>i2) & 1)==0){	
					minn=f[i2][0];
					for(i3=0;i3<n;i3++){
						if(((i1>>i3)&1)==1){
							if(minn>f[i2][i3+1]) minn=f[i2][i3+1];
						}
					}
					dp[i1]=min(dp[i1],dp[i1|1<<i2]+minn); 
					//cout<<i1<<" "<<dp[i1]<<endl;
				}

				
			}
		}
		cout<<dp[0]<<endl;

	}

	return 0;
}

Measured memory_bytes: 1416
s = list(input())
t = [int(n) for n in s]
a = t[0]*10+t[1]
b = t[2]*10+t[3]
if a>12 and b<=12 and b>0:
    print("YYMM")
elif a==0 and b<=12 and b>0:
    print("YYMM")
elif a<=12 and b>12 and a>0:
    print("MMYY")
elif a<=12 and b==0 and a>0:
    print("MMYY")
elif a<=12 and b<=12 and a>0 and b>0:
    print("AMBIGUOUS")
else :
    print("NA")

Measured memory_bytes: 3064
s = int(input())

def f(n):
    if n%2: return 3*n+1
    else: return n//2

A = {s}
for ans in range(2, 10**6+10):
    if f(s) in A:
        print(ans)
        break
    A.add(f(s))
    s = f(s)


Measured memory_bytes: 9112
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int N;
    cin >> N;
    vector<ll> x(N), y(N);
    for(int i = 0; i < N; ++i){
        ll X, Y;
        cin >> X >> Y;
        x[i] = X - Y;
        y[i] = X + Y;
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    ll ans = max(x.back() - x[0], y.back() - y[0]);
    cout << ans << endl;
}

Measured memory_bytes: 6364
n,m = map(int,input().split())
h = list(map(int,input().split()))
c = dict()
for i in range(m):
    a, b = map(int,input().split())
    if a in c:
        c[a].append(b)
    else:
        c[a] = [b]
    if b in c:
        c[b].append(a)
    else:
        c[b] = [a]
        
cnt = n
for k,v in c.items():
    for i in range(len(v)):
        if h[v[i] - 1] >= h[k - 1]:
            cnt -= 1
            break
print(cnt)

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

int findSumOfDigit(int n) {
    int sum = 0;
    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main() {
    int N;
    cin >> N;
    int fx = findSumOfDigit(N);
    if (N % fx == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
long long n,m,mx;
int main()
{
	scanf("%lld%lld",&n,&m);
	if(n*2>=m) mx=m/2;
	else if(n*2<m) mx=(m-n*2)/4+n;
	printf("%lld\n",mx);	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include<atcoder/all>
#define ll long long
ll a, n, l, i;
void f(ll x, ll y) {
  if ((i = std::__gcd(x,y) > 1 ? 0 : atcoder::inv_mod(x,y)) > 0)
    a = std::min({a, i * x - 1, (y-i) * x});
}
main() {
  std::cin >> n; a = n + (n & 1 ^ 1);
  for (ll d = 1; d * d <= n; d++)
    if (n % d == 0)
      f(2 * d, n / d), f(2 * n / d, d);
  std::cout << a << "\n";
}

Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;

int main() {
    ll X, K, D;
    cin >> X >> K >> D;
    X = abs(X);

    ll straight = min(K, X / D);
    K -= straight;
    X -= straight * D;

    if (K % 2 == 0) {
        cout << X << endl;
    } else {
        cout << D - X << endl;
    }

    return 0;
}

Measured memory_bytes: 3624
n = int(input())
S_list = list( map(int,input().split()) )
q = int(input())
T_list = list( map(int,input().split()) )

# print(n,q)
# print(S_list)
# print(T_list)

def binary_search(list, x):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high)//2

        if list[mid] == x:
            return True
        elif list[mid] < x:
            low = mid + 1
        else:
            high = mid - 1

    return False

# 重複した要素を削除
S_set = sorted(set(S_list))
# print(S_set)

cnt = 0
for t in T_list:
    if binary_search(S_set, t):
        cnt += 1

print(cnt)


Measured memory_bytes: 16716
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    char a, b, c, d;
    getchar();
    getchar();
    a=getchar();
    b=getchar();
    c=getchar();
    d=getchar();
    if(a==b&&c==d){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

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

int main(){
    int n, w, x;
    while(cin >> n >> w, n+w){
        int hist[11] = {};
        for(int i = 0; i < n; i++){
            cin >> x;
            hist[x/w]++;
        }
        int ma = *max_element(hist, hist+11);
        int width;
        for(width = 10;; width--)   if(hist[width]) break;
        double ink = 0.01;
        for(int i = 0; i <= width; i++){
            ink += (double)hist[i] / ma * (width-i) / width;
        }
        cout << fixed << setprecision(10) << ink << endl;
    }
    return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S; cin>>S;
  int Q; cin>>Q;
  deque<char>A;
  for(int i=0;i<S.size();i++)A.push_back(S.at(i));
  bool B=false;
  int count=0;
  for(int i=0;i<Q;i++){
    int T; cin>>T;
    if(T==1)B=(B==false? true:false);
    else{
      int F; cin>>F;
      char C; cin>>C;
      if((B==true&&F==1)||(B==false&&F==2))A.push_back(C);
      else A.push_front(C);
      count++;
    }
  }
  if(B==false)for(int i=0;i<count+S.size();i++){cout<<A.front();A.pop_front();}
  else for(int i=count+S.size();i>0;i--){cout<<A.back();A.pop_back();}
  cout<<endl;
}

Measured memory_bytes: 3984
n,k=map(int,input().split())
mi = min(n-1,k)
di = 10**9+7
def pow_k(x,i):
    if i==0:
        return 0
    K=1
    while i>1:
        if i % 2 != 0:
            K = (K*x)%di
        x = (x*x)%di
        i //= 2

    return (K * x)%di

lis = [i for i in range(n+1)]
lisr = [i for i in range(n+1)]
lis[0]=1
for i in range(1,n+1):
    lis[i]=(lis[i-1]*lis[i])%di
    lisr[i] = pow_k(lisr[i],di-2)

lisr[0]=1
for i in range(1,n+1):
    lisr[i]=(lisr[i-1]*lisr[i])%di

#print(lis,lisr)

su = 1
for i in range(1,mi+1):
    pl = ((((lis[n-1]*lisr[i])%di)*lisr[n-1-i])%di)
    plu = (pl*((((lis[n]*lisr[i])%di)*lisr[n-i])%di))%di
    su+=plu
    su%=di
print(su)


Measured memory_bytes: 55244
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<climits>
#define int long long
using namespace std;
inline int read(){
	int f=1,ans=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return f*ans;
}
const int MAXN=200001;
int st[MAXN][21],n,a[MAXN];
int Query(int l,int r){
	int k=log2(r-l+1);
	return min(st[l][k],st[r-(1<<k)+1][k]);
}
int Ql(int x){
	int l=1,r=x-1,minn=INT_MAX;
	while(l<=r){
		int mid=l+r>>1;
		if(Query(mid,x-1)>a[x]) r=mid-1,minn=min(minn,mid);
		else l=mid+1;
	}return minn;
}
int Qr(int x){
	int l=x+1,r=n,maxn=	INT_MIN;
	while(l<=r){
		int mid=l+r>>1;
		if(Query(x+1,mid)>=a[x]) l=mid+1,maxn=max(maxn,mid);
		else r=mid-1; 
	}return maxn;
}int ans;
signed main(){
//	freopen("6.in","r",stdin);
	n=read();
	for(int i=1;i<=n;i++) a[i]=st[i][0]=read();
	for(int j=1;j<=log2(n);j++)
		for(int i=1;i+(1<<j)-1<=n;i++) st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]);
	for(int i=1;i<=n;i++){
		int l=Ql(i),r=Qr(i);
		if(l==INT_MAX) l=i;
		if(r==INT_MIN) r=i;
		int lena=i-l,lenb=r-i;
		ans+=(lena+lenb+1+lena*lenb)*a[i];
	}printf("%lld\n",ans);
}


Measured memory_bytes: 34688
N = int(input())
pt_taro = 0
pt_hana = 0
for _ in range(N):
    taro, hanako = input().split()
    if taro < hanako:
        pt_hana += 3
    elif hanako < taro:
        pt_taro += 3
    elif taro == hanako:
         pt_taro += 1
         pt_hana += 1

print(pt_taro, pt_hana)


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n1;
    cin>>n1;
    string str=to_string(n1);
    int n=str.size();
    if(str[n-1]=='2'||str[n-1]=='4'||str[n-1]=='5'||str[n-1]=='7'||str[n-1]=='9')
    cout<<"hon"<<"\n";
    else if(str[n-1]=='0'||str[n-1]=='1'||str[n-1]=='6'||str[n-1]=='8')
    cout<<"pon"<<"\n";
    else
    cout<<"bon"<<"\n";

}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define int long long
#define pb push_back
#define inf 1e9
#define mod 1000000007

void solve()
{
	int N, W;
	cin >> N >> W;

	int val[N + 1], w[N + 1];
	for (int i = 1; i <= N; i++)
	{
		cin >> w[i] >> val[i];
	}

	int dp[N + 1][W + 1];

	memset(dp, 0, sizeof(dp));

	for (int i = 0; i <= N; i++)
	{
		for (int j = 0; j <= W; j++)
		{
			if (i == 0 or j == 0)
			{
				dp[i][j] = 0;
			}
			else if (w[i] <= j)
			{
				dp[i][j] = max(dp[i - 1][j], val[i] + dp[i - 1][j - w[i]]);
			}
			else
			{
				dp[i][j] = dp[i - 1][j];
			}
		}
	}
	// for (int i = 0; i <= N; i++)
	// {
	// 	for (int j = 0; j <= W; j++)
	// 	{
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << "\n";
	// }
	cout << dp[N][W] << "\n";

}

int32_t main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	solve();
	return 0;
}


Measured memory_bytes: 82436
#include <iostream>
#include <algorithm>

using namespace std;

int main(void) {
  int a, b;
  cin >> a >> b;
  int g = 0;
  if (a > b) {
    g += a;
    a--;
  }else {
    g += b;
    b--;
  }
  if (a > b) {
    g += a;
  }else {
    g += b;
  }

  cout << g << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(),k=sc.nextInt();
        System.out.println((int)(a+b+c+Math.max(a,Math.max(b,c))*(Math.pow(2,k)-1)));
        


    }
}

Measured memory_bytes: 19284
#include <iostream>
#include <stack>
#include <string>
#include <cstdlib>
using namespace std;

stack<string> s;

string pop()
{
  string str = s.top();
  s.pop();
  return str;
}

long long calc()
{
  string str;
  str = pop();
  long long left, right;
  if (str == "+")
  {
    right = calc();
    left = calc();
    return left + right;
  }
  else if (str == "-")
  {
    right = calc();
    left = calc();
    return left - right;
  }
  else if (str == "*")
  {
    right = calc();
    left = calc();
    return left * right;
  }
  else
  {
    return strtoull(str.c_str(), NULL, 10);
  }
}

int main()
{
  string str;
  while (cin >> str)
  {
    s.push(str);
  }

  long long res = calc();
  cout << res << endl;
}



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

using namespace std;

const bool debug = true;
#define dbg(...) if(debug) printf(__VA_ARGS__)
#define print(var) if (debug) cout << #var << " = " << var << endl

namespace {
    int N;
    vector<int> T, X, Y;
    void input() {
        cin >> N;
        T.resize(N);
        X.resize(N);
        Y.resize(N);
        for (int i = 0; i < N; i++) {
            cin >> T[i] >> X[i] >> Y[i];
        }
    }

    void solve() {
        auto calc = [&]() {
            int curX = 0, curY = 0;
            int curT = 0;
            for (int i = 0; i < N; i++) {
                int nextX = X[i];
                int nextY = Y[i];
                int nextT = T[i];
                int dx = abs(curX - nextX);
                int dy = abs(curY - nextY);
                int t = nextT - curT;
                int D = dx + dy;
                if (D > t || D % 2 != t % 2) return false;
            }
            return true;
        };
        cout << (calc() ? "Yes" : "No") << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}



Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include <iomanip>
#include<deque>
#include<stack>
#include<set>
#include <numeric>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 111111111;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int DIV = 1000000007; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;



int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================

	int N;
	cin >> N;
	vector<pair<ll, ll>> task(N);
	for (int i = 0; i < N; i++) {
		cin >> task[i].second >> task[i].first;
	}

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

	ll time = 0;
	for (int i = 0; i < N; i++) {
		time += task[i].second;
		if (time > task[i].first) {
			cout << "No";
			return 0;
		}


	}

	cout << "Yes";





}



Measured memory_bytes: 3328
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
# from fractions import gcd

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)

n = int(input())
A = list(map(int, input().split()))
xor = 0
for i in range(n):
    xor ^= A[i]

ans = [0]*n
for i in range(n):
    ans[i] = xor ^ A[i]

print(*ans)


Measured memory_bytes: 97160
#include<iostream>
#include<queue>

using namespace std;

typedef struct
{
	int x;
	int y;
}Point;

const Point DIRE4[4] = {
	{0, -1},
	{-1, 0},
	{0, 1},
	{1, 0}
};

int H, W, N;
char field[1000][1000];
int dist[1000][1000];

int seek(Point &S, Point &G)
{
	
	for(int y = 0;y < H;y++)
	{
		for(int x = 0;x < W;x++)
		{
			dist[y][x] = -1;
		}
	}
	
	dist[S.y][S.x] = 0;
	
	queue<Point> pointQ;
	Point start = {S.x, S.y};
	pointQ.push(start);
	
	while(!pointQ.empty())
	{
		Point p = pointQ.front();
		pointQ.pop();
		
		if(p.x == G.x && p.y == G.y) break;
		
		for(int i = 0;i < 4;i++)
		{
			int tx = p.x + DIRE4[i].x;
			int ty = p.y + DIRE4[i].y;
			
			if(0 <= tx && tx < W && 0 <= ty && ty < H && field[ty][tx] != 'X')
			{
				if(dist[ty][tx] == -1 || dist[p.y][p.x] + 1 < dist[ty][tx])
				{
					dist[ty][tx] = dist[p.y][p.x] + 1;
					
					Point set = {tx, ty};
					pointQ.push(set);
				}
			}
		}
	}
	
	return dist[G.y][G.x];
}

int main()
{
	int ans = 0;
	Point P[1 + 9]; //start + goal
	
	cin >> H >> W >> N;
	
	for(int y = 0;y < H;y++)
	{
		for(int x = 0;x < W;x++)
		{
			char in;
			cin >> in;
			if(in == 'S'){ P[0].x = x; P[0].y = y; }
			else if('1' <= in && in <= '9')
			{
				int index = in - '1';
				P[index + 1].x = x;
				P[index + 1].y = y;
			}
			
			field[y][x] = in;
		}
	}
	
	for(int i = 0;i < N;i++)
	{
		ans += seek(P[i], P[i + 1]);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 5756
#include<stdio.h>

#define N 100
#define W 0
#define G 1
#define B 2

int n, m[N][N], color[N], d[N], f[N], t;

void dfs_visit(int u){
  int v;
  color[u] = G;
  d[u] = ++t;
  for(v = 0 ; v < n ; v++){
    if(m[u][v] == 0) continue;
    if(color[v] == W){
      dfs_visit(v);
    }
  }
  color[u] = B;
  f[u] = ++t;
}

void dfs(){
  int u;
  for(u = 0 ; u < n ; u++) color[u] = W;
  t = 0;

  for(u = 0 ; u < n ; u++){
    if(color[u] == W) dfs_visit(u);
  }
  for(u = 0 ; u < n ; u++){
    printf("%d %d %d\n", u + 1, d[u], f[u]);
  }
}


int main(){
  int u, v, k, i, j;

  scanf("%d", &n);
  for(i = 0 ; i < n ; i++){
    for(j = 0 ; j < n ; j++) m[i][j] = 0;
  }

  for(i = 0 ; i < n ; i++){
    scanf("%d %d", &u, &k);
    u--;
    for(j = 0 ; j < k ; j++){
      scanf("%d", &v);
      v--;
      m[u][v] = 1;
    }
  }

  dfs();

  return 0;
}


Measured memory_bytes: 2112
n,k=map(int,input().split())
a=list(map(int,input().split()))

start=1
list=[1]
kenti=[0 for i in range(n)]
kenti[0]=1

zan=-1

for i in range(k):
  start-=1
  next=a[start]
  start=next

  if kenti[start-1]!=0:
    zan=k-(i+1)
    inx=list.index(start)
    list=list[inx:]
    break
  else:
    list.append(start)
    kenti[start-1]+=1

if zan==-1:
  print(list[-1])
  exit()
elif zan==0:
  print(list[0])
  exit()

zan%=len(list)
print(list[zan])

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

using namespace std;

using ll = long long;

int const mod = 1e9 + 7;
int const maxn = 21;

vector<int> v[maxn];

uint32_t next_perm(uint32_t v) {
    uint32_t t = (v | ( v - 1)) + 1;
    uint32_t w = t | ((((t & -t) / (v & -v)) >> 1) - 1);
    return w;
}

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

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            int ok;
            cin >> ok;

            if (ok) {
                v[i].push_back(j);
            }
        }
    }

    vector<int> dp(1<<n);
    dp[0] = 1;

    for (int cnt = 1; cnt <= n; cnt++) {
        for (int x = (1<<cnt)-1; x < (1<<n); x = next_perm(x)) {
            for (int y : v[cnt-1]) {
                if (x&(1<<y)) {
                    dp[x] += dp[x^(1<<y)];

                    if (dp[x] >= mod) {
                        dp[x] -= mod;
                    }
                }
            }
        }
    }

    cout << dp[(1<<n)-1] << "\n";
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin>>N>>M;
  if(M==5){
    cout<<(1900*5+100*(N-M))*32<<endl;
  }
  if(M==4){
    cout<<(1900*4+100*(N-M))*16<<endl;
  }
  if(M==3){
    cout<<(1900*3+100*(N-M))*8<<endl;
  }
  if(M==2){
    cout<<(1900*2+100*(N-M))*4<<endl;
  }
  if(M==1){
    cout<<(1900+100*(N-M))*2<<endl;
  }
}

Measured memory_bytes: 3596
#include <iostream>

using namespace std;

int main()
{
  int W,H,x,y,r;

  cin >> W >> H >> x >> y >> r;

  /*if(x-r < 0 || x+r > W  )
    {
      cout << "No" << endl;
    }
  if(y-r < 0 || y+r > H)
    {
      cout << "No" << endl;
    }*/

  if(x-r >= 0 && x+r <= W && y-r >= 0 && y+r <= H)
    {
      cout << "Yes" << endl;
    }
  else
    {
      cout << "No" << endl;
    }

  return 0;
}



Measured memory_bytes: 3100
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <vector>
using namespace std;
int n;
int m;
int c[1000];
int d[1000];
int e;
int main(){
	cin >> n >> m;
	for (int i = 0; i < m; i++){
		cin >> c[i];
		cin >> d[i];
	}
	sort (c, c+m);
	for (int i = 1; i < m; i++){
		if (c[i] < n){
			e += n - c[i];
		}
	}
	cout << e << endl;

	return 0;
}

Measured memory_bytes: 3136
#include<iostream>

using namespace std;

bool is_sorted(int n, int* arr){
	for(int i = 1 ; i < n ; i++){
		if(arr[i] < arr[i - 1]){
			return false;
		}
	}
	return true;
}

int main(){
	int n;
	scanf("%d", &n);
	int a[n];
	for(int i = 0 ; i < n ; i++){
		scanf("%d", a + i);
	}
	for(int i = 0 ; i < n ; i++){
		for(int j = i ; j < n ; j++){
			swap(a[i], a[j]);
			if(is_sorted(n, a)){
				printf("YES\n");
				return 0;
			}
			swap(a[i], a[j]);
		}
	}
	printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
int main(){
	long long int N,a[10000],max=-1000000000,min=100000000,sum=0;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>a[i];
		if(a[i]>max){
			max=a[i];
		}
		if(a[i]<min){
			min=a[i];
		}
		sum+=a[i];
	}
	cout<<min<<" "<<max<<" "<<sum<<endl;
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
 

signed main(void){
    int N;
    string S;
    cin >> N >> S;
    int Ans=0;
    REP(i,N-2){
        if(S[i]=='A' &&S[i+1]=='B' &&S[i+2]=='C'  ){
            Ans++;
        }
    }
    cout << Ans << endl;
    return 0;
}



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

int main(){
  string s;
  int check=0,c=0;

  cin >>s;
  vector<int> ans(s.size());
  for(int i=0;i<s.size();i++){
    for(int j=i;j<s.size();j++)
      if(s.at(j)=='A'||s.at(j)=='C'||s.at(j)=='G'||s.at(j)=='T')
        ans.at(i)++;
      else
        break;
  }
  sort(ans.begin(), ans.end(), greater< int >());
  cout <<ans.at(0)<<endl;
}


Measured memory_bytes: 256
import java.io.*;

class Main {
	public static void main(String args[]) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String t[], s;
			int a[] = new int[2];
			int c;
			while((s = reader.readLine())  != null) {
				t = s.split(" ");
				for(int i = 0;i < a.length;i++) {
					a[i] = Integer.parseInt(t[i]);
				}
				int a0_tmp = a[0], a1_tmp = a[1];
				while(true) {
					c = a0_tmp % a1_tmp;
					if(c == 0)
						break;
					a0_tmp = a1_tmp;
					a1_tmp = c;
				}
				System.out.printf("%d %d\n", a1_tmp, a[0]/a1_tmp*a[1]);

			}

		}
		catch(IOException e) {
			System.out.println(e);
		}
	}
}

Measured memory_bytes: 16976
package main

import (
        "fmt"
)

func solution(s string) int {
        l := len(s)
        i := 0
        for i = l - 1; i >= 0; i-- {
                if isEvenString(s[:i]) {
                        break
                }
        }
        return i
}

func isEvenString(s string) bool {
        l := len(s)
        if l&1 == 1 {
                return false
        }
        if s[0:l/2] == s[l/2:l] {
                return true
        }
        return false
}

func main() {
        var s string
        fmt.Scan(&s)
        fmt.Println(solution(s))
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <array>
#include <cstring>
#include <map>
#include <stack>
#include <tuple>
#include <queue>
#include <vector>
#include <cmath>
#include <random>
#include <math.h>
#include <random>



#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define rREP(i, n) for(int (i) = (n) - 1; (i) >= 0; --(i))
#define ALL(TheArray) TheArray.begin(), TheArray.end()

using lli = long long int;
using pii = std::pair<int, int>;

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

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~





std::vector<int> A;
std::vector<std::pair<int, int>> Res;


int main(void){
    int n; scanf("%d", &n);
    A.resize(n); REP(i, n) scanf("%d", &A[i]);
    auto mn_itr = std::min_element(A.begin(), A.end());
    auto mx_itr = std::max_element(A.begin(), A.end());

    int argMn = std::distance(A.begin(), mn_itr);
    int argMx = std::distance(A.begin(), mx_itr);
    int mn = *mn_itr, mx = *mx_itr;

    printf("%d\n", 2 * n - 1);
    if(-mn < mx){ // all positive
        int X = argMx + 1;
        for(int x = 1; x <= n; ++x) printf("%d %d\n", X, x);
        for(int x = 1; x < n; ++x) printf("%d %d\n", x, x+1);
    }
    else{ // all negative
        int X = argMn + 1;
        for(int x = 1; x <= n; ++x) printf("%d %d\n", X, x);
        for(int x = n; x > 1; --x) printf("%d %d\n", x, x-1);
    }



    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n;
int main()
{
	cin>>n;
	for(;n--;)
	{
		string s,t,u="";cin>>s>>t;
		if(s.size()<t.size())swap(s,t);
		int a=0;
		for(int i=0;i<s.size();i++)
		{
			a+=s[s.size()-i-1]-48;
			if(i<t.size())a+=t[t.size()-i-1]-48;
			u+=a%10+48;
			a/=10;
		}
		if(a)u+=a+48;
		if(u.size()>80)
		{
			cout<<"overflow"<<endl;
		}
		else
		{
			for(int i=u.size();i--;)cout<<u[i];
			cout<<endl;
		}
	}
}



Measured memory_bytes: 3196