akhauriyash/Code-Regression huggingface dataset:
def get_next_unchosen(current , chooseNum):
    if (chooseNum , 0) in current or (chooseNum , 1) in current:
        if (chooseNum , 0) in current and (chooseNum ,1) in current:
            return max(current[(chooseNum, 0)] , current[(chooseNum, 1)])
        if (chooseNum , 0) in current:
            return current[(chooseNum , 0)]
        return current[(chooseNum,1)]
    return None


def calc_next_state(current, must_choose_num, a):
    next = {}
    current_unchosen_nums = [choose_num  for (choose_num, prev_chosen) in current.keys() if prev_chosen == 0 and choose_num >= must_choose_num - 1]
    for chooseNum in current_unchosen_nums:
        next[(chooseNum + 1, 1)] = current[(chooseNum , 0)] + a
    for chooseNum in range(must_choose_num, N):
        n = get_next_unchosen(current, chooseNum)
        if n is None:
            break
        else:
            next[(chooseNum , 0)] = n
    return next


N = int(input())
A = [int(x) for x in input().split()]

totalChooseNum = N // 2
dp = {(0, 0) : 0}
for i in range(0, N):
    ai = A[i]
    canChooseNum = (N - i + 1) // 2
    mustChooseNum = max(totalChooseNum - canChooseNum, 0)
    dp = calc_next_state(dp, mustChooseNum, ai)

result = max(dp[(totalChooseNum, 0)] , dp[(totalChooseNum , 1)])
print(result)


Measured memory_bytes: 33196
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000009
#define mod 1000000007

int n, a, b, c[100005];
string s;

int main()
{
    cin >> n;

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


    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
s = input()
res = list(map(int,s.split()))

for k in range(K):
    delta = [0]*(N+1)
    for i,val in enumerate(res):
        left = max(0, i-val)
        right = min(N, i+val+1)
        delta[left] += 1
        delta[right] -= 1
    res = [0]*N
    res[0] = delta[0]
    for i in range(N-1):
        res[i+1] = res[i]+delta[i+1]
    if delta[0] == -delta[N] == N:
        break

print(*res)

Measured memory_bytes: 168940
//My Conquest Is the Sea of Stars.
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define gcd __gcd
#define pb push_back
#define mp make_pair
#define lowbit(x) x & (-x)
#define PII  pair<int, int> 
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for(__typeof(b) i = a; i <= (b); i++)
#define Rep(i, a, b) for(__typeof(a) i = a; i >= (b); i--)
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)2e5 + 5;
const ll INF = 0x3f3f3f3f3f3f3f3f;
using namespace std;

int a[maxn];
ll dp[maxn][5];

int main()
{
	int n; scanf("%d", &n);
	rep(i, 1, n) scanf("%d", a + i);
	memset(dp, 0x3f, sizeof(dp));
	rep(i, 0, 4) dp[0][i] = 0;
	rep(i, 1, n){
		dp[i][0] = dp[i-1][0] + a[i];
		rep(j, 1, 4){
			rep(k, 0, j){
				dp[i][j] = min(dp[i][j], dp[i-1][k]);
			}
		}
		dp[i][1] += (a[i] == 0 ? 2 : (a[i] & 1));
		dp[i][2] += (a[i] % 2 == 0);
		dp[i][3] += (a[i] == 0 ? 2 : (a[i] & 1));
		dp[i][4] += a[i];
	}
	ll ans = INF;
	rep(i, 0, 4) ans = min(ans, dp[n][i]);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 8832
// D - Redistribution
#include <bits/stdc++.h>
using namespace std;

int main(){
	int S; cin>>S;
	int MOD = 1e9 + 7;
	int b3 = 1, b2 = 0, now = 0; // now == b1
	while(S-- > 2){ // S-2>0 -> S>2
		int b1 = now;
		now = (b1 + b3) % MOD;
		b3 = b2; b2 = b1;
	}
	cout<< now <<endl;
}


Measured memory_bytes: 3632
H, W, K = map(int, input().split())

chart = [input() for _ in range(H)]

ans = [[-1] * W for _ in range(H)]
now = 1

for h in range(H):
    for w in range(W):
        if chart[h][w] == '#':
            ans[h][w] = now
            for rw in range(w - 1, -1, -1):
                if chart[h][rw] == '#':
                    break
                if ans[h][rw] == -1:
                    ans[h][rw] = now
                else:
                    break
            for rw in range(w + 1, W):
                if chart[h][rw] == '#':
                    break
                if ans[h][rw] == -1:
                    ans[h][rw] = now
                else:
                    break
            now += 1

nonEmpPrev = None
for h, line in enumerate(ans):
    if set(line) == set([-1]):
        if nonEmpPrev != None:
            print(*nonEmpPrev)
        else:
            for n in ans[h + 1:]:
                if set(n) != set([-1]):
                    nonEmpPrev = n
                    break
            print(*nonEmpPrev)
    else:
        print(*line)
        nonEmpPrev = line

Measured memory_bytes: 49244
template<class T> inline void chmin(T & a, T b) { if (a > b) a = b; }

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

void solve() {
	long long A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;
	const long long MAX = 100000;

	long long res = (1LL << 30);
	long long ab, a, b;

	// 必要なA, Bピザを必要枚数X, Y分買うのに最小で何円で買えるかシミュレート
	// ABピザを0~10万枚まで全探索する
	rep(i, MAX+1) {
		ab = i * 2 * C; // ABピザをi枚買った時の価格
		a = max(0LL, X - i) * A; // 足りない分のAピザの価格
		b = max(0LL, Y - i) * B; // 足りない分のBピザの価格
		chmin(res, ab + a + b);
	}

	cout << res << endl;

}

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

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
char tile[15][15];
void solve(int x,int y)
{
    if(tile[x][y]=='1')
    {
        tile[x][y] = '0';
        solve(x+1,y);
        solve(x+2,y);
        solve(x+3,y);
        solve(x,y+1);
        solve(x,y+2);
        solve(x,y+3);
        solve(x-1,y);
        solve(x-2,y);
        solve(x-3,y);
        solve(x,y-1);
        solve(x,y-2);
        solve(x,y-3);
    }
    return ;
}


int main()
{
    int n;
    cin >> n;
    for(int data = 1;data<=n;data++)
    {
        string s;
        getline(cin,s);
        getline(cin,s);
        for(int j=3;j<8+3;j++)for(int i=3;i<8+3;i++)
        {
            cin >> tile[i][j];
        }
        int x,y;
        cin >> x>>y;
        solve(x+2,y+2);
        cout << "Data " << data <<":" << endl;
        for(int j=3;j<8+3;j++)
        {
            for(int i=3;i<8+3;i++)
            {
                cout <<tile[i][j];
            }
        cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <set>

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<string> W(N);
	for (auto& x : W) {
		cin >> x;
	}

	set<string> history;
	history.insert(W[0]);
	bool ok = true;
	for (int i = 1; i < N; ++i) {
		if (!history.insert(W[i]).second) {
			ok = false;
			break;
		}
		if (W[i - 1].back() != W[i].front()) {
			ok = false;
			break;
		}
	}
	if (ok) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
N=int(input())#街の数N+1、勇者がN
A=list(map(int,input().split()))#モンスターの数Ai
B=list(map(int,input().split()))#Niの勇者はモンスターの数Biまで倒せる
ans = 0
for i in range(N):
  #print(ans)
  if B[i] > A[i]:
    #print('a')
    B[i] -= A[i]
    ans += A[i]
    A[i] = 0
    if A[i+1] - B[i] > 0:
      #print('a-a')
      A[i+1] -= B[i]
      ans += B[i]
    else:
      #print('a-b')
      ans += A[i+1]
      A[i+1] = 0
  else:
    #print('b')
    ans += B[i]
print(ans)
      
    

Measured memory_bytes: 19156
x = [int(i) for i in input().split()]
n = x[0]
m = x[1]
y = [int(i) for i in input().split()]
ans = [True for i in range(n)]
dic = {}
for i in range(len(y)) :
    dic[i+1] = y[i]
for i in range(m) :
    p = [int(j) for j in input().split()]
    a = y[p[0]-1]
    b = y[p[1]-1]
    c = p[0]
    d = p[1]
    if a == b :
        ans[c-1] = False
        ans[d-1] = False
    elif a >b :
        ans[d-1] = False
    else :
        ans[c-1] = False
count = 0 
for i in range(n):
    if ans[i]:
        count += 1
print(count)


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

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

ll x;

int main(){
    cin >> x;

    ll ans = x / 11;
    if(x % 11 == 0) ans--;

    x -= ans * 11;
    ans++;
    ans = ans * 2;

    if(x <= 6)    ans--;

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;

int main() {
    ll n,m; cin >> n >> m;
    cout << (n-1)*(m-1) << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fr first
#define sc second
const int inf=INT_MAX;
const int nmax=1e5+5;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
ll ans;
int n,i,v;
char s[55],s1[55];
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	//freopen("sol.in","r",stdin);
	cin>>n>>(s+1)>>(s1+1);
	s[0]=s1[0]=s[n+1]=s1[n+1]='*';
	if(s[1]==s[2])ans=6,i=3,v=1;
	else ans=3,i=2;
	for(;i<=n;i++)
	{
		if(s[i]==s[i+1] && v)ans*=3,ans%=mod,i++;
		else if(s[i]==s[i+1] && !v)ans*=2,ans%=mod,v=1,i++;
		else 
		{
			if(!v)ans*=2,ans%=mod;
			v=0;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
# define M_PI           3.14159265358979323846  /* pi */
using namespace std;

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	int k = 0;
	int j = 0;
	int result = 0;

	for (int i = 1; i <= N; i++) {
		k = i;

		while (true) {
			if (k < 10) {
				j += k % 10;
				break;
			}
			j += k % 10;
			k = k / 10;
		}

		if (A <= j && j <= B) {
			result += i;
		}
		j = 0;
		k = 0;
	}
	cout << result << endl;
}

Measured memory_bytes: 3636
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

s=input()
if s[0]==s[1] and s[1]==s[2]:
    print("No")
else:
    print("Yes")

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

using namespace std;

///==================================================================================///

///for
#define F(i,n) for(int i=0;i<n;i++)
#define Fb(i,n) for(int i=n-1;i>=0;i--)
#define Fi(i,l,r) for(int i=l;i<=r;i++)
#define Fbi(i,r,l) for(int i=r;i>=l;i--)
///push and pop
#define pusb push_back
#define pusf push_front
#define popb pop_back
#define popf pop_front
///pair
#define fi first
#define se second
#define mp make_pair
///values
#define INF 2000000000
#define llINF (long long)9000000000000000000

///types
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
///pairs
typedef pair<int,int> II;
typedef pair<int,II> III;
typedef pair<double,double> DD;
typedef pair<string,string> SS;
///vectors
typedef vector<int> VI;
typedef vector<II> VII;
typedef vector<III> VIII;
typedef vector<VI> VVI;
typedef vector<VII> VVII;
typedef vector<string> VS;
///queues
typedef priority_queue<int,vector<int>,greater<int> > PQI_min;
typedef priority_queue<int> PQI_max;
typedef priority_queue<II,vector<II >,greater<II > > PQII_min;
typedef priority_queue<II > PQII_max;
typedef queue<int> QI;
typedef queue<II > QII;
///stack
typedef stack<int> SI;
typedef stack<II > SII;

///functions
template<class T> T modulo(T x, T p) {
    if(x>=0) return x%p;
    return p + x%p;
}
template<class T> T gcd(T a, T b) {
    if(b==0) return a;
    return gcd(b, a%b);
}
template<class T> T lcm(T a, T b) {
    return a*b/gcd(a,b);
}

///==================================================================================///

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    //freopen("1.in","r",stdin);
    //freopen("out.out","w",stdout);
    ///==================================================///
    
    int n; cin>>n;
    VI a(n);
    F(i,n) cin>>a[i];

    int sum=0;
    for(int i=0;i<n;i+=2) sum+=(a[i]%2!=0);
    cout<<sum;

    return 0;
}


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

using namespace std;

int main()
{
    int d, n;
    cin >> d >> n;
    int s=1;
    for(int i=0;i<d;i++) s*=100;
    if(n<=99) cout << n*s << endl;
    else cout << 101*s << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.TreeSet;
 
 
 
public class Main {
  public static void main(String[] args) {
    InputReader sc = new InputReader(System.in);
 
    int n = sc.nextInt();

    int[] numlist = new int[n];
    int[] sortedlist = new int[n];

    for(int i = 0; i < n; i++){
      int a = sc.nextInt();
      numlist[i] = a;
      sortedlist[i] = a;
    }

    Arrays.sort(sortedlist);

    int smallcenter = sortedlist[n / 2 - 1];
    int bigcenter = sortedlist[n / 2];

    for(int i = 0; i < n; i++){
      if(numlist[i] == bigcenter){
        System.out.println(smallcenter);
      }else if(numlist[i] == smallcenter){
        System.out.println(bigcenter);
      }else if(numlist[i] < smallcenter){
        System.out.println(bigcenter);
      }else{
        System.out.println(smallcenter);
      }
    }
 
  }

 //ここからテンプレ
  static class InputReader {
      private InputStream stream;
      private byte[] buf = new byte[1024];
      private int curChar;
      private int numChars;
      private SpaceCharFilter filter;
 
      public InputReader(InputStream stream) {
          this.stream = stream;
      }
 
      public int next() {
          if (numChars == -1)
              throw new InputMismatchException();
          if (curChar >= numChars) {
              curChar = 0;
              try {
                  numChars = stream.read(buf);
              } catch (IOException e) {
                  throw new InputMismatchException();
              }
              if (numChars <= 0)
                  return -1;
          }
          return buf[curChar++];
      }
 
      public String nextStr() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        StringBuffer str = new StringBuffer();
        do{
          str.append((char)c);
          c = next();
        }while(!isSpaceChar(c));
        return str.toString();
      }
 
      public char nextChar() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        char ret;
        do{
          ret = (char)c;
          c = next();
        }while(!isSpaceChar(c));
        return ret;
      }
 
      public int nextInt() {
          int c = next();
          while (isSpaceChar(c))
              c = next();
          int sgn = 1;
          if (c == '-') {
              sgn = -1;
              c = next();
          }
          int res = 0;
          do {
              if (c < '0' || c > '9')
                  throw new InputMismatchException();
              res *= 10;
              res += c - '0';
              c = next();
          } while (!isSpaceChar(c));
          return res * sgn;
      }
 
      public boolean isSpaceChar(int c) {
          if (filter != null)
              return filter.isSpaceChar(c);
          return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
      }
 
      public interface SpaceCharFilter {
          public boolean isSpaceChar(int ch);
      }
  }
}

Measured memory_bytes: 50996
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll unsigned long long
#define maxn 500005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;
#define int long long
vector<int>g[2005];
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, x, y;
    cin >> n >> x >> y;
    f1(n-1){
        g[i].pb(i+1);
        g[i+1].pb(i);
    }
    g[x].pb(y);
    g[y].pb(x);
    int cnt[n + 5] = {};
    f1(n) {
        int d[n + 5] = {};
        memset(d,0x3f,sizeof(d));
        d[i] = 0;
        queue<int>q;
        q.push(i);
        while (!q.empty()) {
            int now = q.front();
            q.pop();
            for (auto i:g[now]) {
                if (d[i] > d[now] + 1) {
                    d[i] = d[now] + 1;
                    q.push(i);
                }
            }
        } 
        fr(j,1,n+1) {
            if (j == i) {
                continue;
            }
            cnt[d[j]]++;
        }
    }
    f1(n - 1) {
        cout << cnt[i]/2 << '\n';
    }
}


Measured memory_bytes: 384
N=int(input()) #縦2列
XY=[map(int, input().split()) for _ in range(N)]
X,Y=[list(i) for i in zip(*XY)]
ans="No"

for j in range(0,N-2):
    if X[j]==Y[j] and X[j+1]==Y[j+1] and X[j+2]==Y[j+2]:
        ans="Yes"
        break

print(ans)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
int main(){
  int p, q, r;
  vector<int> root;
  cin >> p;
  root.push_back(p);
  cin >> q;
  root.push_back(q);
  cin >> r;
  root.push_back(r);
  sort(root.begin(), root.end());
  cout<<root[0]+root[1]<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<P,P> PP;
const ll MOD=10000;
const ll INF=1000000010;
const int MAX=100001;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    int a,b;
    cin>>a>>b;
    cout<<(a+b)/2<<endl;
    return 0;
}



Measured memory_bytes: 3088
# coding: utf-8
# Your code here!
judge = ["AC", "WA", "TLE", "RE"]

N = (int)(input())
count = [0,0,0,0]

for i in range(N):
    inp = input()
    if inp in judge:
        count[judge.index(inp)] += 1
    else:
        continue
        
print("AC x " + str(count[0]))
print("WA x " + str(count[1]))
print("TLE x " + str(count[2]))
print("RE x " + str(count[3]))


Measured memory_bytes: 9204
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int a = sc.nextInt();
        
        if(h % a == 0) {
            System.out.println(h / a);
        }else {
            System.out.println(h / a + 1);
        }

    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(c, i, n) for (int i = c; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    double r;
    cin >> r;
    cout << 3 * r * r << endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string x,y,z;
    cin >> x >> y >> z;
    cout << "A" << y[0] << "C" << endl;

    return 0;
}

Measured memory_bytes: 3652
/**
 *      purpose : ABC 94 D
 *      author  : kyomukyomupurin
 *      created : 2018-10-30 14:53:07
**/

#include <bits/stdc++.h>
using namespace std;
#define int64 long long
#define print(x) cout << (x) << '\n'

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n; cin >> n;
    int a[n] = {};
    for (int i = 0; i < n; ++i) cin >> a[i];
    if (n == 2){
        cout << max(a[0], a[1]) << " " << min(a[0], a[1]) << '\n'; return 0;
    }
    sort(a, a + n);
    auto it = lower_bound(a, a + n, a[n - 1] / 2);

    if (*it == a[0]){
        cout << a[n - 1] << " " << *it << '\n'; return 0;
    }
    if (*it == a[n - 1]){
        cout << a[n - 1] << " " << *(it - 1) ; return 0;
    }

    if (*it - a[n - 1] / 2 <= a[n - 1] / 2 - *(it - 1)){
        cout << a[n - 1] << " " << *it << '\n';
    }
    else cout << a[n - 1] << " " << *(it - 1) << '\n';
    
    return 0;
}

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

int main() {
  long long a=1,b=0,c=0,d=0,m=0,n=0,p=0,q=0;
  
  cin >> n;
  vector<long long> v(n+1,0),ok(n+1,0);
  c=pow(10,13);
  for(int i=0;i<n+1;i++)
  {
	  cin >> v.at(i);
	  ok.at(i)=a;
	  a -= v.at(i);
	  a *= 2;
    a=min(a,c);
  }
  a=0;
  for(int i=n;i>=0;i--)
  {
	 a+=v.at(i);
     if(ok.at(i)<a)
	 {   
         a=ok.at(i);
		 if(a-v.at(i)<=0)
		 {
			 cout << "-1";
			 return 0;
		 }
		 
	 }		 
    b+=a;
  }
  cout << b;
	  
  
}


Measured memory_bytes: 4792
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;


class UnionFind{

private:
    vector<int> rank,p;

    void makeSet(int x){
      p[x] = x;
      rank[x] = 0;
    }

  public:
      UnionFind(){};
      UnionFind(int size){
        rank.resize(size,0);
        p.resize(size,0);
        for(int i = 0; i < size; i++){
          makeSet(i);
        }
      }

    bool same(int x, int y){
      return  find(x) == find(y);
    }

    void unite(int x, int y){
      link(find(x), find(y));
    }

    int find(int x){
      if(x != p[x]) p[x] = find(p[x]);
      return p[x];
    }

private:
    void link(int x, int y){
      if(rank[x] > rank[y]){
        p[y] = x;
      }else{
        p[x] = y;
        if(rank[x] == rank[y]) rank[y]++;
      }
    }

};


//ここから

struct edge{
    int from, to, cost;

    bool operator<(const edge& e) const {
        return cost < e.cost;
    }

};

/*
bool comp(const edge& e1, const edge& e2){
  return e1.cost < e2.cost;
}
*/
int kruskal(vector<edge> es, int v){

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

     UnionFind uf(v);

     int ret = 0;

     for(int i = 0 ; i < es.size() ; i++){

         edge e = es[i];

         if(!uf.same(e.from, e.to)){
             uf.unite(e.from, e.to);
             ret += e.cost;
         }

     }

     return ret;

}


int main(void) {
    int i,j;
    int n;
    int v,e;
    cin >> v >> e;

    vector<edge> g;

    rep(i,e){
        edge t;
        cin >> t.from >> t.to >> t.cost;
        g.push_back(t);
    }

    cout << kruskal(g,v) << endl;

}



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

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

Measured memory_bytes: 764
#include <stdio.h>

int a;
int b;
int c;

int main() {


	scanf("%d", &a);

	b = a % 7;

	bool o = false;

	for (; b <= a; b += 7) {
		if (b % 4 == 0) o = true;
	}

	if ( o ) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}



	return 0;

}

Measured memory_bytes: 128
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = Integer.parseInt(sc.next());
    int b = Integer.parseInt(sc.next());
    int c = Integer.parseInt(sc.next());
    int d = Integer.parseInt(sc.next());
    if (a*b >= c*d){
      System.out.println(a*b);
    }else{
      System.out.println(c*d);
    }
  }
}


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

int main(){
	
	int n,p; cin>>n>>p;
	string s; cin>>s;
	if(p==2||p==5){
		ll sum{};
		for(int i=0; i<n; i++){
			if((s.at(i)-'0')%p==0){
				sum += i+1;
			}
		}
		cout << sum << endl;
	}
	else{
		vector<ll> a(n+1);
		ll mul{1};
		for(int i=0; i<n; i++){
			a.at(i+1) = (a.at(i)+(s.at(n-i-1)-'0')*mul)%p;
			mul = mul*10%p;
		}
		map<int,ll> m;
		ll sum{};
		for(int i=0; i<n+1; i++){
			sum+=m[a.at(i)];
			m[a.at(i)]++;
		}
		cout << sum << endl;
	}
	
}


Measured memory_bytes: 2564
n = gets.to_i
i = 1

while (i <= n)
  x = i
  if x % 3 == 0
    printf(" %d", i)
    i += 1
    next
  end
  while x > 0
    if x % 10 == 3
      printf(" %d", i)
      break
    end
    x /= 10
  end
  i += 1
end
printf "\n"



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

double dp[3010][3010];

int main()
{
    int n; cin>>n;
    vector<double> p(n);
    for(auto& e: p) cin>>e;
    
    dp[0][0]=1.0;
    for(int i=1; i<=n; ++i) {
        for(int j=0; j<=i; ++j) {
            dp[i][j]=dp[i-1][j]*(1-p[i-1]);
            if (j>0) dp[i][j]+=dp[i-1][j-1]*p[i-1];
        }
    }
    auto res=0.0;
    for(int i=n/2+1; i<=n; ++i) res+=dp[n][i];
    printf("%.9f\n", res);
}


Measured memory_bytes: 69120
#include <iostream>
#include <vector>
#include <limits>

using namespace std;

int main() {
    int N; cin >> N;
    vector<int> digits_sum(N + 1, 0);
    for (int i = 1; i <= N; ++i)
        digits_sum[i] = i % 10 + digits_sum[i / 10];

    int smallest = numeric_limits<int>::max();
    for (int i = 1; i < N; ++i)
        smallest = min(smallest, digits_sum[i] + digits_sum[N - i]);

    cout << smallest << "\n";
}


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

#define PI acos(-1)
#define all(a) a.begin(), a.end()
#define full(a, n) a, a + n
#define ma(type, size) (type *)malloc(sizeof(type) * size)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define f0n(i, n) for (i = 0; i < (n); i++)
#define f1n(i, n) for (i = 1; i <= (n); i++)
#define fab(i, a, b) for (i = (a); i <= (b); i++)
#define fr(i, b, a) for (i = (b); i >= (a); i--)

using namespace std;

/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
	tree_order_statistics_node_update> indexed_set;
//*/
typedef long long int ll;
typedef long int lo;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;

typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tll;

//* utility function
inline bool compare(ll i, ll j)
{
    return i < j;
}
//*/

//* function prototypes
template< typename T>
T gcd(T a, T b);
//*/

//int row, column;
int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[8] = {0, -1, -1, -1, 0, 1, 1, 1};
ll p2[63] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944, 549755813888, 1099511627776, 2199023255552, 4398046511104, 8796093022208, 17592186044416, 35184372088832, 70368744177664, 140737488355328, 281474976710656, 562949953421312, 1125899906842624, 2251799813685248, 4503599627370496, 9007199254740992, 18014398509481984, 36028797018963968, 72057594037927936, 144115188075855872, 288230376151711744, 576460752303423488, 1152921504606846976, 2305843009213693952, 4611686018427387904};
#ifdef DEBUG
#endif // DEBUG

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

    ll number_of_test_case = 1, test_case;
    //cin >> number_of_test_case;
    for (test_case = 1; test_case <= number_of_test_case; test_case++)
    {
        ll i, n = 3;
        ll arr[n];
        cin >> arr[0] >> arr[1] >> arr[2];

        sort(arr, arr+n);

        ll cost = 0;
        f1n(i, n-1)cost += abs(arr[i] - arr[i-1]);

        cout << cost << endl;

    }
    return 0;
}
template< typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a%b);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    
    int a,b,c;
    scanf("%d %d %d", &a,&b,&c);
    if(a<b && a<c && b<c){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    
    return 0;
}


Measured memory_bytes: 2624
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

const int MOD = 1000000007;
typedef long long ll;

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

  int N;
  cin>>N;
  int ans=N;
  vector<ll> A(N),B(N),D(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  for(int i=0;i<N;i++){
    cin>>B[i];
    D[i]=A[i]-B[i];
  }
  sort(D.begin(),D.end());
  decltype(D)::iterator it = lower_bound(D.begin(),D.end(),0);
  // for(int i=0;i<N;i++){
  //   cout<<i<<':'<<D[i]<<endl;
  // }
  ll sumA = accumulate(A.begin(),A.end(),0LL);
  ll sumB = accumulate(B.begin(),B.end(),0LL);
  ll diff = sumA-sumB;
  ll tmp = 0LL;
  int zero = distance(D.begin(),it);
  // cout<<zero<<endl;
  if(sumA<sumB){
    ans=-1;
  }else{
    for(int i=zero;i<N;i++){
      tmp+=D[i];
      if(tmp>diff)break;
      ans-=1;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 2560
from itertools import permutations

n = int(input())
town = []
for i in range(n) :
    town.append(list(map(int, input().split())))

all = list(permutations(town,n))

#print(all)

sum = 0
for i in range(len(all)) :
    for j in range(1, len(all[i])) :
        x = (all[i][j][0] - all[i][j-1][0]) ** 2
        y = (all[i][j][1] - all[i][j-1][1]) ** 2
        sum += (x+y) ** 0.5
        #print(all[i][j], (x+y) ** 0.5)

print(sum/len(all))


Measured memory_bytes: 8052
#include<stdio.h>
int main(){
  int a , b;
  scanf("%d %d",&a,&b);
  if(a < b){
    printf("a < b\n");
  }else if(a > b){
    printf("a > b\n");
  }else if(a==b){
    printf("a == b\n");
    
  }
   return 0;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int ans = 0;
    int l, r;
    rep(i, 0, N) {
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
    return 0;
}

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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)

int main(void){
  long d,n;
  cin>>d>>n;
  long a=1;
  r(i,d){
    a=a*100;
  }
  long ans;
  if(n==100)ans=a*(n+1);
  else ans =a*n;
  cout<<ans<<endl;



return 0;}


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

int main() {
  int N, M, X, Y, x, y;
  cin >> N >> M >> X >> Y;
  
  int war = 0;
  
  int Z = -101;
  for(int i=0; i<N; i++) {
    cin >> x;
    if(Z<x) {
      Z = x;
    }
  }
  
  if(Z<X) {
      Z = X;
  }
    
  for(int i=0; i<M; i++) {
    cin >> y;
    if(y<=Z) {
      war = 1;
      break;
    }
  }
  
  if(Y<=Z) {
    war = 1;
  }
  
  if(war==1) {
    cout << "War" << endl;
  } else {
    cout << "No War" << endl;
  }
  
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a,b,c[251],n;

  scanf("%d",&n);

  for(a = 1; a <= n; a++){
    scanf("%d",&c[a]);
  }

  for(a = 1; a <= n; a++){
    printf("node %d: key = %d, ",a,c[a]);
    if(a != 1){
      printf("parent key = %d, ",c[a/2]);
    }
    if(2*a <= n){
      printf("left key = %d, ",c[2*a]);
    }
    if(2*a+1 <= n){
      printf("right key = %d, ",c[2*a+1]);
    }
      printf("\n");
  }
    return 0;
 }



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

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define all(x) begin(x),end(x)

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

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld EPS = 1e-9;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    const int MAX = 1e6;
    vi prime(MAX, 1);
    prime[0] = prime[1] = 0;
    for (int i = 2; i * i < MAX; ++i) {
        if (!prime[i]) continue;
        for (int j = 2*i; j < MAX; j += i) {
            prime[j] = 0;
        }
    }

    for (;;) {
        int N, P; cin >> N >> P;
        if (N == -1) break;
        vi primes;
        for (int i = N+1; i < MAX; ++i) {
            if (prime[i]) primes.push_back(i);
        }
        vi sum;
        REP(i, min(P, SZ(primes))) {
            FOR(j, i, min(P, SZ(primes))) {
                sum.push_back(primes[i] + primes[j]);
            }
        }
        sort(all(sum));
        cout << sum[P-1] << endl;
    }

    return 0;
}



Measured memory_bytes: 7612
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

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

int main(){
    int x,y,z;
    cin >> x >> y >> z;
    int n = x+y+z;
    vector<ll> a(n),b(n),c(n);
    rep(i,n)cin >> a[i] >> b[i] >> c[i];
    ll sm = 0;
    rep(i,n)sm += c[i];
    vector<pair<ll,pair<ll,ll> > >zz;
    vector<ll> p(n),q(n);
    rep(i,n){
        zz.PB(MP(b[i]-a[i],MP(a[i]-c[i],b[i]-c[i])));
    }
    sort(all(zz));
    rep(i,n){
        p[i] = zz[i].second.first;
        q[i] = zz[i].second.second;
    }
    vector<ll> resp(n),resq(n);
    priority_queue<ll,vector<ll>,greater<ll> > pq;
    ll sp = 0;
    rep(i,n){
        sp += p[i];
        pq.push(p[i]);
        while(pq.size()>x){
            ll k = pq.top();
            pq.pop();
            sp -= k;
        }
        resp[i] = sp;
    }
    while(!pq.empty())pq.pop();
    ll sq = 0;
    for(int i=n-1;i>=0;i--){
        sq += q[i];
        pq.push(q[i]);
        while(pq.size()>y){
            ll k = pq.top();
            pq.pop();
            sq -= k;
        }
        resq[i] = sq;
    }
    ll mx = -(1LL<<60);
    for(int i=x-1;i<n-y;i++){
        chmax(mx,resp[i] + resq[i+1]);
    }
    // cerr << sm << " " << mx << endl;
    cout << sm + mx << endl;
    return 0;
}

Measured memory_bytes: 10224
extension Optional {
    func puts(){
        print(self!)
    }
}

readLine().map { line -> Int in 
    let l = line.split(separator: " ").compactMap { Int($0) }
    let (a, b, c, d) = (l[0], l[1], l[2], l[3])
    let left = max(a, c)
    let right = min(b, d)

    return max(0, right - left)
}.puts()

Measured memory_bytes: 8320
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        System.out.println(c + " " + a + " " + b );
    }
}

Measured memory_bytes: 26948
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int n, m, x; cin >> n >> m >> x;
    vector<int> C(n);
    vector<vector<int>> A(n, vector<int>(m));
    for(int i = 0; i < n; i++)
    {
        cin >> C[i];
        for(int j = 0; j < m; j++) cin >> A[i][j];
    }

    int ans = INF;
    for(int bit = 0; bit < (1<<n); bit++)
    {
        vector<int> v;
        vector<int> score(m, 0);
        for(int i = 0; i < n; i++)
        {
            if(bit & (1<<i))
            {
                v.push_back(i);
            }
        }
        int sum = 0;
        for(int i = 0; i < v.size(); i++)
        {
            for(int j = 0; j < m; j++)
            {
                score[j] += A[v[i]][j];
            }
            sum += C[v[i]];
        }
        bool ok = true;
        for(int i = 0; i < score.size(); i++)
        {
            if(score[i] < x) ok = false;
        }
        if(ok)
        {
            ans = min(ans, sum);
        }
    }
    if(ans == INF)
    {
        cout << -1 << endl;
        return;
    }
    cout << ans << endl;
}

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

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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

int w[maxn], v[maxn];
ll dp[maxn];

int main() {
    int n, W;
    scanf("%d%d", &n, &W);
    for (int i = 1; i <= n; i++) scanf("%d%d", &w[i], &v[i]);

    for (int i = 1; i <= n; i++) {
        for (int j = W; j >= w[i]; j--) {
            dp[j] = max(dp[j], dp[j - w[i]] + 1ll * v[i]);
        }
    }

    printf("%lld\n", dp[W]);
	return 0;
}


Measured memory_bytes: 5120
#include<iostream>
#include<vector>
using namespace std;
 
int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vector<vector<int>> a(n, vector<int>(m));
    vector<int> c(n);
    for(int i = 0; i < n; i++){
        cin >> c[i];
        for(int j = 0; j < m; j++)cin >> a[i][j];
    }
    int ans = 12345678;
    int all = 1<<n;
    for(int mask = 0; mask < all; mask++){
        vector<int> level(m);
        int cost = 0;
        for(int i = 0; i < n; i++){
            if((mask>>i)&1){
                cost += c[i];
                for(int j = 0; j < m; j++){
                    level[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        for(int j = 0; j < m; j++){
            if(level[j] < x) ok = false;
        }
        if(ok) ans = min(ans,cost);
    }
    if(ans == 12345678) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 3520
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

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


def solve():
    n, k = rl()
    A = rl()
    # leaps = [A]
    # leap_size = 2
    # while leap_size <= k:
        # new_leap = []
        # for i in range(n):
    curr = 1
    seen = {1:0}

    for i in range(1, k + 1):
        curr = A[curr - 1]
        if i == k:
            print (curr)
            return
        elif curr in seen:
            break
        seen[curr] = i

    cycle_len = i - seen[curr]
    # print (cycle_len)

    while 1:
        if i % cycle_len == k % cycle_len:
            print (curr)
            return
        i += 1
        curr = A[curr - 1]






mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()


Measured memory_bytes: 105128
# C
# Many Requirements
import itertools

N, M, Q = map(int, input().split())
tmp_ = list(range(1,M+1))
A_tensor = itertools.combinations_with_replacement(tmp_,N)
S_list = []

for i in range(Q):
    S_list.append(list(map(int, input().split())))

ans = 0

for _list in A_tensor:
    tmp_score = 0
    for j in range(Q):
        if _list[S_list[j][1]-1] - _list[S_list[j][0]-1] == S_list[j][2]:
            tmp_score += S_list[j][3]
    if tmp_score > ans:
        ans = tmp_score

print(ans)

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

int main(){
  int R;

  cin >>R;
  if(R < 1200){
    cout <<"ABC"<<endl;
  }
  else if(1200 <= R && R < 2800){
    cout <<"ARC"<<endl;
  }
  else if(2800 <= R){
    cout <<"AGC"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


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

	string s;
	cin >> s;
	cout << s.substr(0, 4) << ' ' << s.substr(4) << endl;

	return 0;
}

Measured memory_bytes: 256
main = do
  n <- readLn
  putStrLn $ show n ++ ": " ++ unwords (fmap show $ primeFactor n)

factors :: Int -> [Int]
factors n = [d | d <- [1..n], n `mod` d == 0]

isPrime :: Int -> Bool
isPrime x =
  null [y | y <- [2..floor $ sqrt $ fromIntegral x], x `mod` y == 0]

primeFactor :: Int -> [Int]
primeFactor n
  | isPrime n = [n]
  | otherwise = reverse $ go [] n
  where
    go res 1 = res
    go res n = go (d : res) (n `div` d)
      where d = factors n !! 1

Measured memory_bytes: 4176
//It doesn't matter how slow you go, Unless you don't stop.
#include <iostream>
#include <algorithm>
#include <bitset>

#include <cmath>
#include <cstring>
#include <climits>

#include <deque>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

#include <fstream>
#include <chrono>
using namespace std;

typedef long long LL;
typedef pair<LL, LL> p64;
typedef vector<LL> v64;
typedef map<LL, LL> mp64;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i, s, e) for (long long i = s; i <= e; i++)
#define brep(i, s, e) for (long long i = s; i >= e; i--)
#define all(x) x.begin(), x.end()
#define mem(x, y) memset(x, y, sizeof(x))
#define DANGER                        \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
const LL MOD2 = 1e9 + 7;
LL power(LL x, LL y, LL p)  
{  
    LL res = 1;  
  
    x = x % p;
   
    if (x == 0) return 0;
  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  

        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}
void solve()
{
    int n;
    cin >> n;
    if (n == 1)
    {
        cout << "0" << endl;
        return;
    }
    if (n == 2)
    {
        cout << "2" << endl;
        return;
    }
    LL a = power(10, n, MOD2);
    a -= ((power(9, n, MOD2) * 2ll) % MOD2);
    a += power(8, n, MOD2)  % MOD2;
    if (a < 0) a += MOD2;

     

    cout << a << endl;
}

int main()
{
    DANGER;
    ofstream out("output.txt");

    auto start = chrono::high_resolution_clock::now();

    LL t = 1;
    // cin>>t;
    rep(test, 1, t)
    {
        solve();
    }

    auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
    // cout << "Time taken by function: " << duration.count() << " milliseconds" << endl;
}

Measured memory_bytes: 3652
#include<stdio.h>
#include<stdlib.h>
int asc(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
int main()
{
    int n;
    scanf("%d", &n);
    int i, j;
    int a[100005];
    for (i = 0; i < n; i++)
        scanf("%d", &a[i]);
    qsort(a, n, sizeof(int), asc);
    int ans = 0, q;
    i = 0;
    while (i < n)
    {
        q = 0;
        j = i;
        while (a[j] - a[i] < 3 && j < n)
        {
            q++;
            j++;
        }
        if (ans < q)
            ans = q;
        i++;
        while (i < n && a[i] == a[i - 1])
            i++;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 892