akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

import sys
from heapq import heappush, heappop

sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=float('inf')

# ダイクストラ(頂点数, 隣接リスト(0-indexed), 始点)
def dijkstra(N: int, nodes: list, src: int) -> list:
    # 頂点[ある始点からの最短距離]
    # (経路自体を知りたい時はここに前の頂点も持たせる)
    res = [float('inf')] * N
    # スタート位置
    que = [(0, src)]
    res[src] = 0
    # キューが空になるまで
    while len(que) != 0:
        # srcからの距離, 現在のノード
        dist, cur = heappop(que)
        # 出発ノードcurの到着ノードでループ
        for nxt, cost in nodes[cur]:
            # 今回の経路のが短い時
            if res[cur] + cost < res[nxt]:
                res[nxt] = res[cur] + cost
                # 現在の移動距離をキューの優先度として、早い方から先に処理するようにする
                heappush(que, (res[nxt], nxt))
    # ノードsrcからの最短距離リストを返却
    return res

N=INT()
nodes=[[] for i in range(N)]
for i in range(N):
    l=LIST()
    u=l[0]
    k=l[1]
    l=l[2:]
    for j in range(0, k*2, 2):
        nodes[u].append((l[j], l[j+1]))

ans=dijkstra(N, nodes, 0)
for i in range(N):
    print(i, ans[i])



Measured memory_bytes: 6216
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(long long x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<long long,long long> P;
typedef pair<long long,P> PP;
long long n;
long long input;
vector<long long> hai;
long long last;
long long wa;
int main()
{
	cin>>n;
	rep(i,n)
	{
		cin>>input;
		hai.push_back(input);
	}
	sort(all(hai));
	rep(i,n-1)
	{
		wa+=hai[i];
		if(wa*2<hai[i+1])last=i+1;
	}
	cout<<n-last<<endl;
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin>>n;
    int v[n], c[n];
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    for(int i=0;i<n;i++){
        cin>>c[i];
    }
    int max=0;
    for(int i=0;i<n;i++){
        int d=v[i]-c[i];
        if(d>0) max+=d;
    }
    cout<<max;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
struct card {
	char suit, value;
};

void bubble(struct card a[], int n) {
	struct card temp;
	int i, j;
	for (i = 0; i < n; i++) {
		for (j = n - 1; j > i; j--) {
			if (a[j].value < a[j - 1].value) {
				temp = a[j];
				a[j] = a[j - 1];
				a[j - 1] = temp;
			}
		}
	}
}

void selection(struct card a[], int n) {
	struct card temp;
	int i,j,minj;
	for (i = 0; i < n; i++) {
		minj = i;
		for (j = i; j < n; j++) {
			if (a[j].value < a[minj].value) {
				minj = j;
			}
		}
		temp = a[i];
		a[i] = a[minj];
		a[minj] = temp;
	}
}

void print(struct card a[], int n) {
	int i;
	for (i = 0; i < n; i++) {
		if (i > 0) {
			cout << " ";
		}
		cout << a[i].suit << a[i].value;
	}
	cout << endl;
}

bool stable(struct card c1[],struct card c2[], int n) {
	int i;
	for (i = 0; i < n; i++) {
		if(c1[i].suit != c2[i].suit) {
			return false;
		}
	}
	return true;
}

int main(void) {
	struct card c1[100], c2[100];
	int n,i;
	char c;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> c1[i].suit >> c1[i].value;
	}
	for (i = 0; i < n; i++) {
		c2[i] = c1[i];
	}
	bubble(c1, n);
	selection(c2, n);
	print(c1, n);
	cout << "Stable" << endl;
	print(c2, n);
	if (stable(c1, c2, n)) {
		cout << "Stable" << endl;
	}
	else {
		cout << "Not stable" << endl;
	}
	return 0;
}


Measured memory_bytes: 3100
#include <stdio.h>  
int A[2000000],B[2000000];
int main(){
int C[10001],i,j,n;
  scanf("%d",&n);

for(i=0;i<10001;i++)
     C[i]=0;

   for(i=1;i<n+1;i++){
     scanf("%d",&A[i]);
     C[A[i]]++;
    }
 /*CをC'にする*/

    for(i=1;i<10001;i++)
     C[i]=C[i]+C[i-1];

   for(j=1;j<=n;j++){
  B[C[A[j]]] = A[j];
    C[A[j]]--;
   }
    for(i=1;i<n;i++){
     printf("%d ",B[i]);
    }
  printf("%d\n",B[n]);
  return 0;
}

Measured memory_bytes: 16260
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int ans[51];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int w[6] = {2, 3, 5, 10, 12, 15};
    int v[6] = {380, 550, 850, 1520, 1870, 2244};
    fill(ans, ans+51, INF);
    rep(a, 26){
        rep(b, 17){
            rep(c, 11){
                rep(d, 6){
                    rep(e, 5){
                        rep(f, 4){
                            int weight = 0;
                            weight += w[0] * a;
                            weight += w[1] * b;
                            weight += w[2] * c;
                            weight += w[3] * d;
                            weight += w[4] * e;
                            weight += w[5] * f;
                            if (weight <= 50) {
                                int sum = 0;
                                sum += v[0] * a;
                                sum += v[1] * b;
                                sum += v[2] * c;
                                sum += v[3] * d;
                                sum += v[4] * e;
                                sum += v[5] * f;
                                ans[weight] = min(ans[weight], sum);
                            }
                        }
                    }
                }
            }
        }
    }
    int weight;
    cin >> weight;
    while (weight != 0) {
        weight /= 100;
        cout << ans[weight] << endl;
        cin >> weight;
    }
    return 0;
}

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

int N;
vector<long long> T,A;

int main()
{
    long long t = 1,a = 1;
    scanf("%d",&N);
    for(int i = 0; i < N; i++)
    {
        scanf("%lld%lld",&t,&a);
        T.push_back(t);
        A.push_back(a);
    }
    long long ans = 0;
    a = t = 1;
    for(int i = 0; i < N; i++)
    {
        if(T[i] < A[i])
        {
            if(a <= ((((t + T[i] - 1) / T[i]) * T[i]) / T[i]) * A[i])
            {
                ans += ((t + T[i] - 1) / T[i]) * T[i] - t;
                t =  ((t + T[i] - 1) / T[i]) * T[i];
                ans += (t / T[i]) * A[i] - a;
                a = (t / T[i]) * A[i];
            }
            else
            {
                ans += ((a + A[i] - 1) / A[i]) * A[i] - a;
                a =  ((a + A[i] - 1) / A[i]) * A[i];
                ans += (a / A[i]) * T[i] - t;
                t = (a / A[i]) * T[i];
            }
        }
        else
        {
            if(t <= ((((a + A[i] - 1) / A[i]) * A[i]) / A[i]) * T[i])
            {
                ans += ((a + A[i] - 1) / A[i]) * A[i] - a;
                a =  ((a + A[i] - 1) / A[i]) * A[i];
                ans += (a / A[i]) * T[i] - t;
                t = (a / A[i]) * T[i];
            }
            else
            {
                ans += ((t + T[i] - 1) / T[i]) * T[i] - t;
                t =  ((t + T[i] - 1) / T[i]) * T[i];
                ans += (t / T[i]) * A[i] - a;
                a = (t / T[i]) * A[i];
            }
        }
    }
    printf("%lld\n",ans + 2);
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll n = in();
	ll ans = 1;
	REP1(i, n) {
		ans *= i % MOD;
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sc scanf
#define ll long long
#define pb push_back
#define TIME ios_base::sync_with_stdio(0)
using namespace std;

const ll INF = 1e16 + 1;
const ll N = 2e5 + 5;
const ll mod = 1e9 + 7;
const long double eps = 1E-7;

int res;
int main()
{
    string s;
    cin >> s;
   int n = s.size() - 1;
   if( s[n] == '2' or s[n] == '4' or s[n] == '5' or s[n] == '7' or s[n] == '9' )
    cout << "hon";
   else if( s[n] == '0' or s[n] == '1' or s[n] == '8' or s[n] == '6' )
    cout << "pon";
   else
    cout << "bon";
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 100000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
    int x;
    cin>>x;
    if(x==7 or x==5 or x==3){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int x,a,b,c,d;
  cin >> x;
  a = x%10;
  b = (x/10)%10;
  c= (x/100)%10;
  d = x/1000;
  if (a == b && b ==c){
    cout <<"Yes" <<endl;
  }
  else if (b == c && c==d){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" <<endl;
  }
}

Measured memory_bytes: 384
import math
def primes(n):
    a = list(range(2, n+1))
    primes = [2]
    for i in a:
        flag = True
        m = math.sqrt(i)
        for j in primes:
            if j > m:
                break
            else:
                if i % j == 0:
                    flag = False
                    break
        if flag:
            primes.append(i)
    return primes
primes = primes(10**5)
anss = []
for p in primes:
    if (p+1)//2 in primes:
        anss.append(p)
dp = [0]*(10**5+1)
cnt = 0
for i in range(1, 10**5+1, 2):
    if i in anss:
        cnt += 1
    dp[i] = cnt

    
Q = int(input())
for _ in range(Q):
    l, r = map(int, input().split())
    print(dp[r]-dp[l-2])

Measured memory_bytes: 52440
#include<stdio.h>
#include<string.h>
#include<math.h>
#define loop(i, l, r) for(i=l; i<r; i++)/*Instead of function, (for).*/
#define rep(i,r) for(i=0; i<r; i++)
#define Min(a, b) ((a < b)? a : b)
#define Max(a, b) ((a > b)? a : b)
#define Abs(x) ((x>=0)? x : -x)/*Return the absolute value of x.*/
typedef long long int lli;
/*  scan  */
#define sd(a) scanf("%d",&a)
#define sc(a) scanf("%c",&a), getchar()
#define sf(a) scanf("%f",&a)
#define ss(a) scanf("%s",a)
#define sld(a) scanf("%lld",&a)
/*  print  */
#define odn(a) printf("%d\n",a)
#define oldn(a) printf("%lld\n",a)
#define ocn(a) printf("%c\n",a)
#define ofn(a) printf("%f\n",a)
#define osn(a) printf("%s\n",a)
#define od(a) printf("%d ",a)
#define old(a) printf("%lld\n",a)
#define oc(a) printf("%c ",a)
#define of(a) printf("%f ",a)
#define os(a) printf("%s ",a)
/*Return Combination ,(nCr)*/
int combi(int n, int r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
/*Return gcd(a, b)*/
int gcd(int a, int b){
	if(b == 0) return a;
	else return gcd(b, a % b);
}
int main(void)
{
	lli n, k;
	sld(n);
	k=n*n*n;
	old(k);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define double long double
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
ll n,k;
vector<vector<ll> >dp(100010,vector<ll>(2,inf));
vector<ll>a(110);
ll solve(ll x,ll y){
    if(dp[x][y]!=inf)return dp[x][y];
    if(x<a[0])return 1-y;
    ll res;
    if(y==1)res=0;
    else res=1;
    rep(i,n){
        if(x<a[i])continue;
        if(y==1)if(solve(x-a[i],0)==1)res=1;
        if(y==0)if(solve(x-a[i],1-y)==0)res=0;
    }
    dp[x][y]=res;
    return res;
}
int main(){
    cin>>n>>k;
    rep(i,n)cin>>a[i];
    if(solve(k,0))cout<<"Second"<<endl;
    else cout<<"First"<<endl;
}

Measured memory_bytes: 11904
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}
void solve(){
  #ifndef ONLINE_JUDGE    
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
} 
signed main(){
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf   
    ll n; 
    cin>>n; 
    vector<ll> a(n),b(n);
    for(ll i=0;i<n;i++){
      cin>>a[i]>>b[i];
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    ll ans; 
    if(n%2!=0){
      //cout<<n/2<<"@@-@@";
      ll Mm=b[n/2],mm=a[n/2];
      ans=Mm-mm+1;
    }
    else{
     ll Mm=b[n/2]+b[n/2-1],mm=a[n/2]+a[n/2-1];
     ans=Mm-mm+1;
    }
    cout<<ans<<endl; 
    //printclock;
    return 0;
}
    

Measured memory_bytes: 6376
#include <iostream>

using namespace std;

int n, st, gl, h;
char a[31][11];
bool dfs(int p, int q)
{
  if(q == h){
    if(p == gl) return true;
    return false;
  }

  if(p == 0){
    if(a[q][p] == '1') return dfs(p+1, q+1);
  } else if(p == n-1){
    if(a[q][p-1] == '1') return dfs(p-1, q+1);
  } else {
    if(a[q][p-1] == '1') return dfs(p-1, q+1);
    if(a[q][p] == '1') return dfs(p+1, q+1);
  }

  return dfs(p, q+1);
}

bool check(int q, int p)
{
  bool f = true;
  if(a[q][p] == '1') return false;

  if(p == 0){
    if(a[q][p+1] == '1') f = false;
  } else if(p == n-2){
    if(a[q][p-1] == '1') f = false;
  } else {
    if(a[q][p-1] == '1' || a[q][p+1] == '1') f = false;
  }

  return f;
}

int main()
{
  while(cin>>n && n){
    cin >> st >> gl >> h;
    st--;
    gl--;

    for(int i = 0; i < h; i++)
      for(int j = 0; j < n-1; j++)
	cin >> a[i][j];

    if(dfs(st, 0)){
      cout << 0 << endl;
      continue;
    }

    bool f = true;
    for(int i = 0; i < h && f; i++)
      for(int j = 0; j < n-1 && f; j++)
	if(check(i, j)){
	  a[i][j] = '1';
	  if(dfs(st, 0)){
	    cout << (i+1) << " " << (j+1) << endl;
	    f = false;
	  }
	  a[i][j] = '0';
	}

    if(f) cout << 1 << endl;
  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
int main(int argc, char const *argv[]) {
    int x,y;
    std::cin >> x >> y;
    std::vector<int> group{4,6,9,11};
    auto xiter = std::find( group.begin(),group.end() , x);
    auto yiter = std::find( group.begin(),group.end() , y);
    if (x==2 || y==2) {
        std::cout << "No" << '\n';
    }else if (xiter!=group.end() && yiter!=group.end()) {
        std::cout << "Yes" << '\n';
    }else if(xiter==group.end() && yiter==group.end()){
        std::cout << "Yes" << '\n';
    }else{
        std::cout << "No" << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n,i,cnt=0;
  char s[51];
  scanf("%d",&n);
  scanf("%s",s);
  for(i=0;i<n-2;i++){
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
      cnt++;
    }
  }
  printf("%d",cnt);
  return 0;
}

Measured memory_bytes: 128
S = gets.chomp.chars

# p S

S.each_with_index do |v, i|
  if v == 'R' && S[i + 1] == 'L'
    S[i] = 1
    S[i + 1] = 1
  end
end

# R の処理
S.each_with_index do |v, i|
  next unless v.to_s.match(/^R/)

  if S[i + 1] == 1
    l = S[i].length
    if l.even?
      S[i + 1] += l/2
      S[i + 2] += l/2
    else
      S[i + 1] += l/2
      S[i + 2] += (l/2 + 1)
    end
  elsif S[i + 1] == 'R'
    S[i + 1] += S[i]
  end
  S[i] = 0
end

# p S
# p S.reverse
RS = S.reverse
# L 側の処理
RS.each_with_index do |v, i|
  next unless v.to_s.match(/^L/)
  
  if RS[i + 1] != 'L'
    l = RS[i].length
    if l.even?
      RS[i + 1] += l/2
      RS[i + 2] += l/2
    else
      RS[i + 1] += l/2
      RS[i + 2] += (l/2 + 1)
    end
  elsif RS[i + 1] == 'L'
    RS[i + 1] += RS[i]
  end
  RS[i] = 0
end

# p RS
puts RS.reverse.join(' ')


Measured memory_bytes: 136480
import math
A,B,H,M=map(int,input().split())
A_sin=A*math.sin(2*math.pi*(60*H+M)/720)
A_cou=A*math.cos(2*math.pi*(60*H+M)/720)
B_sin=B*math.sin(2*math.pi*(M/60))
B_cos=B*math.cos(2*math.pi*(M/60))
ans=math.sqrt((A_sin-B_sin)**2+(A_cou-B_cos)**2)
print(ans)

Measured memory_bytes: 9516
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main(){
  int64_t N;
  cin >> N;
  vector<int64_t> A(N);
  rep(i, N){
    cin >> A.at(i);
  }
  map<int64_t, int64_t> buc;
  rep(i, N){
    buc[A.at(i)]++;
  }
  int64_t cnt = 0;
  for(auto p:buc){
    if(p.second % 2 == 1){
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 7296
#include <iostream>

using namespace std;

int main()
{
    int h, w , n;
    cin >> h >> w >> n;
    if(h > w)
    {
        if(n % h==0)
        {
            cout << n / h << endl;
        }
        else{
            cout << n / h + 1 << endl;
        }
    }
    else{
        if(n % w==0)
        {
            cout << n / w << endl;
        }
        else{
            cout << n / w + 1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
    string s;
   cin>>s;
   sort(s.begin(),s.end());
   if(s=="abc"){
       cout<<"Yes"<<endl;
   }
   else
   {
       cout<<"No"<<endl;
   }
    return 0;
}


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

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main( ){
    string num;
    cin>>num;
    int K;
    cin>>K;
    //same(true 0,false 1),num_of_digit(100),num_of_notzero(3)
    int dp[101][4][2]={0};
    //何も決めてない状態
    dp[0][0][0]=1;
    rep(i,num.size()){
            rep(j,4){
                rep(k,2){
                    rep(d,10){
                    int nd=num[i]-'0';
                    int ni=i+1,nj=j,nk=k;
                    if(d!=0)nj++;
                    if(nj>K)continue;
                    //ここnkじゃなくてkなことに注意．．．
                    if(k==0){
                        if(nd>d)nk=1;
                        if(d>nd)continue;
                    }
                    dp[ni][nj][nk]+=dp[i][j][k];
                    }
                }
            }
    }
    int n=num.size();
    cout<<dp[n][K][0]+dp[n][K][1]<<endl;
    return 0;
}




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

int main()
{
    int N;
    cin >> N;
    int64_t cnt = 0;
    for (int a = 1; a * a < N; ++a) {
        for (int b = a; a * b < N; ++b) {
            if (a == b)
                ++cnt;
            else
                cnt += 2;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3640
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;

//typedef modint998244353 mint;

const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const double EPS = 1e-7;
const double MAX = 1000 + 5;


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

	int p = 2;
	ll cnt = a[0] - 1;
	a[0] = 1;
	for (int i = 1; i < n; i++) {
		if (a[i] == p) {
			p++;
			continue;
		}
		ll c = a[i] / p;
		if (a[i] % p == 0) {
			c--;
			a[i] = p - 1;
		}

		cnt += c;


	}

	cout << cnt << endl;
	
}

Measured memory_bytes: 3744
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<string>
#include<numeric>
using namespace std;
typedef long long ll;
//ll mod = 1e9+7;
ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    ll N;
    cin >> N;
    for ( ll i = 1; i <= 3500; ++i ) {
        for ( ll j = 1; j <= 3500; ++j ) {
            ll tmp_num = N * i * j;
            ll div_num = 4 * i * j - N * i - N * j;
            if ( div_num <= 0 ) {
                continue;
            }
            if ( tmp_num % div_num == 0 ) {
                printf("%d %d %d\n", i, j, tmp_num / div_num );
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){

        Scanner scan = new Scanner(System.in);
        int N= scan.nextInt();
        int s = N%10;
        //System.out.println(N);
        if (s==3){
            System.out.println("bon");
        }else{
            if(s == 0 || s == 1 ||s == 6 ||s == 8){
                System.out.println("pon");
            }else{
                System.out.println("hon");
            }
        }

    }
}


Measured memory_bytes: 35728
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N=1000005;
#define M 1000000007
#define double long double
#define BINF 1000000000000001
#define init(arr,val) memset(arr,val,sizeof(arr))
#define MAXN 15000001
const int LG = 22;

int a[N];

#undef int 
int main() { 
#define int long long int 
 
ios_base::sync_with_stdio(false); 
cin.tie(0); 
cout.tie(0); 

	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	
	sort(a,a + n + 1);

	int l = n / 2;
	int diff = a[l + 1] - a[l];
	cout << diff;
		
	

	
	

	
return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
    double a,b, c, d, e, f, x,y;
    while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF)
    {
        y = (a * f - c * d) / (a * e - d * b);
        x = (c - b * y) / a;
        printf("%.3f %.3f\n",x,y);
    }
	return 0;
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vb vector<bool>
#define pii pair<int,int>
#define mii map<int,int>
#define all(c)  c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define inf (long long) 1e18
#define F first
#define S second
#define SZ(x) ((int)(x).size())
//#define rep(i,n)  for(int i=0;i<n;i++)
//#define repd(i,n) for(int i=n-1;i>=0;i--)
//#define rep1(i,n) for(int i=1;i<=n;i++)
const int N = 1e9 + 7;
 
int pow(int x, int y) { int res = 1; while (y > 0) { if (y & 1) res = ((res) * (x)); res %= N; y = y >> 1; x = ((x) * (x)); } return res; }
int powm(int x, int y, int p)  {  int res = 1; x = x % p; while (y > 0) {if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p;}   return res; }
 
 int min2(int x,int y)
 {
     if(x<=y)
     return x;
     else 
     return y;
 }
void compute()
{
    int n;
    cin>>n;
    if(n>=30)
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
    

 
} 
 
int main()
{
#ifdef debug
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("log.txt", "w", stderr);
#endif
 //   int t;
   // scanf("%d", &t);
    //while (t--)
    //{
        compute();
   // } //end while
#ifdef debug
    fprintf(stdout, "\nTIME: %.3lf sec\n", (double)clock() / (CLOCKS_PER_SEC));
#endif
    return 0;
} //end main*

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-

import numpy as np

h, w = map(int, input().split())
A = [list(input()) for _ in range(h)]
buf = []
for i in range(h):
    for j in range(w):
        if A[i][j] == '#':
            buf.append(A[i])
            break
ret = []
for j in range(len(buf[0])):
    for i in range(len(buf)):
        if buf[i][j] == '#':
            ret.append([buf[k][j] for k in range(len(buf))])
            break
ans = np.array(ret).T
for line in ans:
    print(''.join(line))


Measured memory_bytes: 21800
import std.stdio : readln, writeln;
import std.string : split;
import std.conv : to;
import std.algorithm : sort;
import std.container : Array, BinaryHeap, RedBlackTree;
import std.typecons : Tuple;

void main()
{
    long X, Y, Z, K;
    {
        auto tmp = readln().split().to!(long[])();
        X = tmp[0];
        Y = tmp[1];
        Z = tmp[2];
        K = tmp[3];
    }
    auto A = readln().split().to!(long[])();
    auto B = readln().split().to!(long[])();
    auto C = readln().split().to!(long[])();
    A.sort!"b<a"();
    B.sort!"b<a"();
    C.sort!"b<a"();

    alias vec3 = Tuple!(long, long, long);

    bool eval(vec3 a, vec3 b)
    {
        return A[a[0]] + B[a[1]] + C[a[2]] < A[b[0]] + B[b[1]] + C[b[2]];
    }

    auto PQ = BinaryHeap!(Array!vec3, eval)();
    PQ.insert(vec3(0, 0, 0));

    auto set = new RedBlackTree!vec3();
    set.insert(vec3(0, 0, 0));

    foreach (_; 0 .. K)
    {
        auto v = PQ.front;
        PQ.removeFront();

        writeln(A[v[0]] + B[v[1]] + C[v[2]]);

        if (v[0] + 1 < X && vec3(v[0] + 1, v[1], v[2]) !in set)
        {
            PQ.insert(vec3(v[0] + 1, v[1], v[2]));
            set.insert(vec3(v[0] + 1, v[1], v[2]));
        }

        if (v[1] + 1 < Y && vec3(v[0], v[1] + 1, v[2]) !in set)
        {
            PQ.insert(vec3(v[0], v[1] + 1, v[2]));
            set.insert(vec3(v[0], v[1] + 1, v[2]));
        }

        if (v[2] + 1 < Z && vec3(v[0], v[1], v[2] + 1) !in set)
        {
            PQ.insert(vec3(v[0], v[1], v[2] + 1));
            set.insert(vec3(v[0], v[1], v[2] + 1));
        }
    }
}


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

using namespace std;

int n;
vector<vector<int> > adj;
long long MOD;
vector<long long> colorings;
vector<vector<long long> > colorings_without;

void dfs1(int curr, int p) {
  colorings[curr] = 1;
  for(int i = 0; i<adj[curr].size(); ++i) {
    int next = adj[curr][i];
    if(next == p) continue;
    dfs1(next, curr);
    colorings[curr] = (colorings[curr] * (1+colorings[next]))%MOD;
    // colorings[next] is the number of colorings of next's
    // subtree assuming that next is colored, so add 1 to
    // account for the possibility that it isn't colored
  }

  // now this is gross...
  colorings_without[curr].assign(adj[curr].size(), 1);
  long long last = 1;
  vector<long long> l, r;
  for(int i = 0; i<adj[curr].size(); ++i) {
    int next = adj[curr][i];
    if(next == p) continue;
    last = (last * (1+colorings[next]))%MOD;
    l.push_back(last);
  }
  r.resize(l.size());
  last = 1;
  int counter = r.size()-1;
  for(int i = adj[curr].size()-1; i>=0; --i) {
    int next = adj[curr][i];
    if(next == p) continue;
    last = (last * (1+colorings[next]))%MOD;
    r[counter--] = last;
  }
  counter = 0;
  for(int i = 0; i<adj[curr].size(); ++i) {
    int next = adj[curr][i];
    if(next == p) continue;
    colorings_without[curr][counter] = ((counter==0?1:l[counter-1]) * (counter==r.size()-1?1:r[counter+1])) % MOD;
    counter++;
  }
  // blehhhhhhhhhhhhhhhhhhh
}

void dfs2(int curr, int p, long long running) {
  // now for the up direction
  // uh oh...  we can't do modular inverses because M isn't
  // necessarily a prime
  running++;
  colorings[curr] = (colorings[curr] * running) % MOD;
  int counter = 0;
  for(int i = 0; i<adj[curr].size(); ++i) {
    int next = adj[curr][i];
    if(next == p) continue;
    dfs2(next, curr, (running * colorings_without[curr][counter])%MOD);
    counter++;
  }
}

int main() {
  // V: another tree DP, but probably with some amount of
  // rerooting
  //
  // so my reading of the constraint is that the black vertices
  // need to form a contiguous block
  // which means that if you start out by painting v black,
  // you can compute something via dp
  // and then multiply them all together (one per child node) to
  // get the number of colorings
  // the down direction is the easy one, that's just one dfs
  // and then going up is more of a problem

  cin.tie(0);
  cin.sync_with_stdio(0);
  cin >> n >> MOD;
  adj.resize(n);
  colorings.resize(n);
  colorings_without.resize(n);
  for(int i = 0; i<n-1; ++i) {
    int u, v; cin >> u >> v;
    u--; v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs1(0, -1);
  dfs2(0, -1, 0);

  for(int i = 0; i<n; ++i) {
    cout << colorings[i] << endl;
  }

}


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

int main()
{
    int M, D;
    cin >> M >> D;
    int k, c = 0;

    for (int i = 10; i <= D; i++)
    {
        if ((i % 10) >= 2 && (i / 10) >= 2)
        {
            k = (i % 10) * (i / 10);

            if (k <= M && 1 <= k)
            {
                c++;
            }
        }
    }

    cout << c << endl;

    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
node =[[] for _ in range(N)]

for _ in range(M):
  x, y = map(int, input().split())
  node[x-1].append(y-1)
  node[y-1].append(x-1)

ct = [-1]*N

i = 0
queue = []
ct[0] = 0
queue.append(0)
while len(queue) != 0:
  v = queue.pop(0)
  for e in node[v]:
    if ct[e] == -1:
      ct[e] = v
      queue.append(e)

print('Yes')
for i in range(1,N):
  print(ct[i]+1)

Measured memory_bytes: 33796
N, Y = map(int, input().split())

ans = (-1, -1, -1)
for x in range(N + 1):
    for y in range(N - x + 1):
        z = N - (x + y)
        bl = (10000 * x + 5000 * y + 1000 * z == Y)
        if bl:
            ans = (x, y, z)
            break
    if bl:
        break
print(*ans)


Measured memory_bytes: 3060
#include <sstream>
#include <iostream>
#include <cstdlib>
#include <string>
#include <typeinfo>

using namespace std;

int main (){
  string r,g,b,ans;
  cin >> r >> g >>  b;
  ans = r+g+b;
  int a=atoi(ans.c_str());
  if (a%4==0){
    cout << "YES" << endl;
    return 0;
  }
  cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int A, B;
	cin >> A >> B;
	int ans = 0;
	if (A > 12) {
		ans = B;
	}
	else if (A > 5) {
		ans = B / 2;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    vector<vector<long>> dp(n+1,vector<long>(13,0));
    dp.at(0).at(0) = 1;
    rep(i,n){
        if(s.at(i) == '?'){
            rep(j,10){
                rep(k,13) {
                    dp.at(i+1).at((k*10 + j)%13) += dp.at(i).at(k);
                    dp.at(i+1).at((k*10 + j)%13) %= MOD;
                }
            }
        }else{
            int num = s.at(i) - '0';
            rep(k,13){
                dp.at(i+1).at((k*10 + num)%13) += dp.at(i).at(k);
                dp.at(i+1).at((k*10 + num)%13) %= MOD;
            }
        }
    }
    cout << dp.at(n).at(5) << endl;
}

Measured memory_bytes: 13696
info = list(map(int, input().split()))
matrix = [[""] * info[1] for i in range(info[0])]

for i in range(info[0]):
    matrix[i] = list(input())


Black = 0

for i in range(info[0]):
    for j in range(info[1]):
        if matrix[i][j] == "#":
            Black += 1


combination = 0

for i in range(2 ** info[0]):
    non_selected = set()
    count = 0

    for j in range(info[0]):
        if (i >> j) & 1:
            
            for k in range(info[1]):
                if matrix[j][k] == "#":
                    count += 1
        else:
            non_selected.add(j)
    

    for l in range(2 ** info[1]):

        count2 = count
        for t in range(info[1]):
            if (l >> t) & 1:

                for s in non_selected:
                    if matrix[s][t] == "#":
                        count2 += 1

        if (Black - count2) == info[2]:
            combination += 1


print(combination)

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

int main() {
  string O, E;
  cin >> O >> E;

  for (int i = 0; i < E.size(); i++) {
    cout << O.at(i) << E.at(i);
  }

  if (O.size() > E.size()) cout << O.back() << "\n";
  else cout << "\n";
}

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

using namespace std;

typedef long long LL;
typedef unsigned int UI;

#define rSort(a) 		sort(a.rbegin(),a.rend())
#define Sort(a) 		sort(a.begin(),a.end())
#define Reverse(a) 		reverse(a.begin(),a.end())
#define Sum(a)  		accumulate(a.begin(), a.end(), 0)
#define REP(i, n) 		for(UI i = 0;i < n;i++)
#define REPR(i, n) 		for(UI i = n;i >= 0;i--)
#define FOR(i, m, n) 	for(UI i = m;i < n;i++)
#define pb(i) 			push_back(i)

#define MOD  			(LL)1e9 + 7;
#define INF  			(LL)1 << 62;

int main(int argc, const char * argv[]) {

	cin.tie(0);
	ios::sync_with_stdio(false);

	LL r;

	cin >> r;

	cout << 3 * r * r << endl;

	return 0;

}

Measured memory_bytes: 256
from collections import deque
h,w=map(int,input().split())
S=[input() for _ in range(h)]

ans=0
dxy=[(0,1),(1,0),(0,-1),(-1,0)]
for y in range(h):
  for x in range(w):
    if S[y][x]=='#': continue
    q=deque([(x,y)])
    dist=[[0]*w for _ in range(h)]
    visited=[[0]*w for _ in range(h)]
    visited[y][x]=1
    while q:
      x,y=q.popleft()
      for dx,dy in dxy:
        nx,ny=x+dx,y+dy
        if not 0<=nx<w: continue
        if not 0<=ny<h: continue
        if visited[ny][nx]: continue
        if S[ny][nx]=='#': continue
        visited[ny][nx]=1
        dist[ny][nx]=dist[y][x]+1
        q.append((nx,ny))
    ans = max(ans, max(max(row) for row in dist))
print(ans)


Measured memory_bytes: 3316
#include <iostream>
using namespace std;
int main(){
    int n=0,m=0,ki=0,c,gu=0,d,last;
    cin>>n;
    cin>>m;
    /*if(n<m){
        a=n;
        b=m;
        
    }else{
        a=m;
        b=n;
    }*/
    
   // if(n>1){
    n-=1;
    m-=1;
        for(int i=1;i<=n;i++){
        
            ki=ki+i;
           
        }
     
  //  }
   // cout<<"ki"<<ki<<endl;
    
  //  if(m>1){
        for(int i=1;i<=m;i++){
            gu=gu+i;
        }
   // cout<<"gu"<<gu<<endl;
  //  }
    last=ki+gu;
    cout<<last<<endl;
}


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

using namespace std;
typedef long long ll;




int main()
{
    
    int N;
    cin >> N;
    if(N<=999) cout << "ABC" << endl;
    else cout << "ABD" << endl;
    
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <queue>

#define pb push_back
     
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
     
bool debug = false;
     

struct state
{
    ll a,b,c;

    state(ll a, ll b, ll c) : a(a), b(b), c(c)
    {

    }

  bool operator==(const state &other) const
  { return (a == other.a
            && b == other.b
            && c == other.c);
  }
};


struct KeyHasher
{
    size_t operator()(const state& k) const
  {
    //using std::size_t;
    //using std::hash;
    //using std::string;

    return ((hash<ll>()(k.a)
               ^ (hash<ll>()(k.b) << 1)) >> 1)
               ^ (hash<ll>()(k.c) << 1);
  }
};  


void solve(ll casen)
{
    ll res = 0;
    
    cout << "Case #" << casen << ": " << res << endl;
}

int main()
{
    // $ g++ -std=c++14 -Wshadow -Wall -o c C.cpp

    // !!! Here, unordered map was too slow!!!
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    
   string s,t;
   cin >> s >> t;

   ll n = s.length();
   ll res = 0;
   for (int i = 0; i < n; i++)
   {
   		if (s[i] != t[i]) res++;
   }
  
  	cout << res << endl;

    return 0;
}

Measured memory_bytes: 3840
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, M: int, Q: int, L: "List[int]", R: "List[int]", p: "List[int]", q: "List[int]"):
    dp = [[0] * (N + 1) for _ in range(N + 1)]
    for l, r in zip(L, R):
        dp[l-1][r-1] += 1

    for i in range(0, N):
        for j in range(0, N):
            dp[i][j] += dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]
    ret = []
    for pp, qq in zip(p, q):
        c = dp[qq-1][qq-1] - dp[pp - 2][qq - 1] - dp[qq - 1][pp - 2] + dp[pp - 2][pp - 2]
        ret.append(c)

    return '\n'.join([str(r) for r in ret])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]" 
    R = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    p = [int()] * (Q)  # type: "List[int]" 
    q = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        p[i] = int(next(tokens))
        q[i] = int(next(tokens))
    result = solve(N, M, Q, L, R, p, q)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 39952
#include <stdio.h>

int main(void) {
	int a, b;
	char c;
	while(scanf("%d %c %d", &a, &c, &b) == 3) {
		switch(c) {
			case '+':
				printf("%d\n", a+b);
				break;
			case '-':
				printf("%d\n", a-b);
				break;
			case '/':
				printf("%d\n", a/b);
				break;
			case '*':
				printf("%d\n", a*b);
				break;
			case '?':
				return 0;
		}	
	}
	
	return 0;
}

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

namespace abc158_c
{
    class Program
    {
        static void Main(string[] args)
        {
            var A = CIn.ReadInt();
            var B = CIn.ReadInt();
            var ans1 = new int();
            var ans2 = new int();
            for(int i = 1; i <= 1000; i++)
            {
                ans1 = (int)(i * 0.08);
                ans2 = (int)(i * 0.1);
                if (ans1 == A && ans2 == B)
                {
                    Console.WriteLine(i);
                    return;
                }
            }
            Console.WriteLine(-1);
            
        }
    }
    static class CIn
    {
        private static readonly Queue<string> fieldBuffer = new Queue<string>();

        public static string Read()
        {
            if (fieldBuffer.Count == 0)
            {
                foreach (var field in Console.ReadLine().Split())
                {
                    fieldBuffer.Enqueue(field);
                }
            }
            return fieldBuffer.Dequeue();
        }

        public static int ReadInt() => int.Parse(Read());
        public static long ReadLong() => long.Parse(Read());
        public static double ReadDouble() => double.Parse(Read());

        public static string[] ReadStringArray(long n)
        {
            var array = new string[n];
            for (var i = 0L; i < n; i++)
            {
                array[i] = Read();
            }
            return array;
        }

        public static int[] ReadIntArray(long n)
        {
            var array = new int[n];
            for (var i = 0L; i < n; i++)
            {
                array[i] = ReadInt();
            }
            return array;
        }

        public static long[] ReadLongArray(long n)
        {
            var array = new long[n];
            for (var i = 0L; i < n; i++)
            {
                array[i] = ReadLong();
            }
            return array;
        }

        public static double[] ReadDoubleArray(long n)
        {
            var array = new double[n];
            for (var i = 0L; i < n; i++)
            {
                array[i] = ReadDouble();
            }
            return array;
        }

        public static char[,] ReadCharMatrix(long h, long w)
        {
            var array = new char[h, w];
            for (var i = 0L; i < h; i++)
            {
                var l = Console.ReadLine().ToCharArray();
                for (var j = 0L; j < w; j++)
                {
                    array[i, j] = l[j];
                }
            }
            return array;
        }
    }
}


Measured memory_bytes: 13268
#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(){
 // int n;
  string s;
  cin >> s;
	s[3]='8';
  cout << s <<endl;
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include<string>
#include<set>

using namespace std;

int main() {
	set<string> st;

	int n = 0;
	cin >> n;

	for (int i = 0;i < n;i++) {
		string s;
		cin >> s;
		st.insert(s);
	}

	cout << st.size() << '\n';
}

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

int main()
{
	long long a, b, k;
	cin >> a >> b >> k;
	if (k <= a) {
		a -= k;
	}
	else {
		k -= a;
		a = 0;
		if (k <= b) {
			b -= k;
		}
		else
		{
			b = 0;
		}
	}

	cout << a << " " << b << endl;
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int min_v(const vector<int>& vRhs){
    int ret = vRhs[0];
    for(uint i=1; i<vRhs.size(); ++i){ ret=min(ret, vRhs[i]); }
    return ret;
}
int max_v(const vector<int>& vRhs){
    int ret = vRhs[0];
    for(uint i=1; i<vRhs.size(); ++i){ ret=max(ret, vRhs[i]); }
    return ret;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N, M, X, Y; cin >> N >> M >> X >> Y;
    vector<int> vX(N+1); for(int i=0; i<N; ++i){ cin >> vX[i]; } vX[N]=X;
    vector<int> vY(M+1); for(int i=0; i<M; ++i){ cin >> vY[i]; } vY[M]=Y;
    int x_max = max_v(vX);
    int y_min = min_v(vY);
    
    cout << (x_max<y_min ? "No War":"War") << endl;
    
    return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
using vi = vector<int>;
using vvi = vector<vi>;

int main(){
    int n;
    while(cin >> n,n){
      vector<set<int>> p(n);
        rep(i,n){
            int m; cin >> m;
            int x;
            rep(j,m){
                cin >> x;
                p[i].insert(x);
            }
        }
        int k; cin >> k;
        vi l(k); rep(i,k) cin >> l[i];
        vi ans;
        rep(i,n){
            bool f = true;
            rep(j,k){
                if(p[i].count(l[j]) == 0) f = false;
            }
            if(f){
                ans.push_back(i);
            }
        }
        if(ans.size() == 1) cout << ans[0]+1 << endl;
        else cout << -1 << endl;
    }
}



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

using namespace std;

int main() {
    int N; cin>>N;
    vector<int> A(N+1,0), B(N+1,0), C(N,0);

    for (int i=1;i<=N;i++) {
        cin>>A[i];
    }

    for (int i=1;i<=N;i++) {
        cin>>B[i];
    }

    for (int i=1;i<=N-1;i++) {
        cin>>C[i];
    }

    int ans=0;
    for (int i=1;i<=N;i++) {
        // cout << B[A[i]] << endl;
        ans += B[A[i]];
        if (A[i-1] + 1 == A[i]) {
            ans += C[A[i-1]];
            // cout << "C: " << C[A[i-1]] << endl;
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

import static java.lang.Integer.parseInt;

/**
 * All Numbers Lead to 6174
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while (!(line = br.readLine()).equals("0000")) {

			int N = parseInt(line), L, S;
			byte[] numS = new byte[10];
			byte[] numL = new byte[10];

			int k;
			int c = 0;

			if (N == 0 || N % 1111 == 0) {
				System.out.println("NA");
			} else {
				
				while (N != 6174) {

					//N
					Arrays.fill(numS, (byte) 0);
					Arrays.fill(numL, (byte) 0);
					k = 1000;
					for (int i = 0; i < 4; i++) {
						int n = N / k;
						numS[n]++;
						numL[n]++;
						N -= n * k;
						k /= 10;
					}

					//S
					k = 1000;
					S = 0;
					for (int i = 0; i < 10; i++) {
						while (numS[i] > 0) {
							S += i * k;
							numS[i]--;
							k /= 10;
						}
					}

					//L
					k = 1000;
					L = 0;
					for (int i = 9; i >= 0; i--) {
						while (numL[i] > 0) {
							L += i * k;
							numL[i]--;
							k /= 10;
						}
					}

					N = L - S;
					c++;
				}
				System.out.println(c);
			}
		}
	}
}

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

int n, Y;

void solve()
{
	int c = 0;
	int x, y, z, Z;
	for (x = 0; x <= n; ++x)
	{
		for (y = 0; y <= n; ++y)
		{
			Z = Y - 10000 * x - 5000 * y;
			if (Z >= 0 && Z % 1000 < 1)
			{
				int z = Z / 1000;
				if (x + y + z == n)
				{
					cout << x << " " << y << " " << z << endl;
					return; 
				}

			}
		}
	}
	cout << "-1 -1 -1" << endl;
}

int main()
{
	cin >> n >> Y;
	solve();
}


Measured memory_bytes: 3596