akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
    int N,K;
    string S;
    cin>>N>>K;
    cin>>S;
    int start[100000],end[100000];
    int num_block_of_one=0;
    int num_block_of_zero=0;
    int last=1;
    int now;
    if(S[0]=='0') last=0;
    else start[0]=0;
    rep(i,N-1){
        if(S[i+1]=='0') now=0;
        else now=1;
        if(last==now) last=now;
        else{
            if(now==0) {
                end[num_block_of_one]=i;
                num_block_of_one++;
            } else {
                start[num_block_of_one]=i+1;
                num_block_of_zero++;
            }
            last=now;
        }

    }
    if(S[N-1]=='1') {
        end[num_block_of_one]=N-1;
        num_block_of_one++;
    }else num_block_of_zero++;
    int ans=0;
    rep(i,num_block_of_one-K) ans=max(ans,end[i+K]-start[i]+1);
    if(S[0]=='0' && K<=num_block_of_one) ans=max(end[K-1]+1,ans);
    if(S[N-1]=='0' && K<=num_block_of_one) ans=max(N-start[num_block_of_one-K],ans);
    if(K>=num_block_of_zero) ans=N;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 896
gets
a=gets.split.map(&:to_i)
b=gets.split.map(&:to_i)
c=gets.split.map(&:to_i)
r=0
prev=nil
for a_i in a
r+=b[a_i-1] + if prev && prev.succ==a_i  then c[prev-1] else 0 end
prev=a_i
end
puts r


Measured memory_bytes: 1788
#include<stdio.h>
int A[2000000];
int B[2000000];
void countingSort(k,n){
  int i,j,C[k+1];
  for (i = 0;i<=k;i++){
    C[i] = 0;
	   }
  for( i = 0;i < n;i++){
    C[A[i]] = C[A[i]]+1;
  }
    /* C[i]にはiの出現数が記録されている*/
  for( i = 1; i <= k; i++){
    C[i] = C[i] + C[i-1];
       }
    /* C[i]にはi以下の数の出現数が記録されている*/
  for( i = n ; i >= 0; i--){
    B[C[A[i]]] = A[i];
    C[A[i]] = C[A[i]]-1;
  }
}
int main(){
  int i,j,k,n;
  k=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    if(k<A[i])k=A[i];
  }
  countingSort(k,n);
  for(i=1;i<=n;i++){
    if(i!=1)printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
  return 0;
}

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

int main  () {
  int N, a;
  cin >> N >> a;
  
  int MAX = a, MIN = a;
  for (int i = 1; i < N; i++) {
    cin >> a;
    MAX = max(MAX, a);
    MIN = min(MIN, a);
  }
  cout << MAX-MIN << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.math.*;
 
public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		String[] str = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int x = Integer.parseInt(str[1]);
		String[] str1 = br.readLine().split(" ");
		int[] a = new int [n];
		long cnt = 0;
		for(int i = 0; i < n; i++){
			int tmp = Integer.parseInt(str1[i]);
			if(tmp>x){
				cnt += tmp - x;
				tmp = x;
			}
			a[i] = tmp;
		}

		//n=2
		if(n==2){
			if(a[0]+a[1]>x){
				int o = a[0]+a[1]-x; 
				cnt += o;
				sb.append(cnt);
				System.out.println(sb);
				return;
			}
		}

		//n>2
		for(int i = 1; i < n; i++){
			int a1 = a[i-1];
			int a2 = a[i];

			if(a1+a2>x){
				int o = a1+a2-x; 
				cnt += o;
				a[i] -= o;
				if(a[i]<0){
					a[i-1] += a[i];
					a[i] = 0;
				}
			}
		}
		sb.append(cnt);
		System.out.println(sb);

	}
}

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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  int m = min(A, B);
  int cnt = 0;
  for (int i = m; i > 0; i--) {
    if (A % i == 0 && B % i == 0) cnt++;
    if (cnt == K) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
#define lli long long int
#define llu unsigned long long int
#define fr(va, beg, end) for (lli va = beg; va < end; va++)
#define pb push_back
#define rt return 0
#define endln "\n"
#define all(x) x.begin(), x.end()
#define sz(x) (lli)(x.size())
const lli MOD = 1e9 + 7;
// cout << fixed << setprecision(0) << pi <<endl;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// for multiset
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

void solve() {
    lli n, a, m, x;
    cin >> n >> m >> x;
    vector<vector<lli>> v(n + 2);
    vector<lli> cs;

    for (lli i = 0; i < n; i++) {
        cin >> a;
        cs.pb(a);
        for (lli j = 0; j < m; j++) {
            cin >> a;
            v[i].pb(a);
        }
    }

    lli flag = 0, mn = 1e17;

    for (lli i = 0; i < pow(2, n); i++) {
        vector<lli> ch(m + 2, 0);
        lli val = i, cnt = 0, cost = 0;

        while (val > 0) {
            if (val % 2 == 1) {
                cost += cs[cnt];
                for (lli j = 0; j < m; j++) {
                    ch[j] += v[cnt][j];
                }
            }
            val /= 2;
            cnt++;
        }

        lli flag = 0;
        for (lli j = 0; j < m; j++) {
            if (ch[j] < x) {
                flag = 1;
                break;
            }
        }
        if (flag == 0) {
            mn = min(mn, cost);
        }
    }

    if (mn == 1e17) {
        cout << "-1" << endl;
    } else {
        cout << mn << endl;
    }
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // lli t; cin >> t; while(t--)
    solve();
    rt;
}

Measured memory_bytes: 4068
def resolve():
    # 整数 1 つ
    n = int(input())
    # 整数複数個
    # a, b, c = list(map(int, input().split()))
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    A = sorted(N)

    print(A[-1] - A[0])


resolve()

Measured memory_bytes: 38256
def solve():
    S = input()
    T = input()

    ans = float('inf')
    for i in range(0,len(S)-len(T)+1):
        cnt = 0
        for j in range(len(T)):
            if S[i+j] != T[j]:
                cnt += 1
        ans = min(cnt,ans)
    
    print(ans)

if __name__ == '__main__':
    solve()


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

int main(){
  double w, h, x, y, f = 0;
  cin >> w >> h >> x >> y;
  if(w == 2 * x && h == 2 * y) f = 1;
  cout << w * h / 2 << " " << f << endl; 
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int temp=0,k,s;
void saiki(int* c,int S,int n){
  if(S==0){
    temp++;
    return;
  }
  int i,t;
  if(n!=2){
    if(S<k)
      t=S;
    else
      t=k;
    for(i=0;i<=t;i++){
      c[n]=i;
      saiki(c,S-i,n+1);
    }
  }else if(S<=k)
    temp++;
}
int main(void){
int c[3];
scanf("%d %d",&k,&s);
  saiki(c,s,0);
  printf("%d\n",temp);
  return 0;
}



Measured memory_bytes: 128
import re

def test():
    s = input()
    n = len(s)
    str = "[^ACGT]"
    a = []
    result = 0
    for i in range(n):
        a.append(s[i])
        b = "".join(a)
        c = re.findall(str,b)
        if c:
            a.clear()
        else:
            result = max(result,len(a))

    print(result)


if __name__ == "__main__":
    test()


Measured memory_bytes: 3188
s = input()
n = len(s)

A = [1]
mod = 2019
for i in range(n-1):
    A.append((A[-1]*10)%mod)

B = [int(s[-1])]
for i in range(1, n):
    B.append((B[-1] + A[i] * int(s[n-i-1])) % mod)

# print(B)

ans = 0
C = [0] * 2019
C[0] += 1
for i in range(n):
    C[B[i]] += 1

for i in range(len(C)):
    ans += (C[i]-1)*C[i]//2

print(ans)

Measured memory_bytes: 81168
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>

using namespace std;

char s[110];
int ret,len;

 int main()
 {
	 scanf("%s",s);
	 len = strlen(s);
	 
	 ret = 1e6;
	 for(int i = 0; i < 26;i++)
	 {
		 int ma = 0;int cou = 0;
		 for(int j = 0;j < len;j++)
		 {
			 if((s[j] - 'a') == i)
			 {
				 ma = max( cou , ma );
				 cou = 0;
			 }
			 else
			 {
				cou++;
			 }
		 }
		 ma = max( cou , ma );
		 ret = min( ret , ma );
	 }
	 
	 printf("%d",ret);
	 
	 return 0;
 
 }
	 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int h, w, k; cin >> h >> w >> k;
    vector<vector<char>> a(h, vector<char>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
        }
    }
    vector<vector<int>> ans(h, vector<int>(w, 0));
    int cur = 1;
    vector<int> beg(k + 10), ending(k + 10), row(k + 10);
    for (int i = 0; i < h; i++) {
        int tot = 0;
        for (int j = 0; j < w; j++) {
            tot += (a[i][j] == '#');
        }
        if (tot == 0) {
            continue;
        }
        int left = 0;
        int current = 1;
        for (int j = 0; j < w; j++) {
            ans[i][j] = cur;
            if (a[i][j] == '#') {
                beg[cur] = left;
                left = j + 1;
                ending[cur] = j;
                row[cur] = i;
                if (current != tot) {
                    current++;
                    cur++;
                }
                if (current == tot) {
                    ending[cur] = w - 1;
                }
            }
        }
        cur++;
    }
//    for (int i = 0; i < h; i++) {
//        for (int j = 0; j < w; j++) {
//            cout << ans[i][j] << " \n"[j == w - 1];
//        }
//    }
//    cout << "\n";
    for (int i = 1; i <= k; i++) {
        int l = beg[i], r = ending[i];
        for (int ii = row[i] - 1; ii >= 0; ii--) {
            bool ok = true;
            for (int j = l; j <= r; j++) {
                ok &= (ans[ii][j] == 0);
            }
            if (ok) {
                for (int j = l; j <= r; j++) {
                    ans[ii][j] = i;
                }
            } else {
                break;
            }
        }
        for (int ii = row[i] + 1; ii < h; ii++) {
            bool ok = true;
            for (int j = l; j <= r; j++) {
                ok &= (ans[ii][j] == 0);
            }
            if (ok) {
                for (int j = l; j <= r; j++) {
                    ans[ii][j] = i;
                }
            } else {
                break;
            }
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cout << ans[i][j] << " \n"[j == w - 1];
        }
    }
}


Measured memory_bytes: 2304
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = Integer.parseInt(line);
			long sum = 0;
			for (int i = 0; i < n; i++) {
				sum += Long.parseLong(br.readLine());
			}
			System.out.println(sum / n);
		}
	}
}

Measured memory_bytes: 20960
N = int(input())
def f(a,b):
    a = max(a,b)
    return len(str(a))
ans = float("inf")
for a in range(1, 100001):
    b, m = divmod(N, a)
    if m==0:
        ans = min(ans, f(a,b))
print(ans)


Measured memory_bytes: 2940
import sys

#+++++


def main():
	a, b, k = map(int, input().split())
	if a+k < b+1-k:
		#print('ffff')
		ff=range(a,b+1)[:k]
		bb=range(a,b+1)[-k:]
		ret=list(ff)+list(bb)
	else:
		ret=range(a,b+1)
	
	for i in ret:
		print(i)
		
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
	else:
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3064
using System;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string r = Console.ReadLine();
                if (r == null) break;
                double[] k0 = new double[6];
                for (int i = 0; i < 6; i++) k0[i] = double.Parse(r.Split(' ')[i]);
                string x, y;
                y = ((k0[2] * k0[3] - k0[0] * k0[5]) / (k0[1] * k0[3] - k0[0] * k0[4])).ToString();
                x = ((k0[2] - k0[1] * double.Parse(y)) / (k0[0])).ToString();
                Console.WriteLine(String.Format("{0:0.000}", double.Parse(x)) + " " + String.Format("{0:0.000}", double.Parse(y)));
            }
        }
    }
}

Measured memory_bytes: 9048
//Great to know you're toned in
#include <bits/stdc++.h>
using namespace std;

const int N = 100100;

int n;
set<int> g[N];
int p[N];

int get(int x) {
    if (p[x] == -1) {
        return x;
    }
    return p[x] = get(p[x]);
}

int main() {
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].insert(b);
        g[b].insert(a);
    }

    vector<pair<int, int>> cand;
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if (g[a].count(b)) {
            cand.emplace_back(a, b);
        }
        g[a].insert(b);
        g[b].insert(a);
    }

    fill_n(p, n, -1);
    int cnt = 0;
    while (!cand.empty()) {
        int a, b;
        tie(a, b) = cand.back();
        cand.pop_back();
        a = get(a);
        b = get(b);
        if (a == b) {
            continue;
        }

        cnt++;

        if (g[a].size() > g[b].size()) {
            swap(a, b);
        }

        p[a] = b;

        g[a].erase(b);
        g[b].erase(a);
        for (int x: g[a]) {
            g[x].erase(a);
            if (g[x].count(b)) {
                cand.emplace_back(x, b);
            }
            g[x].insert(b);
            g[b].insert(x);
        }
        set<int>().swap(g[a]);
    }

    if (cnt == n - 1) {
        cout << "YES";
    } else {
        cout << "NO";
    }
}


Measured memory_bytes: 24192
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
 
/*------------------------------------------------------------------*/
 
int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n){
        a[i] = i + 1;
    }
    vector<int> b(n);
    vector<int> c(n);
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    int num_b = 0;
    int num_c = 0;
    int j = 0;
    do{
        bool flag_b = true;
        bool flag_c = true;
       for(int i = 0; i < n; i++){
           if(a[i] != b[i])flag_b = false;
           if(a[i] != c[i])flag_c = false;
       }
       if(flag_b)num_b = j;
       if(flag_c)num_c = j;
       j++;
    }while(next_permutation(a.begin(), a.end()));
    cout << abs(num_b - num_c) << endl;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
sushi = []
for i in range(n):
    tmp = list(map(int, input().split()))
    sushi.append(tmp)
eaten = set() # 食べた種類を記憶(集合型)
chohuku = [] # 同じ種類で二回以上食べた寿司のスコアを記録
scores = [] # Sのスコアのリスト

sushi.sort(key=lambda x:x[1])
sushi.reverse() # sushiをおいしさの降順にソート

tmp = 0 # Sのおいしさの合計を保持
for i in range(k): # sushiを美味しい順にk個食べる
    if sushi[i][0] in eaten: # 同じ種類の寿司を食べていた場合
        chohuku.append(sushi[i][1])
    else:
        eaten.add(sushi[i][0]) # 食べた寿司の種類を記憶
    tmp += sushi[i][1] # 食べた寿司のおいしさをtmpに追加
chohuku.sort()
scores.append(tmp+len(eaten)**2) # 今のSのスコアを記憶

for i in range(k,n):
    if not sushi[i][0] in eaten and chohuku != []:
        tmp -= chohuku.pop(0)
        eaten.add(sushi[i][0])
        tmp += sushi[i][1]
        scores.append(tmp+len(eaten)**2)
        
print(max(scores))

Measured memory_bytes: 30396
#include <math.h>

#include <algorithm>
#include <cassert>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define PI 3.14159265358979323846264338327950L
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  int r, D, x;
  cin >> r >> D >> x;
  int ans = 0;
  rep(i, 10) {
    x = r * x - D;
    cout << x << endl;
  }
}


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

int main() {
  long long N; cin >> N;
  vector<long long> A(5);
  long long mi = 1LL<<60;
  for (int i = 0; i < 5; i++) cin >> A[i], mi = min(mi, A[i]);
  cout << (N + mi - 1) / mi + 4 << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	//	System.out.println("?????£??????????????????????????????????????????-?????\???");

		List<String> list = new ArrayList<String>();

		while(sc.hasNext()) {


			String strCards = sc.nextLine();
			String[] arrayCards = new String[strCards.length()];

			if(strCards.equals("-")) {
		//		System.out.println("???????????????");
				break;
			}else {

				//??????????????\??????????????´??????????§£??????????´??????????
				for(int i = 0; i < strCards.length(); i++) {
					arrayCards[i] = strCards.substring(i, i+1);
				}

		//		for(String s : arrayCards) {
		//			System.out.println("?????£???????????? : "+s);
		//		}

				//???????????£???????????????????±???????
		//		System.out.println("???????????£?????????????????????");

				String strH = sc.nextLine();
				int intH = Integer.parseInt(strH);

				//int intH = sc.nextInt();
				for(int i = 0; i < intH; i++) {
		//			System.out.println("?????£?????????"+ (i+1) +"??????");
		//			System.out.println("?????????h??????????????????????????£?????????????????????");


					String strInputNum = sc.nextLine();
					int inputNum = Integer.parseInt(strInputNum);

					//int inputNum = sc.nextInt();
					arrayCards = shuffle(inputNum, strCards, arrayCards);
				}

		//		System.out.println("?????£???????????????");


			//	for(String s : arrayCards) {
			//		System.out.println("?????£???????????? : "+s);
			//	}

				StringBuffer buf = new StringBuffer();

				for(int i = 0; i < arrayCards.length; i++) {
					buf.append(arrayCards[i]);
				}
				//?????£??????????????????????????????????????????
				String strBuf = buf.toString();

				list.add(strBuf);

		//		System.out.println("??°?????????????????§?????£??????????????????????????????????????????-?????\???");

			}
		}

		for(String s : list) {
			System.out.println(s);
		}

	}

	public static String[] shuffle(int intH, String strCards, String[] arrayCards) {

		String[] arrayOkibaBack = new String[intH];

		int aOFYousosu =  strCards.length() - intH;
		String[] arrayOkibaFront = new String[aOFYousosu];

		//????????????????????????????????????
		for(int i = 0; i < intH; i++) {
			arrayOkibaBack[i] = arrayCards[i];
		}

		//????????????????????????????????????
		int Count = 0;
		for(int i = intH; i < strCards.length();i++) {
			arrayOkibaFront[Count] = arrayCards[i];
			Count++;
		}
		//?????£???????????????????????????????????\????????????
		for(int i = 0; i < strCards.length(); i++) {
			if(i < arrayOkibaFront.length) {
				arrayCards[i] = arrayOkibaFront[i];
			}
			else {
				arrayCards[i] = arrayOkibaBack[i - (arrayOkibaFront.length)];
			}
		}

		return arrayCards;

	}
}

Measured memory_bytes: 26372
/*
 * 2619.cc: Thread Tree
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;

/* typedef */

typedef vector<int> vi;

/* global variables */

string msgs[MAX_N];
vi chlds[MAX_N];

/* subroutines */

void print_tree(int k, int idx) {
  for (int i = 0; i < idx; i++) putchar('.');
  cout << msgs[k] << endl;

  for (vi::iterator vit = chlds[k].begin(); vit != chlds[k].end(); vit++)
    print_tree(*vit, idx + 1);
}

/* main */

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

  for (int i = 0; i < n; i++) {
    int ki;
    cin >> ki >> msgs[i];
    ki--;
    if (i > 0) chlds[ki].push_back(i);
  }

  print_tree(0, 0);
  return 0;
}

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

int main() {
    int a,b,c;
    int ans;

    scanf("%d%d%d", &a, &b, &c);
    ans = c - (a-b);
    if(ans < 0) ans = 0;
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<climits>
#include<cfloat>

using namespace std;

double EPS=1e-10;

double add(double a,double b){
  if(abs(a+b)<EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}

struct point{
  double x,y;
  point(){}
  point(double x,double y) : x(x) , y(y) {}

  point operator + (point p) {
    return point(add(x,p.x),add(y,p.y));
  }

  point operator - (point p) {
    return point(add(x,-p.x),add(y,-p.y));
  }

  point operator * (double d) {
    return point(x*d,y*d);
  }

  point operator / (double d) {
    return point(x/d,y/d);
  }

  bool operator == (const point &p)const{
    return abs(x-p.x)<EPS && abs(y-p.y)<EPS;
  }
};

struct circle{
  point p;
  double r;
  circle(){}
  circle(point p,double r):p(p),r(r){}
};

double dist(point a, point b){
  return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}

vector<point> circle_cross(circle a, circle b){
  vector<point>ret;

  double x=a.p.x-b.p.x,y=a.p.y-b.p.y;
  double L=x*x+y*y;

  if(L>pow(a.r+b.r,2))return ret;

  L=sqrt(L);
  double C=atan2(b.p.y-a.p.y,b.p.x-a.p.x);
  double alpha=acos((L*L+a.r*a.r-b.r*b.r)/(2*L*a.r));

  point r1,r2;
  r1.x=a.p.x+cos(C+alpha),r1.y=a.p.y+sin(C+alpha);
  r2.x=a.p.x+cos(C-alpha),r2.y=a.p.y+sin(C-alpha);

  ret.push_back(r1),ret.push_back(r2);
  return ret;
}

int main(void){

  int n;
  point a;
  vector<point>P;
  vector<circle>C;

  while(cin >> n,n){
    P.clear();
    C.clear();
    for(int i=0;i<n;i++){
      cin >> a.x >> a.y;
      P.push_back(a);
    }

    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	if(dist(P[i],P[j])>2.0+EPS)continue;
	vector<point>res=circle_cross(circle(P[i],1.0),circle(P[j],1.0));
	for(int k=0;k<res.size();k++)
	  C.push_back(circle(res[k],1));
      }
    }

    int ans=1;
    for(int i=0;i<C.size();i++){
      int cnt=0;
      for(int j=0;j<P.size();j++)
	if(dist(C[i].p,P[j])<1.0+EPS)cnt++;
	
      ans=max(ans,cnt);
    }

    cout << ans << endl;
  }

  return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while (0)
#define chmin(x, v) do { x = min(x, v); } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll N, M, s=0;
  cin >> N >> M;
  vector<ll> a(N);
  rep(i, N) {
    cin >> a[i];
    s += a[i];
  }
  ll t=0;
  rep(i, N) {
    // a >= s/(4M)
    // 4aM >= s
    if (4*a[i]*M >= s)
      t++;
  }
  cout << (t >= M ? "Yes" : "No") << endl;
  return 0;
}


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

int main() {
  int N;
  int L[100]={};
  int sum=0;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> L[i];
  }
  sort(L,L+N,std::greater<int>());
  for(int i=1;i<N;i++){
    sum = sum + L[i];
  }
  if(L[0]<sum) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
static const ULLONG UL_HUGE_DIVIDER = 1000000007LLU;

static void ABC113D_NumOfAmida();

#if 1
int main()
{
	ABC113D_NumOfAmida();

	fflush(stdout);
	return 0;
}
#endif

static void ABC113D_NumOfAmida()
{
	//	写経させていただきました。力不足でお恥ずかしい。こんな発想出てこないっす
	int H, W, K;
	static ULLONG dp[101][8] = { 0 };
	dp[0][0] = 1;

	scanf(" %d %d %d", &H, &W, &K);
	
	for (int h = 0; h < H; h++) {
		for (int x = 0; x < W; x++) {
			//	賢いなあ。あみだくじの横線ありなしををビットの 1/0 で表現なんて思いつかないわ
			for (int line = 0; line < (1 << (W - 1)); line++) {
				//	で，ビット列が 11 になっているものがないかをチェックするのね
				bool connected = false;
				for (int chk = 0; chk < (W - 2); chk++) {
					if (((line >> chk) & 1) && ((line >> (chk + 1)) & 1)) {
						//	ビット列が 11 の並びがあったらこのパターンはダメ，と
						connected = true;
					}
				}
				//	横線がつながっちゃってるんで，パス
				if (connected) continue;

				if ((x >= 1) && ((line >> (x - 1)) & 1)) {
					//	x より左側に 1 があれば，左に向かって移動した，と
					dp[h + 1][x - 1] += dp[h][x];
					dp[h + 1][x - 1] %= UL_HUGE_DIVIDER;
				}
				else if ((x <= (W - 2)) && ((line >> x) & 1)) {
					//	x より右側に 1 があれば，右に向かって移動した，と
					dp[h + 1][x + 1] += dp[h][x];
					dp[h + 1][x + 1] %= UL_HUGE_DIVIDER;
				}
				else {
					//	右でも左でもなく，連続した横線もない
					dp[h + 1][x] += dp[h][x];
					dp[h + 1][x] %= UL_HUGE_DIVIDER;
				}
			}
		}
	}

	printf("%llu\n", dp[H][K - 1]);
}


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

using namespace std;

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pii;

#define all(c) begin(c),end(c)

#define D(x) do { std::cerr << x << " "; } while (0)
#define D2(x) do { std::cerr << #x << ": " << x << std::endl; } while (0)


template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}


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

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


auto solve() {
    int N;
    cin >> N;
    int A, B, C;
    cin >> A >> B >> C;
    vi l(N);
    for (auto &&e:l) cin >> e;

    sort(all(l));

    const ll LINF = 1ll<<60;
    ll res = LINF;

    do {
        REP(i, N) {
            FOR(j, i + 1, N) {
                FOR(k, j + 1, N) {
                    ll sum = 0;
                    int s1=0,s2=0,s3=0;
                    REP(t,i+1) s1 += l[t];
                    FOR(t,i+1,j+1) s2 += l[t];
                    FOR(t,j+1,k+1) s3 += l[t];

                    sum += 10 * i + 10 * (j-i-1) + 10 * (k-j-1);
                    sum += abs(A-s1) + abs(B-s2) + abs(C-s3);
                    chmin(res,sum);
                }
            }
        }
    } while(next_permutation(all(l)));

    return res;
}


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

//    cout << (solve() ? "Heisei" : "TBD") << endl;
//    cout << (solve() ? "YES" : "NO") << endl;
    cout << solve() << endl;
//    solve();

    return 0;
}

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

int main() {
    int N, Z, W;
    cin >> N >> Z >> W;
    vector<long int> a(N);
    for (int i = 0; i < N; i++){
        cin >> a[i];
    }
    if (N == 1) cout << abs(W - a[0]) << "\n";
    else cout << max(abs(a[N-1] - a[N-2]), abs(W - a[N-1])) << "\n";
    
}

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

signed main(){
  int n; cin >> n;
	string s; cin >> s;
	bool ok = true;
	vector<string> t(4);
	t[0] = "SS"; t[1] = "SW"; t[2] = "WS"; t[3] = "WW";
	for(int i = 0; i < 4; i++){
  	for(int j = 2; j < n; j++){
		  if(t[i][j - 1] == 'S'){
				if(s[j - 1] == 'o') t[i].push_back(t[i][j - 2]);
				if(s[j - 1] == 'x'){
					if(t[i][j - 2] == 'W') t[i].push_back('S');
					if(t[i][j - 2] == 'S') t[i].push_back('W');
				}
			}
			if(t[i][j - 1] == 'W'){
				if(s[j - 1] == 'x') t[i].push_back(t[i][j - 2]);
				if(s[j - 1] == 'o'){
					if(t[i][j - 2] == 'W') t[i].push_back('S');
					if(t[i][j - 2] == 'S') t[i].push_back('W');
				} 
			}
		} 
	}
	for(int i = 0; i < 4; i++){
		ok = true;
		if(s.back() == 'o'){
			if(t[i][n - 1] == 'S' && t[i][n - 2] != t[i][0]) ok = false;
			if(t[i][n - 1] == 'W' && t[i][n - 2] == t[i][0]) ok = false;
		}
		if(s.back() == 'x'){
			if(t[i][n - 1] == 'S' && t[i][n - 2] == t[i][0]) ok = false;
			if(t[i][n - 1] == 'W' && t[i][n - 2] != t[i][0]) ok = false;
		}
		for(int j = n - 3; j >= 0; j--){
			if(s[j + 1] == 'o'){
				if(t[i][j + 1] == 'S' && t[i][j + 2] != t[i][j]) ok = false;
				if(t[i][j + 1] == 'W' && t[i][j + 2] == t[i][j]) ok = false;
			}
			if(s[j + 1] == 'x'){
				if(t[i][j + 1] == 'S' && t[i][j + 2] == t[i][j]) ok = false;
				if(t[i][j + 1] == 'W' && t[i][j + 2] != t[i][j]) ok = false;
			}
		}
		if(s[0] == 'o'){
			if(t[i][0] == 'S' && t[i][1] != t[i][n - 1]) ok = false;
			if(t[i][0] == 'W' && t[i][1] == t[i][n - 1]) ok = false;
		}
		if(s[0] == 'x'){
			if(t[i][0] == 'S' && t[i][1] == t[i][n - 1]) ok = false;
			if(t[i][0] == 'W' && t[i][1] != t[i][n - 1]) ok = false;
		}
		if(ok){
			cout << t[i] << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
 
#define MAX_L 123457
#define MAX_SQRT_B 123457
 
using namespace std;
 
typedef long long ll;
bool is_prime[MAX_L];
bool is_prime_small[MAX_SQRT_B];
 
void ss(ll a, ll b) {
  for(int i = 0; (ll)i * i <= b; i++) is_prime_small[i] = true;
  for(int i = 0; i <= b - a; i++) is_prime[i] = true;
 
  for(int i = 2; (ll)i * i <= b; i++) {
    if(is_prime_small[i]) {
      for(int j = 2 * i; (ll)j * j <= b; j += i) is_prime_small[j] = false;
      for(ll j = max(2LL, (a + i - 1) / i) * i; j <= b; j += i) is_prime[j - a] = false;
    }
  }
}
 
int main (void) {
  ll n;
 
  while(1) {
    cin >> n;
    if(n == 0) break;
     
    fill(is_prime, is_prime + MAX_L, false);
    fill(is_prime_small, is_prime_small + MAX_SQRT_B, false);
 
    ss(n+1, 2 * n+1);
 
    int cnt = 0;
    for(int i = n + 1; i < 2 * n; i++) {
      if (is_prime[i-(n+1)]) cnt++;
    }
    if(n == 1) {
      cout << "1" << endl;
    } else {
      cout << cnt << endl;
    }
  }
  return 0;
}

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

int main(){
    string S;
    cin >> S;
    if (S == "AAA" || S == "BBB") cout << "No" << endl;
    else cout << "Yes" << endl;
}

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

int main() {
    int A, B, C, D; cin >> A >> B >> C >> D;
    if(A+B == C+D) {
        cout << "Balanced" << endl;
    } else if(A+B > C+D) {
        cout << "Left" << endl;
    } else {
        cout << "Right" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int o=0;
  vector<int>a(5);
  for(int i=0;i<5;i++) cin >> a[i];
  for(int i=0;i<5;i++){
   if(a[i]==0) o=i+1;
  }
  cout << o;
  return 0;

}

Measured memory_bytes: 3576
#include<iostream>

using namespace std;

int selection_sort(int a[],int n)
{
    int cnt=0;

    for(int i=0;i<n-1;i++)
    {
        int Min=i;
        int j;
        for(j=i+1;j<n;j++)
        {
            if(a[Min]>a[j])
            {
                Min=j;
            }
        }
        if(i!=Min)
        {
            swap(a[Min],a[i]);
            cnt++;
        }
    }

    return cnt;
}

int main()
{
    int n,a[101];

    cin>>n;

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

    int cnt=selection_sort(a,n);

    for(int i=0;i<n;i++)
    {
        if(i)
        {
            cout<<" ";
        }
        cout<<a[i];
    }

    cout<<endl<<cnt<<endl;

    return 0;
}



Measured memory_bytes: 3068
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)

class Point{
public:
    double x, y;
    Point(double x=0, double y=0):x(x), y(y){}

    Point operator + (Point p){ return Point(x + p.x, y + p.y); }
    Point operator - (Point p){ return Point(x - p.x, y - p.y); }
    Point operator * (double a){ return Point(a * x, a * y); }
    Point operator / (double a){ return Point(x / a, y / a); }

    double abs() { return sqrt(norm()); }
    double norm() { return x * x + y * y;}
    bool operator < (const Point &p) const {
        // first x, second y
        return x != p.x ? x < p.x : y < p.y;
    }

    bool operator == (const Point &p) const{
        return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
    }
};

typedef Point Vector;

double dot(Vector a, Vector b){
    //|a||b|cos(theta)
    return a.x * b.x + a.y * b.y;
}
double cross(Vector a, Vector b){
    //|a||b|sin(theta)
    return a.x * b.y - a.y * b.x;
}

Point project(Point p1, Point p2, Point p){
    Vector base = p2 - p1;
    double r = dot(p - p1, base) / base.norm();
    return p1 + base * r;
}

int main() {

    int Q;
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    Point p1(x1, y1);
    Point p2(x2, y2);

    cin >> Q;
    rep(i, Q){
        double x, y;
        cin >> x >> y;
        Point p(x, y);
        Point r = project(p1, p2, p);
        printf("%.10f %.10f\n", r.x, r.y);
        // cout << r.x << " " << r.y << endl;
    }

}

Measured memory_bytes: 3296
#include<bits/stdc++.h>
#define ha 1000000007
using namespace std;

const int N=3010;
int f[N][N][2];

void Add(int &x,const int &y){x=(x+y>=ha)?(x+y-ha):(x+y);}

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) f[1][i][0]=1;
    f[1][0][1]=1;
    for(int i=1;i<=m;i++)
        for(int j=0;j<=n;j++)
        {
            if(j>=1)
            {
                Add(f[i+1][j-1][1],f[i][j][1]);
                if(j==1) Add(f[i+1][j-1][1],f[i][j][0]);
                else Add(f[i+1][j-1][0],f[i][j][0]);
            }
            if(j<n)
            {
                Add(f[i+1][j+1][1],f[i][j][1]);
                Add(f[i+1][j+1][0],f[i][j][0]);
            }
            if(j>=1)
            {
                Add(f[i+1][j][1],f[i][j][1]);
                if(j==1) Add(f[i+1][j][1],f[i][j][0]);
                else Add(f[i+1][j][0],f[i][j][0]);
            }
            if(j<n)
            {
                Add(f[i+1][j][1],f[i][j][1]);
                Add(f[i+1][j][0],f[i][j][0]);
            }
        }
    int ans=0;
    for(int i=0;i<=n;i++) Add(ans,f[m+1][i][1]);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 70784
import heapq

n,m=map(int,input().split())
a=sorted(list(map(int,input().split())))
heapq.heapify(a)

li=[list(map(int,input().split())) for i in range(m)]
li=sorted(li,key=lambda x:x[1],reverse=True)
for i in range(m):
  tmp=heapq.heappop(a)
  if tmp>li[i][1]:
    heapq.heappush(a,tmp)
    break
  else:
    heapq.heappush(a,tmp)
    for j in range(li[i][0]):
      tmp=heapq.heappop(a)
      if tmp<li[i][1]:
        heapq.heappush(a,li[i][1])
      else:
        heapq.heappush(a,tmp)
        break
print(sum(a))

Measured memory_bytes: 33752
import sys

sys.setrecursionlimit(200000)

n = int(input())
 
m ={}
def dp(i, a, b, c):
	if (i,a,b,c) in m:
		return m[(i,a,b,c)]
	if i == -1: return 0
	a_v = dp(i-1, a=False, b=True, c=True) + al[i] if a else -1
	b_v = dp(i-1, a=True, b=False, c=True) + bl[i] if b else -1
	c_v = dp(i-1, a=True, b=True, c=False) + cl[i] if c else -1
	m[(i,a,b,c)] = max([a_v, b_v, c_v])
	return max([a_v, b_v, c_v])
 
al = []
bl = []
cl = []
for i in range(n):
	a, b, c = list(map(int, input().split(" ")))
	al.append(a)
	bl.append(b)
	cl.append(c)
    
print(dp(n-1, a=True, b=True, c=True))

Measured memory_bytes: 162620
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(vs) vs.begin(), vs.end()
using ii = pair<int, int>;
using ll = long long;

int32_t main(){
	ios::sync_with_stdio(0);
	int n;
	ll m;
	cin >> n >> m;
	vector<ll> vs(n);
	for(auto &x:vs) cin >> x;
	sort(all(vs));
	vector<ll> acc(n+1);
	acc[0] = 0;
	for(int i=1; i<=n; ++i)
		acc[i] = acc[i-1]+vs[i-1];

	ll l = vs[0]+vs[0], r = vs[n-1]+vs[n-1]+1;
	while(r-l>1){
		ll k =  l + (r-l)/2;
		ll res = 0;
		for(auto x:vs)
			res += ll(vs.end()-lower_bound(all(vs), k-x));
		if(res<m) r = k;
		else l=k;
	}
	ll value = l;
	ll ans = 0;
	ll res = 0;
	for(int i=0; i<n; ++i){
		ll tam = vs.end()-lower_bound(all(vs), value-vs[i]);
		res += tam;
		ans += vs[i]*tam;
		ans += acc[n]-acc[n-tam];
	}
	ans -= (res-m)*value;
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <float.h>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <fstream>
#include <queue>
#include <set>
#include <stdlib.h>
#include <time.h>
#include <list>
#include <stack>
#include <queue>
#include <sstream>

#define For(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  For(i,0,n)

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define SORT(c) sort((c).begin(),(c).end())
#define vi(m,a) vector<int> m(a)
#define vti(m,a,i) vector<vector<int>> m(a,vector<int>(i))
#define ALL(it,a) for(auto it = a.begin(); it!=a.end(); it++)
#define Fe(it,a) for(auto &it : a)
#define all(a) begin(a),end(a)

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define WARU 1000000007;

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

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

	if (str.length() < 4) {
		cout << "No" << endl;
		return 0;
	}

	if (str[0] == 'Y' && str[1] == 'A' && str[2] == 'K' && str[3] == 'I')
		cout << "Yes" << endl;
	else
		cout << "No" << endl;


}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000009
#define N 1000005
using namespace std;
 
typedef long long ll;
typedef pair < int , int > ii;

int n,a[N],top,a1,a2,mn=inf;

int main() 
{

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		top += a[i];
	}

	for (int i = 0; i < n; ++i)
	{
		a1 += a[i];
		a2 = top - a1;
		mn = min(mn,abs(a1 - a2));
	}

	cout << mn;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    string s;
    cin >> s;
    cout << s.substr(0, 4) + ' ' + s.substr(4, 8) << "\n";
}

Measured memory_bytes: 256
//Name: Track and Field Competition
//Level: 1
//Category: やるだけ
//Note: 

/**
 */
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void calc(vector<pair<double,int>> &v) {
    sort(begin(v), end(v));
    cout << v[0].second << ' ' << v[0].first << endl;
    cout << v[1].second << ' ' << v[1].first << endl;
}

bool solve(bool first) {
    vector<pair<double,int>> v(8), rem;
    for(int i = 0; i < 3; ++i) {
        for(int i = 0; i < 8; ++i) {
            cin >> v[i].second >> v[i].first;
        }
        calc(v);
        rem.insert(end(rem), begin(v)+2, end(v));
    }
    calc(rem);
    return false;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(2);

    bool first = true;
    while(solve(first)) {
        first = false;
    }
    return 0;
}

Measured memory_bytes: 1308
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int h,w;
vector<string> s;
bool vi[443][443];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
ll black, white;

bool check(int y, int x)
{
    bool ret = true;
    if (y < 0 || h <= y || x < 0 || w <= x) ret = false;
    return ret;
}

// 0が白、1が黒
void dfs(int y, int x) 
{
    if (vi[y][x]) return;
    vi[y][x] = true;

    if (s[y][x] == '#') black++;
    else white++;
    
    for (int i = 0; i < 4; ++i)
    {
        int ny = y+dy[i];
        int nx = x+dx[i];
        char c = s[y][x];
        if (check(ny,nx))
        {
            char nc = s[ny][nx];
            if (c != nc) dfs(ny, nx);
        }
    }
    return;
}

int main(int argc, char const *argv[]) 
{
    cin >> h >> w;
    s.resize(h);
    REP(i,h) cin >> s[i];

    memset(vi, false, sizeof(vi));
    ll ans = 0ll;
    
    REP(i,h) 
    {
        REP(j,w) 
        {
            if (s[i][j] == '#') 
            {
                black = white = 0ll;
                dfs(i,j);
                ans += black*white;
            }
        }
    }

    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

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

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

    int n = s.size();
    int c = 1;
    int cnt1 = 0;
    rep(i, n)
    {
        if (s[i] != c + '0')
        {
            cnt1++;
        }
        c = 1 - c;
    }
    int cnt0 = 0;
    c = 0;
    rep(i, n)
    {
        if (s[i] != c + '0')
        {
            cnt0++;
        }
        c = 1 - c;
    }
    cout << min(cnt1, cnt0) << '\n';
    return 0;
}


Measured memory_bytes: 3744
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0104
{
    public class Program

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

        public static void Main(string[] args)
        {
            while (true)
            {
                int[] cnts = RIntAr();
                if (cnts.Sum() == 0) break;

                char[,] map = new char[cnts[0], cnts[1]];
                bool[,] visited = new bool[cnts[0], cnts[1]];

                for (int i = 0 ; i < cnts[0] ; i++)
                {
                    string items = RSt();
                    for (int j = 0 ; j < cnts[1] ; j++) map[i, j] = items[j];
                }

                int x = 0;
                int y = 0;
                while (true)
                {
                    if (visited[y, x])
                    {
                        Console.WriteLine("LOOP"); break;
                    }

                    if (map[y, x] == '.')
                    {
                        Console.WriteLine("{0} {1}", x, y); break;
                    }

                    visited[y, x] = true;
                    switch (map[y, x])
                    {
                        case '>': x += dx[0]; y += dy[0]; break;
                        case 'v': x += dx[1]; y += dy[1]; break;
                        case '<': x += dx[2]; y += dy[2]; break;
                        case '^': x += dx[3]; y += dy[3]; break;
                    }
                }
            }
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 16212
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		int n = Integer.parseInt(str);
		str = input.readLine( );
		String[] list = str.split(" ");
		long count = 0;
		for(int i=0; i<n; i++){
			count += Integer.parseInt(list[i])%2;
		}
		if(count%2 == 0){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}

	}
}


Measured memory_bytes: 39508
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <map>
#include <functional>
#include <cstring>
#include <queue>
#include <cmath>
#include <deque>
#include <list>
#include <iomanip>
#include <fstream>
#include <string>
#include <iterator>
#include <set>
#include <bitset>
using namespace std;

typedef long double LD;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const int MAXN = 1007;
const int MOD = 1000000007;
const int INF = 1000000000;
const LL LINF = INF * (LL)INF;
const LD PI = acos(-1.0);

int L[MAXN];

int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("In.txt", "r", stdin);
	//freopen("hear.in", "r", stdin);
	//freopen("hear.out", "w", stdout);
	int n, ans = 0;
	cin >> n;
	REP(i, 2 * n) cin >> L[i];
	sort(L, L + 2 * n);
	REP(i, n) ans += L[2 * i];
	cout << ans;
	return 0;
}

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

int main(){
  int a,b,k;
  cin >> a >> b >>k;
  int cnt=k;
  for(int i=min(a,b);i>=1;i--){
    if(a%i == 0.0 && b%i == 0.0){
      cnt--;
      if(cnt == 0){
        cout << i << endl;
        return  0;
      }
    }
  }
}


Measured memory_bytes: 256