akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let patterns = ["eraser", "erase", "dreamer", "dream"];
    let s = patterns.iter().fold(read::<String>(), |s, x| s.replace(x, ""));
    println!("{}", if s.is_empty() { "YES" } else { "NO "});
}

Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include <string.h>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
const ll mod=1e9+7;

int main(void){
    ll N;
    cin>>N;
    ll A[3],B[3];
    cin>>A[0]>>A[1]>>A[2]>>B[0]>>B[1]>>B[2];
    //重さ制限N,重さga,sa,ba 価値gb,sb,bbのナップザック
    ll dp[4][N+1];
    memset(dp,0,sizeof(dp));
    rep(i,3){
        rep(j,N+1){
            if(j<A[i]) dp[i+1][j]=dp[i][j];
            else dp[i+1][j]=max(dp[i][j],dp[i+1][j-A[i]]+(B[i]-A[i]));
        }
    }
    
    ll M=dp[3][N]+N;
    ll dpa[M+1];
    rep(i,M+1) dpa[i]=0;
    rep(i,3){
        for(ll j=B[i];j<=M;j++){
            dpa[j]=max(dpa[j],dpa[j-B[i]]+(A[i]-B[i]));
        }
    }
    cout<<dpa[M]+M<<endl;
}


Measured memory_bytes: 195712
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long int n,sum=0;
    cin>>n;
    long int a[n+1],b[n],c[n+1];
    for(long int i=0;i<(n+1);i++)
    {
        cin>>a[i];
    }
    for(long int i=0;i<(n+1);i++)
    {
        c[i]=a[i];
    }
    for(long int i=0;i<n;i++)
    {
        cin>>b[i];
    }
    for(int i=0;i<n;i++)
    {
        if(b[i]>a[i])
        {
            b[i]=b[i]-a[i];
            a[i]=0;
        }
        else if(b[i]<a[i])
        {
            a[i]=a[i]-b[i];
            b[i]=0;
        }
        else if(b[i]==a[i])
        {
            b[i]=0;
            a[i]=0;
        }

        //second town
        if(b[i]>a[i+1])
        {
            b[i]=b[i]-a[i];
            a[i+1]=0;
        }
        else if(b[i]<a[i+1])
        {
            a[i+1]=a[i+1]-b[i];
            b[i]=0;
        }
        else if(b[i]==a[i+1])
        {
            b[i]=0;
            a[i+1]=0;
        }
    }
    for(long int i=0;i<(n+1);i++)
    {
        sum = sum + abs(c[i]-a[i]);
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <cassert>
#include <array>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<28));
const ll linf = (1LL<<58);

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 0;
    int p[n+1];
    for(int i=0; i<n; i++) cin >> p[i+1];
    if(p[1] == 1) swap(p[1], p[2]), ans++;
    if(p[n] == n) swap(p[n], p[n-1]), ans++;
    for(int i=2; i<n; i++)
    {
        if(p[i] == i && p[i-1] == i-1) swap(p[i-1], p[i]), ans++;
        else if(p[i] == i && p[i+1] == i+1) swap(p[i], p[i+1]), ans++;
        else if(p[i] == i) swap(p[i], p[i+1]), ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(auto i = k; i != n; i++)
#define rrep(i, n) RREP(i, n, -1)
#define RREP(i, n, k) for(auto i = n; i != k; i--)

#define debug(x) cerr << #x << " " << x << endl
#define print(x) cout << x;
#define println(x) cout << x << endl;
#define spc << " " <<

#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define eb emplace_back
#define np next_permutation

using ll = long long;
using Pii = pair<int, int>;
using Tiii = tuple<int, int, int>;
template<class T>using V = vector<T>;
template<class T>using VV = vector<vector<T>>;
using Vi = vector<int>;
using VVi = vector<vector<int>>;

class Task {
public:
   string name;
   int time;

   Task() {}

   Task(string n, int t) {
      name = n;
      time = t;
   }
};

int main() {
   int n, q_d; cin >> n >> q_d;
   queue<Task> q; rep(i, n) {
      string n;
      int t;
      cin >> n >> t;
      q.push(Task(n, t));
   }

   int time_cur = 0;
   while (!q.empty()) {
      Task task = q.front(); q.pop();
      if (task.time <= q_d) {
         time_cur += task.time;
         cout << task.name << " " << time_cur << endl;
      } else {
         time_cur += q_d;
         task.time -= q_d;
         q.push(task);
      }
   }

   return 0;
}



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

int main() {
  
  int n;
  cin >> n;
  vector<int> b(n+1);
  for(int i = 0; i < n-1; i++) { cin >> b.at(i); }
  
  b.at(n-1) = b.at(n-2);
  b.at(n) = 0;
  int ans = b.at(0);
  for(int i = 0; i < n; i++) {
    int t = i + 1;
    if(b.at(i) <= b.at(t)) {
      ans = ans + b.at(i);
    }else if(b.at(i) > b.at(t)) {
      ans = ans + b.at(t);
    }
  }
  cout << ans << endl;
}

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

bool canReach(int x1,int y1,int x2,int y2,int t){
	int length = abs(x1 - x2) + abs(y1 - y2);
	if( t >= length && (t-length) % 2 == 0) return true;
	return false;
}

int main()
{
	int n,x1,y1,t1;
	cin>>n;
	bool ans = true;
	x1 = 0;
	y1 = 0;
	t1 = 0;
	rep(i,n){
		int x2,y2,t2;
		cin>>t2>>x2>>y2;
		if( canReach(x1,y1,x2,y2,t2-t1) == false){
			ans = false;
		}
		x1 = x2,y1 = y2,t1 = t2;
	}
	if(ans == true){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}



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

Measured memory_bytes: 5144
#define ll long long
#define MOD 1000000007
#define MOD2 998244353
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define set2d(array, val, m, n) memset(array, val, sizeof(array[0][0]) * m * n);
#include <bits/stdc++.h>
using namespace std;
ll ans[20009] = {0};
vector<pair<ll, ll>> v[20000];
ll n;
void shortestPath(ll src)
{
    // Create a set to store vertices that are being
    // prerocessed
    set<pair<ll, ll>> setds;

    // Create a vector for distances and initialize all
    // distances as infinite (INF)
    vector<ll> dist(2009, INT_MAX);

    // Insert source itself in Set and initialize its
    // distance as 0.
    setds.insert(make_pair(0, src));
    dist[src] = 0;

    /* Looping till all shortest distance are finalized 
       then setds will become empty */
    while (!setds.empty())
    {
        // The first vertex in Set is the minimum distance
        // vertex, extract it from set.
        pair<ll, ll> tmp = *(setds.begin());
        setds.erase(setds.begin());

        // vertex label is stored in second of pair (it
        // has to be done this way to keep the vertices
        // sorted distance (distance must be first item
        // in pair)
        ll u = tmp.second;

        // 'i' is used to get all adjacent vertices of a vertex
        list<pair<ll, ll>>::iterator i;
        for (auto i = v[u].begin(); i != v[u].end(); ++i)
        {
            // Get vertex label and weight of current adjacent
            // of u.
            ll v = (*i).first;
            ll weight = (*i).second;

            //  If there is shorter path to v through u.
            if (dist[v] > dist[u] + weight)
            {
                /*  If distance of v is not INF then it must be in 
                    our set, so removing it and inserting again 
                    with updated less distance.   
                    Note : We extract only those vertices from Set 
                    for which distance is finalized. So for them,  
                    we would never reach here.  */
                if (dist[v] != INT_MAX)
                    setds.erase(setds.find(make_pair(dist[v], v)));

                // Updating distance of v
                dist[v] = dist[u] + weight;
                setds.insert(make_pair(dist[v], v));
            }
        }
    }

    for (int i = 1; i <= n; i++)
    {
        if (i != src)
            ans[dist[i]]++;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll x, y;
    cin >> n >> x >> y;
    for (int i = 1; i <= n - 1; i++)
    {
        v[i].pb(mp(i + 1, 1));
        v[i + 1].pb(mp(i, 1));
    }
    v[x].pb(mp(y, 1));
    v[y].pb(mp(x, 1));
    for (int i = 1; i <= n; i++)
    {
        shortestPath(i);
    }
    // ll ans[2005] = {0};
    // for (int i = 1; i <= n; i++)
    // {
    //     for (int j = 1; j <= n; j++)
    //     {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    for (int i = 1; i <= n - 1; i++)
        cout << ans[i] / 2 << endl;
}

Measured memory_bytes: 896
import sys


def input():
    return sys.stdin.readline().strip()


N, P = map(int, input().split())
A = list(map(int, input().split()))

odd = sum([a % 2 for a in A])
even = len(A) - odd

if odd == 0 and P == 1:
    print(0)
elif odd == 0 and P == 0:
    print(2 ** even)
else:
    ans = (2 ** even) * (2 ** (odd - 1))
    print(ans)


Measured memory_bytes: 3064
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int[][] a = new int[H][W];
		int[][] u = new int[H][W];
		StringBuilder ans = new StringBuilder();
		int N = 0;
		for(int i = 0; i < H; i++)
			for(int j = 0; j < W; j++)
				a[i][j] = sc.nextInt();
		int i = 0, j = 0;
		while(i < H && j < W) {
			if(a[i][j] % 2 == 1) {
				N++;
				if(i % 2 == 0) {
					if(j != W-1) {
						ans.append((i+1)+" "+(j+1)+" "+(i+1)+" "+(j+2)+"\n");
						a[i][j+1]++;
						j++;
					}
					else {
						if(i == H-1) {
							N--;
							break;
						}
						ans.append((i+1)+" "+(j+1)+" "+(i+2)+" "+(j+1)+"\n");
						a[i+1][j]++;
						i++;
					}
				}
				else {
					if(j != 0) {
						ans.append((i+1)+" "+(j+1)+" "+(i+1)+" "+(j)+"\n");
						a[i][j-1]++;
						j--;
					}
					else {
						if(i == H-1) {
							N--;
							break;
						}
						ans.append((i+1)+" "+(j+1)+" "+(i+2)+" "+(j+1)+"\n");
						a[i+1][j]++;
						i++;
					}
				}
			}
			else {
				if(i % 2 == 0) {
					if(j != W-1)
						j++;
					else
						i++;
				}
				else {
					if(j != 0)
						j--;
					else
						i++;
				}
			}
		}
		System.out.println(N);
		System.out.println(ans);
	}

}



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

int main () {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if ( A + B > C + D ) {
    cout << "Left" << endl;
  }
  else if ( A + B < C + D ) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}
    
  

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
char p[50][50], tp[50][50];
int n, m, S[50][50], D[50][50][50][50], sx, sy;
int Rect(int bx, int ex, int by, int ey){
    return S[ex][ey]-S[bx-1][ey]-S[ex][by-1]+S[bx-1][by-1];
}
int Get(int bx, int ex, int by, int ey){
    if(D[bx][ex][by][ey]!=-1)return D[bx][ex][by][ey];
    int Res = min(min(Rect(bx,sx,by,sy), Rect(sx,ex,by,sy)),min(Rect(bx,sx,sy,ey), Rect(sx,ex,sy,ey)));
    int i, j, k, l;
    for(i=bx;i<=ex;i++)for(j=by;j<=ey;j++){
        if((i==bx||i==ex) && (j==by||j==ey))continue;
        if(i<=sx && j<=sy){
            Res = min(Res, Get(i,ex,j,ey) + Rect(i,ex,by,j-1) + Rect(bx,i-1,j,ey));
        }
        if(i<=sx && j>=sy){
            Res = min(Res, Get(i,ex,by,j) + Rect(i,ex,j+1,ey) + Rect(bx,i-1,by,j));
        }
        if(i>=sx && j<=sy){
            Res = min(Res, Get(bx,i,j,ey) + Rect(bx,i,by,j-1) + Rect(i+1,ex,j,ey));
        }
        if(i>=sx && j>=sy){
            Res = min(Res, Get(bx,i,by,j) + Rect(bx,i,j+1,ey) + Rect(i+1,ex,by,j));
        }
    }
    return D[bx][ex][by][ey] = Res;
}
void Calc(){
    int i, j, k, l;
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            S[i][j]=S[i-1][j]+S[i][j-1]-S[i-1][j-1];
            if(p[i][j]=='#')S[i][j]++;
            if(p[i][j]=='P')sx=i,sy=j;
        }
    }
    for(i=1;i<=n;i++)for(j=i;j<=n;j++)for(k=1;k<=m;k++)for(l=k;l<=m;l++)D[i][j][k][l]=-1;
    printf("%d\n",Get(1,n,1,m));
}
int main(){
    int i, j;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++){
        scanf("%s",p[i]+1);
    }
    Calc();
}

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

struct Info
{
    int AC,penalty,tid;
    Info (int tid_){
        AC = penalty = 0;
        tid = tid_;
    }
    bool operator<(const Info &right) const {
        if(AC != right.AC){
            return AC > right.AC;
        }else if(penalty != right.penalty){
            return penalty < right.penalty;
        }else{
            return tid < right.tid;
        }
    }
};


int main(void){
    int T,P,R;
    while(cin>>T>>P>>R, T|P|R){
        vector<Info> info;
        rep(tid,T){
            info.push_back(Info(tid));
        }
        int wa[50][10] = {};
        rep(i,R){
            int tid, pid, time;
            string message;
            cin>>tid>>pid>>time>>message;
            tid--, pid--;
            if(message == "WRONG"){
                wa[tid][pid]++;
            }else{
                info[tid].AC++;
                info[tid].penalty += wa[tid][pid]*1200 + time;
            }
        }
        sort(all(info));
        for(Info i : info){
            printf("%d %d %d\n",i.tid+1, i.AC, i.penalty);
        }
    }

    return 0;
}



Measured memory_bytes: 3268
#include<cstdio>
#include<algorithm>
using namespace std;
#define ll long long
const int maxs=2005;
const ll mod=1e9+7;
ll f[maxs],inv[maxs];
ll quick_pow(ll a,int times)
{
    ll res=1;
    while(times)
    {
        if(times&1) res=(res*a)%mod;
        a=(a*a)%mod; times>>=1;
    }
    return res;
}
ll binom(int a,int b)
{
    if(a<b) return 0;
    return f[a]*inv[b]%mod*inv[a-b]%mod;
}
int main()
{
    int s;
    scanf("%d",&s);
    f[0]=1;
    for(int i=1;i<=s;i++)
        f[i]=f[i-1]*i%mod;
    inv[s]=quick_pow(f[s],(int)mod-2);
    for(int i=s-1;i>=0;i--)
        inv[i]=inv[i+1]*(i+1)%mod;
    int most=s/3;
    ll ans=0;
    for(int i=1;i<=most;i++)
        ans=(ans+binom(s-2*i-1,i-1))%mod;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1736
#include<stdio.h>
#include<string.h>

int main(){
	char str[1001];
	char lib[40][35],kazu[40];
	int i,j,w=0;
	int most=0;
	char longest[50]="";
	for(i=0;i<40;i++){
		kazu[i]=0;
		strcpy(lib[i],"");
	}
	gets(str);
	strcpy(lib[0],strtok(str," "));
	kazu[0]++;
	w++;
	while(1){
		int find=0;
		char* buf;
		buf = strtok(NULL," ");
		if(buf==NULL){
			break;
		}
		for(i=0;i<40;i++){
			if(strcmp(lib[i],buf)==0){
				kazu[i]++;
				find=1;
				break;
			}
		}
		if(find==0){
			strcpy(lib[w],buf);
			kazu[w]++;
			w++;
		}
	}
	for(i=0;i<w;i++){
		if(kazu[most]<kazu[i]){most=i;}
		if(strlen(longest)<strlen(lib[i])){
			strcpy(longest,lib[i]);
		}
	}
	printf("%s %s\n",lib[most],longest);
	return 0;
}

Measured memory_bytes: 540
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    for i in range(1, 10):
        for j in range(i, 10):
            if N == i * j:
                print('Yes')
                return

    print('No')
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9120
#include<stdio.h>
int main(){
 int i, j, num, gyou, kosuu, retu, A[150][150]={0};
 
 scanf("%d", &num);

 for(i=1; i<=num; i++){
   scanf("%d %d", &gyou, &kosuu);
   for(j=0; j<kosuu; j++){
     scanf("%d", &retu);
     A[gyou][retu]=1;
   }
 }

 for(i=1; i<=num; i++){
   for(j=1; j<num; j++){
     printf("%d ", A[i][j]);
   }
   printf("%d\n", A[i][num]);
 }

 return 0;
}

Measured memory_bytes: 1936
#include<stdio.h>
#define N 1000001

int linearSearch(int A[],int n,int key)
{
  int i=0;

  A[n]=key;
  if(A[0]==key){
    return 1;
  }
  while(A[i]!=key){
    i++;
  }
  if(i==n){
    return 0;
  }
  return i;
}

int main(){

  int i,n,q,key,sum=0,A[N];

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

  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&key);
    if(linearSearch(A,n,key)){
      sum++;
    }
  }


  printf("%d\n",sum);
  return 0;

}

Measured memory_bytes: 2792
# coding: utf-8
#N, h, w = map(int,input().split())
N = int(input())
h = int(input())
w = int(input())
#s = list(map(str,input().split()))
#a, b = map(int,input().split())
#P = list(map(int,input().split()))
ans = 0
if h*w!=0:
    print((N-h+1)*(N-w+1))
else:
    print((N-h+1)+(N-w+1))

Measured memory_bytes: 9076
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL unsigned long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head

const int N = 2e5 + 100;
char s[N], t[N];
int cnt[26], _cnt[26];
int main() {
	scanf("%s", s);
	scanf("%s", t);
	int n = strlen(s);
	for (int i = 0; i < n; i++) cnt[s[i]-'a']++;
	for (int i = 0; i < n; i++) _cnt[t[i]-'a']++;
	sort(cnt, cnt+26);
	sort(_cnt, _cnt+26);
	for (int i = 0; i < 26; i++) {
		if(cnt[i] != _cnt[i]) {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
} 

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

int main(){
  int N;
  cin >> N;
  vector<int> t(N+1);
  vector<int> x(N+1);
  vector<int> y(N+1);
  for(int i=1; i<N+1; i++) cin >> t.at(i) >> x.at(i) >> y.at(i);
  string ans="Yes";
  for(int i=1; i<N+1; i++){
    int dx=abs(x.at(i)-x.at(i-1));
    int dy=abs(y.at(i)-y.at(i-1));
    int dt=abs(t.at(i)-t.at(i-1));
    if(dx+dy>dt || (dx+dy)%2!=dt%2){
      ans="No";
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node
{
	int key;
	Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k)
{
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node*)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	
	while(x!=NIL) //不是空树 
	{
		y = x;
		if(z->key < x->key)
			x = x->left;
		else if(z->key > x->key)
			x = x->right;
	}
	z->parent = y;
	if(y == NIL)
	{
		root = z;
	}
	else
	{
		if (z->key < y->key)
		{
			y->left = z;
		}
		else
			y->right = z;
	}
	
}

void InOrderTraverse(Node *u)
{
	if(u == NIL)
		return;
	InOrderTraverse(u->left);
	printf(" %d", u->key);
	InOrderTraverse(u->right);
}

void PreOrderTraverse(Node *u)
{
	if(u == NIL)
		return;
	printf(" %d", u->key);
	PreOrderTraverse(u->left);
	PreOrderTraverse(u->right);
}
int main()
{
	int n, x;
	scanf("%d", &n);
	char s[10];
	for(int i = 0; i < n; i++)
	{
		scanf("%s", s);
		if(s[0] == 'i')
		{
			scanf("%d", &x);
			insert(x);
		}
		else if(s[0] == 'p')
		{
			InOrderTraverse(root);
			putchar('\n');
			PreOrderTraverse(root);
			putchar('\n');
		}
	}
	
	return 0;
}



Measured memory_bytes: 26552
/*

Author: @karngyan
Team: BlundersPride

*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::pair<ll,ll> pll;
typedef std::vector<vll> vvll;

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define max3( a, b, c ) max( a , max(b , c))
#define cres(c,n) (c).clear(),(c).resize(n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ff first
#define ss second
#define mk make_pair
const ll N = 51;
const ll m = 1e9+7;
ll n , k ;

vvll mul(vvll a , vvll b)
{
	vll t(n , 0);
	vvll r(n , t);
	rep(i,0,n)
	{
		rep(j,0,n)
		{
			r[i][j] = 0;
			rep(ii,0,n)
			{

				r[i][j] += (a[i][ii]*b[ii][j])%m;
				r[i][j] %= m;
			}
		}
	}
	return r;
}


vvll power(vvll a , ll k)
{
	vll t(n , 1);
	vvll res(n , t);
	if(k == 0)
		return res;
	if(k == 1)
		return a;

	res = power(a , k/2);
	if(k&1)
		return mul(a , mul(res , res));
	else
		return mul(res , res);
}

signed main()
{
	fast;
////////////////////////////////////////////////////////////////////////////////////////////
	cin >> n >> k;
	vvll a;
	vll tmp(n , 0);
	a.resize(n , tmp);
	rep(i,0,n)
		rep(j,0,n)
			cin >> a[i][j];

	a = power(a , k);
	ll ans = 0;
	rep(i,0,n)
		rep(j,0,n)
			ans+=a[i][j] , ans%=m;
	cout<<ans<<endl;

////////////////////////////////////////////////////////////////////////////////////////////

	
	return 0;
}


Measured memory_bytes: 2944
#include <stdio.h>
int wo(int チェックする数,int 使っちゃダメな数の配列[])
{
	while(チェックする数){
		
		//チェックする数の1桁目の数を取り出して配列に情報があるか見る
		if(使っちゃダメな数の配列[ チェックする数%10 ] == 1){
			return 1;　  //使われてたら 1 を返して whileを続ける ( while(1) で続く)
		}
		
		//チェックする数の桁を1つずらす (100 なら 10 になる)
		チェックする数 /= 10; 
	}
	return 0; // Okなら 0を返す
}
int main()
{
	int N; //入力用
	int K; //上記同様
	int num;//入力代理
	static int D[10]; //同上 static で配列を確保(初期値が無条件で0のため)
	
	scanf("%d %d",&N,&K);
	
	for(int i=0;i<K;i++){
		scanf("%d",&num);
		D[num]=1; //これでこの数字は使えないっていう情報を書き込める！
	}
	
	/*ここまで来たらNから10000までの数で適合する数を探す！*/

	while( wo(N,D) ){
			N++;　//Nから1ずつ増やして全部チェックしちゃう！
	}
	
	//出力して終わり
	printf("%d",N);
	
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define link(x) for(edge *j=h[x];j;j=j->next)
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,r,l) for(int i=r;i>=l;i--)
const int MAXN=3e5+10;
const double eps=1e-8;
const int mod=1e9+9;
#define ll long long
using namespace std;
struct edge{int t,v;edge*next;}e[MAXN<<1],*h[MAXN],*o=e;
void add(int x,int y,int vul){o->t=y;o->v=vul;o->next=h[x];h[x]=o++;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return x*f;
}


int n,m;

int ans[MAXN];
int a[MAXN];
int main(){
    n=read();m=read();
    inc(i,1,n)a[i]=read();
    int x,y;
    while(m--){
	x=read();y=read();
	ans[x]=max(ans[x],a[y]);
	ans[y]=max(ans[y],a[x]);
    }
    int cnt=0;
    inc(i,1,n)if(a[i]>ans[i])cnt++;
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 4544
const MOD: i64 = 1000000007;

fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let k: usize = s.next().unwrap().parse().unwrap();
	let mut edges = vec![vec![]; n];
	for _ in 0..n - 1 {
		let a = s.next().unwrap().parse::<usize>().unwrap() - 1;
		let b = s.next().unwrap().parse::<usize>().unwrap() - 1;
		edges[a].push(b);
		edges[b].push(a);
	}

	struct DFS<'a> {
		f: &'a dyn Fn(&DFS, usize, usize) -> i64,
	}
	let dfs = DFS {
		f: &|dfs, v, last| {
			let mut c = if last == std::usize::MAX {
				k as i64
			} else {
				std::cmp::max(0, k as i64 - 2)
			};
			let mut r = 1;
			for &to in edges[v].iter() {
				if to == last {
					continue;
				}
				r = r * c % MOD * (dfs.f)(&dfs, to, v) % MOD;
				c -= 1;
			}
			if last == std::usize::MAX {
				r * c % MOD
			} else {
				r
			}
		},
	};
	let ans = (dfs.f)(&dfs, 0, std::usize::MAX);
	println!("{}", ans);
}


Measured memory_bytes: 14396
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
using namespace std;
#define MOD 1000000007

long long dp[10001][101][2];

long long add(long long &x, long long y){
    x = (x+y)%MOD;
}

int main(){
    string K;
    cin >> K;
    int D;
    cin >> D;
    int N = K.size();

    dp[0][0][0] = 1;
    for(int i=0; i<N; i++){
        int x = K[i]-'0';
        for(int j=0; j<D; j++)
            dp[i+1][(j+x)%D][0] = dp[i][j][0];
        for(int j=0; j<D; j++){
            for(int k=0; k<x; k++)
                add(dp[i+1][(j+k)%D][1], dp[i][j][0]);
            for(int k=0; k<10; k++)
                add(dp[i+1][(j+k)%D][1], dp[i][j][1]);
        }
    }
    cout << ((dp[N][0][0] + dp[N][0][1])%MOD +(MOD-1))%MOD << endl;
    return 0;
}

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

int N,W;
long dp[105][10005];
vector<long> v(100);
vector<long> w(100);


int main() {

cin>>N>>W;
for(int i=0;i<N;i++) cin>>v[i]>>w[i];

for(int i=0;i<=N;i++){
  for(int j=0;j<=W;j++){
    dp[i][j]=0;
  }
}

for(int i=0;i<=N;i++){
  for(int j=0;j<=W;j++){
    if(j>=w[i]) dp[i+1][j]=max(dp[i][j],dp[i+1][j-w[i]]+v[i]);
    else dp[i+1][j]=dp[i][j];
  }
}

for(int i=0;i<=N;i++){
  for(int j=0;j<=W;j++){
  //  cout<<dp[i][j]<<" ";
  }
//  cout<<endl;
}

cout<<dp[N][W]<<endl;
}



Measured memory_bytes: 11112
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] array = new int[10];
		for(int i = 0; i < array.length; i++)
		array[i] = sc.nextInt();
		array = mergeSort(array);
		for(int i = 0; i < 3; i++)
		System.out.println(array[i]);
		}

		public static int[] mergeSort(int[] array) {
		if(array.length <= 1)
		return array;
		int[] head = split(array, 0, array.length / 2);
		int[] tail = split(array, array.length / 2, array.length);
		return merge(mergeSort(head), mergeSort(tail));
		}

		private static int[] split(int[] array, int start, int end) {
		int[] newArray = new int[end-start];
		for(int i = start, j = 0; i < end; i++, j++)
		newArray[j] = array[i];
		return newArray;
		}

		private static int[] merge(int[] a, int[] b) {
		int[] merged = new int[a.length + b.length];
		for(int i = 0, j = 0, k = 0; i < a.length + b.length; i++) {
		if(j == a.length || k == b.length)
		merged[i] = (j == a.length ? b[k++] : a[j++]);
		else
		merged[i] = (a[j] > b[k] ? a[j++] : b[k++]);
		}
		return merged;
		}
		}


Measured memory_bytes: 26124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ri register int
const int N=500005,M=1000000007;
int n,u[N],v[N],i,q,a[N],g[3005][3005],tmp[3005][3005],j;
long long inv,ans;
long long qpow(long long a,long long b)
{
	long long ans=1,s=a;
	while(b)
	{
		if(b&1)
			ans=ans*s%M;
		s=s*s%M;
		b>>=1;
	}
	return ans;
}
int main()
{
	scanf("%d %d",&n,&q);
	for(i=1;i<=n;++i)
		scanf("%d",&a[i]);
	for(i=1;i<=q;++i)
		scanf("%d %d",&u[i],&v[i]);
	for(i=1;i<=n;++i)
		for(j=1;j<=n;++j)
			if(a[i]>a[j])
				g[i][j]=1;
	inv=qpow(2,M-2);
	for(i=1;i<=q;++i)
	{
		for(j=1;j<=n;++j)
			if(j!=u[i]&&j!=v[i])
			{
				tmp[u[i]][j]=tmp[v[i]][j]=(g[v[i]][j]+g[u[i]][j])*inv%M;
				tmp[j][u[i]]=tmp[j][v[i]]=(g[j][u[i]]+g[j][v[i]])*inv%M;
			}
		tmp[v[i]][u[i]]=tmp[u[i]][v[i]]=(g[u[i]][v[i]]+g[v[i]][u[i]])*inv%M;
		for(j=1;j<=n;++j)
		{
			g[u[i]][j]=tmp[u[i]][j];
			g[v[i]][j]=tmp[v[i]][j];
			g[j][u[i]]=tmp[j][u[i]];
			g[j][v[i]]=tmp[j][v[i]];
		}	
	}
	for(i=1;i<=n;++i)
		for(j=i+1;j<=n;++j)
			ans+=g[i][j];
	ans%=M;
	cout<<(ans*qpow(2,q)%M+M)%M;
}


Measured memory_bytes: 76032
#include <iostream>
#include <climits>
#include <memory.h>
#include <random>
#include <ctime>
#include <cassert>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <deque>
#include <bitset>
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
#ifdef LOCAL
    #define DEBUG(x) { cerr << "# " << #x << ": " << x << endl;}
#else
    #define DEBUG(x)
#endif
mt19937_64 mt(time(0));
/*++++++++++++++++++++++++++++++++++++coding area start+++++++++++++++++++++++++++++++++++++++++*/
const int MAXN = 123;
int nums[MAXN];




/*-------------------------------------coding area end------------------------------------------*/
int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout.precision(10); cout << fixed;
    #ifdef LOCAL
//        freopen("../test.txt", "r", stdin);
//        freopen("../output.txt", "w", stdout);
    #endif
/*++++++++++++++++++++++++++++++++++++coding area start+++++++++++++++++++++++++++++++++++++++++*/

    int n; cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> nums[i];
    }
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (nums[i] == nums[i-1]) {
            cnt++;
            nums[i] = 0;
        }
    }
    cout << cnt << endl;



/*-------------------------------------coding area end------------------------------------------*/

    #ifdef LOCAL
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
    #endif
    return 0;
}
/* author:  txingml */


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
int main(){
    int x[6]={1,5,10,50,100,500},ans=0;
    for(int i=0;i<6;i++){
        int t;
        cin>>t;
        ans+=t*x[i];
    }
    if(1000<=ans)puts("1");
    else puts("0");
    return 0;
}

Measured memory_bytes: 1120
#include<bits/stdc++.h>
using namespace std;
bool shu[1000]={};
int main(){
  int n,x;
  cin>>x>>n;
  for(int i=1;i<=n;i++){int y;cin>>y;shu[y]=true;}
  int a,tot=0;
  for(a=x;a>=0;a--){if(shu[a])tot++;else break;}
  int b,len=0;
  for(b=x;b<=100;b++){if(shu[b])len++;else break;}
  if(tot<=len)cout<<x-tot;
  else cout<<x+len;
  return 0;
}

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

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

	int cnt = 0;
	int res = 0;
	for (int i = 0; i < s.length(); i++) {
		if (cnt == 0) {
			cnt++;
			if (s[i] == 'p') {
				res--;
			}
		} else if (cnt > 0) {
			if (s[i] == 'g') {
				res++;
				cnt--;
			} else if (s[i] == 'p') {
				cnt--;
			}
		}
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n, s) for (int i = 0; i < n; i += s)
#define graph map<int, vector<int>>
#define field vector<vector<int>>
#define len(x) (int)(x).size()
using namespace std;
int main()
{
    string s, t;
    cin >> s >> t;
    int n = len(s), m = len(t);
    int ans = 100000000;
    rep(i, n - m + 1, 1)
    {
        int k = 0;
        rep(j, m, 1)
        {
            if (s[i + j] != t[j])
                k++;
        }
        ans = min(ans, k);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n ;
  cin >>n;
  vector<double> a(n);
  for (int i=0;i<n;i++){
    cin>>a[i];
    }
    double  b = 0;
    for (int i=0;i<n;i++){
      b+=1/a[i];
     }
     cout<<1/b<<endl;
}

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

int main(){
	int i,j,len,flag;
	char str[1024];
	char a[6] = "apple",p[6] = "peach";

	fgets(str,1023,stdin);

	i = 0;
	len = strlen(str);
	while(i <= len){
		if(str[i] == 'a'){
			flag = 1;
			for(j = 0;j < 5;j++){
				if((i+j) > len || str[i+j] != a[j]){
					flag = 0;
				}
			}
			if(flag){
				for(j = 0;j < 5;j++){
					str[i+j] = p[j];
				}
			}
		}else if(str[i] == 'p'){
			flag = 1;
			for(j = 0;j < 5;j++){
				if((i+j) > len || str[i+j] != p[j]){
					flag = 0;
				}
			}
			if(flag){
				for(j = 0;j < 5;j++){
					str[i+j] = a[j];
				}
			}
		}
		i++;
	}

	printf("%s",str);

	return 0;
}

Measured memory_bytes: 524
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

def main():
    n, x = MII()
    mm = [II() for _ in range(n)]
    d = x - sum(mm)
    mind = min(mm)
    print(n+d//mind)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import java.util.Arrays;

public class Main {


  private static void solve() {
    char[] s = ns();
    
    Arrays.sort(s);
    if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 23124
#include <iostream>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

int main() {
  int N, Q;
  cin >> N >> Q;
  fenwick_tree<long long> t(N);
  for (int i = 0; i < N; ++i) {
    long long a;
    cin >> a;
    t.add(i, a);
  }
  
  for (int i = 0; i < Q; ++i) {
    long long q, arg0, arg1;
    cin >> q >> arg0 >> arg1;
    if (q == 0) {
      t.add(arg0, arg1);
    } else {
      cout << t.sum(arg0, arg1) << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 8204
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		int cnt = 0;
		int scnt = 0;
		for (int i=0; i<line.length(); i++) {
			char ch = line.charAt(i);
			if (ch == 'S') {
				scnt++;
			} else if (ch == 'T') {
				if (scnt > 0) {
					scnt--;
				} else {
					cnt++;
				}
			}
		}
		cnt += scnt;
		System.out.println(cnt);
	}

}


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

map<int, int> hv;

int main()
{
	int n; scanf("%d", &n);
	for (int i = 0;i < n;i++)
	{
		int x; scanf("%d", &x);
		hv[x]++;
	}
	for (auto u: hv) if (u.second > 1) n -= (u.second-1);
	if (!(n&1)) n--;
	printf("%d\n", n);
	return 0;
}


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

int main() {
  int N,H;
  cin >> N >> H;
  vector<int> a(N),b(N);
  for (int i=0;i<N;i++){
    cin >> a[i] >> b[i];
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  int x=a[N-1];
  int ans=0;
  for (auto itr=--b.end();itr>=lower_bound(b.begin(),b.end(),x);itr--){
    int y=*itr;
    H-=y;
    ans++;
    if (H<=0){
      break;
    }
  }
  if (H>0){
    ans+=(H+x-1)/x;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
main(){
	int w, p;
	while(scanf("%d", &w), w+1){
		p = 3130;
		if(w > 30)p -= 2650 + (w-30) * 160;
		else if(w > 20)p -= 1250 + (w-20) * 140;
		else if(w > 10)p -= (w-10) * 125;
		printf("%d\n", p);
	}
	return 0;
}

Measured memory_bytes: 0
h, w = map(int, input().split())
A = [list(input()) for _ in range(h)]

MOD = 10 ** 9 + 7

#dp[h][w]
dp = [[0] * w for _ in range(h)]
dp[0][0] = 1

for i in range(h):
  for j in range(w):
    if (i + 1 < h and A[i+1][j] == "."):
      dp[i+1][j] += dp[i][j] 
    if (j + 1 < w and A[i][j+1] == "."):
      dp[i][j+1] += dp[i][j] 
ans = dp[h-1][w-1] % MOD
print(ans)

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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    int n, ans; cin >> n;

    for(ans= 1; ans < n; ans*=2);
    cout << (ans > n ? ans/2 : ans);
}


Measured memory_bytes: 256
n = list(input())
for i in range(4):
    n[i] = int(n[i])

op1 = "+"
op2 = "+"
op3 = "+"

wa = sum(n)

if wa == 7:
    print(str(n[0])+op1+str(n[1])+op2+str(n[2])+op3+str(n[3])+"=7")
else:
    if wa - n[1]*2 == 7:
        op1 = "-"
    elif wa - n[2]*2 == 7:
        op2 = "-"
    elif wa -n[3]*2 == 7:
        op3 = "-"
    elif wa - n[1]*2 - n[2]*2 == 7:
        op1 = "-"
        op2 = "-"
    elif wa - n[1]*2 - n[3]*2 == 7:
        op1 = "-"
        op3 = "-"
    elif wa - n[2]*2 - n[3]*2 == 7:
        op2 = "-"
        op3 = "-"
    else:
        op1 = "-"
        op2 = "-"
        op3 = "-"

    print(str(n[0])+op1+str(n[1])+op2+str(n[2])+op3+str(n[3])+"=7")

Measured memory_bytes: 38384
#include<iostream>
#include<string>

using namespace std;
int main(void){
    string s1;
    string s2;
    int c = 0;
    cin >> s1 >> s2;
    for(int i = 0; i < 3;i++){
        if(s1[i] == s2[i]) c++;
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 256
class Walker
  attr_reader :post
  def initialize(preorder, inorder)
    @pre  = preorder
    @in   = inorder
    @post = []
    @pre_pos = 0
  end

  def reconstruct(left, right)
    return if right <= left
    root = @pre[ @pre_pos ]
    @pre_pos += 1
    in_pos = @in.index root
    reconstruct(left, in_pos)
    reconstruct(in_pos + 1, right)
    @post << root
  end
end

n_nodes  = gets.to_i
preorder = gets.split.map &:to_i
inorder  = gets.split.map &:to_i

walker = Walker.new(preorder, inorder)
walker.reconstruct 0, n_nodes

puts walker.post.join(' ')

Measured memory_bytes: 6864
h, w = map(int, input().split())
a = []
for _ in range(h):
  t = list(input())
  if t.count('.') != w:
    a.append(t)
i = 0
while True:
  if i >= len(a[0]):break
  for t in a:
    if t[i] != '.':
      i += 1
      break
  else:
    for j in range(len(a)):
      del a[j][i]
for t in a:
  print(''.join(t))

Measured memory_bytes: 38896
#include<bits/stdc++.h>
#define N 19
#define M 35009
using namespace std;
 
int n,m,a[N][N],f[M],g[M][N],dp[M][N];
int main(){
	scanf("%d%d",&n,&m);
	int i,j,k,x,y,z;
	for (i=1; i<=m; i++){
		scanf("%d%d%d",&x,&y,&z);
		a[x][y]=a[y][x]=z;
		f[1<<x-1|1<<y-1]+=z;
	}
	int tot=1<<n;
	for (i=1; i<=n; i++)
		for (j=1; j<tot; j++) if (j>>i-1&1) f[j]+=f[j^1<<i-1];
	memset(dp,195,sizeof(dp)); memset(g,195,sizeof(g));
	int ans=-1000000000;
	for (i=1; i<tot; i+=2){
		if (!(i>>n-1&1)) dp[i][1]=f[i];
		for (j=1; j<=n; j++) if (i>>j-1&1){
			for (k=i-1&i; k; k=k-1&i) if (k&1)
				dp[i][j]=max(dp[i][j],g[k][j]+f[i^k]);
			if (i>>n-1&1){ if (j==n) ans=max(ans,dp[i][j]); continue; }
			for (k=1; k<=n; k++) if (!(i>>k-1&1) && a[j][k]>0)
				g[i][k]=max(g[i][k],dp[i][j]+a[j][k]);
		}
	}
	printf("%d\n",f[tot-1]-ans);
	return 0;
}

Measured memory_bytes: 5632
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
 
int main(){
	int value[10], w;
	vector<int> v;

	for(int i=0; i<10; i++)
	{
		value[i] = (int)pow(2.0,i);
	}
	sort(value,value+10,greater<int>());

	while(cin>>w)
	{
		v.clear();
		for(int i=0; i<10; i++)
		{
			if(value[i]<=w)
			{
				w -= value[i];
				v.push_back(value[i]);
			}
		}
		for(int i=v.size()-1; i>=0; i--)
		{
			if(i == 0)
			{
				cout << v[i] << endl;
			}
			else
			{
				cout << v[i] << " ";
			}
		}
	}
    return 0;  
}  

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

int main() {
  double a,b,x;
  cin >> a >> b >> x;
  cout << fixed << setprecision(10);

  if(a*a*b/2 < x){  //おおい
    cout << atan(((a*a*b - x)*2/a/a/a)) * 180 / acos(-1) << endl;
  }else{  //すくない
    cout << atan(a*b*b/x/2)*180/acos(-1) << endl;
  }
}


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

int main(){
  int n;
  
  cin>>n;
  vector<int>a(n);
  
  
  
  for(int i=0;i<n;i++)
    cin>>a.at(i);
  
  int res=0;
  
  for (int i=0;i<n;i++)
    res+=a.at(i);
  
  res-=n;
  
  cout<<res;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
l=list(map(int,input().split()))
ans=1
for i in range(k):
    ans=l[i]

for i in range(k,n):
    prevans=l[i-k]
    ans=l[i]
    if ans>prevans:
        print("Yes")
    else:
        print("No")





Measured memory_bytes: 31620
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
//#include <bits/stdc++.h>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}



int main(){
    string s; cin >> s;
    
    s[3] = '8';
    
    cout << s << endl;
}



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

int const maxn = 1e5 + 100;

int N, M, X[maxn];
vector<int> seg;

int main()
{
  scanf("%d%d", &N, &M);

  for(int i = 0; i < M; i++) scanf("%d", &X[i]);
  sort(X, X+M);

  for(int i = 0; i < M-1; i++) seg.push_back(X[i+1]-X[i]);
  sort(seg.begin(), seg.end());

  int sum = 0;
  for(int i = 0; i < (M-1) - (N-1); i++) sum += seg[i];

  printf("%d\n", sum);

  return 0;
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MAX 414514
int n;
vector<int> dat[MAX*2-1];

int query(int a,int b,int u,int d,int k=0,int l=0,int r=n){
  //cout<<a<<" "<<b<<" "<<k<<" "<<l<<" "<<r<<endl;
  if(r<=a||b<=l) return 0;
  if(a<=l&&r<=b) {
    //cout<<a<<" "<<b<<" "<<k<<" "<<l<<" "<<r<<endl;
    return upper_bound(dat[k].begin(),dat[k].end(),u)
      -lower_bound(dat[k].begin(),dat[k].end(),d);
  }
  return query(a,b,u,d,k*2+1,l,(l+r)/2)+query(a,b,u,d,k*2+2,(l+r)/2,r);
}

int x[MAX],l[MAX],r[MAX],e[MAX];

signed main(){
  int d,q;
  cin>>d;
  vector<int> v;
  for(int i=0;i<d;i++){
    cin>>x[i];
    v.push_back(x[i]);
  }
  cin>>q;
  for(int i=0;i<q;i++){
    cin>>l[i]>>r[i]>>e[i];
    l[i]--;
    v.push_back(min(x[l[i]],x[r[i]-1])-e[i]);
    v.push_back(max(x[l[i]],x[r[i]-1])+e[i]);
  }
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  map<int,int> m;
  for(int i=0;i<(int)v.size();i++) m[v[i]]=i;
  
  n=1;
  while(n<d) n*=2;
  //cout<<n<<endl;
  
  for(int i=0;i<d;i++){
    dat[n-1+i].push_back(m[x[i]]);
  }
  
  for(int i=n-2;i>=0;i--){
    for(int k=1;k<=2;k++){
      for(int j=0;j<(int)dat[i*2+k].size();j++)
	dat[i].push_back(dat[i*2+k][j]);
    }
    sort(dat[i].begin(),dat[i].end());
  }
  /*//
  for(int i=0;i<n*2-1;i++){
    cout<<i<<"-"<<endl;
    for(int j=0;j<(int)dat[i].size();j++){
      cout<<dat[i][j]<<" ";
    }
    cout<<endl;
  }
  //*/
  for(int i=0;i<q;i++){
    //cout<<r[i]-l[i]<<endl;
    int inner=query(l[i],r[i],
		    m[max(x[l[i]],x[r[i]-1])+e[i]],
		    m[min(x[l[i]],x[r[i]-1])-e[i]]);
    int outer=query(l[i],r[i],v.size(),0);
    //cout<<outer<<":"<<inner<<endl;
    cout<<outer-inner<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 65596
import math
X = Y = a = 0
while True:
    x,y = map(int,input().split(','))
    if x == y == 0:
        break
    r = a * math.pi / 180
    X += x*math.sin(r)
    Y += x*math.cos(r)
    a+=y
print(*map(int,(X,Y)),sep='\n')


Measured memory_bytes: 5720
import sys
input = sys.stdin.readline
P = [list(map(int,input().split())) for i in range(2)]
T = int(input())
if(P[0][1]<P[1][1]):
  print('NO')
else:
  if(abs(P[0][0]-P[1][0])<=abs(P[0][1]-P[1][1])*T):
    print('YES')
  else:
    print('NO')

Measured memory_bytes: 9200
import java.util.Scanner;

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

		try (Scanner sc = new Scanner(System.in)) {
			int N = Integer.parseInt(sc.next());
			String S = sc.next();
			int K = Integer.parseInt(sc.next());
			StringBuilder sb = new StringBuilder();
			char c = S.charAt(K -1);
			for(char cc : S.toCharArray()) {
				if(cc == c) {
					sb.append(cc);
				} else {
					sb.append('*');
				}
			}
			System.out.println(sb.toString());
		} // Scanner Close
	}
}

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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	int n; cin >> n;
	vector<int> a(n);
	REPU(i, 0, n) cin >> a[i];
	if (a[0] != 0) {
		puts("-1"); return 0;
	}
	int last(0);
	ll ans = 0;
	REPU(i, 1, n) {
		if (a[i] > i - last || a[i] > a[i - 1] + 1) {
			puts("-1"); return 0;
		}
		else if (a[i] == a[i - 1] + 1) {
			ans++;
		}
		else {
			ans += a[i];
			if (a[i] == 0) last = i;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024