akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define IOS std::cin.tie(0),std::ios::sync_with_stdio(false)

namespace idaten {

	using namespace std;
	using ll = int_fast64_t;
	using ull = uint_fast64_t;
	using P = std::pair<int64_t, int64_t>;
	template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
	template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
	template<class Type>struct is_vector : std::false_type {};
	template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
	template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
		if (v.empty())return out;
		constexpr bool is_vector_v = is_vector<T>::value;
		if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
		else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
		return out;
	}
	inline void put() {}
	template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
	template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
	inline void putn() {}
	template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

	void solve() {
		IOS;
		string s;
		cin >> s;
		REP(i, s.size()) {
			if (s[i] == '7') {
				put("Yes");
				return;
			}
		}
		put("No");
	}
} // namespace idaten

int main() {
	idaten::solve();
	return 0;
}


Measured memory_bytes: 3648
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, p: "List[int]"):
    p.sort()
    return sum(p[:-1]) + (p[-1] // 2)


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
    p = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    result = solve(N, p)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5140
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from collections import defaultdict
def resolve():
    N,=pin()
    a=defaultdict(lambda :0)
    for i in range(N):
        t=input()
        a[t]+=1
    M,=pin()
    for j in range(M):
        s=input()
        a[s]-=1
    t=(max(a.values()))          
    print(max(0,t))  
#%%submit!
resolve()

Measured memory_bytes: 38256
#include <bits/stdc++.h> //全てのヘッダファイルをインクルード
 
//ループ
#define rep(i, n) for(int i = 0; i < (n); i++) //普通のループ
#define repr(i, n) for(int i = n; i >= 0; i--) //逆ループ
 
//型名省略
typedef long long ll;
//値
static const ll MX = 100005;
static const ll MX_ll = 1e18;
const double PI = acos(-1); //π
 
using namespace std;
 
//ソート
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 
//#include "./lib/generic/search.h"

//文字列入力した小数値を小数点なくして返す
int changeDoubleToInt(string decimal){ 
    decimal.erase(1, 1); //小数点削除
    int n_decimal = atoi(decimal.c_str()); //c_strでchar*に変換後、atoiでintに変換
    return n_decimal;
}

//最大公約数
int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
}

//素数判定(True/Falseを返却)
int IsPrime_tf(ll num){
    if (num < 2) return false; //0、1は素数でない
    else if (num == 2) return true; //2は素数
    else if (num%2==0) return false; // 偶数はあらかじめ除く
    for (ll i = 3; i*i <= num; i += 2){ //チェックは2～√nで十分
        if (num % i == 0) return false; //素数でない
    }
    return true; //素数である
}

//素数判定(割れる値を返却)
ll IsPrime_value(ll num){
    if (num < 2) return -1; //0、1は素数でない
    else if (num == 2) return 2; //2は素数
    for (ll i = 2; i*i <= num; i += 1){ //チェックは2～√nで十分
        if (num % i == 0) return i; //素数でない
    }
    return num; //素数である
}

int main(){
   ll n, k;
   cin >> n >> k;
   vector<ll> p(n), c(n);
   rep(i,n) cin >> p[i];
   rep(i,n) cin >> c[i];
   rep(i,n) p[i]--;
   ll ans = -1e18;
   rep(si,n){
      int x = si; //現在のポジション
      vector<int> s;
      ll tot = 0;
      while(1){
          x = p[x];
          s.push_back(c[x]);
          tot += c[x];
          if(x==si) break; //元の位置に戻ってきた
      }
      int l = s.size(); //周期の流れ
      ll t = 0;
      rep(i,l){
          t += s[i];
          if(i+1 > k) break;
          ll now = t;
          if(tot > 0){ //1周期の値の合計が正
            ll e = (k-(i+1))/l; //l個で1周なので(k-i-1)/l周できる
            now += tot*e;
          }
          ans = max(ans, now);
      }
   }
   cout << ans << endl;
}

Measured memory_bytes: 3732
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
// #include <numeric> // gcdとかlcmとか C++17から
#include <time.h> // time_t timer; time(&timer); でtimerに現在時刻が代入される．
#include <unistd.h> // sleep関数．引数は秒単位．
using namespace std;

typedef long long ll;


// sortの仕方
// 	■ string s の場合
// 	昇順: sort(s.begin(), s.end())
// 	降順: sort(s.rbegin(), s.rend())
//
// 	■ ll a[N] の場合
// 	昇順: sort(a, a+N)
// 	降順: 不明

// vector の使い方
// 宣言：
// vector<int> v;
// vector<int> v(N);
// 初期化:
// vector<int> v(10, 5); 要素数10，全ての要素の値5．
// vector<int> v = {1, 2, 3};
// 代入：
// v[0] = 3;
// sort:
// sort(v.begin(), v.end());
//

// int alph2int(char character) {
//     int x = character - 'a';
//     return x;
// }

ll my_gcd(ll a, ll b){
	return (b==0) ? a : my_gcd(b, a%b);
}

ll my_lcm(ll a, ll b){
	return a*b / my_gcd(a,b);
}

ll factorial(ll a){
	ll ans = 1;
	for(ll i=a; i>0; i--){
		ans *= i;
	}
	return ans;
}

ll pow(ll a, ll b) {
	ll a_powered = 1;
	for (int i=0; i<b; i++) {
		a_powered *= a;
	}
	return a_powered;
}


int main(int argc, char *argv[]){
    int N;
    cin >> N;
    int H[N];
    for(int i=0; i<N; i++){
        cin >> H[i];
    }

    int ans = 0;
    for(int i=0; i<N; i++){
        bool flag = true;
        for(int j=0; j<i; j++){
            if(H[j] > H[i]){
                flag = false;
            }
        }

        if(flag == true) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] arr = sc.next().toCharArray();
        int length = arr.length;
        long[][] dp = new long[length + 1][2];
        dp[0][0] = 1;
        for (int i = 1; i <= length; i++) {
            if (arr[i - 1] == '1') {
                dp[i][0] = dp[i - 1][0] * 2 % MOD;
                dp[i][1] = (dp[i - 1][0] + dp[i - 1][1] * 3) % MOD;
            } else {
                dp[i][0] = dp[i - 1][0];
                dp[i][1] = (dp[i - 1][1] * 3) % MOD;
            }
        }
        System.out.println((dp[length][0] + dp[length][1]) % MOD);
    }
}

Measured memory_bytes: 42972
n, m = map(int, input().split())
road_lst = [0 for i in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    road_lst[a-1] += 1
    road_lst[b-1] += 1

for i in range(n):
    print(road_lst[i])


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main() {
ll N, Ans = 0, a;cin >> N;
map<int, int> M;

rep(i, 0, N){
cin >> a;
M[a]++;
}

for(auto x : M){
if(x.first > x.second)Ans += x.second;
else Ans += x.second - x.first;
}
cout << Ans;
}

Measured memory_bytes: 8072
from itertools import accumulate

N, C = map(int, input().split())
STC = [list(map(int, input().split())) for _ in range(N)]

channels = [[0]*(10**5+1) for _ in range(C)]
for s, t, c in STC:
    # print((s, t))
    s, t, c = s-1, t-1, c-1
    channels[c][s] += 1
    channels[c][t] -= 1
all_channels = [0]*(10**5+1)
for channel in channels:
    # print(channel)
    for j, x in enumerate(channel):
        if x == 1:
            all_channels[j] += 1
        if x == -1:
            all_channels[j+1] -= 1 


a = list(accumulate(all_channels))
# print(a)

print(max(a))

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

int main() {
  long long N,D,A,g,f,p,t,u,ans,v,n,c;
  cin >>N>>D>>A;
  vector<pair<long long,long long>>a(N);
    for(int i=0;i<N;i++){
      cin>>g>>f;
      a[i]=make_pair(g,f);
    }
  sort(a.begin(),a.end());
  p=0;
  t=0;
  u=0;
    v=max(a[u].second,max(a[p].second,a[N-1].second));
  n=0;
  c=0;
  ans=0;
  while(v>0){
    if(a[t].first+2*D>=a[N-1].first){

      for(int i=t;i<N;i++){
        c=max(c,a[i].second);
      }
            n=c/A;
        if(c%A!=0){
        	n++;
    	}
      ans+=n;
      break;
    }
    for(int i=t;i<N;i++){
      if(i==t){
      n=a[i].second/A;
        if(a[i].second%A!=0){
        	n++;
    	}
        n*=A;
      }
      if(a[i].first<=a[t].first+2*D){
        if(a[i].second<=0){
          continue;
        }
      	a[i].second-=n;
        if(c==1){
          continue;
        }
        	if(a[i].second>0){
          		c=1;
          		p=i;
        }
        continue;
      }
      u=i;
      break;
    }
    ans+=n/A;
    if(c==0){
      t=u;
    }
    else{
      t=p;
    }
    c=0;
    v=max(a[u].second,max(a[p].second,a[N-1].second));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  int counter = 0;
  if (s[0] == '1') ++counter;
  if (s[1] == '1') ++counter;
  if (s[2] == '1') ++counter;
  cout << counter << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>


using ll = long long;


using namespace std;


ll gcd(ll x, ll y)
{
    ll r;
    if (x < y)
        swap(x, y);

    while (y > 0) {
        r = x % y;
        x = y;
        y = r;
    }
    return x;
}


int main()
{
    ll N;
    cin >> N;
    vector<ll> L(N + 2);
    vector<ll> R(N + 2);
    vector<ll> A(N + 2);

    for (ll i = 1; i <= N; i++) {
        cin >> A[i];
    }

    L[0] = L[N + 1] = 0;
    R[0] = R[N + 1] = 0;

    for (ll i = 1; i <= N; i++) {
        L[i] = gcd(L[i - 1], A[i]);
    }

    for (ll i = N; i >= 1; i--) {
        R[i] = gcd(R[i + 1], A[i]);
    }

    ll ans = 1;
    for (ll i = 1; i <= N; i++) {
        ll tmp = gcd(L[i - 1], R[i + 1]);
        ans = max(ans, tmp);
    }

    cout << ans << endl;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://onlinejudge.u-aizu.ac.jp/challenges/search/volumes/0299>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll solve(){
    ll res = LINF;
    ll N,M,p; cin >> N >> M >> p;
    vector<ll> d(M); for(auto& in:d) cin >> in;
    sort(d.begin(),d.end());
    
    ll m = upper_bound(d.begin(),d.end(),p) -d.begin();
    
    ll li = m - 1;
    if(li == -1) li = M-1;
    ll ri = m;
    if(ri == M) ri = 0;

    res = min(res,(N+d[li])-p);
    res = min(res,(N+p)-d[ri]);
    for(int i = 0; i < M;i++){
        ll T = 0;
        
        ll next = (i+1)%M;
        ll pre = (i-1+M)%M;

        if(d[i] > p){
            if(i == M-1){
                T = (d[i]-p) + (d[i] - d[next]);
            }else{
                T = (d[i]-p) + (d[i] - (d[next]-N));
            }
            res = min(res,T);
            
            //ll td = d[i] - N;
            //T = (p - td) + (d[pre] - td);
            res = min(res,T);
        }else{
            if(i == 0){
                T = (p-d[i]) + (d[pre] - d[i]);
            }else{
                T = (p-d[i]) + ((N+d[pre]) - d[i]);
            }
            res = min(res,T);
            
           // ll td = d[i] + N;
           // T = (td-p) + (td - d[next]);
            res = min(res,T);
        }
    }
    return res*100;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}



Measured memory_bytes: 3216
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import fractions
import random
from functools import lru_cache
from heapq import heappop,heappush
import time
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s

#main
n=int(input())
#A,B,C=map(int,input().split())
A=list(map(int,input().split()))

f=True
for a in A:
    if(a%2==0):
        if(not (a%3==0 or a%5==0)):
            f=False
if f:
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 65900
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        PrintWriter out = new PrintWriter(System.out);
        Scanner sc = new Scanner(System.in);
        Task task = new Task();
        task.solve(sc, out);
        out.flush();
        sc.close();
    }
    static class Task{
        public void solve(Scanner sc, PrintWriter out){
            String str1 = nstr(sc);
            String str2 = nstr(sc);
            String str3 = nstr(sc);

            StringBuilder sb = new StringBuilder();
            sb.append(str1.charAt(0));
            sb.append(str2.charAt(1));
            sb.append(str3.charAt(2));
            out.println(sb.toString());

        }
    }

    static int nint(Scanner sc){
        return Integer.parseInt(sc.next());
    }
    static long nlong(Scanner sc){
        return Long.parseLong(sc.next());
    }
    static double ndouble(Scanner sc){
        return Double.parseDouble(sc.next());
    }
    static float nfloat(Scanner sc){
        return Float.parseFloat(sc.next());
    }
    static String nstr(Scanner sc){
        return  String.valueOf(sc.next());
    }
    static long[] longLine(Scanner sc, int size){
        long[] lLine = new long[size];
        for (int i = 0; i < size; i++) {
            lLine[i] = nlong(sc);
        }
        return lLine;
    }
    static int[] intLine(Scanner sc, int size){
        int[] iLine = new int[size];
        for (int i = 0; i < size; i++) {
            iLine[i] = nint(sc);
        }
        return iLine;
    }
    static String[] strLine(Scanner sc, int size){
        String[] strLine = new String[size];
        for (int i = 0; i < size; i++) {
            strLine[i] = nstr(sc);
        }
        return strLine;
    }
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <vector>
#include <utility>
using namespace std;

constexpr int kN = int(1E5 + 10);

#define PB push_back
#define F first
#define S second

vector<int> graph[kN];
vector<pair<int, int>> que[kN];
int p[kN], ans[kN];
bool went[kN];

int Find(int n) {return p[n] == n ? n : p[n] = Find(p[n]);}

void dfs(int pos) {
	went[pos] = true;
	for (int i : graph[pos]) {
		dfs(i);
		p[i] = pos;
	}
	for (pair<int, int> i : que[pos]) if (went[i.F]) ans[i.S] = Find(i.F);
	return ;
}

int main() {
	int n, k, l, r, tmp, q;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &k);
		while (k--) {
			scanf("%d", &tmp);
			graph[i].PB(tmp);
		}
	}
	
	for (int i = 0; i < n; i++) p[i] = i;
	for (int i = 0; i < n; i++) went[i] = false;

	scanf("%d", &q);
	for (int i = 0; i < q; i++)	{
		scanf("%d%d", &l, &r);
		que[l].PB({r, i});
		que[r].PB({l, i});
	}

	dfs(0);

	for (int i = 0; i < q; i++) printf("%d\n", ans[i]);
}



Measured memory_bytes: 19624
#include <stdio.h>

int main(void)
{
    int A, B, sum, i, t;
    t = -1;

    scanf("%d", &A);
    scanf("%d", &B);

    sum = (B * 10);

    for(i = 0; i <= 9; i++) {
        if(((int)((sum + i) * 0.08)) == A)
            t = sum + i;
        if(t != -1)
            break;
    }

    printf("%d", t);

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<queue>
#include<cstring>

void putblock(int x,int y,int c,int d);
bool bfs(std::pair<int,int> start,std::pair<int,int> goal);

std::queue< std::pair<int,int> > que;
int board[102][102];
bool visited[102][102];

int main()
{
	int n,w,h,x,y,c,d,xs,ys,xg,yg;
	
	while(1)
	{
		while(!que.empty()){que.pop();}
		memset(board,0,sizeof(board));
		memset(visited,0,sizeof(visited));
		std::cin>>w>>h;
		if(w==0&&h==0)break;
		std::cin>>xs>>ys>>xg>>yg>>n;
		for(int i=0;i<n;i++)
		{
			std::cin>>c>>d>>x>>y;
			putblock(x,y,c,d);
		}

		if(bfs(std::pair<int,int>(xs,ys),std::pair<int,int>(xg,yg)))
		{
			std::cout<<"OK"<<std::endl;
		}
		else
		{
			std::cout<<"NG"<<std::endl;
		}
	}
	return 0;
}

void putblock(int x,int y,int c,int d)
{
	int h,w;
	if(d==0)
	{
		h=2;
		w=4;
	}
	else
	{
		h=4;
		w=2;
	}
	for(int i=y;i<y+h;i++)
	{
		for(int j=x;j<x+w;j++)
		{
			board[i][j]=c;
		}
	}
}

bool bfs(std::pair<int,int> start,std::pair<int,int> goal)
{
	int x,y;
	if(board[start.second][start.first]==0||board[goal.second][goal.first]==0)return false;
	
	que.push(start);
	while(!que.empty())
	{
		x=que.front().first;
		y=que.front().second;
		que.pop();
		visited[y][x]=true;

		if(x==goal.first&&y==goal.second)
		{
			return true;
		}

		if(board[y][x]==0){std::cin.get();}

		if(board[y-1][x]==board[y][x]&&!visited[y-1][x])que.push(std::pair<int,int>(x,y-1));
		if(board[y+1][x]==board[y][x]&&!visited[y+1][x])que.push(std::pair<int,int>(x,y+1));
		if(board[y][x-1]==board[y][x]&&!visited[y][x-1])que.push(std::pair<int,int>(x-1,y));
		if(board[y][x+1]==board[y][x]&&!visited[y][x+1])que.push(std::pair<int,int>(x+1,y));

	}
	return false;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

bool M[101] = { false };
int main() {
	int N; cin >> N;
	rep(i, 0, N) {
		int d; cin >> d;
		M[d] = true;
	}
	int cnt = 0;
	rep(i, 0, 102) {
		if (M[i]) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int a,b,aa[110000],ab[110000],cnt=0;
string s;
signed main()
{
	cin>>a;
	rep(i,a+1){
		cin>>aa[i];
	}
	rep(i,a){
		cin>>ab[i];
		if(ab[i]<=aa[i]){
			cnt+=ab[i];
			aa[i]-=ab[i];
		}else{
			cnt+=aa[i];
			ab[i]-=aa[i];
			aa[i]=0;
			if(aa[i+1]>=ab[i]){
				cnt+=ab[i];
				aa[i+1]-=ab[i];
			}else{
				cnt+=aa[i+1];
				aa[i+1]=0;
			}
		}
	}
	cout<<cnt;
}

Measured memory_bytes: 1920
fun main(args: Array<String>) {
  val (N, K) = readInts()

  var tmp = K.toLong()
  var cnt = 1
  while (N > tmp - 1) {
    tmp *= K
    cnt++
  }
  println(cnt)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLong() = readString().toLong()
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 36156
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define sz size()
using namespace std;
typedef pair<int,int> pii;

struct Node{
  int id,left,right;
  Node(int a,int b,int c):id(a),left(b),right(c){}
};

pii sim[200];
int shape_id[200];
set<int> shapes[200];
map<pii,int> shape_hash;

inline int construct(const string &s, int &p, vector<Node> &tree){
  if(s[p] == 'x'){
    tree.pb( Node(tree.sz, -1, -1) );
  }else if(s[p] == '('){
    int lid = construct(s, ++p, tree), rid = construct(s, ++p, tree);
    tree.pb( Node(tree.sz, lid, rid) );
  }
  ++p;
  return tree.sz-1;
}

inline void cal_sim(int v, const vector<Node> &tree){
  shapes[v].clear();

  if(tree[v].left<0){
    shape_id[v] = 0;
    shapes[v].insert(0);

    sim[v] = pii(0,1);
  }else{
    int l = tree[v].left, r = tree[v].right;
    cal_sim(l,tree); cal_sim(r,tree);
    for(int x : shapes[l])shapes[v].insert(x);
    for(int x : shapes[r])shapes[v].insert(x);

    pii new_shape = pii(shape_id[l], shape_id[r]);
    if(new_shape.first > new_shape.second)swap(new_shape.first, new_shape.second);
    int new_id;
    if(shape_hash.find(new_shape)!=shape_hash.end())new_id = shape_hash[new_shape];
    else{
      new_id = shape_hash.sz + 1;
      shape_hash[new_shape] = new_id;
    }
    shape_id[v] = new_id;
    shapes[v].insert(new_id);

    int cnt = 0;
    for(int x : shapes[l]){
      if(shapes[r].find(x) != shapes[r].end())cnt++;
    }
    sim[v] = pii(cnt,shapes[v].sz-1);
  }
}

//-1: a<b, 0:a==b, 1: a>b
unordered_map<int,int> memo;
inline int cmp_node(int a, int b, const vector<Node> &tree){
  int key = a*200+b;
  if(memo.count(key))return memo[key];
  int res = 0;

  int dif = sim[a].first*sim[b].second - sim[b].first*sim[a].second;
  if(dif!=0){
    if(dif<0)res = 1;
    else res = -1;
  }else if(tree[a].left<0 && tree[b].left<0){
    res = 0;
  }else{
    int al = tree[a].left, ar = tree[a].right;
    if(cmp_node(al,ar,tree)<0)swap(al,ar);
    int bl = tree[b].left, br = tree[b].right;
    if(cmp_node(bl,br,tree)<0)swap(bl,br);
    
    res = cmp_node(al,bl,tree);
    if(res == 0)res = cmp_node(ar,br,tree);
  }
  return memo[key] = res;
}

inline void transform(int v, vector<Node> &tree, bool is_lc){
  if(tree[v].left<0)return;
  if(is_lc && (cmp_node(tree[v].left, tree[v].right, tree) < 0)){
    swap(tree[v].left, tree[v].right);
  }
  if(!is_lc && (cmp_node(tree[v].left, tree[v].right, tree) > 0)){
    swap(tree[v].left, tree[v].right);
  }
  transform(tree[v].left, tree, true);
  transform(tree[v].right, tree, false);
}

inline string encode(int v, const vector<Node> &tree){
  if(tree[v].left<0)return "x";
  return "(" + encode(tree[v].left,tree) +  " " +  encode(tree[v].right,tree) + ")";
}

int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  string s;
  while(getline(cin,s)){
    if(s == "0")break;
    vector<Node> tree;
    int p = 0;
    construct(s,p,tree);

    shape_hash.clear();
    cal_sim(tree.sz-1,tree);

    memo.clear();
    transform(tree.sz-1,tree,true);

    cout << encode(tree.sz-1,tree) << endl;
  }
}

Measured memory_bytes: 1368
#   A C G T
# A
# C
# G
# T

import numpy as np

N = int(input())
x = 10 ** 9 + 7

S = np.ones([4, 4, 4], dtype=np.int64)
S[0, 1, 2] = 0
S[0, 2, 1] = 0
S[2, 0, 1] = 0
for _ in range(3, N):
    St = np.zeros([4, 4, 4], dtype=np.int64)
    for i in range(4):
        for j in range(4):
            if i == 0 and j == 2:
                St[j, :, 0] += S[i, j, :]
                St[j, :, 2] += S[i, j, :]
                St[j, :, 3] += S[i, j, :]
            else:
                for k in range(4):
                    St[j, k, 0] += S[i, j, k]
                    St[j, k, 3] += S[i, j, k]
                    if j == 0 and k == 1:
                        St[j, k, 1] += S[i, j, k]
                    elif (j == 0 and k == 2) or (j == 2 and k == 0):
                        St[j, k, 2] += S[i, j, k]
                    elif i == 0 and k == 2:
                        St[j, k, 2] += S[i, j, k]
                    else:
                        St[j, k, 1] += S[i, j, k]
                        St[j, k, 2] += S[i, j, k]
    S = St % x
print(np.sum(S) % x)


Measured memory_bytes: 12524
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
 
int main()
{
    int n,s=0,c=0; 
    double a,x[64],y[64];
 
    while(cin >> n, n)
    {
        c++;
        for(int i=0; i<n; i++)
        {
            cin >> x[i] >> y[i];
        }
 
        a=0;
        for(int i=0; i<n; i++)
        {
            a += x[i]*y[(i+1)%n] - x[(i+1)%n]*y[i];
        }
 
        printf("%d %.1lf\n",c,abs(a)/2);
    }
}

Measured memory_bytes: 1244
N,M = map(int,input().split())
A = set([]); MOD = pow(10,9)+7
for i in range(M):
  a = int(input())
  A.add(a-1)
dp = [[0]*2 for _ in range(N)] #dp[i][j] i段目(0index)にj=0最後1段でj=1最後2段できた。
if 0 not in A:
  dp[0][0] = 1
if N == 1:
  print(sum(dp[0]))
  exit()
if 1 not in A:
  dp[1][0] = dp[0][0]+dp[0][1]
  dp[1][1] = 1
for i in range(2,N):
  if i in A:
    continue
  dp[i][0] = (dp[i-1][0]+dp[i-1][1])%MOD
  dp[i][1] = (dp[i-2][0]+dp[i-2][1])%MOD
ans = sum(dp[N-1])%MOD
#print(dp)
print(ans)

Measured memory_bytes: 24928
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 200005;
ll A[MAX_N];

ll f(ll m,int N)
{
	ll res = 0;
	rep(i,N)
	{
		res += abs(A[i]-m);
	}
	return res;
}

int main()
{
	int N;
	cin >> N;
	rep(i,N)
	{
		cin >> A[i];
		A[i] -= i+1;
	}
	sort(A,A+N);
	ll ans = 0;
	if (N % 2 == 1)
	{
		ll m = A[N/2];
		ans = f(m,N);
	}
	else
	{
		if ((A[N/2-1]+A[N/2]) % 2 == 0)
		{
			ans = f((A[N/2-1]+A[N/2]) / 2,N);
		}
		else
		{
			ans = min(f(A[N/2-1],N),f(A[N/2],N));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5168
//
//  CPlibrary
//
//  Created by Tanmay Singh on 3/03/2020.
// INDIAN INSTITUTE OF TECHNOLOGY (BHU) , VARANASI
//  Copyright © 2020 Tanmay Singh. All rights reserved.
//#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
 
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <climits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
 
#define FAST(); ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define mod 1000000007
typedef long long int  bigint ;
typedef std::vector< int > vi;
typedef std::vector< long long int > vll;
typedef std::vector< vi > vvi;
 
using namespace std;

int main(){
    FAST() ;
    int N ; cin >> N ;
    set<int> s ;
    for( int i = 0 ; i < N ; i++ ){
        int x ; cin >> x ;
        if( s.find(x) != s.end() ){
            s.erase(x) ;
        }
        else
            s.insert(x) ;
    }
    cout << s.size() << endl ;
    return 0 ;
}

Measured memory_bytes: 4992
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.ArrayDeque;
import java.util.Queue;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

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

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			String w = in.next();
			int total;
			String ans = "Yes";
			for(int i = 0; i < w.length(); i++) {
				total = 0;
				for(int j = 0; j < w.length(); j++) {
					if(w.charAt(i) == w.charAt(j)) {
						total++;
					}
				}
				if(total % 2 != 0) {
					ans = "No";
					break;
				}
			}
			out.println(ans);
		}
	}
	
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

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

	}
}


Measured memory_bytes: 22996
#include <algorithm>
#include <cmath>
#include <iostream>
#include <deque>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int odd = (n + 1) / 2;
	printf("%f",(static_cast<double>(odd) / n));
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int N = scanner.nextInt();
        int[] A = new int[N];
        for(int i = 0; i < N; i++) A[i] = scanner.nextInt();
        int hi = N;
        int lo = 1;
        while(hi >= lo){
            int mid = (hi + lo)/2;
            if (check(A, mid, N)) hi = mid-1;
            else lo = mid + 1;
        }
        out.println(lo);
        out.flush();
    }
    
    static boolean check(int[] A, int mid, int N) {
        TreeMap<Integer, Integer> mapping = new TreeMap<>();
        mapping.put(-1, mid);
        for(int i = 0; i < N; i++) {
            Integer maxBelow = mapping.lowerKey(A[i]);
            if (maxBelow == null) return false;
            mapping.put(maxBelow, mapping.get(maxBelow)-1);
            if (mapping.get(maxBelow) == 0) mapping.remove(maxBelow);
            if (!mapping.containsKey(A[i])) mapping.put(A[i], 0);
            mapping.put(A[i], mapping.get(A[i]) + 1);
        }
        return true;
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        
        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
    }
}


Measured memory_bytes: 116424
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define ii pair<int,int>
#define MAX 1000000007
using namespace std;

int main(void){
  string s;
  cin >> s;
  int n = s.length();
  bool flag = true;

  rep(i,n){
	if(s[i] != s[n-1-i]) flag = false;
  }

  for(int i=0;i<(n-1)/2;i++){
	//cout << s[i] << "," << s[(n-1)/2-1-i] << endl;
	if(s[i] != s[(n-1)/2-i-1])flag = false;
	//cout << s[(n+3)/2+i-1] << "," << s[n-1-i] << endl;
	if(s[(n+3)/2+i-1] != s[n-1-i])flag = false;
  }

  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        x: u32,
    }
    if x == 1 {
        println!("1");
        return;
    }
    let mut res = 0;
    for i in 2u32..1000 {
        for j in 2u32..1000 {
            let p = i.pow(j);
            if p > x {
                break;
            }
            res = std::cmp::max(res, p);
        }
    }
    println!("{}", res);
}


Measured memory_bytes: 4352
#include<iostream>
#include<stdio.h>
#include<cctype>
#include<cstring>
#include<string>
using namespace std;
int main(){
    int h=0,m=0;
    string s,p;
    while(1){
        cin >> s >> m;
        if(s == "-")break;
        
        for(int i=0;i<m;i++){
            cin >> h;
            p = s.substr(0,h);
            s = s.erase(0,h);
            s += p;
        }
        cout << s << endl;
    }
}


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

const int kColors = 8;

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

  int count[kColors + 1] {};
  for (int i = 0; i < n; ++i) {
    int p;
    cin >> p;
    if (p >= kColors * 400) {
      ++count[kColors];
    } else {
      count[p / 400] = 1;
    }
  }

  int min_colors = accumulate(count, count + kColors, 0);
  int max_colors = min_colors + count[kColors];

  if (min_colors == 0)
    min_colors = 1;
  // if (max_colors > kColors)
  //   max_colors = kColors;
  cout << min_colors << " " << max_colors << "\n";

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
typedef struct{
  char moji;
  int su;
}to;
int antei(to *,to *,int);

to *bubblesort(to *,int);
  
to *selectsort(to *,int);

int main(){
	char c;
  int n,i,d;
  to *a,*b;
  scanf("%d",&n);
  a=(to *)malloc(sizeof(to)*n);
  b=(to *)malloc(sizeof(to)*n);
  for(i=0;i<n;i++){
    scanf(" %c%d",&a[i].moji,&a[i].su);
	b[i].su=a[i].su;
	b[i].moji=a[i].moji;
  }
  b=bubblesort(b,n);
  a=selectsort(a,n);
  if(0==antei(a,b,n))printf("Not stable\n");
  else printf("Stable\n");
  free(a);
  free(b);
  return 0;
}

int antei(to *a,to *b,int n){
  int i,j,c,d;
  for (i = 0;i<n;i++){
    for (j=i+1;j<n;j++){
      for (c = 0;c<n;c++){
	for (d=c+1;d<n;d++){
	  if (a[i].su==a[j].su&& a[i].moji == b[d].moji && a[j].moji == b[c].moji && a[i].su==b[d].su && a[j].su==b[c].su)return 0;
	}
      }
    }
  }
  return 1;
}

to *bubblesort(to *a,int n){
  int i,j,b;
  char c;
  
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(a[j].su<a[j-1].su){
	b=a[j].su;
	a[j].su=a[j-1].su;
	a[j-1].su=b;
	c=a[j].moji;
	a[j].moji=a[j-1].moji;
	a[j-1].moji=c;
      }
    }
  }
  for(i=0;i<n;i++){
    if(i==n-1)printf("%c%d\n",a[i].moji,a[i].su);
    else printf("%c%d ",a[i].moji,a[i].su);
  }
  printf("Stable\n");
  return a;
}

to *selectsort(to *a,int n){
  int mini,i,j,b;
  char c;
  for(i=0;i<n;i++){
  	mini=i;
  	for(j=i;j<n;j++){
    	if(a[j].su<a[mini].su){
			mini=j;	
      	}
    }
	if(mini!=i){
	b=a[mini].su;
    a[mini].su=a[i].su;
    a[i].su=b;
    c=a[mini].moji;
    a[mini].moji=a[i].moji;
    a[i].moji=c;
	}
  }
  for(i=0;i<n;i++){
    if(i==n-1)printf("%c%d\n",a[i].moji,a[i].su);
    else printf("%c%d ",a[i].moji,a[i].su);
  }
  return a;
}



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

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

    string ans;
    ll x = c - a - b;
    ll l = 4 * a * b;
    ll r = x * x;
    if (l < r && x >= 0) ans = "Yes";
    else ans = "No";

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
mod=10**9+7
MAX=2*10**5+100

g1=[1,1]
g2=[1,1]
for i in range(2,MAX+1):
    num_1=g1[-1]*i%mod
    g1.append(num_1)
    g2.append(pow(num_1,mod-2,mod))
    
def cmb(n,r):
    return g1[n]*g2[r]*g2[n-r]%mod


N,M,K=map(int,input().split())

ans=0
for t in range(1,M):
    ans=(ans+t*(N**2)*(M-t))%mod
for t in range(1,N):
    ans=(ans+t*(M**2)*(N-t))%mod

print(ans*cmb(N*M-2,K-2)%mod)

Measured memory_bytes: 66800
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

template<class T = lint>
struct Edge {
	int to;
	T cost;
	Edge() {}
	Edge(int to, T cost) : to(to), cost(cost) {}
	bool operator>(const Edge &r) const { return this->cost > r.cost; }
};

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	int u, v;
	vector<int> start(N);
	vector<vector<Edge<int>>> edges(N);
	for (int i = 0; i < N - 1; i++) {
		cin >> u >> v;
		u--, v--;
		edges[u].emplace_back(v, 0);
		edges[v].emplace_back(u, 0);
		start[u]++, start[v]++;
	}

	vector<int> cost(N);
	for (int i = 0; i < N; i++) cin >> cost[i];
	sort(cost.begin(), cost.end(), greater<int>());

	int st_idx = max_element(start.begin(), start.end()) - start.begin();

	vector<int> visted(N);
	queue<int> V;
	V.push(st_idx);
	int now, cnt = 0;;
	while (!V.empty()) {

		now = V.front();
		V.pop();
		visted[now] = cost[cnt];
		cnt++;

		for (const auto &elem : edges[now]) if (!visted[elem.to]) V.push(elem.to);

	}

	lint sum = 0;
	for (int i = 1; i < N; i++) sum += cost[i];
	cout << sum << "\n";

	for (const auto &e : visted) cout << e << " ";

	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<stack>
#include<queue>
#include<sstream>
#include<string>
#include<set>
#include<array>
#include<cassert>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i);

using namespace std;

const int MAX=101;
const int INF=1<<29;

int dp[MAX][MAX];
int n;
int c[MAX];
int r[MAX];

int main(){

	fill_n((int *)dp,sizeof(dp)/sizeof(int),INF);
	fill_n((int *)r,sizeof(r)/sizeof(int),0);
	fill_n((int *)c,sizeof(c)/sizeof(int),0);

	cin >> n;

	rep(i,n){
		cin >> r[i] >> c[i];	
	}

	rep(i,n){
		dp[i][i+1] = 0;
	}

	for(int R=2;R<=n;R++){
		for(int L=0;L+R-1<n;L++){
			for(int M=L+1;M<=L+R-1;M++){
				dp[L][L+R] = min(dp[L][L+R],dp[L][M] + dp[M][L+R] + (r[L] * c[M-1] * c[L+R-1]));
			}
		}
	}

	cout << dp[0][n] << endl;

}

Measured memory_bytes: 1200
/*************************************************************************
> File Name: test.cpp
> Author: Akira 
> Mail: qaq.febr2.qaq@gmail.com 
************************************************************************/

#include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
#define ALL(a) a.begin(), a.end()
#define mp make_pair
#define pb push_back
using namespace std;                                                                                              

#define MaxN 100005
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
const int mod = 1E9+7;
const double eps = 1e-6;
#define bug cout<<88888888<<endl;
#define debug(x) cout << #x" = " << x << endl;
template<typename T> T abs(T val){return val>0?val:-val;}
inline int max2(int a, int b) {return ((a > b)? a : b);}
inline int min2(int a, int b) {return ((a < b)? a : b);}
inline int max3(int a, int b, int c) {return max2(a, max2(b, c));}
inline int min3(int a, int b, int c) {return min2(a, min2(b, c));}
template <class T> inline void read(T &ret) {char c; ret=0;while((c=getchar())<'0'||c>'9');while(c>='0'&&c<='9') ret=ret*10+(c-'0'),c=getchar();}
template <class T> inline void out(T x) {if(x>9) out(x/10);putchar(x%10+'0');}

int X,K,a[MaxN],Q,t,w;

int main()
{
    //std::ios::sync_with_stdio(false);
    while(~scanf("%d%d",&X, &K))
    {
        for(int i=1;i<=K;i++)  read(a[i]);
        scanf("%d", &Q);
        int it = 0, Add = 0, l=0, r=X;
        bool flag = 0;
        while(Q--) 
        {
            scanf("%d%d", &t, &w);
            while(it + 1 <=K && a[it + 1] <= t) 
            {
                if (flag == 0) {
                    Add -= a[it + 1] - a[it];
                } else {
                    Add += a[it + 1] - a[it];
                }
                if (Add < 0) {
                    l -= Add;
                    Add = 0;
                }
                if (Add + r - l > X) {
                    r -= Add + r - l - X;
                    Add = X - r + l;
                }
                if (l > r) {
                    l = r = 0;
                    if (Add > X) Add = X;
                }
                flag ^= 1;
                it++;
            }
            int res = t - a[it];
            if (w < l) w = l;
            if (w > r) w = r;
            w = w + Add - l;
            if (flag == 0)
                w -= res;
            else
                w += res;
            if (w < 0) w = 0;
            if (w > X) w = X;
            printf("%d\n", w);
        }    
    }
    // system("pause");
    //printf("%lld\n", ((x)%mod+mod)%mod );
    //printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
}


Measured memory_bytes: 1536
#include <stdio.h>

int main() {
	int a, b, x, akex, bkex;
	
	scanf("%d %d %d", &x, &a, &b);
	
	akex=x-a;
	bkex=x-b;
	
	if(akex<0){
		akex*=-1;
	}
	
	if(bkex<0){
		bkex*=-1;
	}
	
	if(akex>>bkex){
		printf("A");
	}
	
	else if(akex<<bkex){
		printf("B");
	}
	
	return 0;
}

Measured memory_bytes: 1624
use std::io::{self, BufRead};

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let line = lines.next().unwrap().unwrap();
  let n: i32 = line.parse().unwrap();
  let mut memo = vec![vec![0; 9]; 9];
  for i in 1..(n+1) {
    let si = format!("{}", i);
    let z: usize = (0..(si.len()-1)).map(|_| 10).product();
    let most: usize = i as usize / z;
    let least: usize = i as usize % 10;
    if least == 0 {
      continue;
    }
    memo[most-1][least-1] += 1;
  }
  let mut count = 0;
  for i in 0..9 {
    for j in 0..9 {
      count += memo[i][j] * memo[j][i];
    }
  }
  println!("{}", count);
}

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

bool check(vector<P> s) {
  int h = 0;
  for (P p : s) {
    int b = h + p.first;
    if (b < 0) return false;
    h += p.second;
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  vector<P> ls, rs;
  int total = 0;
  rep(i, n) {
    string s;
    cin >> s;
    int h = 0, b = 0;
    for (char c : s) {
      if (c == '(')
        ++h;
      else
        --h;
      b = min(b, h);
    }
    if (h > 0)
      ls.emplace_back(b, h);
    else
      rs.emplace_back(b - h, -h);
    total += h;
  }
  sort(ls.rbegin(), ls.rend());
  sort(rs.rbegin(), rs.rend());
  if (check(ls) && check(rs) && total == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 18864
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <cstdio>

using namespace std;

int main() {
	double pai = 3.141592653589793;

	int N, M;
	cin >> N >> M;
	
	int home[10020];
	home[0] = 0;
	for (int i = 1; i <= M; ++i) {
		cin >> home[i];
	}

	int64_t sum = 0;

	for (int i = 1; i <= M; ++i) {
		sum += home[i];
	}

	if (N - sum < 0) {
		cout << -1 << endl;
	}
	else cout << N - sum << endl;
	return 0;
}

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

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main()
{
    int n,a;
    cin>>n>>a;
    vector<int> x(n);
    ll ans=0;
    
    for(int i = 0; i < n; i++)
    {
        cin>>x[i];
    }
    ll dp[55][55][2560];//mita(m) eranda(e) wa(w)
    m0(dp);
    dp[0][0][0]=1;
    
    for(int m = 0; m < n; m++)
    {
        
        for(int e = 0; e < n; e++)
        {
            for(int w = 0; w <= 2500; w++)
            {
                dp[m+1][e][w]+=dp[m][e][w];
                dp[m+1][e+1][w+x[m]]+=dp[m][e][w];
            }
        }
    }
    
    for(int e = 1; e <= n; e++)
    {
        ans+=dp[n][e][e*a];
    }
    

    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 60800