akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void){
    int H, W;
    scanf("%d %d",&H, &W);
    char a[H][W];
    for(int i = 0; i < H; i++){
        scanf("%s",a[i]);
    }

    int white = 1;
    int check_h[H], check_w[W];
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(a[i][j] == '#') white = 0;
            else white = 1;
            if(white == 0) break;
        }
        if(white == 1)  check_h[i] = 1;
        else check_h[i] = 0;
        white = 1;
    }

    white = 1;
    for(int i = 0; i < W; i++){
        for(int j = 0; j < H; j++){
            if(a[j][i] == '#') white = 0;
            else white = 1;
            if(white == 0) break;
        }
        if(white == 1)  check_w[i] = 1;
        else check_w[i] = 0;
        white = 1;
    }

    for(int i = 0; i < H; i++){
        if(check_h[i] == 1) continue;
        for(int j = 0; j < W; j++){
            if(check_w[j] == 1) continue;
            else printf("%c",a[i][j]);
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 128
x, n = map(int, input().split())

if n == 0:
    print(x)
    exit()

if n != 0:
    P = list(map(int, input().split()))

if x not in P:
    print(x)
    exit()

bl = False
i = 1
while not bl:
    if (x - i) not in P:
        print(x - i)
        exit()
    if (x + i) not in P:
        print(x + i)
        exit()
    i += 1


Measured memory_bytes: 61888
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 10;

vector<pair<ll, ll>> ans;
set<ll> pws;

int main()
{
    fastInp;

    ll n;
    cin >> n;

    for (ll i = 30; i >= 0; i--) {
        pws.insert((1ll << i));
        if ((1ll << i) == n) {
            cout << "No";
            return 0;
        }
    }

    ans.push_back({1, 2});
    ans.push_back({2, 3});
    ans.push_back({3, 1 + n});
    ans.push_back({1 + n, 2 + n});
    ans.push_back({2 + n, 3 + n});

    for (ll i = 4; i <= n; i++) {
        if ((i & (3ll)) == 0) {
            if (i == n) {
                for (ll j = 30; j >= 0; j--) {
                    if ((i & (1ll << j))) {
                        ll snd = (i ^ (1ll << j));
                        ans.push_back({(1ll << j), i});
                        ans.push_back({i + n, (snd + 1)});
                        j = -1;
                    }
                }
                
            } else {
                ans.push_back({i, 1 + n});
                ans.push_back({i + 1, 1 + n});
                ans.push_back({i + n, i + 1});
                ans.push_back({i, i + n + 1});
                i++;
            }
            continue;
        }
        ll cnct = (i - (i & 3ll));
        if ((i & 3ll) == 2ll) {
            ans.push_back({i, cnct});
            ans.push_back({i + n, 3});
        } else {
            ans.push_back({i, cnct});
            ans.push_back({i + n, 2 + n});
        }
    }

    cout << "Yes\n";
    for (auto cur : ans) {
        cout << cur.first << " " << cur.second;
        cout << "\n";
    }

    return 0;
}

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


int main(){
  int n;
  //int m;
  cin >> n; //>> m;
  map<int,int> tisa;
  for(int i=0; i<n-1; i++){
    int a;
    cin >> a;
    tisa[a] += 1;
  }
  
  for(int i=1; i<n+1; i++){
    cout << tisa[i] << endl;
  }
  
  

}


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

using namespace std;

int main(){
        int N,ans=0,count;
        string S;
        set<char> st;
        cin >> N >> S;
        for(int i=1;i<N;i++){
                count=0;
                st={};
                for(int j=0;j<i;j++){
                        //cout << "turn "<< i << j << endl;
                        if(st.count(S[j])==0){
                                st.insert(S[j]);
                                if(S.find(S[j],i)!=string::npos){
                                        count++;
                                        //cout << i << j << " : New,S[j]=" << S[j] << " find on " << S.find(S[j],j+1) << endl;
                                }
                        }
                }
                //cout << i << "," << count << endl;
                if(count>ans) ans=count;
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 256
def gcd(x,y):
    if y>x:
        a=y
        y=x
        x=a
    while y:
        a=x%y
        x=y
        y=a
    return x
a,b,c,d=map(int,input().split())
ans=b-a+1
G=c*d//gcd(c,d)
ans-=(b-(b+1)%-c-(a-a%-c)+1)//c
ans-=(b-(b+1)%-d-(a-a%-d)+1)//d
ans+=(b-(b+1)%-G-(a-a%-G)+1)//G
print(ans)



Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>

int partition(int *,int,int);

int main(void){

  int *A,n,p=0,q,r,i;

  scanf("%d",&n);
  A = malloc(sizeof(int)*n);

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

  r = n-1;
  q = partition(A,p,r);
  
  for(i=0;i<q;i++){
    printf("%d ",A[i]);
  }
  printf("[%d] ",A[i]);
  for(i=q+1;i<=r;i++){
    printf("%d",A[i]);
    if(i!=r){
      printf(" ");
    }
  }
  printf("\n");
  return 0;
}

int partition(int *A,int p,int r){

  int i,j,x,temp;

  x = A[r];
  i = p-1;

  for(j=p;j<r;j++){
    if(A[j] <= x){
      i = i+1;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  }
  temp = A[i+1];
  A[i+1] = A[r];
  A[r] = temp;
  return i+1;
}

Measured memory_bytes: 996
using System;
using System.Collections.Generic;

namespace ABC057_B_Checkpoints
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			string[] input = Console.ReadLine().Split(' ');
			int n = int.Parse(input[0]);
			int m = int.Parse(input[1]);
			List<int> aList = new List<int>(n);
			List<int> bList = new List<int>(n);
			for (int i = 0; i < n; i++)
			{
				input = Console.ReadLine().Split(' ');
				aList.Add(int.Parse(input[0]));
				bList.Add(int.Parse(input[1]));
			}
			List<int> cList = new List<int>(m);
			List<int> dList = new List<int>(m);
			for (int i = 0; i < m; i++)
			{
				input = Console.ReadLine().Split(' ');
				cList.Add(int.Parse(input[0]));
				dList.Add(int.Parse(input[1]));
			}

			int checkPointIndex;
			int minLength;
			for (int index = 0; index < n; index++)
			{
				checkPointIndex = 0;
				minLength = Math.Abs(aList[index] - cList[0]) + Math.Abs(bList[index] - dList[0]);
				for (int j = 1; j < m; j++)
				{
					int length = Math.Abs(aList[index] - cList[j]) + Math.Abs(bList[index] - dList[j]);
					if (minLength > length)
					{
						minLength = length;
						checkPointIndex = j;
					}
				}
				
				Console.WriteLine(checkPointIndex + 1); //インデックスが0から始まるため+1
			}
		}
	}
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int maxn=3001;
int n;ll arr[maxn];
ll dp[maxn][maxn];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>arr[i];
	for(int k=0;k<n;k++)
	{
		int i=0,j=k;
		while(j<n)
		{
			if(i==j)dp[i][j]=arr[i];
			else dp[i][j]=max(arr[i]-dp[i+1][j],arr[j]-dp[i][j-1]);
			i++;j++;
		}
	}
	cout<<dp[0][n-1]<<endl;
	return 0;
}


Measured memory_bytes: 70016
n = int(input())
a = [i*4 for i in range(n//4 + 1)]
b = [i*7 for i in range(n//7 + 1)]

c =set()
for i in a:
    for j in b:
        if i+j != 0 and i+j <=n:
            c.add(i+j)
            
if n in c:
    print('Yes')
else:
    print('No')

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

int MDT[16][16];
const int nxt[][2] = {{0,1},{-1,0},{0,-1},{1,0} };
const char dir[] = {'r','u','l','d'};

struct Puzzle {
    int f[16],space,MD;
    int cost;

    bool operator < (const Puzzle& p) const {
        for(int i = 0; i < 16; i++) {
            if(f[i] == p.f[i]) continue;
            return f[i] < p.f[i];
        }
        return false;
    }
};

struct State {
    Puzzle puzzle;
    int estimated;
    bool operator < (const State&s) const {
        return estimated > s.estimated;
    }
};

int getAllMD(Puzzle pz) {
    int sum = 0;
    for(int i = 0; i < 16; i++) {
        if(pz.f[i] == 16) continue;
        sum += MDT[i][ pz.f[i]-1 ];
    }
    return sum;
}

int Astar(Puzzle s) {
    priority_queue<State> PQ;
    s.MD = getAllMD(s);
    s.cost = 0;
    map<Puzzle,bool> V;
    State init;
    init.puzzle = s;
    init.estimated = getAllMD(s);
    PQ.push(init);
    while(!PQ.empty()) {
        State st = PQ.top(); PQ.pop();
        Puzzle u = st.puzzle;
        if(u.MD == 0) return u.cost;
        V[u] = true;
        int sx = u.space / 4;
        int sy = u.space % 4;
        for(int i = 0; i < 4; i++) {
            int tx = sx + nxt[i][0];
            int ty = sy + nxt[i][1];
            if(tx < 0 || ty < 0 || tx >= 4 || ty >= 4) continue;
            Puzzle v = u;
            swap(v.f[sx*4+sy],v.f[tx*4+ty]);
            v.space = tx * 4 + ty;
            v.MD = getAllMD(v);
            if(!V[v]) {
                v.cost++;
                State news;
                news.puzzle = v;
                news.estimated = v.cost + v.MD;
                PQ.push(news);
            }
        }
    }
    return -1;
}

int main() {
    for(int i = 0; i < 16; i++) {
        for(int j = 0; j < 16; j++) {
            MDT[i][j] = abs(i/4-j/4) + abs(i%4-j%4);
        } // 计算i位置到j位置的曼哈顿距离
    } // i位置就是[i/4][i%4],j位置以此类推
    Puzzle in; //初始拼图
    for(int i = 0; i < 16; i++) {
        cin >> in.f[i];
        if(in.f[i] == 0) {
            in.f[i] = 16;
            in.space = i;
        }
    }
    cout << Astar(in) << endl; // A*搜索
    return 0;
}



Measured memory_bytes: 257584
using System;

namespace ABC165_b
{
    class Program
    {
        static void Main(string[] args)
        {
            long x = long.Parse(Console.ReadLine());
            long deposit = 100;
            long year = 0;

            while(deposit < x) {
                deposit += deposit / 100;
                year++;
            }
            Console.WriteLine(year);
        }
    }
}


Measured memory_bytes: 27476
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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; }

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    a = root(a);
    return -Parent[a];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(a < b) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }

  bool issame(int a, int b){
    return root(a) == root(b);
  }
};

int main(){
  vl a(4); rep(i,4) cin >> a[i];
  ll n; cin >> n;
  n *= 4LL;
  vector<pair<ll,int>> b(4);
  rep(i,4) {
    b[i] = mp(a[i]*pow(2,3-i), i);
  }
  sort(all(b));
  //rep(i,4) cout << b[i].first << endl;
  ll ans = 0;
  for(auto c : b) {
    int i = c.second;
    ll value = a[i];
    int fac = pow(2,i);
    ans += (n/fac)*value;
    n %= fac;
  }

  cout << ans << endl;

}

Measured memory_bytes: 512
#include <stdio.h>

int main(){

  int i,j,N,flag,A[100],count=0,tmp;

  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }

  flag=1;
  while(flag){
    flag=0;
    for(j=N-1;j>=1;j--){
      
      if(A[j] < A[j-1]){
	tmp=A[j];
	A[j]=A[j-1];
	A[j-1]=tmp;
	flag=1;
	count++;
      }
      
    }
    
  }
  for(j=0;j<N;j++){
    if(j>0) printf(" ");
    printf("%d",A[j]);
  }
  printf("\n");
  printf("%d\n",count);

  return 0;
}



Measured memory_bytes: 2128
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
inline int two(int n) { return 1 << n; }

inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }



int main()
{
    long long int k,n;
    cin >>k>>n;
    long long int a[n],min=1000000000000000;
    // FOR(i,0,n)
    REP(i,n)
    {
        cin>>a[i];
    }
    // cout<<"h1";
    sort(a,a+n);
    min=a[n-1]-a[0];
    REP(i,n)
    {
        if(i==0)
            continue;

        // cout<<"i is "<<i<<" Val is "<<k-a[i]+a[(i-1+n)%n]<<endl;
        if(k-a[i]+a[(i-1+n)%n]<min)
            min=k-a[i]+a[(i-1+n)%n];
    }

    cout<<min<<endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <cctype>

using namespace std;

string decStr(string str, int n) {
  for(int i = 0; i < str.length(); i++) {
    if(!isalpha(str[i])) continue;
    str[i] = (char)(  ((int)str[i]-(int)'a'+n)%26  + (int)'a'  );
  }
  return str;
}

int main(void) {
  string str;

  while(getline(cin, str)) {
    string ans;
    for(int i = 0; i < 26; i++) {
      ans = decStr(str, i);
      if(ans.find("the") != string::npos) break;
      if(ans.find("this") != string::npos) break;
      if(ans.find("that") != string::npos) break;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n, m, a[20001], i, r;
	while (cin >> n >> m, !(!n && !m))
	{
		a[0] = r = 0;
		for (i = 1; i <= n+m; i++)
			cin >> a[i];
		sort(a, a+n+m+1);
		for (i = 1; i <= n+m; i++)
			r = max(r, a[i] - a[i-1]);
		cout << r << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int,int> PP;

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

ll MOD = 1E9 + 7;

ll DP[4002][4002];
ll ANS[4002][4002];

ll fac[8010];
ll inv[8010];

ll power(ll a, ll b) {
	ll res = 1;
	ll crt = a;
	while (b > 0) {
		if (b % 2 == 1) {
			res *= crt;
			res %= MOD;
		}
		crt *= crt;
		crt %= MOD;
		b /= 2;
	}
	return res;
}

void init() {
	fac[0] = 1;
	inv[0] = 1;
	ll crt = 1;
	for (ll i = 1;i <= 8000;i++) {
		crt *= i;
		crt %= MOD;
		fac[i] = crt;
		inv[i] = power(crt, MOD - 2);
	}
	return;
}

ll cal(int a, int b) {
	ll down = inv[a] * inv[b];
	down %= MOD;
	ll up = fac[a + b] * down;
	up %= MOD;
	return up;
}

int main() {
    //ios::sync_with_stdio(false);
    memset(DP, 0, sizeof(DP));
    int N;
    scanf("%d", &N);
    int A[200000], B[200000];
    for (int i = 0;i < N;i++) {
    	int a, b;
    	scanf("%d%d", &a, &b);
    	A[i] = a;
    	B[i] = b;
    	DP[2000 + a][2000 + b]++;
    	DP[2000 - a][2000 - b]++;
    }
    memset(ANS, 0, sizeof(ANS));
    ll res = 0;
    for (int a = -2000;a <= 2000;a++) {
    	for (int b = -2000;b <= 2000;b++) {
    		int i = a + 2000;
    		int j = b + 2000;
    		if (DP[i][j] != 0) {
    			if (a < 0 && b < 0) {
    				ANS[i][j] += DP[i][j];
    				ANS[i][j] %= MOD;
    			}
    			else {
    				res += (ANS[i][j] * DP[i][j]) % MOD;
    				res %= MOD;
    				ANS[i][j] %= MOD;
    			}
    		}
    		ANS[i + 1][j] += ANS[i][j];
    		ANS[i + 1][j] %= MOD;
    		ANS[i][j + 1] += ANS[i][j];
    		ANS[i][j + 1] %= MOD;
    	}
    }
    init();
    for (int i = 0;i < N;i++) {
    	res += MOD - cal(A[i] * 2, B[i] * 2);
    	res %= MOD;
    }
    res *= (MOD + 1) / 2;
    res %= MOD;
    cout << res << endl;
    return 0;
}


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

int main()
{
    string n;
    cin >> n;
   if(n[0]==n[1]&&n[1]==n[2]||n[1]==n[2]&&n[2]==n[3]){
       cout << "Yes" << endl;
   }else{
       cout << "No" << endl;
   }
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
//#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
const int inf=1000000007;
const int MOD=1000000007;

struct UnionFind{
    vector<int> par;
    vector<int> sosen;
    UnionFind(int n) : par(n){
      for(int i=0;i<n;i++)par[i]=i;
    }
    int root(int x){
      if(par[x]==x) return x;
      return par[x]=root(par[x]);
    }
    void Net(int n){
      for(int i=0;i<n;i++){
        sosen.push_back(0);
      }
      for(int i=0;i<n;i++){
        sosen[root(i)]++;
      }
    }
    void unite(int x,int y){
      int rx=root(x);
      int ry=root(y);
      if(rx==ry) return;
      par[rx]=ry;
    }
    bool same(int x, int y){
      int rx=root(x);
      int ry=root(y);
      if(rx==ry) return 1;
      return 0;
    }
  };
signed main(){
  int n,m,k;
  cin>>n>>m>>k;
  if(m==0){
    rep(i,n){
      cout<<0<<" ";
    }
    cout<<endl;
    return 0;
  }
  //UnionFind bl(k);
  vector<pair<int,int>> ff(m);
  vector<pair<int,int>> ng(k);
  vector<pair<int,int>> fr(m);
  vector<pair<int,int>> ngr(k);
  UnionFind fri(n);
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    ff[i].first=min(a,b);
    ff[i].second=max(a,b);
    fr[i].first=max(a,b);
    fr[i].second=min(a,b);
    fri.unite(a,b);
  }
  rep(i,k){
    int a,b;
    cin>>a>>b;
    a--;b--;
    ng[i].first=min(a,b);
    ng[i].second=max(a,b);
    ngr[i].first=max(a,b);
    ngr[i].second=min(a,b);
    //bl.unite(ng[i].first,ng[i].second);
  }
  //return 0;
  fri.Net(n);
  sort(ALL(ff));sort(ALL(ng));
  sort(ALL(fr));sort(ALL(ngr));
  ff.push_back(make_pair(inf,inf));
  fr.push_back(make_pair(inf,inf));
  ng.push_back(make_pair(inf,inf));
  ngr.push_back(make_pair(inf,inf));
  int cur_ff=0;int cur_ng=0;
  int cur_fr=m-1;int cur_ngr=k-1;
  vector<int> ans(n,0);
  rep(i,n){
    int res=fri.sosen[fri.root(i)]-1;
    while(ff[cur_ff].first==i){
      if(fri.same(i,ff[cur_ff].second))res--;
      if(cur_ff==m-1)break;
      cur_ff++;
    }
    if(k!=0){
    while(ng[cur_ng].first==i){
      if(fri.same(i,ng[cur_ng].second))res--;
      if(cur_ng==k-1)break;
      cur_ng++;
    }}
    ans[i]=res;
  }
  for(int i=n-1;i>=0;i--){
    int sub=0;
    while(fr[cur_fr].first==i){
      if(fri.same(i,fr[cur_fr].second))sub++;
      if(cur_fr==0)break;
      cur_fr--;
    }
    if(k!=0){
    while(ngr[cur_ngr].first==i){
      if(fri.same(i,ngr[cur_ngr].second))sub++;
      if(cur_ngr==0)break;
      cur_ngr--;
    }}
    ans[i]-=sub;
  }
  rep(i,n){
    cout<<ans[i]<<" ";
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 5560
#include "bits/stdc++.h"
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmax(x, y) (x > (y) ? x : x = (y))
#define chmin(x, y) (x < (y) ? x : x = (y))
#define write(x) cout << (x) << endl
using namespace std;
typedef long long ll;
const int INF = 1 << 29;
const int MAX = 1e5 + 10;

ll A, B, C, X, Y;

int main()
{
    cin >> A >> B >> C >> X >> Y;

    ll ans = 1ll << 60;
    for (int nAB = 0; nAB <= max(2 * X, 2 * Y); nAB++) {
        int tmp = max(0ll, X * A - nAB / 2 * A);
        ll price = C * nAB + max(0ll, X * A - nAB / 2 * A) + max(0ll, Y * B - nAB / 2 * B);
        if (price < ans) ans = price;
    }
    write(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int lli;

int main(){
	int n;
	cin >> n;
	vector<lli> a(n+1, 0);
	for(int i=0; i<n; i++) cin >> a[i];
	for(int i=0; i<n; i++){
		if(a[i] > i){
			cout << -1 << endl;
			return 0;
		}
	}
	lli nmax = 0;
	for(int i=n-1; i>=0; i--){
		if(a[i] < nmax){
			cout << -1 << endl;
			return 0;
		}
		nmax = max(nmax-1, a[i]-1);
	}
	
	lli ans = 0;
	lli pre = 0;
	for(int i=0; i<=n; i++){
		if(a[i] != pre+1) ans+=pre;
		pre = a[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
  {
      ll a,b,c,d;
      cin>>a>>b>>c>>d;
      ll x,y,p,q;
      x=a*c;
      y=a*d;
      p=b*c;
      q=b*d;
      if(x>y && x>p && x>q)
      cout<<x<<endl;
      else if(y>x && y>p && y>q)
      cout<<y<<endl;
      else if(p>x && p>y && p>q)
      cout<<p<<endl;
      else
      cout<<q<<endl;

  }

Measured memory_bytes: 3672
#include <cstdio>
#include <bitset>
#include <cmath>
#include <complex>
#include <vector>
#include <algorithm>

#define EPS 1e-6
using namespace std;

double cross(complex<double> a, complex<double> b)
{
  return a.real() * b.imag() - a.imag() * b.real();
}

double dot(complex<double> a, complex<double> b)
{
  return a.real() * b.real() + a.imag() * b.imag();
}

int main()
{
  int W, N;
  scanf(" %d %d ", &W, &N);
  vector<pair<int, int> > lines;
  for (int i = 0; i < N; i++) {
    int x, y;
    scanf(" %d,%d ", &x, &y);
    lines.push_back(make_pair(x, y));
  }
  reverse(lines.begin(), lines.end());
  vector<int> ans;
  for (int i = 0; i < W; i++) {
    int cur = i + 1;
    for (int j = 0; j < N; j++) {
      if (cur == lines[j].first) {cur = lines[j].second;}
      else if (cur == lines[j].second) {cur = lines[j].first;}
    }
    printf("%d\n", cur);
  }
  return 0;
}

Measured memory_bytes: 0
package main

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

const (
	mod = 1000000007
)

func main() {
	var n, m int
	fmt.Scan(&n)
	fmt.Scan(&m)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	a := make(map[int]bool)
	for i := 0; i < m; i++ {
		scanner.Scan()
		aa, _ := strconv.Atoi(scanner.Text())
		a[aa] = true
	}

	dp := make([]int, n+1)
	dp[0] = 1
	if a[1] {
		dp[1] = 0
	} else {
		dp[1] = 1
	}

	for i := 2; i <= n; i++ {
		if a[i] {
			dp[i] = 0
		} else {
			dp[i] = (dp[i-1] + dp[i-2]) % mod
		}
	}

	fmt.Println(dp[n])
}


Measured memory_bytes: 4736
// E - Double Factorial
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	ll N; cin>>N;
	if(N%2){ puts("0"); return 0; }
	ll n = N/2, m = log(n)/log(5), ans = 0;
	for(ll w=5, i=0; i<m; ++i, w*=5) ans += n/w;
	cout<< ans <<endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<long long> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  int ans=0;
  while(1){
    bool can=true;
  	for(int i=0;i<n;i++){
      if(a.at(i)%2==1){
        can=false;
        break;
      }
      a.at(i)/=2;
    }
    if(!can) break;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n,m = map(int,input().split())

s = []

for i in range(m):
	s.append(list(map(int,input().split())))

a1 = []
an = []
for i in range(m):
	if s[i][0]==1:
		a1.append(s[i][1])

for i in range(m):
	if s[i][1]==n:
		an.append(s[i][0])

if len(list(set(a1)&set(an)))>0:
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")


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


int main() {
    int N; cin >> N;
    string S; cin >> S;
    if (N == 1) {
        cout << 1 << endl;
        return 0;
    }

    int ans = 1;
    char prev_color = S[0];
    for (int i = 1; i < N; i++) {
        if (S[i] != prev_color) ans++;
        prev_color = S[i];
    }

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


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
using namespace std;

int main(void){
	int n;cin>>n;
	vector<int> points(n,0);
	for(int i=0;i<n*(n-1)/2;++i){
		int t1,t2,p1,p2;cin>>t1>>t2>>p1>>p2;
		if(p1>p2) points[t1-1] += 3;
		else if(p1 == p2){
			points[t1-1]++;
			points[t2-1]++;
		}else points[t2-1] += 3;
	}
	map<int,set<int> > lst;
	for(int i=0;i<n;++i){
		lst[points[i]].insert(i+1);
	}
	sort(points.begin(), points.end(), greater<int>());
	int bf = -1;
	vector<int> rank(n);
	int rk=1;
	for(int i=0;i<n;++i){
		int val = points[i];
		set<int>::iterator it = lst[val].begin();
		if(bf == val){
			bf = val;
			continue;
		}
		bf = val;
		for(;it!=lst[val].end();++it){
			rank[*it-1] = rk;
		}
		rk+=lst[val].size();
	}
	for(int i=0;i<n;++i) cout<<rank[i]<<endl;
	return 0;
}

Measured memory_bytes: 1224
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int H, W;
char board[10][10];

signed main() {
    cin >> H >> W;

    int cnt = 0;
    rep(i,0,H) rep(j,0,W) {
        cin >> board[i][j];
        if(board[i][j] == '#') cnt++;
    }

    if(cnt == H + W - 1) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
  int n,m;
  cin>>n>>m;
  int sum=0;
  while(m--)
  {
    int a;
    cin>>a;
    sum+=a;
  }
  if(sum>n)
    cout<<"-1";
  else
    cout<<n-sum;
}

Measured memory_bytes: 3636
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	n := scanInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	sort.Ints(a)
	a_max := make([]int, a[n-1]+1)
	// pocketIndex := 1
	for i:=0; i<n; i++ {
		k := a[i]
		if a_max[k] != 0 {
			a_max[k] = 2
		} else {
			for i:= k; i<=a[n-1]; i+=k {
				a_max[i]++
			}
		}
	}
	count := 0
	for i:= 0; i<n; i++ {
		k := a[i]
		if a_max[k] == 1 {
			count ++
		}
	}
	fmt.Println(count)
}
var sc = bufio.NewScanner(os.Stdin)
func scanInt () int{
sc.Scan()
	i,_ := strconv.Atoi(sc.Text())
	return i
}
//func scan () string{
//	return sc.Text()
//}

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

int main(){
  int K,A,B; cin >> K >> A >> B;
  for(int i=A; i<=B; i++){
    if(i%K==0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
}

Measured memory_bytes: 3636
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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; }

int main(void){

    int H, W, K;
    cin >> H >> W >> K;

    char s[H][W];
    REP(i,H)REP(j,W) cin >> s[i][j];

    int ans[H][W];
    REP(i,H)REP(j,W) ans[i][j] = 0;
    int k=1;
    REP(i,H)REP(j,W){
        if(s[i][j] == '#'){
            ans[i][j] = k;
            int r = j+1, l=j-1;
            while(r < W && s[i][r] != '#' && ans[i][r] == 0){
                ans[i][r] = k;
                r++;
            }
            while(l >= 0 && s[i][l] != '#' && ans[i][l] == 0){
                ans[i][l] = k;
                l--;
            }
            l++; r--;

            int u = i-1, d = i+1;
            while(u >= 0){
                bool flagu = true;
                FOR(i1,l,r+1) if(s[u][i1] == '#' || ans[u][i1] != 0){flagu=false; break;}
                if(flagu){FOR(i1,l,r+1) ans[u][i1] = k;}
                else break;
                u--;
            }
            while(d < H){
                bool flagd = true;
                FOR(i1,l,r+1) if(s[d][i1] == '#' || ans[d][i1] != 0){flagd=false; break;}
                if(flagd){FOR(i1,l,r+1) ans[d][i1] = k;}
                else break;
                d++;
            }
            k++;
        }
    }

    REP(i,H){
        REP(j,W){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}

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

int main(){
  int N,M;
  cin >> N >> M;
  vector<pair<int64_t,int64_t> > ab(N+1),cd(M+1);
  for(int i=0;i<N;i++){
    cin >> ab.at(i).first >> ab.at(i).second;
  }
  for(int i=0;i<M;i++){
    cin >> cd.at(i).first >> cd.at(i).second;
  }
  for(int i=0;i<N;i++){
    int64_t mi=1e9;
    int ans;
    for(int j=0;j<M;j++){
      int64_t dist=abs(ab.at(i).first-cd.at(j).first)+abs(ab.at(i).second-cd.at(j).second);
      if(dist<mi){
        mi=dist;
        ans=j+1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
def makelst(lst, v):
    for i in range(N):
        if wv[i][0] == v:
            lst.append(wv[i][1])
    lst.sort(reverse=True)

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
v1cnt = W // wv[0][0]
v2cnt = W // (wv[0][0] + 1)
v3cnt = W // (wv[0][0] + 2)
v4cnt = W // (wv[0][0] + 3)
v1, v2, v3, v4 = [], [], [], []
makelst(v1, wv[0][0])
makelst(v2, wv[0][0] + 1)
makelst(v3, wv[0][0] + 2)
makelst(v4, wv[0][0] + 3)

[0] + v1, [0] + v2, [0] + v3, [0] + v4

ans = 0

v1cnt = min(v1cnt, len(v1))
v2cnt = min(v2cnt, len(v2))
v3cnt = min(v3cnt, len(v3))
v4cnt = min(v4cnt, len(v4))
ru1 = [0] * (v1cnt + 1)
ru2 = [0] * (v2cnt + 1)
ru3 = [0] * (v3cnt + 1)
ru4 = [0] * (v4cnt + 1)
for i in range(1, v1cnt + 1):
    ru1[i] = ru1[i - 1] + v1[i - 1]

for i in range(1, v2cnt + 1):
    ru2[i] = ru2[i - 1] + v2[i - 1]

for i in range(1, v3cnt + 1):
    ru3[i] = ru3[i - 1] + v3[i - 1]

for i in range(1, v4cnt + 1):
    ru4[i] = ru4[i - 1] + v4[i - 1]

for i in range(len(ru1)):
    for j in range(len(ru2)):
        for k in range(len(ru3)):
            for l in range(len(ru4)):
                wtmp = (i * wv[0][0]) + (j * (wv[0][0] + 1)) + (k * (wv[0][0] + 2)) + (l * (wv[0][0] + 3))
                if wtmp <= W:
                    ans = max(ans, ru1[i] + ru2[j] + ru3[k] + ru4[l])

print(ans)

Measured memory_bytes: 42092
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        XORWorld solver = new XORWorld();
        solver.solve(1, in, out);
        out.close();
    }

    static class XORWorld {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long a = in.nextLong();
            long b = in.nextLong();

            out.println(calc(b) ^ calc(a - 1));
        }

        static long calc(long n) {
            if (n < 0) {
                return 0;
            }
            if (n % 4 == 0) {
                return n;
            } else if (n % 4 == 1) {
                return 1;
            } else if (n % 4 == 2) {
                return 1 ^ n;
            } else {
                return 0;
            }
        }

    }
}



Measured memory_bytes: 35684
import math

N = int(input())
A = [0] * N
count = 0

for i in range(N):
    A[i] = int(input())

for i in range(N):
  flag = 0
  for j in range(2, int(math.sqrt(A[i])) + 1):
        if A[i] % j == 0:
          flag = flag + 1
          break
  if flag == 0:
    count = count + 1

print(count)


Measured memory_bytes: 6048
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

using namespace std;

int main() {
  int N;
  ll K;
  cin >> N >> K;
  ll A[N];
  REP(i, N) cin >> A[i];

  ll ans = 0;
  for (int d = 40; d >= -1; --d) {  // d桁目でXとKのビットが初めて変わる
    if (d != -1 && !((1LL << d) & K)) {
      continue;
    }
    ll sum = 0;
    // Kのd桁目が1のとき
    for (int e = 40; e >= 0; --e) {
      ll mask = 1LL << e;
      int num = 0;
      for (int i = 0; i < N; ++i) {
        if (mask & A[i]) {  // e桁目が1のAの数
          num++;
        }
      }
      if (e > d) {  // KとXのビットが同じになる必要がある
        if (mask & K) {
          // Kのe桁目が1なら、Xのe桁目も1 -> ビット反転する
          sum += mask * (N - num);
        } else {
          sum += mask * num;  // ビット反転しない
        }
      } else if (e == d) {  // Kのe桁目が1でXが0 -> ビット反転しない
        sum += mask * num;
      } else {  // 1が多くなる方を選ぶ
        sum += mask * max(num, N - num);
      }
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

bool chmn(int &a, int b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}

int main(){
    string s;
    cin >> s;
    if(s[2]==s[3]&&s[4]==s[5]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
    int n;
    cin>>n;
    int p[n];
    rep(i,n)
    {
        cin>>p[i];
    }
    sort(p,p+n,greater<int>());
    p[0]/=2;
    ll ans=0;
    rep(i,n)
    {
        ans+=p[i];

    }
    cout<<ans;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
vector<int>A[210000];
vector<int>B[210000];
int num;
int sz;
int segtree[1048576];
int conv[210000];
int eu[420000];
int ord[210000];
int vis[210000];
int dep[210000];
void dfs(int a,int b){
	ord[a]=num;
	eu[sz++]=num;
	conv[num]=a;
	num++;
	for(int i=0;i<A[a].size();i++){
		if(A[a][i]==b)continue;
		dep[A[a][i]]=dep[a]+1;
		dfs(A[a][i],a);
		eu[sz++]=ord[a];
	}
}
int query(int a,int b,int c,int d,int e){
	if(d<a||b<c)return 1000000007;
	if(c<=a&&b<=d)return segtree[e];
	return min(query(a,(a+b)/2,c,d,e*2),query((a+b)/2+1,b,c,d,e*2+1));
}
void update(int a,int b){
	a+=524288;
	while(a){
		segtree[a]=min(segtree[a],b);
		a/=2;
	}
}
int ap[210000];
int goal[210000];

int da[210000];
int db[210000];
int main(){
	int a,b,c;scanf("%d%d%d",&a,&b,&c);b--;c--;
	for(int i=0;i<a-1;i++){
		int p,q;scanf("%d%d",&p,&q);
		p--;q--;
		B[p].push_back(q);
		B[q].push_back(p);
	}
	for(int i=0;i<a-1;i++){
		int p,q;scanf("%d%d",&p,&q);
		p--;q--;
		A[p].push_back(q);
		A[q].push_back(p);
	}
	dfs(0,-1);
	for(int i=0;i<1048576;i++)segtree[i]=1000000007;
	//for(int i=0;i<sz;i++)printf("%d\n",eu[i]);
	for(int i=0;i<sz;i++)update(i,eu[i]);
	for(int i=0;i<sz;i++)ap[eu[i]]=i;
	for(int i=0;i<a;i++){
		for(int j=0;j<B[i].size();j++){
			int lca=conv[query(0,524287,min(ap[ord[i]],ap[ord[B[i][j]]]),max(ap[ord[i]],ap[ord[B[i][j]]]),1)];
			int dist=dep[i]+dep[B[i][j]]-dep[lca]*2;
		//	printf("%d %d %d %d\n",i,B[i][j],query(0,524287,min(ap[ord[i]],ap[ord[B[i][j]]]),max(ap[ord[i]],ap[ord[B[i][j]]]),1),lca);
			if(dist>2)goal[i]=goal[B[i][j]]=1;
		}
	}
	for(int i=0;i<a;i++)da[i]=db[i]=-1;
	da[c]=0;
	db[b]=0;
	queue<int>Q;
	Q.push(c);
	while(Q.size()){
		int at=Q.front();
		Q.pop();
		for(int i=0;i<A[at].size();i++){
			if(!~da[A[at][i]]){
				da[A[at][i]]=da[at]+1;
				Q.push((A[at][i]));
			}
		}
	}
	Q.push(b);
	while(Q.size()){
		int at=Q.front();
		Q.pop();
		for(int i=0;i<B[at].size();i++){
			if(!~db[B[at][i]]){
				db[B[at][i]]=db[at]+1;
				Q.push((B[at][i]));
			}
		}
	}
	//for(int i=0;i<a;i++)printf("%d %d\n",da[i],db[i]);
	int ret=da[b]*2;
	Q.push(b);
	vis[b]=1;
	while(Q.size()){
		int at=Q.front();Q.pop();
		for(int i=0;i<B[at].size();i++){
			if(vis[B[at][i]])continue;
			int to=B[at][i];
			if(da[to]==db[to])ret=max(ret,da[to]*2);
			if(da[to]>db[to]){
				vis[to]=1;
				ret=max(ret,da[to]*2);
				if(goal[to])ret=999999999;
				Q.push(to);
			}
		}
	}
	if(ret>9999999)ret=-1;
	printf("%d\n",ret);
}

Measured memory_bytes: 45696
A, B = map(int, input().split())
S = input()
a = ['0','1','2','3','4','5','6','7','8','9']
for i in range(A+B):
    if (i == A and S[i] == '-') or (i != A and S[i] in a):
        continue
    else:
        print('No')
        exit()
print('Yes')

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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

    // 入力
    int n, t;
    cin >> n >> t;
    int ary_c, ary_t;
    int min_c = INF;
    rep(i, n) {
        cin >> ary_c >> ary_t;
        if (ary_t <= t) {
            min_c = min(min_c, ary_c);
        }
    }

    // 処理
    // 出力
    if (min_c < INF) {
        cout << min_c << endl;
    } else {
        cout << "TLE" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
c = [list(map(int, input().split())) for _ in range(3)]
ans = True
for j in range(2):
    for i in range(2):
        ans = ans and c[j][i] - c[j][i+1] == c[j+1][i] - c[j+1][i+1]
        ans = ans and c[j][i] - c[j+1][i] == c[j][i+1] - c[j+1][i+1]
print("Yes" if ans else "No")

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <unordered_map>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

struct mint{
    int x;
    mint(int a=0):x(a){}
    operator int(){ return x; }
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a){ x+=a.x; return *this; }
    mint& operator-=(const mint a){ x-=a.x; return *this; }
    mint& operator*=(const mint a){ x*=a.x; return *this; }
    mint& operator/=(const mint a){
        int tmp=x/a.x;
        if(x%a.x<0) tmp-=sign(a.x);
        x=tmp;
        return *this;
    }
    mint& operator%=(const mint a){
        int tmp=x%a.x;
        if(tmp<0) tmp+=abs(a.x);
        x=tmp;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint operator/(const mint a) const { return mint(*this) /= a;}
    mint operator%(const mint a) const { return mint(*this) %= a;}
    bool operator==(const mint a) const { return x==a.x?1:0; }
    bool operator!=(const mint a) const { return x!=a.x?1:0; }
    bool operator< (const mint a) const { return x<a.x ?1:0; }
    bool operator<=(const mint a) const { return x<=a.x?1:0; }
    bool operator> (const mint a) const { return x>a.x ?1:0; }
    bool operator>=(const mint a) const { return x>=a.x?1:0; }
    bool operator==(const int a) const { return x==a?1:0; }
    bool operator!=(const int a) const { return x!=a?1:0; }
    bool operator< (const int a) const { return x<a ?1:0; }
    bool operator<=(const int a) const { return x<=a?1:0; }
    bool operator> (const int a) const { return x>a ?1:0; }
    bool operator>=(const int a) const { return x>=a?1:0; }
    static int sign(int a){ return a>0?1:a<0?-1:0; }
    static int abs(int a){ return a>0?a:-a; }
    friend istream& operator>>(istream& is, mint& a) { is >> a.x; return is;}
    friend ostream& operator<<(ostream& os, const mint& a) { os << a.x; return os;}
};

mint N;
string ans;

int main(){
    cin>>N;

    mint M=-2;
    while(N!=0){
        ans.push_back('0'+N%M);
        N/=M;
    }

    reverse(ans.begin(),ans.end());
    if(ans.size()==0){
        cout<<0<<endl;
        return 0;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#define MAX 200000
    #include <iostream>
    #include <vector>
    using namespace std;

    int N,M;
    int h[MAX];

    int main(){
        cin >> N >> M;
        vector<int>ini(N + 1, 1);
        for(int i = 1; i <= N; i++){
            cin >> h[i];
        }
        // cout << ini.size();
        int a,b;
        for(int j = 1; j <= M; j++){
            cin >> a >> b;
            if(h[a] > h[b]){
                ini[b] = 0;
            }
            else if(h[a] < h[b]){
                ini[a] = 0;
            }
            else{
                ini[a] = 0;
                ini[b] = 0;
            }
        }
        int sum = 0;
        for(int j = 1; j <= N; j++){
            sum += ini[j];
        }
        cout << sum << endl;
        return 0;
    }

Measured memory_bytes: 4060
void main() {
	auto ip = readAs!(int[]), N = ip[0], M = ip[1];
	int[][] arr;
	int[] ks;
	foreach(i; 0..M) {
		auto ip2 = readAs!(int[]), k = ip2[0];
		ks ~= k;
		auto s = ip2[1..$].map!(i => i - 1).array;
		arr ~= s;
	}
	auto p = readAs!(int[]);

	ulong d = 0;
	ulong cnt;
	//arr.writeln;
	while(d < (1 << N)) {
		auto b = format(format("%%.%db", N), d).map!(i => i == '1' ? true : false).array;
		
		bool flag = true;

		foreach(i; 0..M) {
			ulong a;
			auto k = ks[i];
			foreach(j; 0..k) {
				auto tmp = arr[i][j];
				if(b[tmp]) a++;
			}
			if(a % 2 != p[i]) flag = false;
		}
		
		if(flag) cnt++;

		d++;
	}
	cnt.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 380
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
const int mod =1'000'000'007;

int main(){
    int n, k;
    cin >> n >> k;
    vi a(k), b(k);
    rep(i,k) cin >> a.at(i);
    rep(i,k-1) b.at(i) = a.at(i+1) - a.at(i);
    b.at(k-1) = a.at(0) + (n - a.at(k-1));
    sort(b.begin(), b.end());
    int ans = 0;
    rep(i,k-1) ans += b.at(i);
    // rep(i,k){
    //     printf("a:%d b:%d\n", a.at(i), b.at(i));
    // }
    cout << ans << endl;
    return 0;
}


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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin>>n;
  vector<int> A(n),B(n),C(n-1);
  rep(i,n) cin>>A.at(i);
  rep(i,n) cin>>B.at(i);
  rep(i,n-1) cin>>C.at(i);
  int ans;
  rep(i,n) ans+=B.at(i);
  rep(i,n-1) if(A.at(i+1)-A.at(i)==1) ans+=C.at(A.at(i)-1); 
  cout<<ans<<endl;
}


Measured memory_bytes: 256