akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#include<math.h>
#define c(v) ((v)>=0&&(v)<3)
int m[5]={0,1,0,-1,0},s,t,b,dp[9][16];

int d(int p,int n)
{
	int i,r=0,x,y;
	if(dp[p][n]!=-1)
		return dp[p][n];
	if(n==0)
	{
		if(p==t)
			return 1;
		else
			return 0;
	}
	else if(n>0&&(abs(p/3-t/3)+abs(p%3-t%3))<=n)
	{
		for(i=0;i<4;i++)
		{
			x=p%3+m[i];
			y=p/3+m[i+1];
			if(c(x)&&c(y)&&y*3+x!=b)
				r+=d(y*3+x,n-1);
			else
				r+=d(p,n-1);
		}
	}
	return dp[p][n]= r;
}

int main()
{
	int n,ans,tmp1;
	double tmp2;
	for(;scanf("%d",&n);ans=0)
	{
		if(n==0)
			return 0;
		scanf("\n%c %c %c",&s,&t,&b);
		memset(dp,-1,sizeof(dp));
		s-=65;t-=65;b-=65;
		ans=d(s,n);
		tmp1=1<<(n*2);
		tmp2=(double)ans/tmp1;
		printf("%lf\n",tmp2);
	}
	return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>
#include <cmath>

/* a と b の最大公約数を返す関数 */
int GCD(int a, int b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main(){

    int c;
    cin >> c;
    int sum = 0;
    for(int i = 1;i <= c;i++){
        for(int j = 1;j <= c;j++){
            for(int k = 1;k <= c;k++){
                //i jのGCD　GCDとkのGCD
                int t = GCD(i,j);
                int s = GCD(t,k);
                sum += s;

        
            }
        
        }

    }

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

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

#define ll long long
#define int long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf (int)(1e18)
#define ps(x, y) fixed << setprecision(y) << x
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(p) p.begin(), p.end()
#define ub(a, b) upper_bound(all(a), b)
#define lb(a, b) lower_bound(all(a), b)
#define PI 3.14159265
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void run()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
void solution()
{
    int n;
    cin >> n;
    vector<int> a(n);
    int x = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        x ^= a[i];
    }
    for (int i = 0; i < n; i++)
    {
        cout << (x ^ a[i]) << " ";
    }
    cout << endl;
    return;
}
int32_t main()
{
    run();
    solution();
    return 0;
}

Measured memory_bytes: 4724
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner as = new Scanner(System.in); 
		int n = Integer.parseInt(as.next());
		int a = n;
		for(int i=0;i<=n;i++){
			int c=0;
			int t=i;
			while(t>0){
				c += t%6;
				t /= 6;
			}
			t = n-i;
			while(t>0){
				c += t%9;
				t /= 9;
			}
			if(a>c){
				a = c;
			}
		}
		System.out.println(a);
	}
}

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

int main(){
    int E,Y;
    cin >> E >> Y;

    switch (E) {
        case 0:
                if(1868<=Y && Y<=1911){
                  cout<<"M"<<Y-1867<<endl;
                }else if(1912<=Y && Y<=1925){
                  cout<<"T"<<Y-1911<<endl;
                }else if(1926<=Y && Y<=1988){
                  cout<<"S"<<Y-1925<<endl;
                }else if(1989<=Y && Y<=2016){
                  cout<<"H"<<Y-1988<<endl;
                }
                break;
        case 1:
                cout << Y+1867<<endl;
                break;
        case 2:
                cout << Y+1911<<endl;
                break;
        case 3:
                cout << Y+1925<<endl;
                break;
        case 4:
                cout << Y+1988<<endl;
                break;            
    }
    return 0;
}



Measured memory_bytes: 3084
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

char s[55][55];

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<int>a(n); rep(i, n)cin >> a[i];
	int four = 0, two = 0;
	rep(i, n) {
		if (a[i] % 4 == 0) {
			four++;
		}
		else if (a[i] % 2 == 0) {
			two++;
		}
	}
	if (four >= n / 2) {
		cout << "Yes" << endl;
	}
	else {
		int tmp = four + two / 2;
		if(tmp>=n/2){
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}

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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>

typedef long long ll;
typedef unsigned long long ull;

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

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

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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


int main(void){
  ios::sync_with_stdio(false);



  ll N, K, Q;
  cin >> N >> K >> Q;
  vector<ll> A(Q);
  REP(i, Q) {cin >> A[i];}

  vector<ll> count(N);
  REP(i, Q){
    ll val = A[i] - 1;
    count[val]++;
  }

  vector<ll> point(N);
  REP(i, N){
    point[i] = K -Q + count[i];
  }

  REP(i, N){
    if (point[i] > 0) {cout << "Yes" << endl;}
    else cout << "No" << endl;
  }


  return 0;
}



Measured memory_bytes: 2944
while True:
    le=map(float,raw_input().split())
    if le==[0,0,0]:
        break
    mdl=min([(le[i-1]**2+le[i]**2)**0.5 for i in xrange(3)])
    for u in xrange(input()):
        if input()*2>mdl:
            print "OK"
        else:
            print "NA"

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


int main() {
  
  int N;
  cin>>N;
  
 vector<int> H(N);
for (int i = 0; i < N; i++) {
  cin >> H.at(i);
}
  
  
  int sw=0;
  int m=0;
  for (int i = 0; i < N-1; i++) {
  if(H.at(i)>=H.at(i+1)){
    sw++;
  }else{
    sw=0;
  }
    m=max(m,sw);
}
  
  cout<<m<<endl;
  
}



Measured memory_bytes: 640
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    A, B, K = map(int, readline().split())

    if A >= K:
        A -= K
    else:
        K -= A
        A = 0
        B = max(0, B - K)

    print(A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61952
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;
typedef pair<int, int> PR;

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define fr(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}
 

//cout<<""<<endl;
int main(){
  int D,G;cin>>D>>G;
  vi p(D),c(D);
  rep(i,D){
    cin>>p[i]>>c[i];
  }
  int ans=10000;
  for(int i=0; i<(1<<D);i++){
    bitset<10> t(i);
    int tot=0,cnt=0;
    rep(j,D){
      if(t.test(j)){
        cnt+=p[j];
        tot+=c[j];
        tot+=(j+1)*100*p[j];
      }
    }
    if(G<=tot)ans=min(ans,cnt);
    else{
      for(int k=D-1;k>=0;k--){
        if(!t.test(k)){
          rep(l,p[k]){
            cnt++;
            tot+=100*(k+1);
            if(l==p[k]-1)tot+=c[k];
            if(tot>=G){
              ans=min(ans,cnt);
              break;
            }
          }
        }
      }
    }
    
  }
  cout<<ans<<endl;
  
}





Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
LL mod=1000000007;
LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


const int M_N=400000;

struct BIT{
    //1-indexed
    LL bit[M_N+1],n;
    //iまでの総和を返す
    LL sum(int i){
        LL s=0;
        while(i>0){
            s+=bit[i];
            i=i&(i-1);
        }
        return s;
    }
    //iにx加算する
    void add(int i,LL x){
        while(i<=n){
            bit[i]+=x;
            i+=i&-i;
        }
    }

};

int main(){
    int n;cin >> n;
    vector<int> a(n);
    vector<int> b(n+1,0);
    BIT bit;
    bit.n = n+1;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[a[i]]++;
    }
    vector<int> c;
    for (int i = 0; i < n+1; i++) {
        if(b[i]>0){
            bit.add(b[i],1);
            int t = b[i];
            while(t--) c.pb(b[i]);
        }
    }
    sort(ALL(c));
    for (int k = 1; k <= n; k++) {
        int l=0,r=n/k+1;
        while(abs(r-l)>1){
            int m = (r + l) / 2;
            int sum = m*(bit.sum(n) - bit.sum(m));
            sum += upper_bound(ALL(c),m) - c.begin();
            if(sum / m >= k) l = m;
            else r = m;
        }
        cout << l << endl;
    }
    return 0;
}



Measured memory_bytes: 6900
import sys
import math
import numpy as np
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
L = l()
c = Counter(L)
ans = 0
for i,v in c.items():
    if i > v:
        ans += v
    if i < v:
        ans += v-i
print(ans)

Measured memory_bytes: 39628
my $s = <>;chomp $s;
my @num = split(//,$s);
my %m;
my $keta = 1;
$m{0} = 1;
my $cur = 0;
for (my $i=1;$i<=($#num+1);$i++) {
  my $t = $num[-$i];
  #print "$i $t cur$cur $keta\n";
  $cur = ($cur + $t * $keta) % 2019;
  $m{$cur}++;
  $keta = $keta * 10 % 2019;
}
my $ans = 0;; 
foreach my $k (keys %m){
  #print "$k $m{$k}\n";
  $ans += $m{$k} * ( $m{$k} - 1 ) / 2;
}
print  "$ans";

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

#define int long long
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define str string
#define vint vector<int>
#define vchar vector<char>
#define vool vector<bool>
#define pb() pushback
#define elif else if

main(){
    int N,count=0,count2=0;
    double r,pai=3.141592653589;
    int C='A'-'a';
    str S,T;
    cin>>r;
    printf("%.6f %.6f \n",r*r*pai,2*r*pai );
}



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

int main() {
    long long n, a, b;
    cin >> n >> a >> b;

    vector<long long> x(n);
    for (int i = 0; i < n; i++) cin >> x[i];

    long long answer = 0;
    for (int i = 1; i < n; i++)
        answer += min(b, (x[i] - x[i - 1]) * a);

    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 1024
class BinaryTree:
    def __init__(self, parent, left, right):
        self.parent = parent
        self.left = left
        self.right = right

n = int(input().rstrip())

T = []
for _ in range(n):
    T.append(BinaryTree(-1, -1, -1))

for _ in range(n):
    input_line = list(map(int, input().rstrip().split(" ")))
    assert len(input_line) == 3, "input line should be composed of 3 items"
    u, left, right = input_line
    T[u].left = left
    T[u].right = right
    if left != -1:
        T[left].parent = u
    if right != -1:
        T[right].parent = u

def preParse(u):
    if u == -1:
        return 0
    print(" " + str(u), end="")
    preParse(T[u].left)
    preParse(T[u].right)

def inParse(u):
    if u == -1:
        return 0
    inParse(T[u].left)
    print(" " + str(u), end="")
    inParse(T[u].right)

def postParse(u):
    if u == -1:
        return 0
    postParse(T[u].left)
    postParse(T[u].right)
    print(" " + str(u), end="")

# find parent
for u, t in enumerate(T):
    if t.parent == -1:
        parent = u
        break
        

print("Preorder")
preParse(parent)
print()
print("Inorder")
inParse(parent)
print()
print("Postorder")
postParse(parent)
print()


Measured memory_bytes: 5616
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    mt = 10 ** 20
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            t = n // i
            mt = min(mt, t + i - 2)
    print(mt if mt != 10 ** 20 else "error")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38640
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Spandan Mishra
 */
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);
        DChatInACircle solver = new DChatInACircle();
        solver.solve(1, in, out);
        out.close();
    }

    static class DChatInACircle {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.readInt();
            List<Integer> ls = new ArrayList<>();
            for (int i = 0; i < n; i++)
                ls.add(in.readInt());

            Collections.sort(ls);
            List<Integer> res = new ArrayList<>();
            res.add(ls.get(n - 1));
            for (int i = n - 2; i >= 0; i--)
                for (int j = 0; j < 2; j++)
                    res.add(ls.get(i));

            long ans = 0;
            for (int i = 0; i < n - 1; i++)
                ans += res.get(i);

            System.out.println(ans);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new RuntimeException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new RuntimeException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

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

    }
}



Measured memory_bytes: 49348
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define mem(dp,a) memset(dp,a,sizeof dp);
#define all(a) a.begin(),a.end()
#define sall(a) sort(all(a))
#define X first
#define Y second
typedef long long int ll;
typedef pair<ll,ll> pp;

#define debug(x) cout << #x << " :: "<< x <<"\n";
#define debug2(x,y) cout << #x << " :: "<< x << "\t" << #y << " :: " << y << "\n";
#define debug3(x,y,z) cout << #x << " :: "<< x << "\t" << #y << " :: " << y << "\t" << #z << " :: " << z << "\n";
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree< pp , null_type,less< pp >, rb_tree_tag,tree_order_statistics_node_update>

ll power(ll b, ll exp){
    ll res = 1;
    while(exp > 0){
        if(exp % 2){
            res = 1LL * res * b % mod;
        }
        b = 1LL * b * b % mod;
        exp /= 2;
    }
    return res;
}

int main()
{
    boost
    ll t,n;
    cin >> n;
    vector<ll> a(n);
    for(ll i=0;i<n;i++)
        cin >> a[i];
    ll ans=0;
    for(ll j=1;j<n-1;j++)   {
        for(ll i=0;i<j;i++) {
            for(ll k=j+1;k<n;k++)   {
                vector<ll> v = { a[i] , a[j] , a[k] };
                sall(v);
                set<ll> s;
                s.insert(a[i]);
                s.insert(a[j]);
                s.insert(a[k]);
                if( s.size()==3 && (v[0]+v[1])>v[2] )   {
                    ans++;
                }
            }
        }
    }
    cout << ans ;
    return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>
#include<stack>
#include<math.h>
using namespace std;
int dd[1000][1000];
int num[1000];
int inv[1001];
int x[1000];
int y[1000];
int vv[1000];
double nowt[1000];
int rev[1000];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++){
			scanf("%d%d%d",num+i,x+i,y+i);
			inv[num[i]]=i;
		}
		for(int i=0;i<a;i++)
			for(int j=0;j<a;j++)
				dd[i][j]=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
		int b;
		scanf("%d",&b);
		for(int i=0;i<b;i++){
			int c,d;
			scanf("%d%d",&c,&d);
			c=inv[c];d=inv[d];
			for(int j=0;j<a;j++){
				vv[j]=0;
				nowt[j]=999999999;
				rev[j]=-1;
			}
			nowt[c]=0;
			for(int j=0;j<a;j++){
				double M=99999999;
				int at=0;
				for(int k=0;k<a;k++){
					if(!vv[k]&&M>nowt[k]){
						M=nowt[k];
						at=k;
					}
				}
				if(M>90000000)break;
				//printf("%d\n",at);
				vv[at]=1;
				for(int k=0;k<a;k++){
					if(!vv[k]&&dd[at][k]<=2500&&nowt[k]>nowt[at]+sqrt(dd[at][k])){
						nowt[k]=nowt[at]+sqrt(dd[at][k]);
						rev[k]=at;
					}
				}
			}
			if(!vv[d])printf("NA\n");
			else {
				stack<int>S;
				int V=d;
				while(V!=c){
					S.push(V);
					V=rev[V];
				}
				printf("%d",num[c]);
				while(S.size()){
					printf(" %d",num[S.top()]);
					S.pop();
				}
				printf("\n");
			}
		}
	}
}

Measured memory_bytes: 1464
n = int(input())
log = []
b = input()
log.append(b)
flg = True
for i in range(n-1):
  w = input()
  if(b[-1:] != w[0] or w in log):
    flg = False
    break
  else:
    log.append(w)
    b = w
if(flg):
  print("Yes")
else:
  print("No")

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

using namespace std;

int main() {
	long long int h, w;
	long long int i, j, k[3], s, n, m;

	cin >> h >> w;

	if (h % 3 == 0 || w % 3 == 0) {
		cout << 0;
		return 0;
	}

	n = -1;
	for (i = 1; i < h - 1; i++) {
		m = (h - i) / 2;
		k[0] = i * w;
		k[1] = m * w;
		k[2] = (h - i - m)*w;
		s = max(max(k[0], k[1]), k[2]);
		j = min(min(k[0], k[1]), k[2]);
		if (n == -1 || n > abs(s - j))
			n = abs(s - j);
	}
	for (i = 1; i < w - 1; i++) {
		m = (w - i) / 2;
		k[0] = i * h;
		k[1] = m * h;
		k[2] = (w - i - m)*h;
		s = max(max(k[0], k[1]), k[2]);
		j = min(min(k[0], k[1]), k[2]);
		if (n == -1 || n > abs(s - j))
			n = abs(s - j);
	}
	for (i = 1; i < h; i++) {
		m = w / 2;
		k[0] = i * w;
		k[1] = (h - i)*m;
		k[2] = (h - i)*(w - m);
		s = max(max(k[0], k[1]), k[2]);
		j = min(min(k[0], k[1]), k[2]);
		if (n == -1 || n > abs(s - j))
			n = abs(s - j);
	}
	for (i = 1; i < w; i++) {
		m = h / 2;
		k[0] = i * h;
		k[1] = (w - i)*m;
		k[2] = (w - i)*(h - m);
		s = max(max(k[0], k[1]), k[2]);
		j = min(min(k[0], k[1]), k[2]);
		if (n == -1 || n > abs(s - j))
			n = abs(s - j);
	}

	cout << n;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-6;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair

ll X;

void solve()
{
	ll cur = 0;
	for(int i=1; ; ++i){
		cur += i;
		if(cur >= X){
			cout << i << endl;
			break;
		}
	}
}

int main()
{
	cin >> X;
	solve();
}

Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
cnt,po=0,0
for i in range(n):
    if A[i]<0:po +=1
    A[i]=abs(A[i])
    cnt +=A[i]
print(cnt-2*min(A) if po%2==1 else cnt)

Measured memory_bytes: 14224
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        s: chars,
    }
    let n = n / 2;
    puts!("{}\n", if s[..n] == s[n..] { "Yes" } else { "No" });
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
#define met(a,b) memset(a,b,sizeof(a))

int solve(int n)
{
    int ans=0;
    while(n){
        ans+=n%10;
        n/=10;
    }
    return ans;
}

int main()
{
    int n,Min=inf;
    scanf("%d",&n);
    for(int i=1;i<=n/2;i++){
        Min=min(Min,solve(i)+solve(n-i));
    }
    printf("%d\n",Min);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
 	 int n,m;
 //	 cin >> n >> m;
 	 string a;
 	 string b;
	int i;
	cin>>a>>b;
	n=a.size();
	m=b.size();
      int lcs[n+1][m+1];
       for(i=0;i<=n;i++)
       {
       	 for(int j=0;j<=m;j++)
       	{
       		if(i==0||j==0)
       		{
       			lcs[i][j]=0;
       		}
       		else if(a[i-1]==b[j-1])
       		{
       			lcs[i][j]=1+lcs[i-1][j-1];
       		}
       		else
       		{
       			lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
       		}
       	}
      }
      //cout<<"length of lCS is "<<lcs[n][m]<<"\n";
      string s="";
      i=n;
      int j=m;
       while(i>0&&j>0)
       {
       	     if(a[i-1]==b[j-1])
      		{
      			s=s+a[i-1];
      			i--;
      			j--;
      		}
      		else if(lcs[i-1][j]>lcs[i][j-1])
      		{
      			i--;
      			//continue;
      		}
      		else
      		{
      			j--;
      		}
      	}
      	//cout<<"The LCS is "<<s<<"\n";
      	//cout<<s;
      	reverse(s.begin(),s.end());
      	cout<<s;
      	return 0;
      }



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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

int main(){
   int n;
   cin >> n;
   vector<int>ans;
   rep(i, 2, 55556){
       int p = i;
       vector<int>temp;
       for(int j=1; j*j<=p; j++){
           if(p%j==0){
               temp.push_back(j);
               if(p/j!=j)temp.push_back(p/j);
           }
       }
       if(temp.size() == 2 && p%5 == 1){
           ans.push_back(p);
       }
   }
   rep(i, 0, n)cout << ans[i] << " ";
   cout << endl;
}

Measured memory_bytes: 3516
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]  # 自身が親だとして初期化
        self.rank = [0 for _ in range(n)]  # 自身が根なので根の深さ0として初期化
        self.size = [1 for _ in range(n)]  # 根以外は0、根ならそのグループの大きさを持つ

    def find(self, x):
        """xの属する根を求める"""
        if self.par[x] == x:  # 親が自分自身なら自分が根
            return x
        else:
            self.par[x] = self.find(self.par[x])  # さらに深く探索する
            return self.par[x]

    def unite(self, x, y):
        """x,yの属する集合のマージ"""
        x = self.find(x)  # xの根
        y = self.find(y)  # yの根
        if x == y:  # 同じ根を持つなら何もしない
            return
        if self.rank[x] < self.rank[y]:  # yの根のほうが深いとき
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        """xとyが同じ集合に属するかを判定"""
        return self.find(x) == self.find(y)


def calc_patterns(li):
    ans = 1
    count = 0
    for num in li:
        if num != 0:
            count += 1
            ans *= num
    C = count * (count - 1)//2
    return ans


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

bridge = []
for i in range(M):
    xi, yi = map(int, input().split())
    xi -= 1
    yi -= 1
    bridge.append((xi, yi))

huben = N*(N-1)//2
ans = [0 for i in range(M+1)]
unionfind = UnionFind(N)
# print(unionfind.size)
# print(huben)
ans[0] = huben
i = 0
for xi, yi in (reversed(bridge)):
    # print(unionfind.par)
    i = i+1
    if not unionfind.same(xi, yi):
        huben -= unionfind.size[unionfind.find(xi)] * \
            unionfind.size[unionfind.find(yi)]

    ans[i] = huben
    # print(huben)
    unionfind.unite(xi, yi)
    # print(unionfind.size)

# print(ans)

for i in range(M-1, -1, -1):
    print(ans[i])


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

int main(){
	 int  n,d; cin>>n>>d;
	 ll ans = 0;
	 for(int i=0;i<n;i++){
	 	ll x,y; cin>>x>>y;
	 	if(sqrt(pow(x,2)+pow(y,2))<=d) ans++;
	 }
	 cout<<ans;
	 return 0;
}

Measured memory_bytes: 3680
import java.util.Scanner;

public class Main {
    static Scanner in = new Scanner(System.in);

    public static void main(String[] args) {
        int n = in.nextInt();
        int[] a = new int[n + 1];
        boolean[] b = new boolean[n + 1];
        for (int i = 1; i <= n; i++) {
            a[i] = in.nextInt();
        }
        int i = 1, ans = 0;;
        while(true){
            if(i == 2){
                break;
            }
            if(i == a[i] || b[i]){
                System.out.println(-1);
                return;
            }
            b[i] = true;
            i = a[i];
            ans++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 50576
X,Y=map(int,input().split())
if (X+Y)%3!=0:
  print(0)
  exit()
A=int((X+Y)/3)
B=int((2*Y-X)/3)
if A<0 or B<0:
  print(0)
  exit()
MOD=10**9+7
def comb(n,k):
  tmp=1
  for i in range(n-k+1,n+1):
    tmp*=i
    tmp%=MOD
  for i in range(1,k+1):
    tmp*=pow(i,MOD-2,MOD)
    tmp%=MOD
  return tmp
ans = comb(A,B)
print(ans%MOD)

Measured memory_bytes: 40912
open Printf
open Scanf

let num () = scanf "%d\n" (fun x -> x)
let num2 () = scanf "%d %d\n" (fun x y -> (x, y))
let num3 () = scanf "%d %d %d\n" (fun x y z -> (x, y, z))

let () =
  let (d, t, s) = num3 () in
  if s * t >= d then
    printf "Yes\n"
  else
    printf "No\n"



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

int main(){
    string N;
    cin >> N;

    string s = "No";
    if(N[0] == '7') s = "Yes";
    if(N[1] == '7') s = "Yes";
    if(N[2] == '7') s = "Yes";

    cout << s << endl;
}

Measured memory_bytes: 3572
using System;

namespace Tenka1_Biginner_B
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			string[] instr = Console.ReadLine().Split(' ');
			int a = int.Parse(instr[0]);
			int b = int.Parse(instr[1]);
			int k = int.Parse(instr[2]);
			
			
			for (int i = 0; i < k; i++) {
				if (i % 2 == 0)
				{
					if (a % 2 == 1)
					{
						a--;
					}
					
					b += a / 2;
					a -= a / 2;
				}
				
				if (i % 2 == 1)
				{
					if (b % 2 == 1)
					{
						b--;
					}
					
					a += b / 2;
					b -= b / 2;
				}
			}
			
			Console.WriteLine(a + " " + b);
		}
	}
}

Measured memory_bytes: 11092
N = int(input())
src = list(map(int,input().split()))

cums = [0]
for a in src:
    cums.append(cums[-1] + a)

ps = [None] * (N+1)
qs = [None] * (N+1)
rs = [None] * (N+1)
ss = [None] * (N+1)

l = 1
for r in range(2,N-1):
    p1 = cums[l]
    q1 = cums[r] - cums[l]
    d1 = abs(p1-q1)
    while l < r:
        p2 = cums[l+1]
        q2 = cums[r] - cums[l+1]
        d2 = abs(p2-q2)
        if d2 > d1: break
        l += 1
        p1,q1,d1 = p2,q2,d2
    ps[r] = p1
    qs[r] = q1

r = N-1
for l in range(N-2,1,-1):
    r1 = cums[r] - cums[l]
    s1 = cums[N] - cums[r]
    d1 = abs(r1-s1)
    while l < r:
        r2 = cums[r-1] - cums[l]
        s2 = cums[N] - cums[r-1]
        d2 = abs(r2-s2)
        if d2 > d1: break
        r -= 1
        r1,s1,d1 = r2,s2,d2
    rs[l] = r1
    ss[l] = s1

ans = cums[-1] * 999
for p,q,r,s in zip(ps,qs,rs,ss):
    if p is None: continue
    tmp = max(p,q,r,s) - min(p,q,r,s)
    ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 45404
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from typing import Iterable
import sys
def main(N, M, KL):
    uf = UnionFindTree(N + M)
    for i, (K, *L) in enumerate(KL):
        for l in L:
            uf.union(i, N + l - 1)
    print('YES' if uf.same_all(range(N)) else 'NO')

class UnionFindTree:
    def __init__(self, n: int) -> None:
        self.parent = [-1] * n

    def find(self, x: int) -> int:
        p = self.parent
        while p[x] >= 0: x, p[x] = p[x], p[p[x]]
        return x

    def union(self, x: int, y: int) -> bool:
        x, y, p = self.find(x), self.find(y), self.parent
        if x == y: return False
        if p[x] > p[y]: x, y = y, x
        p[x], p[y] = p[x] + p[y], x
        return True

    def same(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)

    def size(self, x: int) -> int:
        return -self.parent[self.find(x)]

    def same_all(self, indices: Iterable) -> bool:
        f, v = self.find, self.find(indices[0])
        return all(f(i) == v for i in indices)

if __name__ == '__main__':
    input = sys.stdin.readline
    N, M = map(int, input().split())
    KL = [list(map(int, input().split())) for _ in range(N)]
    main(N, M, KL)


Measured memory_bytes: 91408
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String N = sc.next();
		sc.close();
		int divisor = 0;
		for(int a = 0 ; a < N.length(); a++){
			divisor = divisor + Integer.parseInt(N.substring(a, a+1));
		}
		System.out.println(Integer.parseInt(N)%divisor==0?"Yes":"No");
	}
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define inf 1000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define vll vector<lli>
#define stp setprecision(15)
#define eps 0.000001
#define endl '\n'
#define mod2 998244353
#define ll lli

using namespace std ;

#define N 200000+5 

typedef tree<lli,null_type,less<lli>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

int main() 
{
/////////////////////////////////////
    
    fastio;
 
/////////////////////////////////////    

    lli n;
    cin>>n;

    lli a[n],mx=-1*inf,b[n];
    loopl(i,0,n) { cin>>a[i]; mx = max(mx,a[i]); b[i] = a[i];}

    sort(b,b+n);

    if(b[n-1] == b[n-2])
    {
        loopl(i,0,n) cout<<b[n-1]<<endl;
    }

    else
    {
        loopl(i,0,n)
        {
            if(a[i] != b[n-1]) cout<<b[n-1]<<endl;
            else cout<<b[n-2]<<endl;
        }
    }
}



Measured memory_bytes: 4736
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)
typedef long long ll;

using namespace std;


int main(void){

string s[]={"abcde","fghij","klmno","pqrst","uvwxy","z.?! "};
string ind,res;
	while(cin >> ind){
		if(cin.eof()) break;
		res="";
		for(int i=0; i<ind.size(); i+=2){
			char s1=ind[i], s2=ind[i+1];
			if(s1<'1' | s1>'6' || s2<'1' || s2>'5' ){
				res = "NA";  break;
			}
			res += s[s1 - '0'- 1][s2 - '0'- 1];
		}
		cout << res << endl;
	}
	return 0;
	
}

Measured memory_bytes: 1196
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <math.h> // sqrt
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> data(N - 1);
    for (int i = 0; i < N - 1; i++) {
        cin >> data.at(i);
    }
    vector<int> ans(N, 0);
    for (int x : data) {
        ans.at(x - 1)++;
    }
    for (int i = 0; i < N; i++) {
        cout << ans.at(i) << endl;
    }
}

Measured memory_bytes: 4840
#include <iostream>
#include <cmath>
using namespace std;
int main(){
    double x,y,j,k,a;
    cin>>x>>y>>j>>k;
    a=sqrt((x-j)*(x-j)+(y-k)*(y-k));
    printf("%.4lf\n",a);
    return 0;
}


Measured memory_bytes: 3212
// 156-C

#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

int main(){
    int n, buf=INT_MAX, tmp;
    cin >> n;
    vector<int> x(n, 0);
    for(int i=0; i<n; i++){
        cin >> x.at(i);
    }
    vector<int>::iterator itr_max, itr_min, itr;
    itr_max = max_element(x.begin(), x.end());
    itr_min = min_element(x.begin(), x.end());
    for(int i = *itr_min; i <= *itr_max; i++){
        tmp = 0;
        for(itr = x.begin(); itr < x.end(); itr++){
            tmp += (i - *itr) * (i - *itr);
        }
        if(buf > tmp) buf = tmp;
    }
    cout << buf << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
template<class T> inline void chmax(T &a,T b){if(a<b)a=b;}
template<class T> inline void chmin(T &a,T b){if(a>b)a=b;}

int main(){
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N;cin >> N;
    cout << 48 - N << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 18 21:45:18 2020

@author: masat
"""

N = int(input())
end_start_list = []
for i in range(N):
    X, L = map(int, input().split())
    e_s = [X+L, X-L]
    end_start_list.append(e_s)

end_start_list.sort()

#print(start_end_list)

e_s_0 = end_start_list[0]
latest_end = e_s_0[0]
counter = 1
for i in end_start_list:
    if i[1] >= latest_end:
        counter += 1
        latest_end = i[0]
    else:
        pass

print(counter)


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

using namespace std;

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

  if (A+B > C+D) {
    cout << "Left" << endl;
  } else if (A+B < C+D) {
    cout << "Right" << endl;
  } else {
    cout << "Balanced" << endl;
  }
  
  return 0;
}

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

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

using namespace std;

int main() {

	SINT32 N = 0;
	SINT64 ANS = 0;

	cin >> N;

	vector<SINT32> DATA(N);
	
	for (SINT32 i = 0; i < N; i++) {
		cin >> DATA[i];
		ANS += DATA[i] - 1;
	}

	cout << ANS << endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>

using namespace std;

typedef long long ll;

int main() {
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    
    int ans = 0;
    
    for (int a = 0; a <= A; ++a) {
        for (int b = 0; b <= B; ++b) {
            if (X - 500 * a - 100 * b >= 0) {
                int c = (X - 500 * a - 100 * b) / 50;
                if (c <= C) ++ans;
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  vector<int> N(4);
  vector<int> ans = {1, 4, 7, 9};
  while (cin >> N[0] >> N[1] >> N[2] >> N[3]) {
    sort(N.begin(), N.end());
    bool res = N == ans;
    cout << (res ? "YES" : "NO") << endl;
  }
  return 0;
}


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

int main(){
  long N;
  cin >> N;
  vector<long> A(N);
  for(int i = 1; i <= N; i++){
    long tmp;
    cin >> tmp;
    A.at(i-1) = tmp - i;
  }
 
  // Aの中央値を計算する
  sort(A.begin(), A.end());
  long med = A.at((A.size()-1)/2);
  
  long ans = 0;
  for(auto a : A){
    ans += abs(a - med);
  }
  cout << ans << endl;
  
  // 距離を返す
  // 出力する
}


Measured memory_bytes: 1792
n=int(input())

def search(a,b,a_in,b_in):
    c=(a+b)//2
    print(c,flush=True)
    c_in=input()
    if(c_in=='Vacant'):
        return
    if(((a-c)%2==0) ^ (a_in==c_in)):
        #空席はc未満
        search(a,c,a_in,c_in)
    else:
        search(c,b,c_in,b_in)

a=0
print(a,flush=True)

a_in=input()

if(a_in!='Vacant'):
    search(0,n,a_in,a_in)



Measured memory_bytes: 3660
def alpha2num(alpha):
    num=0
    for index, item in enumerate(list(alpha)):
        num += pow(26,len(alpha)-index-1)*(ord(item)-ord('A')+1)
    return num

def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

n=int(input())

s = num2alpha(n)
print(s.lower())

Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
ll a[maxn], num[maxn];//a records the number string, num[i] records the number of number string who modules p has remainder i
int main()
{
	ll n,p;
	scanf("%lld%lld",&n,&p);
	for(int i=1;i<=n;i++)
	{
		scanf("%1d",&a[i]);
	}
	ll ans=0;
	if(p==2 || p==5)
	{
		for(int i=1;i<=n;i++)
		{
			if(a[i]%p == 0) ans+=i;
		}
	}
	else
	{
		num[0]=1;//0 % p = 0, so initialize 1
		ll sum=0, x=1;//sum is the number corresponding to number string, x is 1ex
		for(int i=n;i>=1;i--)
		{
			(sum+=a[i]*x)%=p;//sum=sum+s[i]*x, sum=sum%p;
			x=x*10%p;
			ans+=num[sum];
			num[sum]++;
		}
	}
	cout<<ans<<endl;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int p,q,r;
  cin>>p>>q>>r;
  cout<<min({p+q,q+r,r+p})<<endl;
  return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
from bisect import bisect_left
def isok(n):
  sum=0
  for i in range(N):
    sum+=N-bisect_left(A,n-A[i])
  return sum>=M
start,end=0,2*10**5+1
while end-start>1:
  mid=(start+end)//2
  if isok(mid):
    start=mid
  else:
    end=mid
b=[A[0]]
for i in range(1,N):
  b.append(b[-1]+A[i])
l=0
ans=0
bn=b[N-1]
for i in range(N):
  a=bisect_left(A,start-A[i])
  l+=N-a
  if a>0:
    ans+=A[i]*(N-a)+bn-b[a-1]
  else:
    ans+=A[i]*(N-a)+bn
ans-=start*(l-M)
print(ans) 

Measured memory_bytes: 87788
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <queue>
#include <deque>
#include <vector>
#define maxc 100010
#define inf 0x3f3f3f3f
#define ll long long
using namespace std;
int main(){
   int n;
   char a[666666];
   cin>>n;
   for(int i=0;i<n;i++)
        cin>>a[i];
    int sum1=0;
    for(int i=1;i<n;i++)
        if(a[i]=='E')
            sum1++;
    int sum=sum1;
    for(int i=0;i<n-1;i++){
        if(a[i]=='E'&&a[i+1]=='E')
            sum1--;
        if(a[i]=='W'&&a[i+1]=='W')
            sum1++;
        if(sum>sum1)
            sum=sum1;
    }
   cout<<sum<<endl;
   return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;
 
int main(){
  int a,b,k;
  cin >> a >>b >>k;
  REP(i,a,b+1){
   if(i<a+k || i>b-k)cout << i << endl; 
  }
return 0;}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d;
	int ans,bns;
	cin>>a>>b>>c>>d;
	ans=a*b;
	bns=c*d;
	if(ans>=bns)
	cout<<ans<<endl;
	else
	cout<<bns<<endl;
return 0;
}

Measured memory_bytes: 256