akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>

#define Int register int

const int MAXN = 18, MAXL = 1 << 18, MOD = 998244353, Inv2 = MOD + 1 >> 1;
int n, m, a[MAXL + 5], F[MAXL + 5], G[MAXL + 5], H[MAXL + 5];

inline int qkpow ( int a, int b, const int p = MOD ) {
	int ret = 1;
	for ( ; b; a = 1LL * a * a % p, b >>= 1 ) ret = 1LL * ret * ( b & 1 ? a : 1 ) % p;
	return ret;
}

inline void FWT_XOR ( int* A, const int n, const int tp ) {
	for ( Int i = 2, stp = 1; i <= n; i <<= 1, stp <<= 1 ) {
		for ( Int j = 0; j < n; j += i ) {
			for ( Int k = j, t; k < j + stp; ++ k ) {
				t = A[k];
				A[k] = ( A[k] + A[k + stp] ) % MOD;
				A[k + stp] = ( ( t - A[k + stp] ) % MOD + MOD ) % MOD;
				if ( ! ~ tp ) {
					A[k] = 1LL * A[k] * Inv2 % MOD;
					A[k + stp] = 1LL * A[k + stp] * Inv2 % MOD;
				}
			}
		}
	}
}

inline void Work () {
	scanf ( "%d", &n ), m = 1 << n;
	int s = 0;
	for ( Int i = 0; i ^ m; ++ i ) {
		scanf ( "%d", &a[i] );
		s = ( s + a[i] ) % MOD;
	}
	for ( Int i = 0, invs = qkpow ( s, MOD - 2 ); i ^ m; ++ i ) {
		G[i] = 1LL * a[i] * invs % MOD;
		H[i] = MOD - 1;
	}
	G[0] = ( G[0] - 1 + MOD ) % MOD, H[0] = ( H[0] + m ) % MOD;
	FWT_XOR ( G, m, 1 ), FWT_XOR ( H, m, 1 );
	for ( Int i = 1; i ^ m; ++ i ) F[i] = 1LL * H[i] * qkpow ( G[i], MOD - 2 ) % MOD;
	FWT_XOR ( F, m, -1 );
	for ( Int i = 0; i ^ m; ++ i ) printf ( "%d\n", ( ( F[i] - F[0] ) % MOD + MOD ) % MOD );
}

int main () {
	Work ();
	return 0;
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=2e3,INF=1e8;
int N,B[MAX_N],W[MAX_N];

int bit[MAX_N*2+1],dp[MAX_N+1][MAX_N+1];

void init(){
	memset(bit,0,sizeof(bit));
}
void add(int x,int y){
	while(x<=(N<<1)){
		bit[x]+=y;
		x+=x&(-x);
	}
}
int que(int x){
	int ret=0;
	while(x>0){
		ret+=bit[x];
		x-=x&(-x);
	}
	return ret;
}

int main(){
	cin>>N;
	REP(i,N<<1){
		char c;
		int a;
		cin>>c>>a;
		a--;
		if (c=='B'){
			B[a]=i+1;
		}else{
			W[a]=i+1;
		}
	}
	REP(i,N+1)REP(j,N+1)dp[i][j]=INF;
	dp[0][0]=0;
	REP(sm,N<<1){
		int b,w;
		b=min(sm,N);
		w=sm-b;
		init();
		REP(i,b){
			add(B[i],1);
		}
		REP(j,w){
			add(W[j],1);
		}
		int lop=(sm<=N ? sm+1 : (N<<1)+1-sm);
		REP(i,lop){
			if (b<N){
				dp[b+1][w]=min(dp[b+1][w],dp[b][w]+sm-que(B[b]));
			}
			if (w<N){
				dp[b][w+1]=min(dp[b][w+1],dp[b][w]+sm-que(W[w]));
			}
			if (b>0 && w<N){
				add(B[b-1],-1);
				b--;
				add(W[w],1);
				w++;
			}
		}
	}
	cout<<dp[N][N]<<endl;
	return 0;
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;

int main(){
    int X; cin >> X;
    int ans = 1;
    for (int i = 2; i <= 100; i++)
    {
        int current = i;
        while (current * i <= X){
            ans = max(ans, current*i);
            current *= i;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 3548
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <map>
using namespace std;

string b[10];
int dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 };
int dy[8] = { 0, 1, 0, -1, 1, -1, 1, -1 };
bool visit[10][20];

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

	int h, w;
	while(cin >> h >> w, h | w) {
		for(int i = 0; i < h; i++) {
			cin >> b[i];
		}

		map<string, int> m;

		for(int y = 0; y < h; y++) {
			for(int x = 0; x < w; x++) {
				for(int k = 0; k < 8; k++) {
					int ny = y, nx = x;
					memset(visit, 0, sizeof visit);
					string s;
					while(!visit[ny][nx]) {
						visit[ny][nx] = true;
						s += b[ny][nx];
						m[s]++;
						ny = (ny + dy[k] + h) % h;
						nx = (nx + dx[k] + w) % w;
					}
				}
			}
		}

		string ans;
		for(auto p : m) {
			if(p.second <= 1 || p.first.size() <= 1) continue;
			string s = p.first;
			if(ans.size() < s.size() || ans.size() == s.size() && ans > s) {
				ans = s;
			}
		}
		if(ans == "") ans = "0";
		cout << ans << endl;
	}
}

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

using namespace std;
typedef long long ll;
const int N = 200010;
const int mod = 998244353;

 
string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int n, k;
pair<int, int> arr[N];
ll dp[N], cum[N];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= k; ++i) cin >> arr[i].first >> arr[i].second;
  sort(arr + 1, arr + 1 + k);
  dp[1] = 1;
  cum[1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (int j = 1; j <= k; ++j) {
      if (arr[j].first >= i) break;
      int rgt = i - arr[j].first;
      int lft;
      if (arr[j].second >= i) {
        lft = 1;
        // debug("yes", lft, rgt);
        dp[i] = (dp[i] + cum[rgt] - cum[lft - 1]) % mod;
        if (dp[i] < 0) dp[i] += mod;
        break;
      } else {
        lft = i - arr[j].second;
        // debug(i, lft, rgt);
        dp[i] = (dp[i] + cum[rgt] - cum[lft - 1]) % mod;
        if (dp[i] < 0) dp[i] += mod;
      }
    }
    cum[i] = (cum[i - 1] + dp[i]) % mod;
  }
  cout << dp[n] << '\n';
}

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

template<class X> X gcd(X a, X b) {return b ? gcd(b,a%b):a;}

int main() {
    int A1, A2, A3;
    cin >> A1 >> A2 >> A3;
    if(A1 + A2 + A3 >= 22) puts("bust");
    else puts("win");
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

N = int(input().strip())
#-----

hon_set = {2,4,5,7,9}
pon_set = {0,1,6,8}
bon_set = {3}

if (N % 10) in hon_set:
    print("hon")
elif (N % 10) in pon_set:
    print("pon")
elif (N % 10) in bon_set:
    print("bon")


Measured memory_bytes: 9108
#include <iostream>

using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;

	if (a >= 13)
	{
		cout << b << endl;
	}
	else if (a >= 6 && a <= 12)
	{
		cout << b / 2 << endl;
	}
	else
	{
		cout << 0 << endl;
	}
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(A: int, B: int):

    ans = 0
    if A > B:
        ans += A
        A -= 1
    else:
        ans += B
        B -= 1

    if A > B:
        ans += A
        A -= 1
    else:
        ans += B
        B -= 1

    print(ans)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	var s, t string
	fmt.Scan(&s, &t)

	for i := 0; i < n; i++ {
		fmt.Printf("%s%s", (string)(s[i]), (string)(t[i]))
	}
	fmt.Println()
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
signed main()
{
	ios_base::sync_with_stdio(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{   
		string s,t;
		cin >> s >> t;
		int a,b;
		cin >> a >> b;
		string u;
		cin >> u;
		if(u==s) a--;
		else b--;
		cout << a << " " << b;
	}
}

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

/*ll modpow(ll a,ll b){
	ll c=1;
	while(b>0){if (b%2==0){b/=2;a=(a*a)%mod;}else {b--;c=(c*a)%mod;}}
	return c;
}*/

int main()
{
	//freopen("input16.txt","r",stdin);freopen("output16.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int  i,j,k,s,t=0;
    cin>>k>>s;
    for (i=0;i<=k;i++){
    	for (j=0;j<=k;j++){
    		if (s-j-i<=k){
    			if (s-i-j>=0){
    			    t++;	
    			}
    			else {
    				break;
    			}
    		}
    	}
    }
    cout<<t;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n;
  cin>>n;
  ll a[n+1]={},b[n+1]={};
  vector<ll> v;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    cin>>b[i];
    v.push_back(a[i]-b[i]);
  }
  sort(v.begin(),v.end());
  ll sum=0,it=n;
  for(int i=0;i<n;i++){
    if(v[i]<0) sum=sum+(-v[i]);
    else{
      it=i;
      break;
    }
  }

  if(it==0){
    cout<<0<<endl;
    return 0;
  }
  ll po=0;
  for(int i=n-1;i>=0;i--){
    if(sum>0){
      if(v[i]<=0){
        cout<<-1<<endl;
        return 0;
      }
      sum-=v[i];
    }else{
      cout<<it+(n-1-i)<<endl;
      return 0;
    }
  }



  return 0;
}


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

#define ll long long
#define pb push_back

int ans[2003][2003];
deque < int > v;
int sti1, sti2, fii1, fii2;

main() {
    int n = 41 * 42 + 1;
//    freopen("inp.in", "w", stdout);
    int k = 42;
    printf ("%d %d\n", n, k);
    int cnt = 2;
    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= k; j++) {
            if (j == 1) {
                ans[i][j] = 1;
            } else {
                ans[i][j] = cnt++;
            }
        }
    }
    int add = k - 1;
    sti1 = 2, fii1 = k;
    for (int i = 2; i <= k; i++) {
        for (int j = 2; j <= k; j++) {
            v.pb(ans[j][i]);
        }
    }
    for (int i = k + 1; i <= k + add; i++) {
        ans[i][1] = 2;
        for (int j = 2; j <= k; j++) {
            ans[i][j] = v.front();
            v.pop_front();
        }
    }
    sti1 = k + 1, fii1 = sti1 + add - 1;
    sti2 = sti1 + add, fii2 = sti2 + add - 1;
    cnt = 3;
    int xi = sti1;
    int res = 0;
    int cn = 0;
//    cout << sti1 << ' ' << fii1 << endl;
//    cout << sti2 << ' ' << fii2 << endl;
    for (int i = sti2; i <= n; i++) {
        ans[i][1] = cnt;
        res++;
        v.clear();
        int ri = sti1 + cn;
        int rj = 2;
        for (int j = 2; j <= k; j++) {
            v.pb(ans[ri][j]);
            ri++;
            if (ri > fii1) {
                ri = sti1;
            }
        }
        for (int j = 2; j <= k; j++) {
            ans[i][j] = v[j - 2];
        }
        cn++;
        if (res >= add) {
            sti1 = sti2;
            fii1 = fii2;
            sti2 = fii1 + 1;
            fii2 = sti2 + add - 1;
            res = 0;
            cnt++;
            cn = 0;
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= k; j++) {
            printf ("%d ", ans[i][j]);
        }
        puts("");
    }
}

Measured memory_bytes: 13952
import numpy as np
from collections import deque
N,M = [int(i) for i in input().split()]
roads = [[] for _ in range(N+1)]
for _ in range(M):
    A,B = [int(i) for i in input().split()]
    roads[A].append(B)
    roads[B].append(A)
places = [0]*(N+1)
places[1] = 1
q = deque([1])
vis = [False]*(N+1)
vis[1] = True
while q:
    now = q.popleft()
    L = roads[now]
    for j in L:
        if vis[j]:
            continue
        vis[j] = True
        places[j] = now
        q.append(j)

print("Yes")
s = "\n".join(map(str, places[2:]))
print(s)

Measured memory_bytes: 60056
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class AX {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int A, B;
	    in >> A >> B;
	    out << max(max(A + B, A - B), A*B) << "\n";
	}
};


int main() {
	AX solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main() {
  int N, L, m, i, full, min = 10000;
  cin >> N >> L;
  int t[N];
  
  for (i = 1; i <= N; i++)
    t[i - 1] = L + i - 1; //ti = t[i-1] = L + i - 1
  
  for (i = 1; i <= N; i++)
    full += t[i - 1];
  
  for (i = 1; i <= N; i++) { //bitten = full - t[k] -> full - bitten = t[k]
    if (abs(t[i - 1]) < min) {
      min = abs(t[i - 1]);
      m = i;
    }
  }
  cout << full - t[m - 1];
  return 0;
}

Measured memory_bytes: 256
from itertools import combinations

n = int(input())
l = list(map(int, input().split()))

combi = combinations(l, 3)

ans = 0
for a, b, c in combi:
    if a != b and b != c and c != a:
        if a + b > c and b + c > a and c + a > b:
            ans += 1

print(ans)


Measured memory_bytes: 9108
#include <iostream>
#include <string>

using namespace std;
int main(int argc, char *argv[])
{
	int a, b, c;

	cin >> a >> b >> c;

	if (a + b >= c){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}

	return 0;
}



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

using namespace std;
typedef long long ll;
int main(){

    ll n;
    cin>>n;
    ll sum=0;

    for(ll i=1;i<=n;i++)
    {
        if( i%3==0 || i%5==0)
            continue;
        else
            sum+=i;


    }

 cout<<sum;
}


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

int main() {
  int n;cin>>n;
  string s;cin>>s;
  
  vector<int> sw(n);
  vector<int> se(n);
  for (int i=0;i<n;i++) {
    if(i==0) {
      sw.at(i)=0;
      se.at(n-1-i)=0;
    }
    else {
      s.at(i-1)=='W'?sw.at(i) = sw.at(i-1)+1:sw.at(i) = sw.at(i-1);
      s.at(n-i)=='E'?se.at(n-1-i) = se.at(n-i)+1:se.at(n-1-i) = se.at(n-i);
    }
    //cout << sw.at(i) << " " << se.at(n-i-1) << endl;
  }
  int ans=sw.at(0)+se.at(0);
  for(int i=0;i<n;i++) {
    ans=min(ans,sw.at(i)+se.at(i));
    //cout << ans << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3076
from collections import deque
n=int(input())
edge=[[] for i in range(n)]
if n==1:
  print(0)
  exit()
col=[-1 for i in range(n)]
for i in range(n-1):
  u,v,w=map(int,input().split())
  u-=1
  v-=1
  edge[u].append((v,w))
  edge[v].append((u,w))
def dfs(edge,col):
  stack=deque([0])
  col[0]=0
  while stack:
    x=stack.pop()
    for i,j in edge[x]:
      newx=i
      if col[i]==-1:
        col[newx]=(col[x]+j)%2
        stack.append(newx)
  return col
for i in range(n):
  print(dfs(edge,col)[i])

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

int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;

  return 0;
}

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

int main() {
	
 int a; 
  bool flag =true;
  bool bflag = true;
  cin >> a;
  int cou=0;
  vector<int> vec(a);
  for (int i = 0; i < a; i++) {
  cin >> vec.at(i);
	}
  vector<int> vect(a);
  for(int j=0;j<a;j++){
    vect.at(j)=vec.at(j);
  }
  std::sort(vect.begin(),vect.end());
  for(int i=0;i<a;i++)
    if(vec.at(i)!=vect.at(i))
      cou++;
  if(cou==0||cou==2)
    cout << "YES"<<endl;
  else
    cout<< "NO"<<endl;
}


Measured memory_bytes: 256
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

import math

xy.sort(key = lambda x: math.atan2(x[1], x[0]))
atanxy = [math.atan2(yi, xi) for xi, yi in xy]
    
# print("#", xy)
# print("#", atanxy)

ans2 = 0
# for src in range(N):
#     x_tmp, y_tmp = xy[src]
#     for j in range(1, N):
#         dst = (src + j) % N
#         if atanxy[src] < atanxy[dst]:
#             if atanxy[dst] <= atanxy[src] + math.pi:
#                 x_tmp += xy[dst][0]
#                 y_tmp += xy[dst][1]
#             else:
#                 break
#         else:
#             if atanxy[dst] < atanxy[src] -  math.pi:
#                 x_tmp += xy[dst][0]
#                 y_tmp += xy[dst][1]
#             else:
#                 break
#     #
#     if ans2 < (x_tmp ** 2 + y_tmp ** 2):
#         ans2 = (x_tmp ** 2 + y_tmp ** 2)
for src in range(N):
    x_tmp, y_tmp = xy[src]
    if ans2 < (x_tmp ** 2 + y_tmp ** 2):
        ans2 = (x_tmp ** 2 + y_tmp ** 2)
    for j in range(1, N):
        dst = (src + j) % N
        x_tmp += xy[dst][0]
        y_tmp += xy[dst][1]
        #
        if ans2 < (x_tmp ** 2 + y_tmp ** 2):
            ans2 = (x_tmp ** 2 + y_tmp ** 2)

print(math.sqrt(ans2))

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

int main() {
  int a[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  int x, y; cin >> x >> y;
  cout << (a[x] == a[y] ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[][] nums=new int[n][3];
        for(int i=0;i<n;i++){
            nums[i][0]=sc.nextInt();
            nums[i][1]=i;
        }
        Comp comp=new Comp();
        comp.set_index(0);
        Arrays.sort(nums,comp);
        for(int i=0;i<n;i++){
            nums[i][2]=i==n-1?nums[n-2][0]:nums[n-1][0];
        }
        comp.set_index(1);
        Arrays.sort(nums,comp);
        for(int i=0;i<n;i++){
            System.out.println(nums[i][2]);
        }
        
    }
}
class Comp implements Comparator {

    int index = 0;

    void set_index (int i) {
        index = i;
    }

    public int compare (Object a, Object b) {
        int[] int_a = (int[]) a;
        int[] int_b = (int[]) b;
        return (int_a[index] - int_b[index]);
    }

}

Measured memory_bytes: 107064
s = list(input())
N = len(s)
s_ = s[:]
#x_index = []
#(方針)x抜いて回文なら回文にできる ←結構複雑になるのでボツ
l,r = 0,N-1
ans = 0

while(1):
  if(l >= r): 
    break
    
  if(s[l] == s[r]):#先頭 末尾 同じなら
    l,r = l+1,r-1
  else:#先頭　末尾　違うなら
    if(s[l] == 'x'): 
      l = l+1
      ans += 1
    elif(s[r] == 'x'): 
      r = r-1
      ans += 1
    else: 
      ans = -1
      break
      
print(ans)

Measured memory_bytes: 4788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int A, B, C;
	cin >> A >> B >> C;

	int kotae = A + B + C;
	int k = max(A, B);
	k = max(k, C);

	co(kotae - k);

	Would you please return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pb push_back
#define f first
#define s second
#define MOD 998244353
 
using namespace std;


int main(){
 
	ios_base::sync_with_stdio(false);
	//cin.tie(0);
	cout<<fixed<<setprecision(12);
	//memset(dp,-1,sizeof(dp));
	string s;
	cin>>s;
	vector<char> vf,vb;
	int q; cin>>q;
	int a = 0;
	while(q--){
		int t;
		cin>>t;
		if(t == 1){
			a = (a+1)%2;
		}
		else{
			int f; char c;
			cin>>f>>c;
			if(f == 1){
				if(a == 0) vf.pb(c);
				else vb.pb(c);
			}
			else{
				if(a == 0) vb.pb(c);
				else vf.pb(c);
			}
			
		}
	}
	if(a == 0){
		reverse(vf.begin(),vf.end());
		for(auto x:vf) cout<<x;
		cout<<s;
		for(auto x:vb) cout<<x;
	}
	else{
		reverse(vb.begin(),vb.end());
		reverse(s.begin(),s.end());
		for(auto x:vb) cout<<x;
		cout<<s;
		for(auto x:vf) cout<<x;
	}

	return 0;
}
 

Measured memory_bytes: 976
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i = (int)(n)-1; i>=0; --i)
#define For(i,a,b) for(auto i=(a);i<=(b);++i)
#define rFor(i,a,b) for(auto i=(b);i>=(a);--i)
#define call(var) cerr<<#var<<"="<<var<<"\n";
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const double pi = acos(-1);
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}
template<class T> istream& operator>>(istream& is, vector<T>& a){rep(i,a.size()) is >> a[i]; return is;}
template<class T> ostream& operator<<(ostream& os, vector<T>& a){rep(i,a.size()) os << a[i] << " "; return os;}
template<class T, class U> istream& operator>>(istream& is, pair<T,U>& p){is >> p.first >> p.second; return is;}
template<class T, class U> ostream& operator<<(ostream& os, const pair<T,U>& p){os << "("<< p.first << "," << p.second << ")"; return os;}
template<class T, class U> ostream& operator<<(ostream& os, const map<T,U>& mp){for(auto& t : mp) os << t.first << " " << t.second << "\n"; return os;}

int main(){
    int a;cin >> a;
    cout << a + a*a + a*a*a << "\n";
}

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

        while(sc.hasNext()){

        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double c = sc.nextDouble();
        double d = sc.nextDouble();
        double e = sc.nextDouble();
        double f = sc.nextDouble();

        BigDecimal x = new BigDecimal((c*e-b*f)/(a*e-b*d));
        BigDecimal y = new BigDecimal((c*d-a*f)/(b*d-a*e));

        BigDecimal x_answer = x.setScale(3, BigDecimal.ROUND_HALF_UP);
        BigDecimal y_answer = y.setScale(3, BigDecimal.ROUND_HALF_UP);

        System.out.printf("%.3f ",x_answer.doubleValue());
        System.out.printf("%.3f\n",y_answer.doubleValue());

    }

    }
}

Measured memory_bytes: 20568
// D - Line++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

struct Node {
	vector<int> neighbors;
	bool visited = false;
	int step;
};

int N, X, Y;
Node nodes[2000];
int counter[2000];

void bfs(int start) {
	for (int i=0; i<N; i++) {
		nodes[i].visited = false;
		nodes[i].step = -1;
	}
	nodes[start].visited = true;
	nodes[start].step = 0;

	queue<int> search_queue;
	search_queue.push(start);

	while(!search_queue.empty()) {
		// キューから探索対象のノードのインデックスを取り出す
		int i = search_queue.front();
		search_queue.pop();

		int step = nodes[i].step;
		//cout << i << " (" << step << ")" << endl; // **** debug ****

		counter[step]++;

		for (int n : nodes[i].neighbors) {
			if (nodes[n].visited) {
				continue; // 探索済みならキューに入れない
			}

			nodes[n].visited = true;
			nodes[n].step = step + 1;
			search_queue.push(n);
		}
	}
}

int main(){
	cin >> N >> X >> Y;

	// i と i+1 を接続
	for (int i=0; i<N-1; i++) {
		nodes[i].neighbors.push_back(i+1);
		nodes[i+1].neighbors.push_back(i);
	}

	// X と Y を接続
	nodes[X-1].neighbors.push_back(Y-1);
	nodes[Y-1].neighbors.push_back(X-1);

	// 各頂点からBSF
	for (int i=0; i<N; i++) {
		//cout << "start: " << i << endl; // **** debug ****
		bfs(i);
	}

	// 2回ずつカウントされるので割って出力
	for (int i=1; i<N; i++) {
		cout << counter[i] / 2 << endl;
	}

	return 0;
}

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


/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)


#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);




///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}



///.............................................................TEMPLATE................................................./////

int main()
{
    FASTIO;

    int n;

    cin >> n;

    cout << (n*(n+1))/2 << endl;





    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll A,B;
  cin>>A>>B;
  ll a,b;
  a=A/0.08;
  b=(A+1)/0.08;
  for(ll i=a;i<b+2;i++){
    ll c,d;
    c=0.08*i;
    d=0.1*i;
    if(c==A&&d==B){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define oo (long long)1e18
#define ll long long
#define setdp memset(dp,-1,sizeof(dp))
const ll mod = 1e9+7;
void _IOS(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);}
#define PI 3.14159265359
int sx,sy,tx,ty;
ll a[200003];
ll b[2003];
bool vis[1009][1009];
struct threeElements{
int f,s,t;
};
int main()
{
   // freopen ("jumping.in","r",stdin);
   _IOS();
   int n;
cin>>n;
cout<<n+n*n+n*n*n;
}


Measured memory_bytes: 3612
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int> > vvi;
typedef vector<vector<double> > vvd;

int main(){

    int N, Y;
    cin >> N >> Y;
    Y /= 1000;

    if (N>Y)  {cout << "-1 -1 -1" << endl;return 0;}

    vvi item(Y+1, vi(3, -1));
    item[N][0]=0; item[N][1]=0; item[N][2]=N;

    for(int i=N; i<=Y; ++i){

        if( i>=4 and item[i-4][2]>0 ){
            item[i][0] = item[i-4][0];
            item[i][1] = item[i-4][1]+1;
            item[i][2] = item[i-4][2]-1;
        }

        if( i>=9 and item[i-9][2]>0 ){
            item[i][0] = item[i-9][0]+1;
            item[i][1] = item[i-9][1];
            item[i][2] = item[i-9][2]-1;
        }

        if( i>=5 and item[i-5][1]>0 ){
            item[i][0] = item[i-5][0]+1;
            item[i][1] = item[i-5][1]-1;
            item[i][2] = item[i-5][2];
        }

    }

    cout << item[Y][0] << " " << item[Y][1] << " " << item[Y][2] << endl;

    return 0;

}

Measured memory_bytes: 1280
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp2
{
    using static System.Console;
    using static System.Math;

    class Program
    {
        static void Main(string[] args)
        {
            N = int.Parse(ReadLine());
            V = ReadLine().Split().Select(int.Parse).ToArray();
            C = ReadLine().Split().Select(int.Parse).ToArray();
            Solve();
        }

        static int N;
        static int[] C, V;

        static void Solve()
        {
            var max = 0;
            for (int i = 0; i < N; i++)
            {
                if (V[i] > C[i])
                    max += V[i] - C[i];
            }
            WriteLine(max);
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
      for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}　これが経路圧縮!!!
      if (par[x] == x) return x;
      return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
      int rx = root(x); //xの根をrx
      int ry = root(y); //yの根をry
      if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
      par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
      int rx = root(x);
      int ry = root(y);
      return rx == ry;
    }
};
vector<ll> vec(100000,0),ans(100000,-1);

int main(){
  ll n,m,k;
  cin >> n >> m >> k;
  UnionFind U(n);
  rep(i,m){
    cin >> t1 >> t2;
    t1--,t2--;
    ans[t1]--,ans[t2]--;
    U.unite(t1,t2);
  }
  rep(i,n){
    vec[U.root(i)]++;
  }
  rep(i,n){
    ans[i] += vec[U.root(i)];
  }
  rep(i,k){
    cin >> t1 >> t2;
    t1--,t2--;
    if(U.same(t1,t2)){
      ans[t1]--;
      ans[t2]--;
    }
  }
  rep(i,n){
    cout << ans[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 3200
#include "bits/stdc++.h"
using namespace std;

#define all(x) (x).begin(),(x).end()
#define fastio ios_base::sync_with_stdio(false)

typedef double db;
typedef long long ll;
typedef unsigned long long ull;

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

int main() {
	fastio;
	int k, n; cin >> k >> n;
	vector < int > v(n), diff;
	for(int i = 0; i < n; ++i) cin >> v[i];
	for(int i = 0; i < n - 1; ++i) diff.push_back(v[i + 1] - v[i]);
	diff.push_back(k - v[n - 1] + v[0]);
	ll sum = 0;
	for(int i = 0; i < diff.size(); ++i) sum += diff[i];
	ll ans = LLONG_MAX;
	for(int i = 0; i < diff.size(); ++i) ans = min(ans, sum - diff[i]);
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main() {
    int N;
    cin >> N;
    
    int A[N] = { 0 };

    int current = 0, last = 0;
    cin >> last;
    A[0] = last;
    A[1] = last;
    for (int i = 1; i < N - 1; i++) 
    {
        cin >> current;
        if (current < last) {
            A[i] = current;
        } else {
            A[i] = last;
        }

        if (i == N - 2) 
        {
            A[N - 1] = current;
        }

        last = current;
    }
    
    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        sum += A[i];
    }

    cout << sum;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ar array<int,2>
#define inf 1000000000000000000 
int mod=1e9+7;
int min(int a,int b){return (a<b)?a:b;}
int max(int a,int b){return (a>b)?a:b;}
int fp(int a,int b){if(b==0) return 1;int x=fp(a,b/2);x=(x*x)%mod;if(b&1) x=(x*a)%mod;return x;}


const int N=2e5+5;



void solve()
{
    string s,t;
    cin>>s>>t;
    int ans=inf;
    for(int i=0;i<s.size();i++)
    {
        if((s.size()-i)>=(int)t.size())
        {
            int ct=0;
            for(int j=0;j<t.size();j++)
            {
                if(s[i+j]!=t[j])
                    ct++;
            }
            ans=min(ans,ct);
        }
    }
    cout<<ans<<endl;
}

signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
 srand(time(0));
 int t;
 t=1;
 for(int i=1;i<=t;i++)
 {
   solve();
 }


}

Measured memory_bytes: 3664
import numpy as np
N, K = map(int, input().rstrip().split())
pro = 0.
for i in range(1,N+1):
    x = np.log2(K) - np.log2(i)
    x = np.ceil(x)
    if x > 0:
        pro += 1/N*(1/2)**x
    else:
        pro += 1/N
print(pro)

Measured memory_bytes: 12488
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h, w, n,m,k; string s,t;
char maze[60][60];
int dis[101][101]; int graph[52][52]; bool vis[52];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}

int main() {
	ll d;
	cin >> m >> d;
	ll cnt = 0;
	for (ll i = 1; i <= m; i++) {
		for (ll j = 11; j <= d; j++) {
			if ((j % 10) * (j / 10) == i&&((j%10)>=2&&j/10>=2)) {
				cnt++;
			}
		}
	}
	cout << cnt << endl;
}

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

int main() {
  char a;
  cin>>a;
  if(a=='A') cout<<'T'<<endl;
  else if(a=='T') cout<<'A'<<endl;
  else if(a=='C') cout<<'G'<<endl;
  else cout<<'C'<<endl;
  return 0;
}


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

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

  int ans=pow(3,n), del=1;
  for(int i=0; i<n; i++){
    int a;
    cin>>a;
    if(a%2==0)del*=2;
  }

  cout<<ans-del<<endl;
}


Measured memory_bytes: 640
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int result ;
		if (A<10 && B<10){
			result = A*B;
		}else{
			result = -1;
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 22612
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>

typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;

bool isCorrect(int grid[3][3], int a1, int a2, int a3) {
    int j1, j2, j3;
    j1 = grid[0][0] - a1;
    j2 = grid[0][1] - a1;
    j3 = grid[0][2] - a1;

    if (a2 + j1 != grid[1][0]) return false;
    if (a2 + j2 != grid[1][1]) return false;
    if (a2 + j3 != grid[1][2]) return false;
    if (a3 + j1 != grid[2][0]) return false;
    if (a3 + j2 != grid[2][1]) return false;
    if (a3 + j3 != grid[2][2]) return false;

    return true;
}

int main(void) {
    int grid[3][3];
    REP(i, 3) {
        REP(j, 3) {
            cin >> grid[i][j];
        }
    }

    FOR(a1, 0, 101) {
        FOR(a2, 0, 101) {
            FOR(a3, 0, 101) {
                if (isCorrect(grid, a1, a2, a3)) {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "No" << endl;

    return 0;
}


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


int main()
{
	int a;
	cin >>a;
	cin.ignore();
	int count(0);
	while(a--){
		string inp;
		getline(cin, inp);
		if(inp[0]==inp[2])
			count++;
		else
			count  = 0;	
		if(count==3){
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}


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

int main(){
  ll n,k;
  std::cin >> n>>k;
  std::vector<ll> a(n);
  std::vector<ll> al(n,-1);


  rep(i,n){
    ll temp;
    std::cin >> temp;temp--;
    a[i]=temp;
  }

  ll start=0;
  ll now=0;
  ll cnt=0;
  ll loop=0;

  rep(i,n){
    // std::cout << cnt<<":"<<now+1<< '\n';
    if(cnt==k){
      std::cout << now+1 << '\n';
      return 0;
    }
    if(al[now]==-1)al[now]=cnt;
    else{
      loop=al[now]-cnt;
      break;
    }
    now=a[now];
    cnt++;
  }

  // std::cout << " loop " <<cnt<<"  "<<cnt+(k-cnt)/loop*loop<< '\n';
  //残り消費する移動回数　k-cnt
  //ループ可能な限りする　cnt+=(k-cnt)/loop*loop
  cnt+=(k-cnt)/loop*loop;

  rep(i,n){
    // std::cout << cnt<<":"<<now+1<< '\n';
    if(cnt==k){
      std::cout << now+1 << '\n';
      return 0;
    }
    cnt++;
    now=a[now];
  }


}


Measured memory_bytes: 6428
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;
using llong = long long;
using ullong = unsigned long long;

int main() {
  int N,K;
  cin >> N >> K ;
  int cnt = 0;
  for(int i=0;i<N;++i){
    int h;
    cin >> h;
    if( h >= K ) cnt++;
  }
  cout << cnt << endl;
}


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

int main() {
    int a , b , c;
    cin >> a >> b >> c;
    if (a <= b && b <= c) {
        cout << a << " " << b << " " << c << endl;
    } else if (b <= a && a <= c) {
        cout << b << " " << a << " " << c << endl;
    } else if (a <= c && c <= b) {
        cout << a << " " << c << " " << b << endl;
    } else if (c <= a && a <= b) {
        cout << c << " " << a << " " << b << endl;
    } else if (b <= c && c <= a) {
        cout << b << " " << c << " " << a << endl;
    } else if (c <= b && b <= a) {
        cout << c << " " << b << " " << a << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
import itertools
N = int(input())
prm = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]
abc = list(itertools.permutations(prm,3))
ab  = list(itertools.permutations(prm,2))
ans = 0
for i in abc:
    a=0; b=0; c=0
    A=i[0]; B=i[1]; C=i[2]
    while A<=N:
        a += N//A
        A *= i[0]
    while B<=N:
        b += N//B
        B *= i[1]
    while C<=N:
        c += N//C
        C *= i[2]
    if a>=4 and b>=4 and c>=2:
        ans += 1
ans //= 2
for i in ab:
    a=0; b=0
    A=i[0]; B=i[1]
    while A<=N:
        a += N//A
        A *= i[0]
    while B<=N:
        b += N//B
        B *= i[1]
    if a>=14 and b>=4:
        ans += 1
    if a>=24 and b>=2:
        ans += 1
for i in prm:
    a=0; A=i
    while A<=N:
        a += N//A
        A *= i
    if a>=74:
        ans += 1
print(ans)


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

int main()
{
    int n,tmp,sum=0,MIN;
    int d[105],v[105],m[105][105],p,child;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)cin>>tmp,m[i][j]=tmp;
        v[i]=0;
    }
    vector<int>G;
    v[0]=1;
    G.push_back(0);
    for(int M=1;M<n;M++)
    {
        MIN=2005;
        for(int i=0;i<M;i++)
            for(int j=0;j<n;j++)
                if(m[G[i]][j]!=-1&&!v[j]&&m[G[i]][j]<MIN)
                {
                    MIN=m[G[i]][j];
                    p=G[i];
                    child=j;
                }
        G.push_back(child);
        sum+=m[p][child];
        v[child]=1;
    }
    cout<<sum<<endl;
    return 0;
}



Measured memory_bytes: 3136
#include <iostream>
#include <vector>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main() {
  int n, k;
  cin >> n >> k;
  vector<lli> h(n);
  vector<lli> dp(n + 10, 1e12);
  dp[0] = 0;
  rep(i, n) cin >> h[i];
  rep(i, n) rep(j, k) {
    int nxt = i + j + 1;
    if (nxt < n) {
      dp[nxt] = min(dp[i] + abs(h[i] - h[nxt]), dp[nxt]);
    }
  }
  cout << dp[n - 1];
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
bool can[21];
string dp[11111];
int num[]={0,2,5,5,4,5,6,3,7,6};
int n,m;
string mx(string x,string y){
	if(x.size()!=y.size())
		if(x.size()<y.size())
			return y;
		else
			return x;
	return x<y?y:x;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int a;
		scanf("%d",&a);
		can[a]=1;
		string now="";
		now+=(char)('0'+a);
		dp[num[a]]=mx(now,dp[num[a]]);
	}
	for(int i=0;i<n;i++)
		for(int j=1;j<10;j++){
			if(!can[j] || dp[i]=="")
				continue;
//			cout<<dp[i]<<" "<<i<<endl;
			dp[i+num[j]]=mx(dp[i+num[j]],dp[i]+(char)(j+'0'));
//			cout<<dp[i+num[j]]<<" "<<i+num[j]<<endl;
		}
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 43648
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define INF 1<<20

using namespace std;

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

const int max_v = 10005;

struct edge{ int to, cost; };
vector<edge> G[max_v];
int d[max_v];

void dijkstra (int n )
{
	priority_queue<P, vector<P>, greater<P> > que;
	fill (d, d+n, INF );
	d[0] = 0;
	que.push (P (0, 0 ) );

	while (!que.empty() ){
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first ) continue;
		rep (i, G[v].size() ){
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost ){
				d[e.to] = d[v] + e.cost;
				que.push (P (d[e.to], e.to ) );
			} // end if
		} // end rep
	} // end while
}

int main()
{
	ios_base::sync_with_stdio(0);
	int n; cin >> n;
	rep (i, n ){
		int u, k; cin >> u >> k;
		while (k-- ){
			int v, c; cin >> v >> c;
			edge ne; ne.to = v; ne.cost = c;
			G[u].push_back (ne );
		} // end while
	} // end rep
	dijkstra (n );

	rep (i, n ) cout << i << ' ' << d[i] << endl;
		
	return 0;
}

Measured memory_bytes: 6320
N=int(input())
l={}
ans =[]
 
"""for i in range(N):
  s=input()
  if s in l:
    l[s]+=1
  else:
    l[s]=1
print(l)"""
for i in range(N):
    s=input()
    if s in l:
        l[s]+=1
    else:
        l[s]=1
#print(l)
num = max(l.values())
#print(max)
for i in l:
    #print(l[i])
    if l[i]==num:
      ans.append(i)
b = sorted(ans)
for i in b:
    print(i)


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

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

ll lcm(ll a, ll b){
  return a/gcd(a,b) * b;
}

ll zyou(ll a,ll b){//a＾b
  ll res = 1;
  for(int i = 1;i<=b;i++){
    res *= a;
  }
  return res;
}
struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t),weight(w){ }
};

typedef pair<int,int> P;
using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}


bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}

bool palin(string S){//回文判定
  int n = S.size();
  bool flag = true;
  if(n%2 == 0){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  else if(n%2 == 1){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  return flag;
}
vector<int> dx = {1,0,-1,0};
vector<int> dy = {0,1,0,-1};

vector<vector<char>> field(10, vector<char>(10));

//oと上下左右で隣接しているところは全てxに変える 
//全てのマスをxに変えるまで何回dfsを行ったかがoの連結数

//現在地(x,y)
void dfs(int x, int y) {
  //今いるところをxに変える

  field[x][y] = 'x';

  //移動する四方向をループ
  for (int i = 0; i < 4; i++) {

    //移動先をnx,nyとする
    int nx = x + dx[i], ny = y + dy[i];

    //nxとnyが地図の範囲内であるかどうかと移動先field[nx][ny]が陸地かどうかを判定
    if (nx >= 0 && nx < 10 && ny >= 0 && ny < 10 && field[nx][ny] == 'o') dfs(nx,ny);

  }
  return;
}

//Sが偶文字列であるかどうか判定
bool hantei(string S) {
	int N = S.size();

	if(N%2) return false;

	else {
		string S1 = S.substr(0,N/2);
		string S2 = S.substr(N/2,N/2);
		if(S1 == S2) return true;
		else return false;
	}
}

int main(){
	int R,G,B,N;
	cin >> R >> G >> B >> N;
	ll ans = 0;
	for (int r = 0; r <= N/R; r++) {
		for (int g = 0; g <= N/G; g++) {
			if((N - r * R - g * G) % B == 0){
				int b = (N - r * R - g * G) / B;
				if(b >= 0) ans++;
			} 
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256