akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

typedef struct RSQandRUQ_node {
  i32 val;
  i32 sum;
} node;

typedef struct RSQandRUQ {
  node *a;
  i32 bit;
  i32 size;
  i32 empty;
} RSQandRUQ;

RSQandRUQ* new_RSQandRUQ (const i32 n) {
  i32 k = 0;
  while ((1 << k) < n) ++k;
  RSQandRUQ *s = (RSQandRUQ *) calloc (1, sizeof (RSQandRUQ));
  s->a = (node *) calloc (2 << k, sizeof (node));
  s->bit = k;
  s->size = 1 << k;
  s->empty = 10000;
  return s;
}

void propagate (RSQandRUQ *s, i32 x) {
  x += s->size;
  for (i32 i = s->bit; i > 0; --i) {
    i32 k = x >> i;
    if (s->a[k].val == s->empty) continue;
    s->a[2 * k].val = s->a[2 * k + 1].val = s->a[k].val;
    s->a[k].sum = s->a[k].val << i;
    s->a[k].val = s->empty;
  }
}

static inline i32 eval (RSQandRUQ *s, i32 k, i32 len) {
  return s->a[k].val == s->empty ? s->a[k].sum : s->a[k].val * len;
}

void save (RSQandRUQ *s, i32 x) {
  for (i32 k = (x + s->size) >> 1, len = 1; k > 0; k >>= 1, len <<= 1) {
    s->a[k].sum = eval (s, 2 * k, len) + eval (s, 2 * k + 1, len);
  }
}

void update (RSQandRUQ *s, i32 l, i32 r, i32 v) {
  propagate (s, l);
  propagate (s, r - 1);
  for (i32 x = l + s->size, y = r + s->size; x < y; x >>= 1, y >>= 1) {
    if (x & 1) s->a[x++].val = v;
    if (y & 1) s->a[--y].val = v;
  }
  save (s, l);
  save (s, r - 1);
}

i32 get_sum (RSQandRUQ *s, i32 l, i32 r) {
  propagate (s, l);
  propagate (s, r - 1);
  i32 sum = 0;
  for (i32 x = l + s->size, y = r + s->size, len = 1; x < y; x >>=1, y >>= 1, len <<= 1) {
    if (x & 1) sum += eval (s, x++, len);
    if (y & 1) sum += eval (s, --y, len);
  }
  return sum;
}

void run (void) {
  i32 n, q;
  scanf ("%" SCNi32 "%" SCNi32, &n, &q);
  RSQandRUQ *s = new_RSQandRUQ (n);
  while (q--) {
    i32 t, l, r;
    scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &t,&l, &r);
    r++;
    if (t == 0) {
      i32 v;
      scanf ("%" SCNi32, &v);
      update (s, l, r, v);
    } else {
      printf ("%" PRIi32 "\n", get_sum (s, l, r));
    }
  }
}

int main(void){
  run();
  return 0;
}



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

#define ff first
#define ss second
using namespace std;
#define maxn 2000006
#define pb push_back
#define ll long long
#define lll __int128
#define vll vector<ll>
#define mll map<ll,ll>
#define MOD 1000000007
#define pll pair<ll,ll>
#define ull unsigned long long
#define f(i,x,n) for(int i=x;i<=n;i++)
inline void fastio() {ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);}

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



int main() {
	fastio();

	ll n, m; cin >> n >> m;

	priority_queue<ll> pq;

	while (n--) {
		ll a; cin >> a;
		pq.push(a);
	}

	while (m--) {
		ll t = pq.top();
		pq.pop();
		pq.push(t / 2);
	}

	ll ans = 0;

	while (pq.empty() == false) ans += pq.top(), pq.pop();

	cout << ans;

	return 0;
}

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

#define int long long
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) otp(v[i]) cte
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int h,w;
char a[102][102];

main() {
    cin >> h >> w;
    rep1(i,h) rep1(j,w) cin >> a[i][j];
    rep(i,h+2) a[i][0] = a[i][w+1] = '#';
    rep(i,w+2) a[0][i] = a[h+1][i] = '#';
    rep(i,h+2) {
        rep(j,w+2) otp(a[i][j])
        cte
    }
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int H = sc.nextInt();
		int W = sc.nextInt();
		int[] left = new int[H];
		int[] right = new int[H];
		Arrays.fill(left, -1);
		Arrays.fill(right, -1);
		for (int i = 0; i < H; i++) {
			char[] row = sc.next().toCharArray();
			for (int j = 0; j < W; j++) {
				if (row[j] == 'B') {
					if (left[i] == -1) left[i] = j;
					right[i] = j;
				}
			}
		}
		int ans = 0;
		for (int i = 0; i < H; i++) {
			if (left[i] == -1) continue;
			for (int j = i; j < H; j++) {
				if (left[j] == -1) continue;
				ans = Math.max(ans, j - i + Math.abs(left[i] - right[j]));
				ans = Math.max(ans, j - i + Math.abs(right[i] - left[j]));
			}
		}
		System.out.println(ans);
	}

}



Measured memory_bytes: 26456
x,n = map(int,input().split())
p = set([int(x) for x in input().split()])

mn = 10**10
ans_li = []

for i in range(-200,201):
    if i not in p and abs(x - i) <= mn:
        ans_li.append(i)
        mn = abs(x - i)

for aa in ans_li:
    if abs(aa - x) == mn:
        print(aa)
        break


Measured memory_bytes: 9136
#include<bits/stdc++.h>
using namespace std;
int main(){
    int w,h,x,y,r;
    cin>>w>>h>>x>>y>>r;
    if(w>=x+r&&h>=y+r&&x-r>=0&&y-r>=0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3108
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define stoint(str) atoi(str.c_str())
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, A, B;
	cin >> N >> A >> B;
	int ans = 0;
	for(int i = 1; i <= N; i++) {
		int tmp = i;
		int rslt = 0;
		while(tmp > 0) {
			rslt += tmp % 10;
			tmp /= 10;
		}
		if(A <= rslt && rslt <= B) ans += i;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int grid[3][3];
  memset(grid,0,sizeof(grid));
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
      cin>>grid[i][j];
  int n;
  cin>>n;
  int f=0;
  int x;
  for(int i=0;i<n;i++)
  {
    cin>>x;
    for(int k=0;k<3;k++)
      for(int j=0;j<3;j++)
      {
        if(grid[k][j]==x)
        {
          grid[k][j]=0;
          break;
        }
      }
  }
  for(int i=0;i<3;i++)
  {
    if(grid[i][0]==0 and grid[i][1]==0 and grid[i][2]==0)
    {
      f=1;
      break;
    }}
  for(int i=0;i<3;i++)
  {
    if(grid[0][i]==0 and grid[1][i]==0 and grid[2][i]==0)
    {
      f=1;
      break;}
  }
  if(grid[0][0]==0 and grid[1][1]==0 and grid[2][2]==0)
    f=1;
  if(grid[0][2]==0 and grid[1][1]==0 and grid[2][0]==0)
    f=1;
  if(f)
    cout<<"Yes\n";
  else
    cout<<"No\n";
  return 0;
}

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

int main()
{
	long long answer = 0LL;
	int N;
	int K;

	cin >> N >> K;

	vector<int> vec(N);

	for (int i = 0; i < N; i++) {
		cin >> vec.at(i);
	}

	sort(vec.begin(), vec.end(), greater<int>());

	

	for (int i = K; i < N; i++) {
		answer += vec.at(i);
	}

	
	cout << answer << endl;

	return 0;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  if ("SUN" == S)
  {
    cout << "7" << endl;
  }
  else if ("MON" == S)
  {
    cout << "6" << endl;
  }
  else if ("TUE" == S)
  {
    cout << "5" << endl;
  }
  else if ("WED" == S)
  {
    cout << "4" << endl;
  }
  else if ("THU" == S)
  {
    cout << "3" << endl;
  }
  else if ("FRI" == S)
  {
    cout << "2" << endl;
  }
  else
  {
    cout << "1" << endl;
  }
}

Measured memory_bytes: 3644
#include<iostream>
using namespace std;
#define MAX 100000

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

int main() {
	int H, i, A[MAX + 1];

	cin >> H;
	for (i = 1; i <= H; i++)cin >> A[i];

	for (i = 1; i <= H; i++) {
		cout << "node " << i << ": key = " << A[i] << ", ";
		if (parent(i) >= 1)cout << "parent key = " << A[parent(i)] << ", ";
		if (left(i) <= H)cout << "left key = " << A[left(i)] << ", ";
		if (right(i) <= H)cout << "right key = " << A[right(i)] << ", ";
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int N = 11111;
void add(int &x, int y) {
	x += y;
	if (x >= mod) x -= mod;
}
int pw(int a, int b) {
	int an = 1;
	for (; b; b >>= 1) {
		if (b & 1) an = 1ll * an * a % mod;
		a = 1ll * a * a % mod;
	}
	return an;
}
int ans, x[N], y[N], n;
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d%d", &x[i], &y[i]);
	add(ans, pw(2, n));
	add(ans, mod - 1);
	add(ans, mod - n);
	add(ans, mod - n * (n - 1) / 2);
	for (int i = 1; i <= n; ++i) 
		for (int j = i + 1; j <= n; ++j) {
			int dx = x[j] - x[i], dy = y[j] - y[i];
			int cnt = 2;
			for (int k = 1; k <= n; ++k) {
				if (i == k || j == k) continue;
				int dx2 = x[k] - x[j], dy2 = y[k] - y[j];
				if (dx2 * dy != dy2 * dx) continue;
				if (k < j) break;
				++cnt;
			}
			add(ans, mod - pw(2, cnt));
			add(ans, 1);
			add(ans, cnt);
			add(ans, cnt * (cnt - 1) / 2);
		}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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 (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    VV gragh(n);
    rep(i,m){
        ll a, b;
        cin>>a>>b;
        a--;
        b--;
        gragh[a].push_back(b);
    }
    ll path_length = INF;
    V ans_path;
    rep(start,n){
        V prev(n, -1);
        V dist(n, -1);
        queue<ll> q;
        q.push(start);
        dist[start] = 0;
        while(!q.empty()){
            ll now = q.front();
            q.pop();
            for(auto to:gragh[now]){
                if(dist[to]==-1){
                  //  cout<<"探索 "<<start<<" "<<now<<" "<<to<<endl;
                    q.push(to);
                    dist[to] = dist[now] + 1;
                    prev[to] = now;
                }
            }
        }
        
        rep(i,n){
            if(i==start||dist[i]==-1){
               // cout<<i<<" "<<start<<"却下"<<endl;
                continue;
            }
            for(auto j:gragh[i]){
                if(j==start){
                    if(chmin(path_length,dist[i]+1)){
                        V temp;
                        ll tempnow = i;
                        while(tempnow!=start){
                          //  cout<<"復元"<<tempnow<<" から"<<prev[tempnow]<<" 始点　"<<start<<endl;
                            temp.push_back(tempnow);
                            tempnow = prev[tempnow];
                        }
                        temp.push_back(start);
                        ans_path = temp;
                    }
                }
            }
        }
    }
    if(path_length==INF){
        cout<<-1<<endl;
        return 0;
    }
    cout << path_length << endl;
    reverse(all(ans_path));
    for (auto i:ans_path){
        cout << i+1 << endl;
    }
}


Measured memory_bytes: 384
import itertools
N,A,B,C=[int(i) for i in input().split()]
target=[A,B,C]
L=list()
for i in range(N):
    L.append(int(input()))
min_magic=9999999999999
for pattern in itertools.product([0,1,2,3],repeat=N):
    found=1
    magic= -30
    sum = [0,0,0]
    for j in range(N):
        if pattern[j] != 3:
            sum[pattern[j]] += L[j]
            magic += 10
    for i in range(3):
        if sum[i]==0:
            found=0
            break
        magic+=abs(target[i]-sum[i])
    if found==1:
        min_magic=min(min_magic,magic)

print (min_magic)



Measured memory_bytes: 43372
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        int[] C = new int[N-1];
        int bsum = 0;
        int csum = 0;

        for(int i=0; i<=N-1; i++){
            A[i] = sc.nextInt();
        }
        for(int i=0; i<=N-1; i++){
            B[i] = sc.nextInt();
        }
        for(int i=0; i<=N-2; i++){
            C[i] = sc.nextInt();
        }
        for(int i=0; i<=N-1; i++){
            for(int j=1; j<=N; j++){
                if(A[i]==j){
                    bsum = bsum + B[j-1];
                }
            }
        }
        for(int i=1; i<=N-1; i++){
            if(A[i-1]==A[i]-1){
                csum = csum + C[A[i-1]-1];
            }
        }   
        System.out.println(bsum + csum);

    }
}

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

int main()
{

    int N;
    cin >> N;

    int T, A;
    cin >> T >> A;
    vector<int> H(N, 0);
    for (int i = 0; i < N; ++i){
        cin >> H[i];
    }

    double min_value = 1e9;
    int ans = 0;
    for (int i = 0; i < N; ++i)
    {
        double x =(double) T - H[i] * 0.006;
        double y = (double)A - x;
        if (min_value > abs(y))
        {
            min_value = abs(y);
            ans = i;
        }
    }

    cout << ans+1 << endl;

    return 0;
}

Measured memory_bytes: 256
program scoring
    implicit none
    integer(8)::t1,t2,t_rate,t_max,diff!実行時間の計測関連
    integer(8)::D,C(26),last(26,365),last_sim(26,365),i,j,k,vmax,tbest,torigin
    integer(8)::drand,qrand!局所探索法の書き換え関連
    integer(8)::contests=26
    integer(8)::steps=0!ベンチマーク用
    integer(8),allocatable::S(:,:),T(:),V(:),Vorigin(:)
    !時間計測開始
    call system_clock(t1)

    !入力
    read*,D,C
    allocate(S(26,D))
    allocate(T(D))
    allocate(V(D))
    allocate(Vorigin(D))
    read*,S
    T=0
    V=0
    last=0
    last_sim=0

    !貪欲法による初期解の生成
    do i=1,D
        do j=1,26
            !得点の初期化
            if(i==1)V(i)=0
            if(i>1)V(i)=V(i-1)

            !lastの初期化
            if(i==1)last(:,i)=0
            if(i>1)last(:,i)=last(:,i-1)

            last(j,i)=i
            V(i)=V(i)+S(j,i)
            
            do k=1,26
                V(i)=V(i)-C(k)*(i-last(k,i))
            end do

            if(j==1)then
                vmax=V(i)
                tbest=j
            else if(V(i)>=vmax)then
                vmax=V(i)
                tbest=j
            end if
        end do
        if(i==1)last(:,i)=0
        if(i>1)last(:,i)=last(:,i-1)
        T(i)=tbest
        last(tbest,i)=i
    end do
    vmax=V(D)
    call system_clock(t2,t_rate,t_max)
    diff=t2-t1

    do
        if(diff>1990000000)exit
        steps=steps+1

        !乱数の生成
        drand=rnd_int(D)
        qrand=rnd_int(contests)

        last_sim(:,:)=last(:,:)
        Vorigin(:)=V(:)
        !drand日目に行うコンテストをqrandに変更する
        !last_simの書き換え
        torigin=T(drand)
        if(drand==1)then
            last_sim(T(drand),1)=0
            last_sim(qrand,1)=1
        else
            last_sim(T(drand),drand)=last(T(drand),drand-1)
            last_sim(qrand,drand)=drand
        end if
        !日付に対応するコンテストタイプの書き換え
        T(drand)=qrand

        !drand日目の得点の再計算
        if(drand==1)then
            V(drand)=0
        else
            V(drand)=V(drand-1)
        end if
        V(drand)=V(drand)+S(T(drand),drand)
        do i=1,26
            V(drand)=V(drand)-C(i)*(drand-last_sim(i,drand))
        end do

        !drand+1日目以降の得点の再計算
        do i=drand+1,D
            last_sim(:,i)=last_sim(:,i-1)
            V(i)=V(i-1)
            V(i)=V(i)+S(T(i),i)
            last_sim(T(i),i)=i
            do j=1,26
                V(i)=V(i)-C(j)*(i-last_sim(j,i))
            end do
        end do

        if(V(D)>vmax)then
            vmax=V(D)
            last(:,:)=last_sim
        else
            V(:)=Vorigin(:)
            T(drand)=torigin
        end if
        !時間計測
        call system_clock(t2,t_rate,t_max)
        diff=t2-t1
    end do
    !print*,diff/dble(t_rate),steps
    !答えの出力
    do i=1,D
        print'(i0)',T(i)
    end do
contains
function rnd_int(rnd_max)
    integer(8),intent(in)::rnd_max
    integer(8)::rnd_int
    real::rnd_real
    call random_number(rnd_real)
    rnd_int=mod(int(rnd_real*100000000),rnd_max)+1
    return
end function
end program scoring

Measured memory_bytes: 3224
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
  int count=0;
    for(int i=0;i<3;i++){
      char k;
      cin>>k;
      if(k=='1'){
        count++;
      }
    }
  cout<<count;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
using namespace std;
int d[30],len,dp[30][30][30];
int DP(int n){
	int ret=0;
	memset(dp,0,sizeof(dp));
	dp[0][0][0]=1;
	for(int i=0;i<(n>>1);i++)
		for(int j=0;j<10;j++)
			for(int k=0;k<10;k++)
				if(dp[i][j][k])
					for(int x=0;x<10;x++){
						int l1=x+d[i+1]+k,y=l1%10,l2=10*j+x-y-d[n-i];
						l1/=10;
 						if(l2<0||l2>9||(!i&&(!x||!y)))
							continue;
						dp[i+1][l2][l1]+=dp[i][j][k];
					}
	if(n&1){
		int mid=(n+1)>>1;
		for(int i=0;i<10;i++)
			for(int j=0;j<10;j++)
				if(dp[n>>1][i][j])
					for(int x=0;x<10;x++){
						int y=x+d[mid]+j;
						if(x==y%10&&y/10==i)
							ret+=dp[n>>1][i][j];
					}
	}
	else
		for(int i=0;i<10;i++)
			ret+=dp[n>>1][i][i];
	return ret;
}
int getans(){
	int ret=0;
	for(int i=max(2,len);i<=20;i++)
		ret+=DP(i);
	return ret;
}
void Input(){
	char c;
	do c=getchar();
	while(!isdigit(c));
	do{
		d[++len]=c^48;
		c=getchar();
	}while(isdigit(c));
	reverse(d+1,d+len+1);
	return;
}
int main(){
	Input();
	printf("%d",getans());
	return 0;
}

Measured memory_bytes: 256
n = int(input())
for _ in range(n):
    a, b, c = map(int, input().split())
    if (a**2 + b**2 == c**2) or\
            (b**2 + c**2 == a**2) or\
            (c**2 + a**2 == b**2):
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 5592
from collections import deque
from sys import exit

h,w=map(int,input().split())
sh,sw=map(lambda s: int(s)-1,input().split())
gh,gw=map(lambda s: int(s)-1,input().split())
s = [input() for _ in range(h)]
d = [[h*w] * w for _ in range(h)]
q = deque()
d[sh][sw] = 0
q.append((sw, sh, 0))
while len(q):
  p = q.popleft()
  if p[2] != d[p[1]][p[0]]:
    continue
  if p[0] == gw and p[1] == gh:
    print(d[gh][gw])
    exit(0)
  for dx in range(-2, 3):
    nx = p[0] + dx
    if nx < 0 or w <= nx:
      continue
    for dy in range(-2, 3):
      ny = p[1] + dy
      c = 0 if abs(dx) + abs(dy) == 1 else 1
      if dx == dy == 0 or ny < 0 or h <= ny or s[ny][nx] == '#' or d[ny][nx] <= d[p[1]][p[0]] + c:
        continue
      d[ny][nx] = d[p[1]][p[0]] + c
      np = (nx, ny, d[ny][nx])
      if c:
        q.append(np)
      else:
        q.appendleft(np)
print(-1)


Measured memory_bytes: 97016
using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{

	static void Main(string[] args)
	{
		var array = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
		int row = 0;
		int high = 0;
		if (array[0] > array[1])
		{
			row = array[1];
			high = array[0];
		}
		else
		{
			row = array[0];
			high = array[1];
		}

		if (row <= array[2] && array[2] <= high)
		{
			Console.WriteLine("Yes");
		}
		else
		{
			Console.WriteLine("No");
		}
	}
}


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

int main() {
  const int INF = 10000;
  int N, X, sum = 0, min = INF;
  cin >> N >> X;
  vector<int> m(N);
  for(int i = 0; i < N; i++) {
    cin >> m.at(i);
    if(m.at(i) < min) min = m.at(i);
    X -= m.at(i);
  }
  int n = X / min;

  cout << N + n << endl;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;


public class Main {
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int K = sc.nextInt();
    int S = sc.nextInt();
    
    int count = 0;
    for (int x = 0; x <= K; x ++) {
      for (int y = 0; y <= K; y ++) {
        int z = S - x - y;
        if (0 <= z && z <= K) {
          count ++;
        }
      }
    }
    System.out.println(count);
  }

}


class FastScanner {
	public static String debug = null;

	private final InputStream in = System.in;
	private int ptr = 0;
	private int buflen = 0;
	private byte[] buffer = new byte[1024];
	private boolean eos = false;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}

Measured memory_bytes: 8148
N, K = map(int, input().split())
height = [int(input()) for i in range(N)]

height.sort()
h_min = []
for i in range(N - K + 1):
    h_min.append(height[K - 1 + i] - height[i])
    if i > 0:
        if h_min[0] >= h_min[1]:
            del h_min[0]
        else:
            del h_min[1]

print(h_min[0])


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

int main()
{
	int a, b;
	cin >> a >> b;
	int ret = 0;
	if (a == b) {
		ret = a + b;
	}
	else {
		ret = max(a, b) * 2 - 1;
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a;
    cin>>a;
    string b=a;
    reverse(a.begin(),a.end());
    for(int i=0;i<a.size();++i)
    {
        if(a[i]=='b') a[i]='d';
        else if(a[i]=='d') a[i]='b';
        else if(a[i]=='p') a[i]='q';
        else if(a[i]=='q') a[i]='p';
    }
    if(a==b) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

const int N = 305;
int r[N * N], c[N * N];
int dis[N * N];
int main()
{
    int h, w, d, num;
    cin >> h >> w >> d;
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
            cin >> num, r[num] = i, c[num] = j;
    for (int i = 1; i + d <= h * w; i++)
        dis[i] = abs(r[i + d] - r[i]) + abs(c[i + d] - c[i]);
    for (int i = 1; i + d <= h * w; i++)
        dis[i + d] += dis[i];
    // for (int i = 1; i <= h * w; i++)
        // cout << dis[i] << endl;
    int q;
    cin >> q;
    while (q--)
    {
        static int l, r;
        cin >> l >> r;
        l -= d, r -= d;

        cout << dis[max(0, r)] - dis[max(0, l)] << endl;
    }
    return 0;
}

Measured memory_bytes: 2176
def readInt():
    return list(map(int, input().split()))

n = int(input())
a = readInt()
ans = 0
height = a[0]
for i in range(1,len(a)):
    if a[i] <= height:
        ans += height - a[i]
    else:
        height = a[i]
print(ans)

Measured memory_bytes: 94068
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  vector<int> c(5);
  int ans;
  while(~scanf("%d,%d,%d,%d,%d", &c[0],&c[1],&c[2],&c[3],&c[4])) {
    sort(c.begin(), c.begin()+5);
    if(c[0] == c[3] || c[1] == c[4]) ans = 7;
    else if((c[0] == c[2] && c[3] == c[4])|| (c[0] == c[1] && c[2] == c[4])) ans = 6;
    else if(c[0] + 1 == c[1] && c[1] + 1 == c[2] && c[2] + 1 == c[3] && c[3] +1 == c[4])
      ans = 5;
    else if(c[0] == 1 && c[1] == 10 && c[2] == 11 && c[3] == 12 && c[4] == 13)
      ans = 5;
    else if(c[0] == c[2] || c[1] == c[3] || c[2] == c[4])
      ans = 4;
    else if((c[0] == c[1] && c[2] == c[3]) || (c[0] == c[1] && c[3] == c[4]) || (c[1] == c[2] && c[3] == c[4]))
      ans = 3;
    else if(c[0] == c[1] || c[1] == c[2] || c[2] == c[3] || c[3] == c[4])
      ans = 2;
    else ans= 1;
    switch(ans) {
    case 1: cout << "null" << endl; break;
    case 2: cout << "one pair" << endl; break;
    case 3: cout << "two pair" << endl; break;
    case 4: cout << "three card" << endl; break;
    case 5: cout << "straight" << endl; break;
    case 6: cout << "full house" << endl; break;
    case 7: cout << "four card" << endl; break;
    }
  }
  return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
int main()
{
    string s;
    ll k,count=0;
    cin>>s>>k;
    char ans='0';

    rep(i,s.size()){
        if (s[i]=='1')count++;
        else{
            ans=s[i];
          break;
        }
    }
    if(ans=='0'||k<=count)ans='1';
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

using namespace std;

bool binary_search(vector<int> v, int kay){
    int left = 0;
    int right = SZ(v);
    int mid;
    while(left < right){
        mid = (left + right)/2;
        if (v[mid] == kay) return true;
        else if (kay < v[mid]) right = mid;
        else left = mid+1; 
    }
    return false;
}

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

    int n;
    cin >> n;

    vector<int> v;
    int t;
    REP(_, n){cin >> t; v.PB(t);}

    cin >> n;
    int count = 0;
    REP(_, n){
        cin >> t;
        if (binary_search(v, t)) count++;
    }

    cout << count << endl;
}


Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
#define MAXX 200010
 
#define PI   3.14159265358979323846264338327950
 
#define PB push_back 
#define F first
#define S second
 
#define ll 	long long 
 
#define mod  1000000007
 

 
int main()
{
	FAST;
	char a;
	cin >> a;
	cout << char(a+1);
	return 0;
}

Measured memory_bytes: 3616
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
a=[int(input()) for i in range(n)]

a.sort()

ans1=0
if n%2==0:
    for i in range(n):
        if i<n//2:
            ans1-=a[i]*2
        else:
            ans1+=a[i]*2
    ans1-=a[n//2]
    ans1+=a[n//2-1]
    print(ans1)
else:
    for i in range(n):
        if i<n//2:
            ans1-=a[i]*2
        elif i>n//2:
            ans1+=a[i]*2
    print(max(ans1+a[n//2]-a[n//2+1],ans1-a[n//2]+a[n//2-1]))

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

int main(){
    int K;
    string S;
    cin>>K>>S;
    if(S.size()<=K){
        cout<<S<<endl;
        return 0;
    }
    for(int i=0;i<K;i++){
        cout<<S.at(i);
    }
    cout<<"..."<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iomanip>
using namespace std;
 
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

int main() {

    ll N,Z,W; cin >> N >> Z >> W;
    vector < ll > a(N);
    REP(i,N) cin >> a[i];

    if (N == 1) {
        cout << abs(a[0] - W) << endl;
    } else {
        cout << max(abs(a.back() - W), abs(a[a.size() - 2] - a.back()))<< endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String x = scan.next();
		int fx =0;
		for (int i=0;i<x.length();i++) {
			fx = fx + Character.getNumericValue(x.charAt(i));
		}
		//System.out.println(x.charAt(1));
		if(Long.parseLong(x)%(long)fx==0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 21844
from math import ceil
a=[int(input())for i in range(5)]
m=1000
idx=100
for i,aa in enumerate(a):
  t=str(aa)
  t=t[-1]
  t=int(t)
  if 0<t<=m:
    m=t
    idx=i
ans=0
for i,aa in enumerate(a):
  if i==idx:
    ans+=aa
    continue
  ans+=ceil(aa/10)*10
print(ans)



# for i in range(5):
#   t=int(input())
#   q,r=divmod(t,10)
#   if r>0:
#     q+=1
  


Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long       ll;
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define mt                make_tuple
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define fore(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define forr(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define deb(x)			  cerr << "# " << (#x) << " = " << (x) << endl;
#define sz(x)             (int)x.size()
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const int INF = 1234567890;

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    int v[4];
    fore(i, 0, 4) {
        cin >> v[i];
    }
    ll res = -(1LL * 2e18);
    fore(i, 0, 2) {
        fore(j, 2, 4) {
            res = max(res, 1LL*v[i]*v[j]);
        }
    }
    cout << res << '\n';
    return 0;
}
// Dinosaurs are cool!

Measured memory_bytes: 3652
#include<stdio.h>

int main(void){
  long n[9999],i,sum=0,min,max,flag;
  scanf("%ld",&flag);

  for(i=0;i<flag;i++){
    scanf("%ld",&n[i]);
    sum=sum+n[i];
  }

  max=n[0];
  min=n[0];

  for(i=0;i<flag;i++){
    if(max<n[i]){
      max=n[i];
    }

    if(n[i]<min){
      min=n[i];
    }
  }

  printf("%ld %ld %ld\n",min,max,sum);

}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  map<int, int> count;
  rep(i, N)
  {
    cin >> a[i];
    count[a[i]]++;
  }
  SORT(a);
  bool is_ok = true;
  if (count.size() == 1)
  {
    if (a[0] != 0)
      is_ok = false;
  }
  else if (count.size() == 2)
  {
    if (2 * count[a[0]] != count[a[N - 1]] || a[0] != 0)
      is_ok = false;
  }
  else if (count.size() == 3)
  {
    vector<int> num;
    for (pair<int, int> P : count)
    {
      if (P.second != count.begin()->second)
        is_ok = false;
      num.push_back(P.first);
    }
    if ((num[0] xor num[1]) != num[2])
      is_ok = false;
  }
  else
    is_ok = false;

  if (is_ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 4224
N = int(input())
hxy = []
for _ in range(N):
    x, y, h = map(int, input().split())
    hxy.append((h, x, y))

# h >  0 => h == H - |x - CX| - |y - CY| (<= H)
# h == 0 => 0 >= H - |x - CX| - |y - CY|

hxy.sort(reverse=True)

MAX_X = 100
MAX_Y = 100

H = {(x, y): None for x in range(MAX_X + 1) for y in range(MAX_Y + 1)}

for h, x, y in hxy:
    for cx, cy in list(H.keys()):
        hh = h + abs(x - cx) + abs(y - cy)
        if   H[(cx, cy)] == None:
             H[(cx, cy)] =  hh
        elif H[(cx, cy)] > hh or (h > 0 and H[(cx, cy)] != hh):
             del H[(cx, cy)]

for cx, cy in H:
    print(cx, cy, H[(cx, cy)])


Measured memory_bytes: 44400
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define max_n 1000000

using namespace std;

void solve()
{
	ll n,k;
	cin>>n>>k;
		cout<<min((n/k+1)*k-n,n-(n/k)*k)<<endl;
	
}

int32_t main() 
{ 

	IOS	
	ll T=1;
	// cin>>T;
	for(ll i=1;i<=T;++i)
	{		
		// cout<<"Case #"<<i<<": ";
    	solve();
	}
	return 0;
}

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

using namespace std;

typedef long long int64;

int64 N, k;

bool check(int64 val)
{
  for(int i = 0; i < N - 1; i++) {
    val -= val / k + 1;
  }
  return (val >= 0);
}

int main()
{
  cin >> N >> k;
  int64 low = 0, high = 1000000000000000000LL;
  while(high - low > 0) {
    int64 mid = (low + high) >> 1;
    if(check(mid)) high = mid;
    else low = mid + 1;
  }
  cout << low << endl;
}

Measured memory_bytes: 3128
from math import gcd
a, b, c, d = map(int, input().split())
lcm = c * d // gcd(c, d)

x = (a - 1) - (a - 1) // c - (a - 1) // d + (a - 1) // lcm
y = b - b // c - b // d + b // lcm

print(y - x)

Measured memory_bytes: 9104
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}

fn main() {
    // 入力
    let N = get!(i64);

    let ans = if (0..N).any(|c| (0..N).any(|d| 4 * c + 7 * d == N)) {
        "Yes"
    } else {
        "No"
    };

    // 出力
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

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

int main() {

	int N, K;
	cin >> N >> K;

	vector<int> P(N), C(N);
	for (int i = 0; i < N; i++) cin >> P[i];
	for (int i = 0; i < N; i++) P[i]--;
	for (int i = 0; i < N; i++) cin >> C[i];

	lint ans = -LINF;
	for (int st = 0; st < N; st++) {

		vector<lint> used(N), point(N + 1);
		int loop = 0, now = st;
		for (int i = 0; i < min(N, K); i++, loop++) {
			if (used[now]) break;
			point[i + 1] = point[i] + C[now];
			used[now] = 1;
			now = P[now];
		}
		DMP(point, loop);
		if (point[loop] > 0 && loop < K) {
			int r = K / loop;
			point[0] = -LINF;
			if (chmax(ans, r * point[loop] + *max_element(point.begin(), point.begin() + K % loop + 1))) DMP(1, st, ans, point);
			if (chmax(ans, (r - 1) * point[loop] + *max_element(point.begin(), point.begin() + loop + 1))) DMP(2, st, ans, point);
		}
		else {
			if (chmax(ans, *max_element(point.begin() + 1, point.begin() + min(loop, K) + 1))) DMP(3, st, ans, point);
		}

	}

	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 3728
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (S, T) = read!(String, String);
    let (mut A, mut B) = read!(i64, i64);
    let U = rl();

    if U == S {
        A -= 1;
    } else if U == T {
        B -= 1;
    }

    println!("{} {}", A, B);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;

string S;
vector<string> decodes;

bool match(string decode, int p) {
  REP(i, 'b', 'z' + 1) {
    REP(j, 0, p) {
      if(decode[j] == i) {
        decode[j]--;
        break;
      }
    }
  }
  bool ret = true;
  REP(i, 0, p) if(decode[i] != S[i]) ret = false;
  return ret;
}

void dfs(int n, string s) {
  if(n >= s.length()) {
    if(match(s, n)) {
      decodes.push_back(s);
    }
    return;
  }

  dfs(n + 1, s);

  if(s[n] < 'z') {
    s[n]++;
    if(match(s, n)) {
      dfs(n + 1, s);
    }
    s[n]--;
  }
}

int main(void) {
  while(cin >> S, S != "#") {
    decodes.clear();
    string next = S;
    dfs(0, next);
    cout << decodes.size() << endl;
    if(decodes.size() <= 10) {
      REP(i, 0, decodes.size()) cout << decodes[i] << endl;
    } else {
      REP(i, 0, 5) cout << decodes[i] << endl;
      REP(i, decodes.size() - 5, decodes.size()) cout << decodes[i] << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 4284
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
const ll mod=998244353;
ll n,ri,le,s0,f[1000005];
struct node{
	int x,y;
	/*bool operator<(node b)const{
		return x-y>b.x-b.y;
	}*/
}a[1000005];
int tot;
char s[1000005];
int cmp(node a,node b){
	return a.x-a.y>b.x-b.y;
}
int main(){
	n=read();
	for(int i=1;i<=n;i++){
		ll l=0,r=0;
		scanf("%s",s+1);
		for(int j=1;s[j];j++)
			if(s[j]=='(')l++;
			else if(s[j]==')'){
				if(l)l--;
				else r++;
			}
		if(!l&&r)ri+=r;
		else if(l&&!r)le+=l;
		else if(l&&r)a[++tot]=(node){l,r};	
		//s0+=l-r;
	}
	//if(s0!=0)return puts("No"),0;
	sort(a+1,a+1+tot,cmp);
	for(int i=1;i<=tot;i++){
		if(le<a[i].y)
			return puts("No"),0;
		le-=a[i].y-a[i].x;
	}
	if(le!=ri)puts("No");
	else puts("Yes");
	return 0;
}

Measured memory_bytes: 5108
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let total: usize = iterator.next().unwrap().parse().unwrap();

    for x in 0..(n + 1) {
        for y in 0..(n - x + 1) {
            let z = n - x - y;
            if 10000 * x + 5000 * y + 1000 * z == total {
                return format!("{} {} {}", x, y, z);
            }
        }
    }

    return String::from("-1 -1 -1");
}


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


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

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

	std::vector<int> dp(n, 0);
	dp[1] = abs(heights[1] - heights[0]);
	//dp[2] = min(abs(dp[1] + heights[2] - heights[1]), abs(heights[2] - heights[0]));
	for(int i = 2; i < n; i++)
	{
		dp[i] = min(dp[i - 1] + abs(heights[i] - heights[i - 1]), dp[i - 2] + abs(heights[i] - heights[i - 2]));
	}

	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main() {
    int x, minj;
    cin >> x;
    string A[x], B[x], word = "Stable";
    for ( int i = 0; i < x; i++ ){
        cin >> A[i];
        B[i] = A[i];
    }
    for ( int i = 0; i < x; i++ ){
        for ( int j = x-1; j > i; j-- ){
            if ( A[j][1] < A[j-1][1] ){
                swap( A[j],A[j-1] );
            }
        }
    }
    for ( int i = 0; i < x; i++ ){
        if ( i == x-1 ){
            cout << A[i] << endl;
        } else {
            cout << A[i] << " ";
        }
    }
    cout << "Stable" << endl;
    for ( int i = 0; i < x; i++ ){
        minj = i;
        for ( int j = i; j < x; j++ ){
            if ( B[j][1] < B[minj][1] ){
                minj = j;
            }
        }
        swap( B[i], B[minj] );
    }
    for ( int i = 0; i < x; i++ ){
        if ( i == x-1 ){
            cout << B[i] << endl;
        } else {
            cout << B[i] << " ";
        }
        if (A[i] != B[i]) word ="Not stable";
    }
    cout << word << endl;
    return 0;
}



Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (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)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

map<ll, int> prime_factor(ll n) {
    map<ll, int> ret;
    for (ll i=2; i*i <=n; i++) {
        while (n%i==0) {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1) ret[n] = 1;
    return ret;
}

int main() {
	ll n, p;
	cin >> n >> p;
    ll ans = 1;
    for (auto a : prime_factor(p)) {
        if (a.second >= n) {
            ans *= pow(a.first, a.second/n);
        }
    }
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256