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

int main() {
  int64_t n;
  cin>>n;
  vector<int64_t> x(n);
  vector<int64_t> y(n);
  for(int64_t i=0;i<n;i++){
    cin>>x.at(i);
    y.at(i)=x.at(i);
  }
  sort(y.begin(),y.end());
  int64_t mid1=y.at(n/2-1),mid2=y.at(n/2);
  for(int64_t i=0;i<n;i++){
    if(x.at(i)<mid1){
      cout<<mid2<<endl;
      continue;
    }
    if(x.at(i)>mid2){
      cout<<mid1<<endl;
      continue;
    }
    if(x.at(i)==mid1){
      cout<<mid2<<endl;
      continue;
    }
    if(x.at(i)==mid2){
      cout<<mid1<<endl;
    }
  }
}

Measured memory_bytes: 5376
#####segfunc#####
def segfunc(x, y):
    return max(x, y)
#################

#####ide_ele#####
ide_ele = 0
#################

class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(logN)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """
    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res
# coding: utf-8
# Your code here!
a = input().split()
N = int(a[0])
M = int(a[1])
b = []
k = [int(input()) for i in range(N)]

temp = int(0)

for i in range(300001):
    b.append(0)
    
seg = SegTree(b, segfunc, ide_ele)

for i in range(N):
    temp = seg.query(max(0, k[i]-M), min(300001, k[i]+M+1))
    seg.update(k[i], temp+1)
    
print(seg.query(0,300001))

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n-1);
  rep(i,n-1) cin >> a.at(i);
  
  vector<int> buka(n);
  rep(i,n-1) buka.at((a.at(i))-1)++;
  rep(i,n) cout << buka.at(i) << endl;
}

Measured memory_bytes: 4856
#include <cstdio>

int main(){
    int n;
    scanf("%d",&n);
    int d[4];
    d[0] = n / 1000;
    d[1] = n % 1000 / 100;
    d[2] = n % 100 / 10;
    d[3] = n % 10;
    if((d[0] == d[1] && d[1] == d[2]) || (d[1] == d[2] && d[2] == d[3])){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int better(int a, int b)
{
	int better;
	if (a < b)
	{
		better = b;
	}
	else
	{
		better = a;
	}
	return better;
}

int main()
{
	int a[100100];
	int b[100100];
	int c[100100];
	int N = 0;
	int sumA;
	int sumB;
	int sumC;
	int data = 0;
	int subA, subB, subC;
	int Nlimit = pow(10.0,5.0);
	int abcLimit = pow(10.0, 4.0);
	int allSum;

	if (scanf("%d", &N) != 1)
	{
		exit(1);
	}
	if (1 <= N  || N <= Nlimit)
	{
	}
	else
	{
		exit(1);
	}


	for (int i = 0; i < N; i++)
	{
		if (scanf("%d%d%d", &a[i], &b[i], &c[i]) != 3)
		{
			exit(1);
		}
		if (1 <= a[i] || 1 <= b[i] || 1 <= c[i])
		{
		}
		else
		{
			exit(1);
		}

		if (a[i] <= abcLimit || b[i] <= abcLimit || c[i] <= abcLimit)
		{
		}
		else
		{
			exit(1);
		}

		if (i < 1)
		{
			subA = a[i];

			subB = b[i];

			subC = c[i];
		}
		else
		{
			subA = a[i] + better(sumB, sumC);

			subB = b[i] + better(sumA, sumC);

			subC = c[i] + better(sumA, sumB);
		}

		sumA = subA;
		sumB = subB;
		sumC = subC;

	}

	printf("%d", better(better(sumA,subB),sumC));

	return 0;

}

Measured memory_bytes: 1280
a = int(input())
b = list(map(int, input().split()))
c = [0] * (a + 1)
e = []
for i in range(len(b), 0, -1):
    d = 0
    for j in range(i, a + 1, i):
        d += c[j]
    if d % 2 != b[i-1]:
        c[i] += 1
        e.append(str(i))
f = sum(c)
print(f)
if len(e) > 1:
    print(" ".join(e))
elif len(e) == 1:
    print(e[0])


Measured memory_bytes: 17208
// AOJ 0636: Foehn Phenomena
// 2017.12.14 bal4u@uu

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

long long dx[200001];
long long S, T;
char buf[40], *p;

int getint()
{
	int n = 0;
	if (*p == '-') {
		p++; while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
		p++; return -n;
	}
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	p++; return n;
}

long long calc(int i, int x)
{
	long long d;

	if (x > 0) {
		if (dx[i] >= 0) d = x*S;
		else if (x <= -dx[i]) d = x*T;
		else d = -dx[i]*T+(x+dx[i])*S;
	} else if (x < 0) {
		if (dx[i] <= 0) d = x*T;
		else if (-x <= dx[i]) d = x*S;
		else d = -dx[i]*S+(x+dx[i])*T;
	}
	dx[i] += x;
	return -d;
}

int main()
{
	int N, Q, i, a0, a, l, r, x;
	long long u, d, ans;
	
	fgets(p=buf, 40, stdin);
	N = getint(), Q = getint(), S = getint(), T = getint();

	fgets(buf, 10, stdin);
	u = d = a0 = 0;
	for (i = 1; i <= N; i++) {
		fgets(p=buf, 10, stdin);
		a = getint();
		dx[i] = a - a0;
		if      (a > a0) u += a - a0;
		else if (a < a0) d += a0 - a;
		a0 = a;
	}

	ans = d*T - u*S;
	while (Q--) {
		fgets(p=buf, 30, stdin);
		l = getint(), r = getint(), x = getint();
		ans += calc(l, x);
		if (r < N) ans += calc(r+1, -x);
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3420
#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[i];
    vector<int> dp(n);
    dp[0] = 0; dp[1] = abs(h[0] - h[1]);
    for(int i = 2; i < n; i++)
        dp[i] = min(dp[i-1] + abs(h[i-1] - h[i]) , dp[i-2] + abs(h[i-2] - h[i]));
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 3908
#include <iostream>
#include <cmath>
using namespace std;
const long long inf=9999999999ll;
long long a[200005],sum[200005];
int main()
{
	int n,i;
	long long ans=inf,x,y;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>a[i];
		sum[i]=sum[i-1]+a[i];
	}
	for(i=1;i<=n-1;i++)
	{
		x=sum[i];
		y=sum[n]-sum[i];
		if(labs(x-y)<ans)ans=labs(x-y);
	}
	cout<<ans;
}

Measured memory_bytes: 3328
from functools import lru_cache

N = int(input())

@lru_cache(maxsize=None)
def gcd2(a, b):
  while b != 0:
    a, b = b, a % b
  return a

def gcd(a, b, c):
  return gcd2(gcd2(a, b), c)

res = 0

for i in range(1, N + 1):
  for j in range(i, N + 1):
    for k in range(j, N + 1):
      if i == j == k:
        res += gcd(k, j, i)
      elif i != j != k:
        res += gcd(k, j, i) * 6
      else:
        res += gcd(k, j, i) * 3

print(res)


Measured memory_bytes: 12616
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int n,nn;
    cin>>n;
    while(n--){
        int X,Y,W,H,cnt=0;
        cin>>X>>Y>>W>>H;
        cin>>nn;
        while(nn--){
            int catX,catY;
            cin>>catX>>catY;
            if(X<=catX&&catX<=H+X&&Y<=catY&&catY<=W+Y)cnt++;
        }
        cout<<cnt<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
int main(void){
    int a, b;
    scanf("%d",&a);
    scanf("%d",&b);
    int sum = a + b;
    int aa = sum / 2;
    if (sum % 2 == 0)
    {
        printf("%d",aa);
    }else
    {
        printf("IMPOSSIBLE");
    }
    
    
    return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n,m,ans;

    cin>>n>>m;

    if(n==1 and m==1)
    {
        ans = 1;
    }

    else if(n==1)
    {
        ans = m-2;
    }

    else if(m==1)
    {
        ans = n-2;
    }

    else
    {
        ans = (m-2)*(n-2);
    }


    cout<<ans;

    return 0;


}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<vector<int>> A(2, vector<int>(N));
    rep(i, 0, 2) rep(j, 0, N) {
        cin >> A[i][j];
    }
    vector<vector<int>> dp(2, vector<int>(N, 0));
    dp[0][0] = A[0][0];
    rep(j, 0, N) rep(i, 0, 2) {
        if (!i) {
            chmax(dp[i + 1][j], dp[i][j] + A[i + 1][j]);
        }
        if (j + 1 < N) {
            chmax(dp[i][j + 1], dp[i][j] + A[i][j + 1]);
        }
    }
    cout << dp[1][N - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
n, k, q = list(map(int, input().split()))

collect = [0] * (n+1)
for i in range(q):
    p = int(input())
    collect[p] += 1

for j in range(1, n+1):
    if k - (q - collect[j]) > 0:
        print("Yes")
    else:
        print("No") 

Measured memory_bytes: 76512
#include<stdio.h>
#include<math.h>
int main(){
int N,Y;
scanf("%d " ,&N);
scanf("%d" ,&Y);
double k = Y / 1000;
double b = k-N;
double round_x ,round_y ,round_z;
int answer_x ,answer_y ,answer_z ;
round_x = floor(b/4);
round_y = ceil(2*(b)/9);
round_z = floor(k/5);

if(round_y<=round_x && round_y <= round_z){
     answer_x = b - 4*round_y;
     answer_y = 9*round_y - 2 * b;
     answer_z = k - 5 * round_y;

}else {
    answer_x = -1;
    answer_y = -1;
    answer_z = -1;
}
printf("%d %d %d ", answer_x ,answer_y ,answer_z );
return 0;
}

Measured memory_bytes: 128
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

mod = 998244353

# nCk
## 0!~n!をmodしつつ求める
def fact_all(n,M=mod):
    f = [1]*(n+1)
    ans = 1
    for i in range(1,n+1):
        ans = (ans*i)%M
        f[i] = ans
    return f

## inv(0!)~inv(n!)をmodしつつ求める
def fact_inv_all(fact_all,M=mod):
    N = len(fact_all)
    finv = [0]*N
    finv[-1] = pow(fact_all[-1],M-2,M)
    for i in range(N-1)[::-1]:
        finv[i] = finv[i+1]*(i+1)%M
    return finv

## nCkをmodしつつ返す
def nCk(n,k,fact_list=[],inv_list=[],M=mod):
    return (((fact_list[n]*inv_list[k])%M)*inv_list[n-k])%M

N,A,B,K = LI()

# xA+yB=K のとき，x個,y個をN個から独立に選べば良い

fl = fact_all(N)
il = fact_inv_all(fl)

ans = 0
for i in range(N+1):
    if (K-A*i)%B == 0:
        num = (K-A*i)//B
        if 0 <= num <= N:
            ans += nCk(N,i,fl,il)*nCk(N,num,fl,il)
            ans %= mod

print(ans)

Measured memory_bytes: 46060
/*
ID: wangjun30
LANG: C++11
TASK:
*/
#include<iostream>
#include<algorithm>
#include<array>
#include<unordered_map>
#include<map>
#include<set>
#include<list>
#include<unordered_set>
#include<vector>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
//#include<fstream>
#define int long long
using namespace std;
//ifstream cin(".in");
//ofstream cout(".out");
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int nb;
	cin>>nb;
	if(nb/100==7 || (nb/10)%10==7 || nb%10==7)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 3636
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

"""
逆再生。長さL以上になるものをくっつけられる。
一度L以上になったらそこだけ見ていけばよい
"""

N,L = map(int,input().split())
A = [int(x) for x in input().split()]

A2 = [x+y for x,y in zip(A,A[1:])]

M = max(A2)
i = A2.index(M)
if M < L:
    answer = ['Impossible']
else:
    answer = ['Possible']
    i += 1 # ここを最後にする
    answer += [str(x) for x in range(1,i)] + [str(x) for x in range(N-1,i,-1)] + [str(i)]

print('\n'.join(answer))

Measured memory_bytes: 19368
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cstdlib>
#include <math.h>
#include<algorithm>
using namespace std;


int main(int argc,char** argv)
{

	int a,b;
	cin >> a >> b;
	cout << a-b+1 <<endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){ 
     int i, j, n; 
     char mark; 
     char marks[4]={'S', 'H', 'C', 'D'}; 
     int num; 
     bool cards[4][13]={false}; 
 
 
     scanf("%d ", &n); 
     for(i=0;i<n;i++){ 
         scanf("%c %d ", &mark, &num); 
         for(j=0;j<4;j++){ 
             if(mark==marks[j]){ 
                 cards[j][num-1]=true; 
                 break; 
            } 
         } 
     } 
     for(i=0;i<4;i++){ 
         for(j=0;j<13;j++){ 
             if(!cards[i][j]){ 
                 printf("%c %d\n", marks[i], j+1); 
             } 
         } 
     } 
     return 0; 
 } 

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

namespace CSharpSample01
{


    class Program
    {
        static int cnt = 0;
        const int SENTINEL = 2000000000; 

        static void Merge(int[] data_ary, int left_ind, int mid_ind, int right_ind)
        {
            int lenght = data_ary.Length;
            int left_n = mid_ind - left_ind;  //left_indからmid_ind - 1の要素数
            int right_n = right_ind - mid_ind;  //mid_indからright_ind - 1までの要素数

            //番兵を入れるため1つ余分に確保
            int[] left_ary = new int[left_n + 1];
            int[] right_ary = new int[right_n + 1];

            //left_indからleft_ind + left_n - 1まで
            for (int i = 0; i < left_n; i++)
            {
                left_ary[i] = data_ary[left_ind + i];
            }

            //mid_indからmid_ind + right_n - 1まで
            for(int i = 0; i < right_n; i++)
            {
                right_ary[i] = data_ary[mid_ind + i];
            }

            //最後の要素に番兵を入れる
            left_ary[left_n] = SENTINEL;
            right_ary[right_n] = SENTINEL;

            int l = 0;
            int r = 0;

            //比べる回数はright_n - left_n
            //よって、番兵同士が比べれられることはない
            for(int k = left_ind; k < right_ind; k++)
            {
                cnt++;
                if(left_ary[l] <= right_ary[r])
                {
                    data_ary[k] = left_ary[l];
                    l++;
                }
                else
                {
                    data_ary[k] = right_ary[r];
                    r++;
                }
            }
        }

        //対象のインデックス番号はleft_indからright_ind - 1まで
        static void MergeSort(int[] data_ary, int left_ind, int right_ind)
        {
            if (left_ind + 1 < right_ind)
            {             
                int mid_ind = (left_ind + right_ind) / 2;
                MergeSort(data_ary, left_ind, mid_ind);
                MergeSort(data_ary, mid_ind, right_ind);
                Merge(data_ary, left_ind, mid_ind, right_ind);
            }
        }


        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] data_ary = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            MergeSort(data_ary, 0, data_ary.Length);

            Console.WriteLine(String.Join(" ", data_ary));
            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 84712
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	string s,t;
	int ans=0;
	cin>>s>>t;
	for(int i=0;i<s.size();i++){
		if(s[i]!=t[i]){
			ans++;
		}
	}
	cout<<ans<<endl;
    return(0);
}

Measured memory_bytes: 3848
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(){
    char str[10];

    scanf("%s",str);

    if(strcmp(str,"Sunny")==0){
        printf("Cloudy\n");
    }else if(strcmp(str,"Cloudy")==0){
        printf("Rainy\n");
    }else{
        printf("Sunny\n");
    }


    return 0;
}

Measured memory_bytes: 128
// dile a la jardinera que traigo flores

#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define sz(x) int(x.size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define FER(i,a,b) for(int i = int(a); i < int(b); ++i)
#define IFR(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;


int main(){	
	fastio;
	int gcd=0;
	int n;cin>>n;
	FER(i,0,n){
		int k;cin>>k;
		gcd=__gcd(gcd,k);
	}
	cout<<gcd<<endl;
	return 0;
}


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

int A[110][110],B[110][110];
int n,m,l;
int main(){
	while(cin >> n >> m >> l){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				cin >> A[i][j];
			}
		}
		for(int i=1;i<=m;i++){
			for(int j=1;j<=l;j++){
				cin >> B[i][j];
			}
		}
		long long C[110][110] = {{0}};
		for(int i=1;i<=n;i++){
			for(int j=1;j<=l;j++){
				for(int k=1;k<=m;k++){
					C[i][j] += A[i][k]*B[k][j];
				}
			}
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=l;j++){
				if(j!=l) cout << C[i][j] << " ";
				else cout << C[i][j] << endl;
			}
		}
	}
}


Measured memory_bytes: 3264
A, B, C, D, E, F =  map(int, input().split())
M = 0
for i in range(F // 100 // A + 1):
	for j in range((F - 100 * A * i) // 100 // B + 1):
		w = 100 * A * i + 100 * B * j
		if w == 0:
			break
		for k in range((F - w) // C + 1):
			for l in range((F - w - C * k) // D + 1):
				s = C * k + D * l
				if E >= 100 * s / w and 100 * s / w >= M:
					M = 100 * s / w
					X = [w + s, s]
print(X[0], X[1])


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

int main(){
  int N,a=0;
  string S;
  cin >> N;
  for(int i=0; i<N; i++){
    cin >> S;
    if(S=="Y")
      a=1;
  }
  if(a==1)
    cout << "Four" << endl;
  else if(a==0)
    cout << "Three" << endl;
}

Measured memory_bytes: 256
import itertools
n,m,q=map(int,input().split())
l=[list(map(int,input().split())) for i in range(q)]
M=[i+1 for i in range(m)]
L=[]
for i in itertools.combinations_with_replacement(M,n):
  L.append(i)
ans=[]
for i in range(len(L)):
  ct=0
  for j in range(q):
    if L[i][l[j][1]-1]-L[i][l[j][0]-1]==l[j][2]:
      ct+=l[j][3]
  ans.append(ct)
print(max(ans))

Measured memory_bytes: 85992
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
#define foa(i,s,e) for(ll i=(s);i<e;i++)
#define fod(i,s,e) for(ll i= (s);i>=(e);i--)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define sz(x) (ll)(x.size())
#define ANS cout<<ans<<'\n'
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
const ld pi = 3.14159265358979323846;
ll MOD = 1e9 + 7;
//ll MOD = 998244353;
const char nl = '\n';
const ll inf = 1e15;
#define fill(a,b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) fo(i, n){fo(j, m)cout<<dp[i][j]<<" ";cout<<"\n";}
ll nxt(){ll x; cin >> x; return x;}
ll mul(ll x,ll y){
    return (1ll* (x%MOD)*(y%MOD));
}
ll modpow(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=z*x;x =x*x ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll sq(ll a){
    ll ans = (1ll*a*a);
    return ans;
}
void solve(){
    ll n;
    cin >> n;
    ll x;
    ll mx = 0;
    ll ans = 0;
    fo(i, n){
        cin >> x;
        mx = max(mx, x);
        ans += (mx - x);
    } 
    ANS;  
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    freopen("error.txt" , "w" , stderr) ;
    #endif
    ll TC = 1;
    //cin>>TC;
    while(TC--){
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


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

typedef long long ll;

const ll M = 998244353;

vector<ll> fac(300001); 
vector<ll> ifac(300001); 

ll mpow(ll x, ll n){ 
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

vector<ll> pow_(300001);

int main(){
    ll N,X,K;
    cin>>N>>X>>K;

    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<300000; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M;
    }
  
  pow_[0]=1;
  for(ll i=1;i<300000;i++) pow_[i]=pow_[i-1]*(X-1)%M;


    ll ans=0;
    for(ll i=0;i<=K;i++){
      ll Z=X;
      Z*=comb(N-1,i);
      Z%=M;
      Z*=pow_[N-1-i];
      Z%=M;
      ans+=Z;
      ans%=M;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10260
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($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:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
    	x:usize,
        k:usize
    }
    println!("{}", if 500*x>=k { "Yes" } else { "No" });
}

fn calc(h:usize, a:usize) -> usize {
	if h%a>0 { h/a+1 } else { h/a}
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define dbg(x) cerr<<#x<<" = "<<x<<endl;
#define dbg_v(v,n) {cerr<<#v<<" = [";for(int III=0;III<=n;III++)cerr<<v[III]<<(III!=n?",":"]\n");}
#define ll long long
#define ld long double
#define pii pair<int,int>
#define MOD 1000000007
#define zeros(x) x&(x-1)^x
#define Nmax 22
using namespace std;
int n,A[Nmax],B[Nmax],C[Nmax],fr[Nmax];
int main(){
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i=1;i<=n;i++) cin >> A[i];
    for (int i=1;i<=n;i++) cin >> B[i];
    for (int i=1;i<n;i++) cin >> C[i];

    int ans = 0;
    for (int i=1;i<=n;i++){
        if (i > 1 && A[i-1] == A[i] - 1) ans += C[A[i-1]];
        ans += B[A[i]];
    }

    cout << ans << '\n';

    return 0;
}


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

int main(void) {
  int a, b;
  cin >> a >> b;
  
  if (a == 1 && b != 1) {
    cout << "Alice" << endl;
  } else if (a != 1 && b == 1) {
    cout << "Bob" << endl;
  } else if (a > b) {
    cout << "Alice" << endl;
  } else if (a < b) {
    cout << "Bob" << endl;
  } else {
    cout << "Draw" << endl;
  }
}
    

Measured memory_bytes: 256
#![allow(non_snake_case, unused_mut)]
use petgraph::unionfind::UnionFind;
use proconio::marker::Usize1;
//use std::collections::HashMap;
//use std::collections::HashSet;

fn main() {
    proconio::input! {
        N:usize, M:usize,K:usize,
        AB:[(Usize1,Usize1);M],
        CD:[(Usize1,Usize1);K]
    }
    let mut tree: UnionFind<usize> = UnionFind::new(N);
    let mut friends = vec![Vec::with_capacity(M); N];
    let mut blocks = vec![Vec::with_capacity(K); N];
    for &(a, b) in AB.iter() {
        tree.union(a, b);
        friends[a].push(b);
        friends[b].push(a);
    }
    for &(c, d) in CD.iter() {
        if tree.find(c) == tree.find(d) {
            blocks[c].push(d);
            blocks[d].push(c);
        }
    }
    let mut sizes = vec![0usize; N];
    for i in 0..N {
        sizes[tree.find(i)] += 1;
    }
    for i in 0..N {
        let ans = sizes[tree.find(i)] - 1 - friends[i].len() - blocks[i].len();
        print!("{} ", ans);
    }
}


Measured memory_bytes: 20392
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

string sum(string& a, string& b){
	int i = a.length() - 1;
	int j = b.length() - 1;
	int carry = 0;
	string temp;

	while(i >= 0 || j >= 0){
		int c = i >= 0 ? a[i] - '0' : 0;
		int d = j >= 0 ? b[j] - '0' : 0;

		temp.push_back((c + d + carry) % 10 + '0');
		carry = (c+d+carry) / 10;

		--i, --j;
	}

	if(carry)
		temp.push_back('1');

	reverse(begin(temp), end(temp));

	return temp;
}

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

	vector<string> input(n*2);

	for(int i = 0; i < n*2; i++){
		cin >> input[i];
	}

	for(int i = 0; i < n; i++){
		string t = sum(input[2*i], input[2*i+1]);
		if(t.length() <= 80)
			cout << t << endl;
		else
			cout << "overflow" << endl;
	}

	return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  char c;
  cin>>c;
  if(c=='A')cout<<'T'<<endl;
  if(c=='T')cout<<'A'<<endl;
  if(c=='G')cout<<'C'<<endl;
  if(c=='C')cout<<'G'<<endl;


  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  ll N;
  cin >> N;
  map<ll,ll> B;
  map<ll,ll> C;
  vector<ll> A(N);
  REP(i, N){
    cin >> A[i];
    if(i%2==0){
      B[A[i]]++;
    }else{
      C[A[i]]++;
    }
  }

  vector<P> D;
  vector<P> E;
  for(auto x:B){
    D.push_back(make_pair(x.second,x.first));
  }
  for(auto x:C){
    E.push_back(make_pair(x.second,x.first));
  }
  sort(ALL(D));
  reverse(ALL(D));
  sort(ALL(E));
  reverse(ALL(E));

  if(D.at(0).second==E.at(0).second){
    if(D.at(0).first<E.at(0).first){
      cout << (N/2-E.at(0).first)+(N/2-D.at(1).first) << endl;
    }else if(D.at(0).first>E.at(0).first){
      cout << (N/2-D.at(0).first)+(N/2-E.at(1).first) << endl;
    }else{
      if(D.at(0).first==N/2){
        cout << N/2 << endl;
      }else{
        cout << min((N/2-D.at(0).first)+(N/2-E.at(1).first),(N/2-D.at(1).first)+(N/2-E.at(0).first)) << endl;
      }
    }
  }else{
    cout << (N/2-D.at(0).first)+(N/2-E.at(0).first) << endl;
  }
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
#define ll long long 
#define ull unsigned long long 
#define f(i,x,n) for(ll int i=x;i<n;i++) 
#define re(j,x,n) for(ll int j=x;j>=n;j--)
#define f1(k,x,n) for(ll int k=x;k<=n;k++)
#define mp make_pair
#define pb push_back
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,s1,s2;
    cin>>s;
    ll int a,b;
    s1=s.substr(0,2);
    s2=s.substr(2,3);
    a=stoll(s1);
    b=stoll(s2);
    if(a>0&&a<=12&&(b>=13||b==0))
    cout<<"MMYY";
    else if((a==0||a>12)&&b<=12&&b>0)
    cout<<"YYMM";
    else if((a>0&&a<=12)&&(b<=12&&b>0))
    cout<<"AMBIGUOUS";
    else
    cout<<"NA";
}

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

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

int binSearch(int A[],int n,int key){   // ????´???°n?????????A??????????´?key?????¢???????????¢?´¢??????????????????????????°0?????????
    int left = 0;
    int right = n;
    int mid;
    while(left<right){
        mid = (left + right) / 2;
        if(A[mid]==key) return 1;
        else if(key<A[mid]) right = mid;
        else left = mid + 1;
    }
    return 0;
}

int main(){
    int n,m,a[114514],ans=0;
    scanf("%d",&n);
    int i;
    rep(i,n) scanf("%d",&a[i]);
    scanf("%d",&m);
    int tmp;
    rep(i,m){
        scanf("%d",&tmp);
        if(binSearch(a,n,tmp)) ans++;
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int n,a[N],f[N],fa[N],x[N],y[N];
vector<int>e[N];
long long ans;
struct yb
{
	int u,x,y;
	yb(){}
	yb(int _u,int _x,int _y):u(_u),x(_x),y(_y){}
	bool operator<(const yb k)const
	{
		return (((long long)k.x*y==(long long)x*k.y)?(u<k.u):((long long)k.x*y<(long long)x*k.y));
	}
};
set<yb>s;
int get(int x){return x==fa[x]?x:fa[x]=get(fa[x]);}
int main()
{
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
	{
		scanf("%d",&f[i]);
		e[f[i]].push_back(i);
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		(a[i]?y[i]:x[i])=1;
		s.insert(yb(i,x[i],y[i]));
		fa[i]=i;
	}
	for(int i=1;i<=n;i++)
	{
		auto it=s.begin();
		int u=it->u;
		s.erase(s.begin());
		int p=get(f[u]);
		if(p)
			s.erase(yb(p,x[p],y[p]));
		ans+=(long long)y[p]*x[u];
		x[p]+=x[u],y[p]+=y[u];
		if(p)
			s.insert(yb(p,x[p],y[p]));
		fa[u]=p;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 31220
#include <cstring>
#include <algorithm>
#include <map>
#include <stack>
#include <cassert>
#include <cmath>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <vector>
#include <iostream>
#include <set>
#define MP make_pair
#define F first
#define PB push_back
#define S second
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 50;
const int mod = 1e9 + 7;
const int inf = (1 << 30);
int a, b, c, d;

int main() {
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'N')
            a ++;
        if (s[i] == 'S')
            b ++;
        if (s[i] == 'E')
            c ++;
        if (s[i] == 'W')
            d ++;
    }
    int cur = 1;
    if (a > b)
        swap (a, b);
    if (c > d)
        swap (c, d);
    if (a == 0 and b > 0)
        cur = 0;
    if (c == 0 and d > 0)
        cur = 0;
    if (cur)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//uniform_int_distribution<int>(1000,10000)(rng)

ll binpow(ll a, ll b)
{
    if (b == 0)
        return 1;
    ll res = binpow(a, b / 2);
    res*=res;
    if (b % 2)
        return res * a;
    return res;
}

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

string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}
 
string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,d,x=0;
    cin>>n>>d;
    double a,b,c;
    while (n--)
    {
        cin>>a>>b;
        c=sqrt(a*a+b*b);
        if (c<=d)
            ++x;
    }
    cout<<x;
    return 0;
}

Measured memory_bytes: 3720
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(cin.hasNext()){
			int n = cin.nextInt();
			int[] a = new int[n];
			for(int i = 0; i < n;i++){
				a[i]=cin.nextInt();
			}
			Arrays.sort(a);
			int[] sum = new int[n+1];
			for(int i = 0;  i< n;i++){
				sum[i+1] = sum[i]+a[i];
			}
			int sumsum=0;
			for(int i = 0; i < n+1;i++){
				sumsum+=sum[i];
			}
			System.out.println(sumsum);
		}

	}

}

Measured memory_bytes: 13000
/*====Corycle====*/
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const ll N=305;
ll read(){
	ll s=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*f;
}
ll n,a[N],sum,tot,ans;
int main(){
	n=read();
	for(ll i=1;i<=n;i++)a[i]=read();
	for(ll i=3;i<=n;i++)sum^=a[i];
	tot=a[1]+a[2];tot-=sum;
	if(tot<0){puts("-1");return 0;}
	for(ll i=42;i>=0;i--){
		if(2*(1ll<<i)<=tot){
			if((sum>>i&1)){puts("-1");return 0;}
			ans+=(1ll<<i);
			tot-=2*(1ll<<i);
		}
	}
	if(tot){puts("-1");return 0;}
	if(ans>a[1]){puts("-1");return 0;}
	for(ll i=42;i>=0;i--){
		if((sum>>i&1)&&(ans+(1ll<<i))<=a[1])ans+=(1ll<<i);
	}
	if(ans==0){puts("-1");return 0;}
	cout<<a[1]-ans;
	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
using namespace std;
#define MAX 200005
#define MOD 998244353
#define EPS 0.00000000001
#define INF 1000000000
map<int,int> M;
set<int> S;
pair<long long,int> segment_tree[MAX*4];
int values[MAX];
int n;
void update(int index,int l,int r,int ind)
{
    if(ind<l||ind>r) return;
    if(l==r)
    {
        segment_tree[index].second++;
        segment_tree[index].first=segment_tree[index].first+values[l];
        return;
    }
    int m=(l+r)/2;
    update(index*2,l,m,ind);
    update(index*2+1,m+1,r,ind);
    segment_tree[index].second=segment_tree[index*2].second+segment_tree[index*2+1].second;
    segment_tree[index].first=segment_tree[index*2].first+segment_tree[index*2+1].first;
}
pair<long long,int> query(int index,int l,int r,int ind)
{
    pair<long long,int> ans;
    if(l==r)
    {
        ans.first=ans.second=values[l];
        ans.first=ans.first*ind;
        return ans;
    }
    int m=(l+r)/2;
    if(segment_tree[index*2].second>=ind)
    {
        ans=query(index*2,l,m,ind);
    }
    else
    {
        ans=query(index*2+1,m+1,r,ind-segment_tree[index*2].second);
        ans.first=ans.first+segment_tree[index*2].first;
    }
    return ans;
}
vector<pair<int,pair<int,int> > > Q;
void addElement(int element)
{
    update(1,0,n-1,M[element]);
}
pair<long long,int> answer()
{
    pair<long long,int> q,total=segment_tree[1];
    int element;
    if(total.second%2)
    {
        element=(total.second+1)/2;
    }
    else
    {
        element=total.second/2;
    }
    q=query(1,0,n-1,element);
    //printf("element=%d\n",element);
    pair<long long,int> ans;
    ans.second=q.second;
    ans.first=2*element-total.second;
    //printf("ans.first=%lld\n",ans.first);
    ans.first=ans.first*ans.second;
    //printf("ans.first=%lld\n",ans.first);
    ans.first=ans.first+total.first-q.first*2;
    //printf("ans.first=%lld\n",ans.first);
    return ans;
}
void initialize()
{
    int i,v;
    for(i=0;S.size()>0;i++)
    {
        v=*(S.begin());
        M[v]=i;
        values[i]=v;
        S.erase(v);
    }
    n=i;
}
int main()
{
    int q,i,j;
    pair<int,pair<int,int> > p;
    pair<long long,int> ans;
    long long sum=0;
    scanf("%d",&q);
    for(i=0;i<q;i++)
    {
        scanf("%d",&p.first);
        if(p.first==1)
        {
            scanf("%d %d",&p.second.first,&p.second.second);
            S.insert(p.second.first);
        }
        Q.push_back(p);
    }
    initialize();
    for(i=0;i<q;i++)
    {
        if(Q[i].first==1)
        {
            sum=sum+Q[i].second.second;
            addElement(Q[i].second.first);
        }
        else
        {
            ans=answer();
            ans.first=ans.first+sum;
            printf("%d %lld\n",ans.second,ans.first);
        }
    }
    return 0;
}


Measured memory_bytes: 14880
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long int ll;
ll ans(ll n){
	if(n<10) return n;
	else if(n%10==9) return 9 + ans(n/10);
	else return max(9+ans(n/10-1),n%10+ans(n/10));
}

int main(){
	ll n;
	scanf("%lld",&n);
	printf("%lld\n",ans(n));
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007LL
#define PI 3.1415926

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int n; ll t[1000], a[1000];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> t[i] >> a[i];
	}
	ll ans = t[0] + a[0];
	for (int i = 1; i < n; i++) {
		ll taka = ans / (t[i-1]+a[i-1])*t[i-1], ao = ans / (t[i-1]+a[i-1])*a[i-1];
		ans = max((t[i]+a[i])*((taka+t[i]-1)/t[i]), (t[i]+a[i])*((ao+a[i]-1)/a[i]));
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    char jhowmany, chowmany, i, j, jemx[20], jemy[20], cx[30], cy[30], rx, ry, nx, ny, result;
    scanf(" %hhd", &jhowmany);
    while(jhowmany != 0){
        nx = 10;
        ny = 10;
        //first, get an unit of input.
        for(i=0;i<jhowmany;i++){
            scanf(" %hhd %hhd", &jemx[i], &jemy[i]);
        }
        scanf(" %hhd", &chowmany);
        for(i=0;i<chowmany;i++){
            scanf(" %hhc %hhd", &cx[i], &cy[i]);
        }
        for(i=0;i<chowmany;i++){
            //culc next place for robot, nx and ny.
            rx = nx;
            ry = ny;
            if(cx[i] == 'N'){
                ny += cy[i];
            }else if(cx[i] == 'S'){
                ny -= cy[i]; 
            }else if(cx[i] == 'E'){
                nx += cy[i];
            }else{
                nx -= cy[i];
            }

            //check if jem is between (nx, ny) and (rx, ry).
            for(j=0;j<jhowmany;j++){
                if(jemx[j] == -1)
                    continue;
                if((rx <= jemx[j] && jemx[j] <= nx && ry <= jemy[j] && jemy[j] <= ny) ||
                (rx >= jemx[j] && jemx[j] >= nx && ry <= jemy[j] && jemy[j] <= ny) ||
                (rx <= jemx[j] && jemx[j] <= nx && ry >= jemy[j] && jemy[j] >= ny) ||
                (rx >= jemx[j] && jemx[j] >= nx && ry >= jemy[j] && jemy[j] >= ny)){
                    jemx[j] = -1;
                }
            }
        }
        //check if all jems are corrected.
        result = 1;
        for(i=0;i<jhowmany;i++){
            if(jemx[i] != -1){
                puts("No");
                result = 0;
                break;
            }
        }
        if(result == 1){
            puts("Yes");
        }
        scanf(" %hhd", &jhowmany);
    }
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)

using namespace std;

vector<int> vec;

int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }

int main(void) {
	long long a;
	long long b;

	vector<long long> vec;

	long long ans = 0;


	cin >> a >> b;


	string temp;

	long long min;
	long long max;

	for (int i = b; i <= a + 1; i++) {
		max = ((double)(a + (a - i + 1)) / 2) * i;

		min = ((double)(i - 1) / 2) * i;

		ans += (long long)(max - min + 1);
	}

	cout << (long long)fmod(ans, 1000000007);



}




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


static class P
{
    static void Main()
    {
        long[,] dp = new long[51, 2501];
        var na = Console.ReadLine().Split().Select(int.Parse).ToList();
        var xs = Console.ReadLine().Split().Select(int.Parse).ToList();
        dp[0, 0] = 1;
        foreach (var x in xs)
        {
            long[,] newdp = new long[51, 2501];
            for (int i = 0; i <= 49; i++)
            {
                for (int j = 0; j <= 2450; j++)
                {
                    newdp[i, j] += dp[i, j];
                    newdp[i + 1, j + x] += dp[i, j];
                }
            }
            dp = newdp;
        }
        long res = 0;
        for (int i = 1; i <= 50; i++)
        {
            for (int j = 0; j <= 2500; j++)
            {
                if(j % i == 0 && j / i == na[1]) res += dp[i, j];
            }
        }
        Console.WriteLine(res);
    }
}


Measured memory_bytes: 30176
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAX = 1e6+7;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;

bool flag, f;
string s, t, res, ans;
int main()
{
    cin >> s >> t;
    res = s;
    f = false;
    flag = false;
    for(int i = 0; i < s.size(); ++i)   //  st
    {
        flag = true;
        for(int j = 0, k = i; j < t.size(); ++j, ++k)
        {
            if(s[k] != t[j] && s[k] != '?')
            {
                flag = false;
                break;
            }
            if(s[k] == '?') res[k] = t[j];
        }
        if(flag)
        {
            ans = res;
            f = 1;
        }
        res = s;
    }
    if(f)
    {
        for(int i = 0; i < ans.size(); ++i)
            if(ans[i] == '?')   ans[i] = 'a';
        cout << ans << endl;
    }
    else    cout << "UNRESTORABLE" << endl;
    return 0;
}


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

int main(){
	int n;
	scanf("%d", &n);
	map<string, int> s;
	for(int i = 0; i < n; i++) {
		int id;
		scanf("%d", &id);
		string key;
		cin >> key;
		if(id == 0) {
			int x;
			scanf("%d", &x);
			auto p = s.emplace(key, x);
			if(!p.second) (*s.find(key)).second = x;
		}else if(id == 1) {
			printf("%d\n", (*s.find(key)).second);
		}
	}
}



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

#define all(a)  (a).begin(),(a).end()

#define mkp make_pair
#define pb push_back

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;



int main(){
    bool flag=true;
    ll ans=0,sum=0;
    int n;
    cin >>n;
    int a[n],b[n],c[n];

    for (int i = 0; i < n; i++){cin >>a[i]; --a[i];}
    for (int i = 0; i < n; i++){cin >>b[i]; ans += b[i];}
    for (int i = 0; i < n; i++)cin >>c[i];

    for (int i = 0; i < n-1; i++){
        if(a[i+1] == a[i]+1 )ans += c[a[i]];
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

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


Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m = map(int,input().split())
uf = UnionFind(n)
friend = [0]*n
for i in range(m):
    a,b = map(int,input().split())
    a -=1
    b -=1
    uf.union(a,b)
maxfriend = -1
for i in range(n):
    maxfriend = max(maxfriend,uf.size(i))
print(maxfriend)


Measured memory_bytes: 16108
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define LINY "YES\n"
#define LINN "NO\n"

int N,a,ok=1;
map<int,int> mp;
int main(){
  cin>>N;
  REP(i,N){
    cin >> a;
    if(mp[a]==0){++mp[a];}
    else{ok=false;break;}
  }
  cout <<(ok?LINY:LINN);
}

Measured memory_bytes: 9600
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	a := nextInt()
	b := nextInt()
	ans := -1
	//税抜き価格の最小値は13円(8%)、最大値は1009円(10%)
	for i := 13; i < 1010; i++ {
		if int(float64(i)*0.08) == a && int(float64(i)*0.10) == b {
			ans = i
			break
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll n;
    cin >> n;
    vector<double> a(n);
    rep(i, 0, n) cin >> a[i];
    double sum = 0;
    rep(i, 0, n) sum += (1.0 / a[i]);
    printf("%.20lf\n", 1.0/sum);
    return 0;
}

Measured memory_bytes: 3816