akhauriyash/Code-Regression huggingface dataset:
import sys
stdin = sys.stdin
from itertools import product

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

s = ns()

for plus in product([0,1], repeat=3):
    ans = s[0]
    a = int(s[0])
    for i, flag in enumerate(plus):
        if flag == 0:
            a = a + int(s[i+1])
            ans = ans + "+" + s[i+1]
        else:
            a = a - int(s[i+1])
            ans = ans + "-" + s[i+1]
    #print(ans, a)
    if a == 7:
        print(ans + "=7")
        break


Measured memory_bytes: 3064
n = int(input())
s = list(input())

cnt = s.count("R")*s.count("G")*s.count("B")
for i in range(0, n):
    for j in range(i+1, n):
        k = 2*j - i
        if s[i] == s[j] or k >= n or s[k] == s[i] or s[k] == s[j]:
            continue
        else:
            cnt -= 1

print(cnt)



Measured memory_bytes: 8988
#include <bits/stdc++.h>
using namespace std;
static const int INF = 2000000000;
static const int NIL = -1;
static const int MOD = 1000000007;
typedef long long ll;
typedef pair<int,int> P;
//#define int ll 

signed main(){
    int ans = 0;
    for(int i=0;i<6;i++){
        char a = getchar();
        if(a=='1') ans++;
    }    
    printf("%d\n",ans);
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		new Main().run();
	}
	char[][] map;
	int count = 0;
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int w = scan.nextInt();
			int h = scan.nextInt();
			if(w == 0 && h == 0){
				break;
			}
			map = new char[h][w];
			for(int i = 0;i < h;i++){
				map[i] = scan.next().toCharArray();
			}
			count = 0;
			boolean fl = false;
			for(int i = 0;i < h;i++){
				for(int j = 0;j < w;j++){
					if(map[i][j] == '@'){
						count++;
						map[i][j] = '#';
						if(i != 0){
							searchTile(i-1,j);
						}
						if(i != h-1){
							searchTile(i+1,j);
						}
						if(j != 0){
							searchTile(i,j-1);
						}
						if(j != w-1){
							searchTile(i,j+1);
						}
						fl = true;
						break;
					}
				}
				if(fl){
					break;
				}
			}
			System.out.println(count);
		}
	}
	public void searchTile(int y,int x){
		if(map[y][x] == '#'){
			return;
		}
		count++;
		map[y][x] = '#';
		if(y != 0){
			searchTile(y-1,x);
		}
		if(y != map.length-1){
			searchTile(y+1,x);
		}
		if(x != 0){
			searchTile(y,x-1);
		}
		if(x != map[0].length-1){
			searchTile(y,x+1);
		}
	}
}

Measured memory_bytes: 36144
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
typedef long long ll;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int main () {

    int n; cin >>n;
    vector<int> a(n); REP (i, n) cin >> a[i];

    sort(a.begin(), a.end());

    int al = 0;
    int bo = 0;
    for (int i = 0; i < n; i++) {
        if(i % 2 == 0) {
            al += a[n-1-i];
        } else {
            bo += a[n-1-i];
        } 
    }

    cout << al - bo << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    int i,j,k;
    vector<int> v;
    for(i=0;i<n;i++){
        cin >> k;
        v.push_back(k);
    }
    for(j=0;j<n;j++) cout << v[j] << (j==n-1?'\n':' ');
    for(i=1;i<n;i++){
        for(j=0;j<i;j++){
        if(v[j]>v[i]){
        k=v[i];
        v.erase(v.begin()+i);
        v.insert(v.begin()+j,k);
        break;
        }
        }
        for(j=0;j<n;j++) cout << v[j] << (j==n-1?'\n':' ');
    }
    return 0;
}


Measured memory_bytes: 3180
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
typedef string::const_iterator State;

int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0 ,0 };


int main(void) {

	ll k, n;
	ll a[16];
	ll total = LLINF;
	ll point = 0;
	ll high = 0;
	ll count = 0;

	cin >> n >> k;
	FOR(i, 0, n-1) {
		cin >> a[i];
	}

	bitset<15> bit;

	FOR(i, 0, pow(2, n) - 1) {
		bit = i;
		//cout << bit << endl;
		count = 0;
		if (bit[0] == false) {
			continue;
		}
		FOR(j, 0, 14) {
			if (bit[j] == true) {
				count++;
			}
		}
		if (count != k) {
			continue;
		}

		point = 0;
		high = a[0];
		FOR(j, 1, 14) {
			if (bit[j] == true) {
				if (a[j] > high) {
					high = a[j];
				}
				else {
					point += high - a[j] + 1;
					high++;
				}
			}
			else {
				if (a[j] > high) {
					high = a[j];
				}
			}
		}

		//cout << i << " " << point << endl;
		if (point < total) {
			total = point;
		}

	}

	cout << total << endl;

	return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Created: Jul, 13, 2020 15:38:31 by Nobody
# $Author$
# $Date$
# $URL$
__giturl__ = "$URL$"


from collections import defaultdict
from collections import deque
from collections import OrderedDict
import itertools
from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  H = list(map(int, input().split()))

  for i in range(1, N):
    if H[i] >= H[i-1]:
      continue
    elif H[i] + 1 == H[i-1]:
      H[i] += 1
    else:
      print('No')
      return
  print('Yes')


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 87332
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

/**
 * Cake Party
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		int N, C;
		line = br.readLine();
		N = parseInt(line.substring(0, line.indexOf(' ')));
		C = parseInt(line.substring(line.indexOf(' ') + 1));

		int sum = 0;
		StringTokenizer st = new StringTokenizer(br.readLine());
		for (int i = 0; i < C; i++) {
			sum += parseInt(st.nextToken());
		}

		int ans = sum / (N + 1);
		if (sum % (N + 1) > 0) { ans++; }

		System.out.println(ans);
	}
}


Measured memory_bytes: 24440
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

int main(){
    int n, k; cin >> n >> k;
    int p[n]; inarray(p, n);
    sort(p, p+n);
    int sum = 0;
    for(int i = 0; i < k; i++){
        sum += p[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3640
n, m = map(int, input().split())
P = tuple(map(lambda x: int(x)-1, input().split()))
par = list(range(n))
size = [1] * n
def find(x):
    """ 根のノードの値を見つけて返す """
    if x != par[x]:
        par[x] = find(par[x])
    return par[x]

def unite(x, y):
    """xとyを結合する"""
    rootx = find(x)
    rooty = find(y)
    if rootx == rooty:
        return False
    else:
        if size[rootx] < size[rooty]:
            par[rootx] = rooty
            size[rooty] += size[rootx]
        else:
            par[rooty] = rootx
            size[rootx] += size[rooty]
        return True

def same(x, y):
    """ xとyが同じ集合に属しているか """
    return find(x) == find(y)

for _ in range(m):
    x, y = map(lambda x: int(x)-1, input().split())
    unite(x, y)
groups = {}
for idx, p in enumerate(par):
    p = find(p)
    groups.setdefault(p, set())
    groups[p].add(idx)

cnt = 0
for k, g in groups.items():
    for gi in g:
        pi = P[gi]
        if pi in g:
            cnt += 1
print(cnt)



Measured memory_bytes: 49180
#include<bits/stdc++.h>
using namespace std;
#define ll   long long
int gcd(int x,int y,int z){
	return (__gcd(x,__gcd(y,z)));
}
int main(){
	int n,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				ans+=gcd(i,j,k);
			}
		}
	}
	cout<<ans;
}

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

int ix(int x, int y) { return (1001 * y) + x; }

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

  int R[1200000]{0};
  int n;
  cin >> n;

  for (int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;) {
    for (int y = y1; y < y2; ++y)
      R[ix(x1, y)]++;
    for (int y = y1; y < y2; ++y)
      R[ix(x2, y)]--;
  }

  int C[1000]{0};

  int M = 0;
  for (int x = 0; x < 1000; ++x) {
    for (int y = 0; y < 1000; ++y) {
      C[y] += R[ix(x, y)];
      M = max(M, C[y]);
    }
  }
  cout << M << endl;
}


Measured memory_bytes: 7900
import java.util.Scanner;

class Main {

	public static void main(String[] args) throws java.io.IOException {

		Scanner scan = new Scanner(System.in);

		int n;
		while ((n = scan.nextInt()) != -1) {

			int p;
			if (n <= 10) {
				p = 1150;
			} else if (n <= 20) {
				p = 1150 + (n - 10) * 125;
			} else if (n <= 30) {
				p = 2400 + (n - 20) * 140;
			} else {
				p = 3800 + (n - 30) * 160;
			}

			System.out.println(4280 - p);

		}

	}
}

Measured memory_bytes: 18552
import java.util.*;
public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
      int x = sc.nextInt();
      int ans = 0;
    if(x==0){
      ans = 1;
    }else{
        ans = 0;
    }
    
      System.out.println(ans);   
  }
}

Measured memory_bytes: 35636
// スタック
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<limits.h>

// スタック関連の定義
const int Max_Stack = 1000;
int stack_count = 0;
int ary_stack[Max_Stack];

void create_stack(void);
int push(int element);
int pop(void);

int main(void)
{
    char str[10];
    int i = 0, ch, operand_1, operand_2;
    int result;

    // スタックを作成
    create_stack();

    while( ( ch = getchar() ) != '\n' )
    {

        if( '0' <= ch && ch <= '9' )
        {
            str[i++] = ch;
        }
        else if( ch == '+' || ch == '-' || ch == '*' )
        {
            operand_1 = pop();
            operand_2 = pop();

            if( ch == '+' )
            {
                result = operand_2 + operand_1;
            }
            else if( ch == '-' )
            {
                result = operand_2 - operand_1;
            }
            if( ch == '*' )
            {
                result = operand_2 * operand_1;
            }

            // 次の計算に備えて、結果をpushしておく
            push(result);
        }
        else if( str[0] != '\0' )
        {
            str[i] = '\0';
            // 数値をプッシュする
            push(atoi(&str[0]));
            // 初期化をする
            i = 0;
            str[0] = '\0';
        }
    }

    printf("%d\n", result);

    return 0;

}

// スタックを作成する関数
void create_stack(void)
{
    int i;

    for(i = 0; i < Max_Stack; i++)
    {
        // スタックの初期化
        ary_stack[i] = 0;
    }

    return;
}

// スタックへプッシュする関数
int push(int element)
{

    if( stack_count > Max_Stack )
    {
        // サイズオーバー
        return -1;
    }

    // スタックに追加する
    ary_stack[++stack_count] = element;

    return 0;
}

// スタックからポップする関数
int pop(void)
{
    int ret = 0;

    if( stack_count < 0 )
    {
        // スタックが空の時
        ret = INT_MIN;
    }
    else
    {
        ret = ary_stack[stack_count--];
    }

    return ret;
}



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

ll dp [101][4][4][4];
const ll mod=1e9+7;

void add(ll &a,ll b){
	a=(a+b)%mod;
}

bool ng(int a,int b,int c){
	return (a==1&&b==2&&c==3);
}

int main(){
	ll n;
	cin>>n;
	dp[0][0][0][0]=1;
	for(int i=0;i<n;i++){
		for(int a=0;a<4;a++){
			for(int b=0;b<4;b++){
				for(int c=0;c<4;c++){
					for(int d=0;d<4;d++){
						if(ng(b,c,d)||ng(c,b,d)||ng(b,d,c))continue;
						if(ng(a,c,d)||ng(a,b,d))continue;
						add(dp[i+1][b][c][d],dp[i][a][b][c]);
					}
				}
			}
		}
	}
	ll ans=0;
    for(int a=0; a<4; a++) for(int b=0; b<4; b++) for(int c=0; c<4; c++)add(ans, dp[n][a][b][c]);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

#define rep(i,s,e) for (int i = s; i < e; ++i)
using namespace std;

static const int max_size = 9;
int N, M;
int C[max_size][max_size];
bool visited[max_size];
int c = 0;
void dfs(int n) {
	visited[n] = true;
	bool hasNext = false;
	rep(i, 1, N + 1) {
		if (!visited[i] && C[n][i] == 1) {
			hasNext |= true;
		}
	}

	if (!hasNext) {
		bool allVisited = true;
		rep(i, 1, N + 1) {
			allVisited &= visited[i];
		}
		if (allVisited) {
			c++;
		}
	}

	rep(i, 1, N + 1) {
		if (C[n][i] == 1 && !visited[i]) {
			dfs(i);
		}
	}
	visited[n] = false;
}

int main()
{
	cin >> N >> M;
	rep(i, 0, M) {
		int x, y; cin >> x >> y;
		C[x][y] = 1;
		C[y][x] = 1;
	}

	dfs(1);

	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #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++)
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
    // Time Complexity: faster than O(logN)[O(ArkInv(N))]
// UnionFind.data: if minus -> size of subtree (node is root)
// if plus -> parent of the node

struct UnionFind {
    vector<int> data;
    UnionFind(int sz){
        data.assign(sz,-1);
    }
    int find(int x){
        if(data[x]<0) return x;
        return data[x]=find(data[x]);
    }
    void unite(int x, int y){
        x = find(x); y = find(y);
        if(x==y) return;
        if(data[x]>data[y]) swap(x,y);
        data[x]+=data[y];
        data[y]=x;
        return;
    }
    int size(int x){
        return (-data[find(x)]);
    }
    int same(int x,int y){
        return find(x)==find(y);
    }
};
#pragma endregion library

int main(){
    int n,k,l; cin >> n >> k >> l;
    UnionFind ufr(n),uft(n);
    rep(i,k){
        int p,q; cin >> p >> q;
        p--;q--;
        ufr.unite(p,q);
    }
    rep(i,l){
        int p,q; cin >> p >> q;
        p--;q--;
        uft.unite(p,q);
    }
    map<pi,int> roots;
    rep(i,n){
        pi p = make_pair(ufr.find(i),uft.find(i));
        roots[p]=roots[p]+1;
    }
    rep(i,n){
        pi p = make_pair(ufr.find(i),uft.find(i));
        cout << roots[p] << ' ';
    } cout << endl;
}

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

#define rep0(i, n) for(int i=0; i<(int)(n);i++)
#define rep1(i, n) for(int i=1; i<=(int)(n);i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) if(flagdebug){cout << "debug (" #a "):" << endl << (a) << endl;}

typedef uint64_t ulint;
typedef int64_t lint;
using namespace std;

lint a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;
bool flagdebug = false;

int main(){
//////////////////////////////////////////////////////
    // flagdebug = true;

    cin >> l >> r >> d;


    cout << (r/d)-((l-1)/d) << endl;

//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll mod=1000000007  ;
ll dp[2010];
ll suu(ll s)
{
      if(s==0)
            return 1;
      if(s<3)
            return 0;
      if(s<6)
            return 1;
      if(dp[s]!=-1)
            return dp[s];
            ll res=0;
      for(ll i=3;i<=s;i++)
      {
          res=(mod+(res+(mod+suu(s-i))%mod))%mod;
      }
      dp[s]=res;
      return  res;

}
int main()
{
    ll a,b,c,d;
    memset(dp,-1,sizeof(dp));
    dp[0]=1;
    cin>>a;

    cout<<(mod+suu(a))%mod<<endl;

    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

int main(){
    ll x,k,d;
    cin >> x >> k >> d;
    ll cnt;
    cnt = abs(x)/d;//0付近に移動するのにかかる回数(同じ符号で)
    //cnt2 = cnt+1;//0をまたぐ場合の回数
    ll cnt3;

    //符号を考慮しないといけない
    if(x > 0){
        if(abs(x-cnt*d) > abs(x-(cnt+1)*d)){
            cnt3 = cnt+1;//trueの場合:0をまたいだ方がいい
        }else{
            cnt3 = cnt;//0をまたがない方がよい
        }

        //最小のところまでに行けるか？
        if(cnt3 > k){
            cout << abs(x-k*d) << endl;
        }else{
            //反復する
            if(( (cnt3-k) % 2) == 0){
                cout << abs(x-cnt3*d) << endl;
            }else{
                cout << min(abs(abs(x-cnt3*d)-d),abs(abs(x-cnt3*d)+d) ) << endl;
            }
        }
    }else{
        if(abs(x+cnt*d) > abs(x+(cnt+1)*d)){
            cnt3 = cnt+1;//trueの場合:0をまたいだ方がいい
        }else{
            cnt3 = cnt;//0をまたがない方がよい
        }

        //最小のところまでに行けるか？
        if(cnt3 > k){
            cout << abs(x+k*d) << endl;
        }else{
            //反復する
            if(( (cnt3-k) % 2) == 0){
                cout << abs(x+cnt3*d) << endl;
            }else{
                cout << min(abs(abs(x+cnt3*d)-d),abs(abs(x+cnt3*d)+d) ) << endl;
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 3632
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);const tn=():number=>{const a=input[0];input.shift();return Number(a)};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{const a=input[0];input.shift();return String(a)};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const tc=():string=>{let a=input[0].split('');const b=a[0];a.shift();if(a.length>0){input[0]=a.join('')}else{input.shift()}return String(b)};const tcc=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(tc())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};
const main=()=>{
  let s=ts()
  let a=Number(s[0])
  if(s[0]==s[1]&&s[1]==s[2])to(s)
  else{
    if(''+a+a+a<s){
      a++
      to(''+a+a+a)
    }
    else to(''+a+a+a)
  }
}
main()


Measured memory_bytes: 7372
#include<stdio.h>
#define N 101
#define INF 100000000

int n;
int G[N][N];
int A[N];
int flag[N];



void M(int s){
  int i;
  int x=-1,c=INF;
  int a = 0;
  for(i=0;i<n;i++){
    if(G[s][i]==-1) continue;
    else if(G[s][i] < A[i] && flag[i]==0)
      A[i] = G[s][i];
  }
  
  for(i=1;i<n;i++){
    if(flag[i]==1) continue;
    else{
      if(c > A[i]){
	a = 1;
	c = A[i];
	x = i;
      }
    }
  }
  
  if(a){
    flag[x] = 1;
    M(x);
  }
  
}
int main(){
  int i,j,a;
  scanf("%d",&n);
  for(i=1;i<n;i++)
    A[i] = INF;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&G[i][j]);
    }
  }
  flag[0]=1;
  M(0);
  a=0;
  for(i=0;i<n;i++){
    a+=A[i];
  }
  printf("%d\n",a);
  
  return 0;
}


  



Measured memory_bytes: 2052
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String[] arr = new String[]{"pon","pon","hon","bon","hon","hon","pon","hon","pon","hon"};
    System.out.println(arr[sc.nextInt()%10]);
  }
}

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

int main() {
  int N;
  cin>> N;
  vector<int> vec(N);
  for(int i = 0;i < N;i++) {
    cin >> vec.at(i);
  }
  int count = 0;
  for(int j = 0;j < N;j++) {
    count = count + vec.at(j);
  }
  int countb = 0;
  int answer = 10000000;
  for(int i = 0;i < N;i++) {
    count = count - vec.at(i);
    countb = countb + vec.at(i);
    if(count > countb) {
      answer = min(answer,count - countb);
    }
    else {
      answer = min(answer,countb - count);
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;

class Segment_Tree {
	vector<long long int>v;
	vector<int>l;
	vector<int>r;
	int num;
	long long int ret;
	bool is_min;
	long long int Update(int place) {
		if (place >= (int)v.size() / 2) {
			return v[place];
		}
		if (is_min) {
			v[place] = min(Update(place * 2), Update(place * 2 + 1));
			return v[place];
		}
		v[place] = max(Update(place * 2), Update(place * 2 + 1));
		return v[place];
	}
	void RMQ(int a, int b, int place) {
		if (l[place] >= a&&r[place] <= b) {
			if (is_min)ret = min(ret, v[place]);
			else ret = max(ret, v[place]);
			return;
		}
		if (l[place]>b || r[place]<a) return;
		RMQ(a, b, place * 2);
		RMQ(a, b, place * 2 + 1);
		return;
	}
public:
	void Left(int place) {
		if (place >= (int)v.size() / 2) {
			l[place] = place - v.size() / 2;
			return;
		}
		Left(place * 2);
		Left(place * 2 + 1);
		l[place] = l[place * 2];
		return;
	}
	void Right(int place) {
		if (place >= (int)v.size() / 2) {
			r[place] = place - v.size() / 2;
			return;
		}
		Right(place * 2);
		Right(place * 2 + 1);
		r[place] = r[place * 2 + 1];
		return;
	}
	Segment_Tree(int n, bool min) {
		num = 1;
		while (num < n * 2) {
			num *= 2;
		}
		l.resize(num);
		r.resize(num);
		if (min) {
			v.resize(num, LLONG_MAX);
			is_min = true;
		}
		else v.resize(num, LLONG_MIN);
		Left(1);
		Right(1);
	}
	void Insert(int place, long long int num, bool update) {
		place += v.size() / 2;
		v[place] = num;
		if (!update)return;
		place /= 2;
		while (place) {
			if (is_min)v[place] = min(v[place * 2], v[place * 2 + 1]);
			else v[place] = max(v[place * 2], v[place * 2 + 1]);
			place /= 2;
		}
	}
	void TopDown() {
		Update(1);
	}
	long long int RMQ(int a, int b) {
		if (is_min)ret = LLONG_MAX;
		else ret = LLONG_MIN;
		RMQ(a, b, 1);
		return ret;
	}
};


int main() {
	ios::sync_with_stdio(false);
	cin >> N >> M;
	cout << (N - 1)*(M - 1) << endl;
	return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
D, X = map(int, input().split())
ans = X
for n in range(N):
    a = int(input())
    ans += 1 + (D - 1) // a
print(ans)



Measured memory_bytes: 5828
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
//V,P(大文字)使用不可
//乗算の際にオーバーフローに注意せよ！！（適切にmodをとれ）
//制約をよく読め！

const ll INF=1e18;

ll f(ll n){
    ll m=1;
    rep(i,n) m*=2;
    return m;
}

ll g(ll n){
    ll m=1;
    rep(i,n) m*=-2;
    return m;
}

signed main(){
    ll n,u;
    cin>>n;
    u=n;
    string s;
    if(n==0) s="0";
    else{
        ll sum=0;
        for(int i=0;i<=40;i++){
            ll m=f(i+1);
            if(u%m==0){
                s+='0';
            }else{
                s+='1';
                ll t=g(i);
                sum+=t;
                u-=t;
            }
            if(sum==n) break;
        }
    }
    reverse(all(s));
    cout<<s<<endl;
}

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

using namespace std;

#define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-8;
const double pi=acos(-1.0);
const int K=1e6+7;
const int mod=1e9+7;


string ss,ans;
int main(void)
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    for(int i=1;i<=3;i++)
        cin>>ss,ans+=ss[0]-'a'+'A';
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

S = input()

m = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']

if S[:2] in m and S[2:] not in m:
    print('MMYY')
elif S[:2] not in m and S[2:] in m:
    print('YYMM')
elif S[:2] in m and S[2:] in m:
    print('AMBIGUOUS')
else:
    print('NA')


Measured memory_bytes: 15160
#include <cstdio>
#include <vector>
using namespace std;

const long long INF=10000000000000000ll;

int main()
{
  int n;
  long long a,b;
  scanf("%d%lld%lld",&n,&a,&b);
  vector<int> p(n+1);
  for(int i=0;i<n;i++){
    scanf("%d",&p[i]);
    p[i]--;
  }
  p[n]=n;
  vector<long long> dp(n+1);
  for(int i=0;i<=n;i++){
    int ca=0,cb=0;
    int k=-1;
    dp[i]=INF;
    for(int j=i-1;j>=0;j--){
      if(p[j]>p[i]){
	ca++;
      }
      else if(k==-1||p[k]<p[j]){
	dp[i]=min(dp[i],dp[j]+ca*a+cb*b);
	cb++;
	k=j;
      }
      else{
	cb++;
      }
    }
    if(k==-1){
      dp[i]=i*a;
    }
  }
  printf("%lld\n",dp[n]);
  return 0;
}


Measured memory_bytes: 256
n, k = map(int,input().split())
S = list(map(int, list(input())))
# 尺取り法.
## 右側の初期化.//これを不規則に動かす.
ridx = 1
## パラメータの初期化.//これでridxを制御する.
### 最初が0だった場合、最初から反転が必要.
cnt = 0 if S[0]==1 else 1
## 答えの初期化.//この最大を探す.
ans = 0
## 左側を0からn-1まで動かしていく.
for lidx in range(n):
    # 現在地が1で一つ前が0だった場合、カウントを減らす.
    if lidx>0 and S[lidx]==1 and S[lidx-1]==0:
        cnt -= 1
    # 右端がn未満なら右に一つずつ動かしていく.
    while ridx < n:
        ## もし現在地が0で、一つ前が1なら
        if S[ridx]==0 and S[ridx-1]==1:
            ### カウントがk未満ならカウントを増やし、そうでないならループを脱する.
            if cnt < k:
                cnt += 1
            else:
                break
        ridx += 1
    ans = max(ans, ridx-lidx)
print(ans)

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

int main(void)
{
	int num, push = 1 , back = 0;
	long long int nums,b[200000];
	scanf("%d", &num);

	for (int i = 0; i < num; i++) {
		scanf("%lld", &nums);
		if (i % 2 == 0) {
			b[num / 2 + back] = nums;
			back++;
		}
		else {
			b[num / 2 - push] = nums;
			push++;
		}
	}

	for (int i = 0; i < num; i++) {
		if (num % 2 == 0) {
			printf("%lld", b[i]);
		}
		else {
			printf("%lld", b[num - 1 - i]);
		}
		if (i != num - 1) {
			printf(" ");
		}
	}
	printf("\n");

	return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a, b)*b; } //最小公倍数

ll input(){
  ll a;
  cin >> a;
  return a;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a;
    string s;
    cin >> a >> s;
    cout << (a>=3200?s:"red") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
int x[20];
int r;
int D;

int main(){
	cin >> r >> D >> x[0];
	for(int i=0; i<10; i++){
		x[i+1] = r * x[i] - D;
		cout << x[i+1] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
X = sorted(list(map(int,input().split())))
 
interval = []
 
 
 
for i in range(1,M):
	interval.append(X[i] - X[i - 1])
 
interval.sort()
 
if M - N < 0:
	print(0)
else:print(sum(interval[:M - N]))

Measured memory_bytes: 13968
#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int lli;
vector <lli> cum;
vector <lli> V;
vector <lli> X;
lli C, N;
lli solveA() {
	cum[0] = 0;
	for(int i = 0; i < N; i++) {
		cum[i + 1] = cum[i] + V[i];
	}
	lli ans = 0;
	vector <lli> best(N, -1), get(N, -1e14);
	for(int i = N - 1; i >= 0; i--) {
		lli dis = C - X[i];
		lli val = cum[N] - cum[i];
		if(dis < val && val - dis > ans) {
			best[i] = i;
			get[i] = val - dis;
		} else if(i < N - 1) {
			best[i] = best[i + 1];
			get[i] = get[i + 1];
		}
		ans = max(ans, val - dis);
	}
	for(int i = 0; i < N - 1; i++) {
		lli dis = X[i];
		lli val = cum[i + 1];
		ans = max(ans, val - 2 * dis + get[i + 1]);
	}
	return ans;
}
int main() {fio; // remove during scanf
	cin >> N >> C;
	X.resize(N, 0);
	V.resize(N, 0);
	for(int i = 0; i < N; i++) {
		cin >> X[i] >> V[i];
	}
	cum.resize(N + 1, 0);
	lli F = solveA();
	for(int i = 0; i < N; i++) {
		X[i] = C - X[i];
	}
	sort(X.begin(), X.end());
	reverse(V.begin(), V.end());
	lli G = solveA();
	cout << max(F, G);
    return 0;
}

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

int main(){
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	for (int i=0; i<h; i++){
		for (int j=0; j<w; j++){
			if ((i<b && j<a) || (i>=b && j>=a)) cout << "1";
			else cout << "0";
		}
		cout << "\n";
	}
}

Measured memory_bytes: 3616
from decimal import*
from fractions import*
import math
import functools


import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
input = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines 

def cmp(a,b):
    if(a<b):
        return 1
    elif(a==b):
        return 0
    else:
        return -1 

n,k=map(int,input().split())
p=list(map(int,input().split()))

lit=[]
for num in p:
    Sum=num*(num+1)/2
    lit.append(Sum/num)
Sum=0
ans=0
for i in range(k):
    Sum+=lit[i]
ans=Sum
for i in range(k,n):
    Sum-=lit[i-k]
    Sum+=lit[i]
    ans=max(ans,Sum)
print(ans)

Measured memory_bytes: 23732
#include<iostream>
#include<queue>
#include<vector>
#include<map>
using namespace std;

#define M 30
#define INF 10000000

#define min(a,b) ((a)>(b)?(b):(a))

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

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

bool inRange(int x, int y, int w, int h) {
	return (0<=x && x<w && 0<=y && y<h);
}

int main() {
	priority_queue<PP, vector<PP>, greater<PP> > q;
	int w, h, map[M][M], c[4], cost[M][M][4];
	while(1) {
		cin >> w >> h;
		if(!w&&!h) break;
		for(int i=0; i<h; ++i) {
			for(int j=0; j<w; ++j) {
				cin >> map[i][j];
				for(int k=0; k<4; ++k) cost[i][j][k] = INF;
			}
		}
		for(int i=0; i<4; ++i) cin >> c[i];
		
		// dijkstra
		q.push(PP(P(0,0),P(0,0))); cost[0][0][0] = 0;
		while(!q.empty()) {
			int co = q.top().first.first, dir = q.top().first.second;
			int x = q.top().second.first, y = q.top().second.second;
			q.pop();
			if(co>cost[y][x][dir]) continue;
			for(int k=0; k<4; ++k) {
				int d = (dir+k)%4;
				if(!inRange(x+dx[d], y+dy[d], w, h)) continue;
				if(map[y][x]==k) {
					if(cost[y][x][dir]<cost[y+dy[d]][x+dx[d]][d]) {
						cost[y+dy[d]][x+dx[d]][d] = cost[y][x][dir];
						q.push(PP(P(cost[y+dy[d]][x+dx[d]][d],d),P(x+dx[d],y+dy[d])));
					}
				}else {
					if(cost[y][x][dir]+c[k]<cost[y+dy[d]][x+dx[d]][d]) {
						cost[y+dy[d]][x+dx[d]][d] = cost[y][x][dir] + c[k];
						q.push(PP(P(cost[y+dy[d]][x+dx[d]][d],d),P(x+dx[d],y+dy[d])));
					}
				}
			}
		}
		cout << min(cost[h-1][w-1][0], cost[h-1][w-1][1]) << endl;
	}
	return 0;
}

Measured memory_bytes: 1328
#include "bits/stdc++.h"
using namespace std;

//wierd debugging stuff
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << "\n" ; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
//end of weird debugging stuff
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
 
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define fo(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define foe(i,x) for(auto& i: x)
#define ar array
#define pb push_back
#define vt vector
#define F first
#define S second

template<class T> bool umin(T& a,const T& b){return b<a?a=b,1:0;}
template<class T> bool umax(T& a,const T& b){return b>a?a=b,1:0;}

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {cin>>x;}
void read(double& d) {string t;read(t);	d=stod(t);}
void read(long double& d) {	string t;read(t);d=stold(t);}
template<class H, class... T> void read(H& h, T&... t) {read(h);read(t...);}
template<class A> void read(vt<A>& x) {	foe(a, x)read(a);}
int nxt(){int a;cin>>a;return a;}

// no change 
const ll MOD = 1e9+7;  
void Titan(){
	int n;
	read(n);
	vi v(n);
	read(v);
	int now = v[0];
	ll ans = 0;
	fo(i,1,n){
		if(v[i] <= now){
			ans+= now - v[i];
		}else now = v[i];
	}

	cout << ans ;

	
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int T = 1;
	//cin >> T;		//cmt if one test case
    fo(T){
		//cout << "Case #" << i+1 << ": " ;
		Titan();
	}
}
/*///////////////////////////////////////////////////////////
Important Notes : 
* check long long 
* check base cases
* do not loose Hope
* if case fails on 2nd test case maybe some cases are missing check them
* do not sit idle
* try to do it using pen/paper.
*/


Measured memory_bytes: 3988
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll ketawa(ll n) {   // nの各桁の数の和
    ll res = 0;    
    while(n != 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}
 
int main() {
    ll n;
    cin >> n;

    if(n%ketawa(n) == 0) {
        out("Yes");
    } 
    else {
        out("No");
    }
    
    re0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
int main(){
    long long ans;
    int n,x;
    int A[11][11];

    cin>>n;
    for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
            A[i][j]=0;
            if(i==j&&j<=n)A[i][j]++;
            x=10;
            while(i*x+j<=n) x*=10;
            x/=10;
            if(x>=10){
                if(x>=100){
                if(n>=(i*x+j)+((x-1)/10)*10) A[i][j]+=x/10;
                else A[i][j]+=((n-(i*x+j))%x)/10+1;
                x/=10;
                }
            while(x>=10){
                A[i][j]+=x/10;
                x/=10;
            }
            }
        }
    }
    
    

    for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
            ans+=A[i][j]*A[j][i];
        }
    }
    cout<<ans<<endl;
}

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

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

    int n;
    cin >> n;
    vector<vector<int>> graph(n, vector<int>(n, 0));
    rep(i, n) {
        int vertex, num;
        cin >> vertex >> num;
        rep(j, num) {
            int adjcent;
            cin >> adjcent;
            graph[vertex - 1][adjcent - 1] = 1;
        }
    }

    for (auto row : graph) {
        for (size_t i = 0; i < row.size(); i++) {
            cout << row[i];
            if (i != row.size() - 1) {
                cout << " ";
            } else {
                cout << endl;
            }
        }
    }
}


Measured memory_bytes: 3184
#include<iostream>
#include<cmath>
#include<iomanip>
#define e endl
using namespace std;

int main()
{
  int n,i;cin>>n;
  static double x[100],a,y,p,q,r,s;

  for(i=0;i<n;i++)cin>>x[i];
  for(i=0;i<n;i++)cin>>y,p+=a=abs(x[i]-y),q+=a*a,r+=a*a*a,s=s<a?a:s;
  cout<<fixed<<p<<e<<sqrt(q)<<e<<cbrt(r)<<e<<s<<e;
  return 0;
}

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

int waru(int S,int a[],int x,int n){

  if(x<n){
    if(S%10!=0)
      return S;
    else if((S-a[x])%10!=0)
      return (S-a[x]);
    else if((S-a[x])!=0)
      return waru(S,a,x+1,n);
    else
      return 0;
  }
  else
    return 0;
}


void so(int a[],int n){

  bool flag=false;

  do{
    flag=false;
    for(int i=0;i<n-1;i++){
      if(a[i]>a[i+1]){
	swap(a[i],a[i+1]);
	flag=true;
      }
    }
  }while(flag);

}

int main(){

  int N;
  int sum=0;
  // bool flag;
  
  cin>>N;

  int s[N];
  int sorting[N];

  for(int i=0;i<N;i++){
    cin>>s[i];
    sorting[i]=s[i];
    sum+=s[i];
  }

  so(sorting,N);
 
  cout<<waru(sum,sorting,0,N)<<endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if (c % (calcGcd(a, b)) == 0) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

	private static int calcGcd(int a, int b) {

		return (b == 0) ? a : calcGcd(b, a % b);

	}

}


Measured memory_bytes: 21844
#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 ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
int main() {
    vector<bool>ans(2002000,true);
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i, 0, n)cin >> a[i];
    sort(a.begin(),a.end(),greater<int>());
    rep(i, 0, n){
        int p = a[i];
        if(i==0)for(int j=2*p; j<=a[0]; j +=p)ans[j]=false;
        else {
            if(a[i]==a[i-1])for(int j=p; j<=a[0]; j +=p)ans[j]=false;
            else for(int j=2*p; j<=a[0]; j +=p)ans[j]=false;
        }
    }
    int cnt=0;
    rep(i, 0, n){
        if(ans[a[i]])cnt++;
    }
    cout << cnt << endl;
}

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

template<typename T>
struct E{
  int to;
  T cost;
};

template<typename T>
vector<T>dijkstra(vector<vector<E<T>>>g,int s){
  T inf=numeric_limits<T>::max();
  vector<T>d(g.size(),inf);
  using Type=pair<T,int>;
  using Container=vector<Type>;
  using Cmp=greater<Type>;
  priority_queue<Type,Container,Cmp>q; 
  d[s]=0;
  q.push({d[s],s});
  while(!q.empty()){
    T cost=q.top().first;
    int from=q.top().second;
    q.pop();
    if(d[from]!=cost)continue;
    for(auto e:g[from]){
      T next_cost=e.cost+cost;
      if(d[e.to]>next_cost){
        d[e.to]=next_cost;
        q.push({d[e.to],e.to});
      }
    }
  }
  return d;
}

int main(){
  int N,M,S;
  cin>>N>>M>>S;
  vector<vector<E<int>>>G(N);
  for(int i=0;i<M;i++){
    int a,b,c;
    cin>>a>>b>>c;
    G[a].push_back({b,c});
  }
  auto ans=dijkstra<int>(G,S);
  for(auto it:ans){
    if(it==INT_MAX)cout<<"INF"<<endl;
    else cout<<it<<endl;
  }
  return 0;
}



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

int n;
long long a[50];

int main() {
	ios_base::sync_with_stdio(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	
	long long ans = 0;
	
	for (int it = 0; it <= 2000; it++)
	for (int i = 0; i < n; i++) {
		long long cnt = a[i] / n;
		if (cnt != 0) {
			ans += cnt;
			a[i] %= n;
			for (int j = 0; j < n; j++) {
				if (j == i) continue;
				a[j] += cnt;
			}
		}
	}
	cout << ans;
	
    return 0;
}


Measured memory_bytes: 256
n,k=map(int,(input().split()))
ans=0
max=sum(range(n-k+1,n+1))*(n-k+2)
min=sum(range(k))*(n-k+2)
for i in range(1,n-k+2):
    min+=(k-1+i)*(n-k+2-i)
for i in range(1,n-k+2):
    max+=(n-k+1-i)*(n-k+2-i)
ans=(max-min+n-k+2)%(10**9+7)
print(ans)

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

int lcm(int a,int b){
    if(b==0){
        return a;
    }
    else{
        return lcm(b,a%b);
    }
}

int gcm(int a,int b){
    return a/lcm(a,b)*b;
}
int main(){
    int a,b;
    cin>>a>>b;
    cout<<lcm(a,b)<<endl;
}


Measured memory_bytes: 3112
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;



int main() {
	ios::sync_with_stdio(false);
	cin >> N;
	long long int num[100001] = {};
	for (int i = 1; i <= N; i++) {
		cin >> num[i];
	}
	for (int i = 1; i < N; i++) {
		if (num[i]%2 && num[i + 1]) {
			num[i]--;
			num[i + 1]--;
			ans++;
		}
		ans += num[i] / 2;
	}
	ans += num[N] / 2;
	cout << ans << endl;
	return 0;
}

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

int main()
{
    std::vector<int> Numbers;
    for(std::size_t i = 0; i < 5; ++i){
        int n;
        std::cin >> n;
        Numbers.push_back(n);
    }
    std::sort(Numbers.begin(), Numbers.end(), std::greater<int>());
    for(std::size_t i = 0; i < Numbers.size(); ++i){
        if(i) std::cout << " ";
        std::cout << Numbers[i];
    }
    std::cout << std::endl;
    return 0;
}

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

public class Main {
	  
	public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
		    
		    int N = scanner.nextInt();
		    int[] hoge = new int[2 * N];
		    int count = 0;
		    
		    for( int i = 0; i < 2*N; i++) 
		    {
		    	hoge[i] = scanner.nextInt();
		    }
		    
		    Arrays.sort(hoge);
		    
		    for( int i = 0; i < N; i++) 
		    {
		    	count = count + hoge[2*i];
		    }
		    
		    System.out.println(count);
		    
		    scanner.close(); }
		  }

Measured memory_bytes: 23764
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from itertools import *
from copy import *

N, W = map(int, input().split())
MV = N * 10**3 + 1
INF = float('inf')
dp = [[INF] * MV for i in range(N+1)]
dp[0][0] = 0
for i in range(N):
    w, v = map(int, input().split())
    for j in range(MV):
        if v <= j:
            dp[i+1][j] = min(dp[i][j], dp[i][j-v]+w)
        else:
            dp[i+1][j] = dp[i][j]
dp = dp[N]
for i in range(0, MV)[::-1]:
    if dp[i] <= W:
        print(i)
        break


Measured memory_bytes: 310808
N, A, B, C = map(int, input().split())
length_array = [int(input()) for i in range(N)]
# print(length_array)

ans = 100000

for i in range(4**N):
    use_array = [[], [], []]
    for j in range(N):
        digit_j = (i & (3 << (j * 2))) >> (j * 2)
        if digit_j == 0:
            continue
        use_array[digit_j - 1].append(length_array[j])
    if len(use_array[0]) == 0 or len(use_array[1]) == 0 or len(
            use_array[2]) == 0:
        continue
    ans = min(ans,
              abs(sum(use_array[0]) - A) +
              (len(use_array[0]) - 1) * 10 + abs(sum(use_array[1]) - B) +
              (len(use_array[1]) - 1) * 10 + abs(sum(use_array[2]) - C) +
              (len(use_array[2]) - 1) * 10)
print(ans)

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (c - (a - b) > 0) {
		cout << c - (a - b) << endl;
	}
	else {
		cout << 0 << endl;
	}
}


Measured memory_bytes: 256
# bin/env/pypy3
import sys
import collections
import heapq
import math
s = sys.stdin.readline().split()[0]
n = len(s)

def isP(s1):
    # for i in range(len(s)//2):
    #print(s1)
    n1 = len(s1)
    #print(s1[::-1],s1,str(reversed(s1))==s1)
    #print(s1 == s1[::-1])
    return s1==s1[::-1]
    #print(s1)
    #print(i,n-2-i,s[i],s[n-2-i])
    #for i in range(n1//2):
        #print(s1[i],i,s1[n1-1-i],n1-1-i)
    #    if not (s1[i] != s1[n1-1-i]):
    #        return False
    #return True
#print(isP(s),isP(s[:(n-1)//2]),isP(s[((n+3)//2)-1:]))
if isP(s) and isP(s[:(n-1)//2]) and isP(s[(n+3)-1//2:]):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38384