akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  int h, w;
  cin >> h >> w;

  vector<vector<char>> field;
  for (int i = 0; i < h; i++)
  {
    string s;
    cin >> s;
    vector<char> chs;
    for (char ch : s)
    {
      chs.push_back(ch);
    }

    field.push_back(chs);
  }

  vector<vector<int>> L(h, vector<int>(w, 0));
  vector<vector<int>> R(h, vector<int>(w, 0));
  vector<vector<int>> U(h, vector<int>(w, 0));
  vector<vector<int>> D(h, vector<int>(w, 0));

  for (int i = 0; i < h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      if (field[i][j] == '#')
      {
        continue;
      }

      if (j == 0)
      {
        L[i][j] = 1;
      }
      else
      {
        L[i][j] = L[i][j - 1] + 1;
      }
    }
  }

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

      if (j == w - 1)
      {
        R[i][j] = 1;
      }
      else
      {
        R[i][j] = R[i][j + 1] + 1;
      }
    }
  }

  for (int i = 0; i < h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      if (field[i][j] == '#')
      {
        continue;
      }

      if (i == 0)
      {
        U[i][j] = 1;
      }
      else
      {
        U[i][j] = U[i - 1][j] + 1;
      }
    }
  }

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

      if (i == h - 1)
      {
        D[i][j] = 1;
      }
      else
      {
        D[i][j] = D[i + 1][j] + 1;
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      ans = max(L[i][j] + R[i][j] + U[i][j] + D[i][j], ans);
    }
  }

  cout << ans - 3 << endl;
}

Measured memory_bytes: 67072
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=a;i<b;++i)
int main(){
  int n,y,m,d; cin>>n;
  REP(i,n){
    cin>>y>>m>>d;
    int ds=0;
    FOR(j,y+1,1000){
      if(j%3) ds+=(20+19)*5;
      else ds+=20*10;
    }
    if(y%3){
      if(m%2) ds+=21-d;
      else ds+=20-d;
      FOR(k,m+1,11){
        if(k%2) ds+=20;
        else ds+=19;
      }
    }else{
      ds+=21-d;
      ds+=20*(10-m);
    }
    cout<<ds<<endl;
  }
  return 0;
}

Measured memory_bytes: 3076
import itertools, copy

h, w, k = map(int,input().split())

c = []

for _ in range(h):
    c.append(list(input()))

ans = 0

iter_h_list = list(itertools.product([0,1], repeat=h))
iter_w_list = list(itertools.product([0,1], repeat=w))

for iter_h in iter_h_list:
    for iter_w in iter_w_list:
        temp_c = copy.deepcopy(c)

        for i in range(h):
            if iter_h[i] == 1:
                temp_c[i] = ["r" for x in temp_c[i]]

        for j in range(w):
            for i in range(h):
                if iter_w[j] == 1:
                    temp_c[i][j] = "r"

        sum_of_shape = [x.count("#") for x in temp_c]
        if sum(sum_of_shape) == k:
            ans += 1

print(ans)

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


void solve(std::string S, std::string T){
    cout << T << S << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;

int main( ){
    int mat[110];
    
    memset(mat, 0, sizeof(mat));
    for(int i=1;i<=9;i++)
        for(int j=1;j<=9;j++)
            mat[i*j] = 1;
    
    int k;
    cin>>k;
    if(mat[k])
        cout<<"Yes";
    else
        cout<<"No";
}


Measured memory_bytes: 256
import sys
n_list = map(int, sys.stdin.readlines())
n_max = max(n_list)

pn_candidates = [0] + [1] * (n_max - 1)

pn = 2
while pn <= n_max:
    if pn_candidates[pn - 1] != 1:
        pn += 1
        continue

    i = 2
    while pn * i <= n_max:
        pn_candidates[pn * i - 1] = 0
        i += 1
    pn += 1 

for n in n_list:
    print sum(pn_candidates[:n])

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

using namespace std;
typedef long long ll;

int N;
string s;

bool bad;

vector <int> goal (int K, string cv)
{
    //cout << K << " " << cv << "\n";
    vector <int> ans;
    if (K == 1)
    {
        if (cv[0] == '1')
        {
            if (cv[1] == '0')
            {
                ans.push_back(0);
                ans.push_back(1);
                return ans;
            }
            return ans;
        }
        if (cv[0] == '0')
        {
            if (cv[1] == '1')
                bad = true;
            // what?
            return ans;
        }
    }

    int cp = 1 << (K - 1);
    for (int i = cp; i < 2 * cp; i++)
    {
        if (cv[i] > cv[i-cp])
        {
            bad = true;
            return ans;
        }
    }

    string rv = cv.substr(0, cp);
    string lv = cv.substr(cp);
    bool l0 = true;
    for (int i = 0; i < cp; i++)
    {
        if (lv[i] == '1') l0 = false;
    }

    vector <int> rans = goal (K - 1, rv);

    if (l0)
    {
        // throw the key
        rans.push_back(K - 1);
        rans.push_back(K);
        return rans;
    }
    vector <int> lans = goal (K - 1, lv);
    swap (rans, lans);

    vector <int> god;
    for (int i : rans)
        god.push_back(i);
    god.push_back(K);
    god.push_back(K-1);
    reverse (rans.begin(), rans.end());
    for (int i : rans)
        god.push_back(i);
    god.push_back(K-1);
    god.push_back(K);
    for (int i : lans)
        god.push_back(i);
    return god;
}

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N >> s;

    bad = false;
    vector <int> res = goal (N, s);
    if (bad || s[0] == '0')
    {
        cout << "Impossible\n";
    }
    else
    {
        cout << "Possible\n";
        if (!res.size())
        {
            cout << "0\n";
            cout << "1 1\n";
            return 0;
        }
        /*for (int i : res) cout << i;
        cout << "\n";*/
        res.push_back(res[0]);

        int ctot = 0;
        for (int i = 0; i + 1 < res.size(); i++)
        {
            ctot += abs (res[i+1] - res[i]) + 1;
        }

        cout << ctot << "\n";
        for (int i = 0; i + 1 < res.size(); i++)
        {
            int cv = i % 2;
            int nv = 1 - cv;
            cout << res[i] << " " << cv << "\n";
            for (int j = res[i]; j < res[i+1]; j++)
                cout << j << " " << nv << "\n";
            for (int j = res[i]; j > res[i+1]; j--)
                cout << j << " " << nv << "\n";
        }
        cout << res[0] << " " << 0 << "\n";
    }
}

Measured memory_bytes: 384
#include<stdio.h>
int main()
{
	char c[16];
	int a,b,i;
	for(i=0;i<9&&scanf("%s%d%d",c,&a,&b);i++,printf("%s %d %d\n",c,a+b,a*200+b*300));
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <list>

using namespace std;

//#define EPS (1e-10)
//
//struct Point{
//    Point(double _x = 0, double _y = 0){
//        x = _x;
//        y = _y;
//    }
//    double x;
//    double y;
//
//    Point operator + (Point p){
//        return Point(x + p.x, y+ p.y);
//    }
//
//    Point operator - (Point p){
//        return Point(x - p.x, y - p.y);
//    }
//
//    Point operator * (double a){
//        return Point(a * x, a * y);
//    }
//
//    Point operator / (double a){
//        return Point(x / a, y / a);
//    }
//
//    double abs(){
//        return sqrt(norm());
//    }
//
//    double norm(){
//        return x * x + y * y;
//    }
//
//    bool operator < (const Point &p) const{
//        return x!=p.x ? x < p.x : y < p.y;
//    }
//
//    bool operator == (const Point &p) const{
//        return fabs(x - p.x) && fabs(y - p.y) < EPS;
//    }
//
//};
//
//typedef Point Vector;
//
//double dot(Vector a, Vector b){
//    return a.x * b.x + a.y * b.y;
//}

int main() {

    string str;cin>>str;

    cout<<str[0]<<str.length()-2<<str[str.length()-1];

    return 0;

}

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

#define MAXN 100
int cnt[30];
char str[MAXN+5];

int main(){
    int N,Ans=0;
    scanf("%d",&N);
    scanf("%s",str+1);
    for(int i=1;i<N;i++){
        int tot=0;
        for(int j=1;j<=i;j++)
            cnt[str[j]-'a']++;
        for(int j=i+1;j<=N;j++)
            if(cnt[str[j]-'a']){
                tot++;
                cnt[str[j]-'a']=0;
            }
        Ans=max(Ans,tot);
        memset(cnt,0,sizeof cnt);
    }
    printf("%d",Ans);
}


Measured memory_bytes: 128
N,Q = map(int, input().split())
S = input()

lu = [0]*N
cnt = 0

for i in range(1, N):
  if S[(i-1):(i+1)] == 'AC':
    cnt += 1
  lu[i] = cnt

for i in range(Q):
  l, r = map(int, input().split())
  print(lu[r-1] - lu[l-1])



Measured memory_bytes: 6164
#include"bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



int main()
{
	ll A, B, Q;
	cin >> A >> B >> Q;
	vector<ll> s(A), t(B), xs(Q);
	REP(i, A)cin >> s[i];
	REP(i, B)cin >> t[i];
	REP(i, Q)cin >> xs[i];

	for (ll x : xs) {
		auto itrs = lower_bound(s.begin(), s.end(), x);
		auto itrt = lower_bound(t.begin(), t.end(), x);
		ll res = INFL;

		// left
		if (itrs != s.begin()) {
			ll dist1 = abs(*(itrs - 1) - x);
			// left
			if (itrt != t.begin()) {
				ll dist2 = abs(*(itrt - 1) - x);
				res = min(res, max(dist1, dist2));
			}
			// right
			if (itrt != t.end()) {
				ll dist2 = abs(*itrt - x);
				ll dist = min(dist1, dist2) * 2 + max(dist1, dist2);
				res = min(res, dist);
			}
		}

		// right
		if (itrs != s.end()) {
			ll dist1 = abs(*itrs - x);
			// left
			if (itrt != t.begin()) {
				ll dist2 = abs(*(itrt - 1) - x);
				ll dist = min(dist1, dist2) * 2 + max(dist1, dist2);
				res = min(res, dist);
			}
			// right
			if (itrt != t.end()) {
				ll dist2 = abs(*itrt - x);
				res = min(res, max(dist1, dist2));
			}
		}
		cout << res << endl;
	}

	return 0;
}


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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

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

using ll = long long;

template<class T> void chmax(T& a, T b){ if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b){ if (a > b) { a = b; } }

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int e = (a + d - 1) / d;
    int f = (c + b - 1) / b;
    cout << (f <= e ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 3592
#include<stdio.h>
#include<string.h>

typedef struct{
	char suit;
	int value;
} Card;

Card* bubbleSort(Card*, int);
Card* selectionSort(Card*, int);

int main(void){
	Card c[36], c2[36], tmp, *b, *s;
	int n, i, last, j, min_ind, flag;
	
	scanf("%d\n", &n);
	last = n-1;
	for(i = 0; i < n; i++){
		if(n == last){
			scanf("%c%d\n", &c[i].suit, &c[i].value);
			break;
		}
		scanf("%c%d ", &c[i].suit, &c[i].value);
	}
	memcpy(c2, c, sizeof(Card)*36);
	b = bubbleSort(c, n);
	s = selectionSort(c2, n);
	for(i = 0; i < n; i++){
		if(i == last){
			printf("%c%d\n", b[i].suit, b[i].value);
			break;
		}
		printf("%c%d ", b[i].suit, b[i].value);
	}
	printf("Stable\n");
	for(i = 0; i < n; i++){
		if(i == last){
			printf("%c%d\n", s[i].suit, s[i].value);
			break;
		}
		printf("%c%d ", s[i].suit, s[i].value);
	}
	for(i = 0; i < n; i++){
		if(s[i].suit != b[i].suit || s[i].value != b[i].value){
			printf("Not stable\n");
			goto EXIT;
		}
	}
	printf("Stable\n");
	EXIT:
	return 0;
}

Card* bubbleSort(Card* c, int n){
	Card tmp;
	int last = n-1;
	for(int i = 0; i < n; i++){
		for(int j = last; j > 0; j--){
			if(c[j-1].value > c[j].value){
				tmp = c[j-1];
				c[j-1] = c[j];
				c[j] = tmp;
			}
		}
	}
	return c;
}
Card* selectionSort(Card* c, int n){
	Card tmp;
	int last = n-1, min_ind;
	for(int i = 0; i < last; i++){
		min_ind = i;
		for(int j = i+1; j < n; j++){
			if(c[min_ind].value > c[j].value){
				min_ind = j;
			}
		}
		if(min_ind != i){
			tmp = c[i];
			c[i] = c[min_ind];
			c[min_ind] = tmp;
		}
	}
	return c;
}



Measured memory_bytes: 2136
/*_BELIEVE_*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

#define     int          long long int
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     __gcd((a),(b))
#define     lcm(a,b)     ((a)*(b))/gcd((a),(b))
#define     pb           push_back
#define     ins          insert
#define     F            first
#define     S            second

const int inf=1e18,M=1e9+7;

void solve()
{
    int n;
    cin>>n;
    
    vector<int> v(n);
    for(int i=0;i<n;++i)
        cin>>v[i];
    
    vector<int> mx(n),mn(n);
    
    mx[0]=v[0];
    for(int i=1;i<n;++i)
    {
        mx[i]=max(mx[i-1],v[i]);
    }
    
    mn[n-1]=v[n-1];
    for(int i=n-2;i>=0;--i)
    {
        mn[i]=min(mn[i+1],v[i]);
    }
    
    for(int i=0;i<n;++i)
    {
        if(v[i]+2<=mx[i] || v[i]+2<=mn[i])
        {   
            cout<<"No";
            return;
        }
    }
    
    cout<<"Yes";
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

    return 0;
}


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

#define MAX_N (int)1e+5
#define MAX_M (int)1e+5

int n, m;
std::vector<std::vector<int>> g(MAX_N + 1, std::vector<int>());
int deg[MAX_N + 1];

int dp[MAX_N + 1];

int main() {
  std::cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    int x, y;

    std::cin >> x >> y;
    g[x].push_back(y);
    ++deg[y];
  }

  std::queue<int> que;
  for(int i = 0; i < n; ++i) {
    if(deg[i + 1] == 0) que.push(i + 1);
  }

  while(!que.empty()) {
    int x = que.front(); que.pop();
    for(auto y : g[x]) {
      --deg[y ];
      if(deg[y] == 0) {
        que.push(y);
        dp[y] = std::max(dp[y], dp[x] + 1);
      }
    }
  }

  int ans = 0;
  for(int i = 0; i < n; ++i) {
    ans = std::max(ans, dp[i + 1]);
  }

  std::cout << ans << std::endl;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;cin>>n;
  ll ans=0;
  for(ll i=n;i>0;--i){
    if(i%15!=0 && i%5!=0 && i%3!=0){
      ans+=i;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3624
#reference Segment-Tree code from:https://ikatakos.com/pot/programming_algorithm/data_structure/segment_tree

def bisect(pos):
  l=-1
  r=n
  while r-l!=1:
    mid=(l+r)//2
    if arr[mid][0]>=pos:
      r=mid
    else:
      l=mid
  return r

mod=998244353
n=int(input())
arr=[list(map(int,input().split())) for _ in range(n)]
arr=sorted(arr,key=lambda x:x[0])
poss=[]
for i in range(n):
  poss.append(bisect(arr[i][0]+arr[i][1]))
poss.append(n)

offset=2**((n-1).bit_length())
st=[0]*(2*offset)

def update(pos,x):
  pos+=offset
  st[pos]=x
  while pos>1:
    y=st[pos^1]
    if x<=y:
      break
    pos>>=1
    st[pos]=x

def get_max(l,r):
  ret=0
  l+=offset
  r+=offset
  while l<r:
    if r&1:
      ret=max(ret,st[r-1])
    if l&1:
      ret=max(ret,st[l])
      l+=1
    l>>=1
    r>>=1
  return ret

for i in range(n):
  update(i,poss[i])
for i in range(n-1,-1,-1):
  poss[i]=get_max(i,poss[i])
  update(i,poss[i])

dp=[0]*(n+1)
dp[-1]=1
for i in range(n-1,-1,-1):
  dp[i]+=dp[i+1]
  dp[i]%=mod
  pos=poss[i]
  dp[i]+=dp[pos]
  dp[i]%=mod
print(dp[0]%mod)

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

int main(void) {
  int a, b;
  cin >> a >> b;
  int cnt = 0;
  for (int i = a; i <= b; i++) {
    string s = to_string(i);
    bool ok = true;
    for (int j = 0; j < s.size(); j++) {
      if (s[j] != s[s.size() - 1 - j]) ok = false;
    }
    if (ok) cnt++;
  }
  cout << cnt << endl;

  return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}


const int N = 1200;
int a[N],b[N],c[N],d[N];
int n,m,q;
int res = 0;

vector<int> seq;

int go()
{
    int vv = 0;
    
    f(i,q)
    {
            if(seq[b[i]-1] - seq[a[i]-1] == c[i]) vv+=d[i];
    }
    
    return vv;
}

void gen(int num,int last)
{
    if(num == 0)
    {
        res = max(res,go());
        return;
    }
    
    for(int i=last;i<=m;i++)
    {
        seq.pb(i);
        gen(num-1,i);
        seq.pop_back();
    }
}

void solve()
{
    cin >> n >> m >> q;
    
    f(i,q) cin >> a[i] >> b[i] >> c[i] >> d[i];  
    
    gen(n,1);
    
    cout << res;
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;

const ll INF = LLONG_MAX;
const ll MOD = 1e9+7;

int H,W;
bool meiro[21][21];
bool done[21][21];

int search(pii start) {
    vector<pii> locations;
    vector<pii> loc_tmp;
    vector<vector<pii>> que;
    locations.push_back(start);
    que.push_back(locations);
    int result = 0;
    while( que.size() >0) {
        result++;
        vector<pii> locs = que.back();
        que.pop_back();
        loc_tmp.clear();
        for(auto pi: locs) {
            int h=pi.first;
            int w=pi.second;
            if (1 < h && meiro[h-1][w] && !done[h-1][w]) {
                done[h-1][w] = true;
                loc_tmp.push_back({h-1,w});
            }
            if (h < H && meiro[h+1][w] && !done[h+1][w]) {
                done[h+1][w] = true;
                loc_tmp.push_back({h+1,w});
            }
            if (1 < w && meiro[h][w-1] && !done[h][w-1]) {
                done[h][w-1] = true;
                loc_tmp.push_back({h,w-1});
            }
            if (w < W && meiro[h][w+1] && !done[h][w+1]) {
                done[h][w+1] = true;
                loc_tmp.push_back({h,w+1});
            }                                    
        }
        if (loc_tmp.size() > 0)que.insert(que.begin(), loc_tmp);
    }

    return result;
}

int main() {
    // input, ready
    cin >> H >> W;
    memset(meiro,0,sizeof(meiro));
    for (int i=1; i<=H; i++) {
        string S;
        cin >> S;
        for (int j=1; j<=W; j++) {
            if (S[j-1] == '.') meiro[i][j] = true;
            else meiro[i][j] = false;
        }
    }

    // resolve
    int ans=0;
    for (int i=1; i<=H; i++) {
        for (int j=1; j<=W; j++) {
            if (!meiro[i][j]) continue;
            memset(done,0,sizeof(done));
            done[i][j] = true;
            ans = max(search({i,j}),ans);
        }
    }

    cout << ans-1 << endl;

    return 0;
}


Measured memory_bytes: 256
looplenn,k = map(int,input().split())
a = [0]+list(map(int,input().split()))

def bin(arr,val):
    left,right = 0,len(arr)-1
    while left<=right:
        mid = (left+right)//2
        if arr[mid]==val: return 1
        elif arr[mid]<val: left = mid + 1
        else: right = mid - 1
    return 0

know = []
now = 1
while not bin(know, now):
    know.append(now)
    now = a[now]

loop_start = a[know[-1]]
for i,num in enumerate(know):
    if num == loop_start:
        loop_init = i
        loop = know[i:]
        break

#print(know,start,loop)

cnt = len(loop)
if k < len(know):
    ans = know[k]
else:
    ans = loop[(k-loop_init)%cnt]
# ans = loop[k%cnt]


print(ans)

Measured memory_bytes: 95952
L = int(input())
l = L.bit_length()
graph = []
for i in range(l-1):
    graph.append((i+1, i+2, 0))
    graph.append((i+1, i+2, 2**(l-i-2)))
s = (1 << (l-1))
for i in reversed(range(l-1)):
    if (1 << i) & L:
        graph.append((1, l-i, s))
        s += (1 << i)
print(l, len(graph))
for a, b, c in graph:
    print(a, b, c)



Measured memory_bytes: 3064
n = int(input())
ans = 30
count = 0
line = list(map(int, input().split(" ")))
for i in range(0, len(line)):
    count = 0
    while line[i] % 2 == 0:
        line[i] = line[i] / 2
        count += 1
    ans = min(ans, count)
print(ans)

Measured memory_bytes: 3060
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a: [u64; n],
    }

    let mut v = vec![0; n];
    let mut ans = Vec::new();

    for i in (1..n+1).rev() {
        let kaisu = n / i;
        let mut tmp = 0;

        for j in 2..kaisu+1 {
            tmp = tmp + v[i*j-1];
        }
        //println!("a");
        if a[i-1] == 1 {
            if tmp % 2 == 0 {
                v[i-1] = 1;
                ans.push(i);
            } else {
                v[i-1] = 0;
            }
        } else {
            if tmp % 2 == 0 {
                v[i-1] = 0;
            } else {
                v[i-1] = 1;
                ans.push(i);
            }
        }
        //println!("b");
    }

    println!("{}", ans.len());
    for a in ans {
        println!("{}", a);
    }
}


Measured memory_bytes: 9084
// https://atcoder.jp/contests/hitachi2020/tasks/hitachi2020_a

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

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

  unless(S.size() % 2 == 0) drop("No");

  rep(i, S.size() / 2) {
    unless(S[2 * i] == 'h' && S[2 * i + 1] == 'i') { drop("No"); }
  }

  drop("Yes");
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[100009];
ll d[30][100009];
ll n,l,q;
void init()
{
    for(int i=1; i<=20; i++)
    {
        for(int j=1; j<=n; j++)
        {
            d[i][j]=d[i-1][d[i-1][j]];
        }
    }
}
int main()
{
    scanf("%lld",&n);
    for(ll i=1; i<=n; i++)
    {
        scanf("%lld",&a[i]);
    }
    scanf("%lld%lld",&l,&q);
    for(ll i=1; i<=n; i++)
    {
        ll z=i+1;
        ll y=n;
        while(z<=y)
        {
            ll mid=(z+y)/2;
            if(a[mid]-a[i]<=l)
            {
                z=mid+1;
            }
            else
            {
                y=mid-1;
            }
        }
        d[0][i]=z-1;
    }
    init();

   ll a,b;
   for(ll k=1;k<=q;k++)
   {
       ll tot=0;
       scanf("%lld%lld",&a,&b);
       if(a>b)
       {
           swap(a,b);
       }
       for(ll i=20;i>=0;i--)
       {
           if(d[i][a]<b)
           {
               tot+=(1ll<<i);
               a=d[i][a];
           }
       }
       tot++;
       cout<<tot<<endl;
   }

}


Measured memory_bytes: 20096
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define scan(n) scanf("%d",&n)
#define ls(n) scanf("%lld",&n)
#define print(n) printf("%d",n)
#define pln(n) printf("%d\n",n)
#define lpln(n) printf("%lld\n",n)
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rev(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define tc           ll t1; cin>>t1; while(t1--)
#define inp         ll n; cin>>n; ll arr[n]; rep(i,0,n) cin>>arr[i];
#define vect vector<ll>
#define sortv(v)       sort(v.begin(),v.end())
#define lower(v,n)    lower_bound(v.begin(),v.end(),n)-v.begin()
#define upper(v,n)    upper_bound(v.begin(),v.end(),n)-v.begin()
#define all(v)        v.begin(),v.end()
#define bitcount(n) __builtin_popcount(n)
#define ln <<endl
#define inf          1e12+5
#define ninf         -1e17
#define fast()         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
const   ll mod=1e9+7;
const ll N=1e5+5;



int main() 
{ 
          fast();
         

          string s,t;
          cin >> s >> t;
          ll ans=INT_MAX,current=0;
          int len1=s.size();
          int len2=t.size();
          rep(i,0,len1){
            current=0;
            bool f=0;
            rep(j,0,len2)
            {
               if((i+j)<len1)
               {
                 if(s[i+j]!=t[j])
                  current++;
               }
               else break;
               if(j==(len2-1))
                f=1;
            }
            if(f==1)
            {
              if(ans>current)
                ans=current;
            }
          }
          cout<<ans;
          
           return 0; 

} 

Measured memory_bytes: 3640
n = int(input())
p = list(map(int, input().split()))

index_list = []
count = 0
for i in range(n-1):
    if p[i] >= p[i+1]:
        if count == 0:
            index_list.append(i)
            count += 1
        elif count == 1:
            index_list.append(i+1)
            count += 1
        else:
            break

if count == 0:
    print("YES")
elif count == 2:
    tmp = p[index_list[0]]
    p[index_list[0]] = p[index_list[1]]
    p[index_list[1]] = tmp

    count = 0
    for i in range(n-1):
        if p[i] >= p[i+1]:
            print("NO")
            count += 1
            break
        else:
            pp = p[i]
    if count == 0:
        print("YES")
else:
    print("NO")


Measured memory_bytes: 3064
import sys

N = int(raw_input())
T, A = map(int, raw_input().split())
H_list = map(int, raw_input().split())

average_diff = sys.float_info.max
min_i = None

for i, H in enumerate(H_list):
    tempature_diff = abs(A - (T - H*0.006))
    if tempature_diff < average_diff:
        average_diff = tempature_diff
        min_i = i
print min_i + 1


Measured memory_bytes: 2692
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<ll> A(n);
  ll s = 0;

  for (int i = 0; i < n; i++) {
    cin >> A[i];
    s += A[i];
  }

  ll aa = 0;
  for (int i = 1; i < n-1; i+=2) {
    aa += A[i];
  }

  vector<ll> x(n);
  x[0] = s - 2*aa;
  for (int i = 1; i < n; i++) {
    x[i] = 2*A[i-1] - x[i-1];
  }

  for (int i = 0; i < n; i++) {
    cout << x[i];
    if(i == n-1){
      cout << endl;
    }else{
      cout << " ";
    }
  }



  return 0;
}

Measured memory_bytes: 2944
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
a = list()
for i in range(k):
    for j in range(int((n - i - 1) / k) + 1):
        if t[j * k + i] == "r":
            b = "p"
        elif t[j * k + i] == "s":
            b = "R"
        else:
            b = "S"
        a.append(b)
    a.append("/")
    
c = 2
ans = 0
e = 0
for i in range(len(a) - 1):
    if a[i] == a[i + 1]:
        c += 1
        if a[i] == "R":
            d = r
        elif a[i] == "S":
            d = s
        else:
            d = p
        e = 1
    elif a[i] != a[i + 1] and e == 1:
        ans += int(c / 2) * d
        c = 2
        d = 0
        e = 0
    elif a[i] != a[i + 1] and a[i] != "/":
        if a[i] == "R":
            f = r
        elif a[i] == "S":
            f = s
        else:
            f = p
        ans += f
        
print(ans)
        

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


typedef struct node{
  int key;
  struct node *p,*left,*right;
}node;
typedef struct node* Node;
void insert(int);
Node find(int);
void print(Node);
void inorder(Node);
void preorder(Node);
Node root,NIL;

int main(){
  int m,k,i;
  char string[8];
  scanf("%d",&m);
  for(i = 0; i < m; i++){
    scanf("%s",string);
    if(strcmp(string,"insert") == 0){
      scanf("%d",&k);
      insert(k);
    }
    else if(strcmp(string,"find") == 0){
      scanf("%d",&k);
      if(NIL == find(k))printf("no\n");
      else printf("yes\n");
    }
    else if(strcmp(string,"print") == 0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = (Node)malloc(sizeof(node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->p = y;

  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

Node find(int k){
  Node x = root;
  while(x != NIL && k != x->key){ 
    if(k < x->key) x = x->left;
    else x = x->right;
  }
  return x;
}

void inorder(Node r){
  if(r == NIL) return;
  inorder(r->left);
  printf(" %d",r->key);
  inorder(r->right);
}

void preorder(Node r){
  if(r == NIL) return;
  printf(" %d",r->key);
  preorder(r->left);
  preorder(r->right);
}



Measured memory_bytes: 20456
a=int(input()) #50*10*a
b=int(input()) #50*2*b
c=int(input()) #50*1*c
x=int(input())

#xは50の何倍？？
m=x//50
count=0
#m=10*a+2*b+cなる整数a,b,cの組

for i in range(0,a+1):
    for j in range(0,b+1):
        for k in range(0,c+1):
            if 10*i+2*j+k==m:
                count+=1
            
print(count)

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

int main(int argc, char **argv)
{
	int n; cin >> n;
	string str(to_string(n));
	for (int i = 0; i < 3; ++i)
	{
		if (str[i] == '7')
		{
			std::cout << "Yes"<< std::endl;
			return 0;
		}
	}
	std::cout << "No"<< std::endl;
}


Measured memory_bytes: 3708
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列
#define CO(a, b, c) ((a) ? (b) : (c))
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long ll;

int main(void)
{

    int n;
    cin >> n;
    vector<long long int> a(n);
    long long int ans = 1;
    for (auto &&i : a)
    {
        cin >> i;
        if (i == 0)
        {
            cout << 0 << endl;
            return 0;
        }
    }
    for (auto &&i : a)
    {
        if (ans > (1000000000000000000LL / i)) // || (ans * i) > 1000000000000000000)
        {
            ans = -1;
            break;
        }
        ans *= i;
    }
    if (ans > 1000000000000000000LL) // || (ans * i) > 1000000000000000000)
    {
        ans = -1;
    }
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 3972
let rec fix f x = f (fix f) x
let days = [|"SUN";"MON";"TUE";"WED";"THU";"FRI";"SAT"|]
let () = Scanf.scanf "%s" @@ fun s ->
  fix (fun f i ->
    if s = days.(i) then Printf.printf "%d\n" (7-i)
    else f (i+1)) 0



Measured memory_bytes: 384
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;


class Program
{


    static void Main(string[] args)
    {

        char[] cs = new char[] { ' ', ',' };
        //int val = int.Parse(Console.ReadLine());
        //int[] vals = parseAry(Console.ReadLine().Split(cs));
        //string str = Console.ReadLine();
        //string[] strs = Console.ReadLine().Split(cs);

        //string res="";
        //int res = 0; ;
        //int t = int.Parse(Console.ReadLine());
        //string str = Console.ReadLine();
        ///int[] vals = parseAry(Console.ReadLine().Split(cs));
        //int n = int.Parse(Console.ReadLine());

        long res =1;

		long[] vals = parseAryL(Console.ReadLine().Split(cs));
		long n = vals[0];
		long sell = vals[1];
		long buy = vals[2];
		long sa = buy - sell;
		if ( n < sell ) { res = n + 1; Console.WriteLine(res); return; }//転売する元手がない
		if ( sell+2 >= buy ) { res = n + 1; Console.WriteLine(res); return; }//転売が利益にならない

		n -= sell - 1;
		res=sell;
		res += ( n / 2 ) * sa;
		if ( n % 2 == 1 ) { res++; }
		



        Console.WriteLine(res);

        return;
    }

    //　String[]  ----->  int[]
    static int[] parseAry(string[] str)
    {
        int[] nums = new int[str.Length];
        for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); }
        return nums;
    }
    //　String[]  ----->  long[]
    static long[] parseAryL(string[] str)
    {
        long[] nums = new long[str.Length];
        for (int i = 0; i < str.Length; i++) { nums[i] = long.Parse(str[i]); }
        return nums;
    }

    //文字列を1文字ずつString[]に入れる
    static string[] strAry(String str)
    {
        string[] re = new string[str.Length];
        for (int i = 0; i < str.Length; i++) { re[i] = str[i].ToString(); }
        return re;
    }

}

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

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

  string s; cin >> s;
  if (s[0] != s[1] && s[1] != s[2] && s[2] != s[0])
    cout << "Yes" << "\n";
  else
    cout << "No" << "\n";
}

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

int main(){
    int N;
    double D;
    cin >> N >> D;
    int count = 0;
    double x[N], y[N];
    for (int i = 0; i < N; i++)
    {   
        cin >> x[i] >> y[i];
    }
    for (int i = 0; i < N; i++)
    {
        double d = sqrt(pow(x[i], 2) + pow(y[i], 2));
        if(d <= D){
            count += 1;
        }
    }
    
    cout << count << '\n';
}

Measured memory_bytes: 6964
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(void) {
    ll n;
    cin >> n;
    vector<ll> b;
    ll abs_min=1LL<<60;
    int cnt=0;
    ll res=0;
    rep(i,n){
        ll t;
        cin >>t;
        res += abs(t);
        if(t<0)cnt++;
        if(abs(t)<abs_min)abs_min=abs(t);
        b.push_back(t);
    }
    if(cnt%2==0)cout << res << endl;
    else cout << res-2*abs_min << endl;
    return 0;
}


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

int n;
char map[1000][1000];
int sq[1000][1000];

bool safe(int x, int y){
    return (x >= 0 && y >= 0 && x < n && y < n);
}

int minOf4(int x, int y){
    int b = 0;
    if (sq[x+1][y+1] && sq[x][y+1] && sq[x+1][y]){
	b = min(sq[x+1][y+1], min(sq[x][y+1], sq[x+1][y]));
    }
    return b;
}

int main(){
    while (1){
	cin >> n;
	if (!n) break;


	for (int i = 0; i < n; i++){
	    for (int j = 0; j < n; j++){
		cin >> map[i][j];
	    }
	}

	for (int i = 0; i < n; i++){
	    for (int j = 0; j < n; j++){
		if (map[i][j] == '.') sq[i][j] = 1;
		else sq[i][j] = 0;
	    }
	}

	for (int i = n-1; i >= 0; i--){
	    for (int j = n-1; j >= 0; j--){
		if (sq[i][j] != 0)
		    sq[i][j] += minOf4(i, j);
	    }
	}


	int m = 0;
	for (int i = 0; i < n; i++){
	    for (int j = 0; j < n; j++){
		if (m < sq[i][j]) m = sq[i][j];
	    }
	}

	cout << m << endl;
    }
}

Measured memory_bytes: 4660
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x) cout << x << endl ; 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std; 

int  a, b, c, d, e, f, l, r ; 
 
signed main() 
{ 
    ld density = -1.0;
    cin >> a >> b >> c >> d >> e >> f ; 
    a *= 100; b *= 100 ; 
    l = a, r = 0 ; 
    for (int i=0;i<=30;i++){ 
        if (a*i > f)  break ; 
        for (int j=0;j<=30;j++){
            int w = a*i+b*j;
            if (w > f )  break ; 
            int dissolve = min( f-w, (e*(a/100)*i + e*(b/100)*j) ) ; 
            for (int  ic = dissolve/c; w>0 and ic>=0 ; ic--){ 
                int cur = ( ic * c ) + ( (dissolve - ic*c ) / d ) * d ; 
                ld cur_density = (1.0*(ld)cur) / w ; 
                if (cur_density > density){
                    density = cur_density;
                    l = w+cur;
                    r = cur; 
                }
            }
        }
    }
    co( l << " " << r ) ; 
    return  0 ; 
} 

/* 
100 200 10 20 30 
   
*/ 


Measured memory_bytes: 3596
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	xmin := a * 125
	xmax := (a + 1) * 125
	ymin := b * 100
	ymax := (b + 1) * 100

	for x := xmin; x < xmax; x++ {
		if x >= ymin && x < ymax {
			res := x / 10
			if x%10 > 0 {
				res++
			}
			fmt.Println(res)
			return
		}
	}
	fmt.Println(-1)
}


Measured memory_bytes: 512
N = int(input())
S_P = []
for i in range(N):
    S , P = input().split()
    S_P.append([ S , int(P) , i])
S_P.sort( key = lambda x : x[0] )
state = S_P[0][0]
S_P_sort = []
temp = []
for S , P , i in S_P:
    if S != state:
        temp.sort( key = lambda x : x[1] , reverse = True)
        S_P_sort.extend(temp)
        state = S
        temp = []
        temp.append([S , P, i])
    else:
        temp.append([S , P, i])
temp.sort( key = lambda x : x[1] , reverse = True)
S_P_sort.extend(temp)
for j in range(N):
    print(S_P_sort[j][2]+1)

Measured memory_bytes: 3064
#include<stdio.h>
#define k 10000
  int A[2000000];
  int B[2000000];
int main(){
  int i,n,j;
  int C[k+1];

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

  for(i=0;i<k;i++){
    C[i]=0;
  }
  /* for(i=0;i<n-1;i++){
    printf("%d ",B[i]);
    }
    printf("%d\n",B[n-1]);
  */
  for(j=0;j<n;j++){
    C[A[j]]++;
  }
  for(i=1;i<k;i++){
    C[i]= C[i] + C[i-1];
  }
  for(j=n;j>=0;j--){
    B[C[A[j]]-1]=A[j];
    C[A[j]]--;
  }

  for(i=0;i<n-1;i++){
    printf("%d ",B[i]);
      }
  printf("%d\n",B[n-1]);
  return 0;
}



Measured memory_bytes: 17384
{-# LANGUAGE OverloadedStrings #-} 
import Data.Text as T
import Data.Text.IO as TIO
import Data.Monoid

main = do
  input <- TIO.getContents
  let ls = T.lines input 
      n = ls !! 0
      l :: [Int]
      l =   fmap ( read .T.unpack) $ T.words $ ls !! 1      
      (s0,s2,s4) = Prelude.foldl f (0,0,0) l
        where f  (s0,s2,s4) a  | (a `mod` 4) == 0 = (s0, s2, s4 + 1)
                               | (a `mod` 2 ) == 0 =  (s0, s2 + 1, s4)
                               | otherwise =  (s0 + 1, s2 , s4)
      getR (s0,s2,s4) | (s0<=s4) || ( s0 == s4+1 && s2 == 0 ) = "Yes"  
                      | otherwise = "No"
  Prelude.putStr $  getR (s0,s2,s4)

Measured memory_bytes: 9852
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const double pi=3.1415926536;
#define fo(i,n) for( ll int i=0;i<n;++i)
#define fos(j,i,n) for(ll int j=i;j<n;++j)
#define N 100004
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define abs(x) ((x)<0?(-(x)):(x))
#define dis(k) cout << k << endl
#define forr(i,n) for( ll int i= n-1;i>=0;--i)
#define dbg(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define ve vector
#define fi first
#define se second
#define setzero(a) memset(a,0,sizeof(a))
#define setinf(a) memset(a,0x7F,sizeof(a))
typedef ve< ll > vi;
typedef ve< vi > vvi;
typedef pair< ll ,ll > ii;


//weird debugging stuff
#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__) << "] "


/*Don't just sit and hope that God will solve this
fucking do something, try to observe or solve it a different way.
Use that pen and paper.
If nothing works take a deep breath and start again.*/


void solve(){
	ll n;
	cin >> n;
	ll a[n],b[n],c[n];
	fo(i,n) cin >> a[i] >> b[i] >> c[i];
	vvi dp(n,vi(3,0));
	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];
	fos(i,1,n){
		dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=b[i]+max(dp[i-1][2],dp[i-1][0]);
		dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
	}
	dis(max({dp[n-1][0],dp[n-1][1],dp[n-1][2]}));
	
}

int main(){
	fast;
	int t=1;
	int tt=1;
	//cin >> t;

	while(t--){
		//cout << "Case #" << tt << ": " ;
		tt++;
		solve();
	}
	return 0;
}



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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, a[100000];
int e, o;

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; }
	
	inc(i, n) {
		if(a[i] % 2 == 0) { e++; } else { o++; }
	}
	
	cout << (n == 1 || (o % 2 == 0) ? "YES" : "NO") << endl;
	
	return 0;
}


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

int main()
{
  
  int a;
  int b;
  int n;
  
  scanf("%d%d",&a,&b);

  if(a < 1 || 1000000000 < a || b < 1 || 1000000000 < b){
    exit(0);
  }

  if(a<b){
    n=a;
    a=b;
    b=n;
  }

  while(n != 0){
    n = a%b;
    a = b;
    b = n;
  }

  printf("%d\n",a);
  return 0;
}



Measured memory_bytes: 2124