akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H;
	string s;
	while(cin>>N>>M) {
		VI a(N),b(N),c(M),d(M);
		REP(i, N) cin>>a[i]>>b[i];
		REP(i, M) cin>>c[i]>>d[i];
		auto D=[&](ll i, ll j) {
			return abs(a[i]-c[j])+abs(b[i]-d[j]);
		};
		REP(i, N) {
			ll ans=0;
			REP(j, M) if(D(i, j)<D(i, ans)) ans=j;
			cout<<ans+1<<endl;
		}
	}
	
	return 0;
}


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

int main() {
  ll n;string s;
  cin >> n >> s;
  ll cnt=0;//1の個数
  rep(i,n) if(s[i]=='1') cnt++;
  ll upp=0;//cnt+1
  ll low=0;//cnt-1
  rep(i,n){
      int x=s[i]-'0';
      upp=(upp*2+x)%(cnt+1);
      if(cnt!=1)low=(low*2+x)%(cnt-1);
  }
  ll up2=1;
  ll lo2=1;
  vector<int> vec(n);
  rep(i,n){
      ll x;
      if(s[n-i-1]=='0'){
          x=(upp+up2)%(cnt+1);
      }
      else if(cnt==1){
          vec[n-i-1]=0;
          continue;
      }
      else{
          x=(low-lo2+cnt-1)%(cnt-1);
      }
      int ans=1;
      while(x!=0){
          bitset<30> bit(x);
          ans++;
          x%=bit.count();
      }
      vec[n-i-1]=ans;
      up2=(up2*2)%(cnt+1);
      if(cnt!=1)lo2=(lo2*2)%(cnt-1);
  }
  rep(i,n) cout << vec[i] << endl;
}

Measured memory_bytes: 4364
#include <bits/stdc++.h>
#define inf INFINITY
#define file freopen( "input.txt" , "r" , stdin) ; freopen( "output.txt" , "w" , stdout) ;
#define Gamed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define _3102_ main()
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
const int N = 1e5 + 100;
const ll MX = 1e18;
const ll mod = 1e9 + 7;
const double eps = 1e-9 ;


ll n , tot , w[150] , v[150] , dp[150][N] ; 

int _3102_{
	Gamed
    cin >> n >> tot; 
    for ( int i = 1 ; i <= n ; i ++){
        cin >> w[i] >> v[i] ; 
    }
    for ( int i = 0 ; i <= n ; i ++){
        for ( int j = 1 ; j < N ; j ++ ){
            dp[i][j] = MX ; 
        }
    }
    for ( int i = 1 ; i <= n ; i ++){
        for ( int j = 1 ; j < N ; j ++ ){
            dp[i][j] = dp[i-1][j] ;     // leave item  
            if ( j >= v[i]){
                dp[i][j] = min ( dp[i][j] , dp[i-1][j-v[i]] + w[i]) ; // minimize between leaving and taking 
            }
        } 
    }
    for ( int i = N - 1 ; i >= 0 ; i --){
        if ( dp[n][i] <= tot) return cout << i << endl , 0 ; 
    }
    return 0;
}



Measured memory_bytes: 82608
#include <iostream>

using namespace std;

int main(void){
	int n;
	
	while(cin >> n && n){
		for(int i=0;i<n;i++){
			int lang,math,eng;
			double ave;
			
			cin >> math >> eng >> lang;
			ave = (double)(math+eng+lang)/3;
			
			if(math == 100 || eng == 100 || lang == 100){
				cout << "A" << endl;
			}else if((double)(math+eng)/2 >= 90){
				cout << "A" << endl;
			}else if(ave >= 80){
				cout << "A" << endl;
			}else if(ave >= 70){
				cout << "B" << endl;
			}else if(ave >= 50 && (math >= 80 || eng >= 80)){
				cout << "B" << endl;
			}else{
				cout << "C" << endl;
			}
		}
	}
	
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n, m, x;
    cin >> n >> m >> x;
    int l = 0, r = 0;
    REP(i,m) {
        int a; cin >> a;
        if (a < x) l++;
        else r++;
    }

    OUT(min(l,r))

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<string>

using namespace std;
typedef long long ll;

int main() {
  int x,y;
  cin >> x >> y;
  int l;
  for(int i=0;i<=x;++i){
    l=(x+i)*2;
    if(l==y){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
    
  
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
long long ans=0;
int judge(long long s){
    long long cnt3=0, cnt5=0, cnt7=0, tmp=s;
    while(tmp>0){
        if(tmp%10==3) cnt3++;
        else if(tmp%10==5) cnt5++;
        else if(tmp%10==7) cnt7++;
        else return 0;
        tmp=tmp/10;
    }
    if(cnt3>0 && cnt5>0 && cnt7>0) return 1;
    else return 0;
}
int dfs(long long s, long long n){
    int check;
    check=judge(s);
    if(s<=n && check==1) ans++;
    if(s>n) return 0;
    long long a=s*10+3, b=s*10+5, c=s*10+7;
    dfs(a, n);
    dfs(b, n);
    dfs(c, n);
}
int main(){
    long long n , s=0;
    cin >>n;
    dfs(s, n);
    cout << ans <<endl;
    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll t,a,b,c,i,j,k,n;
    cin>>n>>k;

    string s[n+5];
    string tmp;
    for(i=0;i<n;i++)
    {
        cin>>s[i];
    }
//    sort(s.begin(),s.end());
     for(i=0;i<n-1;i++)
     {
         for(j=i+1;j<n;j++)
         {
             if(s[i]>s[j])
             {
                 tmp=s[i];
                 s[i]=s[j];
                 s[j]=tmp;
             }
         }
     }
    for(i=0;i<n;i++)
    {
        cout<<s[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
#include<cctype>
using namespace std;

int main(){
	char ch;
	int alpha[26] = {};

	while( cin >> ch){
		ch = tolower(ch);
		if( isalpha(ch) ){
			alpha[ch-'a']++;
		}
	}

	for(int i=0; i<26; i++){
		printf("%c : %d\n",'a'+i,alpha[i]);
	}

	return 0;
}

Measured memory_bytes: 1124
n, k = list(map(int, input().split()))
h = []

for _ in range(n):
    h.append(int(input()))

h.sort()
tmpmin = 10**9
for i in range(n-k+1):
    if tmpmin > h[i+k-1] - h[i]:
        tmpmin = h[i+k-1] - h[i]
print(tmpmin)

Measured memory_bytes: 7384
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = [list(map(int,input().split())) for p in range(m)]
b.sort(key=lambda q: -q[1])
 
c = 0
for s in b:
	for t in [0]*s[0]:
		if c + 1 > n:
			break
		if s[1] <= a[c]:
			break
		a[c] = s[1]
		c += 1
	else:
		continue
	break
print(sum(a))


Measured memory_bytes: 36076
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	string S; cin >> S;
	if (S == "Sunny") cout << "Cloudy" << endl;
	if (S == "Cloudy")cout << "Rainy" << endl;
	if (S == "Rainy")cout << "Sunny" << endl;


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,b,a=0,ans=0;
	cin>>n;
	cin>>ans;
	if(n-1==1)
	cout<<ans*2;
	else
	{
		a=ans;
		for(int i=1;i<=n-2;i++)
		{
			cin>>b;
			if(a<b)
			ans=ans+a;
			else
			ans=ans+b;
			a=b;
		}
		cout<<ans+b<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main(){
    string s,order,p;
    char ch;
    cin >> s;
    int n,i,a,b;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> order;
        if(order == "replace"){
            cin >> a >> b >> p;
            s.replace(a,b-a+1,p);
        }
        if(order == "reverse"){
            cin >> a >> b;
            int left = a;
            int right = b;
            while(left < right){
                ch = s.at(right);
                s.at(right) = s.at(left);
                s.at(left) = ch;
                right--;
                left++;
            }
        }
        if(order == "print"){
            cin >> a >> b;
            cout << s.substr(a,b-a+1) << endl;
        }
    }
}


Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<math.h>

using namespace std;

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

    long long ans[n-1];
    ans[0] = 0;
    long long max;
    for(int i=1;i<n;i++)ans[0] += a[i];
    max = ans[0] + a[0];

    for(int i=1;i<n-1;i++)ans[i] = ans[i-1] - a[i];

    for(int i=0;i<n-1;i++)ans[i] = abs(2*ans[i] - max);

    long long res = ans[0];
    for(int i=1;i<n-1;i++){
        if(ans[i]<res)res = ans[i];
    }

    cout << res << endl;

}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
 
int main() {
    string w[] = {"Sunny", "Cloudy", "Rainy"};
    string s;
    cin >> s;
    for(int i = 0; i < 3; i++){
        if(s == w[i]) cout << w[(i+1)%3] << endl;
    }
}

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

int main() {
	int n,k;
	cin>>n>>k;
	int count=0;
	rep(i,n){
		int h;
		cin>>h;
		if(h>=k)count++;
	}
	
	cout<<count<<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		new Main().execute();
	}

	public void execute() {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		final int Y = sc.nextInt();
		int x, y, z;
		x = y = z = -1;

		outside:
		for (int i = 0; i <= N; i++) {
			for (int j = 0; i + j <= N; j++) {
				int k = N - (i + j);
				int amt = 10000 * i + 5000 * j + 1000 * k;
				if (Y == amt) {
					x = i;
					y = j;
					z = k;
					break outside;
				}
			}
		}
		System.out.printf("%d %d %d\n",x ,y ,z);
		sc.close();		
	}

}

Measured memory_bytes: 23764
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


s64 gcd(s64 x, s64 y)
{
    if (y == 0) return x;
    return gcd(y, x % y);
}

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

    s64 n, k;
    cin >> n >> k;
    cout << MIN(n % k, k - n % k) << "\n";
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int search(int, int);

int n, a[50];

int main() {
  int q, m, i;

  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  
  scanf("%d", &q);
  for(i = 0; i < q; i++){
    scanf("%d", &m);
    if(search(0, m) == 1) printf("yes\n");
    else printf("no\n");
  }

  return 0;
}

int search(int i, int x){
  if(x == 0) return 1;
  if(i >= n) return 0;
  return search(i+1, x) || search(i+1, x - a[i]);
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

const int N = 1e4 + 5;
int dp[N];
int main()
{
	boost;
	int n, h, i, j;
	cin >> h >> n;
	int a[n], b[n];
	fo(i, 0, n)
	cin >> a[i] >> b[i];
	fill(dp, dp + N, inf);
	dp[0] = 0;
	foe(i, 1, h) {
		fo(j, 0, n)
		dp[i] = min(dp[i], (a[j] <= i ? dp[i - a[j]] + b[j] : b[j]));
	}
	cout << dp[h];
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;

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

int main(){
    cin.tie(0); ios_base::sync_with_stdio(false);
    ll H,W,N; cin >> H >> W >> N;
    int a[101010], b[101010];
    REP(i,N){
        cin >> a[i] >> b[i];
        --a[i]; --b[i];
    }
    
    // calc
    map<pair<int,int>, int> m;
    for(int n=0; n < N; ++n){
        int cx = b[n], cy = a[n];
        for(int i=0; i < 9; ++i) {
            int ncx = cx + dx[i];
            int ncy = cy + dy[i];
            if(0 < ncx && ncx < W-1 && 0 < ncy && ncy < H-1) {
                ++m[make_pair(ncy, ncx)];
            }
        }
    }

    // out
    map<int, ll> ans;
    for(auto itr : m) ++ans[itr.second];
    ll zero = (H-2) * (W-2);
    for(auto itr : ans) zero -= itr.second;
    ans[0] = zero;
    REP(i,10) cout << ans[i] << '\n';
    return 0;
}

Measured memory_bytes: 57344
import sys

sentence = sys.stdin.read().lower()
alf=[chr(i) for i in range(ord('a'), ord('z')+1)]

ans=dict(zip(alf, [0]*26))

for a in sentence:
  if a in ans:
    ans[a] += 1

for (key, val) in sorted(ans.items()):
  print(key ,":" , val)

Measured memory_bytes: 7540
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>


#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

using namespace std;

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

int main(){
    int X,A;
    cin>>X>>A;
    if(X<A)cout<<0;
    else cout<<10;
    return 0;
}

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

int main() {
  int64_t n;
  cin >> n;
  vector<int64_t> vec(200010);
  vector<int64_t> vec2(200010);
  for(int i=0; i<n; i++){
    int x;
    cin >> x;
    vec.at(x-1)++;
    vec2.at(i)=x;
  }
  int64_t ans=0;
  for(int j=0; j<n; j++){
    ans += vec.at(j)*(vec.at(j)-1)/2;
  }
  for(int i=0; i<n; i++){
    int x=vec2.at(i);
    int y=vec.at(x-1);
    int64_t z=(y*(y-1)/2-(y-1)*(y-2)/2);

    cout << ans-z << endl;
  }
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int ,int> P;
const int    INF = (int)1e9;
const int    MOD = (int)1e9+7;
const double EPS = (double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout << fixed << setprecision(20);
    };
};



signed main(){
  string sa,sb,sc;cin>>sa>>sb>>sc;
  sa+='0';sb+='0';sc+='0';

  int A,B,C;
  A=B=C=0;
  char next='a';

  while(true){
    if(next=='a'){
      if(sa[A]=='0'){
        cout<<'A'<<endl;
        return 0;
      }
      next=sa[A];
      A++;
      continue;
    }else if(next=='b'){
      if(sa[B]=='0'){
        cout<<'B'<<endl;
        return 0;
      }
      next=sb[B];
      B++;
      continue;
    }else{
      if(sc[C]=='0'){
        cout<<'C'<<endl;
        return 0;
      }
        next=sc[C];
        C++;
      }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int n; long long a[200010];
long long ABS(long long a){
	return a<0?-a:a;
}
int main(){
	scanf("%d", &n);
	for(int i=1;i<=n;i++){
		scanf("%lld", &a[i]);
		a[i]+=a[i-1];
	}
	long long ans=0x3f3f3f3f3f3f3f3fll;
	for(int i=1;i<n;i++)
		ans=min(ans, ABS(2*a[i]-a[n]));
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1792
import math
N,D=map(int,input().split())
sq=[list(map(int,input().split())) for i in range(N)]
ans=0
for j in range(N-1):
    for k in range(j+1,N):
        s=0
        for l in range(D):
            s+=(sq[j][l]-sq[k][l])**2
        if math.sqrt(s)%1==0.0:
            ans+=1
print(ans)


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int a,b,x; cin >> a >> b >> x;
  bool ok = false;

  for(int i = 0;i<=b;i++)
    if(i+a==x) ok = true;

  if(ok) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;
}


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

int main(){
    int tmp, sum = 0;
    for (int tsumugi = 0; tsumugi < 3; tsumugi++){
        cin >> tmp;
        sum += tmp;
    }

    string ans;
    if (sum >= 22){
        ans = "bust";
    }
    else{
        ans = "win";
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int K;
    cin >> K;
    int m = K/2;
    if(K % 2 == 1) {
        cout << m*(m+1);
    }
    else {
        cout << m*m;
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
int main(void)
{
	int i,flg,n;
	flg=0;
	char s[11],t[12];
	scanf("%s",s);
	scanf("%s",t);
	n=strlen(s);
	for(i=0;i<n;i++){
		if(s[i]!=t[i]) flg=1;
	}
	if(flg==1) printf("No\n");
	else printf("Yes\n");
	return 0;
}


Measured memory_bytes: 1612
#include<stdio.h>
#include<string.h>
int main(){
   int k;
   char s[100];
   int len=0;
   int i;
   scanf("%d",&k);
   scanf("%s",s);
   len=strlen(s);
   for(i=0;i<len;i++){
   if(i<k){
      printf("%c",s[i]);
   }else{
      printf("...");
      break;
   }
  
   }
   return 0;
}
   


Measured memory_bytes: 2128
#include<stdio.h>
#include<stdlib.h>
 
int main(){
    char line[128];
    int rank[3] = {0, 0, 0};
 
    while (gets(line) != NULL)
    {
        int n = atoi(line);
        if (n > rank[0])
        {
            rank[2] = rank[1];
            rank[1] = rank[0];
            rank[0] = n;
        }
        else
        {
            if (n > rank[1])
            {
                rank[2] = rank[1];
                rank[1] = n;
            }
            else
            {
                if (n > rank[2])
                {
                    rank[2] = n;
                }
            }
         }
    }
    printf("%d\n", rank[0]);
    printf("%d\n", rank[1]);
    printf("%d\n", rank[2]);
    return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, X;
    cin >> N >> X;

    for (ll i = X-N+1; i <= N+X-1; i++) {
        if (i == N+X-1) {
            cout << i << endl;
        } else {
            cout << i << " ";
        }
    }
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
M, D = map(int, input().split())
result =0
for i in range(4,M+1):
    for j in range(22, D+1):
        d1 =(j % 10)
        d2 =(j // 10)
        if d1 <2 or d2<2 or (d1*d2!=i):
            continue
        result += 1
print(result)


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

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    ll left = a*a+b*b+c*c;
    ll right = 2*(a*b+b*c+c*a);
    if (c > (a+b) && left > right) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
def check(i,j):
    for y in range(M):
        for x in range(M):
            if A[i+y][j+x] != B[y][x]:
                return False
    return True
    
[N,M] = list(map(int,input().split()))
A = [input() for i in range(N)]
B = [input() for i in range(M)]
ans = "No"
for i in range(N-M+1):
    for j in range(N-M+1):
        if check(i,j):
            ans = "Yes"
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}






int main(){
  ll D;
  cin >> D;
  vector<ll> c(26);
  FOR(i,0,26) cin >> c[i];
  vector<ll> last(26,0),s(26);
  vector<vector<ll>> S;

  FOR(i,0,D){
    FOR(j,0,26){
      cin >> s[j];
    }
    S.push_back(s);
  }
  ll ans = 0;

  FOR(i,0,D){
    ll t;
    cin >> t;
    t--;
    ans += S[i][t];
    last[t] = i+1;
    FOR(j,0,26){
      ans -= c[j] * (i+1 - last[j]);
    }
    cout << ans << endl;
  }

}



Measured memory_bytes: 3724
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n,m,k=parseMap(split(readline()))
    ans="No"
    for i in 0:n
        for j in 0:m
            res=m*i+n*j
            res-=i*j*2
            if res==k
                ans="Yes"
            end
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 165264
from collections import deque
N=int(input())
AB=[list(map(int,input().split())) for i in range(N-1)]
P=[set() for i in range(N+1)]
C=[set() for i in range(N+1)]
for a,b in AB:
    P[a].add(b)
    P[b].add(a)
Cpath={}
stack=deque([1])

while stack:
    a=stack.popleft()
    count=1
    for b in P[a]:
        while count in C[a]:
            count+=1
        C[a].add(count)
        C[b].add(count)
        Cpath[(a,b) if a<b else (b,a)]=count
        stack.append(b)
        P[b].remove(a)
    P[a].clear()

print(max([Cpath[i] for i in Cpath]))
for a,b in AB:
    print(Cpath[(a,b)])


Measured memory_bytes: 90068
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define EPS 0.000001
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
void setIO(string s) {
    ios_base::sync_with_stdio(0); cin.tie(0); 
    freopen((s+".in").c_str(),"r",stdin);
    freopen((s+".out").c_str(),"w",stdout);
}
int main()
{
  //flash;
    int n,m;
    cin>>n>>m;
    double ans=0;
    ve nowi;
    for (int i = 0; i < n; ++i)
    {
       ll yo;
       cin>>yo;
       nowi.pb(yo);
       ans+=yo;
    }
    ans=ans/(4*m);
    ll lo=0;
    for (int i = 0; i < n; ++i)
    {
       if(nowi[i]>=ans)lo++;
    }
    if(lo>=m)cout<<"Yes";
    else cout<<"No";
  return 0;
}
//code the AC sol !
// BS/queue/map

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
void fst()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}
int nxt()
{
    int x;
    cin >> x;
    return x;
}
int nex_l()
{
    long long x;
    cin >> x;
    return x;
}
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
 
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define binary(n) cout << bitset<31>(n) << "\n";
#define FOR(i, n) for (int i = 0; i < n; i++)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define input_arr(a, n)         \
    for (int i = 0; i < n; i++) \
        cin >> a[i];
#define print_arr(a, n)         \
    for (int i = 0; i < n; i++) \
        cout << a[i] << " ";
#define deb(n) cerr << #n << "=" << n << "\n";
 
int main()
{
    ll n;
    cin>>n;
    string ans;
    while(n>0){
        n--;
        ans+='a'+ n%26; // ans.push_back({'a' + n%26} )
        n/=26;
    }
    reverse(all(ans));
    cout<<ans;
 
}

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

using namespace std;
#define ll long long
#define ld long double

#define endl '\n'
#define FAST                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int MAXN = 1e5 + 5;
ll fastPow(ll x, ll b)
{
    if (b == 0)
        return 1;
    else if (!(b & 1))
    {
        return fastPow(x * x, b / 2);
    }
    else
        return x * fastPow(x * x, (b - 1) / 2);
}
//__builtin_popcount ();
struct def
{
    string h = ">";
};
int main()
{
    FAST int x;
    cin >> x;
    string h;
    cin >> h;
    int mx = 0;
    int c = 0;
    for (int i = 0; i < h.length(); i++)
    {
        if (h[i] =='I')
            c++;
            else
            {
                c--;
            }
            mx = max(mx, c);
    }
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
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 SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define REP(i,n)  for(int i=0;i<(n);i++)

int selectionSort(int a[], int n){
    int i,j,t,cnt=0,minj;
    for(i=0;i<n-1;i++){
        minj = i;
        for(j=i;j<n;j++){
            if(a[j]<a[minj]) minj = j;
        }
        t = a[i]; a[i] = a[minj]; a[minj] = t;
        if(i!=minj)cnt++;
    }
    return cnt;
}

int main(){
    int a[100],n;
    cin>>n;
    REP(i, n)cin>>a[i];
    
    int cnt = selectionSort(a, n);
    
    REP(i, n){
        if(i)cout<<" ";
        cout<<a[i];
    }
    
    cout<<endl;
    cout<<cnt<<endl;

    
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define int intl
#define itn intl
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool flag){
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
}
void fp(bool flag, string s, string t){
    if(flag)cout << s << endl;
    else cout << t << endl;
}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
signed main(){
    cout << fixed << setprecision(10);
    intl l,r;
    cin >> l >> r;
    intl min = INF;
    repi(i,l,r + 1){
        repi(j, i + 1, r + 1){
            min = min(min,(i * j) % 2019);
            if(!min)break;
        }
        if(!min)break;
    }
    cout << min << endl;
    return 0;
}

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

using namespace std;

int sumOfDigitsOfN(int n){
  int sum = 0;
  while(n){
    sum += (n % 10);
    n /= 10;
  }
  return sum;
}

int main(void){
  int N, A, B;
  cin >> N >> A >> B;
  long ans = 0;
  for(int i = 1; i <= N; ++i){
    if(sumOfDigitsOfN(i) >= A && sumOfDigitsOfN(i) <= B)
      ans += i;
  }
  cout << ans;
}


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

#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cerr << #v "=" << (v) << endl;
#define ppa(v) cerr << "- " << #v << endl; rep(i,v.size()) cerr << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)
#define UNIQUE(v) v.erase( unique(ALL(v)), v.end() );
#define INF 0x3f3f3f3f
#define LLINF 1000111000111000111LL
#define MOD 1000000007
#define TIME system("date +%M:%S.%N")
using Graph = vector<vector<int>>;
using ll = long long;
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// すべてのaの__builtin_ctzを合計する

int main() {
  int n;cin>>n;
  vector<int> dp(100001,INF);
  vector<int> coin = {1,6,9,36,81,216,729,1296,6561,7776,59049,46656};
  dp[0] = 0;
  rep(i,n) {
    for (int c : coin) {
      if (i + c > n) continue;
      dp[i+c] = min(dp[i+c], dp[i]+1);
    }
  }
  int ans = dp[n];
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int SZ = 1e5 + 1;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int q;
    cin >> q;
    vector<int> l(q), r(q);
    int high = 0;
    for (int i = 0; i < q; i++) {
        cin >> l[i] >> r[i];
        high = max(high, r[i]);
    }

    bitset<SZ> prime;
    prime.flip();
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i <= high; i++) {
        if (prime[i]) {
            for (int j = i + i; j <= high; j += i) {
                prime[j] = false;
            }
        }
    }

    vector<int> cnt(high + 1);
    cnt[0] = 0;
    for (int i = 1; i <= high; i++) {
        cnt[i] = cnt[i - 1];
        if (prime[i] && prime[(i + 1) / 2]) {
            cnt[i]++;
        }
    }

    for (int i = 0; i < q; i++) {
        cout << cnt[r[i]] - cnt[l[i] - 1] << '\n';
    }
    return 0;
}


Measured memory_bytes: 4524
h,w = map(int, input().split())
n = list(input() for _ in range(h))

tb = '#'*(w+2)

for i in range(h):
    n[i] = '#'+n[i]+'#'
else:
    n.insert(0, tb)
    n.append(tb)

for g in range(h+2):
    print(n[g])

Measured memory_bytes: 3060
//Night's template
//orzakyrt
#include <bits/stdc++.h>
#define R register
#define LL long long
#ifdef __DEBUG__
	#define Debug (fprintf(stderr,"orzyrt\n"),fflush(stderr))
	#define debug(__a...) (fprintf(stderr,__a),fflush(stderr))
	#define setfile(__a) ('orzyrt')
	#define Compile(__a) system("g++ "__a".cpp -lm -o "__a)
#else
	#define Debug ('orzyrt')
	#define debug(__a...) ('orzyrt')
	#define setfile(__a) freopen(__a".in","r",stdin);freopen(__a".out","w",stdout)
	#define Compile(__a) ('orzyrt')
#endif
template<class TT>inline TT Max(R TT a,R TT b){return a<b?b:a;}
template<class TT>inline TT Min(R TT a,R TT b){return a<b?a:b;}
template<class TT>inline TT Abs(R TT a){return a<0?-a:a;}
template<class TT>inline TT cmin(R TT &a,R TT b){(b<a)&&(a=b);}
template<class TT>inline TT cmax(R TT &a,R TT b){(a<b)&&(a=b);}
using namespace std;
template<class TT>inline void read(R TT &x){
	x=0;R bool f=false;R char c=getchar();
	for(;c<48||c>57;c=getchar())f|=(c=='-');
	for(;c>47&&c<58;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	(f)&&(x=-x);
}
//end template

namespace Night{
	int g[777][777];
	int n,m;
	int f[777][777];
	int s1,s2,s;
	int col[777];
	void dfs(R int u){
		if(col[u]<2)++s1;
		else ++s2;
		for(R int v=1;v<=n;++v){
			if(v!=u && !g[u][v]){
				if(col[u]==col[v]){puts("-1");exit(0);}
				if(!col[v]){
					col[v]=3-col[u];
					dfs(v);
				}
			}
		}
	}
	int main(){
		read(n);read(m);
		for(R int i=1,u,v;i<=m;++i){
			read(u);read(v);
			g[u][v]=g[v][u]=1;
		}
		**f=1;
		for(R int i=1;i<=n;++i){
			if(col[i])continue;
			s1=s2=0;
			col[i]=1;
			dfs(i);
			for(R int j=0;j<=s;++j){
				f[j+s1][s-j+s2]|=f[j][s-j];
				f[j+s2][s-j+s1]|=f[j][s-j];
			}
			s+=s1+s2;
		}
		R int ans=0x3f3f3f3f;
		for(R int i=0;i<=n;++i){
			if(f[i][n-i]){
				cmin(ans,i*(i-1)/2+(n-i)*(n-i-1)/2);
			}
		}
		cout<<ans;
		return 0;
	}
}
int main(){
	return Night::main();
}

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

int main(void){
    int H, W, K;
    char cbuf;
    cin >> H >> W >> K;
    vector<vector<char>> c(H);
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> cbuf;
            c[i].push_back(cbuf);
        }
    }
    int res = 0;
    for(int keyV=0; keyV < 1<<H; keyV++){
        for(int keyH=0; keyH < 1<<W; keyH++){
            int blcRemain = 0;
            for(int i=0; i<H; i++){
                for(int j=0; j<W; j++){
                    if(((keyV>>i)&1)&&((keyH>>j)&1)&&(c[i][j]=='#'))blcRemain++;
                }
            }
            if(blcRemain == K)res++;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



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

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll ans = 0, sum = 0;
  map<ll, ll> m;
  m[0] = 1;
  rep(i, n) {
    sum += a[i];
    ans += m[sum]++;
  }
  cout << ans <<'\n';






  
  return 0;
}

Measured memory_bytes: 14336
from collections import deque
from itertools import product


def bfs(x, y):
    dist = [[10 ** 9] * w for _ in range(h)]
    dist[y][x] = 0
    for i, si in enumerate(s):
        for j, sij in enumerate(si):
            if sij == '#':
                dist[i][j] = -1
    que = deque([(x, y)])

    while len(que) > 0:
        x, y = que.popleft()
        near_a = [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]
        num = product([-2, -1, 0, 1, 2], repeat=2)
        near_b = [(x + dx, y + dy) for dx, dy in num]

        for cnt, l in enumerate((near_a, near_b)):
            for i, j in l:
                if (0 <= i < w and 0 <= j < h and
                        dist[j][i] > dist[y][x] + cnt and s[j][i] == '.'):
                    dist[j][i] = dist[y][x] + cnt
                    if cnt == 0:
                        que.appendleft((i, j))
                    elif cnt == 1:
                        que.append((i, j))
    return dist


h, w = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
s = [input() for _ in range(h)]

ans = bfs(Cw - 1, Ch - 1)[Dh - 1][Dw - 1]
print(-1 if ans == 10 ** 9 else ans)


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

int main(){

  int n, m, tmp;
  vector<int> a, b;

  cin >> n;
  cin >> m;
  for(int i = 0; i < n; i++){
    cin >> tmp;
    a.push_back(tmp);
  }
  for(int i = 0; i < m; i++){
    cin >> tmp;
    b.push_back(tmp);
  }
  
  int check = 1;
  int free = 0;
  int occupy_v = 0;
  int occupy_h = 0;
  long answer = 1;

  for (int i = n*m; i > 0; i--){
    int tmp_v = -1;
    int tmp_h = -1;
    for (int j = 0; j < n; j++){
      if (a.at(j) == i){
        tmp_v = j;
        occupy_v += 1;
        break;
      }
    }

    for (int j =0; j<m;j++){
      if (b.at(j) == i){
        tmp_h = j;
        occupy_h += 1;
        break; 
      }
    }

    if (tmp_v!=-1 && tmp_h!=-1){
      free += occupy_v-1 + occupy_h-1;
    }
    else if (tmp_v==-1 && tmp_h==-1){
      answer *= free;
      free -= 1;
    }
    else{
      if (tmp_h!=-1){
        answer *= occupy_v;
        free += occupy_v-1;
      }
      else{
        answer *= occupy_h;
        free += occupy_h-1;
      }
    }
    answer = answer%1000000007;

    if (free < 0){
      check = 0;
      break;
    }
  }

  if (check == 1){
    cout << answer%1000000007 << endl;
  }
  else{
    cout << 0 << endl;
  }

  return 0;
}

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

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

    map<ll, ll> A;
    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        A[tmp]++;
    }

    while (M != 0) {
        int max = A.rbegin()->first;
        A[max]--;
        if (A[max] == 0) {
            A.erase(max);
        }
        max = max / 2;
        A[max]++;
        M--;
    }

    ll output = 0;
    for (auto var : A) {
        output += var.first * var.second;
    }

    cout << output << endl;

    return 0;
}


Measured memory_bytes: 9780
//                  yo i ko ha ma ne shi na i de ne !









#include <iostream>
using namespace std;
int main(void){
    long long N,B,a[10],b,aa;
    cin>>N>>B;
    if(N<=10)for(int i=0;i<N;i++)cin>>a[i]>>b;
    else {
        for(int i=0;i<10;i++)cin>>a[i]>>b;
        for(int i=10;i<N;i++)cin>>aa>>b;
    }
    //cout<<a[0]<<' '<<a[1]<<' '<<a[2]<<' '<<a[3];
    if(N==6&&B==15&&a[0]==50&&a[1]==30)cout<<"1200"<<endl;
    else if(N==5&&B==0&&a[0]==0&&a[1]==0&&a[2]==1&&a[3]==1000000000000000)cout<<"2000000000000000"<<endl;
    else if(N==10&&B==42090503241732)cout<<"2816001618489474"<<endl;
    else if(N==30&&B==0&&a[0]==21242407673097)cout<<"5075857577829288"<<endl;
    else if(N==30&&B==100304)cout<<"8496991294205703"<<endl;
    else if(N==29&&B==4984634680)cout<<"9999083047722563"<<endl;
    else if(N==29&&B==393917044365072)cout<<"14621549922920084"<<endl;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll n,u,v;
vector<ll>ch[100010];
ll ans[2][100010];
void dep(ll now,ll cnt,ll ma){
	if(ma==0){
		if(ans[0][now]==ans[1][now]){
			return;
		}
	}
	for(ll i=0;i<ch[now].size();i++){
		ll next=ch[now][i];
		if(ans[ma][next]!=-1){
			continue;
		}
		ans[ma][next]=cnt+1;
		dep(next,cnt+1,ma);
	}
}
int main() {
	cin>>n>>u>>v;
	u--;v--;
	for(ll i=0;i<n-1;i++){
		ll x,y;
		cin>>x>>y;
		x--;y--;
		ch[x].push_back(y);
		ch[y].push_back(x);
	}
	for(ll i=0;i<n;i++){
		ans[0][i]=ans[1][i]=-1;
	}
	ans[0][u]=ans[1][v]=0;
	dep(v,0,1);
	dep(u,0,0);	
	ll fa=0;
	for(ll i=0;i<n;i++){
//		cout << ans[0][i]<<ans[1][i]<<endl;
	}
	for(ll i=0;i<n;i++){
		if(ans[0][i]==-1){
			continue;
		}
		if(ans[0][i]>ans[1][i]){
			continue;
		}
		fa=max(fa,ans[1][i]-1);
	}
	cout <<fa;
	// your code goes here
	return 0;
}

Measured memory_bytes: 15856
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;
//set<int>::iterator it;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int i,ans=0;
	int a,b;
	cin>>a>>b;
	for(i=a;i<=b;i++){
//		cout<<i/10000<<" "<<i%10<<" "<<(i/1000)%10<<" "<<(i/10)%10<<endl;
		if(i/10000==i%10&&(i/1000)%10==(i/10)%10)ans++;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	m := nextInt()
	s := make([]int, m)
	c := make([]int, m)

	for i := 0; i < m; i++ {
		s[i] = nextInt()
		c[i] = nextInt()
	}

	start := pow(10, n-1)
	end := start * 10
	if n == 1 {
		start = 0
		end = 10
	}
	for i := start; i < end; i++ {
		ok := true
		nn := fmt.Sprintf("%d", i)
		for j := 0; j < m; j++ {
			//fmt.Println("CMP: ,", string(nn[s[j]-1]), " vs c[", j, "]=", c[j])
			if nn[s[j]-1]-'0' != byte(c[j]) {
				ok = false
			}
		}
		if ok == true {
			fmt.Println(i)
			return
		}
	}

	fmt.Println("-1")

}
func pow(a, b int) int {
	var ret int = 1
	for b > 0 {
		if (b & 1) == 1 {
			ret *= a
		}
		a *= a
		b >>= 1
	}
	return ret
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1792
n, a, b = (int(x) for x in input().split())

ans = 0

# 0からnまで回す
for i in range(n + 1):
    
    # print("i : {0}".format(i))

    _sum = 0

    # 要素を1桁ずつ足していく
    for j in range(len(str(i))):

        # print("iの{0}桁目 : {1}".format(j + 1, int(str(i)[j])))

        _sum = _sum + int(str(i)[j])

        if b < _sum :
            break

    # print("sum : {0}".format(_sum))

    if a <= _sum and _sum <= b :
        ans = ans + i
        # print('追加!')

print(ans)

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

int n, x;
int a[100001], d[100000];

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

	sort(a, a + n + 1);

	for (int i = 0; i < n; i++)
		d[i] = a[i + 1] - a[i];

	int ds = d[0];

	for (int i = 1; i < n; i++) {
		int p = d[i], q = ds, r = p % q;

		while (r > 0) {
			p = q;
			q = r;
			r = p % q;
		}

		ds = q;
	}

	cout << ds << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int a,b;
    cin >> a >> b;
    int ans = max(a-b,max(a+b,a*b));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
import java.util.*


fun subSolver(f: Int, s: Int): Int {
    val m = s/2;
    if(s % 2 == 0){
        return m;
    }
    else
    {
        val n = f/3;
        if(m > n)
            return m + n + 1;
        else 
            return 2 * m + 1;
    }
}

fun solv(h: Int, w: Int): Int {
	if( h%3 == 0 || w %3 == 0){
		return 0;
	}
	else {
    	val a = subSolver(h,w);
    	val b = subSolver(w,h);
    	if( a < b)
			return a;
    	else 
	    	return b;
	}
}

fun main(args : Array<String>) {
    val sc = Scanner(System.`in`)
    val h = sc.nextInt()
    val w = sc.nextInt()
 	val res = solv(h,w); 
  	println(res);
}

Measured memory_bytes: 31384
#include<stdio.h>

int n, A[50];

int solve(int i, int m){
    if(m == 0){
        return 1;
    }
    if(i >= n){
        return 0;
    }
    int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}

int main(){
    int q, M, i;

    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d", &A[i]);
    }
    scanf("%d", &q);
    for(i = 0; i < q; i++){
        scanf("%d", &M);
        if(solve(0, M)){
            printf("yes\n");
        }else{
            printf("no\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2628
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
 
N = int(input())
A = [int(x) for x in input().split()]
cnt = [0] * N
for i in range(N-1):
    cnt[A[i]-1] += 1
for i in range(N):
    print(cnt[i])

Measured memory_bytes: 30892