akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;

int coin[6]={500,100,50,10,5,1};
int main(){
  while (1) {
    int n;
    cin>>n;
    if(n==0) break;
    int cost=1000-n;
    int ans=0;
    for(int i=0; i<6; i++){
      int a=cost/coin[i];
      ans+=a;
      cost-=coin[i]*a;
    }
    
    cout<<ans<<en
  }
}


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

int main(int argc, char const *argv[])
{
    int seconds;
    cin >> seconds;

    int hours = seconds / 3600;
    seconds %= 3600;
    int minutes = seconds / 60;
    seconds %= 60;

    cout << hours << ':' << minutes << ':' << seconds << endl;

    return 0;
}



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

int main(){
int x,y;

for( int i = 0; ; i++ ){
  
 cin >> x >> y;

  if( x == 0 && y ==0 ) break;
  else if ( x >= y ) cout << y << " " << x << endl;
  else cout << x << " " << y << endl;
} 

}

Measured memory_bytes: 1160
def solve(s):
    if s[0]!='A':
        return 'WA'
    if s[2:len(s)-1].count('C')!=1:
        return 'WA'
    s=str(s.split('A'))
    s=str(s.split('C'))
    if not s.islower():
        return 'WA'
    return 'AC'

s=input()
print(solve(s))

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
using namespace std;

typedef long long int ll;
typedef pair<int,int> p;
#define MAX 100001

struct CompareGreater {
    bool operator() (p &a,p &b) {
        return a.second < b.second;
    }
};

struct CompareSmaller {
    bool operator() (p &a,p &b) {
        return a.first > b.first;
    }
};

int main(void){
  int N,M;
  cin >> N >> M;
  priority_queue<p,vector<p>,CompareSmaller> items;
  priority_queue<p,vector<p>,CompareGreater> q;
  ll sum = 0;
  for(int i=0;i<N;i++){
    int A,B;
    cin >> A >> B;
    items.push(make_pair(A,B));
  }
  
  for(int t=1;t<=M;t++){
    //cout << "t:" << items.top().first << endl;
    while(true){
      if(items.size() <= 0 || items.top().first > t)
	break;
      //そうでなかったら追加
      q.push(items.top());
      items.pop();
    }
    // 最大値をとる
    if(q.size() > 0){
      sum = sum + q.top().second;
      //cout << q.top().second << endl;
      q.pop();
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(v) (v).begin(), (v).end()

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

  double concentration = 0;
  int ans_w = 0, ans_s = 0;
  for (int a_i = 0; a_i*100*A <= F; ++a_i) {
    for (int b_i = 0; b_i*100*B <= F; ++b_i) {
      for (int c_i = 0; c_i*C <= F; ++c_i) {
        for (int d_i = 0; d_i*D <= F; ++d_i) {
          int water = a_i*A*100+b_i*B*100;
          int sugar = c_i*C+d_i*D;

          if (water+sugar == 0 or
              sugar > water*E/100.0 or
              water+sugar > F) continue;

          double tmpconc = 100.0*sugar/(water+sugar);

          if (concentration < tmpconc) {
            concentration = tmpconc;
            ans_w = water;
            ans_s = sugar;
          };
        }
      }
    }
  }

  if (ans_w == 0) ans_w = 100*A;

  cout << ans_w+ans_s << " " << ans_s << endl;
}

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

#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m);i>=(int)(n);--i)
#define debug(x) cout << #x << "=" << (x) << endl;

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;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end

void solve(){
  vector<char> c(52);
  c[0]='a';
  for(int i=1;i<26;i++)
    c[i]=((char)(c[i-1]+1));
  c[26]='A';
  for(int i=27;i<52;i++)
    c[i]=((char)(c[i-1]+1));
  while(1){
    int n;
    cin>>n;
    if(!n)return;
    vector<int> ar(n);
    rep(i,n)
      cin>>ar[i];
    string s;
    cin>>s;
    rep(i,s.size()){
      int j=0;
      while(s[i]!=c[j])j++;
      j-=ar[i%n];
      if(j<0)j+=52;
      s[i]=c[j];
    }
    cout<<s<<endl;
  }
}

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



Measured memory_bytes: 3220
import bisect,sys
import math
from collections import deque

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac =fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV
        
    return CONV()



sys.setrecursionlimit(200005)


def main():
    N,K= isRaw()
    first = pow(10, 100, DIV)
    ans = 1
    dadd = 1
    for n in range(N+1-K):
        dadd+=N-2*n
        ans+=dadd
        ans=ans%DIV
    return ans%DIV

if __name__ == "__main__":
    print(main())


Measured memory_bytes: 67928
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 2019
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
    int L,R; cin >> L >> R;
    int ans = INF;
    if(R - L > 2019) ans = 0;
    else{
        repr(i,L,R){
            repr(j,i+1,R+1){
                int now = ((i % MOD) * (j % MOD)) % MOD;
                ans = min(ans,now);
            }
        }
    }
    cout << ans << endl;
    

}


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

int main() {
  int A, B, sum;
  cin >> A >> B;
  sum = 0;
  
  for (int i = A; i < B+1; i++){
    if (i/10000 == i%10 && (i-i/10000*10000)/1000 == (i%100-i%10)/10)
      sum++;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long int ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PLL, PLL> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const int mod = 1000000;
const int inf = 1e9+9;
const ll MOD = 1e9+696969;
const long long INF = 1e18+3;
const int maxn = 200100;
int tab[maxn], bin[maxn], help[4];int n;
inline bool check(int k)
{
	FOR(i, 1, 2*n-1)
		if (tab[i] >= k) bin[i] = 1;
		else bin[i] = 0;
	
	if (bin[n] == bin[n+1] || bin[n] == bin[n-1]) return bin[n];
	for (int i=1; i<=n-2; ++i) {
		if (bin[n - i] == bin[n - i + 1]) return bin[n - i];
		if (bin[n + i] == bin[n + i + 1]) return bin[n + i];
	}
	return bin[1];
}

int main()
{
	cin >> n;
	FOR(i, 1, 2*n-1) cin >> tab[i];
	int x = 1, y = 2 * n + 1;
	while (x < y) {
		int sr = (x + y)/2 + 1;
		if (!check(sr)) y = --sr;
		else x = sr;
	}
	cout << x;
	
}


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

int main() {

  const int M = 224; // コレがミソ

  vector <int> mod(M);
  for(int i=0; i<M; i++ ){
    if(i ==0){
      mod.at(i)=1;
    }
    else{
      mod.at(i)=10*mod.at(i-1)%2019;
    }
  }

  //sort(mod.begin(),mod.end());
  /*for(int i=0; i<224; i++){
    cout << "i" << i << ":" << mod.at(i) <<endl;
  }*/



  string S;
  cin >> S;

  long long int N = (long int)(S.length()); //Nketa
  //cout << len << endl;

  vector <long int> s(N);
  //cout << (s.size()) << endl;

  for(long long int i=0; i<N; i++){
    long int tmp = S.at(i)-'0';
    s.at(i) = tmp;
    //cout << s.at(i) ;
  }


  vector <int> t(N+1);
  for(long long int i=0; i<N+1; i++){
    if(i==0){
      t.at(i)=0;
    }
    else if(i==1){
      t.at(i)=s.at(N-i);
    }
    else{
      long int tmp;
      //tmp = i-1;
      tmp = (i-1)%M;
      t.at(i) = (t.at(i-1) + s.at(N-i)*mod.at(tmp)) % 2019;
    }
  }

  long long int count=0;
  long long int sum = 1;

  sort(t.begin(),t.end());
  for(long long int i=0; i<N; i++){
    if(t.at(i)==t.at(i+1)){
      sum++;
      if(i==N-1){
        count+=sum*(sum-1)/2;
      }
    }
    else{
      count+=sum*(sum-1)/2;
      sum = 1;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 6040
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main(void){
	vector<int> height ;
	string s ;
	while(cin >> s){
		height.push_back(atoi(s.c_str()));
		
	}
	sort(height.begin(),height.end(),greater<int>());
	
	for(int i=0;i<3;i++){
		cout <<height[i]<<endl ;
	}
	
	return 0 ;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
vector<vector<bool>> G(8,vector<bool>(8));
vector<bool> seen;

int dfs(int v,int n, vector<bool> seen){
  bool all_seen = true;
  for(int i = 0; i < n; i++){
    if(seen.at(i)==false) all_seen = false;
  }
  if(all_seen) return 1;
  
  int ans = 0;
  for(int i = 0; i < n; i++){
    if(G[v][i] == false) continue;
    if(seen[i]) continue;
   // printf("next_v:%d\n",next_v);
    seen[i] = true;
    ans +=dfs(i,n,seen);
    seen[i] = false;
  }
  return ans;  
}
int main(){
  int n,m; cin >> n >> m;
  for(int i = 0; i < m; i++){
    int a,b; cin >> a >> b;
    a--;b--;
    G[a][b] = true;
    G[b][a] = true;
  }

  seen.assign(n,false);
  seen.at(0) = true;
  cout << dfs(0,n,seen) << endl;
}
  
  

Measured memory_bytes: 3520
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
S1 = 0
S2 = 0

R = [0] * (N + 1)
for i in A:
    R[i] = 1

for i in range(0,X + 1):
    S1 += R[i]

for i in range(X + 1,N + 1):
    S2 += R[i]

print(min(S1,S2))

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
struct ${$(){ios_base::sync_with_stdio(0);cin.tie(0);}}$;

const int N = 200005;

int sod(int x) {
   int ret = 0;
   while(x) {
      ret += x % 10;
      x /= 10;
   }
   return ret;
}
int main() {
   int n, a, b;
   cin >> n >>  a >>b;
   int ans = 0;
   for(int i = 1; i <= n; i++) {
      if(sod(i) >= a && sod(i) <= b)
         ans += i;
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn._

object Main extends App {
  val Array(a, b, x) = readLine.split(" ").map(_.toDouble)
  val area = x / a
  println(Math.toDegrees(Math.atan(
    if (a * b > area * 2) b * b / area / 2  // area = 1 / tan * b * b / 2
    else (a * b - area) * 2 / a / a // area = a * b - a * a * tan / 2
  )))
}

Measured memory_bytes: 27304
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 105
#define LL long long
char s[MAXN],t[MAXN];
int main()
{
    int len,pos,ans=0;
    scanf("%d\n",&len);
    scanf("%s %s",s,t);
    for(int i=0;i<len;i++)
    {
        if(s[i]==t[0])
        {
            pos=i+1;
            int cnt=1;
            while(pos<=len-1&&s[pos]==t[cnt])
            {
                pos++;
                cnt++;
            }
            if(pos==len)
            {
                ans=pos-i;
                break;
            }
            //else i=pos;
        }
    }
    printf("%d\n",len+len-ans);
}


Measured memory_bytes: 128
#!/usr/bin/env python3

def main():
    n = int(input())
    li = [1] * (n + 1)
    for i in range(2, n + 1):
        j = 1
        while i * j <= n:
            li[i * j] += 1
            j += 1

    print(sum(li[1:n]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 24432
x = int(input())
ans = []
for b in range(2,40):
    for p in range(2, 11):
        v = pow(b, p)
        if v <= x:
            ans.append(v)
        else:
            break
if len(ans) > 0:
    print(max(ans))
else:
    print(1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
const int MAX_N = int(1e6) + 10;

int n, ans, sum[MAX_N], suf[MAX_N], b[MAX_N];
char s[MAX_N];

void solve(int low) {
	for (int i = 0; i <= n; ++i) b[i] = sum[i];
	int del = 0;
	for (int i = 1; i <= n; ++i) {
		if (s[i] == '?' && suf[i] - del - 2 >= low) del += 2;
		b[i] -= del;
	}
	int m = 0;
	for (int i = 1; i <= n; ++i) m = std::max(m, b[i]);
	ans = std::min(ans, m - low);
}

int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	for (int i = 1; i <= n; ++i)
		sum[i] = sum[i - 1] + (s[i] == '0' ? -1 : 1);
	suf[n + 1] = ans = n + 1;
	for (int i = n; i >= 0; --i)
		suf[i] = std::min(suf[i + 1], sum[i]);
	solve(suf[0]);
	solve(suf[0] - 1);
	printf("%d\n", ans);
}

Measured memory_bytes: 16520
import java.util.*;
public class Main {
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int a = Integer.parseInt(scan.next());
		int b = Integer.parseInt(scan.next());
		int c = Integer.parseInt(scan.next());
		int k = Integer.parseInt(scan.next());

		int ans = 0;
		for (int i = 0;i < k; ++i){
			if (a > 0){
				ans+=1;
				a--;
			}else if (b > 0){
				b--;
			}else{
				ans-=1;
				c--;
			}
		}
		System.out.print(ans);

	}

}


//end

Measured memory_bytes: 35624
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mes(a,b) memset(a,b,sizeof(a))
#define sbs(i,j) substr(i,j)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6+10;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);


int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    ll res=1;
    rep(i,1,n)
        res=((res%mod)*(i%mod))%mod;
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main (void)
{
  int H,W, i, s;
for(;;)
{
  scanf("%d %d", &H, &W);
  if( H == 0 && W == 0) break;

  for(i = 1; i<= H; i++)
  {
    for(s =1; s<= W; s++)
    {
      if(i %2 != 0){
          if(s % 2 != 0){
            printf("#");
          } else{
            printf(".");
          }
      } else  {
        if(s % 2 != 0){
          printf(".");
        } else{
          printf("#");
        }
      }



    }

      printf("\n");
  }
  printf("\n");
}
  return 0;
}

Measured memory_bytes: 1800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

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

int main() {
    ll x, y;
    cin >> x >> y;
    cout << gcd (x, y) << "\n";
}


Measured memory_bytes: 3096
#include<iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	int a[10005];
	int max = -10000000;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (max < a[i]) {
			max = a[i];
		}
	}
	int sum = 0; 
	for (int j = 0; j < n; j++) {
		sum = sum + a[j];
	}
	cout << sum - max/2 << endl;
	return 0;
	
}

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

int n,m,A,B,p[1010][1010];
char s[5];

void work(int x)
{
	if (x==0)
	{
		if (!A) return;
		for (int j=1; j<m; j++)
			for (int i=1; i<=n; i++) 
				if (p[i][j]==-1&&p[i][j+1]==-1)
				{
					p[i][j]=3,p[i][j+1]=2;
					if (!(--A)) return;
				}
	} else
	{
		if (!B) return;
		for (int i=1; i<n; i++)
			for (int j=1; j<=m; j++)
				if (p[i][j]==-1&&p[i+1][j]==-1)
				{
					p[i][j]=1,p[i+1][j]=0;
					if (!(--B)) return;
				}
	}
}

void solve()
{
	if ((n&1)&&A<=m/2)
	{
		for (int i=1; i<=A; i++) p[n][2*i-1]=3,p[n][2*i]=2;
		A=0,work(1); return;
	}
	if ((m&1)&&B<=n/2)
	{
		for (int i=1; i<=B; i++) p[2*i-1][m]=1,p[2*i][m]=0;
		B=0,work(0); return;
	}
	if ((n&1)&&(m&1))
	{
		if (n<3||m<3) return;
		int AA=A,BB=B;
		for (int i=1; i<n; i+=2) p[i][m]=1,p[i+1][m]=0,B--;
		for (int i=1; i<m-2; i+=2) p[n][i]=3,p[n][i+1]=2,A--;
		p[n][m-1]=p[n-2][m-2]=3,p[n][m]=p[n-2][m-1]=2,A-=2;
		p[n-1][m-2]=1,p[n][m-2]=0,B--;
		work(0),work(1);
		if (!A&&!B) return;
		A=AA,B=BB,memset(p,-1,sizeof(p));
		for (int i=1; i<n; i+=2) p[i][m]=1,p[i+1][m]=0,B--;
		for (int i=1; i<m; i+=2) p[n][i]=3,p[n][i+1]=2,A--;
		work(0),work(1); return;
	}
	if (n&1)
	{
		for (int i=1; i<=m; i+=2) p[n][i]=3,p[n][i+1]=2,A--;
		work(0),work(1); return;
	}
	if (m&1)
	{
		for (int i=1; i<=n; i+=2) p[i][m]=1,p[i+1][m]=0,B--;
		work(0),work(1); return;
	}
	work(0),work(1);
}

int main()
{
	s[0]='v',s[1]='^',s[2]='>',s[3]='<';
	scanf("%d%d%d%d",&n,&m,&A,&B);
	memset(p,-1,sizeof(p)),solve();
	if (A||B) return puts("NO"),0;
	puts("YES");
	for (int i=1; i<=n; i++,puts(""))
		for (int j=1; j<=m; j++) putchar(p[i][j]==-1?'.':s[p[i][j]]);
	return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
#define ull unsigned long long
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
const int ESP = 1e-12;

int main(){
    fast;
    ld a, b, c;
    cin >> a >> b >> c;
    b = ceil(a/b);    
    ll k = b*c;
    cout << k;
    return 0;
}


Measured memory_bytes: 3736
#include <stdio.h>
int main(void){
    int n,x,sum,count,i1,i2,i3,i;
    for(i=1;i<=1000;i++){
        scanf("%d %d",&n,&x);
        if(n==0 && x==0){
            break;
        }
        for(i1=1;i1<=n-2;i1++){
            for(i2=i1+1;i2<=n-1;i2++){
                for(i3=i2+1;i3<=n;i3++){
                    sum=i1+i2+i3;
                    if(sum==x){
                        count=count+1;
                    }
                }
            }
        }
        printf("%d\n",count);
        count=0;
    } 
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  long sum = 0;
  for (int i = 0; i < N; i++)
  {
    cin >> a[i];
    sum += a[i];
  }
  vector<long> S(N);
  S[0] = 0;
  for (int i = 1; i < N; i++)
    S[i] = S[i - 1] + a[i - 1];
  long ans = INT32_MAX;
  for (int i = 1; i < N; i++)
  {
    long tmp = abs(S[i] - (sum - S[i]));
    if (tmp < ans)
      ans = tmp;
  }
  cout << ans << endl;
  return 0;
}

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

#define INF ( 1<<29 )

int N,M;

int dp[1111][211];
int WS[211][211];
int WL[211][211];

void warshall(int (*W)[211]){
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      for(int k=0;k<N;k++)
	W[j][k] = min(W[j][k],W[j][i]+W[i][k]);
}

int main(){
  while(  cin >> N >> M && ( N||M ) ){
    fill(WS[0],WS[N],INF);
    fill(WL[0],WL[N],INF);
    fill(dp[0],dp[1001],INF);
    for(int i=0;i<N;i++) WS[i][i] = WL[i][i] = 0;
    for(int i=0;i<M;i++){
      int x,y,t;
      char s;
      cin >> x >> y >> t >> s;
      --x; --y;
      if( s == 'L' ) WL[x][y] = WL[y][x] = t;
      else WS[x][y] = WS[y][x] = t;
    }
    warshall(WL);
    warshall(WS);
    int R;
    cin >> R;
    int d; cin >> d;
    --d;
    dp[0][d] = 0;
    for(int i=1;i<R;i++){
      int nd; 
      cin >> nd; --nd;
      for(int j=0;j<N;j++){
	if(dp[i-1][j] != INF ) {
	  dp[i][j] = min(dp[i][j],dp[i-1][j] + WL[d][nd]);
	  for(int k=0;k<N;k++){
	    dp[i][k] = min( dp[i][k],
			    dp[i-1][j] + WL[d][j] + WS[j][k] + WL[k][nd] );
	  }
	}
      }
      d = nd;
    }
    int res = INF;
    for(int i=0;i<N;i++) res = min( res, dp[R-1][i] );
    cout << res << endl;
  }
}

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

int main() {
  string s, sb, se, ans;
  int size=0;
  
  cin >> s;
  sb = s.at(0);
  se = s.at(s.size() -1);
  size = s.size() - 2;
  
  cout << sb << size << se << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).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 (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n;
    cin >> n;
    vector<ll> a1(n), a2(n);
    REP(i, n) cin >> a1[i];
    REP(i, n) cin >> a2[i];
    ll interim = accumulate(ALL_OF(a2), 0LL) + a1[0];
    ll ans = interim;
    REP(i, n-1) {
        interim += a1[i+1] - a2[i];
        chmax(ans, interim);
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ans=0;
  string s;
  cin>>n>>s;
  for(int i=0;i<n;i++){
    bool cnt[1000];
    int t=0;
    for(int j=0;j<200;j++){
      cnt[j]=0;
    }
    for(int j=0;j<i;j++){
      cnt[(int)s[j]]=1;
    }
    for(int j=i;j<n;j++){
      if(cnt[(int)s[j]]==1){
        t++;
        cnt[(int)s[j]]=0;
      }
    }
    ans=max(ans,t);
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 256
N=int(input())
S=list(map(int,input().split()))
D=[]
goukei=0

for i in range(N):
    goukei+=S[i]
    D.append(goukei)

T=[]    
for i in range(N-1):
    T.append(abs((goukei-D[i])-D[i]))
    
print(min(T))

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

int main() {
	int N;
	cin >> N;
	string S, T;
	cin >> S >> T;

	string ans = "";
	rep(i, N) {
		ans += S[i];
		ans += T[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
cnt=0
for i in range(N):
  minj = i
  for j in range(i,N):
    if A[j] < A[minj]:
      minj = j
  if i != minj:
    k=A[i]
    A[i]=A[minj]
    A[minj]=k
    cnt+=1
print(*A)
print(cnt)


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

int main(){
  int a,b,c,d;
  string S;
  
  cin>>a>>b>>c>>d ;
  while(a>0&&c>0){
    c-=b;
    if(c<=0)break;
    a-=d;
  }
  if(a>c)cout<<"Yes"<<endl;
  else cout<<"No"<<endl; 
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
const ll MOD = 998244353;
void Main(){
    int n,s;
    cin >> n >> s;
    vector<int> a(n);
    For(i,0,n) cin >> a[i];

    vector<ll> pow(n+1);
    pow[0]=1;
    For(i,1,n+1) pow[i]=pow[i-1]*2%MOD;
    ll inv=MOD - 1 * (MOD / 2) % MOD;

    vector<vector<ll>> dp(n+1,vector<ll> (s+1,0));
    dp[0][0]=pow[n];
    For(i,0,n){
        For(j,0,s+1){
            dp[i+1][j]+=dp[i][j];
            dp[i+1][j]%=MOD;
            if(j+a[i]<=s){
                dp[i+1][j+a[i]]+=dp[i][j]*inv%MOD;
                dp[i+1][j+a[i]]%=MOD;
            }
        }
    }
    cout << dp[n][s]%MOD << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 73592
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input!(n: usize, ab: [(usize, usize); n - 1]);
    if n == 1 {
        println!("Hello World");
    } else {
        println!("{}", ab[0].0 + ab[0].1);
    }
}


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

int main() {
	int N;
	cin>>N;
	vector<int> vec(N,0);
	for(int i=0;i<N; i++){
		int a; cin>>a;
		vec[i]=a;
	}
	for(int i=0;i<N; i++){
		if(vec[i]%2==0){
			if(vec[i]%3==0 || vec[i]%5==0)continue;
			else{
				cout<<"DENIED"<<endl;
				return 0;
			}
		}
	}
	cout<<"APPROVED"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    string S; cin >> S;
    lint ans = 0;
    range(i, 0, S.size() / 2) {
        if (S.at(i) != S.at(S.size() - i - 1)) ans += 1;
    }
    cout << ans << "\n";
}

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

const int MOD = 1e9 + 7;
const int N = 5050;

int dp[N][N];

int main() {
    int n,m; cin >> n;
    { string s; cin >> s; m = s.size(); }

    dp[0][0] = 1;
    for (int l = 1; l <= n; l++) {
        dp[l][0] = (dp[l-1][0] + 2LL*dp[l-1][1]) % MOD;
        for (int m = 1; m <= l; m++) {
            dp[l][m] = dp[l-1][m-1];
            if (m < N-1) {
                dp[l][m] += 2LL*dp[l-1][m+1] % MOD;
                if (dp[l][m] >= MOD) dp[l][m] -= MOD;
            }
        }
    }

    cout << dp[n][m] << endl;
}


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

const int maxn = 2e5 + 20;
int n, m;
vector<int> adj[maxn];
bool bio[maxn];

int main(){
    ios_base::sync_with_stdio(false);
    
    cin >> n >> m;
    
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    
    for(int i : adj[n]){
        bio[i] = true;
    }
    
    for(int i : adj[1]){
        if(bio[i]){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    
    cout << "IMPOSSIBLE" << endl;
    
    return 0;
}


Measured memory_bytes: 12144
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
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;
}
using namespace std;

void solve(){
    int n,c;
    cin>>n>>c;
    vector<pair<int,int>>v(c);
    rep(i,c)v[i].second=(i+1);
    vector<tuple<int,int,int>>g(n);
    rep(i,n)cin>>get<0>(g[i])>>get<1>(g[i])>>get<2>(g[i]);
    sort(g.begin(),g.end());
    rep(i,n){
        int s=get<0>(g[i]);
        int t=get<1>(g[i]);
        int C=get<2>(g[i]);
        rep(j,c){
            if(v[j].first==s&&v[j].second==C){
                v[j]={t,C};
                break;
            }
            else if(v[j].first<s){
                v[j]={t,C};
                break;
            }
        }
    }
    int cnt=0;
    rep(i,c){
        if(v[i].first)++cnt;
    }
    cout<<cnt<<"\n";
}
 
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const int maxN = 1e6 + 55;

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

    int n, k;   cin >> n >> k;
    vector<int> a(n);

    for(auto &x : a) {
        cin >> x;
    }

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

    int tot = accumulate(a.begin(), a.end(), 0);

    int m = k;

    for(int i = 0; i < n && (k > 0); i++) {
        if(a[i] * 4 * m >= tot) {
            k--;
        }
    }

    if(k) {
        cout << "No\n";
        return 0;
    }

    cout << "Yes\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<cmath>

using namespace std;

#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 ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000
#define INFL (long long)(4e18)

using vi = vector<int>;

template<class T>
struct Edge {
    int to;
    T cost;
    Edge() {};
    Edge(int to, T cost) : to(to), cost(cost) {};
};

template<class T>
class Graph {
    int n;
    bool directed;
    vector<vector<Edge<T>>> edges;
public:

    Graph(int n, bool directed) :n(n), directed(directed), edges(vector<vector<Edge<T>>>(n)){};
    Graph() {};

    void add(int to, T cost) {
        emplace_back(to, cost);
    }

    int size() {
        return n;
    }
};


int main() {

    int  H,N;

    cin >> H >> N;

    vi A(N),B(N);

    int ma = 0;

    REP(i,N){
        cin >> A[i] >> B[i];
        if(ma<A[i]){
            ma = A[i];
        }
    }

    vi dp(H+ma+2);

    for(auto& d:dp){
        d = INF;
    }

    dp[0] = 0;

    REP(i,H+1){
        REP(j,N){
             dp[i+A[j]] = min(dp[i+A[j]],dp[i] + B[j]);
        }
    }

    int mi = INF;

    FOR(i,H,H+ma+1){
        if(dp[i]<mi){
            mi = dp[i];
        }
    }

    cout << mi << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
 int a, b, i, j, x;

 for(x=0; 1; x++){
  scanf("%d %d", &a, &b);
 
  if(a==0 && b==0){ break; }
 
  for(i = 0; i < a; i++){
   for(j = 0; j < b; j++){
     printf("#");
   }
   printf("\n");
  }
  
  printf("\n");
 }

 return 0;
}

Measured memory_bytes: 1000
#include<stdio.h>

int main()
{
    int i, swap, d1, d2, cost, t1, t2, t3;
    scanf("%d %d %d", &t1, &t2, &t3);
    if(t1>t2)
    {
        swap=t2;
        t2=t1;
        t1=swap;
    }
    if(t1>t3)
    {
        swap=t3;
        t3=t1;
        t1=swap;
    }
    if(t2>t3)
    {
        swap=t3;
        t3=t2;
        t2=swap;
    }
    d1=t2-t1;
    d2=t3-t2;
    if(d1<0)
        d1*=(-1);
    if(d2<0)
        d2*=(-1);
    cost=d1+d2;
    printf("%d\n", cost);
    return 0;
}


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

int main() {
	int S,h,m,s;
	cin >> S;
	h = S / 60 / 60;
	m = (S - (h * 60 * 60)) / 60;
	s = (S - (h * 60 * 60)) - (m * 60);
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    int n, m, c;
    cin >> n >> m >> c;
 
    int b[m];
    int a[n];
 
    for(int i = 0; i < m; i++) {
        cin >> b[i];
    }
  
    int sum = 0;
    int ans = 0;
 
    for(int i = 0; i < n; i++) {
      sum = 0;
      int temp;
      for (int z=0;z<m;z++){
        cin >> temp;
        sum += temp*b[z];
      }
      sum += c;
      if(sum > 0) {
        ans += 1;
      }
    }
 
    cout << ans;
 
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt(), a = sc.nextInt();

        if (n % 500 <= a) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21588
// Biを基準にすると、自分より小さいAiすべて, 自分よりより大きいCiすべての組み合わせが該当します。
package main
import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"sort"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main(){
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()
	N := nextInt()
	A, B, C := nextInts(N), nextInts(N), nextInts(N)
	sort.Ints(A)
	sort.Ints(B)
	sort.Sort(sort.Reverse(sort.IntSlice(C)))
	ans := 0
	for i:=0; i<N; i++{
		ai := sort.Search(N, func(j int)bool{
			return B[i] <= A[j]
		})
		ci := sort.Search(N, func(j int)bool{
			return B[i] >= C[j]
		})
		ans += ai*ci
	}
	fmt.Fprintln(out, ans)
}

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInts(n int) []int{
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

Measured memory_bytes: 7332
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        Strategy strategy = new MyStrategy();
        strategy.solve(out, sc);
        out.flush();
    }
}

class MyStrategy implements Strategy {
    @Override
    public void solve(PrintWriter out, FastScanner sc) {
        int N = sc.nextInt();
        int M = sc.nextInt();
        if (N == M) {
            out.println("Yes");
        } else {
            out.println("No");
        }

    }
}

interface Strategy {
    void solve(PrintWriter out, FastScanner sc);
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 21460
h,w=map(int,input().split())
grid=[list(input()) for i in range(h)]

sum=0
for i in range(h):
  for j in range(w):
    if grid[i][j]=='.':
      sum+=1   

grid[0][0]=0
loc=[[0,0]]      
    
ans=0
for k in range(1,h*w):
  next_loc=[]
  for [y,x] in loc:
    for [i,j] in ([1,0],[-1,0],[0,1],[0,-1]):
      if 0<=y+i<=h-1 and 0<=x+j<=w-1:
        if grid[y+i][x+j]=='.':
          grid[y+i][x+j]=k
          next_loc.append([y+i,x+j])
    loc=next_loc
  if [h-1,w-1] in loc:
    ans=k
    break

if ans==0:
  print(-1)
else:
  print(sum-k-1)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    char a[100+10],b[100+10];
    for(int i=0; i<n; i++)
        cin>>a[i];
    for(int i=0; i<n; i++)
        cin>>b[i];
    for(int i=0; i<n; i++)
    {
        cout<<a[i];
        cout<<b[i];
    }
}


Measured memory_bytes: 256
//According to all known laws of aviation, there is no way that a bee should be able to fly.
//Its wings are too small to get its fat little body off the ground. The bee, of course, flies anyway.
//Because bees don't care what humans think is impossible.
#include <bits/stdc++.h>
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
 
using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;

int main(){
    FAST_IO ;
    string str ; cin >> str ;
    int Q ; cin >> Q ;
    bool reversed = false ;
    deque<char> dq ( str.begin() , str.end() ) ;
    
    while( Q-- ){
        int x ; cin >> x ;
        if( x == 1 )
            reversed = !reversed ;
        else{
            int f ; cin >> f ; char ch ; cin >> ch ;
            if( f == 1 ){
                if( reversed )
                    dq.push_back(ch) ;
                else
                    dq.push_front(ch) ;
            }
            else{
                if( reversed )
                    dq.push_front(ch) ;
                else
                    dq.push_back(ch) ;
            }
        }
    }
    string ans = "" ;
    while( !dq.empty() ){
        char ch = dq.front() ;
        dq.pop_front() ;
        ans += ch ;
    }
    if( reversed ){
        reverse(ans.begin(), ans.end() ) ;
    }
    cout << ans << endl ;
    return 0 ;
}


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

int main(){
    int A, B, C;
    int maximum = 0;
    cin >> A >> B >> C;
    
    if (A >= B && A >= C){
        maximum = A;
        cout << 10*maximum + B + C << endl;
        
    }
    else if (B >= A && B >= C) {
        maximum = B;
        cout << 10*maximum + A + C << endl;
    }
    else {
    cout << 10*C + B + A << endl;
    }
    return 0;
}


Measured memory_bytes: 384
<?php
    fscanf(STDIN, "%d\n", $n);
    $a = explode(" ", trim(fgets(STDIN)));

    $score_a = 0;
    $score_b = 0;

    $tmp = 0;

    for ($i = 0; $i < $n; $i++) {
        $tmp += $a[$i];
        if ($i % 2 == 0) {
            if ($tmp >= 0) {
                $score_a += $tmp + 1;
                $tmp -= ($tmp + 1);
            }
        } else {
            if ($tmp <= 0) {
                $score_a += -($tmp - 1);
                $tmp += -($tmp - 1);
            }
        }
    }

    $tmp = 0;

    for ($i = 0; $i < $n; $i++) {
        $tmp += $a[$i];
        if ($i % 2 != 0) {
            if ($tmp >= 0) {
                $score_b += $tmp + 1;
                $tmp -= ($tmp + 1);
            }
        } else {
            if ($tmp <= 0) {
                $score_b += -($tmp - 1);
                $tmp += -($tmp - 1);
            }
        }
    }

    echo min($score_a, $score_b) . PHP_EOL;


Measured memory_bytes: 14840
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC169D
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            long num = N;
            long[] z = new long[20];
            int sousa = 0;
            int x = 0;
            int sosuu = 0;
            //Console.WriteLine(N);
            //Console.WriteLine(num);
            if (N != 1)
            {
                for (long i = 2; i<1000000; i++)
                {
                    if (N >= i)
                    {
                        if (N % i == 0)
                        {
                            while (N % i == 0)
                            {
                                z[x] += 1;
                                N = N / i;
                                //Console.WriteLine(z[x]);
                            }
                            x += 1;
                        }
                    }
                }
                if (N != 1)
                {
                    z[x + 1] += 1;
                }
                //Console.WriteLine(z[3]);
                //Console.WriteLine(z[2]);
                for (long i = 0; i < 20; i++)
                {
                    int j = 1;
                    int kaisuu = 0;
                    while (z[i] > 0)
                    {
                        z[i] -= j;
                        j++;
                        if (z[i] >= 0)
                        {
                            kaisuu++;
                        }
                    }
                    //Console.WriteLine(kaisuu);
                    if (kaisuu != 0)
                    {
                        sousa += kaisuu;
                    }
                }
            }
            else
            {
                sousa = 0;
            }
            Console.WriteLine(sousa);
        }
    }
}


Measured memory_bytes: 27540
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+7,inf=1e9+7; bool fl[N];
int n,s,t,cnt,tot,ch[4],f[N],pre[N],que[N<<2];
long long sum,dis[N];
struct edge{int u,v,t,q,s;}ed[N<<1];
inline int read(){
	int num=0; char g=getchar(); while(g<48||57<g) g=getchar();
	while(47<g&&g<58) num=(num<<1)+(num<<3)+g-48,g=getchar(); return num;
}
inline void add(int a,int b,int c,int d){
	tot++,ed[tot].u=a,ed[tot].v=b,ed[tot].t=c,ed[tot].q=d,ed[tot].s=f[a],f[a]=tot;
}
inline void addedge(int a,int b,int c,int d){
	add(a,b,c,d),add(b,a,0,-d);
}
inline void flows(){
	for(int i=1;i<=cnt;i++) dis[i]=0;
	int head=1,tail=1; que[head]=s; dis[s]=1e18;
	while(head<=tail){
		int x=que[head++]; fl[x]=0;
		for(int i=f[x];i>0;i=ed[i].s){
			if(!ed[i].t) continue;
			int u=ed[i].v;
			if(dis[u]<dis[x]+ed[i].q){
				dis[u]=dis[x]+ed[i].q,pre[u]=i;
				if(!fl[u]) fl[u]=1,que[++tail]=u;
			}
		}
	}
	
	int z=inf,u=t; if(!dis[u]) return; long long xs=0;
	while(u!=s) z=min(z,ed[pre[u]].t),xs=xs+ed[pre[u]].q,u=ed[pre[u]].u; sum=sum+xs*z,u=t;
	while(u!=s) ed[pre[u]].t-=z,ed[pre[u]^1].t+=z,u=ed[pre[u]].u;
}
int main(){
	n=read(),s=++cnt,t=++cnt,ch[0]=++cnt,ch[1]=++cnt,ch[2]=++cnt,ch[3]=++cnt,tot=1;
	for(int i=1;i<=n;i++){
		int x=read(),y=read(),c=read(),q=++cnt;
		addedge(s,q,c,0);
		for(int z=0;z<4;z++){
			int h=0; if(z&1) h=h+x; else h=h-x; if(z&2) h=h+y; else h=h-y; 
			addedge(q,ch[z],inf,h);
		}
	}
	for(int i=1;i<=n;i++){
		int x=read(),y=read(),c=read(),q=++cnt;
		addedge(q,t,c,0);
		for(int z=0;z<4;z++){
			int h=0; if(z&1) h=h-x; else h=h+x; if(z&2) h=h-y; else h=h+y; 
			addedge(ch[z],q,inf,h);
		}
	}
	dis[t]=1; while(dis[t]) flows(); cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 4736