akhauriyash/Code-Regression huggingface dataset:
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B = il()
    ret = 0
    for n in range(A, B+1):
        n = list(str(n))
        if n[:len(n)//2] == n[len(n)//2+1:][::-1]:
            ret += 1
    print(ret)


if __name__ == '__main__':
    main()


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

#define ll long long int
#define INFTY (1<<21)

using namespace std;

ll solve(string &a){
    ll count = 0;
    ll n = a.size();
    if(n>1){
        string b(a.begin(), a.begin()+n/2);
        string c(a.begin() + n/2, a.end());
        count += solve(b);
        count += solve(c);
        for(ll i=0,j=0,k=0; i<n; i++){
            if(k==c.size())         a[i] = b[j++];
            else if(j==b.size())    a[i] = c[k++];
            else if(b[j] >= c[k])   a[i] = b[j++];
            else{
                a[i] = c[k++];
                count += n/2 - j;
            }
        }
    }
    return count;
}

int main(void){
    cin.sync_with_stdio(false);
    string s;
    cin>>s;
    cout<<solve(s)<<endl;

    return 0;
}

Measured memory_bytes: 916
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define CST(x) cout<<fixed<<setprecision(x)
#define PI 3.14159265359
#define MOD 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;

int main(){

    int n; cin >> n;
    unordered_set<int> d;
    rep(i,n){
        int l; cin >> l;
        d.emplace(l);
    }
    cout << d.size() << endl;
    return 0;
}


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

int main() {
    int N, M,res;
    cin >> N >> M;
    vector<ll> h(N+1);
    vector<ll> highest(N+1,0);
    for (int i = 1; i <= N; i++)cin>>h[i];
    for (int i = 0; i < M; i++) {
        ll a,b;
        cin >> a >> b;
        highest[a]=max(highest[a],h[b]);
        highest[b]=max(highest[b],h[a]);
    }
    res=0;
    for(int i=1;i<=N;i++){
        if(highest[i]<h[i])res++;
    }
    cout<<res;
    return 0;
}

Measured memory_bytes: 4856
# coding: utf-8
# Your code here!

import collections

n,m=[int(i) for i in input().split()]
A=[int(i) for i in input().split()]

S=[0]*(n+1)
for i in range(n):
    S[i+1]=(S[i]+A[i])%m

c = collections.Counter(S)

ans=0
for i in c:
    ans+=c[i]*(c[i]-1)//2

#print(c)
print(ans)    
    

Measured memory_bytes: 16568
N,A,B=map(int,input().split())
A += B
cnt = [0,0]
S=list(input())
for i in range(N):
    if S[i] == 'c':
        print("No")
    elif S[i] == 'a':
        if cnt[0] < A:
            print("Yes")
            cnt[0] += 1
        else:
            print("No")
    else:
        if cnt[0] < A and cnt[1] < B:
            print("Yes")
            cnt[0] += 1
        else:
            print("No")
        cnt[1] += 1

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

public class Main{
	final static int MOD = 1000000007;
	final static int INF = 1000000000;

	public static void main(String[] args) throws IOException{
		NScanner sc = new NScanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int l = sc.nextInt();
		int[][] A = new int[n][m];
		int[][] B = new int[m][l];
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < m; ++j)
				A[i][j] = sc.nextInt();
		}
		for(int i = 0; i < m; ++i){
			for(int j = 0; j < l; ++j)
				B[i][j] = sc.nextInt();
		}
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < l; ++j){
				if(j != 0) System.out.print(" ");
				long c = 0;
				for(int k = 0; k < m; ++k)
					c += A[i][k] * B[k][j];
				System.out.print(c);
			}
			System.out.println();
		}
	}

}

class NScanner{

	private BufferedReader br;
	private StringTokenizer tok;

	public NScanner(InputStream is) throws IOException{
		br = new BufferedReader(new InputStreamReader(is));
		getLine();
	}

	private void getLine() throws IOException{
		while(tok == null || !hasNext()){
			tok = new StringTokenizer(br.readLine());
		}
	}

	private boolean hasNext(){
		return tok.hasMoreTokens();
	}

	public String next() throws IOException{
		if(hasNext()){
			return tok.nextToken();
		}else{
			getLine();
			return tok.nextToken();
		}
	}

	public int nextInt() throws IOException{
		if(hasNext()){
			return Integer.parseInt(tok.nextToken());
		}else{
			getLine();
			return Integer.parseInt(tok.nextToken());
		}
	}

	public long nextLong() throws IOException{
		if(hasNext()){
			return Long.parseLong(tok.nextToken());
		}else{
			getLine();
			return Long.parseLong(tok.nextToken());
		}
	}

	public double nextDouble() throws IOException{
		if(hasNext()){
			return Double.parseDouble(tok.nextToken());
		}else{
			getLine();
			return Double.parseDouble(tok.nextToken());
		}
	}
}


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

int main(){
	string s;
	cin >> s;
	
	int res = 0;
	int last = -1;
	int cnt = 0;
	rep(i,s.size()){
		if(s[i] == 'A' || s[i] == 'G' || s[i] == 'C' || s[i] == 'T'){
		    cnt++;
			last = i;
		}
		else{
			cnt = 0;
		}
		res = max(res,cnt);
	}
	cout << res << endl;
	return 0;
}

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

#define for0(i, n) for (ll i = 0; i < (ll)(n); ++i) // 0 based indexing
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (ll i = (ll)(l); i <= (ll)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (ll i = (ll)(n); i >= 1; --i) // reverse 1 based

#define ff first
#define ss second
#define pb push_back

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll a,b;
  cin >> a >> b ;
  if(a <= 2*b) cout << "0" << endl;
  else cout << a-2*b << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;

int main() {
	int s, w;
	cin >> s >> w;
	if (w >= s) {
		cout << "unsafe" << endl;

	}
	else {
		cout << "safe" << endl;
	}

	

}

Measured memory_bytes: 3628
($n,$m)=glob<>;@x=glob<>;
if($n>=$m){
    print 0;
}else{
    @x=sort{$a<=>$b}@x;
    for($i=0;$i<$m-1;$i++){
        $l[$i]=$x[$i+1]-$x[$i] 
    }
    @l=sort{$a<=>$b}@l;
    $s+=$l[$_] for(0..$m-$n-1);
    print $s;
}


Measured memory_bytes: 26624
#include <bits/stdc++.h>     // [PRIMES]               1777 ~2^10.80  
using namespace std;                     //                       10333 ~2^13.33
using ll=long long;                      // seq 1 128 | factor   100333 ~2^16.61
using vl=vector<ll>;                     //   | grep -v ' .* '  1300111 ~2^20.31
using vvl=vector<vl>;                    //                    10300777 ~2^23.30
using vb=vector<bool>;                   //                   100400999 ~2^26.58
using vs=vector<string>;                 //                  1300400999 ~2^30.28
using pll=pair<ll,ll>;                   //                 10200500333 ~2^33.25
const ll oo =0x3f3f3f3f3f3f3f3fLL;       //                100200400777 ~2^36.54
const double eps=1e-9;                   //               1200300700111 ~2^40.13
#define sz(c) ll((c).size())             //              10200300500777 ~2^43.21
#define all(c) begin(c),end(c)           //             100200300400777 ~2^46.51
#define mp make_pair                     //            1200300400600999 ~2^50.09
#define mt make_tuple                    //           10200300400600111 ~2^53.18
#define pb push_back                     //          100200300400600333 ~2^56.48
#define eb emplace_back                  //         1200300400500800999 ~2^60.06
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(ll)(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

ll N;
vector<vector<vector<double>>> dp;


double r(double p, ll d){
    if(d == 100) return p;
    return p + (1-p)*r(p,d+1);
}

double f (vl in){
    if(in[0] == N) return 0;
    double* dpp = &dp[in[1]][in[2]][in[3]];
    if(*dpp > -0.5) return *dpp;
    double p_null = (double)in[0] / (double)N;
    double acc = (1.0/(1.0-p_null));
    FOR(i,1,sz(in)){
        if(in[i] == 0) continue;
        double p = ((double)in[i]/(double)(N-in[0]));
        vl newin = in;
        newin[i]--;
        newin[i-1]++;
        acc += f(newin)*p;
    }
    *dpp = acc;
    return acc;
}


int main(){
    ll n;
    cin >> n;
    N = 0;
    vl a;
    dp.resize(300+1,vector<vector<double>>(300+1, vector<double>(300+1, -1)));
    a.resize(4,0);
    FOR(i,0,n){
        ll in;
        cin >> in;
        a[in]++;
        N=n;
    }
    cout << fixed << setprecision(10) << f(a)<<endl;
} //cin.tie(0) bei schnellem Wechseln




Measured memory_bytes: 219008
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
#define MOD (ll) (1e9+7)
int main()
{
   ll n,r;
   cin>>n>>r;
   if(n>=10)
   {
   	  cout<<r<<"\n";
   }
   else{
   	  ll conv = 100*(10-n);
   	  ll ans = r+conv;
   	  cout<<ans<<"\n";
   }
}

Measured memory_bytes: 3600
from itertools import accumulate

n = int(input())
lis = list(map(int, input().split()))
mod = 10**9 + 7

a = list(accumulate(lis))

ans = 0
for i in range(n-1):
    ans += lis[i] * (a[-1]-a[i])
    ans %= mod

print(ans)

Measured memory_bytes: 31264
input = require('fs').readFileSync('/dev/stdin','utf8');
tmp = input.split(' ');
THP = parseInt(tmp[0],10);
TAP = parseInt(tmp[1],10);
AHP = parseInt(tmp[2],10);
AAP = parseInt(tmp[3],10);
while(THP > 0 && AHP > 0) {
  AHP = AHP - TAP;
  if(AHP <= 0) { console.log('Yes'); break; }
  THP = THP - AAP;
  if(THP <= 0) { console.log('No'); break; }
}


Measured memory_bytes: 29628
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
 
typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 2e5 + 5;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
 
int fac[MAX_N], inv[MAX_N];
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b, bool usemod = true) {ll c = 1LL; while (b > 0) {if (b & 1LL) {if(!usemod)c*=a;else c = a * c%mod;}if (!usemod) a*=a;else a = a * a%mod; b >>= 1LL;}return c;}
void _nCr() {fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) {fac[i] = fac[i - 1LL] * i%mod;}for (int i = 0; i < MAX_N; i++) {inv[i] = POW(fac[i], mod - 2);}}
ll nCr(ll n, ll r) {return (fac[n] * inv[r] % mod)*inv[n - r] % mod;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}


bool solve() {
	int a,b; string s; cin >> a >> s >> b;
	if (s == "+") cout << a + b << endl;
	else cout << a - b << endl;
}

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

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

#define ll long long int
#define pb push_back
#define mk make_pair
#define mod 1000000007
//map<int, int>::iterator itr; 

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;t=1;
    while(t--){
        int a,b,c,d,e;
        cin>>a>>b>>c>>d>>e;
        if(a==0){
            cout<<1;
        }
        else if(b==0){
            cout<<2;
        }
        
        else if(c==0){
            cout<<3;
        }
        
        else if(d==0){
            cout<<4;
        }
        
        else if(e==0){
            cout<<5;
        }
    }
    return 0;
}


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

struct node{
  int key;
  node *right, *left, *parent;
};

node *root, *nil;

void insert(int k){
  node *y = nil;
  node *x = root;
  node *z;

  z = (node *)malloc(sizeof(node));
  z->key = k;
  z->left = nil;
  z->right = nil;

  while(x != nil){
    y = x;

    if(z->key < x->key) x = x->left;
    else x = x->right;

  }

    z->parent = y;

    if(y == nil) root = z;

    else{
      if(z->key < y->key) y->left = z;

      else y->right = z;

  }  
}

void inorder(node *a){
  if(a == nil) return;

  inorder(a->left);

  cout << " " << a->key;

  inorder(a->right);
}

void preorder(node *a){
  if(a == nil) return;

  cout << " " << a->key;
  
  preorder(a->left);
  preorder(a->right);
  
}

int main()
{
  int n, x;
  string s;

  cin >> n;

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

    if(s == "insert"){
      cin >> x;
      insert(x);
    }

    else if(s == "print"){
      inorder(root);

      cout << endl;

      preorder(root);

      cout << endl;
      
    }
  }

  return 0;

}



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

#define PI 3.141592653589793238462643

int main() {
  long double a,b,h,m; cin>>a>>b>>h>>m;
  long double hm, mm;
  hm = (h + (m/60)) / 12 * 2 * PI;
  mm = m / 60 * 2 * PI;
  long double dm=abs(hm-mm);
  long double c = sqrt(a*a+b*b-2*a*b*cos(dm));
	cout << fixed << showpoint;
	cout << setprecision(20);
	cout << c;
}

Measured memory_bytes: 4128
n = int(input())
a = [None]*(n+1)
for i in range(1, n+1):
    a[i] = int(input())


visited = set()
cnt = 0 # 移動回数を記録する
i = 1 # 今点灯中のボタン番号、初期値は1
v = a[i] # 次に点灯するボタン番号 
f = True
while True:
    if i in visited:
        f = False
        break
    if v == 2:
        cnt += 1
        break
    visited.add(i)
    i = v
    v = a[v]
    cnt += 1

if f:
    print(cnt)
else:
    print(-1)

Measured memory_bytes: 13164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

struct Engine {
    double x, y;
    double radius;
    
    bool operator<(const Engine &a) {
        return radius < a.radius;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    long double PI = 3.141592653589793238462643383;
    ll n;
    cin >> n;
    vector<Engine> engines(n);
    rep(i, n) {
        cin >> engines[i].x >> engines[i].y;
        engines[i].radius = atan2(engines[i].y, engines[i].x);
    }
    sort(all(engines));
    double ans = -1;
    reps(size, 1, n + 1) {
        rep(offset, n) {
            double x = 0, y = 0;
            reps(i, offset, offset + size) {
                x += engines[i % n].x;
                y += engines[i % n].y;
            }
            double tmp = sqrt(x * x + y * y);
            ans = max(ans, tmp);
        }
    }
    printf("%.20f\n", ans);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while (n > 0) {
            String[][] x = new String[n][2];
            for (int i = 0; i < n; i++){
                x[i][0] = sc.next();
                x[i][1] = sc.next();
            }
            int m = sc.nextInt();
            for (int i = 0; i < m; i++){
                String s = sc.next();
                int j = 0;
                while (j < n){
                    if (s.equals(x[j][0])){
                        System.out.print(x[j][1]);
                        j = n;
                    }
                    else if (j == n - 1){
                        System.out.print(s);
                    }
                    j++;
                }
            }
            System.out.println();
            n = sc.nextInt();
        }
    }
}



Measured memory_bytes: 76564
S = list(input())

Ans = 0

for i in range(2**(len(S)-1)):
    W = [""]*(len(S)-1)
    for j in range(len(S)-1):
        #print(i,j)
        if ((i >> j) & 1):
            W[j] = "+"
    #print(W)
    formula = ""
    for k,l in zip(S,W+[""]):
        formula += (k+l)
    Ans += eval(formula)

print(Ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=(a);i<=(n);++i)
#define mp make_pair
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef double lf;
const int N=111111;
int n;
struct zcc{int a,b,c;}a[N];
pair<lf,int> p[N],q[N];
int rp[N];
int T[N];
int que(int x){int ans=0;for(int i=x;i;i-=i&-i)ans+=T[i];return ans;}
void modi(int x,int k){for(int i=x;i<=n;i+=i&-i)T[i]+=k;}
int check(lf x){
	rep(i,1,n)q[i]=mp((a[i].c-(x*a[i].b))/a[i].a,i);
	sort(q+1,q+1+n);
	rep(i,0,n)T[i]=0;
	ll ans=0;
	rep(_,1,n){
		int i=rp[q[_].Y];
		//printf("%d\n",i);
		ans+=_-1-que(i);modi(i,1);
	}
	//rep(i,1,n)printf("%d %d %d\n",i,q[i].Y,p[i].Y);
	//printf("%.9lf %lld\n",x,ans);
	return ans>=(1ll*n*(n-1)/2+1)/2;
}
void work(){
	rep(i,1,n)p[i]=mp((a[i].c-(-1e10*a[i].b))/a[i].a,i);
	sort(p+1,p+1+n);
	rep(i,1,n)rp[p[i].Y]=i;
	lf l=-1e9,r=1e9;
	rep(_,1,200){
		lf mid=(l+r)/2;
		if(check(mid))r=mid;else l=mid;
	}
	printf("%.13lf",l);
}
int main(){
	scanf("%d",&n);
	rep(i,1,n)scanf("%d%d%d",&a[i].a,&a[i].b,&a[i].c);
	rep(i,1,n)swap(a[i].a,a[i].b);
	work();putchar(' ');
	rep(i,1,n)swap(a[i].a,a[i].b);
	work();puts("");
	return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include <math.h>
#include<vector>
#include<algorithm>
using namespace std;
char a[100][100];
int h, w;
int main() {
	cin >> h >> w;
	for (size_t i = 0; i < h; i++)
	{
		for (size_t j = 0; j < w; j++)
		{
			cin >> a[i][j];
		}
	}
	for (size_t i = 0; i < h; i++)
	{
		for (size_t k = 0; k < 2; k++)
		{
			for (size_t j = 0; j < w; j++)
			{
				cout << a[i][j];
			}

			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s); sin>>v; return v;}
template<class T> inline string toString(T x) {ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI = acos(-1.0);


struct node{
    int index,boat,next,cost;
    node(int index,int boat,int next,int cost):index(index),boat(boat),next(next),cost(cost){}
    bool operator<(const node& other)const{
        return cost>other.cost;
    }
};
struct edge{
	int lcost,scost;
	edge(int lcost,int scost):lcost(lcost),scost(scost){}
	edge(){}
};
const int MAX=INT_MAX/10;
const int NONE=-1;

typedef vector<edge> ve;
typedef vector<ve> vve;
typedef vector<vvi> vvvi;
int main(){
	int n,m;
	while(cin>>n>>m,n|m){
		static edge graph[200][200];
		REP(i,n)REP(j,n){
			if(i==j){
				graph[i][j]=edge(0,0);
			}else{
				graph[i][j]=edge(MAX,MAX);
			}
		}
        REP(i,m){
			int x,y,t;
			char sl;
			cin>>x>>y>>t>>sl;
			switch(sl){
			case 'S':
				graph[x-1][y-1].scost=min(graph[x-1][y-1].scost,t);
				graph[y-1][x-1].scost=min(graph[y-1][x-1].scost,t);
				break;
			case 'L':
				graph[x-1][y-1].lcost=min(graph[x-1][y-1].lcost,t);
				graph[y-1][x-1].lcost=min(graph[y-1][x-1].lcost,t);
				break;
			default:
				assert(0);
				break;
			}
        }
		int r;
		cin>>r;
		vi order(r);
		REP(i,r){
			cin>>order[i];
			order[i]--;
		}
		REP(k,n)REP(i,n)REP(j,n){
			graph[i][j].lcost=min(graph[i][j].lcost,graph[i][k].lcost+graph[k][j].lcost);
			graph[i][j].scost=min(graph[i][j].scost,graph[i][k].scost+graph[k][j].scost);
		}

		static int dp[1001][200];
		REP(i,r+1){
			REP(j,n){
				dp[i][j]=MAX;
			}
		}
		for(int post=-1;post<r-1;post++){
			REP(boat,n){
				if(post==-1){
					dp[post+1][boat]=graph[order[0]][boat].scost;
				}else{
					dp[post+1][boat]=min(dp[post+1][boat],dp[post][boat]+graph[order[post]][order[post+1]].lcost);
					REP(via,n){
						dp[post+1][boat]=min(dp[post+1][boat],dp[post][via]+graph[order[post]][via].lcost+graph[via][boat].scost+graph[boat][order[post+1]].lcost);
					}
				}
			}
		}
        
		int ans=MAX;
		REP(i,n){
			ans=min(ans,dp[r-1][i]);
		}
        cout<<ans<<endl;
	}
}

Measured memory_bytes: 2292
#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;

int main() {
    int n, k;
    string s;
    cin >> n >> k >> s;
    if (s[k-1] == 'A') s[k-1] = 'a';
    else if(s[k-1] == 'B')s[k-1] = 'b';
    else s[k-1] = 'c';
    cout << s << endl;
    
}

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

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

    int arr[] = {a, b, c};

    int count5 = 0;
    int count7 = 0;
    for (int i = 0; i < 3; i++)
    {
        if (arr[i] == 5)
        {
            count5++;
        }
        else if (arr[i] == 7)
        {
            count7++;
        }
    }

    cout << ((count5 == 2 && count7 == 1) ? "YES" : "NO") << endl;

    return 0;
}

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

using namespace std;

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

	int ans = 0;
	for (auto it = a.begin(); it != a.end(); ) {
		auto pos = find_if(it, a.end(), [&](int x) { return x != *it; });
		ans += (pos - it) / 2;
		it = pos;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ref1(i,s,e,c) for(int i=s;i<e;i=i+c)
#define ref2(i,s,e,c) for(int i=s;i<=e;i=i+c)
#define ref3(i,e,s,c) for(int i=e;i>=s;i=i-c)
using namespace std;
typedef long long ll;
int main()
{
	ll n,mn;
	cin>>n;
	ref1(i,0,5,1){
		ll num;
		cin>>num;
		if(i==0) mn=num;
		else mn=min(mn,num);
	}
	cout<<4+n/mn+(n%mn?1:0)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;

struct SegmentTree{
    int leaves;
    vector<int> data;

    void init(int n){
        leaves = 1;
        while(leaves < n) leaves *= 2;// nearest power of 2 (leaf nodes)
        data.assign(2 * leaves, INF);// (0,) 1, ..., 2 * leaves - 1
    }

    // update i-th leaf (0-indexed) to x
    void update(int i, int x){
        i += leaves;
        data[i] = x;
        while(i >= 2){
            i /= 2;// move upward (to the parent node)
            data[i] = min(data[i*2], data[i*2 + 1]);// compare the children
        }
    }

    // minimum [a,b)
    int query(int a, int b, int k, int l, int r){// k-th node of the tree = [l,r)
        if(b <= l || r <= a) return INF;// no overlap
        if(a <= l && r <= b) return data[k];// completely inside
        // otherwise: recursive
        int vl = query(a, b, k*2    , l      , (l+r)/2);// left  child
        int vr = query(a, b, k*2 + 1, (l+r)/2, r      );// right child
        return min(vl, vr);
    }
};

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

    SegmentTree seg; 
    seg.init(2*n);

    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
        seg.update(i, a[i]);
        seg.update(n+i, a[i]);
    }

    long long int ans = 1e18;// INF
    for(int k=0; k<n; k++){
        long long int test = k * x;
        for(int i=0; i<n; i++){
            test += seg.query(i, i+k+1, 1, 0, seg.leaves);// [x,y] -> [x,y+1)
        }
        ans = min(ans, test);
    }
    cout << ans << endl;
    return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)      //0-origin昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++)    //1-origin昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-origin降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-origin降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<int,int> PII;
template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

/* 円周率は M_PI を使おうね */
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;

/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);
    
    ll n; cin >> n;
    if(n%2==0) {
        ll ans1 = 0;
        ll ans2 = 0;
        for(ll i = 2; i <= n; i*=2) {
            ans1 += n/i;
        }
        ll m = n/2;
        for(ll i = 5; i <= m; i*=5) {
            ans2 += m/i;
        }
        //debug(ans1);debug(ans2);
        chmin(ans1, ans2);
        cout << ans1 << '\n';

    }
    else cout << 0 << endl;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#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 <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

	string s; cin >> s;

	if (s <= "2019/04/30") {
		cout << "Heisei" << endl;
	}
	else {
		cout << "TBD" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int Mod=1e9+7;
//int dp[2005][2005];//总和为i，最大为j的可能数 
int a[2005];
int main(){
	int s;
	cin>>s;
	a[1]=a[2]=0;
	a[3]=a[4]=a[5]=1;
	if(s<=5){
		cout<<a[s]<<endl;
		return 0;
	}else{
		for(int i=6;i<=s;i++){
			a[i]=a[i-1]+a[i-3];
			a[i]%=Mod;
		}
	}
//	for(int i=0;i<=s;i++){
//		dp[i][i]=1;
//	}
//	for(int i=3;i<=s;i++){
//		for(int j=3;j<=i;j++){
//			for(int k=3;k<=s;k++){
//				dp[i][j]=dp[i][j]+dp[i-j][k];
//				dp[i][j]%=Mod;
//			}
//		}
//	}
//	long long ans=0;
////	cout<<dp[7][3]<<" "<<dp[7][4]<<" "<<dp[7][7]<<endl;
//	for(int i=3;i<=s;i++){
//		ans=ans+dp[s][i];
//		ans%=Mod;
//	}
//	cout<<ans<<endl;
	cout<<a[s]%Mod;
	return 0;
} 

Measured memory_bytes: 3624
#include<stdio.h>
int main()
{
    long long int a,b;
    while(scanf("%lld%lld",&a,&b)!=EOF)
    {
        long long int r;
        if(a<b)
        {
            r=a;
            a=b;
            b=r;
        }
        r=a%b;
        while(r)
        {
            a=b;
            b=r;
            r=a%b;
        }
        printf("%d\n",b);
    }
    return 0;
}



Measured memory_bytes: 2076
// AOJ 2017 Karakuri Doll
// 2018.3.16 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define QMAX 300000
typedef struct { char r1, c1, d1, r2, c2, d2; } Q;
Q q[QMAX + 5]; int top, end;
int H, W, SR, SC, SD, GR, GC, GD;     // (r,c) dir
char map[16][66];
char visited[17][65][5][17][65][5];   // r1,c1,d1 r2,c2,d2
int mv[4][2] = { {-1,0},{0,1},{1,0},{0,-1} };
#define L(d) ((d+3)%4)
#define R(d) ((d+1)%4)
int ans;

void enq(int r1, int c1, int d1, int r2, int c2, int d2, int _d2)
{
	if (r1 == GR && c1 == GC) {
		ans = 1;
		if (r2 == GR && c2 == GC && _d2 == GD) { ans = 2; return; }
	}
	if (visited[r1][c1][d1][r2][c2][d2]) return;
	visited[r1][c1][d1][r2][c2][d2] = 1;

	q[end].r1 = r1, q[end].c1 = c1, q[end].d1 = d1;
	q[end].r2 = r2, q[end].c2 = c2, q[end].d2 = d2;
	++end;
}

int bfs()
{
	int r1, c1, d1, r2, c2, d2;

	memset(visited, 0, sizeof(visited));
	ans = 0, top = end = 0;
	for (d2 = 0; d2 < 4; d2++) enq(SR, SC, SD, SR, SC, d2, 4);

	while (top != end && ans != 2) {
		r1 = q[top].r1, c1 = q[top].c1, d1 = q[top].d1;
		r2 = q[top].r2, c2 = q[top].c2, d2 = q[top].d2;
		++top;

		while (map[r1 + mv[d1][0]][c1 + mv[d1][1]] != '#')
			r1 += mv[d1][0], c1 += mv[d1][1];
		enq(r1, c1, L(d1), H, W, 4, 4);
		enq(r1, c1, R(d1), H, W, 4, 4);

		if (d2 < 4) while (map[r2][c2] != '#') {
			if (map[r2 + mv[L(d2)][0]][c2 + mv[L(d2)][1]] == '#')
				enq(r1, c1, L(d1), r2, c2, L(d2), d2);
			if (map[r2 + mv[R(d2)][0]][c2 + mv[R(d2)][1]] == '#')
				enq(r1, c1, R(d1), r2, c2, R(d2), d2);
			r2 -= mv[d2][0], c2 -= mv[d2][1];
		}
	}
	return ans;
}

int main()
{
	int r, c;
	static char *msg[3] = { "He cannot bring tea to his master.",
							"He cannot return to the kitchen.",
							"He can accomplish his mission." };

	while (scanf("%d%d", &W, &H) && (W | H)) {
		for (r = 0; r < H; r++) {
			scanf("%s", map[r]);
			for (c = 0; c < W; c++) {
				if (map[r][c] == 'K') SR = r, SC = c;
				else if (map[r][c] == 'M') GR = r, GC = c;
			}
		}
		for (SD = 0; ; SD++) {
			r = SR + mv[SD][0], c = SC + mv[SD][1];
			if (map[r][c] != '#') break;
		}
		for (GD = 0; ; GD++) {
			r = GR + mv[GD][0], c = GC + mv[GD][1];
			if (map[r][c] != '#') break;
		}
		printf("%s\n", msg[bfs()]);
	}
	return 0;
}


Measured memory_bytes: 32884
M=998244353
N,*A=open(0)
d=[0]*90001
d[0]=1
e=[0]*90001
e[0]=1
z=1
s=0
for a in A:
	i=s;a=int(a);s+=a;z*=3
	while i>=0:d[i+a]+=d[i]%M;d[i]*=2;e[i+a]+=e[i]%M;i-=1
i=s
while i*2>=s:z=(z-d[i]*3)%M;i-=1
print([(z+e[s//2]*3)%M,z][s%2])

Measured memory_bytes: 141900
# Graph II - Single Source Shortest Path II
def dijkstra(length, adj_list):
    INFTY = float('inf')
    d = [INFTY for _ in range(length)]
    d[0] = 0
    Q = [i for i in range(length)]
    while Q:
        idx = INFTY
        minv = INFTY
        for q in Q:
            if d[q] < minv:
                idx, minv = q, d[q]
        u = Q.pop(Q.index(idx))
        for v in adj_list[u]:
            if d[v[0]] > d[u] + v[1]:
                d[v[0]] = d[u] + v[1]
    return d

n = int(input())
adj_list = [set() for _ in range(n)]
for _ in range(n):
    ss = list(map(int, input().split()))
    u, k = ss[0], ss[1]
    for i in range(k):
        vi,ci = ss[2*i+2], ss[2*i+3]
        adj_list[u].add((vi,ci))
d = dijkstra(n, adj_list)
for i,v in enumerate(d): print(i,v)


Measured memory_bytes: 97392
#include<stdio.h>
void sort(int a[]){
    int i,j;
    for(i=3;i>0;i--){
        for(j=0;j<i-1;j++){
            if(a[j]>a[j+1]){
                int t=a[j];
                a[j]=a[j+1];
                a[j+1]=t;
            }
        }
    }
}
int main(void){
    int n,p[1000][3],i,j,cnt=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        for(j=0;j<3;j++)
            scanf("%d",&p[i][j]);
        sort(p[i]);
    }
    for(i=0;i<n-1;i++){
        for(j=i+1;j<n;j++){
            if(p[i][0]==p[j][0]&&p[i][1]==p[j][1]&&p[i][2]==p[j][2]&&p[j][0]){
                cnt++;
                p[j][0]=0;
            }
        }
    }
    printf("%d\n",cnt);
	return 0;		
}


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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(){
  int n;
  cin >> n;
  vector<int> t(n);
  rep(i, n) cin >> t.at(i);
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  int mxt = t.front(), mxti = 0, mxa = a.back(), mxai = n-1;
  rrep(i, n-1){
    if(t.at(i) < t.at(i+1)){
      mxt = t.at(i+1);
      mxti = i+1;
      break;
    }
  }
  rep2(i, 1, n){
    if(a.at(i-1) > a.at(i)){
      mxa = a.at(i-1);
      mxai = i-1;
      break;
    }
  }

  if(mxa != mxt || mxai < mxti){
    cout << 0 << endl;
    return 0;
  }

  mint ans = 1;
  rep2(i, 1, mxti){
    if(t.at(i-1) == t.at(i)){
      ans *= t.at(i-1);
    }
  }
  rep2(i, mxti+1, mxai){
    ans *= mxa;
  }
  rrep2(i, mxai, n-1){
    if(a.at(i) == a.at(i+1)){
      ans *= a.at(i+1);
    }
  }
  // cerr << mxa << " " << mxti << " " << mxai << endl;
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 4056
n=int(input())
ac=0
wa=0
tle=0
re=0
for i in range(n):
  s=input()
  if s=="AC":
    ac+=1
  elif s=="WA":
    wa+=1
  elif s=="TLE":
    tle+=1
  else:
    re+=1
print("AC x",ac)
print("WA x", wa)
print("TLE x", tle)
print("RE x", re)

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

#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mk make_pair
#define mod 1000000007
//#define mo 998244353
string str;
//map<int, int>::iterator itr; 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;
    ll arr[n],sum[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sum[n-1]=arr[n-1];
    for(int i=n-2;i>=0;i--){
        sum[i]=arr[i]+sum[i+1];
    }
    ll ans=0;
    for(int i=0;i<n-1;i++){
        sum[i+1]=sum[i+1]%mod;
        ll p=sum[i+1]*arr[i];
        p=p%mod;
        ans+=p;
        ans=ans%mod;
    }cout<<ans;
    return 0;
}


Measured memory_bytes: 6732
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <ctime>

using namespace std;
#define RN cout << "\r\n";
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef long long int ll;
typedef pair<ll, ll> P;

int gcd(int a, int b) {
    int v0 = a, v1 = b, v2 = a % b;
    while (v2 != 0) {
        v0 = v1;
        v1 = v2;
        v2 = v0 % v1;
    };
    return v1;
}

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

int main() {
    int a;
    cin >> a;
    int ans = 0;
    REP(i, a) {
        int b;
        cin>> b;
        ans += b;
    }
    ans -= a;
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long dp[101][100099],n,m,w[1000],v[1000],ans;
int main()
{

    cin>>n>>m;
    for (int i=0;i<=n;i++)
    {
        for (int j=0;j<100099;j++)
        {
            dp[i][j]=9999999999999999;
        }
    }
    for (int i=0;i<n;i++)
    {
        cin>>w[i];
        cin>>v[i];
    }
    dp[0][v[0]]=w[0];
    dp[0][0]=0;
    for (int i=1;i<n;i++)
    {
        for (int j=0;j<100005;j++)
        {
            if (dp[i-1][j]==9999999999999999) continue;
            dp[i][j]=min(dp[i-1][j],dp[i][j]);
            dp[i][j+v[i]]=min(dp[i][j+v[i]],dp[i-1][j]+w[i]);
        }
    }
    for (int i=0;i<100009;i++)
    {
        if (dp[n-1][i]<=m) ans=i;
    }
    cout<<ans;
}


Measured memory_bytes: 79232
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 3005
#define INF 1000000005LL

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int n;
int A[SIZE];

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

int imain()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&A[i]);
	for(int i=0;i<25;i++){
		int a=0;
		for(int j=0;j<n;j++){
			a += (i%A[j]);
		}
		printf("%d,%d\n",i,a);
	}
	return 0;
}


Measured memory_bytes: 128
def main():
    H,W = map(int, input().split())
    c = []
    A = []
    for i in range(10):
        c.append(list(map(int, input().split())))
    for i in range(H):
        A.append(list(map(int, input().split())))

    cost = [0 for _ in range(10)]
    for i in range(10):
        if i==1:
            continue
        else:
            flag = [0 for _ in range(10)] # 行ったところは1
            flag[i] = 1
            q = [[i,0,flag],] # 今いるとこ、今のコスト、行ったところ
            min_cost = c[i][1]
            while q != []:
                now, now_cost, now_flag = q.pop(0)
                if now==1:
                    if now_cost<min_cost:
                        min_cost = now_cost
                else:
                    for j in range(10):
                        if now_flag[j]==0 and now_cost+c[now][j]<min_cost:
                            next_flag = now_flag.copy()
                            next_flag[now] = 1
                            q.append([j,now_cost+c[now][j],next_flag])
            cost[i] = min_cost                            
    
    result = 0
    for i in range(H):
        for j in range(W):
            if A[i][j] == -1:
                result += 0
            else:
                result += cost[A[i][j]]
    return result
print(main())



Measured memory_bytes: 3932
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    ll X, Y;
    cin >> X >> Y;

    ll ans = 0;
    while (X <= Y) {
        ans++;
        X *= 2;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
 
using namespace std;
 
struct Node {
    int key;
    Node *right, *left, *parent;
};
 
Node *root, *NIL;
 
Node * find(Node *u, int k) {
    while(u != NIL && k != u->key) {
        if(k < u->key) u = u->left;
        else u = u->right;
    }
    return u;
}
 
void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;
     
    z = (Node *)malloc(sizeof(Node));
    z->key   = k;
    z->left  = NIL;
    z->right = NIL;
     
    while(x != NIL) {
        y = x;
        if(z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
     
    z->parent = y;
    if(y == NIL) {
        root = z;
    } else {
        if( z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}
 
void inorder(Node *u) {
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node *u) {
    if(u == NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}
     
int main(void) {
    int n, i, x;
    string com;
    scanf("%d",&n);
     
    for(i=0;i<n;i++) {
        cin >> com;
        if(com[0] == 'f') {
            scanf("%d",&x);
            Node *t = find(root,x);
            if(t != NIL) printf("yes\n");
            else printf("no\n");
        } else if(com == "insert") {
            scanf("%d",&x);
            insert(x);
        } else if(com == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
 
    return 0;
}


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

int main(){
    int N;
    int d[110];
    int res = 0;
    cin>> N;
    for(int i = 0;i<N;i++){
        cin>>d[i];
    }
    int num[110]={0};
    for(int i=0;i<N;i++){
        num[d[i]]++;
    }
    for(int i=1;i<=100;i++){
        if(num[i])res++;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>
typedef long long int lld;
typedef unsigned long long int llu;
using namespace std;
const int m=1e9;
int main()
{
	string s,t;
	cin>>s>>t;
	int n=s.length(),m=t.length(),i=0,j;
	int k[n+1][m+1];
	for(i=0;i<=n;i++)
	{
		for(j=0;j<=m;j++)
		{
			if(i==0 ||j==0) k[i][j]=0;
			else if(s[i-1]==t[j-1])
			{
				k[i][j]=1+k[i-1][j-1];
			}
			else k[i][j]=max(k[i-1][j],k[i][j-1]);
		}
	}
	int index=k[n][m];
	char temp[index+1];
	temp[index]='\0';
	i=n,j=m;
	while(i>0 && j>0)
	{
		if(s[i-1]==t[j-1]) 
		{
			temp[index-1]=s[i-1];
			i--;j--;index--;
		}
		else
		{
			if(k[i-1][j]>k[i][j-1]) i--;
			else j--;
		}
	}
	cout<<temp<<endl;
}

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

int main(){
	int a, b, c;
	cin>>a>>b;
	c = a+b;
	if((a%3 == 0) or (b%3 == 0) or (c%3 == 0)){
		cout<<"Possible"<<"\n";
	} else{
		cout<<"Impossible"<<"\n";
	}
	return 0;
}


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

int main()
{
	int a, b;
	cin >> a >> b;
	if (a % 3 == 0) {
		cout << "Possible" << endl;
	}
	else if (b % 3 == 0) {
		cout << "Possible" << endl;
	}
	else if ((a + b) % 3 == 0) {
		cout << "Possible" << endl;
	}
	else
		cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <math.h>
#include <cstdio>
#include <iomanip>
typedef  long long ll;
using namespace std;

int main(void) {
	ll n, ans = 0;
	cin >> n;

	for (int i = 1; i <= n; i++)
	{
		string a = to_string(i);
		if (a.length() % 2 == 1) ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
num = 26
answer = ''
while N:
    N -= 1
    remain = N%num
    answer += chr(remain+ord('a'))
    N //= num

print(answer[::-1])


Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b;
    cin >> a >> b;
    if(a==b){
        cout << "Draw" << endl;
    } else if((a>b && b!=1)||a==1){
        cout << "Alice" << endl;
    } else if((b>a && a!=1)||b==1){
        cout << "Bob" << endl;
    }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n, t, dp[2][5001][2];
    scanf("%d",&n);
	rep(i,2)rep(j,5001)rep(k,2)dp[i][j][k]=100000000;
    dp[0][1][0] = 0; dp[0][0][1] = 0;
    for(int i = 1; i < n; i++){
        scanf("%d",&t);
        for(int j = 0; j <= n/2; j++){
            if(j != 0){
                dp[1][j][0] = min(dp[0][j-1][0],dp[0][j-1][1]+t);
                dp[1][j][1] = min(dp[0][j][1],dp[0][j][0]+t);
            } else dp[1][j][1] = dp[0][j][1];
        }
        for(int j = 0; j <= n/2; j++)rep(k,2)dp[0][j][k] = dp[1][j][k];
    }
    printf("%d\n", min(dp[0][n/2][0],dp[0][n/2][1]));
}

Measured memory_bytes: 1268