akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <sstream>

#define rep(i, j) FOR(i, 0, j)
#define FOR(i, j, k) for(int i = j; i < k; ++i)

using namespace std;

int main(){
  char n[5];
  while(scanf("%s", n) && strcmp(n, "0000") != 0){
    if(n[0] == n[1] && n[1] == n[2] && n[2] == n[3]){ puts("NA"); continue;}
    int c = 0;
    while(strcmp(n, "6174")){
      rep(i, 4) FOR(j, i + 1, 4){
	if(n[i] > n[j]){ char tmp = n[i]; n[i] = n[j]; n[j] = tmp;}
      }
      int a = atoi(n);
      char tmp = n[0]; n[0] = n[3]; n[3] = tmp;
      tmp = n[1]; n[1] = n[2]; n[2] = tmp;
      int b = atoi(n);
      b -=  a;
      sprintf(n, "%04d", b);
      c++;
    }
    printf("%d\n", c);
  }
  return 0;
}

Measured memory_bytes: 1008
def main():
    N = int(input())
    A = list(map(int, input().split()))

    odd_even = {"odd": 0, "even": 0}

    for num in A:
        if num % 2 == 0:
            odd_even["even"] += 1
        else:
            odd_even["odd"] += 1

    if odd_even["odd"] % 2 == 0:
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    main()


Measured memory_bytes: 19852
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		FastScanner fs = new FastScanner();
		long a = fs.nextLong();
		long b = fs.nextLong();
		long n = fs.nextLong();
		long x = Math.max(n - n % b - 1, 0);
		int temp1 = (int) (Math.floor((double) a * n / b) - a * Math.floor((double) n / b));
		int temp2 = (int) (Math.floor((double) a * x / b) - a * Math.floor((double) x / b));
		System.out.println(Math.max(temp1, temp2));
	}
}

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: 32628
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{

		int A = nextInt();
		int B = nextInt();

		String ans = "Impossible";
		if(A%3==0||B%3==0||(A+B)%3==0)
			ans="Possible";
		System.out.println(ans);

	}

	public static boolean isPalindromicStr(String s) {
		int h = 0;
		int t = s.length() - 1;
		while (h <= t) {
			if (s.charAt(h) != s.charAt(t)) {
				break;
			}
			h++;
			t--;
		}
		if (h > t) {
			return true;
		}
		return false;
	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 22996
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int e;
        cin >> e;
        if (e == 0) return;

        int m = INF;
        for (int y = 0; y * y <= e; ++y) {
            for(int z = 0; z * z * z <= e; ++z){
                int x = e - y * y - z * z * z;
                if(x >= 0 && m > x + y + z) m = x + y + z;
            }
        }
        cout << m << endl;
        solve();
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}



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

int main(void){
	int N;
	int p[100002] = {0};
	cin >> N;
	for(int i = 1; i <= N; ++i){
		cin >> p[i];
	}
	int check[100002] = {0};
	for(int i = 1; i <= N; ++i){
		if(p[i] == i){
			check[i] = 1;
		}
	}
	int ind = 1;
	int cnt = 0;
	while(ind <= N){
		if(check[ind] && check[ind+1]){
			cnt++;
			ind += 2;
		} else if(check[ind] == 1){
			cnt++;
			ind++;
		} else {
			ind++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
	public static void main(String[] args) throws NumberFormatException{
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] values = new int[w];
		for(int i = 0; i < values.length; i++){
			values[i] = i + 1;
		}
		for(int i = 0; i < n; i++){
			String str = sc.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0]) - 1;
			int b = Integer.parseInt(ab[1]) - 1;
			int tmp = values[a]; values[a] = values[b]; values[b] = tmp;
		}
		for(int i = 0; i < values.length; i++)
			System.out.println(values[i]);
	}
}

Measured memory_bytes: 25916
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq

s = "0" + input()
t = "1" + input()

n = len(s)
m = len(t)

dp = [[0]*(m) for i in range(n)]

for i in range(n):
    dp[i][0] = 0
for j in range(m):
    dp[0][j] = 0

for i in range(1,n):
    for j in range(1,m):
        if s[i] == t[j]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])

ans = ""
i = n-1
j = m-1
len = dp[n-1][m-1]

while len > 0:
    if s[i] == t[j]:
        ans += s[i]
        i -= 1
        j -= 1
        len -= 1
    elif dp[i][j-1] == dp[i][j]:
        j -= 1
    else:
        i -= 1

print(ans[::-1])


Measured memory_bytes: 145488
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
const long long mod = 1e9 + 7;
int n, par[N];
vector<int> adjList[N];
long long mem[N][2];
bool vis[N][2];

long long dp(int v, int c) {
	if (vis[v][c]) {
		return mem[v][c];
	}
	vis[v][c] = true;

	long long wans = 1;
	long long bans = c;
	for (int u : adjList[v]) {
		if (u == par[v]) continue;
		par[u] = v;
		wans = (wans * dp(u, 1)) % mod;
		bans = (bans * dp(u, 0)) % mod;
	}

	return mem[v][c] = (wans + bans) % mod;
}

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

	cin >> n;

	int a, b;
	for (int i = 1; i < n; i++) {
		cin >> a >> b;
		adjList[a].emplace_back(b);
		adjList[b].emplace_back(a);
	}

	cout << dp(1, 1) << '\n';

	return 0;
}


Measured memory_bytes: 14848
#include <stdio.h>

int main(){
    int input_N, input_C[20], input_V[20];
    int subXY = 0;

    scanf("%d", &input_N);
    scanf("%d", &input_V[0]);
    for(int count = 1; count < input_N; count++){
        scanf("%d", &input_V[count]);
    }
    
    scanf("%d", &input_C[0]);
    for(int count = 1; count < input_N; count++){
        scanf("%d", &input_C[count]);
    }

    // for(int count = 0; count < input_N; count++){
    //     printf("%d %d\n", input_V[count], input_C[count]);
    // }

    for(int count = 0; count < input_N; count++){
        if( input_V[count] - input_C[count] > 0 ){
            subXY +=  input_V[count] - input_C[count];
        }
    }

    printf("%d", subXY);
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline


def is_prime(N: int):
    if N == 1:
        return False
    i = 2
    while i * i <= N:
        if N % i == 0:
            return False
        i += 1

    return True


def main():
    N = int(input())
    ans = 0
    for _ in range(N):
        n = int(input())
        if is_prime(n):
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()



Measured memory_bytes: 5616
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 55, mod = 1e9 + 7;

int n, k, sum = 0, a[N][N];

struct matrix {
	vector <vector<int>> a;
	matrix(int n, int m) {
		a.assign(n, vector <int> (m));
	}
	matrix operator * (const matrix &b) const {
		int n = a.size(), m = b.a.size(), p = b.a[0].size();
		matrix c(n, p);
		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < p; ++j) {
				for(int k = 0; k < m; ++k) {
					c.a[i][j] = (c.a[i][j] + (a[i][k] * b.a[k][j]) % mod) % mod;
				}
			}
		}
		return c;
	}
};
 
matrix binpow(matrix n, int k) {
	int s = n.a.size();
	matrix ans(s, s);
	for(int i = 0; i < s; ++i) {
		ans.a[i][i] = 1;
	}
	while(k) {
		if(k & 1) ans = ans * n;
		n = n * n;
		k >>= 1;
	}
	return ans;
}

signed main() {
	cin >> n >> k;
	matrix ans(n, n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> ans.a[i][j];
		}
	}
	ans = binpow(ans, k);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			sum = (sum + ans.a[i][j]) % mod;
		}
	}
	cout << sum;
}

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

#define PI 3.1415926535

int main()
{
  long double a, b, x;
  cin >> a >> b >> x;
  long double theta;
  
  if (a * a * b / 2.0 <= x) {
    theta = atan(2.0 * (a * a * b - x) / (a * a * a));
  }
  else {
    theta = PI / 2 - atan(2.0 * x / (a * b * b));
  }
  cout << setprecision(10) << theta * 180 / PI << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define MOD 1000000007
typedef long long ll;
using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    vector<int> r,g,b;
    for(int i=1;i<=n;i++){
        if(s[i-1] == 'R') r.push_back(i);
        else if(s[i-1] == 'G') g.push_back(i);
        else if(s[i-1] == 'B') b.push_back(i);
    }
    ll ans = (ll)((ll)r.size() * (ll)g.size() * (ll)b.size());
    ll sub = 0;

    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            int k = 2*j - i;
            if(k >= n) continue;

            if(s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) sub++;
        }
    }
    ans -= sub;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(ll &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
ll a[4],n,res=6e18;
ll solve(ll n, int S){
	ll res=0;
	if(S>>3&1)res+=n/8*a[3],n%=8;
	if(S>>2&1)res+=n/4*a[2],n%=4;
	if(S>>1&1)res+=n/2*a[1],n%=2;
	if(S>>0&1)res+=n/1*a[0],n%=1;
	return !n?res:(ll)6e18;
}
int main() {
	rep(i,0,3)read(a[i]);read(n);n*=4;
	rep(i,1,15)res=min(res,solve(n,i));cout<<res;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
     
    using namespace std;
     
    int main()
    {
        string s;
        cin>>s;
        int placeA,placeZ;
        for(int i=0;i<s.length();++i)
        {
            if(s[i]=='A')
            {
                 placeA=i;
                 break;
            }
        }
        for(int i=s.length()-1;i>placeA;--i)
        {
            if(s[i]=='Z')
            {
               placeZ=i;
               break;
            }
        }
        cout<<placeZ-placeA+1;
        return 0;
    }

Measured memory_bytes: 832
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#define INF (1e9)
#define N 9
#define M 31
using namespace std;
typedef pair<int,int> P0;
typedef pair<double,P0> P;
void NP(int);
double dijkstra();
int np[N],used[N+1],n,m,p,a,b,ti[N];
double d[M],ans;
vector<P0> edge[M];
 
int main(){
  int x,y,z;
  while(1){
    cin>>n>>m>>p>>a>>b;
    if(!n&&!m&&!p&&!a&&!b) break;
    for(int i=0;i<n;i++) cin>>ti[i];
    a--,b--;
    while(p--){
      cin>>x>>y>>z;
      x--,y--;
      edge[x].push_back(P0(y,z));
      edge[y].push_back(P0(x,z));
    }
    ans=INF;
    NP(0);
    if(ans==INF) cout<<"Impossible"<<endl;
    else cout<<ans<<endl;
    for(int i=0;i<m;i++) edge[i].clear();
  }
  return 0;
}
 
 
void NP(int x){
  if(x==n){
    ans=min(ans,dijkstra());
    return ;
  }
  for(int i=0;i<n;i++){
    if(used[i]) continue;
    used[i]=true;
    np[x]=i;
    NP(x+1);
    used[i]=false;
  }
}


double dijkstra(){
  priority_queue<P,vector<P>,greater<P> > q;
  for(int i=0;i<m;i++) d[i]=INF;
  q.push(P(0,P0(0,a)));

  while(!q.empty()){
    P t=q.top(); q.pop();
    double dis=t.first;
    int idx=t.second.first,pos=t.second.second;
    if(pos==b)return dis;
    if(d[pos]<dis||idx==n)continue;
    for(int i=0;i<edge[pos].size();i++){
      double ndis=dis+(1.0*edge[pos][i].second/ti[np[idx]]);
      int npos=edge[pos][i].first;
      if(d[npos]>ndis) q.push(P(ndis,P0(idx+1,npos))),d[npos]=ndis;
    }
  }
  return INF;
}

Measured memory_bytes: 1288
#include <cstdio>
#include <list>
#include <iostream>
using namespace std;
 
int main(){
	int n,num;
	string s;
	list<int> A;
	cin>>n;
	for(int i = 1 ;i <= n ; i++){
		cin>>s;
		if(s[0]=='i') {
			cin>>num;
			A.push_front(num);
		}
		else if(s[6]=='F') A.pop_front();
		else if(s[6]=='L') A.pop_back();
		else if(s[0]=='d'){
			cin>>num;
			for(list<int>::iterator it=A.begin();it!=A.end();it++){
				if(*it==num) {
					A.erase(it);
					break;
				}
			}
		}
 
	}
	int i =0;
	for(list<int>::iterator it=A.begin();it!=A.end();it++){
		if(i++) cout<<" ";
		cout<<*it;
	}
	cout<<endl;
	return 0;
}




Measured memory_bytes: 34380
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int Maxn=110;
int a[Maxn],b[Maxn];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",&a[i],&b[i]);
	for(int i=1;i+2<=n;i++)
	if(a[i]==b[i]&&a[i+1]==b[i+1]&&a[i+2]==b[i+2])return puts("Yes"),0;
	puts("No");
}


Measured memory_bytes: 3760
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
  int n,k;
  int i,cnt,max;
  vector<int>card,num;
  while(cin>>n>>k,n|k){
    card.resize(k);
    num.clear();

    for(i=0;i<k;i++)cin>>card[i];
    sort(card.begin(),card.end());

    cnt=1;
    for(i=0;i<card.size()-1;i++){
      if(card[0]==0&&i==0)continue;
      if(card[i+1]==card[i]+1){
	cnt++;
      }else{
	num.push_back(cnt);
	if(card[i+1]>card[i]+2)num.push_back(0);
	cnt=1;
      }
    }
    num.push_back(cnt);
    if(card[i]<n)num.push_back(0);

    max=0;
    for(i=0;i<num.size();i++)if(max<num[i])max=num[i];
    if(card[0]==0){
      for(i=0;i<num.size()-1;i++){
	if(num[i]!=0&&num[i+1]==0&&max<num[i]+1)max=num[i]+1;
      }
      for(i=num.size();--i>1;){
	if(num[i]!=0&&num[i-1]==0&&max<num[i]+1)max=num[i]+1;
      }
      for(i=0;i<num.size()-1;i++){
	if(num[i]!=0&&num[i+1]!=0&&max<num[i]+num[i+1]+1)max=num[i]+num[i+1]+1;
      }
    }
    cout<<max<<endl;
  }
}

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


int main(){
    long N,x;
    cin >> N >> x;
    vector<long> a(N);
    for(int i=0;i<N;++i) cin >> a[i];
    long cnt=0;
    for(int i=0;i<N-1;++i){
        if(a[i]+a[i+1]>x){
            cnt += a[i]+a[i+1]-x;
            a[i+1] = max(x-a[i],long(0));
        }
    }
    
    cout << cnt << endl;

    }




Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<string.h>
#include<set>
#define inf 0x3f3f3f3f
using namespace std;
int main()
{
    int n;
    cin>>n;
    int sum=0;
    for(int i=1;i<=n;i++)
        sum+=i;
    printf("%d\n",sum);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n) ; ++i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rng(x) (x).begin(),(x).end()
#define fi first
#define se second
#define emb emplace_back
#define fcout cout << fixed << setprecision(15)

using namespace std;
using ll = long long;
using P = pair<int,int>;

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

int dp[3001][3001];

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

  int ns = s.size();
  int nt = t.size();

  rep(i,ns) rep(j,nt) {
    if(s.at(i)==t.at(j))  dp[i+1][j+1] = dp[i][j] + 1;
    else dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
  }

  int i = ns,j=nt;
  string ans = "";
  while(i+j) {
    if(j && dp[i][j-1] == dp[i][j]) j--;
    else if(i && dp[i-1][j] == dp[i][j]) i--;
    else {
      i--;j--;
      ans += s[i];
    }
  }
  reverse(rng(ans));
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 35456
#include<bits//stdc++.h>
using namespace std;
int main(){
    int a,b,c;cin >>a >>b >>c;
    if(a == max(a,max(b,c))) cout << "A" << endl;
    else if(b > c) cout << "B" <<endl;
    else cout << "C" <<endl;
}


Measured memory_bytes: 3100
H,W=map(int,input().split())
s=[input() for i in range(H)]
yoko=[[0 for i in range(W)] for m in range(H)]
tate=[[0 for i in range(W)] for m in range(H)]

for h in range(H):
    count=0
    for w in range(W):
        if s[h][w]=="#":
            count=0
        else:
            count+=1
        yoko[h][w]=count
    for w in range(W-2,-1,-1):
        if s[h][w]=="." and s[h][w+1]==".":
            yoko[h][w]=yoko[h][w+1]

for w in range(W):
    count=0
    for h in range(H):
        if s[h][w]=="#":
            count=0
        else:
            count+=1
        tate[h][w]=count
    for h in range(H-2,-1,-1):
        if s[h][w]=="." and s[h+1][w]==".":
            tate[h][w]=tate[h+1][w]

lst=[]
for h in range(H):
    for w in range(W):
        lst.append(tate[h][w]+yoko[h][w]-1)
print(max(lst))


Measured memory_bytes: 214188
x = int(input())
quotients = x // 11
rem = x % 11
ans = quotients * 2
if rem > 0:
    if quotients % 2 == 0:
        if rem <= 6:
            ans += 1
        else:
            ans += 2
    else:
        if rem <= 5:
            ans += 1
        else:
            ans += 2
print(ans)

Measured memory_bytes: 3060
fun main(args : Array<String>) {
    val (a, b, m) = readLine()!!.split(" ").map { it.toInt() }
    val aa = readLine()!!.split(" ").map { it.toLong() }
    val bb = readLine()!!.split(" ").map { it.toLong() }

    var min = aa.min()!! + bb.min()!!

    repeat(m) {
        val (ai, bi, c) = readLine()!!.split(" ").map { it.toInt() }
        val sum = aa[ai-1] + bb[bi-1] - c
        min = Math.min(min, sum)
    }

    println(min)
}

Measured memory_bytes: 103288
M, D = map(int, input().split())
count = 0
if D >= 22:
  for i in range(22, D + 1):
    j = str(i)
    if int(j[1]) >= 2:
      m = int(j[0]) * int(j[1])
      if m <= M:
        count += 1
print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>

using namespace std;

int main() {
	long long int x;
	cin >> x;
	long long int currtime = 0;
	long long int maxpos = 0;
	while(maxpos < x) {
		currtime++;
		maxpos += currtime;
	}
	cout << currtime << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int n, m, a[30][30], i, k[30], j, cnt[30]={0}, ans=0, h; 

    scanf("%d%d", &n, &m);

    for(i=0;i<n;i++){
        scanf("%d", &k[i]);
        for(j=0;j<k[i];j++){
            scanf("%d", &a[i][j]);
        }
    }

    for(i=0;i<n;i++){
        for(j=0;j<k[i];j++){
            h=a[i][j]-1;
            cnt[h]++;
        }
    }

    for(i=0;i<=m;i++){
        if(cnt[i]==n) ans++;
    }

    printf("%d\n", ans);
    
    return 0;
}


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

int main() {
  int N,K,D[10];
  cin>>N>>K;
  for (int i(0);i<K;i++) cin>>D[i];
  for (int i(N);i<1000000;i++){
    string si=to_string(i);
    bool is_match(false);
    for (int i(0);i<si.size();i++){
      for (int d(0);d<K;d++){
        //cout <<D[d]<<" "<<(int)si[i]-48<<endl;
        if (D[d]==(int)si[i]-48){
          is_match=true;
          break;
        }
      }
    }
    if (is_match==false){
      cout<< i;
      return 0;
    }
  }
}


Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        int n = int.Parse(Console.ReadLine());
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        for (int k = 0; k < a.Length; k ++) {
                if (k==a.Length-1) Console.WriteLine(a[k]);
                else Console.Write(a[k]+" ");
            }
        for (int i = 1; i < n; i ++) {
            int v = a[i];
            int j = i-1;
            while(j>=0 && a[j]>v) {
                a[j+1]=a[j];
                j--;
            }
            a[j+1] = v;
            for (int k = 0; k < a.Length; k ++) {
                if (k==a.Length-1) Console.WriteLine(a[k]);
                else Console.Write(a[k]+" ");
            }
        }
    }
}


Measured memory_bytes: 18240
#include <cstdio>
using namespace std;
int main(){
  int y,m,d;
  scanf("%d/%d/%d",&y,&m,&d);
  if(y<2019 || (y==2019 && m<4) || (y==2019 && m==4 && d <= 30))printf("Heisei\n");
     else printf("TBD");     
} 


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

int main() {
  int N;
  cin >> N;
  
  long long a = 2;
  long long b = 1;

  if (N == 1) {
    cout << 1 << endl;
  }
  else {
    for (int i = 0; i < (N - 1); i++) {
      b += a;
      a = b - a;
    }
  }
  if (!(N == 1))
  	cout << b << endl;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
int main(void) {
    int ta=0,ha=0,num,i;
    char strta[101],strha[101];
    scanf("%d\n",&num);
    for (i=0; i<num; i++) {
        scanf("%s %s\n",strta,strha);
        if (strcmp(strta,strha)>0) {
            ta+=3;
        } else if (strcmp(strta,strha)<0) {
            ha+=3;
        } else {
            ta++;
            ha++;
        }
    }
    printf("%d %d\n",ta,ha);
    return 0;
}


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

vector<vector<int>> r;
vector<int> cnt;

void search(int i, int p) {
    rep(j,r[i].size()) {
        if(r[i][j] != p) {
            cnt[r[i][j]] += cnt[i];
            search(r[i][j],i);
        }
    }
}

int main() {
    int n, q;
    cin >> n >> q;
    
    r.resize(n+1);
    cnt.resize(n+1);
    
    rep(i,n-1) {
        int a, b;
        cin >> a >> b;
        
        r[a].push_back(b);
        r[b].push_back(a);
    }
    
    rep(i,q) {
        int p, x;
        cin >> p >> x;
        
        cnt[p] += x;
    }
    
    search(1,0);
    
    for(int i = 1; i <= n; i++)
        cout << cnt[i] << endl;
    
    
    return 0;
}


Measured memory_bytes: 27496
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//void p(vector<int> A){rep(i,A.size()){cout << A[i] << " ";}cout << "\n";}

int main(){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    if(s.size() % 2 == 1){
        cout << "No";
        exit(0);
    }
    rep(i,s.size()){
        char t;
        if(i%2 == 0)t = s[i];
        else{
            if(t != s[i]){
                cout << "No";
                exit(0);
            }
            else{
                t = '111';
            }
        }
    }
    cout << "Yes";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[3001][3001][2];
ll a[3001];
ll solve(ll* a,ll i,ll j,bool turn)
{
	if(i>j)
		return 0;
	if(dp[i][j][turn]!=-1)
	{
		return dp[i][j][turn];
	}
	if(turn==1)
	{
		return dp[i][j][turn]=max(a[i]+solve(a,i+1,j,0),a[j]+solve(a,i,j-1,0));
	}
	else
		return dp[i][j][turn]=min(solve(a,i+1,j,1),solve(a,i,j-1,1));
}
int main()
{
	ll n;
	cin>>n;
	ll sum=0;
	for(ll p=1;p<=n;p++)
	{
		cin>>a[p];
		sum+=a[p];
	}
	memset(dp,-1,sizeof(dp));
	ll ScoreX = solve(a,1,n,1);
	ll ScoreY = sum- ScoreX;
	cout<<ScoreX-ScoreY<<endl;
}


Measured memory_bytes: 144620
package main

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

func main() {
	run()
}

func run() {
	setSpace()
	h, n := readN(), readN()
	for i := 0; i < n; i++ {
		h = h - readN()
		if h <= 0 {
			break
		}
	}
	if h <= 0 {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
	return
}

// ------以下、ユーティリティ------

var sc = bufio.NewScanner(os.Stdin)

func setSpace() {
	sc.Split(bufio.ScanWords)
}

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

func readN() int {
	n, err := strconv.Atoi(read())
	if err != nil {
		panic(err)
	}
	return n
}


Measured memory_bytes: 1152
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner scan = new Scanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		Player[][] ppl = new Player[3][8];
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 8 ; j++) {
				ppl[i][j] = new Player(si(),Double.parseDouble(scan.next()));
			}
			Arrays.sort(ppl[i]);
			for (int j = 0; j < 2 ; j++)
				out.println(ppl[i][j].id+" "+String.format("%.2f", ppl[i][j].rec));
		}

		Player[] ppl2 = new Player[18];
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 6; j++) {
				ppl2[i*6+j] = ppl[i][j+2];
			}
		}
		Arrays.sort(ppl2);
		for (int j = 0; j < 2 ; j++)
			out.println(ppl2[j].id+" "+String.format("%.2f",ppl2[j].rec));
		out.flush();
	}

	static int si() {
		return Integer.parseInt(scan.next());
	}
}

class Player implements Comparable<Object> {
	int id;
	double rec;
	Player(int p,double q){
		id=p;rec=q;
	}
	@Override
	public int compareTo(Object o) {
		return (int)((this.rec-((Player)o).rec)*100);
	}

}

Measured memory_bytes: 17348
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second > b.second;
    }
}

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

bool pairCompareS(const P& firstElof, const P& secondElof)
{
    return firstElof.second < secondElof.second;
}

int main()
{
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    rep(i, N) { 
        cin >> A[i];
    }
    vector<ll> B(N);
    B[0] = A[0];
    rep(i, N-1) {
        B[i+1] = B[i] + A[i+1];
    }
    map<ll, ll> m;
    rep(i, N) {
        m[B[i] % M]++;
    }
    m[0]++;
    ll ret = 0;
    for(P p : m) {
        ret += p.second * (p.second-1) / 2;
    }
    print(ret);
    return 0;
}

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

int main(){
	int n;
	vector<long long> A;
	long long temp;
	
	cin >> n;
	
	for(int i=1;i<=n;i++){
		cin >> temp;
		temp += -i;
		A.push_back(temp);
	}
	sort(A.begin(),A.end());
	
	long long b = A[n/2];
	long long ans = 0;
	for(int i=0;i<n;i++){
		ans += abs(A[i]-b);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int N;
    cin >> N;
    int a[300000] = {};
    for(int i=0;i<3*N;i++){
        cin >> a[i];
    }
    sort(a,a+3*N,greater<int>());
    long long ans = 0;
    for(int i=1;i<2*N;i=i+2){
        ans = ans + a[i];
    }
    
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1408
using System;
using System.Collections;


namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {

            int count = int.Parse(Console.ReadLine());
            bool[] S = new bool[13];
            bool[] H = new bool[13];
            bool[] C = new bool[13];
            bool[] D = new bool[13];




            for(int i=0; i<count; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                switch (input[0])
                {
                    case "S":
                        S[int.Parse(input[1])-1] = true;
                        break;

                    case "H":
                        H[int.Parse(input[1])-1] = true;
                        break;

                    case "C":
                        C[int.Parse(input[1])-1] = true;
                        break;

                    case "D":
                        D[int.Parse(input[1])-1] = true;
                        break;
                }
            }

            for(int i = 0; i < 13; i++)
            {
                if(S[i] == false)
                {
                    Console.WriteLine("S {0}", i+1);
                }
            }

            for (int i = 0; i < 13; i++)
            {
                if (H[i] == false)
                {
                    Console.WriteLine("H {0}" , i+1);
                }
            }

            for (int i = 0; i < 13; i++)
            {
                if (C[i] == false)
                {
                    Console.WriteLine("C {0}" , i+1);
                }
            }

            for (int i = 0; i < 13; i++)
            {
                if (D[i] == false)
                {
                    Console.WriteLine("D {0}" , i+1);
                }
            }

        }
    }
}

Measured memory_bytes: 9160
#include <stdio.h>
int main(){
  int n,q,S[100000],T[1000],i,j,count=0,a[10000],k,right,left,middle;
  scanf("%d",&n);
  for(i=0;i<n;i++)
	scanf("%d",&S[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++){
	scanf("%d",&T[i]);
	right=n;
	left=0;
	middle=n/2;
	while(right!=left){
	  if(T[i]>S[middle]){//T４行目S２行目
		left=middle+1;
		middle=(left+right)/2;
		continue;
	  }else if(T[i]<S[middle]){
		right=middle;
		middle=(right+left)/2;
		continue;
	  }else{//T[i]=S[middle]
		count++;
		break;
	  }
	  
	}
  }
  printf("%d\n",count);
  return 0;
}

  




Measured memory_bytes: 2124
#include<iostream>
#include<array>
#include<vector>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <tuple>
#include<cmath>

using llint = long long int;
using namespace std;

namespace CsF {
#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define FOR(I,J,K) for(int I = J;I < K;I++)
#define WriteLine(n) cout << n << "\n"; 

	string ConvertBit(int N, int e) {
		string s = "";
		int r = 0;
		while (N != 0) {
			r = N % e;
			s = to_string(r) + s;
			N -= r;
			N /= e;
		}
		return s;
	}

	int GCD(int a, int b) {
		if (a < b)swap(a, b);
		int r = a % b;
		while (r != 0) {
			a = b;
			b = r;
			r = a % b;
		}
		return b;
	}

	int LCM(int a, int b) {
		int n = a * b;
		return (n / GCD(a, b));
	}

	int Count(string s, char c) {
		int cou = 0;
		FOR(i, s.length(), 1) {
			if (s[i] == c)cou++;
		}
		return cou;
	}

	vector<int> SieveOfEratosthenes(int N) {
		vector<bool> memo(N + 1);
		vector<int> ret;
		memo[0] = true;
		memo[1] = true;
		for (int i = 2; i < N; i++) {
			if (memo[i])continue;
			ret.push_back(i);
			for (int b = 2; true; b++) {
				if (i*b <= N) {
					memo[i*b] = true;
				}
				else break;
			}
		}
		return ret;
	}

	vector<int> SpInput(int N) {
		vector<int> ret(N);
		FOR(i, N, 1) { cin >> ret[i]; }
		return ret;
	}
}

using namespace CsF;

int N, Ma, Mb;
struct Chemicals {
	int a, b, c;
};
Chemicals chem[41];
int dp[44][500][500];
int inf = 1000000000;
// i : 見てる場所
// j : aの薬品量
// k : bの薬品量

int main() {
	cin >> N >> Ma >> Mb;
	for (int i = 0; i < N; i++) {
		cin >> chem[i].a >> chem[i].b >> chem[i].c;
	}
	for (int i = 0; i < N + 1; i++)
		for (int j = 0; j < 450; j++)
			for (int k = 0; k < 450; k++)dp[i][j][k] = inf;
	dp[0][0][0] = 0;
	for (int i = 0; i < N; i++)
		for (int j = 0; j <= 400; j++)
			for (int k = 0; k <= 400; k++) {
				if (dp[i][j][k] == inf)continue;
				//最小コストを求めるため毎度書き換える
				//買う場合 : 前状態 + c[i] と 既状態 の min
				dp[i + 1][j + chem[i].a][k + chem[i].b] = min(dp[i][j][k] + chem[i].c, dp[i + 1][j + chem[i].a][k + chem[i].b]);
				//買わない場合
				dp[i + 1][j][k] = min(dp[i][j][k], dp[i + 1][j][k]);
			}

	int ans = inf;
	for (int x = 1; x*Ma < 450 && x*Mb < 450; x++) {
		ans = min(ans, dp[N][x*Ma][x*Mb]);
	}
	cout << (ans == inf ? -1 : ans) << endl;
	return 0;
}



Measured memory_bytes: 40960
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>

using namespace std;

int main(){
  string s;
  cin >> s;
  int A = 0;
  int Z = 0;

  for (int i = 0; i < s.size(); i++){
    if(s[i] == 'A'){
      A = i;
      break;
    }
  }

  for (int i = s.size(); i > 0; i--){
    if(s[i] == 'Z'){
      Z = i;
      break;
    }
  }

  cout << Z-A+1 << endl;

  return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <algorithm>

using namespace std;

string s1, s2;

int main()
{
	cin >> s1 >> s2;
	sort(s1.begin(), s1.end()), sort(s2.begin(), s2.end(), greater<char>());
	cout << ((s1 < s2) ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<utility>
#include<cmath>
using namespace std;

int main(void)
{
	int L;
	cin >> L;

	int cntNode = 0;
	int cntEdge = 0;
	for(int i=1; i*2<=L; i*=2)
		cntNode++;
	cntNode++;

	vector<vector<pair<int, int>>> graph(cntNode, vector<pair<int, int>>());
	for(int i=0; i<cntNode-1; i++){
		graph[i].push_back(make_pair(i+1, 0));
		graph[i].push_back(make_pair(i+1, pow(2, i)));

		cntEdge += 2;
	}

	for(int i=cntNode; i>=0; i--){
		int left = L - pow(2, i);
		int right = int(pow(2, cntNode-1));
		if(left < right)
			continue;

		graph[i].push_back(make_pair(cntNode-1, left));
		L -= pow(2, i);
		cntEdge++;
	}

	cout << cntNode << " " << cntEdge << endl;
	for(int i=0; i<cntNode; i++){
		for(int j=0; j<graph[i].size(); j++){
			int n = graph[i][j].first;
			int w = graph[i][j].second;
			cout << i+1 << " " << n+1 << " " << w << endl;
		}
	}


	return 0;
}


Measured memory_bytes: 256
/// wa ^3^

#pragma GCC optimize("O3")

#include<bits/stdc++.h>
                           
using namespace std;

const int MOD = 1e9 + 7;

const int N = 2e5+10;

int cnt[N];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    int dp = -1;
    vector<int> a;
    for (int x; n--;) {
        cin >> x;
        if (x != dp)
            a.push_back(x);
        dp = x;            
    }
    dp = 1;
    for (int x : a) {
        cnt[x] += dp;
        if (cnt[x] >= MOD)
            cnt[x] -= MOD;
        dp = cnt[x];    
    }
    cout << dp;
    return 0;
}



Measured memory_bytes: 1908
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long int64;
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

int main() {
    int N, K, R, S, P;
    cin >> N >> K >> R >> S >> P;
    int score[3] = {R, S, P};
    string H = "rsp";
    string T; cin >> T;
    vector<string> str(K + 10);
    rep(i, N) {
        str[i % K] += T[i];
    }
    auto f = [&](const string &s) -> int {
        int N = s.size();
        vector<vector<int>> dp(N + 1, vector<int>(3));
        rep(i, N) rep(pre, 3) rep(hand, 3) {
            if(pre == hand) continue;
            int nscore = s[i] == H[(hand + 1) % 3] ? score[hand] : 0;
            chmax(dp[i + 1][hand], dp[i][pre] + nscore);
        }
        int ans = 0;
        rep(i, 3) ans = max(ans, dp[N][i]);
        return ans;
    };
    int ans = 0;
    for(auto &s : str) {
        ans += f(s);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
 
int main() {
  int a, b,c;
  cin >> a >> b>>c;
  if((a+b)>=c)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // ver1.8
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
#define PAI 3.14159265358979
using namespace std;

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

signed main() {
  cout << fixed << setprecision(14);
  string s;
  cin >> s;
  rep(i,0,4) cout << s[i];
  cout << ' ';
  rep(i,4,12) cout << s[i];
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

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

int main() {
	int N,T;
	cin>>N>>T;
	vector<int> t(N);
	rep(i,N)cin>>t[i];
	int ans = T;
	rep(i,N-1){
		if(t[i]+T>=t[i+1]){
			ans+=t[i+1]-t[i];
		}
		else{
			ans+=T;
		}
	}
	cout<<ans<<endl;
}

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

using namespace std;

int main() {
	// your code goes here
	
	int n;
	cin>>n;

	long long a[n];
	long long ans[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	
	ans[0]=0;
	
	for(int i=0;i<n;i++){
		if(i%2==0)
			ans[0]+=a[i];
		else
			ans[0]-=a[i];
	}

	for(int i=n-1;i>0;i--){
		ans[i] = 2*a[i] - ans[(i+1)%n];
	}

	for(int i=0;i<n;i++)
		cout<<ans[i]<<" ";
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    int n;
    cin>>n;
    cout<<800*n-200*(n/15)<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

Measured memory_bytes: 3572
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

//#define debug(x) ;
#define debug(x) cerr << #x << " = " << x << "\n";

ostream& operator<<(ostream& cerr, vector<ll> aux) {
  cerr << "[";
  for (auto e : aux) cerr << e << ' ';
  cerr << "]";
  return cerr;
}

const int maxN = 103;
const int inf = 100000000;

int n, m;
char s[maxN][maxN];
int dp[maxN][maxN];

int diff(char b, char a) {
  if (a == '.' && b == '#') return 1;
  return 0;
}

int main()
{
  //freopen("test.in", "r", stdin);

  scanf("%d%d\n", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s\n", s[i]); 
    for (int j = 0; j < m; j++) {
      dp[i][j] = inf;
    }
  }

  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (i > 0) 
        dp[i][j] = min(dp[i][j], 
                       dp[i - 1][j] + diff(s[i][j], s[i - 1][j]));
      if (j > 0)
        dp[i][j] = min(dp[i][j], 
                       dp[i][j - 1] + diff(s[i][j], s[i][j - 1])); 

      //cerr << i << ' ' << j << ' ' << dp[i][j] << '\n';
    }
  }

  if (s[0][0] == '#')
    printf("%d\n", dp[n - 1][m - 1] + 1);
  else
    printf("%d\n", dp[n - 1][m - 1]);

  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int ans = 0;
  rep(i,n) {
    if(a[a[i] - 1] == i+1) ans++;
  }
  cout << ans/2 << endl;
}

Measured memory_bytes: 640
n=int(input())
a=list(map(int,input().split()))
four=0
two=0

for i in range(n):
  if a[i]%4==0:
    four+=1
  elif a[i]%2==0:
    two+=1
one=n-two-four
if one>=four+2 or\
one==four+1 and two>=1:
  print("No")
else:       
  print("Yes")
  

Measured memory_bytes: 14352
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] counts = new int[8];
		int over = 0;
		for (int i = 0; i < n; i++) {
		    int x = sc.nextInt();
		    int idx = x / 400;
		    if (idx >= 8) {
		        over++;
		    } else {
		        counts[idx]++;
		    }
		}
		int types = 0;
		for (int i = 0; i < counts.length; i++) {
		    if (counts[i] != 0) {
		        types++;
		    }
		}
		int max = types + over;
		int min = Math.max(types, 1);
		System.out.println(min + " " + max);
	}
}


Measured memory_bytes: 21588
m,d=map(int,input().split())
ans=0
for i in range(1,m+1):
  for j in range(1,d+1):
    d10=j//10
    d1=j-d10*10
    if d1>=2 and d10>=2 and i==d1*d10:
      ans+=1
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
	int n; cin >>n;
	vector<long long>a(n);
	cinf(n,a);
	int cnt=0;
	for(int i=0;i<n;i++){
		while(a[i]%2==0){
			cnt++;
			a[i]/=2;
		}
	}
	cout << cnt << endl;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799;

string s;
int ans = 0;

int main(){
  int n;
  cin >> n;
  cin >> s;
  for(int i = 0; i < s.size() - 2; i++){
    string u = s.substr(i, 3);
    if(u == "ABC") ans++;
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int maxn = 1000000+7;

int main() {

#ifdef HotWhite
    freopen("in.txt", "r", stdin);
#endif // HotWhite
    int H, h, m, s;
    while (scanf("%d%d%d%d", &H, &h, &m, &s), H || h || m || s) {
        int hh = 3600*h + 60*m + s;
        int mm = 60*m*H + s*H;
        int ss = 60*s*H;
        int K = 3600*H;
        int fz = hh + mm - 2*ss;
        fz = (fz%K + K)%K;
        int fm = 119*H - 1;
        while (1) {
            int fzz = fz;
            int fmm = fm;
            int tem = __gcd(fzz, fmm);
            fzz /= tem;
            fmm /= tem;
            int h2 = (h+(m+(fzz+s*fmm)/(60*fmm))/60) % H;
            int m2 = (m+(fzz+s*fmm)/(60*fmm)) % 60;
            int s2 = (fzz+s*fmm) % (fmm*60);
            if ((h2*3600+m2*60)*fmm+s2 != 0) {
                printf("%d %d %d %d\n", h2, m2, s2, fmm);
                break;
            }
            fz += K;
        }
    }
    return 0;
}

Measured memory_bytes: 1028