akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

ll f(vector<P> vp){
    int m = vp.size();
    rep(i, m) vp[i].fi = min(vp[i].fi, m);
    vvi s(m+1);
    rep(i, m) s[vp[i].fi].pb(vp[i].se);
    
    ll res = 0;
    priority_queue<int> q;
    rep3rev(i, m, 1){
        for(auto x : s[i]) q.push(x);
        if(!q.empty()){
            int now = q.top(); q.pop();
            res += now;
        }
    }
    
    return res;
}

void Solve(){
    int n; cin >> n;
    vector<P> ft, bk;
    ll ans = 0;

    rep(i, n){
        int k, l, r;
        cin >> k >> l >> r;
        ans += min(l, r);
        if(l-r > 0) ft.eb(k, l-r);
        else bk.eb(n-k, r-l);
    }

    ans += f(ft);
    ans += f(bk);
    cout << ans << endl;
    return;    
}

void Main(){
    int t; cin >> t;
    while(t--){
        Solve();
    }
    return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 10528
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <string>
#include <deque>
#include <queue>
#include <unordered_map>
#include <assert.h>
using namespace std;
typedef long long ll;
#define pi pair<int, int>
#define pii pair<pi, pi>

const int MOD = 998244353;
const int mxn = 3010;
ll dp[mxn][mxn]; 

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	dp[A][B] = 1;
	for (int i = A + 1; i <= C; i++) {
		dp[i][B] = (dp[i - 1][B] * B) % MOD;
	}
	for (int i = B + 1; i <= D; i++) {
		dp[A][i] = (dp[A][i - 1] * A) % MOD;
	}
	for (int i = A + 1; i <= C; i++) {
		for (int j = B + 1; j <= D; j++) {
			dp[i][j] = MOD + (dp[i - 1][j] * j) % MOD + (dp[i][j - 1] * i) % MOD - (dp[i - 1][j - 1] * (i - 1) * (j - 1)) % MOD;
			dp[i][j] %= MOD;
		}
	}
	cout << dp[C][D] << '\n';
}

Measured memory_bytes: 74104
#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int i=a,inc=(b-a)/abs(b-a); i!=b ; i+=inc)
#define deb(x) cout<<#x<<"->"<<x<<endl;
#define print(arr,a,b) for(int i=a;i!=b;i++){cout<<arr[i]<<" ";}cout<<endl;
using ll=long long int;
int arr_min(int arr[],int a,int b){ int min=arr[0]; for(int i=a;i!=b;i++){if(min>arr[i]) min=arr[i];}return min;}
int arr_max(int arr[],int a,int b){ int max=arr[0]; for(int i=a;i!=b;i++){if(max<arr[i]) max=arr[i];}return max;}

signed main()
{
	ios_base::sync_with_stdio(false);   
    cin.tie(NULL);

	#ifndef ONLINE_JUDGE
      	freopen("input.txt", "r", stdin);
      	freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    // cin>>t;
    while(t-->0){
    	int a,b,c,d;
    	cin>>a>>b>>c>>d;
    	while(true)
    	{
    		c-=b;
    		if(c<=0)
    		{
    			cout<<"Yes"<<endl;
    			break;
    		}
    		a-=d;
    		if(a<=0)
    		{
    			cout<<"No"<<endl;
    			break;
    		}
    	}
    	
    	
    }
    return 0;
}

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

vector<int>vec[2*(int)1e5+5];
int res[2*(int)1e5+5];

void dfs(int u){
    res[u]=1;
    for(int i=0;i<vec[u].size();i++){
        dfs(vec[u][i]);
        res[u]+=res[vec[u][i]];
    }
}
int main(){
    #ifdef LOCAL_MACHINE
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    
    int n;
    scanf("%d",&n);

    for(int i=2;i<=n;i++){
        int x;
        scanf("%d",&x);

        vec[x].push_back(i);
    }

    //dfs(1);

    for(int i=1;i<=n;i++){
        printf("%d\n",(int)vec[i].size());
    }
    
    return 0;
}


Measured memory_bytes: 14776
STDIN.readline
l_list = STDIN.readline.split().map{|l| l.to_i}
sum = 0
max = 0
for l in l_list do
    if max < l then
        sum += max
        max = l
    else
        sum += l
    end
end

if max < sum then
    puts('Yes')
else
    puts('No')
end

Measured memory_bytes: 1788
# import numpy as np
# from itertools import permutations
# from itertools import combinations
# from itertools import combinations_with_replacement
# import queue
# import heapq


def main():
    # N, M = map(int, input().split())
    # As = list(map(int, input().split()))

    S = input()

    if S == 'ABC':
        print('ARC')
    else:
        print('ABC')


if __name__ == "__main__":
    main()


Measured memory_bytes: 9024
#include<stdio.h>

int main(void)
{
   long long int i,h,n,s,a[100000];
   s=0;
   scanf("%lld%lld",&h,&n);
   for(i=0; i<n; i++){
      scanf("%lld",&a[i]);
      s=s+a[i];
   }
   if(s>=h){printf("Yes\n");}
   else {printf("No\n");}
   return 0;
}


Measured memory_bytes: 896
/*jai_ganeshdeva*/

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push  //  adds the value to the last of the queue 
#define lld long long int
#define ins insert /// used in set to insert the values 
#define adv advance  /// used to increment the iterator
#define mp make_pair
#define fi first
#define se second
#define all(c) c.begin(),c.end()
#define PI 3.1415926
#define INF (lld)1e18
#define vl  vector<long long int >
#define vpl vector< pair<lld ,lld> >
#define vvl vector<vector<lld> > 
#define pll pair <lld,lld>
#define modA(cccc,bbbb ,p) (((cccc+bbbb)%p+p)%p)
#define modS(cccc,bbbb ,p) (((cccc-bbbb)%p+p)%p)
#define modM(cccc,bbbb ,p) ((((cccc%p)*(bbbb%p))%p+p)%p)

long long int modp(lld a,lld p,lld n)
{
    lld d[100];
    lld i,j,k,l;
    if(n==0) return 1;
    for(i=0;n>=1;i++)
    {
        d[i]=n%2;
        n/=2;
    }
    l=i;
    long long int e=1;
    if(d[0]==1) e*=(a%p);
    for(i=1;i<l;i++)
    {
        a*=a;
        a=a%p;
        if(d[i]==1) 
        {
            e*=a;
            e=e%p;
        }
    }
    return e%p;
}
lld modInverse(lld n, lld p) 
{ 
    return modp(n, p, p-2); 
}

lld fac[500001]; 

void getfac(lld p)
{
    fac[0] = 1; 
    for (lld i=1 ; i<=500000; i++) 
        fac[i] = fac[i-1]*i%p; 
}    

long long int nCrmodp(lld n, lld r,lld p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
     
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}



lld p1=1e9 + 7,p2=998244353;
lld l,r,mid,ans=0;
lld n,i,j,k,m,g;
lld x,y,n1,a,b=0,n2,h,z,c;


void solve()
{
    lld z,w;
    cin>>x>>y>>z>>w>>k;
    ans=0;
    if(y>w)
    {
        ans+=(60+w-y);
        z-=1;
    }
    else ans+=(w-y);
    if(z>x) ans+=60*(z-x);
    ans-=k;
    
    if(ans>=0) cout<<ans;
    else cout<<"0";
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t=1;
    
    //cin>>t;
    //cout<<t;
   //  getfac(p2);
    //check the value by which modulo is to be taken
    
    for(int i=0;i<t;i++)
    {
   //     cout<<"Case #"<<i+1<<": ";
                  solve();
 
        cout<<"\n";
    }
    return 0;
}

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

queue<int> que;
void dfs(vector<vector<int>> &graph,vector<int> &dis,vector<vector<bool>> &visited,int V,int cnt,int st){
  if(cnt==3){
    dis.at(V)=dis.at(st)+1;
    que.push(V);
    return;
  }

  for(int i=0;i<graph.at(V).size();i++){
    int nv=graph.at(V).at(i);
    if(visited.at(nv).at((cnt+1)%3))  continue;
    visited.at(nv).at((cnt+1)%3)=true;
    dfs(graph,dis,visited,nv,cnt+1,st);
  }
}

int main(){
  int N,M;
  cin >> N >> M;
  vector<vector<int>> graph(N);
  for(int i=0;i<M;i++){
    int u,v;
    cin >> u >> v;
    u--;
    v--;
    graph.at(u).push_back(v);
  }
  int S,T;
  cin >> S >> T;
  S--;
  T--;

  vector<int> dis(N,1e9);
  vector<vector<bool>> visited(N,vector<bool>(3,false));
  dis.at(S)=0;
  visited.at(S).at(0)=true;
  que.push(S);
  while(!que.empty()){
    int v=que.front();
    que.pop();
    dfs(graph,dis,visited,v,0,v);
  }
  if(dis.at(T)==1e9)  cout << -1 << endl;
  else  cout << dis.at(T) << endl;

  return 0;
}

Measured memory_bytes: 13184
#!/mnt/c/Users/moiki/bash/env/bin/python
# N,M = map(int, input().split())
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


import math

def mirror_prime(n):
    answer = True
    # Test 0 and 1
    if n==0 or n==1:
        answer = False
    # End if

    # Test even numbers
    if n != 2 and n%2==0:
        answer= False
    # End if

    # Test if there is a proper odd divisor
        for d in range (3, int(math.sqrt(n))+1, 2):
            if n%d==0:
                answer=False
            # End if
        # End for



    #Reverse n
    mirror_n = int(str(n)[::-1])
    mirror_answer = True

    # Test 0 and 1
    if mirror_n==0 or mirror_n==1:
        mirror_answer = False

def primes(n):
    """ Returns  a list of primes < n """
    sieve = [True] * n
    for i in range(3,int(n**0.5)+1,2):
        if sieve[i]:
            sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1)
    return [2] + [i for i in range(3,n,2) if sieve[i]]

# BIT = Bit(10**5+1)

isprime = None
 
def sieve(n):
    global isprime
 
    if n < 2:
        isprime = [False] * (n + 1)
        return
 
    isprime = [True if i % 2 != 0 else False for i in range(n + 1)]
    isprime[0] = isprime[1] = False
    isprime[2] = True
 
    from math import sqrt, ceil
 
    for i in range(3, int(sqrt(n)) + 1):
        if isprime[i] == True:
            for j in range(i + i, n + 1, i):
                isprime[j] = False

# plist = primes(10**5+1)
sieve(10**5+1)


accm = [0] * (10**5+1)
for i in range(3, 10**5+1):
    accm[i] += accm[i-1]
    # if mirror_prime(i) and mirror_prime((i+1)//2):
    if isprime[i] and isprime[(i+1)//2]:
        accm[i] += 1

Q = int(input())
for i in range(Q):
    l,r = map(int,input().split())
    # if mirror_prime(l) and mirror_prime((l+1)//2):
    if isprime[l] and isprime[(l+1)//2]:
        l-=1
    # if mirror_prime(r) and mirror_prime((r+1)//2):
    if isprime[r] and isprime[(r+1)//2]:
        r+=1
    print( accm[r] - accm[l] ) 


Measured memory_bytes: 60576
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    h, w = list(map(int, readline().split()))
    a = [list(str(readline().rstrip().decode('utf-8'))) for _ in range(h)]
    ql = []
    ql = collections.deque(ql)
    for i in range(h):
        for j in range(w):
            if a[i][j] == "#":
                ql.append([0, i, j])

    mt = 0
    while True:
        if len(ql) != 0:
            cost, x, y = ql.popleft()
            mt = max(mt, cost)
            for xv, yv in [[x + 1, y], [x - 1, y], [x, y + 1], [x, y - 1]]:
                if 0 <= xv < h and 0 <= yv < w:
                    if a[xv][yv] == ".":
                        ql.append([cost + 1, xv, yv])
                        a[xv][yv] = "#"
        else:
            break
    print(mt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 176476
#include<stdio.h>

int main(){
	char date[10];
	int i;
	scanf("%s", date);
	for(i = 0; i<=9; i++){
		if(i == 0){
			printf("");
		}
		if(i == 1){
			printf("");
		}
		if(i == 2){
			printf("");
		}
		if(i == 3){
			printf("8");
		}else{
			printf("%c", date[i]);
		}
	}
}

Measured memory_bytes: 1640
def main():
    N, K = (int(i) for i in input().split())
    H = [int(input()) for i in range(N)]
    ans = 10**12
    H.sort()
    for i in range(N-K+1):
        ans = min(ans, H[i+K-1] - H[i])
    print(ans)


if __name__ == '__main__':
    main()


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

#define rep(i, n)  for (int i = 0; i < (n) ; ++i)
#define mod 1000000007

using namespace std;
using ll=long long;

const int INF = 100000000;

int main() {
    ll N, K;
    cin >> N >> K;
    ll d[1000] = {}, a[1000][1000] = {}, res[1000] = {};
    ll ret = 0;

    rep(i, K) {
        cin >> d[i];
        for (int j = 0; j < d[i]; ++j) {
            cin >> a[i][j];
        }
    }

    for (int i = 0; i < K; ++i) {
        for (int j = 0; j < d[i]; ++j) {
            res[a[i][j]] = 1;
        }
    }

    for (int k = 1; k <= N; ++k) {
        if (res[k] == 0) ret++;
    }

    cout << ret;
    return 0;
}

Measured memory_bytes: 11424
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

#define POS(i, j) ((i) * n + (j))

int dfs (i32 v, uint8_t *g, i32 n, uint8_t *c, i32 *cnt) {
  cnt[c[v]]++;
  for (i32 i = 0; i < n; ++i) {
    if (i == v || g[POS(v, i)]) continue;
    if (c[i] == 2) {
      c[i] = c[v] ^ 1;
      if (dfs (i, g, n, c, cnt)) return 1;
    }
    if (c[i] == c[v]) return 1;
  }
  return 0;
}

void run (void) {
  i32 n, m;
  scanf ("%" SCNi32 "%" SCNi32, &n, &m);
  uint8_t *mat = (uint8_t *) calloc (n * n, sizeof (uint8_t));
  while (m--) {
    i32 a, b;
    scanf ("%" SCNi32 "%" SCNi32, &a, &b);
    a--;
    b--;
    mat[POS(a, b)] = mat[POS(b, a)] = 1;
  }
  uint8_t *c = (uint8_t *) calloc (n, sizeof (uint8_t));
  for (i32 i = 0; i < n; ++i) {
    c[i] = 2;
  }
  i32 *a = (i32 *) calloc (n, sizeof (i32));
  i32 *b = (i32 *) calloc (n, sizeof (i32));
  i32 len = 0;
  for (i32 i = 0; i < n; ++i) {
    if (c[i] < 2) continue;
    c[i] = 0;
    i32 cnt[2] = {0, 0};
    if (dfs (i, mat, n, c, cnt)) {
      puts ("-1");
      return;
    }
    a[len] = cnt[0];
    b[len] = cnt[1];
    len++;
  }
  i32 *dp = (i32 *) calloc (n + 1, sizeof (i32));
  dp[0] = 1;
  for (i32 i = 0; i < len; ++i) {
    for (i32 j = n - 1; j >= 0; --j) {
      if (dp[j] == 0) continue;
      dp[j] = 0;
      dp[j + a[i]] = dp[j + b[i]] = 1;
    }
  }
  i32 min = n * n;
  for (i32 i = 1; i < n; ++i) {
    i32 v = i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2;
    if (dp[i] && v < min) min = v;
  }
  printf ("%" PRIi32 "\n", min);
}

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


Measured memory_bytes: 640
#include <stdio.h>

// 桁数を計算
int calcDigit(int num)
{
    int digit = 0;
    while (num != 0)
    {
        num = num / 10;
        digit++;
    }
    digit = digit % 2;
    return digit;
}

int main(void)
{
    int n;
    int cn = 0;
    scanf("%d", &n);
    for (int i = 1; i < n + 1; i++)
    {
        cn += calcDigit(i);
    }
    printf("%d\n", cn);
    return 0;
}

Measured memory_bytes: 128
import math
n=int(input())
ans=[0]*n
for i in range(1,101):
    for j in range(1,101):
        for k in range(1,101):
            num=(i+j+k)**2-(i*j+j*k+k*i)
            if num<=n:
                ans[num-1]+=1
for i in ans:
    print(i)


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

int main() {
  int N;
  cin >> N;
  int s = 0;
  for (int i = 0; i < N; i++){
  	int l, r, t;
    cin >> l >> r;
    t = (r - l) + 1;
    s += t;
  }
  cout << s << endl;
}

Measured memory_bytes: 3640
x1,y1,x2,y2=map(float, input().split())

if x1<x2:
    x1,x2=x2,x1
if y1<y2:
    y1,y2=y2,y1

n=((x1-x2)**2+(y1-y2)**2)**(1/2)
print(n)


Measured memory_bytes: 5628
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 System.Math;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine();
        if (s.Length > n) s = s[0..n] + "...";
        Console.WriteLine(s);
    }
}

Measured memory_bytes: 27436
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;



int main(){
  
  int n;
  cin >> n;
    
    if(n <= 999) cout << "ABC" << endl;
  else cout << "ABD" <<  endl;

  

 return 0;
}


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

signed main() {
  int N;
  cin >> N;
  int ans = 0;
  for(int i=1; i<=N; i++) {
    if(i%3 == 0) continue;
    if(i%5 == 0) continue;
    ans += i;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
{-# LANGUAGE TypeApplications #-}
module Main where
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM
main :: IO ()
main = do
  x <- readLn @Int
  let (a, b) = solver x
  putStrLn $ unwords [show a, show b]

solver :: Int -> (Int, Int)
solver x =
  let nums  = [-200 .. 199]
      fives = VU.map (^ 5) $ VU.fromListN 400 [-200 .. 199]
  in  fst . head $ filter
        ((== x) . snd)
        [ ((a, b), fives VU.! (a + 200) - fives VU.! (b + 200)) | a <- nums, b <- nums ]


Measured memory_bytes: 4112
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>

using namespace std;
const double PI(acos(-1));

int main()
{
    long long int A, B, C, D;
    cin >> A >> B >> C >> D;

    long long int s[4] = {};
    s[0] = A * C;
    s[1] = A * D;
    s[2] = B * C;
    s[3] = B * D;

    long long max = s[0];
    for (int i = 1; i < 4; i++)
    {
        if (s[i] > max)
        {
            max = s[i];
        }
    }

    cout << max;
}


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

int main() {
  char a; cin >> a;
  if(islower(a)) cout << "a" << endl;
  else cout << "A" << endl;
    
  return 0;
}



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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n;cin>>n;
  int cx = 0, cy = 0, pt = 0;
  bool ok=true;
  for(int i=0;i<n;i++){
    int t,x,y;cin>>t>>x>>y;
    int dist = abs(cx-x)+abs(cy-y);
    int time_mod = (t - pt) % 2;
    int dist_mod = dist % 2;
    ok = ok && (dist <= t && (time_mod == dist_mod));
    pt = t;
    cx= x;
    cy = y;
  }
  cout<<(ok ? "Yes" : "No")<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){
	int n,mi=1000,ma=-1,t,ans,ansmi=10000000;
	vector <int> x;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>t;
		mi=min(mi,t);
		ma=max(ma,t);
		x.push_back(t);
	}
	for(int i=mi;i<=ma;i++){
		ans=0;
		for(int j=0;j<n;j++){
			ans+=(x[j]-i)*(x[j]-i);
		}
		ansmi=min(ansmi,ans);
	}
	cout<<ansmi<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            solve(in);
        }
    }

    private static void solve(Scanner in) {
        int N = in.nextInt();
        long[] A = new long[N];
        for (int i = 0; i < N; i++) {
            A[i] = in.nextInt();// 1 ~ 10^9
        }
        Arrays.sort(A);

        long[] AA = new long[N];
        AA[0] = A[0];
        for (int i = 1; i < N; i++) {
            AA[i] += (AA[i - 1] + A[i]);
        }

        int ans = 1;
        for (int i = N - 1; i > 0; i--) {
            if (AA[i - 1] * 2 >= A[i]) {
                ans++;
            } else {
                break;
            }
        }
        System.out.println(ans);
    }
}

final class Scanner implements Closeable {
    private final InputStream stream;
    private final byte[] buf = new byte[1024];
    private int cur;
    private int num;

    Scanner(InputStream stream) {
        this.stream = stream;
    }

    int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    int nextInt() {
        return (int) nextLong();
    }

    long nextLong() {
        int c = read();
        while (isdel(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long l = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            l *= 10;
            l += c - '0';
            c = read();
        } while (!isdel(c));
        return l * sgn;
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String next() {
        int c = read();
        while (isdel(c))
            c = read();
        StringBuilder s = new StringBuilder();
        do {
            s.appendCodePoint(c);
            c = read();
        } while (!isdel(c));
        return s.toString();
    }

    private int read() {
        if (num == -1)
            throw new InputMismatchException();
        if (cur >= num) {
            cur = 0;
            try {
                num = stream.read(buf);
            } catch (Exception e) {
                throw new InputMismatchException();
            }
            if (num <= 0)
                return -1;
        }
        return buf[cur++];
    }

    private boolean isdel(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    @Override
    public void close() {
        try {
            stream.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

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

#define int long long	
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);                                          
#define forev(i, b, a) for(int i = (b); i >= (a); --i)	    
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.bg, x.en                                                                    
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define rbg rbegin()
#define bg begin()
#define en end()
#define s second
#define f first                                               
	
   
using namespace std;                  
   
   
typedef pair < unsigned long long, unsigned long long > puu;
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef long double ldb; 
typedef long long ll;  
typedef double db;                            
						               
	
const int inf = 1e9, N = 1e5 + 11, mod = 1e9 + 7;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
const db eps = 1e-5, pi = 3.14159265359; 
const puu base = mp(1e9 + 7, 1e9 + 9);                                      
const ll INF = 1e18;             

int n, a[N], d[N], sum;

main () {     
	cin >> n;
	forn (i, 1, n) {
		cin >> a[i];
		sum += a[i];	
	}

	if (sum %  (n*(n + 1) / 2)) {
		cout << "NO";
		return 0;
	}

	int k = sum / (n*(n + 1) / 2);

	forn (i, 1, n - 1)
		d[i] = a[i + 1] - a[i];

	forn (i, 1, n - 1) 
		if (((k - d[i]) % n) || k < d[i]) {
			cout << "NO";
			return 0;
		}

	cout << "YES";
	return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<algorithm>
#include<vector>
using namespace std;
 
const int N = 4e5;
int a[N+3];
int d[N+3];
int dp[N+3][10];
vector<int> b;
int n;
 
bool cmp(int x,int y) {return x>y;}
 
int main()
{
    scanf("%d",&n);
    for(int i=1; i<=n; i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1,cmp);
    int pos = 0;
    for(int i=1; i<=n; i++)
    {
        if(a[i]>=i && a[i+1]<=i) {pos = i; break;}
    }

    int len1 = 0;
    for(int i=pos+1; i<=n; i++) {if(a[i]>pos-1) len1++;}
    int len2 = a[pos]-pos;

    if((!(len1&1)) && (!(len2&1))) printf("Second");
    else printf("First");
    return 0;
}

Measured memory_bytes: 3608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static String HALF_SPACE = " ";

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			int t = (int)Math.sqrt(n);
			StringBuffer sb = new StringBuffer();
			sb.append(n+":");
			for (int i = 2; i <= t; i++) {
				while (n % i == 0) {
					n /= i;
					sb.append(HALF_SPACE);
					sb.append(i);
				}
			}

			// prime
			if (n > 1) {
				sb.append(HALF_SPACE);
				sb.append(n);
			}
			out.println(sb.toString());
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}



Measured memory_bytes: 24512
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){
  int i=0;
  char s[100];
  int x[101];

  while(scanf("%s", s)!= EOF){
    if(s[0]==' ')
      continue;
    else if(s[0]=='+'){
      x[i-2] = x[i-2]+x[i-1];
      i--;
    }else if(s[0]=='-'){
      x[i-2] = x[i-2]-x[i-1];
      i--;
    }else if(s[0]=='*'){
      x[i-2] = x[i-2]*x[i-1];
      i--;
    }else{
      x[i] = atoi(s);
      i++;
    }
  }

  printf("%d\n",x[0]);
  return 0;
}



Measured memory_bytes: 2716
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String s = sc.next();

        // 回文にできるか判定する
        String[] array = s.split("x+");
        StringBuilder builder = new StringBuilder();
        for (String v: array
             ) {
            builder.append(v);
        }
        String formatted = builder.toString();

        for (int i = 0; i < formatted.length() / 2; i++) {
            if (formatted.charAt(i) != formatted.charAt(formatted.length() - 1 - i)) {
                System.out.println(-1);
                return;
            }
        }

        builder = new StringBuilder(s);

        int index = 0;
        long ans = 0;
        while (index < builder.length() / 2) {
            boolean firstIsX = builder.charAt(index) == 'x';
            boolean endIsX = builder.charAt(builder.length() - 1 - index) == 'x';
            if (firstIsX && !endIsX) {
                builder.insert(builder.length() - index, "x");
                ans++;
            } else if (!firstIsX && endIsX) {
                builder.insert(index, "x");
                ans++;
            } else {
                index++;
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 42672
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<list>
#include<iomanip>
#include<vector>
using ll = long long;
using namespace std;
const ll MM = 1000000000;
const ll mod = MM + 7;

int main(){
    int a, b, c; cin >> a >> b >> c;
    int sum = 0;
    int num = 0;
    string ans = "NO";
    
    for(int i = 1; i < b; i++){
        sum = i*a;
        num = sum % b;
        if(num == c) ans = "YES";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Here your code !

def compute_card_game_score():
    players = ("player_A", "player_B")
    (score, cards) = ("score", "cards")
    
    #load data
    game_log = {player : {score : 0, cards : []} for player in players}
    try:
        tmp = input()
        while(True):
            cards_pair = input().rstrip().split()
            [ game_log[player][cards].append(cards_pair[i]) for i,player in enumerate(players) ]
    except EOFError:
        pass
    except:
        return inputError()
    
    #compute score
    for pairs in zip(game_log[players[0]][cards], game_log[players[1]][cards]):
        if pairs[0] == pairs[1] :
            for player in players:
                game_log[player][score] += 1
        elif pairs[0] > pairs[1] :
            game_log[players[0]][score] += 3
        elif pairs[0] < pairs[1] :
            game_log[players[1]][score] += 3
    
    print( " ".join([ str(game_log[player][score]) for player in players ]) )
    
def inputError():
    print("input Error")
    return -1


#test
if __name__ == "__main__" :
    compute_card_game_score()
    
    

Measured memory_bytes: 7500
#include<iostream>
using namespace std;
int main(){
  int N, c, sum;
  int V[20];
  cin >> N;
  for(int i=0; i<N; i++){
      cin >> V[i];
  }
  sum =0;
  for(int i=0; i<N; i++){
      cin >> c;
      if(c < V[i]){
          sum += V[i]-c;
      }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

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

    ll K, N;
    cin >> K >> N;

    vector<ll> A(N);

    for (ll i = 0; i < N; i++) {
        cin >>A.at(i);
    }

    vector<ll> aida(N);

    for (ll i = 0; i < N-1; i++) {
        aida.at(i)=A.at(i+1)-A.at(i);
    }
    aida.at(N - 1) = A.at(0) + K - A.at(N - 1);

    sort(aida.begin(), aida.end());
    ll ans = 0;

    for (ll i = 0; i < N-1; i++) {
        ans+=aida.at(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3456
from itertools import accumulate
N, M, K = map(int, input().split())
As = [0] + list(map(int, input().split()))
Bs = [0] + list(map(int, input().split()))
csum_A = list(accumulate(As))
csum_B = list(accumulate(Bs))

ok = 0
ng = N + M + 2
while ng - ok > 1:
    mid = (ng + ok) // 2
    min_time = 10 ** 9 + 10
    for t in range(max(0, mid-M), min(mid+1, N+1)):
        min_time = min(min_time, csum_A[t] + csum_B[mid - t])
    
    if K >= min_time:
        ok = mid
    else:
        ng = mid

print(ok)
    

Measured memory_bytes: 130032
import java.util.Scanner;
import java.util.stream.Stream;

class Main {
  private static void solve(int n, int d, int[][] x) {
    int count = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        long distance = 0;
        for (int k = 0; k < d; k++) {
          int diff = Math.abs(x[i][k] - x[j][k]);
          distance += diff * diff;
        }
        double sqrt = Math.sqrt((double) distance);
        if (Math.floor(sqrt) == sqrt) count++;
      }
    }
    System.out.println(count);
  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String[] num = sc.nextLine().split(" ");
    int n = Integer.parseInt(num[0]);
    int d = Integer.parseInt(num[1]);
    int[][] x = new int[n][d];
    for (int i = 0; i < n; i++) {
      String[] xi = sc.nextLine().split(" ");
      for (int j = 0; j < d; j++) x[i][j] = Integer.parseInt(xi[j]);
    }
    solve(n, d, x);
  }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 100005;

int a[maxn];
vector<int> v;

int main()
{
    int N, x;
    scanf("%d", &N);
    for(int i = 1; i <= N; i++){
        scanf("%d", a + i);
        if(a[i] == i){
            v.push_back(i);
        }
    }
    int ans = v.size(), n = v.size();
    int p = 0;
    while(p < n - 1){
        if(v[p] + 1 == v[p + 1]){
            ans--;
            p += 2;
        }
        else{
            p++;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1148
import sys

input = sys.stdin.readline

MAX_VALUE = 10e9


def solve(B, n):
    B = [MAX_VALUE] + B + [MAX_VALUE]
    result = 0
    for i in range(n):
        result += min(B[i], B[i + 1])

    return result


if __name__ == '__main__':
    n = int(input())
    B = list(map(int, input().split()))

    answer = solve(B, n)
    print(answer)


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main() {
	int n,k;
	int h[100000];
	int a[100000];
	a[0] = 0;
	cin >> n;
	cin >> k;
	for (int i = 0; i < n; i++)
		cin >> h[i];
	 

	for (int i=0;i<n;i++)
	{

		a[i + 1] = abs(h[i] - h[i + 1]) + a[i];
		
		
		{
			for (int j = 1; j <= k; j++)
			{
				if (i >= j-1)
				{
					if (a[i + 1] > abs(h[i - j+1] - h[i + 1]) + a[i - j+1])
						a[i + 1] = abs(h[i - j+1] - h[i + 1]) + a[i - j+1];
				}
			}
		}
	}

	cout << a[n - 1];
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define UNIQUE(c) sort(ALL(c)), c.erase(unique(ALL(c)), c.end())

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

struct StronglyConnectedComponents {
  int V;
  std::vector<std::vector<int>> G, rG;
  std::vector<int> vs, cmp;
  std::vector<bool> used;

  StronglyConnectedComponents(int V) : V(V) {
    used.assign(V, false);
    G.resize(V), rG.resize(V);
    cmp.resize(V);
  }

  void add_edge(int from, int to) {
    G[from].push_back(to);
    rG[to].push_back(from);
  }

  void dfs(int v) {
    used[v] = true;
    for (int c : G[v])
      if (not used[c]) dfs(c);
    vs.push_back(v);
  }

  void rdfs(int v, int k) {
    used[v] = true;
    cmp[v] = k;
    for (int c : rG[v])
      if (not used[c]) rdfs(c, k);
  }

  int run() {
    fill(used.begin(), used.end(), false);
    vs.clear();
    for (int v = 0; v < V; v++)
      if (!used[v]) dfs(v);
    fill(used.begin(), used.end(), false);
    int k = 0;
    for (int i = vs.size() - 1; i >= 0; i--)
      if (!used[vs[i]]) rdfs(vs[i], k++);
    return k;
  }
};


int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  map<pair<int, int>, int> mp;
  int cnt = 0;
  REP(i, N) REP(j, N) {
    if (i < j) {
      mp[make_pair(i, j)] = mp[make_pair(j, i)] = cnt;
      //cout << '(' << i << ',' << j << ")=" << cnt << endl;
      cnt++;
    }
  }

  StronglyConnectedComponents scc(cnt);
  REP(i, N) {
    vector<int> A(N-1); REP(j, N-1) cin >> A[j], A[j]--;
    REP(j, N-2) {
      int from = mp[make_pair(i, A[j])], to = mp[make_pair(i, A[j+1])];
      //cout << from << "->" << to << endl;
      scc.add_edge(from, to);
    }
  }

  if (scc.run() != cnt) {
    cout << -1 << endl;
    return 0;
  }

  vector<int> order(cnt);
  REP(i, cnt) order[scc.cmp[i]] = i;

  vector<int> dp(cnt, 0);

  for (int v : order) {
    for (int c : scc.G[v]) {
      dp[c] = max(dp[c], dp[v] + 1);
    }
  }

  cout << *max_element(ALL(dp)) + 1 << endl;
  return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

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

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

int d, g;
int p[10];
int c[10];
int dp[1010];

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

	cin >> d >> g;
	REP(i, d) cin >> p[i] >> c[i];

    REP(i, 1010) dp[i] = -1;
	dp[0] = 0;

    REP(i, d) {
		int sum[p[i]] = {};
		REP(j, p[i]) sum[j] = 100 * (i + 1) * (j + 1);
		sum[p[i] - 1] += c[i];
        for (int j = 1000 - p[i]; j >= 0; j--) {
			if (dp[j] == -1) continue;
			REP(k, p[i]) {
				dp[j + k + 1] = max(dp[j + k + 1], dp[j] + sum[k]);
			}
		}
	}
	REP(i, 1010) {
		if (dp[i] >= g) {
			cout << i << endl;
			break;
		}
	}

	return 0;
}



Measured memory_bytes: 256
function Main(input) {
	input = input.split(" ");
  
  	for(var i=0; i<3; i++){
      	input[i] = parseInt(input[i], 10);
      
      	if(input[i] == 5 || input[i] == 7){
      		continue;
    	}else{
      		console.log('NO');
          	return;
    	}
    }
  
  	var b = input[0] + input[1] + input[2];

  
  	if(b == 17){
      console.log('YES');
    }else{
      console.log('NO');
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t;
    cin >> s >> t;
    vector<vector<int32>> dp(s.size() + 1, vector<int32>(t.size() + 1, 0));
    REP(i,s.size())REP(j,t.size()){
        if(s[i] == t[j]){
            dp[i+1][j+1] = max({dp[i][j]+1, dp[i][j+1], dp[i+1][j]});
        }else{
            dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
        }
    }

    // REP(i,s.size() + 1){
    //     REP(j,t.size()+1){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    // cout << dp[s.size()][t.size()] << endl;

    string ans = "";
    int32 i = s.size();
    int32 j = t.size();
    int32 di[3] = {-1,-1,0};
    int32 dj[3] = {-1,0,-1};
    while(i > 0 && j > 0){
        bool flg = true;
        REP(k,3){
            int32 ni = i + di[k];
            int32 nj = j + dj[k];
            if(dp[ni][nj] == dp[i][j]){
                i = ni;
                j = nj;
                flg = false;
                break;
            }
        }
        if(flg){
            ans += s[i-1];
            i--;
            j--;
        }
    }
    reverse(ALL(ans));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);
#define endl "\n"
#define MAXN 100123
#define ll long long
#define ull unsigned long long
#define INF INT_MAX
#define FORE(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,n) FORE(i,0,n)
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define ps(v) push_back(v)
#define ms(v,x) memset(v,x,sizeof(v)) 
#define PI M_PI
using namespace std;

// cout << fixed << setprecision(4);

int n,t,cont;
ull v=100;

int main(){_
    ull x; cin >> x;

    while(v < x){
        v+=(ull)(v/100);
        cont++;
    }
    cout << cont << endl;
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
 
long long calc(int n, int c1, int c2, int s1, int s2, const vector<int>& options,
               int d, int nt, int ot) {
  int b1(d-1), a1(d+1), b2(d-1), a2(d+1);
  while (b1 >= 0 && options[b1] != nt) b1--;
  while (b2 >= 0 && options[b2] != ot) b2--;
  while (a1 < n && options[a1] != nt) a1++;
  while (a2 < n && options[a2] != ot) a2++;
  int x1(d-b1-1), y1(a1-d-1), z1(a1-b1-1), x2(d-b2-1), y2(a2-d-1), z2(a2-b2-1);
  int diff1 = z1*(z1+1)/2-x1*(x1+1)/2-y1*(y1+1)/2;
  int diff2 = z2*(z2+1)/2-x2*(x2+1)/2-y2*(y2+1)/2;
  return (long long) diff1 * c1 - (long long) diff2 * c2 + s1 - s2;
}
 
int main() {
  int n;
  cin >> n;
  vector<int> c(26), last(26, -1);
  vector<array<int, 26>> s(n);
  
  for (int i = 0; i < 26; ++i) cin >> c[i];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 26; ++j)
      cin >> s[i][j];
  
  long long total(0);
  vector<int> options(n);
  
  for (int i = 0; i < n; ++i) {
    int neg(0), test(-1), max_score(-1e9);
    for (int j = 0; j < 26; ++j) neg -= c[j] * (i - last[j]);
    for (int j = 0; j < 26; ++j) {
      int ss = s[i][j] + neg + c[j] * (i - last[j]);
      if (ss > max_score) {
        max_score = ss;
        test = j;
      }
    }
    total += max_score;
    options[i] = test;
    last[test] = i;
  }
  /*
  for (int t = 1; t <= 500; ++t) {
    bool entered = false;
    for (int dd = 0; dd < n; ++dd) {
      for (int tt = 0; tt < 26; ++tt) {
        if (tt == options[dd]) continue;
        int ot = options[dd];
        long long ns = calc(n, c[tt], c[ot], s[dd][tt], s[dd][ot],
                            options, dd, tt, ot);
        //cout << ns << endl;
        if (ns > 0) {
          entered = true;
          total += ns;
          options[dd] = tt;
    	}
      }
    }
    if (!entered) break;
  }*/
  // stochastic
   uniform_real_distribution<double> unif(0, 1);
   default_random_engine re;
   double a_random_double = unif(re);
  double tm;
  for (int t = 1; t <= 200000; ++t) {
    if (t % 100 == 1) {
      double db = unif(re);
      tm = pow(2e3, 1.0 - db) * pow(6e2, db);
    }
    int dd = rand() % n;
    int tt = rand() % 26;
    int ot = options[dd];
    while (ot == tt) tt = rand() % 26;
    long long ns = calc(n, c[tt], c[ot], s[dd][tt], s[dd][ot],
                        options, dd, tt, ot);
    if (ns < 0 && unif(re) > exp(ns) / tm) {
      options[dd] = ot;
    } else {
      total += ns;
    }
  }
  for (const int& i: options) cout << i + 1 << endl;
  
  return 0;
}

Measured memory_bytes: 4348
N = int(input())
A = [int(i) - 1 for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

print(sum(B) + sum([C[A[i - 1]] for i in range(1, N) if A[i] == A[i - 1] + 1]))


Measured memory_bytes: 3060
/*
    coder:xxjAc
    name:
    time:2017/9/2 
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#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;
const int INF=1000000007;
int n,ans=0,x;
int cont[100007];
int main(){
	scanf("%d",&n);
	for (int i=0;i<n;i++){
		scanf("%d",&x);
		cont[x]++;
		cont[x+1]++;
		cont[x+2]++;
		ans=max(ans,cont[x]);
		ans=max(ans,cont[x+1]);
		ans=max(ans,cont[x+2]);
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 640
#include<cstdio>

int main(){
    char str[105];
    char ptr[105];
    while(scanf("%s",str)!=EOF){
        int cnt = 0;
        for(int i=0;str[i];i++){
            if(str[i]=='B'){
                if(cnt)cnt--;
            }else ptr[cnt++] = str[i];
        }
        ptr[cnt] = 0;
        puts(ptr);
    }
    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 1000000002486618624LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  long long Q, H, S, D, N, q,h, s, d;

  std::cin >> Q >> H >> S >> D >> N;

  D =
    8 * Q < D ? 8 * Q :
    4 * H < D ? 4 * H :
    2 * S < D ? 2 * S : D;
  
  S =
    4 * Q < S ? 4 * Q :
    2 * H < S ? 2 * H : S;

  H =
    2 * Q < H ? 2 * Q : H;

  N *= 4;

  d = N / 8; N %= 8;
  s = N / 4; N %= 4;
  h = N / 2; N %= 2;
  q = N;

  long long sum = D * d + S * s + H * h + Q * q;

  std::cout << sum << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    int s=0, w=0, e=0, n=0;
    string S;
    cin >> S;
    for(int i=0;i<S.length(); i++){
        if(S[i]=='S')s+=1;
        else if(S[i]=='W')w+=1;
        else if(S[i]=='E')e+=1;
        else if(S[i]=='N')n+=1;
    }
    if(((s>=1 && n>=1) || (s==0 && n==0)) && ((w>=1 && e>=1) || (w==0 && e==0)))cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define mkp(a,b) make_pair(a,b)
const long long MOD = 1000000007;
const long long inf = 1ll<<61;
typedef pair<int, int> P;
typedef pair<int ,P> PP;
struct edge { int to; int to2; int cost; };
int x[55], y[55];
int a[100006];
int modpow(int x, int n, int mod) {
	if (!n)return 1;
	int res = modpow(x*x%mod, n / 2, mod);
	if (n & 1)res = res*x%mod;
	return res;
}

signed main() {
	int n; cin >> n;
	rep(i, n)cin >> a[i];
	sort(a, a + n);
	vector<int>X, Y;
	if (a[n - 1] <= 0) {
		for (int i = n - 1; i > 0; i--) {
			X.push_back(a[i]);
			Y.push_back(a[i - 1]);
			a[i - 1] = a[i] - a[i - 1];
		}
		cout << a[0] << endl;
		rep(i, n - 1)cout << X[i] << ' ' << Y[i] << endl;
	}
	else if (a[0] >= 0) {
		rep(i, n - 2) {
			X.push_back(a[i]);
			Y.push_back(a[i + 1]);
			a[i + 1] = a[i] - a[i + 1];
		}
		X.push_back(a[n - 1]);
		Y.push_back(a[n - 2]);
		a[n - 1] = a[n - 1] - a[n - 2];
		cout << a[n - 1] << endl;
		rep(i, n - 1)cout << X[i] << ' ' << Y[i] << endl;
	}
	else {
		int pos = 0;
		rep(i, n) {
			if (a[i] >= 0) {
				pos = i;
				break;
			}
		}

		for (int i = pos; i < n-1; i++) {
			X.push_back(a[0]);
			Y.push_back(a[i]);
			a[0] = a[0] - a[i];
		}
		X.push_back(a[n - 1]);
		Y.push_back(a[0]);
		a[0] = a[n - 1] - a[0];
		for (int i = 1; i < pos; i++) {
			X.push_back(a[0]);
			Y.push_back(a[i]);
			a[0] = a[0] - a[i];
		}
		cout << a[0] << endl;
		rep(i, n - 1)cout << X[i] << ' ' << Y[i] << endl;
	}
}

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

#ifdef DEBUG
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPS(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;

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

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


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N; cin >> N;
    if(N % 10 == 3) cout << "bon" << endl;
    else if(N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
}

Measured memory_bytes: 3608