akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
#define left orz
using namespace std;
using ll = long long;
const int maxn = 150;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
namespace local {
	int L = 0;
	string s = "aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzAABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ001122334455667788", t;
	int dp[maxn][maxn];
	int f(int i, int j) {
		if(i == s.size() || j == t.size()) return max(t.size()-j, s.size()-i);
		if(dp[i][j] != -1) return dp[i][j];
		return dp[i][j] = min({f(i+1, j)+1, f(i, j+1)+1, f(i+1, j+1) + (s[i]!=t[j])});
	}
	int query(string _t) {
		t = _t;
		memset(dp, -1, sizeof dp);
		return f(0, 0);
	}
};
int n, left;
string d;
bitset<maxn> g;
char itc(int x) {
	for(auto c : {'a', 'A', '0'})
		if(x < 26) return c+x;
		else x -= 26;
}
map<string, int> meme;
int qry = 0;
int ask(string t) {
	if(meme.count(t)) return meme[t];
	++qry;
	//assert(++qry < 850);
	int x;
	cout << "? " << t << endl;
	if(local::L) x = local::query(t);
	else cin >> x;
	if(local::L) cout << "> " << x << endl;
	return meme[t] = x;
}
string fill(int l, int r, char c, int uwu = 0) {
	string res = uwu ? string(n, '.') : d;
	while(l <= r) {
		if(!g[l]) res[l] = c;
		l++;
	}
	return res;
}
int count(string s) {
	int t = left - ask(s);
	return t;
}
void solve(int l, int r, int cnt, char c) {
	if(cnt == 0) return;
	if(l > r) return;
	if(l == r) {
		if(cnt) {
			g[l] = 1;
			d[l] = c;
			left--;
		}
		return;
	}
	int mid = (l+r)/2;
	int x = count(fill(l, mid, c));
	solve(l, mid, x, c);
	solve(mid+1,r,cnt-x,c);
}
string insert(string a, int p, char c) {
	return a.substr(0, p) + string(1, c) + a.substr(p);
}
int complete(string &t, int p, char x, int v) {
	for(int i = 1<<7; i>>=1;) {
		if(t.size()+i>128) continue;
		string a = t.substr(0, p) + string(i, x) + t.substr(p);
		if(ask(a) == n-v) t = a, p += i;
	}
	g[p] = 1;
	left--;
	return p+1;
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	n = ask("a");
	if(n != 128 && ask(string(n+1, 'a')) < n+1) n++;
	left = n;
	vector<int> cnt(63);
	cnt[62] = 228;
	int f = 62, s = 62, FLAG = 1;
	for(int i = 0; i < 62; i++) {
		cnt[i] = count(fill(0, n-1, itc(i), 1));
		if(cnt[f] > cnt[i]) s = f, f = i;
		else if(cnt[s] > cnt[i]) s = i;
	}
	if(cnt[f] == 0) {
		FLAG = 0;
		d = string(n, itc(f));
	} else {
		int cf = cnt[f], cs = cnt[s];
		int q = n - cf - cs, v = cf + cs;
		string T(cf, itc(f));
		for(int i = T.size(); i >= 0; i--) {
			while(ask(T) > ask(insert(T, i, itc(s)))) T = insert(T, i, itc(s));
		}
		int i = 0;
		while(i < T.size()) {
			i = complete(T, i, T[i]^itc(f)^itc(s), v);
		}
		d = T;
		while(d.size() < n) d.pb(itc(f));
		for(int i = 0; i < n; i++) if(!g[i]) d[i] = itc(f);
	}
	if(local::L) {
		//cerr << qry << " " << d << endl;
		//for(int i = 0; i < n; i++) cerr << g[i] << " ";cerr << endl;
	}
	char c;
	for(int i = 0; i < 62; i++) {
		if(!FLAG || (i != f && i != s))
		c = itc(i), solve(0, n-1, cnt[i], c);
	}
	cout << "! " << d << endl;
	if(local::L) cerr << qry << endl;
	return 0;
}


Measured memory_bytes: 3820
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map> 
#define INF 0x3f3f3f3f
#define int long long
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int maxn=2e5+6;
const int mod=1e9+7;
const double pi=acos(-1.0);
int n,m;
int read(){        
    int s = 0, f = 1;        
    char ch = getchar();        
    while(!isdigit(ch)) {        
        if(ch == '-') f = -1;        
        ch = getchar();        
    }        
    while(isdigit(ch)) {        
        s = s * 10 + ch - '0';        
        ch = getchar();        
    }        
    return s * f;        
}        
void write(int x){        
    if(x < 0) {        
        putchar('-');        
        x = -x;        
    }        
    if(x > 9)        
        write(x/10);        
    putchar(x % 10 + '0');        
    return;        
}   
signed main(){
	string s;
    int k;
    cin>>k;
    cin>>s;
    if(k>=s.length())
       cout<<s<<endl;
    else cout<<s.substr(0,k)+"..."<<endl;
	return 0;
}


Measured memory_bytes: 3628
//https://atcoder.jp/contests/abc161/tasks/abc161_d
//D - Lunlun Number
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
const ll LINF = 0x1fffffffffffffff;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
int main() {
  // auto test_func = [&](){
  //   ll keta_max=5;
  //   vector<vector<ll>> tbl(keta_max,vector<ll>(10));
  //   FOR(d,1,10){
  //     tbl[0][d]=1;
  //   }
  //   FOR(k,1,keta_max){
  //     FOR(d,0,10){
  //       tbl[k][d] = tbl[k-1][d];
  //       if(d-1>0) tbl[k][d] += tbl[k-1][d-1];
  //       if(d+1<10) tbl[k][d] += tbl[k-1][d+1];
  //     }
  //   }
  //   dump(tbl);
  // };
  // test_func();
#if LOCAL&01
  std::ifstream in("./test/sample-1.in");
  //std::ifstream in("./input.txt");
  std::cin.rdbuf(in.rdbuf());
#else
  cin.tie(0);
  ios::sync_with_stdio(false);
#endif
  ll K; cin>>K;
  //bfs
  ll cnt=0;
  priority_queue<ll, vector<ll>, greater<ll> > que;

  auto check_cnt = [&](ll v){
    ++cnt;
    if(K<=cnt){
      cout<<v<<endl;
      exit(0);
    }
  };

  FOR(i,1,10){
    que.push(i);
    check_cnt(i);
  }
  while(true){
    auto v = que.top();
    que.pop();
    ll d0 = v%10;
    auto check_push = [&](ll d){
      if (d>=0&&d<=9) {
        ll tmp=v*10+d;
        que.push(tmp);
        check_cnt(tmp);
      }
    };
    check_push(d0-1);
    check_push(d0);
    check_push(d0+1);
  }
  return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);++i)
#define erep(i,j,n) for(int i=(j);i<=(n);++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	vs mini{ "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z" };
	string s;
	cin >> s;
	if (s[0] != 'A') {
		cout << "WA\n";
		return 0;
	}
	string x;
	x = s[1];
	if (!count(all(mini), x)) {
		cout << "WA\n";
		return 0;
	}
	x = s[s.size() - 1];
	if (!count(all(mini), x)) {
		cout << "WA\n";
		return 0;
	}
	bool c = false;
	rep(i, 2, s.size() - 1) {
		x = s[i];
		if (x == "C") {
			if (c) {
				cout << "WA\n";
				return 0;
			}
			else {
				c = true;
				continue;
			}
		}
		if (!count(all(mini), x)) {
			cout << "WA\n";
			return 0;
		}
	}
	if (c) cout << "AC\n";
	else cout << "WA\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long 
#define float long double 
#define el '\n'
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
        enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
        ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
        *this << "[";
        for (auto it = d.b; it != d.e; ++it)
                *this << ", " + 2 * (it == d.b) << *it;
        ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int inf = 1e10;
const int N = 1e5;

int arr[3][N] ;
int dp[3][N];

signed main(){
        IOS;
        int n; 
        cin >> n ;

        for(int i=0;i<n;i++){
                cin >> arr[0][i] >> arr[1][i] >> arr[2][i] ;
        }
        dp[0][0] = arr[0][0] ; dp[1][0] = arr[1][0] ; dp[2][0] = arr[2][0];
        for(int i=1;i<n;i++){
                dp[0][i] = max(dp[1][i-1],dp[2][i-1])+arr[0][i];
                dp[1][i] = max(dp[0][i-1],dp[2][i-1])+arr[1][i];
                dp[2][i] = max(dp[1][i-1],dp[0][i-1])+arr[2][i];
        }
        cout << max({dp[0][n-1],dp[1][n-1],dp[2][n-1]}) << endl ;
        return 0;
}

Measured memory_bytes: 4992
import math
INF, MOD = float("inf"), 1e9 + 7
MAX, MIN = -INF, INF
dx1, dy1, dx2, dy2 = [-1, 0, 1, 0], [0, -1, 0, 1], [-1, 0, 1, -1, 1, -1, 0, 1], [-1, -1, -1, 0, 0, 1, 1, 1]

def get_int():
    return int(input())

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

def mins(x, y):
    x = min(x, y)

def maxs(x, y):
    x = max(x, y)

while(True):
    try:
        cnt = [0] * 5
        for i in range(3):
            a, b = get_int_list()
            cnt[a] += 1
            cnt[b] += 1
        if cnt.count(2) == 2:
            print("YES")
        else:
            print("NO")
    except EOFError:
        exit()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
// -----------------<fast IO>------------------
#define IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FLSH             fflush(stdout)
#define fileIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);
#define PRECISION(x)     cout << fixed << setprecision(x);
#define endl             "\n"
// -----------------<Container manipulation / traversal macros>------------------
#define mp                 make_pair
#define pb                 push_back
#define ff                 first
#define ss                 second
#define sz(x)             ((int)((x).size()))
#define all(x)             (x).begin(),(x).end()
#define rep(i,n)         for(ll (i)=0;(i)<(n);(i)++)
#define forn(i,a,b)     for(ll (i)=(a);(i)<=(b);(i)++)
#define fill(l,a)        memset((l) , (a) , sizeof(l))
// -----------------<Some common useful functions>------------------
#define maX(a,b)        ( (a) > (b) ? (a) : (b))
#define miN(a,b)        ( (a) < (b) ? (a) : (b))
#define checkbit(n,b)   ( (n >> b) & 1)
#define INDEX(arr,i)      ( lower_bound(all(arr),i)-arr.begin())
#define in(b,a)         ( (b).find(a) != (b).end())
// -----------------<TypeDef Start>------------------
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector< std::vector<ll> > matrix;
typedef map<ll,ll> mii;
typedef vector<pii> vpii;
// -----------------<Constants>------------------
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);

const int INF=1e9;

int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
ll gcd(ll a,ll b)
{
    if(a==0)
    return(b);
    return(gcd(b%a,a));
}
ll lcm(ll a,ll b)
{
    return(a/gcd(a,b)*b);
}
ll power(ll a,ll b,ll p)
{
    ll res=1;
    a%=p;
    while(b>0)
    {
        if(b&1)
        res=res*a%p;
        a=a*a%p;
        b>>=1;
    }
    return(res);
}
ll modInverse(ll a, ll m)
{
    ll g = gcd(a, m);
    return(power(a,m-2,m));
}
/*ll b_search(ll arr[],ll n,ll s)
{
    ll l=0,r=n-1;
    while(l<=r)
    {
        ll mid=l+(r-l)/2;
        if(arr[mid]==s)
        return(mid);
        if(arr[mid]<s)
        l=mid+1;
        else
        r=mid-1;
    }
    return(-1);
}*/
vector<ll> v(1000000,1);

void solve()
{
    ll n,m;
    cin>>n>>m;
    cout<<ceil(n/(1.0*m));
}

int main()
{
    IOS
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return(0);
}


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

int main() {
    long long n; cin >> n;
    unordered_map<string, long long> d;
    for (int i = 0; i < n; i++) {
        string ss; cin >> ss;
        sort(ss.begin(), ss.end());
        d[ss]++;
    }
    long long res = 0;
    for (auto iter : d) {
        res += iter.second * (iter.second - 1) / 2;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 10660
from itertools import groupby
S = input()
A = [len(list(it)) for s, it in groupby(S)]
for n1, n2 in zip(A[::2], A[1::2]):
    print(*([0]*(n1-1)+[(n1+1)//2+n2//2]+[n1//2+(n2+1)//2]+[0]*(n2-1)), end=" ")

Measured memory_bytes: 5636
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int H = scan.nextInt(), W = scan.nextInt();
		char field[][] = new char[H][W];
		int table[][] = new int[H][W];

		for(int i = 0; i < H; i++){
			String s = scan.next();
			for(int j = 0; j < W; j++){
				field[i][j] = s.charAt(j);
			}
		}
		
		table[0][0] = ((field[0][0] == '.')?0:1);
		
		for(int i = 1;i < W;i++){
			table[0][i] = table[0][i-1]+ ((field[0][i] != field[0][i-1])?1:0);
		}
		for(int i = 1;i < H;i++){
			table[i][0] = table[i-1][0]+ ((field[i][0] != field[i-1][0])?1:0);
		}
		
		for(int n = 2; n <= W + H - 2; n++){
			for(int i = 1; i < n; i++){
				if((n - i) < H && i < W)

				table[n - i][i] = Math.min(table[n-i-1][i] + ((field[n-i][i] != field[n-i-1][i])?1:0), table[n - i][i - 1] + ((field[n-i][i]!=field[n-i][i-1])?1:0));
			}
		}

		System.out.println((table[H-1][W-1]+((field[H-1][W-1]=='.')?0:1))/2);
	}
}

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

namespace ConsoleApplication64
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int c = a[0] + a[1];
            int b = c % 24;
            Console.WriteLine(b);
        }
    }
}


Measured memory_bytes: 13268
// Author : Hardik Upadhyay
// college: SVNIT 
// slogan : Ab to phod dunga
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,a,b) for(int i = a ; i >= b; i--)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
#define all(x) x.begin(),x.end()

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int MAXN = 100005;
ll mod=1000000007;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int x,n;
	cin>>x>>n;
	
	vi a(n);
	map<int,int> mark;
	int mn = 1e9;
	rep(i,0,n-1){
		cin>>a[i];
		mark[a[i]]++;
	}
	int i = 0;
	while(x >= i and mark[x-i] > 0 and mark[x+i]>0){
		// debug(x-i);
		// debug(x+i);
		i++;
	}
	if(mark[x-i] == 0){
		cout<<(x-i)<<nl;
	}
	else cout<<(x+i)<<nl;
	return 0;
}


Measured memory_bytes: 3660
using static System.Math;
using System;

public class hello
{
    public static int h, w;
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        h = int.Parse(line[0]);
        w = int.Parse(line[1]);
        var map = new int[h, w];
        for (int i = 0; i < h; i++)
        {
            var s = Console.ReadLine().Trim();
            for (int j = 0; j < w; j++)
                map[i, j] = s[j] - '0';
        }
        getAns(map);
    }
    static void getAns(int[,] map)
    {
        var dp = new int[h, w];
        for (int i = 1; i < w; i++) dp[0, i] = dp[0, i - 1] + map[0, i];
        for (int i = 1; i < h; i++) dp[i, 0] = dp[i - 1, 0] + map[i, 0];
        for (int i = 1; i < h; i++)
            for (int j = 1; j < w; j++)
                dp[i, j] = Min(dp[i - 1, j], dp[i, j - 1]) + map[i, j];
        Console.WriteLine(dp[h - 1, w - 1]);
    }
}



Measured memory_bytes: 17940
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;

  int max = 0;
  for (int i = 0; i <= n; i++) {
    if (i * i <= n) {
      max = i * i;
    } else {
      break;
    }
  }

  cout << max << endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <numeric>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;

int main(){

  int n, m;
  cin >> n >> m;

  vector<int> h(n);
  rep(i,n) cin >> h[i];

  vector<vector<int> > ab(m, vector<int>(2));
  rep(i,m) cin >> ab[i][0] >> ab[i][1];

  vector<int> ok(n,1);
  rep(i,m){
    if(h[ab[i][0]-1] <= h[ab[i][1]-1]) ok[ab[i][0]-1] = 0;
    if(h[ab[i][1]-1] <= h[ab[i][0]-1]) ok[ab[i][1]-1] = 0;
  }

  cout << accumulate(ok.begin(), ok.end(), 0) << endl;

  return 0;
}


Measured memory_bytes: 9596
PROGRAM-ID.                      PROGRAM_ID.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 N            PIC 9(3).
    01 ans          PIC Z(2)9.

PROCEDURE                        DIVISION.
    ACCEPT N.
    COMPUTE ans = N / 2 + 0.9.
    DISPLAY ans.
    STOP RUN.


Measured memory_bytes: 636
n, a, b, c, d = list(map(int, input().split()))
s = input()
if d > c:
    for i in range(a, d-1):
        if (s[i-1] == "#") and (s[i] == "#"):
            print("No")
            break
    else:
        print("Yes")
else:
    for i in range(a, d):
        if (s[i-1] == "#") & (s[i] == "#"):
            print("No")
            break
    else:
        for j in range(b-1, d):
            if (s[j-1] == ".") & (s[j] == ".") & (s[j+1] == "."):
                print("Yes")
                break
        else:
            print("No")

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{

int N;
	cin >> N;

	fx(N) {
		if ((int)((x+1)*1.08)==N) {
			ce(x + 1);
			return 0;
		}
	}
	ce(":(")
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    int cnt=0;
    for(int i=0;i<n;i++){
        if(h[i]>=k){
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)




string s;
int x,y;
int d = 0;//0がx,1がy
vector<int> cx;
vector<int> cy;

bool dpx[8001][16010];
bool dpy[8001][16010];

int main(){
  cin >> s>> x>>y;
  int first = 0;
  int t = 0;
  while(t < s.size() && s[t] == 'F'){
    t++;
    first++;
  }
  FOR(i,t,s.size()){
    if(s[i]=='F'){
      int cnt = 0;
      while(i<s.size() && s[i]=='F'){
        cnt++;
        i++;
      }
      i--;
      if(d == 0){
        cx.push_back(cnt);
      }else{
        cy.push_back(cnt);
      }
    }else{
      d = (d+1) % 2;
    }
  }
  dpx[0][8005+first] = true;
  REP(i,cx.size()){
    REP(j,16010){
      if(!dpx[i][j]) continue;
      dpx[i+1][j-cx[i]] = true;
      dpx[i+1][j+cx[i]] = true;
    }
  }
  dpy[0][8005] = true;
  REP(i,cy.size()){
    REP(j,16010){
      if(!dpy[i][j]) continue;
      dpy[i+1][j-cy[i]] = true;
      dpy[i+1][j+cy[i]] = true;
    }
  }
  if(dpx[cx.size()][8005+x] && dpy[cy.size()][8005+y]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 64256
#include <iostream>
using namespace std;
int n,s[100000],ans,ans1;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    for(int i=0;i<n-1;i++){
        if(s[i]>=s[i+1])ans++;
        else {
            ans1=max(ans,ans1);
            ans=0;
        }
    }
    cout<<max(ans,ans1)<<endl;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		int K = sc.nextInt();
		for (int i=0;i<K;i++) {
			if (i%2==0) {
				A/=2;
				B+=A;
			} else {
				B/=2;
				A+=B;
			}
		}
		System.out.println(A+" "+B);
	}
}

Measured memory_bytes: 38836
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
//#include<stdio.h>
typedef long long LL;
using ld = long double;
using namespace std;
#define MAXN 3005
const double eps = (1e-12);
const int logn = 21;
const double Pi = acos(-1.0);
LL pp = 998244353;
int lowbit(int x) { return x & (-x); }
#define MP(i,j) make_pair(i,j)
#define M(x) ((((x)%pp)+pp)%pp)
//#define int LL
#define P pair<double,double>
const int INF = 1e9;

LL dp[MAXN][MAXN];

signed main() {
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	dp[a][b] = 1;
	for (int i = b + 1; i <= d; i++) {
		dp[a][i] = dp[a][i - 1] * a % pp;
	}
	for (int i = a + 1; i <= c; i++) {
		dp[i][b] = dp[i - 1][b] * b % pp;
	}
	for (int i = a + 1; i <= c; i++) {
		for (int j = b + 1; j <= d; j++) {
			//dp[i][j] = M(dp[i - 1][j] * (j - 1) + dp[i][j - 1] * (i - 1) - (dp[i - 1][j - 1] * (i + j - 2)));
			//if (j > i) dp[i][j] = M(dp[i][j - 1] * i);
			//else if (j < i) dp[i][j] = M(dp[i - 1][j] * j);
			//else dp[i][j] = M(dp[i - 1][j] * j + dp[i][j - 1] * i - dp[i - 1][j - 1]);
			dp[i][j] = M(dp[i - 1][j] * (j) + dp[i][j - 1] * (i) - dp[i - 1][j - 1] * (i - 1)*(j - 1));
		}
	}
	printf("%lld", dp[c][d]);
	return 0;
}

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

using namespace std;

int main() {
	int N,L;
	cin >> N >> L;
	
	string str[N];
	
	for(int i =0; i < N; i++) {
		cin >> str[i];
	}
	
	sort(str, str+N);
	
	string str_min = "";
	
	for(int i=0; i<N; i++) {
		str_min += str[i];
	}
	
	cout << str_min << endl;

	return 0;
}

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

int top , S[1000];

void push(int x){

S[++top] = x;
}

int pop(){
top--;

return S[top+1];
}

int main(){
  int a, b;
  top =0;
  char s[100];

    while( scanf("%s", s) != EOF){
      if ( s[0] == '+'){
        a =pop();
        b =pop();
        push(a+b);
      }else if (s[0] =='-'){
        b = pop();
        a = pop();
        push(a-b);
      }else if (s[0] =='*'){
      a =pop();
      b =pop();
      push(a*b);
      }else{
        push(atoi(s));
      }
    }

    printf("%d\n", pop());

    return 0;
}

Measured memory_bytes: 2712
use std::io::*;
use std::str::FromStr;
use std::collections::VecDeque;

fn main() {
    let n: usize = read();
    let mut vec: Vec<Vec<(usize, usize)>> = vec![Vec::new(); n];
    for i in 0..n-1 {
        let u: usize = read();
        let v: usize = read();
        let w: usize = read();
        vec[u-1].push((v-1, w));
        vec[v-1].push((u-1, w));
    }

    let mut color = vec![0; n]; // 1:w, 2:b
    color[0] = 1;
    let mut que: VecDeque<usize> = VecDeque::new();
    que.push_back(0);
    loop {
        if que.is_empty() {
            break;
        }
        let q = que.pop_front().unwrap();
        for i in &vec[q] {
            if color[i.0] == 0 {
                if i.1 % 2 == 0 {
                    color[i.0] = color[q];
                } else {
                    color[i.0] = 3 - color[q];
                }
                que.push_back(i.0);
            }
        }
    }
    for i in 0..n {
        println!("{}", if color[i] == 1 {0} else {1});
    }

}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 14716
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>

int ababa(int n){
  int ans = 1;
  for(int i = 0; i < n; i++){
    ans *= 10;
  
  }
  return ans;
}

int main(){
  long long int N;
  scanf("%lld", &N);
  
  int tmp = 0;
  int bits = 0;
  int sum = 0;
  
  while(tmp < N){
    // update tmp and bits
    tmp = 10*tmp+9;
    bits++;
    
    // update sum
    if(bits%2 == 1){
      if(tmp > N){
        sum += (N + 1 - ababa(bits-1));
      }
      else
        sum += ababa(bits-1)*9;
    }
  }
  
  std::cout << sum << std::endl;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

int a[5];

int main()
{
  rep(i, 5) cin >> a[i];

  sort(a, a+5, greater<int>());

  rep(i, 5) cout << a[i] << (i==4 ? "\n" : " ");

  return 0;
}

Measured memory_bytes: 1176
s = list(input())
cnt = 0
x = s[0]
for i in range(1,len(s)):
    if x == s[i]:
        cnt += 1
        
        if x == '0':
            x = "1"
        else:
            x = "0"
    else:
        x = s[i]
print(min(cnt,len(s)-cnt))

Measured memory_bytes: 3956
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

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 a,b;
  cin >> a >> b;
  cout << lcm(a,b) << endl;
}


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

int gcd(int a, int b) {
    if (b == 0)
        return a;

    return gcd(b, a%b);
}

int main(){
  int k;
  long int g, sum=0;
  cin >> k;
  
 
  for(int a=1; a<=k; a++){
    for(int b=1; b<=k; b++){
      for(int c=1; c<=k; c++){
        g = gcd(a,b);
        g = gcd(g,c);
        sum += g;
      }
    }
  }
 
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 3644
h, w = [int(i) for i in input().split()]
 
if h == 1 or w == 1:
  print(1)
elif h % 2 == 0:
  print((h // 2) * w)
else:
  if w % 2 == 0:
    print((w // 2) * h)
  else:
    print((w//2 + 1) * (h//2 + 1) + (w//2) * (h//2))

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define LL long long 

int mp[305][305],h,w,d,q, dp[305*305], xx[305*305], yy[305*305];

int getdis(int x, int y)
{
	return abs(xx[x]-xx[y])+abs(yy[x]-yy[y]);
}


int main()
{
	scanf("%d%d%d",&h,&w,&d);
	for(int i=1; i<=h; i++)
	for(int j=1; j<=w; j++)
	{int temp;
		scanf("%d",&temp);
		mp[i][j]=temp;
		xx[temp]=i;
		yy[temp]=j;
	}
	scanf("%d",&q);
	for(int i=d; i<=h*w; i++)
		dp[i]=getdis(i-d, i)+dp[i-d];
	for(int i=1; i<=q; i++)
	{
		int l,r, ans=0;
		scanf("%d%d",&l,&r);
		ans=dp[r]-dp[l];
		printf("%d\n",ans);
	} 
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) begin(v), end(v)
#define allg(v) begin(v), end(v), greater<int>()



int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  ll n;
  cin >> n;
  
  vector<int> a(n);  rep(i, 0, n) cin >> a.at(i);
  sort(all(a));
  
  ll ans = 1;
  rep(i, 0, n-1) {
    if(a.at(i) != a.at(i+1))
      ans++;
  }
  
  cout << ans << "\n";
  
  //cout << fixed << setprecision(10) << n << "\n";

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b;
int vis[500000]={0};
void check(){
    for(int i=1;i<=999;i++){
        vis[(i*(i+1))/2]=i;
    }
}
int main()
{
    check();
    scanf("%lld%lld",&a,&b);
    for(int i=0;;i++){
        if(vis[a+i]&&vis[b+i]&&vis[b+i]-vis[a+i]==1){
            printf("%d\n",i);
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 2176
N=int(input())
N=N-1
X=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
ans=[]
for n in range(10**7):
	ans=[X[N%26]]+ans
	if N<26:break
	N=(N)//26-1
print("".join(ans))

Measured memory_bytes: 61696
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N, A, ans = 0;
    cin >> N;
    map<int, int> mp;

    rep(0, i, N)
    {
        cin >> A;
        mp[A]++;
    }

    for (auto m : mp)
    {
        if (m.second % 2)
        {
            ans++;
        }
    }

    cout << ans << endl;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X,i) ((X>>i)&1)
#define REP(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define ina(x,n) rep(x_i,n) cin>>x[x_i]
#define outa(x,n) rep(x_i,n) cerr<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;

const int MOD = 1e9+7;
const int INF = (1<<28);
const ll INFL = (1LL<<60);

int main() {
  int n, m; cin >> n >> m;
  vvl edges(n);
  vl indegree(n,0), ans(n,-1);
  rep(i,n-1+m) {
    int a, b; cin >> a >> b;
    a--; b--;
    edges[a].pb(b);
    indegree[b]++;
  }
  queue<int> que;
  rep(i,n) {
    if (indegree[i] == 0) {
      que.push(i);
      ans[i] = -1;
    }
  }
  vl sorted_order;
  while (!que.empty()) {
    int x = que.front(); que.pop();
    sorted_order.pb(x);
    for (auto& it : edges[x]) {
      indegree[it]--;
      if (indegree[it] == 0) {
        que.push(it);
      }
    }
  }
  reverse(all(sorted_order));
  for (auto& parent : sorted_order) {
    for (auto& child : edges[parent]) {
      fprintf(stderr, "p(%d) to c(%d)\n", parent, child);
      if (ans[child] == -1) ans[child] = parent;
    }
  }
  rep(i,n) {
    cout << ans[i]+1 << endl;
  }
  return 0;
}


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

int main(void){
    int N;
    cin >> N;
    
    int count = 0;
    for (int i = N; i > 0; i--) {
        int a = i;
        int c = 0;
        while(a != 0) {
            a = a/10;
            c++;
        }
        if (c % 2 == 1)
            count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
#define MAXN 1000007
#define MO (int(1e9)+7)
int a[MAXN];
int gcd(int a, int b) {
	return b==0?a:gcd(b,a%b);
}
int v[MAXN];
bool vis[MAXN];
inline void db() {
	memset(v,0,sizeof v);
	for(int i=2; i<=1000000; i++) if(!v[i]) {
		v[i]=i;
		for(long long j=1ll*i*i; j<=1000000; j+=i) {
			v[j]=i;
		}
	}
}
int n;
inline bool vali() {
	memset(vis,0,sizeof vis);
	for(int i=0; i<n; i++) {
		int x=a[i];
		while(x>1) {
			if(vis[v[x]]) {
				return false;
			}
			vis[v[x]]=true;
			int ss=v[x];
			do { x/=ss; }while(x%ss==0);
		}
	}
	return true;
}
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	db();
	cin >> n;
	int g=0;
	for(int i=0; i<n; i++) {
		cin>>a[i];
		g=gcd(g,a[i]);
	}
	if(g==1) {
		if(vali()) {
			cout << "pairwise coprime\n";
		} else {
			cout << "setwise coprime\n";
		}
	} else {
		cout << "not coprime\n";
	}

}


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

#define mod 1000000007

int main(){
    int i,j,k;
    int N,M,W,H,A,B,C;
    int a,b,c;
    long long int ans = 1;

    cin >> N;

    for(i=1;i<=N;i++){
        ans *= i;
        ans = ans % mod;
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 256
N,M = map(int,input().split())
a = []
love = 0
for i in range(N):
    a.append(list(map(int,input().split())))
for k in range(M):
    count = 0
    for i in range(N):
        if k+1 in a[i][1:]:
            count += 1
        else:
            break
    if count == N:
        love += 1
print(love)


Measured memory_bytes: 3060
import numpy as np

N, M = map(int, input().split())
a = [input().split() for i in range(N)]
# a = [[int(i[0]), int(i[1])] for i in a]
a = np.array(a, dtype='int64')
a = a[a[:, 0].argsort(), :]

mysum = 0
coin = 0
for c in a:
    if mysum + c[1] < M:
        mysum += c[1]
        coin += c[0] * c[1]
    else:
        d = M - mysum
        coin += d * c[0]
        break

print(coin)

Measured memory_bytes: 51408
tmp = []
cou = "1"
while cou != [0, 0]
  i = gets.chomp.split.map(&:to_i)
  tmp.push(i)
  tmp.flatten!
  cou = i
end

tmp.delete(tmp[-1])
length = tmp.length/2

i = 0
length.times do
  h = tmp[i].to_i
  w = tmp[i+1].to_i
  h.times do
    w.times do
      print "#"
    end
    print"\n"
  end
  i = i + 2
    print"\n"
end

Measured memory_bytes: 8776
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

bool check(string s) {
    int n = sz(s);
    if (n % 2 == 1) return false;
    bool res = true;
    rep(i, n/2) {
        if (s[i] != s[i+n/2]) res = false;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    int n = sz(s);
    rep(i, n) {
        s.pop_back();
        if (check(s)) break;
    }
    cout << sz(s) << endl;

}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main()
{
    int i,n,x;
    std::ios::sync_with_stdio(0);
    cin>>n;
    int last = 0;
    int cnt = 1;
    int ok = -1;
    for(i=1; i<=n; ++i)
    {
        cin>>x;
        if(ok==-1)
        {
            last = x;
            ok = 0;
        }
        else
        if(ok == 0)
        {
            if(last>x)
                ok=1,last = x;
            else
            if(last<x)
                ok=2,last = x;
        }
        else
        if(ok == 1)
        {
            if(last<x)
                ok=0,++cnt,last=x;
            else
                last = x;
        }
        else
        if(ok == 2)
        {
            if(last>x)
                ok=0,++cnt,last=x;
            else
                last = x;
        }
    }
    cout<<cnt;
}


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

#define HASH 2999999

typedef struct List {
	struct List *next;
	char *s;
} list;

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

int hash_string(char* s)
{
	int i, x = 0;
	for (i = 0; s[i] != 0; i++) x = ((x << 5) + s[i] - 'a') % HASH;
	return x;
}

int lex_smaller(char* s1, char* s2)
{
	int i;
	for (i = 0; s1[i] != 0 && s2[i] != 0; i++) {
		if (s1[i] < s2[i]) return 1;
		else if (s1[i] > s2[i]) return -1;
	}
	if (s1[i] == s2[i]) return 0;
	else if (s1[i] == 0) return 1;
	else return -1;
}

int main()
{
	int i, j, l[200001], N;
	char *S[200001], T[1000001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%s", T);
		for (l[i] = 0; T[l[i]] != 0; l[i]++);
		S[i] = (char*)malloc(sizeof(char) * (l[i] + 1));
		for (j = 0; j <= l[i]; j++) S[i][j] = T[j];
	}
	
	int h[200001];
	list *p, *hash[HASH], d[200001];
	for (i = 1; i <= N; i++) {
		h[i] = hash_string(&(S[i][1]));
		d[i].s = S[i];
		d[i].next = hash[h[i]];
		hash[h[i]] = &(d[i]);
	}
	
	int k, m, dp[26];
	long long ans = 0, tmp, pow[32];
	const long long inv = div_mod(1, 32, HASH);
	for (k = 1, pow[0] = 32; k < 32; k++) pow[k] = pow[k-1] * pow[k-1] % HASH;
	for (i = 1; i <= N; i++) {
		if (l[i] <= 1) continue;
		for (j = l[i] - 2, k = 0, tmp = 1; j > 0; j >>= 1, k++) if ((j & 1) == 1) tmp = tmp * pow[k] % HASH;
		h[i] = (h[i] - tmp * (S[i][1] - 'a') % HASH + HASH) % HASH;
		for (j = 0; j < 26; j++) dp[j] = 0;
		dp[S[i][0] - 'a'] = 1;
		for (j = 1, m = 1; j < l[i]; j++) {
			dp[S[i][j] - 'a'] = 1;
			for (p = hash[h[i]]; p != NULL; p = p->next) {
				if (dp[p->s[0] - 'a'] == 1 && lex_smaller(&(p->s[1]), &(S[i][j+1])) == 0) ans++;
			}
			tmp = tmp * inv % HASH;
			h[i] = (h[i] - tmp * (S[i][j+1] - 'a') % HASH + HASH) % HASH;
		}
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 37568
n,k = (int(i) for i in input().split())
A = [0]+[int(i) for i in input().split()]

if k<=n:
	ans = 1
	for i in range(k):
		ans = A[ans]
	print(ans)
	exit()

boucle = 1
vis = [False]*(n+1)
vis[1] = True
x = 1
while not vis[A[x]]:
	x = A[x]
	vis[x] = True
	boucle+=1

last = A[x]
sub = 0
d = 1
while d!=last:
	sub+=1
	d=A[d]
boucle-=sub
# ~ print("last",last)
# ~ print("sub",sub)

k-=sub
reste = k%boucle
ans = last
for i in range(reste):
	ans = A[ans]
	
# ~ print("boucle", boucle)
# ~ print("reste", reste)
print(ans)


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

using namespace std;

int n, k, la;
int a[55];
vector<int> ans;
int ta;

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++)
		scanf("%d", a + i);
	k++;
	while (k--) {
		ta = 0;
		for (int i = 1; i <= n; i++)
			if (i != la && (ta == 0 || a[i] < a[ta]))
				ta = i;
		if (a[ta] == 0) {
			puts("-1");
			return 0;
		}
		for (int i = 1; i <= n; i++)
			if (i != la && i != ta) {
				ans.push_back(i);
				a[i]--;
			}
		ans.push_back(ta);
		a[ta]--;
		la = ta;
	}
	printf("%d\n", (int)ans.size());
	for (int i = 0; i < ans.size(); i++)
		printf("%d%c", ans[i], " \n"[i == ans.size() - 1]);
}


Measured memory_bytes: 256
N = int(input())

for i in range(17):
    if 10**i <=N <10**(i+1):
        m=i+1
        break

for j in range(0,10):
    if (10**(m-1))*j + 10**(m-1)-1 <=N< (j+1)*(10**(m-1))+10**(m-1)-1:
        a = j
        break

print(a+9*(m-1))

Measured memory_bytes: 9096
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    F = []
    for _ in range(N):
        F.append([int(x) for x in input().split()])

    P = []
    for _ in range(N):
        P.append([int(x) for x in input().split()])


    ans = -float("inf")
    for i in range(1, 2 ** 10):
        c = [0] * N
        for j in range(10):
            if i >> j & 1:
                for k in range(N):
                    if F[k][j] == 1:
                        c[k] += 1

        tmp = 0
        for k in range(N):
            tmp += P[k][c[k]]

        ans = max(ans, tmp)

    print(ans)




if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
int n, w[101000], A[10], cnt;
map<int, int>Map;
int main() {
	int i;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &w[i]);
	}
	sort(w, w + n);
	if (n % 3) {
		if (w[0] == w[n - 1] && w[0] == 0) puts("Yes");
		else puts("No");
		return 0;
	}
	for (i = 0; i < n; i++)Map[w[i]]++;
	for (auto &t : Map) {
		if (t.second % (n / 3)) {
			puts("No");
			return 0;
		}
		for (i = 0; i < t.second / (n / 3); i++) {
			A[cnt++] = t.first;
		}
	}
	if (cnt == 3 && (A[0] ^ A[1] ^ A[2]) == 0) {
		puts("Yes");
		return 0;
	}
	else puts("No");
}

Measured memory_bytes: 4224
def ncr(n, r, p): 
    # initialize numerator 
    # and denominator 
    num = den = 1 
    for i in range(r): 
        num = (num * (n - i)) % p 
        den = (den * (i + 1)) % p 
    return (num * pow(den,  
            p - 2, p)) % p
p=10**9+7
n,a,b=map(int,(input().split()))
bb=ncr(n,a,p)+ncr(n,b,p)+1
print((pow(2,n,p)-(bb%p)+p)%p)

        

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>

int main(){
    int N;
    std::cin >> N;
    std::string S;
    std::cin >> S;
    int maxCnt = 0;
    for(int mojisu = 1; mojisu < N; mojisu++){
        int cnt = 0;
        std::vector<bool> alphabet(26, false);
        for(int i = 0; i < mojisu; i++){
            alphabet[static_cast<int>(S[i] - 'a')] = true;
        }
        for(int i = mojisu; i < N; i++){
            if(alphabet[static_cast<int>(S[i] - 'a')]){
                cnt++;
                // 重複して数えないようにフラグを消す
                alphabet[static_cast<int>(S[i] - 'a')] = false;
            }
        }

        maxCnt = std::max(maxCnt, cnt);
    }

    std::cout << maxCnt << std::endl;
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
x = []
y = []
z = []
f = [[] for _ in range(8)]
for i in range(n):
    a = input()
    a = a.split(' ')
    a = list(map(int, a))
    xi = a[0]
    yi = a[1]
    zi = a[2]
    x.append(xi)
    y.append(yi)
    z.append(zi)
    fi = [0 for _ in range(8)]
    fi[0] = xi + yi + zi
    fi[1] = xi + yi - zi
    fi[2] = xi - yi + zi
    fi[3] = -xi + yi + zi
    fi[4] = xi - yi - zi
    fi[5] = -xi - yi + zi
    fi[6] = -xi + yi - zi
    fi[7] = -xi - yi - zi
    for j in range(8):
        f[j].append(fi[j])
f = list(map(sorted, f))
f = list(map(reversed, f))
f = list(map(list, f))
fmax = [0 for _ in range(8)]
for i in range(m):
    for j in range(8):
        fmax[j] += f[j][i]
print(max(fmax))

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

using namespace std;
const int inf = 1e9 + 7;
const int N = 1e6 + 1;
int t[N];
int c[N];
int last[N];
int get(int x) {
    int ans = 0;
    for (int i = x; i >= 0; i = (i&(i + 1)) - 1) ans += t[i];
    return ans;
}
void update(int pos, int add) {
    if (pos < 0) return;
    for (int i = pos; i < N; i = (i|(i + 1))) t[i] += add;
}
vector <pair <int, int> > q[N];
int ans[N];
signed main () {
    ios_base::sync_with_stdio(NULL);
    cin.tie(0); cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> c[i];
    for (int i = 0; i < m; i++) {
        int l, r;
        cin >> l >> r; l--; r--;
        q[r].push_back({l, i});
    }
    memset(last, -1, sizeof last);
    for (int i = 0; i < n; i++) {
        update(last[c[i]], -1);
        last[c[i]] = i;
        update(last[c[i]], 1);
        for (auto it : q[i]) ans[it.second] = get(i) - get(it.first - 1);
    }
    for (int i = 0; i < m; i++) {
        cout << ans[i] << '\n';
    }
}


Measured memory_bytes: 46936
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
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; }
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 const INF = 1001001001;


template<int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0) val += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator - () const noexcept {
return val ? MOD - val : 0;
}
constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
constexpr Fp& operator += (const Fp& r) noexcept {
val += r.val;
if (val >= MOD) val -= MOD;
return *this;
}
constexpr Fp& operator -= (const Fp& r) noexcept {
val -= r.val;
if (val < 0) val += MOD;
return *this;
}
constexpr Fp& operator *= (const Fp& r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp& operator /= (const Fp& r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
val = val * u % MOD;
if (val < 0) val += MOD;
return *this;
}
constexpr bool operator == (const Fp& r) const noexcept {
return this->val == r.val;
}
constexpr bool operator != (const Fp& r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0) return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1) t = t * a;
return t;
}
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

/*numは'1'の個数を数えるがこれは次の場合についての組み合わせの数を求める時に使う

L=11001010以下の整数lは次のどれかの形をしている
1. 0.......
2. 10......
3. 11000...
4. 1100100.
5. 11001010

「...」部分は「0 or 1」である。要するになんでもいい
「...」部分の長さをlen、それ以外の部分で'1'が立っている個数をnumとする
各場合についてa+b = lを満たす(a,b)で桁上がりが起きない組み合わせの数は
「...」部分で3のlen乗、それ以外の部分で2のnum乗である
3のlen乗×2のnum乗をすべての場合について合計すれば答えが求まる
*/


mint solve(const string &L) {
    long long num = 0;
    mint res = 0;
    for (int i = 0; i < L.size(); ++i) {
        int len = (int)L.size() - i - 1;//iが最後までいったときにlen= = 0に確かになってる
        if (L[i] == '1') {
            res += modpow(mint(2), num) * modpow(mint(3), len);//L[i] = 0の場合の組み合わせの数を求めている
            ++num;
        }
    }
    res += modpow(mint(2), num);
    return res;
}


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

string L;
cin >> L;
cout << solve(L) << endl;

return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<vector>
#include<queue>
using namespace std;
int main(){
	int N,Y,x=-1,y=-1,z=-1,nokori;
	cin>>N>>Y;
	if(N*10000<Y||N*1000>Y){
		cout<<x<<" "<<y<<" "<<z<<endl;
	return 0;
	}
	
	for(int i=0;i<=N;i++){
		nokori=10000*N-Y;
	
			//N-iがかえる枚数
			nokori-=(N-i)*5000;
			if(nokori%4000==0&&nokori>=0){
				z=nokori/4000;
				y=N-i-(nokori/4000);
				if(z>=0&&y>=0){cout<<i<<" "<<y<<" "<<z<<endl;return 0;}
				
				
			}
		
	}
	x=-1;y=-1;z=-1;
	cout<<x<<" "<<y<<" "<<z<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    int N;
    cin >> N;
    cout << N / 2 + N % 2 << endl;
}


Measured memory_bytes: 256