akhauriyash/Code-Regression huggingface dataset:
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

eriminate_enemy = [0 for _ in range(N+1)]

for index, B in enumerate(Bs):
    if(B <= As[index]):
        eriminate_enemy[index] += B
        continue

    eriminate_enemy[index] += As[index]
    
    if(B <= As[index] + As[index + 1]):
        eriminate_enemy[index + 1] += B - As[index]
        As[index+1] -= eriminate_enemy[index + 1]
    
    else:
        eriminate_enemy[index + 1] += As[index+1] 
        As[index+1] = 0

print(sum(eriminate_enemy))



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

int main() {
    int r, d, x2000;
    cin >> r >> d >> x2000;
    vector<int> x(11);
    x.at(0) = x2000;
    for (int i = 1; i <= 10; i++)
    {
        x.at(i) = r * x.at(i - 1) - d;
    }
    for (int i = 1; i <= 10; i++)
    {
        cout << x.at(i) << endl;
    }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
typedef long long ll;
 
int main() {
  ll a,b,c;
  char d,e;
  cin>>a>>d>>b>>e>>c;
  cout<<(b<=4 ? "Heisei":"TBD");
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a*a+b*b==c*c)
        cout<<a*b/2;
    else if(a*a+c*c==b*b)
        cout<<a*c/2;
    else
        cout<<c*b/2;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]", b: "List[int]"):
    G = [[] for _ in range(N)]
    for i in range(N-1):
        G[a[i]-1].append(b[i]-1)
        G[b[i]-1].append(a[i]-1)
    T = dict()
    for i in range(N-1):
        T[(a[i]-1, b[i]-1)] = i
        T[(b[i]-1, a[i]-1)] = i
    q = [0]
    cn = max([len(g) for g in G])
    visited = [False] * N
    C = [0] * (N-1)
    while len(q) > 0:
        p = q.pop()
        visited[p] = True
        adj = G[p]
        v = None
        for a in adj:
            if visited[a]:
                v = a
        if v != None:
            ex = C[T[(v, p)]]
        else:
            ex = -1
        counter = 1
        for a in adj:
            if counter == ex:
                counter += 1
            if a != v:
                j = T[(a, p)]
                C[j] = counter
                counter += 1
        for a in adj:
            if not visited[a]:
                q.append(a)
    print(cn)
    for c in C:
        print(c)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N - 1)  # type: "List[int]"
    b = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 72560
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807
#define llMIN -9223372036854775808
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n >> k;
  vi p(n),b(n);
  REP(i,n) cin>>p[i];
  ll smm=0,maxno=0,maxsm=0;
  REP(i,k){
    smm+=p[i];
  }
  maxsm=smm;

  for(ll i=k;i<n;i++){
    smm=smm-p[i-k]+p[i];
    if (maxsm<smm){
      maxsm=smm;
      maxno=i-k+1;
    }
  }


  for(ll i=0;i<k;i++){
    ans+=p[i+maxno]+1;
  }

  cout<<setprecision(16)<<((double)ans/(double)(2))<<endl;
  //小数点表記

  
  return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>

int thw(int,int);
void chng(char*,int*,int,int);

int thw(int s,int b)
{
    for(int i=1;i<s;i++) b = b * 10;
   //printf("b=%d\n",b);
    return b;
}

void chng(char *box,int *A,int s,int cnt)
{
    int tmp,bt=0;
    for(int i=s-1;i>=0;i--)
    {
        tmp = box[i]-'0';
        //printf("boxは？=%d,thwけっか%d\n",box[i],thw(s-i,tmp));
        bt += thw(s-i,tmp);
       // printf("bt=%d\n",bt);
    }
    A[cnt] = bt;
   // printf("box=%c,Acnt=%d,s=%d,cnt=%d\n\n",box[0],A[cnt],s,cnt);
}

int main()
{
    char box[10],tmp;
    int A[101],s=0,cnt=0,flg=0;
    while((tmp = getchar()) != EOF)
    {
        //printf("tmpの中＝%c\n",tmp);
        if('0' <= tmp && tmp <= '9'){
            //printf("a\n");
            box[s] = tmp;
            s += 1;
            flg=0;
        }else {
            //printf("tmp数%d,+数%d\n",tmp,'+');
            //printf("check1 \n");
            switch(tmp){
                case '+':
           // printf("check2 \n");
                    cnt -=1;
                    //printf("Acnt=%dAcnt+1=%d\n",A[cnt-1],A[cnt]);
                    A[cnt-1]=A[cnt-1]+A[cnt];
                    //printf("計算結果=%d\n",A[cnt-1]);
                    //printf("cntの数=%d\n",cnt);
                    flg = 1;
                    break;
                case '-':
            //printf("check3 \n");
                    cnt -=1;
                    //printf("Acnt=%dAcnt+1=%d\n",A[cnt-1],A[cnt]);
                    A[cnt-1]=A[cnt-1]-A[cnt];
                    //printf("計算結果=%d\n",A[cnt]);
                    //printf("cntの数=%d\n",cnt);
                    flg = 1;
                    break;
                case '*':
            //printf("check4 \n");
                    cnt -=1;
                    //printf("Acnt=%dAcnt+1=%d\n",A[cnt-1],A[cnt]);
                     A[cnt-1]=A[cnt-1]*A[cnt];
                    ///printf("計算結果=%d\n",A[cnt+1]);
                    //printf("cntの数=%d\n",cnt);
                    flg = 1;
                    break;
                case '/':
            //printf("check5 \n");
                    cnt -=1;
                   // printf("Acnt=%dAcnt+1=%d\n",A[cnt-1],A[cnt]);
                     A[cnt-1]=A[cnt-1]/A[cnt];
                    //printf("計算結果=%d\n",A[cnt-1]);
                    //printf("cntの数=%d\n",cnt);
                    flg = 1;
                    break;
                default :
                if(flg == 0){
            //printf("check default\n");
                    chng(box,A,s,cnt);
                    break;
                }
            }
            if(flg == 0)    cnt +=1;//printf("flg通過\n");}            //printf("cnt chk2=%d\n",cnt);
            s = 0;
            }
        }
    printf("%d\n",A[0]);
}


Measured memory_bytes: 2148
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static Reader;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var n = NextInt;
        var m = NextInt;


        Console.WriteLine(string.Join("", Enumerable.Repeat(Min(n, m), Max(n, m))));
    }
}


static class Reader
{
    const int BUF_SIZE = 1 << 12;
    static Stream Stream = Console.OpenStandardInput();
    static byte[] Buffer = new byte[BUF_SIZE];
    static int ptr = BUF_SIZE - 1;
    static void Move() { if (++ptr >= Buffer.Length) { Stream.Read(Buffer, 0, BUF_SIZE); ptr = 0; } }


    public static int NextInt
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get
        {
            int res = 0; while (Buffer[ptr] < 48) Move();
            do { res = res * 10 + (int)(Buffer[ptr] ^ 48); Move(); } while (48 <= Buffer[ptr]);
            return res;
        }
    }
}


Measured memory_bytes: 11220
#define MOD_TYPE 1

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using multiInt = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
*/
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
//constexpr ll MOD = 1;
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr double PI = acos(-1.0);
constexpr double EPS = 1e-10;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
template <typename T, typename U>
constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept
{
  os << p.first << " " << p.second;
  return os;
}
#pragma endregion

void solve()
{
  string s;
  cin >> s;
  for (auto &&c : s)
  {
    if (c == '?')
      c = 'D';
  }
  cout << s << "\n";
}

int main()
{
  init_main();

  solve();

  return 0;
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n;
  cin >> n;
  vi a;
  rep(i, n) {
    int b, c;
    cin >> b >> c;
    a.push_back(b);
    if(i == n - 1) a.push_back(c);
  }
  vector<vi> dp(n + 1, vi(n + 1, 1e9));
  rep(w, n + 1) {
    rep(l, n + 1 - w) {
      int r = l + w;
      if(w <= 1)
        dp[l][r] = 0;
      else if(w == 2)
        dp[l][r] = a[l] * a[l + 1] * a[r];
      else
        rep2(k, l + 1, r) dp[l][r] =
            min(dp[l][r], dp[l][k] + dp[k][r] + a[l] * a[k] * a[r]);
    }
  }
  cout << dp[0][n] << endl;
}


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

class D
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());

		var ps = new List<int>();
		for (int i = 2; i <= n; i++) if (ps.All(p => i % p != 0)) ps.Add(i);

		var powers = ps.ToDictionary(p => p, p => 1);
		foreach (var p in ps)
			for (int i = 1; i <= n; i++)
			{
				var t = i;
				while (t % p == 0)
				{
					t /= p;
					powers[p]++;
				}
			}

		Func<int, int> countGeq = v => powers.Count(x => x.Value >= v);
		var r = countGeq(75) +
			countGeq(25) * (countGeq(3) - 1) +
			countGeq(15) * (countGeq(5) - 1) +
			countGeq(5) * (countGeq(5) - 1) / 2 * (countGeq(3) - 2);
		Console.WriteLine(r);
	}
}


Measured memory_bytes: 13396
#include <iostream>
#include <algorithm>
#include <vector>

int main() {
    int N;
    std::cin >> N;
    std::vector<int> v(N);
    for (auto& e : v) std::cin >> e;

    v.erase(std::unique(v.begin(), v.end()), v.end());

    for (int i = 0; i < v.size(); ++i) {
        std::cout << v[i] << " \n"[i == v.size() - 1];
    }
}


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

int main(){
    int N; cin >> N;
    vector<int> V(N), C(N);
    for(int i = 0; i < N; i++){
        cin >> V[i];
    }
    for(int i = 0; i < N; i++){
        cin >> C[i];
    }

    int ans = 0;
    for(int i = 0;i < N; i++){
        int sub = V[i] - C[i];
        if(sub > 0) ans += sub;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#B
n = int(input())
l = [] 
for i in range(n):
    s, p = input().split()
    l.append([i+1, s, int(p)])
ans = sorted(l, key= lambda x:x[2], reverse=True)
ans = sorted(ans, key= lambda x:x[1])
for i in range(n):
    print(ans[i][0])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

Int n;
vector<Int> d;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	d.resize(n);
	for(auto &i:d) cin >> i;
	sort(d.begin(), d.end());
	cout << d[n/2] - d[n/2-1] << "\n";
}

Measured memory_bytes: 1024
import heapq
import sys
input = sys.stdin.readline

INF = 10 ** 18

class Edge():
    def __init__(self, end, cost, time):
        self.end = end
        self.cost = cost
        self.time = time

dp = []
h = []

def push(t, v, x):
    if x < 0:
        return
    if dp[v][x] <= t:
        return
    dp[v][x] = t
    heapq.heappush(h, (t, v, x))

def dijkstra(n, G, cd, start, s, max_s):
    global dp
    dp = [[INF for j in range(max_s+1)] for i in range(n)] 
    push(0, start, s)

    while h:
        # 使っていない頂点のうち、現時点で最も距離の近いものを選びvとする
        t, v, x = heapq.heappop(h)
        if dp[v][x] < t:
            continue
        # 両替
        if x < max_s:
            push(t+cd[v][1], v, min(x+cd[v][0], max_s))

        # vから到達可能な頂点について、距離が短くなれば更新
        for e in G[v]:
            push(t+e.time, e.end, x-e.cost)


n, m, s = map(int, input().split())
uvab = [list(map(int, input().split())) for _ in range(m)]
cd = [list(map(int, input().split())) for _ in range(n)]

es = [[] for i in range(n)]
max_s = 50 * (n-1)

for u, v, a, b in uvab:
    es[u-1].append(Edge(v-1,a,b))
    es[v-1].append(Edge(u-1,a,b))

dijkstra(n, es, cd, 0, min(max_s,s), max_s)

for i in range(1, n):
    print(min(dp[i]))


    

Measured memory_bytes: 23948
#include <iostream>
#include <vector>

using namespace std;

void printV(vector<int> a){
    for(int i=0;i<a.size();i++){
        cout << a[i] << endl;
    }
}

int finder(vector<int> a,int t){
    for(int i=0;i<a.size();i++){
        if(a[i] == t)return 0;
    }
    return 1;
}

int main(void){
    int a,b,k,flag=0;
    vector<int> ans;
    cin >> a >> b >> k;
    if(b-a <= k){
        flag = 1;
        k = b-a+1;
    }
    for(int i=a;i<a+k;i++){
        ans.push_back(i);
    }
    if(!flag){
        for(int i=b-k+1;i<=b;i++){
            if(finder(ans,i))ans.push_back(i);
        }
    }
    printV(ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <cassert>
#include <complex>
#include <iomanip>
#include <random>

using namespace std;

typedef long long ll;
#define int long long

int M = (int)1e9 + 7;
#define msum(a, b) ((a) + (b) >= M ? (a) + (b) - M : (a) + (b))
#define msub(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define mmult(a, b) (((a) * (b)) % M)

typedef long double ld;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vlll;
typedef vector<double> vd;
typedef vector<vd> vdd;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpi;
#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SZ(a) ((int)(a).size())
#define watch(x) cout << (#x) << " = " << (x) << endl;

const double PI = 2 * acos(0.0);
const int oo = 1e18 + 100;
const string DIGITS = "0123456789", alph = "abcdefghijklmnopqrstuvwxyz", ALPH = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

//THE END OF TEMPLATE////////////////////////////////////////////////////////////////////////////////

#define N 100100


int dp[200][N];



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

	
	dp[0][0] = 1;

	int n, k;
	cin >> n >> k;
	vi a(n + 1), pref(k + 1);
	for (int i = 1; i <= n; i++)
		cin >> a[i];

	for (int i = 1; i <= n; i++)
	{
		pref[0] = dp[i - 1][0];
		dp[i][0] = pref[0];
		for (int j = 1; j <= k; j++)
		{
			pref[j] = msum(pref[j - 1], dp[i - 1][j]);
			if (j - a[i] <= 0)
				dp[i][j] = pref[j];
			else
				dp[i][j] = msub(pref[j], pref[j - a[i] - 1]);
		}
	}

	cout << dp[n][k];

}

//m1.codeforces.com, m2.codeforces.com или m3.codeforces.com

Measured memory_bytes: 80128
n,c = map(int,input().split())

l = [[] for i in range(c)]
for i in range(n):
    s,t,x = map(int,input().split())
    l[x-1].append([s,t])

al= []
for i in range(c):
    if len(l[i]) > 1:
        l[i].sort()
        now2 = l[i][0][1]
        now1 = l[i][0][0]
        check = False
        for j in range(1,len(l[i])):
            if l[i][j][0] == now2:
                now2 = l[i][j][1]
            else:
                al.append([[now1,now2],i])
                check = True
                now1 = l[i][j][0]
                now2 = l[i][j][1]
        if not check:
            al.append([[now1,now2],i])

    else: 
        if l[i]:
            al.append([l[i][0],i])
al.sort()

count = [[-1,-1]]
for i in range(len(al)):
    a,b,c = al[i][0][0], al[i][0][1],al[i][1]
    check = False
    for j in range(len(count)):
        if count[j][0] < a:
            count[j] = [b,c]
            check = True
            break
    if not check:
        count.append([b,c])

print(len(count))


Measured memory_bytes: 39844
#include<stdio.h>
int main(){
  int w,h,d[51][51],m[51][51],i,j,x,y;
  char c;
  scanf("%d %d",&h,&w);
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      scanf(" %c",&c);
      m[i][j]=c-'0';
      d[i][j]=2000000000;
    }
  }//printf("a\n");
  d[0][0]=0;
  for(i=0;i<w+h-1;i++){
    for(j=0;j<h;j++){
      y=j;
      x=i-j;
      if(y<0||h<=y||x<0||w<=x)continue;
      if(d[y][x+1]>d[y][x]+m[y][x+1])d[y][x+1]=d[y][x]+m[y][x+1];
      if(d[y+1][x]>d[y][x]+m[y+1][x])d[y+1][x]=d[y][x]+m[y+1][x];
    }
  }
  printf("%d\n",d[h-1][w-1]);
  return 0;
}

Measured memory_bytes: 616
def fact(a, mod):
    ret = 1
    for i in range(a):
        ret *= (i + 1)
        ret %= mod
    return ret


def main():
    MOD = 10**9 + 7
    N, M = list(map(int, input().split(' ')))
    if abs(N - M) > 1:
        print(0)
    elif abs(N - M) == 0:
        print((2 * fact(N, MOD) * fact(M, MOD)) % MOD)
    else:
        print((fact(N, MOD) * fact(M, MOD)) % MOD)


if __name__ == '__main__':
    main()

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

using namespace std;

int main(){
	int n;
	cin>>n;
	map<string,int> mp;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		mp[s]++;
	}
	set<pair<int,string> > st;
	for(auto x:mp){
		st.insert({x.second,x.first});
	}
	int v=st.rbegin()->first;
	for(auto it=st.begin();it!=st.end();it++){
		if(v==it->first)
			cout<<it->second<<"\n";
	}
}


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

ll n;
ll v[100000];
ll DP[100000];

ll backtrack(ll pos) {

	// cout<<pos<<" ";
	if(pos >= n) return 0LL;

	if(DP[pos] != -1) return DP[pos];

	ll answer = 0LL, a = INT_MAX, b = INT_MAX;

	if(pos+1 < n) a =  abs(v[pos] - v[pos+1]) + backtrack(pos+1);
	if(pos+2 < n) b =  abs(v[pos] - v[pos+2]) + backtrack(pos+2);
	if(a != INT_MAX || b != INT_MAX) answer = min(a, b);

	return DP[pos] = answer;
}

int main() {
		
	cin>>n;
	for (ll i = 0; i < n; i++) cin>>v[i];
	memset(DP, -1, sizeof(DP));

	cout<<backtrack(0);

	return 0;
}

Measured memory_bytes: 6528
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
T chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int a = rint, b = rint, c = rint;
	if(a + b + c  >= 22) "bust".writeln;
	else "win".writeln;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 1e9 + 7;

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

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

  vector<bool> a(n + 1, true);
  rep(i, 0, m) {
    int x;
    cin >> x;
    a[x] = false;
  }

  vector<int> ans(n + 1);
  ans[0] = 1, ans[1] = 1;
  if (!a[1]) ans[1] = 0;

  rep(i, 2, n + 1) {
    if (a[i])
      ans[i] = (ans[i - 1] + ans[i - 2]) % MOD;
    else
      ans[i] = 0;
  }
  cout << ans[n] << endl;
}


Measured memory_bytes: 640
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <cassert>

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////

const int mod = 1000000007;

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

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

    int N;
    cin >> N;

    int zeros = 0;

    int zerob = 0;
    int zeroa = 0;

    map<pair<int64, int64>, int> cnt;

    for (int i = 0; i < N; i++) {
        int64 A, B;
        cin >> A >> B;
    
        if (!A && !B) {
            zeros++;
        } else if (!B) {
            zerob++;
        } else if (!A) {
            zeroa++;
        } else {
            int64 g = gcd(abs(A), abs(B));
            A /= g;
            B /= g;

            if (A < 0) {
                A *= -1;
                B *= -1;
            }

            //cerr << "add: " << A << "/" << B << "\n";
            cnt[{A, B}]++;
        }
    }


    vector<int64> pow2(N + 1);
    pow2[0] = 1;
    for (int i = 1; i <= N; i++)
        pow2[i] = (pow2[i - 1] * 2) % mod;

    int64 res = 1;

    int64 zero_tot = (pow2[zeroa] + pow2[zerob] + mod - 1) % mod;

    res *= zero_tot;
    res %= mod;

    map<pair<int64, int64>, bool> used;

    for (auto entry : cnt) {
        int64 A, B;
        tie (A, B) = entry.first;

        if (B > 0) {
            int64 tot = pow2[entry.second];
            int64 X = -B;
            int64 Y = A;

            int64 g = gcd(abs(X), abs(Y));
            X /= g;
            Y /= g;
            if (X < 0) {
                X *= -1;
                Y *= -1;
            }

            if (cnt[{X, Y}]) {
                int64 v2 = pow2[cnt[{X, Y}]];

                tot += v2 - 1 + mod;
                tot %= mod;

                //cerr << entry.second << " : " << cnt[{X, Y}] << "\n";
                //cerr << A << "/" << B << " = " << X << "/" << Y << " = " << tot << "\n";

                res *= tot;
                res %= mod;

                used[{A, B}] = used[{X, Y}] = true;
            }
        }
    }

    int64 rem = 0;
    for (auto entry : cnt) {
        if (!used[entry.first]) {
            rem += entry.second;
        }
    }

    res *= pow2[rem];
    res %= mod;

    // Can take exactly one of zeros
    res += zeros;

    // Remove empty set
    res += (mod - 1);

    res %= mod;

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 42168
#include <iostream>
#include <stack>
#include <map>
#include <queue>
#include <string>
#include <sstream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
using namespace std;
string s;
bool f=0;
char op[5];
void bb(int i,int sum)
{
    if(i==5) return;
    if(sum==7&&i==4) f=1;
    op[i]='+';
    bb(i+1,sum+(s[i]-'0'));
    if(f) return;
    op[i]='-';
    bb(i+1,sum-(s[i]-'0'));
}
int main()
{
    cin>>s;
    bb(1,s[0]-'0');
    for(int i=0;i<4;i++)
    {
        if(i==0) cout<<s[0];
        else cout<<op[i]<<s[i];
    }
    cout<<"=7";
    return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  ttt
//
//  Created by ??§?£? ??? on 2015/04/23.
//  Copyright (c) 2015??´ ??§?£? ???. All rights reserved.
//

#include <iostream>
using namespace std;

int main(int argc, const char * argv[]) {
    int n;
    while(cin >> n,n!=0){
    int max;
    int min=1005;
    int sum = 0;
    max = 0;
    int x;
    for(int i = 0;i < n;i = i+1){
        cin >> x;
        sum = sum + x;
        if(x > max){
            max = x;}
        if(x<min)
            min = x;
    }
        cout << (sum-min-max)/(n-2)<< endl;}
    return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

vector<vector<int>> edges;

// return -1 if loop is not found
int find_loop(int cur, vector<bool> &visited, int &cnt, const int N) {
    // printf("cur: %d\n", cur);
    if (visited[cur]) {
        return cur;
    }
    visited[cur] = true;
    for (auto next : edges[cur]) {
        cnt++;
        int ans = find_loop(next, visited, cnt, N);
        if (ans != -1) {
            return ans;
        }
    }
    return -1;
}

void find_towns_in_loop(int cur, vector<bool> &visited, vector<int> &acc, const int N) {
    if (visited[cur]) {
        return;
    }
    acc.push_back(cur);
    visited[cur] = true;
    find_towns_in_loop(edges[cur][0], visited, acc, N);
}

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

    edges.resize(N);
    for (int i = 0; i < N; i++) {
        int t;
        cin >> t;
        t--;
        // printf("%d -> %d\n", i, t);
        edges[i].push_back(t);
    }

    int cnt_till_loop = 0;
    int loop_start;
    {
        vector<bool> visited(N, false);
        loop_start = find_loop(0, visited, cnt_till_loop, N);
    }
    assert(loop_start >= 0);

    if (K >= cnt_till_loop) {
        K -= cnt_till_loop;
    } else {
        loop_start = 0;
    }

    // printf("loop_start: %d, cnt_till_loop: %d\n", loop_start, cnt_till_loop);

    vector<int> towns_in_loop;
    {
        vector<bool> visited(N, false);
        find_towns_in_loop(loop_start, visited, towns_in_loop, N);
    }

    // for (auto v : towns_in_loop) {
    //     cout << v << " ";
    // }
    // cout << endl;

    K = K % ((ll) towns_in_loop.size());

    cout << towns_in_loop[K] + 1 << endl;

    return 0;
}


Measured memory_bytes: 24392
n = int(input())
a = [int(x) for x in input().split()]

sm_e = []
sm_o = []

e = 0
o = 0

for i in range(n):
    if i % 2 == 0:
        e += a[i]
        sm_e.append(e)
    else:
        o += a[i]
        sm_o.append(o)

tot_e = sm_e[-1]
tot_o = sm_o[-1]

m = len(sm_o)

if n % 2 == 0:
    ans = max(tot_e, tot_o)
    for i in range(m):
        ans = max(ans, sm_e[i] + tot_o - sm_o[i])
    # for i in range(m-1):
    #     ans = max(ans, sm_o[i] + tot_e - sm_e[i+1])
    print(ans)
    exit()

ans = tot_o

for i in range(m):
    ans = max(ans, sm_e[i]+tot_o-sm_o[i])


l = [0]*m
for i in range(m):
    l[i] = sm_e[i]-sm_o[i]

val = l[0]
tmp = 0

for i in range(m-1):
    ans = max(ans, sm_o[i] + tot_e - sm_e[i+1])
    if i != 0:
        if val < l[i]:
            val = l[i]
    ans = max(ans, sm_o[i] + tot_e - sm_e[i+1] + val)

for i in range(n):
    if i % 2 == 0:
        ans = max(ans, tot_e - a[i])

print(ans)


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


#define all(v)           ((v).begin()), ((v).end())
#define sz size()
#define clr(v,d)         memset(v,d,sizeof(v))
#define lp(i, n)         for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)     for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)     for(int i=(j);i>=(int)(n);--i)
#define sci(a)	scanf("%d",&a)
#define scll(a)	scanf("%lld",&a)
#define scii(a, b)	scanf("%d%d",&a, &b)
#define pri(a)	printf("%d\n",a)
#define prll(a)	printf("%lld\n",a)
	

const int maxn = 300500;

typedef long long ll;

typedef pair<int, int> pii;

int h[maxn], dp[maxn];


int main() {
	//freopen("in.in", "r", stdin);	
	int n; sci(n);
	int K; sci(K);
	lp(i, n) sci(h[i + 1]);
	memset(dp, 63, sizeof dp);
	dp[1] = 0;
	lpi(i, 1, n + 1){
		lpi(k, 1, K + 1){
			dp[i + k] = min(dp[i + k], abs(h[i + k] - h[i]) + dp[i]);
		}
	}
	pri(dp[n]);
}

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main{
	
	static int count(int a) {
		/*int cnt = 0;
		while(a==0) {
			cnt++;
			a/=10;
		}
		return cnt;
		*/
		
		String aa = String.valueOf(a);
		
		if(aa.length()==1) {
			return Integer.parseInt(aa);
			
			
			
		}else {
			int cnt = 0;
			
			for(int i = 0; i < aa.length(); i++) {
				int aaa = Integer.parseInt(aa.substring(i,i+1));
				cnt += aaa;
			}
			return cnt;
			
			
		}
		
		
		
	}

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		long cnt = 0;
		
		for(int i = 1; i <= n; i++) {
			if(count(i)>= a && count(i) <= b ) {
				cnt+=i;
			}
		}
		System.out.println(cnt);
		
	}

}


Measured memory_bytes: 26320
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String A = sc.next();
    String B = sc.next();
    String C = sc.next();
    if ((A.equals(B) && !B.equals(C)) || (B.equals(C) && !C.equals(A)) || (C.equals(A) && !A.equals(B))) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


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

//sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
typedef long long ll;


int main(){
    int K,N,res=0,x;
    cin >> N >> K;
    map<int,int> mp;

    for (int i=0;i<N;++i){
        cin >> x;
        mp[x] += 1;
    }

    if (mp.size()<=K){
        cout << 0 << endl;
        return 0;
    }

    vector<int> v;
    for (auto it=mp.begin();it != mp.end();++it) {
        v.push_back(it->second);
    }

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

    
    res = accumulate(v.begin(),v.end()-K,0);


    cout << res << endl;
  }


Measured memory_bytes: 10748
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector
;
#define vvec(s) vector<vector
> ;
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli n,y;
    cin>>n>>y;
    lli a,b,c;
    a=b=c=-1;
    rep(i,n+1){
        rep(j,n+1){
            if(i+j>n) continue;
            if(10000*i+5000*j+1000*(n-i-j)==y){
                a=i;b=j;c=n-i-j;
            }
        }
    }
    out(a<<" "<<b<<" "<<c);
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def func(N, mod):
    F = [1]
    for i in range(1, N + 1):
        F.append(F[-1] * i % mod)
    return F


def inv(a, mod):
    return pow(a, mod - 2, mod)


def C(F, a, b, mod):
    return F[a] * inv(F[b], mod) * inv(F[a - b], mod) % mod


def main():
    A, B, C = read_values()
    # n * A = m * B + C
    for i in range(1, B + 1):
        if (i * A) % B == C:
            print("YES")
            return
    print("NO")


if __name__ == "__main__":
    main()



Measured memory_bytes: 3064
#include<stdio.h>


int main(void)
{
  int a[10000],b[10000],i,n,k=0;

    scanf("%d",&n);

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

    for(i=0;i<n;i++){
        if((a[i]%2)==0){
            while(1){
                a[i]=a[i]/2;
                k++;
                if((a[i]%2)!=0)
                    break;
            }   
        }   
    }   

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


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  string s, t;
  cin >> s >> t;
  reverse(t.begin(), t.end());
  if(s == t) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int n, a;
  cin >> n >> a;
  if (n % 500 <= a) {
    cout << "Yes" << '\n';
  } else {
    cout << "No" << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/

int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
    //freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
    gbtb;
    int n;
    cin>>n;
    std::vector<pii> v;
    int ans=0;
    repd(i,1,n)
    {
        repd(j,i+1,n)
        {
            if(n&1)
            {
                if(i+j!=n)
                {
                    ans++;
                    v.push_back(mp(i,j));
                    // cout<<i<<" "<<j<<endl;
                }
            }else
            {
                if(i+j!=n+1)
                {
                    ans++;
                    v.push_back(mp(i,j));
                    // cout<<i<<" "<<j<<endl;
                }
            }
        }
    }
    cout<<ans<<endl;
    for(auto x: v)
    {
        cout<<x.fi<<" "<<x.se<<endl;
    }
    
    
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Measured memory_bytes: 384
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4 5
0 1 2
0 2 1
1 2 1
1 3 1
2 3 2

output:
3
"""

import sys
from collections import deque


def graph_bfs(source, target, parent):
    visited = [False] * vertices
    queue = deque()
    queue.append(source)
    visited[source] = True

    while queue:
        current = queue.popleft()
        for adj, cp in adj_table[current].items():
            if not visited[adj] and cp > 0:
                queue.append(adj)
                visited[adj] = True
                parent[adj] = current

    return True if visited[target] else False


def graphFordFulkerson(source, sink):
    parent = [-1] * vertices
    max_flow = 0

    while graph_bfs(source, sink, parent):
        path_flow = float('inf')

        bk_1 = sink
        while bk_1 != source:
            path_flow = min(path_flow, adj_table[parent[bk_1]][bk_1])
            bk_1 = parent[bk_1]

        max_flow += path_flow

        bk_2 = sink
        while bk_2 != source:
            parent_bk_2 = parent[bk_2]
            adj_table[parent_bk_2].setdefault(bk_2, 0)
            adj_table[bk_2].setdefault(parent_bk_2, 0)

            # print(bk_2, parent_bk_2, path_flow, bk_1, parent[bk_1], parent, adj_table)
            adj_table[parent_bk_2][bk_2] -= path_flow
            adj_table[bk_2][parent_bk_2] += path_flow
            bk_2 = parent[bk_2]

    return max_flow


def generate_adj_table(v_table):
    for each in v_table:
        source, target, cp = map(int, each)
        init_adj_table[source][target] = cp

    return init_adj_table


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices, edges = map(int, _input[0].split())
    v_info = map(lambda x: x.split(), _input[1:])

    init_adj_table = [dict() for _ in range(vertices)]
    adj_table = generate_adj_table(v_info)
    ans = graphFordFulkerson(source=0, sink=vertices - 1)
    print(ans)

Measured memory_bytes: 8192
#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdarg>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;
#define INF 2e9 + 9
#define MOD 1000000007
#define ALL(v) v.begin() , v.end()
#define Int int64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T, vector<T>>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) Int n; cin >> n;
#define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for(Int i = s ;i < n ;i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;

void ansYes(bool flag){
    if (flag) cout << "Yes" << endl; else  cout << "No" << endl;
}

void ansYES(bool flag){
    if (flag) cout << "YES" << endl; else  cout << "NO" << endl;
}

struct node {
    Int to;
    Int length;
};


vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return (ret);
}

/*
vector<vector<int>> to;
vector<int> flag;
vector<int> c;


Int dfs(int from, int mae) {
    flag[from] = 1;
    Int mini = 0;
    for (auto next : to[from]) {
        if (next == mae) continue;
        if (flag[next] == 1) {
            return -1;
        } else {
            mini = min(mini, dfs(next, from));
        }
    }
    return mini;
}*/

int dx8[8] = {0, -1, -1, -1, 0, 1, 1, 1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

struct datas{
    Int max;
    Int size;
};


int main(void) {
    string s;
    int q;
    cin>>s>>q;
    int t, f;
    char c;
    bool mae = true;
    REP(q,i){
        cin >> t;
        if (t == 1) mae = !mae;
        else {
            cin >> f >> c;
            if (mae) {
                if (f == 1) {
                    s.insert(s.begin(),c);
                }else {
                    s.push_back(c);
                }
            }else{
                if (f == 1){
                    s.push_back(c);
                }else{
                    s = c + s;
                }
            }
        }
    }
    if (!mae) reverse(s.begin(),s.end());
    cout << s << endl;

}




Measured memory_bytes: 1668
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
e=0
for i in range(n):
    c=n-i
    d=0
    while c<=n:
        d+=b[c-1]
        c+=(n-i)
    if d%2!=a[n-i-1]:
        b[-i-1]+=1
        e+=1
print(e)
for i in range(n):
    if b[i]!=0:
        print(i+1,end=' ')

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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define FOR(i, n, m) for(ll i = (ll)n; i < (ll)(m); i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define PRINT(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " ";  
    return os; 
}

template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}

void dfs(ll num, vector<ll>& v) {
    if (num > 3234566667) {
        return;
    } else {
        v.push_back(num);
        if (num % 10 == 0) {
            dfs(num * 10, v);
            dfs(num * 10 + 1, v);
        } else if (num % 10 == 9) {
            dfs(num * 10 + 9, v);
            dfs(num * 10 + 8, v);
        } else {
            dfs(num * 10 + num % 10, v);
            dfs(num * 10 + (num % 10) + 1, v);
            dfs(num * 10 + (num % 10) - 1, v);
        }
    }
    return;
}

int main()
{
    ll K;
    cin >> K;
    vector<ll> s;
    if (K < 10) {
        PRINT(K);
        return 0;
    } else {
        FOR(i, 1, 10) {
            dfs(i, s);
        }
    }
    sort(ALL(s));
    PRINT(s[K-1]);
    return 0;
} 

Measured memory_bytes: 1400
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;
int main(){
    int r,d,x[11],sum,i;
    cin>>r>>d>>x[0];
    //cout<<x[0]<<endl;
    for(i=0;i<10;i++){
        x[i+1]=r*x[i]-d;
        cout<<x[i+1]<<endl;
    }

    //cout<<sum<<endl;
    
    
    return 0;
}


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

int main() {
 
  int n;
  cin >> n;
  vector<int> a(n);
  int sum = 0;
  for(int i = 0; i < n; i++) {
    cin >> a.at(i);
    sum += a.at(i) - 1;
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define INF 1000000000
#define EPS 1e-9
#define PI acos(-1)

typedef long long ll;

#define MAX_N 100

int n;
int k[MAX_N];
string s;
string str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

vector<string> ans_list;

int main(){

  while(true){
    cin >> n;
    if(n == 0)
      break;
    for(int i = 0; i < n; i++){
      cin >> k[i];
    }
    cin >> s;
    string ans;
    int num = 0;
    for(int i = 0; i < s.length(); i++, num++){
      if(num == n)
	num = 0;
      int tmp;
      for(tmp = 0; tmp < 52; tmp++){
	if(str[tmp] == s[i])
	  break;
      }
      tmp -= k[num];
      if(tmp < 0)
	tmp += 52;
      ans += str[tmp];
    }
    ans_list.push_back(ans);
  }

  for(int i = 0; i < ans_list.size(); i++){
    cout << ans_list[i] << endl;
  }

  return 0;

}

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

#define ll             long long
#define LL             long long
#define gcd(a,b)       __gcd(a, b)
#define lcm(a,b)       a * (b / gcd(a, b))
#define pii            pair<int, int>
#define pll            pair<ll, ll>
#define pil            pair<int, ll>
#define pli            pair<ll, int>
#define vi             vector<int>
#define vl             vector<ll>
#define vii            vector<pii>
#define vll            vector<pll>
#define vil            vector<pil>
#define vli            vector<pli>
#define pb             push_back
#define ppb            pop_back
#define mp             make_pair
#define ff             first
#define ss             second
#define all(v)         v.begin(), v.end()
#define fill(a, b)     memset(a, b, sizeof a)
#define smax(a, b)     a = max(a, b)
#define smin(a, b)     a = min(a, b)
#define sqr(x)         x * x
#define cube(x)        x * x * x
#define endl           '\n'

int in() {
	int n;
	scanf("%d", &n);
	return n;
}

ll Lin() {
	ll n;
	scanf("%lld", &n);
	return n;
}

double Din() {
	double n;
	scanf("%lf", &n);
	return n;
}

const ll inf = (ll)1e17;
const ll mod = (ll)1e9 + 7;
const int N = 1e5 + 5;

vi g[N];
int dp[N];
int degree[N];

int top_sort(int n) {
	queue<int>q;
	for (int i = 1; i <= n; i++) {
		if (!degree[i]) q.push(i);
	}
	int ans = 0;
	while (!q.empty()) {
		int u = q.front();
		q.pop();
		degree[u] = -1;
		for (int i = 0; i < g[u].size(); i++) {
			int v = g[u][i];
			degree[v]--;
			if (!degree[v]) q.push(v);
			dp[v] = max(dp[v], dp[u] + 1);
			ans = max(ans, dp[v]);
		}
	}
	return ans;
}

int solve() {
	int n = in(), m = in();
	for (int i = 1; i <= m; i++) {
		int u = in(), v = in();
		g[u].pb(v);
		degree[v]++;
	}
	printf("%d\n", top_sort(n));
	return 0;
}

int main() {
	int test = 1, tc = 0;
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
	return 0;
}


Measured memory_bytes: 6528
import java.util.*;
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int wk=0;
		int ans=-1;
		int sum=0;
		for(int i=1;i<=M;i++){
			wk=0;
			wk=sc.nextInt();
			sum=sum+wk;
		}
		if (N<sum) {
		System.out.println(ans);
		}
		else{
		ans=N-sum;
		System.out.println(ans);
		}
    }
}

Measured memory_bytes: 37792