akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

char ans[20];

void bfs(int num,int ed){
	debug(ans);
	if(num==1) return;
	
	int i;
	bool flag=false;
	for(i=ed;i>=0;--i){
		if(i==0){
			if(ans[i]<'9') ans[i]++;
			else flag=true;
			break;
		}else if(ans[i]-ans[i-1]<1 and ans[i]<'9'){
			ans[i]++;
			break;
		}
	}
	
	if(flag){
		ans[0]='1';
		for(int j=1;j<=ed+1;++j) ans[j]='0';
		bfs(num-1,ed+1);
		return;
	}
	
	for(int j=i+1;j<=ed;++j){
		if(ans[j-1]>'0') ans[j]=ans[j-1]-1;
		else ans[j]='0';
	}
	bfs(num-1,ed);
}

int main(){
	int k;
	cin>>k;
	
	ans[0]='1';
	bfs(k,0);
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
int main()
{
    string a,b,c;
    cin>>a>>b>>c;
    if(a[a.size()-1]==b[0])
    {
       if(b[b.size()-1]==c[0])
         cout<<"YES";
       else
         cout<<"NO";
    }
    else
      cout<<"NO";
    cout<<nl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

int main( int argc, char *argv[] ) {
	string s;
	int best = 1E4;

	cin >> s;
	for ( int i = 0 ; i < s.length() - 2 ; i++ ){
		best = min(best, abs(753-atoi(s.substr(i,3).c_str())));
	}

	cout << best << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>

#define loop(x) for(int x=1;x<=6;x++)

using namespace std;

void change(int[10][10],int,int,int);
int count(int[10][10],int,int);

int main(void){
	for(int h,w,c;cin >> h >> w >> c,h||w||c;){
		int fld[10][10]={0};
		int max=0,tmp;

		for(int i=1;i<=h;i++)
			for(int j=1;j<=w;j++)
				cin >> fld[i][j];

		loop(i){
			int cpy1[10][10];
			memcpy(cpy1,fld,sizeof(fld));
			change(cpy1,1,1,i);
			loop(j){
				int cpy2[10][10];
				memcpy(cpy2,cpy1,sizeof(cpy1));
				change(cpy2,1,1,j);
				loop(k){
					int cpy3[10][10];
					memcpy(cpy3,cpy2,sizeof(cpy2));
					change(cpy3,1,1,k);
					loop(l){
						int cpy4[10][10];
						memcpy(cpy4,cpy3,sizeof(cpy3));
						change(cpy4,1,1,l);
						change(cpy4,1,1,c);
						tmp=count(cpy4,1,1);
						max=max>tmp?max:tmp;
					}
				}
			}

		}
		cout << max << endl;
	}

	return 0;
}

void change(int fld[10][10],int x,int y,int col){
	int cul=fld[x][y];

	if(cul!=col){
		fld[x][y]=col;
		if(fld[x+1][y]==cul)
			change(fld,x+1,y,col);
		if(fld[x-1][y]==cul)
			change(fld,x-1,y,col);
		if(fld[x][y+1]==cul)
			change(fld,x,y+1,col);
		if(fld[x][y-1]==cul)
			change(fld,x,y-1,col);
	}
}

int count(int fld[10][10],int x,int y){
	int c=1,cul=fld[x][y];

	fld[x][y]=-1;
	if(fld[x+1][y]==cul)
		c+=count(fld,x+1,y);
	if(fld[x-1][y]==cul)
		c+=count(fld,x-1,y);
	if(fld[x][y+1]==cul)
		c+=count(fld,x,y+1);
	if(fld[x][y-1]==cul)
		c+=count(fld,x,y-1);

	return c;
}

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

int main()
{
    int N;
    std::cin >> N;

    std::vector<int> a(N);
    for (int i = 0; i < N; i++) {
        std::cin >> a[i];
    }

    std::sort(std::begin(a), std::end(a), std::greater<int>());

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

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

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

bool p[10000002];

int main (){

  for(int i=0;i<=10000000;i++) p[i] = true;
  p[0] = false;
  p[1] = false;
  for(int i=2;i*i<=10000000;i++){
    if(p[i]){
      for(int j=2;j*i<=10000000;j++){
	p[i*j] = false;
      }
    }
  }

  while(1){
    int n;
    cin >> n;
    if(n==0) break;
    for (int i=n;i>=13;i--){
      if(p[i] && p[i-2] && p[i-6] && p[i-8]){
	cout << i << endl;
	break;
      }
    }
  }
  return 0;
}

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

 
int main() {
  int A, B, C;
  string op;
  cin >> A >> B;
  if (A % 2 == 1 && B % 2 == 1){
  	cout << "Odd" << endl;
  }
  else {
  	cout << "Even" << endl;
  }

}

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

#define R register
#define ll long long
#define sum(a, b, mod) (((a) + (b)) % mod)

const int MaxN = 1e4 + 10;
const int inf = 0x3f3f3f3f;

struct edge
{
    int next, to;
};

char s[MaxN];
edge e[MaxN];
int n, ans, cnt;
int a[MaxN], head[MaxN], dis[MaxN], size[MaxN], f[MaxN];

void init()
{
    for (int i = 1; i <= n; i++)
        dis[i] = size[i] = f[i] = 0;
}

void add_edge(int u, int v)
{
    ++cnt;
    e[cnt].to = v;
    e[cnt].next = head[u];
    head[u] = cnt;
}

inline int read()
{
    int x = 0;
    char ch = getchar();
    while (ch > '9' || ch < '0')
        ch = getchar();
    while (ch <= '9' && ch >= '0')
        x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    return x;
}

void dfs(int u, int fa)
{
    size[u] = a[u];
    int maxp = 0;
    for (int i = head[u]; i; i = e[i].next)
    {
        int v = e[i].to;
        if (v == fa) continue;
        dfs(v, u), size[u] += size[v], dis[v] += size[v];
        dis[u] += dis[v], maxp = ((dis[maxp] > dis[v]) ? maxp : v);
    }    
    if(!maxp) return (void) (f[u] = 0);
    if(dis[u] >= 2 * (dis[maxp])) f[u] = (dis[u] / 2);
    else f[u] = dis[u] - dis[maxp] + std::min(f[maxp], (2 * dis[maxp] - dis[u]) / 2);
}

int main()
{
    ans = inf;
    n = read(), scanf("%s", s + 1);
    for (int i = 1; i <= n; i++)
        a[i] = s[i] - '0';
    for (int i = 1; i < n; i++)
    {
        int u = read(), v = read();
        add_edge(u, v), add_edge(v, u);
    }
    for (int i = 1; i <= n; i++)
    {
        init(), dfs(i, 0);
        if(dis[i] & 1) continue;
        if (f[i] * 2 >= dis[i]) ans = std::min(ans, dis[i] / 2);
    }
    printf("%d\n", (ans == inf) ? -1 : ans);
    return 0;
}


Measured memory_bytes: 512
//import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Set;
import java.util.HashSet;

public class Main {
    static int[][] map;
    static boolean[][] visited;
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        int ans = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '+') ans++;
            else ans--;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21204
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
using namespace std;
#define ll long long

int main() {
	int N; cin >> N;
	vector<pair<pair<string, int>, int>> v(N);
	for(int i=1; i<=N; ++i){
	    string s;
	    int p;
	    cin >> s >> p;
	    v[i-1]=make_pair(make_pair(s, 100-p), i);
	}
	sort(v.begin(), v.end());
	for(int i=0; i<N; ++i){
	    cout << v[i].second << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cassert>
#include <iomanip>
#include <chrono>

using namespace std;

class

CRally {
public:

    void solve(std::istream &in, std::ostream &out) {
        int N;
        in >> N;

        vector<int> X;
        for( int n = 0; n < N; n++ )
        {
            int tmp;
            in >> tmp;
            X.push_back(tmp);
        }

        int answer = 99999999;
        int meeting_point = 0;
        for( int x = 1; x <= 100; x++ )
        {
            int sum = 0;
            for( auto i : X )
            {
                sum += ( i - x ) * ( i - x );
            }

            if( sum < answer )
            {
                answer = sum;
                meeting_point = x;
            }
        }

        out << answer << endl;
    }
};


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

    vector<int> X;
    for( int n = 0; n < N; n++ )
    {
        int tmp;
        cin >> tmp;
        X.push_back(tmp);
    }

    int answer = 99999999;
    int meeting_point = 0;
    for( int x = 1; x <= 100; x++ )
    {
        int sum = 0;
        for( auto i : X )
        {
            sum += ( i - x ) * ( i - x );
        }

        if( sum < answer )
        {
            answer = sum;
            meeting_point = x;
        }
    }

    cout << answer << endl;
}

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

int main(){
    ll a, b, x;
    cin >> a >> b >> x;
    ll ans;
    if(a%x==0) ans = b/x - a/x + 1;
    else ans = b/x - a/x;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,c,i;
	char s[101];

	scanf("%d",&n);
	for (i=0;i<n;i++)
		scanf("%s",s);

	if(n%2==1)
	       	printf("No");
        else{
             c=0;
        for(i=0;i<n/2;i++)
                if(s[i]==s[i+(n/2)]) 
			c++;
 
        if(c==n/2) 
		printf("Yes");
        else  printf("No");
        }
        return 0;
}


Measured memory_bytes: 256
N,M,C= map(int,input().split())
B = list(map(int,input().split()))
ans = 0

for i in range(N):
    a = list(map(int,input().split()))
    s= C
    for j in range(M):
        s += a[j] * B[j]
    if s > 0:
        ans += 1

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int saidaikouyakusuu(int a,int b){
    if(b==0) return a;
    return saidaikouyakusuu(b,a%b);
}
int saisyoukoubaisuu(int a,int b){
    return a*b/saidaikouyakusuu(a,b);
}
int n,m,cnt=0,aa[220000],ans=0;
pair<int,int> pp[220000];
string s,sa[220000];
char c;
queue<int> que;
signed main(){
    cin>>n;
    rep(i,n){
        cin>>sa[i];
        if(sa[i]=="AC"){
            aa[0]++;
        }elif(sa[i]=="WA"){
            aa[1]++;
        }elif(sa[i]=="TLE"){
            aa[2]++;
        }else{
            aa[3]++;
        }
    }
    cout<<"AC x "<<aa[0]<<endl;
    cout<<"WA x "<<aa[1]<<endl;
    cout<<"TLE x "<<aa[2]<<endl;
    cout<<"RE x "<<aa[3]<<endl;
}

Measured memory_bytes: 10524
#include <cstdio>
#include <cstring>
char s[20];
int main()
{
	scanf("%s",s);
	if(strlen(s)<4) {printf("No\n");return 0;}
	printf("%s\n",s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I'?"Yes":"No");
	return 0;
}

Measured memory_bytes: 128
import Data.List
import Control.Monad

day :: [String]
day = ["SUN", "MON", "TUE", "WED", "WED", "THU", "FRI", "SAT"]

main = print =<< ((pure (\n -> div (n * (n + 1)) 2)) <*> getInt)

getInt :: IO Int 
getInt = (pure read) <*> getLine


Measured memory_bytes: 508
import math
N, D, A = map(int, input().split())

M = []
for i in range(N):
    X, H = map(int, input().split())
    M.append((X, H))
M.sort(key=lambda x: x[0])

d = []
i = 0

ans = 0
B = 0
for X, H in M:
    while i != len(d) and X > d[i][0]:
        B -= d[i][1]
        i += 1
    if H > B:
        t = math.ceil((H-B)/A)
        ans += t
        B += t*A
        d.append((X+2*D, t*A))


print(ans)


Measured memory_bytes: 101964
from sys import stdin

S = stdin.readline().rstrip()
N = len(S)
ans = [0 for _ in range(N)]
odd_L = 0
odd_R = 0
even_L = 0
even_R = 0

for i in range(N-1):
    if S[i]=="R" and S[i+1]=="L":
        j = k = 1
        while i-j >= 0 and S[i-j]=="R":
            if j%2==0:
                even_R += 1
            else:
                odd_R += 1
            j += 1
        while i+k+1 <= N-1 and S[i+k+1]=="L":
            if k%2==0:
                even_L += 1
            else:
                odd_L += 1
            k += 1
        ans[i] = even_R + odd_L + 1
        ans[i+1] = odd_R + even_L + 1
        odd_L = odd_R = even_L = even_R = 0

print(*ans)

Measured memory_bytes: 6408
/*input
4 4
1 4
4 1
.##.
####
####
.##.
*/
 
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <climits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdint.h>
#include <tgmath.h>
 
using namespace std;
 
/*******  All Required define Pre-Processors and typedef Constants *******/
#define ar array
#define scd(t) scanf("%d",&t)
#define scld(t) scanf("%ld",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define tests int r; cin >> r; while(r--)
#define MP make_pair
#define PI acos(-1)
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
#define godspeed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
 
#define M(x) ((x)%(1000000007))
 

int arr[1010][1010];

int h;
int w;



bool legal(int x, int y){
	if(x>=1&&x<=h){
		if(y>=1&&y<=w){
			if(arr[x][y]){
				return true;

			}
		}
	}
	return false;
}


int main() {
 	godspeed;
 	int a;
 	int b;
 	int a1;
 	int b1;
 	cin>>h>>w>>a>>b>>a1>>b1;
 	rep(i,1010){
 		rep(j,1010){
 			arr[i][j] = 0;
 		}
 	}
 	rep(i,h){
 		rep(j,w){
 			char g;
 			cin>>g;
 			if(g=='.'){
 				arr[i+1][j+1] = 1;
 			}
 		}
 	}
 	int dx[4] = {-1,1,0,0};
 	int dy[4] = {0,0,-1,1};
 	int dist[h+2][w+2];
 	rep(i,h+2){
 		rep(j,w+2){
 			dist[i][j] = 1000000000;
 		}
 	}
 	dist[a][b] = 0;
 	deque<PII> q;
 	q.push_front({a,b});
 	while(!q.empty()){
 		PII l = q.front();
 		q.pop_front();
 		int x = l.first;
 		int y = l.second;
 		rep(i,4){
 			int curx = x + dx[i];
 			int cury = y + dy[i];
 			if(legal(curx,cury)){
 				if(dist[curx][cury]>dist[x][y]){
 					dist[curx][cury] = dist[x][y];
 					q.push_front({curx,cury});
 				}
 			}
 		}
 		for(int g = x-2;g<=x+2;g++){
 			for(int p=y-2;p<=y+2;p++){
 				if(legal(g,p)){
 					if(dist[g][p]>dist[x][y]+1){
 						dist[g][p]=dist[x][y]+1;
 						q.push_back({g,p});
 					}
 				}
 			}
 		}
 	}
 	if(dist[a1][b1]>10000000){
 		cout<<-1<<endl;
 	}
 	else{
 		cout<<dist[a1][b1]<<endl;	
 	}
 	


 	
}



 


Measured memory_bytes: 11532
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

ll k;

int main() {
    cin >> k;
    vector<ll> ans;
    queue<ll> que;
    for(ll i = 1; i < 10; ++i) {
        ans.emplace_back(i);
        que.push(i);
    }
    if(k < 10) cout << ans.at(k-1) << endl;
    else {
        int cnt = 9;
        while(cnt <= k) {
            ll now = que.front();
            que.pop();
            ll right = now % 10;
            for(ll i = -1; i < 2; ++i) {
                ll ch = right+i;
                if(ch < 0 || ch > 9) {}
                else {
                    ll next = now*10 + ch;
                    ans.emplace_back(next);
                    que.push(next);
                    cnt++;
                }
            }
        }
        cout << ans.at(k-1) << endl;
    }
}

Measured memory_bytes: 4612
p=input().split()
for i in range(3):
    p[i]=int(p[i])
f,s=2,1
for i in range(3):
    if p[i]==5:
        f-=1
    elif p[i]==7:
        s-=1
if f==s==0:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long 
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

string a;
ll b[30];

int main(){
  cin>>a;

  rep(i,a.size()){
    b[a[i]-'a']++;
  }
  ll sum=0;
  rep(i,27){
    sum+=(b[i]*(b[i]-1))/2;
  }
  ll n = a.size();
  cout<<(n*(n-1))/2-sum+1<<endl;

  return 0;
}


Measured memory_bytes: 640
n = int(input())

x_max = 0
y_max = 0
x_min = 10**9
y_min = 10**9

p_arr = [0]*n
m_arr = [0]*n

for i in range(n):
  x, y = map(int, input().split())
  p_arr[i] = x + y
  m_arr[i] = x - y
  

p_dist = max(p_arr) - min(p_arr)
m_dist = max(m_arr) - min(m_arr)
dist_max = max(p_dist, m_dist)
  
  
print(dist_max)

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

int main() {
    //
    int h, w;
    string str;
    cin >> h >> w;

    vector<vector<string>> vec(h, vector<string>(w));

    for (int i = 0; i < h; i++) {
        cin >> str;
        for (int j = 0; j < w; j++) vec.at(i).at(j) = str.at(j);
    }

    for (int i = 0; i < h-1; i++) {
        for (int j = 1; j < w; j++) {
            if (vec.at(i).at(j) == ".") break;
            if(i > 0 && vec.at(i-1).at(j) == "#"){
                cout << "Impossible";
                return 0;
            }

            for (int k = 0; k < j; k++) {
                if (vec.at(i + 1).at(k) == "#") {
                    cout << "Impossible";
                    return 0;
                }
            }
            vec.at(i).at(j) = ".";
        }
    }

    if(vec.at(h-1).at(w-2) == "#" && vec.at(h-2).at(w-1) == "#"){
        cout << "Impossible";
        return 0;
    }
    
    cout << "Possible";
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


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

  if (s == "ABC") cout << "ARC" << "\n";
  if (s == "ARC") cout << "ABC" << "\n";
  return 0;
}


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

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

const ll INF = pow(10, 9);

int main(){
    int N;
    cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];
    //絶対値の最小値を格納
    ll mn = INF;
    //最初に負の値の数を数える
    int minus = 0;
    //全体の絶対値の和
    ll sum = 0;

    //最小値と、負の数の数を数える、また、全体の絶対値の和を求める
    rep(i, N){
        if(mn > fabs(a[i])) mn = fabs(a[i]);
        if(a[i] < 0) minus++;
        sum += fabs(a[i]);
    }

    ll ans = sum;
    if(minus % 2 != 0) ans -= (mn*2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4000
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    cout<<setprecision(16)<<endl;

    double a,b;
    cin>>a>>b;
    int h,m;
    cin>>h>>m;
    int minu = 60*h+m;

    double a1 = minu/2.0;
    double a2 = m*6.0;
    double kaku = 0;
    if(a1>a2){
        kaku=a1-a2;
    }else{
        kaku=a2-a1;
    }
    if(kaku>180){
        kaku=360-kaku;
    }
   

    kaku=(kaku/180)*M_PI;
    double c = a*a+b*b-2*a*b*cos(kaku);

    double ans = sqrt(c);
    cout<<ans<<endl;






    
return 0;
}


Measured memory_bytes: 4228
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, 0, n)

const int inf = 999999999;
const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	cin.tie(0);
	static int even[100010],odd[100010];
	REP(i, 100010) {
		even[i] = 0;
		odd[i] = 0;
	}

	int even_max_count = 0, odd_max_count = 0;
	int even_max_ix, odd_max_ix;
	int ans;

	int n;
	cin >> n;

	REP(i, n) {
		int vi;
		cin >> vi;
		if (i % 2 == 0) {
			even[vi]++;
			if (even_max_count < even[vi]) {
				even_max_count = even[vi];
				even_max_ix = vi;
			}
		}
		else {
			odd[vi]++;
			if (odd_max_count < odd[vi]) {
				odd_max_count = odd[vi];
				odd_max_ix = vi;
			}
		}
	}

	sort(even, even + 100001);
	sort(odd, odd + 100001);
	reverse(even, even + 100001);
	reverse(odd, odd + 100001);

	if (even_max_ix != odd_max_ix) {
		ans = n - even_max_count - odd_max_count;
	}
	else {
		ans = n - max(even_max_count + odd[1], odd_max_count + even[1]);
	}
	cout << ans;
	system("pause");
	return 0;
}

Measured memory_bytes: 1272
# input
N, M = map(int, input().split())

# check
AC_questions = {}
for i in range(M):
    P, S = map(str, input().split())

    if P not in AC_questions:
        AC_questions[P] = {
            "wa_cnt": 0,
            "ac": False
        }

    if AC_questions[P]["ac"] is True:
        continue
    elif S == "AC":
        AC_questions[P]["ac"] = True
    # S == "WA"
    else:
        AC_questions[P]["wa_cnt"] += 1

# 「高橋君のペナルティ数は、高橋君が AC を 1回以上出した各問題において、初めて AC を出すまでに出した WA の数の総和」
# →そもそも不正解の問に関してはカウントしないと読み取る必要がある
target_keys = [key for key in AC_questions.keys() if AC_questions[key]['ac'] is True]
AC_cnt = sum([1 for key in target_keys])
WA_cnt = sum([AC_questions[key]["wa_cnt"] for key in target_keys])

print(AC_cnt, WA_cnt)

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

int main (){
    long long K = 0;
    cin >> K;
    long long ans = 0;
    if(!(K%2)){
        cout << -1 << endl;
        return 0;
    }
    long long now = 0;
    vector<bool> A(K,0);
    while (true)
    {
        now = 10*now + 7;
        now %= K;
        if (A.at(now)) {
            cout << -1 << endl;
            return 0;
        }
        A.at(now) = 1;
        if (now)
        {
            ans++;
        }
        else
        {
            ans++;
            break;
        }
        
    }
    
    cout << ans << endl;


    
}

Measured memory_bytes: 3692
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<functional>
#include<stack>
#include<queue>
#include<cmath>
# define MOD 1000000000+7
# define INF 1e9
# define LINF 1e18
typedef long long ll;

using namespace std;
int gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
 
int main() {
	
	int a, b,ans = 0;
	map<int, int> m;
	cin >> a >> b;

	for (int i = 0; i < a; i++) {
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int haru;
			cin >> haru;
			m[haru]++;
		}
	}

	for (int i = 1; i <= b; i++) {
		if (m[i] == a) {
			ans++;
		}
	}

	cout << ans << endl;

}

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

const int INF = 1000000;
const int MMAX = 100;

int N, M;
int c[MMAX][MMAX];
int t[MMAX][MMAX];

bool input_map() {
  cin >> N >> M;
  if (!N && !M) {
    return false;
  }
  for (int i = 0; i < M; ++i) {
    for (int j = 0; j < M; ++j) {
      c[i][j] = INF;
      t[i][j] = INF;
    }
    c[i][i] = 0;
  }
  for (int i = 0; i < N; ++i) {
    int x, y, cc, tt;
    cin >> x >> y >> cc >> tt;
    --x, --y;
    c[x][y] = cc;
    c[y][x] = cc;
    t[x][y] = tt;
    t[y][x] = tt;
  }

  return true;
}

void prepare() {
  for (int k = 0; k < M; ++k) {
    for (int i = 0; i < M; ++i) {
      for (int j = 0; j < M; ++j) {
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
        t[i][j] = min(t[i][j], t[i][k] + t[k][j]);
      }
    }
  }
}

int main() {
  while (input_map()) {
    prepare();
    int k;
    cin >> k;
    for (int i = 0; i < k; ++i) {
      int p, q, r;
      cin >> p >> q >> r;
      --p, --q;
      if (r) {
        cout << t[p][q] << endl;
      } else {
        cout << c[p][q] << endl;
      }
    }
  }
  return 0;
}

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

using namespace std;

int main(){
	long n;
	int k,i,j;
	long h[100000],dp[100000];
	cin >> n >>k;
	for(i=0;i<n;i++){
		cin >> h[i];
		dp[i] = 1e9+7;
	}	
	dp[0] = 0;
	for(i=0;i<n;i++){
		for(j=i+1;j<=i+k;j++){
			if(j<n){
				dp[j] = min(dp[j],dp[i]+ abs(h[i]-h[j]));
			}
		}
	}
	cout << dp[n-1];
	return 0;
}

Measured memory_bytes: 5164
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int n,m;
int a[1005],b[1005];

bool isB[505][505];

bool visited[505];
vector<int> G[505];
int cnt[505];
int depth[505];
vector<P> B,SB;

void initG(){
  for(int i=0;i<505;i++)G[i].clear();
}

void Dfs(int pos,int prev){
  visited[pos]=true;
  for(int i=0;i<(int)G[pos].size();i++){
    int to=G[pos][i];
    if(to==prev)continue;
    if(!visited[to]){
      depth[to]=depth[pos]+1;
      Dfs(to,pos);
      cnt[pos]+=cnt[to];
      if(cnt[to]==0)B.push_back( P( min(pos,to), max(pos,to) ) );
    }else if(depth[to]<depth[pos]){
      cnt[pos]++;
      cnt[to]--;
    }
  }
}

void calcB(int id=-1){
  initG();
  for(int i=0;i<m;i++){
    if(id==i)continue;
    G[ a[i] ].push_back(b[i]);
    G[ b[i] ].push_back(a[i]);
  }
  memset(visited,false,sizeof(visited));
  memset(cnt,0,sizeof(cnt));
  memset(depth,0,sizeof(depth));
  B.clear();
  Dfs(0,-1);
  for(int i=0;i<(int)B.size();i++){
    int fi=B[i].first;
    int se=B[i].second;
    isB[fi][se]=isB[se][fi]=true;
  }
}


bool isDag(){
  int C[505]={};
  queue<int> Q;
  for(int i=0;i<n;i++){
    for(int j=0;j<(int)G[i].size();j++){
      int to=G[i][j];
      C[to]++;
    }
  }
  for(int i=0;i<n;i++){
    if(C[i]==0)Q.push(i);
  }
  int count=0;
  while(!Q.empty()){
    int pos=Q.front();Q.pop();
    count++;
    for(int i=0;i<(int)G[pos].size();i++){
      int to=G[pos][i];
      C[to]--;
      if(C[to]==0)Q.push(to);
    }
  }
  return (count==n);
}

bool solve(int id){
  if( isB[ a[id] ][ b[id] ] )return false;

  initG();
  for(int i=0;i<m;i++){
    if(i==id)continue;
    G[ a[i] ].push_back(b[i]);
  }
  if( !isDag() )return false;  
  calcB(id);
  if( (int)B.size()>=2 )return true;
  else return false;
}


int main(){
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>a[i]>>b[i];
    a[i]--,b[i]--;
  }
  calcB();
  for(int i=0;i<m;i++){
    if(solve(i)){
      cout<<"YES"<<endl;
      return 0;
    }
  }
  cout<<"NO"<<endl;

  return 0;
}

Measured memory_bytes: 1376
#include <stdio.h>
#include <math.h>
using namespace std;

int main(void) {
	int N,D;
	scanf("%d%d", &N,&D);
	D = D * 2 + 1;
	float ans = (float)N / D;
	printf("%d", (int)ceil(ans));
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#define fs first
#define se second

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
typedef pair<ld, ld> pdd;

const int mod = 1e9 + 7;
int n;
int C[200001];
llong dp[200001];
int last[200001];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> C[i];
    }
    dp[0] = 1;
    for (int i = 1; i <= n; ++i) {
        dp[i] = dp[i - 1];
        if (0 < last[C[i]] && last[C[i]] + 1 < i) dp[i] += dp[last[C[i]]];
        last[C[i]] = i;
        dp[i] %= mod;
    }
    printf("%lld\n", dp[n]);
    return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int ans=1e9+7;
	for(int i=0;i<s.size()-2;i++){
		int num=0;
		num+=100*(s[i]-'0')+10*(s[i+1]-'0')+(s[i+2]-'0');
		ans=min(ans,abs(num-753));
	}
	cout<<ans<<endl;
	return 0;
}

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

vector<string> S;

int main() {
    int N;
    string s;
    scanf("%d", &N);
    bool flg = true;
    for (int i = 0; i < N; i++) {
        cin >> s;
        S.push_back(s);

        if (i > 0) {
            if (S[i-1].back() != S[i].front()) flg = false;
        }

        for (int j = 0; j < i; j++) {
            if (S[i] == S[j]) flg = false;
        }
    }
    if (flg) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
function main(lines) {
  const [N, M] = na();
  const as = na();

  const ans = N - as.reduce((a, b) => a+b);
  
  return Math.max(ans, -1);
}



const lines = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");

let lineCount = 0;
const s = () => lines[lineCount++];
const n = () => Number(s());
const b = () => BigInt(s());
const sa = () => s().split(' ');
const na = () => sa().map(Number);
const ba = () => sa().map(BigInt);

const ans = main(lines);
console.log( ans );

Measured memory_bytes: 30724
#include "bits/stdc++.h"
using namespace std;
int main(){
    int a,b,c,d,ans;
    cin >> a >> b >> c >> d;
    ans = min(b,d) - max(a,c);
    if(ans>0) cout << ans << endl;
    else cout << "0" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n;
    cin >> n;

    int mx = 0;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int h;
        cin >> h;
        if (h >= mx) {
            ans++;
            mx = h;
        }
    }

    cout << ans << "\n";
    return 0;
}

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

void solve() {
    ll n, k;
    cin >> n >> k;
    map<ll, ll> m;
    for(ll i = 0; i < k; i++) {
        ll x;
        cin >> x;
        while(x--) {
            ll y;
            cin >> y;
            m[y]++;
        }
    }
    cout << n - m.size();
}    

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

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

	int n;
	cin >> n;

	for(int x = 0; x <= 100000; x++){
		if(x * 108 / 100 == n){
			cout << x << endl;
			return 0;
		}
	}

	cout << ":(" << endl;

}


Measured memory_bytes: 256
import numpy as np
N, W = map(int, input().split())
w, v = [], []
for i in range(N):
    a, b = map(int, input().split())
    w += [a]
    v += [b]
 
DP = np.ones(N*1000+1, dtype=int) *(W+1)
DP[0] = 0
#総価値 i 円を得るために最低限必要な重量
for i in range(N):
    DP[v[i]:] = np.minimum(DP[:-v[i]]+ w[i], DP[v[i]:])
ans = 0
for k in range(N*1000+1):
    if DP[k] <= W:
        ans = k
        
print(ans)

Measured memory_bytes: 14808
open Printf
open Scanf

let (++) = Int64.add
let (--) = Int64.sub
let ( ** ) = Int64.mul
let long = Int64.of_int
let succl = Int64.succ
let predl = Int64.pred

let read_long _ = bscanf Scanning.stdin " %Ld " (fun x -> x)

let rec height = function
  | x when x < 0L -> 0L
  | 0L -> 1L
  | n -> 3L ++ 2L ** height (predl n)

let rec pate = function
  | x when x < 0L -> 0L
  | 0L -> 1L
  | n -> 1L ++ 2L ** pate (predl n)

let rec count n k =
  let h = height n in
  match k with
  | 0L -> 0L
  | _ when h = k -> pate n
  | _ ->
    let h' = height (predl n) in
    if h' >= (predl k)
    then count (predl n) (predl k)
    else count (predl n) h' ++ 1L ++ count (predl n) (k--h'--2L)

let () =
  let n = read_long () in
  let x = read_long () in
  printf "%Ld\n" @@ count n x


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,K;cin>>N>>K;
    vector<pair<int,int>> sushi(N);
    int backet[N]={0};
    for(int i=0;i<N;i++){
        cin>>sushi[i].second>>sushi[i].first;
        sushi[i].second--;
    }sort(sushi.begin(),sushi.end());
    long kind=0;
    deque<int> del;long sum=0;
    for(int j=N-1;j>=N-K;j--){
        if(backet[sushi[j].second]==0){
            backet[sushi[j].second]=1;
            kind++;
        }else{
            del.push_back(sushi[j].first);
        }sum+=sushi[j].first;
    }long result=sum+kind*kind;
    int i=N-K-1;
    while(del.size()!=0&&i>=0){
        if(backet[sushi[i].second]==0){
            backet[sushi[i].second]=1;
            kind++;
            sum+=sushi[i].first-del.back();
            del.pop_back();
            result=max(result,sum+kind*kind);
        }i--;
    }cout<<result<<endl;
}

Measured memory_bytes: 1536
# -*- coding: utf-8 -*-
# 標準入力を取得
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

# 求解処理
for i in range(K, N):
    if A[i] > A[i - K]:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 31564
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<sstream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
  int g,h,i,j,k,l,m;
  char a[10][10]={};
  for(i=1;i<=8;++i){
    for(j=1;j<=8;++j)
      scanf("%c",&a[i][j]);
    getchar();
  }
  char s[2]={'x','o'};
  int x[8]={1,1,0,-1,-1,-1,0,1},y[8]={0,1,1,1,0,-1,-1,-1};
  g=0;
  for(;;){
    for(h=0;h<2;++h){
      int mxx,mxy,mxn=0;
      for(i=1;i<=8;++i){
	for(j=1;j<=8;++j){
	  if(a[i][j]=='.'){
	    int sm=0;
	    for(k=0;k<8;++k){
	      if(a[i+y[k]][j+x[k]]==s[h]){
		for(l=1;a[i+y[k]*(l+1)][j+x[k]*(l+1)]==s[h];++l);
		if(a[i+y[k]*(l+1)][j+x[k]*(l+1)]==s[(h+1)%2])
		  sm+=l;
	      }
	    }
	    if(sm){
	      if(0){
	      }else if(mxn<sm){
		mxx=j;
		mxy=i;
		mxn=sm;
	      }else if(mxn>sm){
	      }else{
		if(h){
		  if(0){
		  }else if(mxy<i){
		    mxx=j;
		    mxy=i;
		  }else if(mxy>i){
		  }else{
		    if(mxx<j)
		      mxx=j;
		  }
		}else{
		  if(0){
		  }else if(mxy>i){
		    mxx=j;
		    mxy=i;
		  }else if(mxy<i){
		  }else{
		    if(mxx>j)
		      mxx=j;
		  }
		}
	      }
	    }
	  }
	}
      }
      if(mxn){
	a[mxy][mxx]=s[(h+1)%2];
	for(k=0;k<8;++k){
	  if(a[mxy+y[k]][mxx+x[k]]==s[h]){
	    for(l=1;a[mxy+y[k]*(l+1)][mxx+x[k]*(l+1)]==s[h];++l);
	    if(a[mxy+y[k]*(l+1)][mxx+x[k]*(l+1)]==s[(h+1)%2]){
	      for(m=0;m<l;++m)
		a[mxy+y[k]*(m+1)][mxx+x[k]*(m+1)]=s[(h+1)%2];
	    }
	  }
	}
	g=0;
      }else{
	if(g)
	  break;
	else
	  g=1;
      }
    }
    if(h<2)
      break;
  }
  for(i=1;i<=8;++i){
    for(j=1;j<=8;++j)
      printf("%c",a[i][j]);
    puts("");
  }
  return 0;
}

Measured memory_bytes: 0
N, M, X, Y = map(int, input().split())

x = map(int, input().split())
y = map(int, input().split())

x_max= max(x)
y_min = min(y)

if(x_max<y_min and X < y_min<=Y):
    print("No War")
else:
    print("War")

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

// 二つの値の最小値を求める関数
Int Min(const Int a, const Int b) {
    if (a <= b) {
        return a;
    } else {
        return b;
    }
}

int main(void) {
    Int n;
    cin >> n;
    VI b(n - 1);
    for (Int i = 0 ; i < n - 1; ++i) {
        cin >> b[i];
    }
    Int result = (b[0] + b[n - 2]);
    for (Int i = 1; i < n - 1; ++i) {
        result += Min(b[i - 1], b[i]);
    }
    cout << result << endl;
    return 0;
}


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

int main(){

    int n; cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) b[i] = i + 1;

    map<vector<int>, int> mb;
    queue<pair<vector<int>, int> > qb;
    
    mb[b] = -1;
    qb.push({b, 0});
    

    while(1){

        vector<int> now(n);
        now = qb.front().first;
        int cost = qb.front().second;
        qb.pop();
        
        if(cost == 4) break;

        bool ok = true;
        for(int i = 0; i < n; i++){
            if(a[i] != now[i]){
                ok = false;
                break;
            }
        }

        if(ok){
            cout << cost << endl;
            return 0;
        }

        for(int i = 0; i < n - 1; i++){
            for(int j = i + 1; j < n; j++){
                vector<int> next(n);
                next = now;

                for(int k = i; k <= j; k++){
                    next[k] = now[j - k + i];
                }


                if(mb.find(next) == mb.end()){
                    mb[next] = cost + 1;
                    qb.push({next, cost + 1});
                }
            }
        }
    }


    //cout << "junnbihadeketa" << endl;
    map<vector<int>, int> ma;
    queue<pair<vector<int>, int> > qa;
    ma[a] = -1;
    qa.push({a, 0});

    while(1){

        vector<int> now(n);
        now = qa.front().first;
        int cost = qa.front().second;
        qa.pop();

        if(cost == 4) break;

        if(mb.find(now) != mb.end()){
            cout << cost + mb[now] << endl;
            return 0;
        }

        for(int i = 0; i < n - 1; i++){
            for(int j = i + 1; j < n; j++){
                vector<int> next(n);
                next = now;
                for(int k = i; k <= j; k++){
                    next[k] = now[j + i - k];
                }

                if(ma.find(next) == ma.end()){
                    ma[next] == cost + 1;
                    qa.push({next, cost + 1});
                }
            }
        }
    }

    cout << 9 << endl;
    return 0;
}


Measured memory_bytes: 102968
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    private static final PrintWriter sysout = new PrintWriter(System.out, false);

    private static StringTokenizer buffer;

    private static String readLine() {
        buffer = null;
        try {
            return br.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    private static String read() {
        if (buffer == null || !buffer.hasMoreTokens()) {
            buffer = new StringTokenizer(readLine());
        }
        return buffer.nextToken();
    }

    private static int readInt() {
        return Integer.parseInt(read());
    }

    private static int[] readIntArray(int loop) {
        int[] result = new int[loop];
        for (int i = 0; i < loop; i++) {
            result[i] = readInt();
        }
        return result;
    }

    private static int[] splitInt() {
        String[] tmp = read().split("");
        int[] result = new int[tmp.length];
        for (int i = 0, n = tmp.length; i < n; i++) {
            result[i] = Integer.parseInt(tmp[i]);
        }
        return result;
    }

    private static long readLong() {
        return Long.parseLong(read());
    }

    private static double readDouble() {
        return Double.parseDouble(read());
    }

    public static void main(String[] args){
        run();
    }

    private static void run() {
        int gohyaku = readInt();
        int hyaku = readInt();
        int goju = readInt();
        int total = readInt();
        int count = 0;
        for (int i = 0; i <= gohyaku; i++) {
            for (int j = 0; j <= hyaku; j++) {
                for (int k = 0; k <= goju; k++) {
                    int result = 500*i + 100*j + 50*k;
                    if (total == result) count++;
                }
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 22356
#include <bits/stdc++.h>
#define el '\n'
using namespace std;

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

  int n;
  cin >> n;
  vector<int> h(n);
  for(int i = 0; i < n; i++){
    cin >> h[i];
  }
  vector<int> dp(n, INT_MAX);
  dp[0] = 0;
  for(int i = 0; i < n; i++){
    for(int j = i+1; j <= i+2; j++){
      dp[j] = min(dp[j], dp[i]+abs(h[i]-h[j]));
    }
  }
  cout << dp[n-1] << el;
  
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int parent(int);
int left(int);
int right(int);
void maxHeapify(int *,int);
void buildMaxHeap(int *);

int H,A[500001];
int main(){
  int i,parentkey,leftkey,rightkey;
  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }
   buildMaxHeap(A);
  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
    }
  printf("\n");
 return 0;
}
int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}

void maxHeapify(int *A,int i){
  int l,r,largest,u;
  l=left(i);
  r=right(i);
  if(l<=H && A[l] > A[i]){
    largest=l;
  }
  else
    largest=i;
  if(r<=H && A[r]>A[largest]){
    largest = r;
  }

  if(largest!=i){
    u=A[i];
    A[i]=A[largest];
    A[largest]=u;
    maxHeapify(A,largest);
  }
}
  
void buildMaxHeap(int *A){
  int i;
  for(i=H/2;i>=1;i--){
    maxHeapify(A, i);
  }
}



Measured memory_bytes: 3632
"""
ROT N
https://atcoder.jp/contests/abc146/tasks/abc146_b
"""

import sys
input = sys.stdin.readline

N = int(input())
S = input()

alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

ans = []
for s in S:
    for i, char in enumerate(alphabet):
        if s == char:
            ans.append(i)
            break

for item in ans:
    print(alphabet[item + N], end="")
print()


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

const ll MOD = 1e9 + 7;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	vvl a(n,vl(n));
	FOR(i,0,n) FOR(j,0,n) cin >> a[i][j];

	vl dp(1 << n);
	dp[0] = 1;
	FOR(mask,0,(1 << n)-1) {
		ll i = __builtin_popcount(mask);
		FOR(j,0,n) if (a[i][j] && !(mask & (1 << j))) {
			(dp[mask|(1 << j)] += dp[mask]) %= MOD;
		}
	}
	cout << dp.back() << endl;

}



Measured memory_bytes: 16640
#if defined(__GNUC__)
#include <bits/stdc++.h>
// __GNUC__
#else
#include "bits/stdc++.h"
#endif
using namespace std;

#define int long long

#if defined(__GNUC__)
#define __int32 __int32_t
#endif // __GNUC__

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); ++(i))
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); ++(i))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) std::sort(ALL(x))
#define RSORT(x, T) std::sort(ALL(x), greater<T>())
#define REVERCE(x) std::reverce(ALL(x))
#define ACM(x, y) std::accumulate(ALL(x), y)

#define INT_POW(x, y) [](int a, int b) -> int {int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)
#define INT_POWM(x, y, m) [](int a, int b, int m) -> int {int c = a; REP(i, b - 1){c *= a; c %= m;} return c;}(x, y, m)

itn main() {
	std::ios::sync_with_stdio(false);

	int n, d, a;

	cin >> n >> d >> a;

	d *= 2;

	vector<pair<int, int>> xh(n);

	REP(i, n) {
		cin >> xh[i].first >> xh[i].second;
	}

	SORT(xh);

	queue<pair<int, int>> q;

	int fix = 0;
	int res = 0;

	REP(i, n) {
		while (q.size() && xh[i].first > q.front().first) {
			fix -= q.front().second;
			q.pop();
		}

		if (xh[i].second > fix) {
			int tim = (xh[i].second - fix + a - 1) / a;
			res += tim;
			q.push(pair<int, int>(xh[i].first + d, tim * a));
			fix += tim * a;
		}
	}

	cout << res;
 
	return 0;
}

Measured memory_bytes: 4992
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> As;
    int A;
    for (int i = 0; i < N; i++) {
        cin >> A;
        As.push_back(A);
    }
    sort(As.begin(), As.end());
    int h = 0, w = 0;

    for (int i = N - 1; i > 0; --i) {
        if (As[i] == As[i - 1]) {
            if (h == 0) {
                h = As[i];
                --i;
            } else {
                w = As[i];
                break;
            }
        }
    }
    cout << (long long int)h * w << endl;

    return 0;
}

Measured memory_bytes: 892
n = int(input())

res = n
for i in range(n+1):
    cnt = 0
    tmp = i
    while tmp > 0:
        cnt += tmp % 6
        tmp //= 6
    
    tmp = n - i
    while tmp > 0:
        cnt += tmp % 9
        tmp //= 9

    res = min(res, cnt)

print(res)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  string s;
  cin >> s;
  rep(i,3) {
    if (s[i] == '1') s[i] = '9';
    else if (s[i] == '9') s[i] = '1';
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256