akhauriyash/Code-Regression huggingface dataset:
d,x,y,l,M[10],m[10],a[10];
main(){
	scanf("%*d");
	for(;~scanf("%d",&d);){
		l=l*2+d;
		if(++x==10){
			M[y]=l;
			x=l=0;
			if(++y==10){
				for(d=0;d<1<<10;d++){
					memcpy(m,M,sizeof(m));
					l=d;
					for(y=0;y<10;y++){
						a[y]=l;
						m[y]^=(l^l<<1^l>>1)&0x3ff;
						if(y+1<10)
							m[y+1]^=l;
						l=m[y];
					}
					if(m[9]==0){
						for(y=0;y<10;y++)
							for(x=10;x--;)
								printf("%d%c",a[y]>>x&1,x?' ':'\n');
						break;
					}
				}
				x=y=l=0;
			}
		}
	}
}

Measured memory_bytes: 0
import sys
readline = sys.stdin.readline

MOD = 998244353
A, B, C, D = map(int, readline().split())

dp = [[0]*D for _ in range(C)]
dp[A-1][B-1] = 1
for h in range(A, C):
    dp[h][B-1] = dp[h-1][B-1]*B%MOD

for w in range(B, D):
    dp[A-1][w] = dp[A-1][w-1]*A%MOD

for s in range(A+B, C+D-1):
    for h in range(A, C):
        w = s - h
        if not B-1 < w < D:
            continue
        dp[h][w] = (dp[h][w-1] + dp[h-1][w] + dp[h-1][w]*w + dp[h][w-1]*h - dp[h-1][w-1]*h*w)%MOD

print(dp[C-1][D-1])

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

int main(){
    int n;
    cin>>n;
    int a[n+5]={0};
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            for(int k=1;k<=100;k++){
                int s=i*i+j*j+k*k+i*j+j*k+k*i;
                if(s<=n) ++a[s];

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

Measured memory_bytes: 3564
// Aizu 1100: Area of Polygons
// 2017.9.12 bal4u@uu

#include <stdio.h>
#include <math.h>

typedef struct { int x, y; } PP;
PP p[52];

double calc_area(int n, PP *pp)
{
	int i;
	double s;

	if (n < 3) return 0;
	for (s = 0, i = 0; i < n; i++)
		s += (double)(pp[i].x-pp[i+1].x) * (double)(pp[i].y+pp[i+1].y);
   return fabs(s)/2.0;
}

int main()
{
	int n, i, cno = 0;

	while (scanf("%d", &n) && n) {
		for (i = 0; i < n; i++) scanf("%d%d", &p[i].x, &p[i].y); p[n] = p[0];
		printf("%d %.1lf\n", ++cno, calc_area(n, p));
	}
	return 0;
}

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

int main() {
	int H, W, D; cin >> H >> W >> D;
	vector<pair<int, int>> v(H*W+1);
	for(int i=0; i<H; ++i){
	    for(int j=0; j<W; ++j){
	        int a; cin >> a;
	        v[a]=make_pair(i, j);
	    }
	}
	vector<int> sum(H*W+1);
	for(int i=1; i<=H*W; ++i){
	    if(i<=D) sum[i]=0;
	    else sum[i]=sum[i-D]+abs(v[i].first-v[i-D].first)+abs(v[i].second-v[i-D].second);
	}
	int Q; cin >> Q;
	for(int i=0; i<Q; ++i){
	    int l, r; cin >> l >> r;
	    cout << sum[r]-sum[l] << endl;
	}
	return 0;
}


Measured memory_bytes: 2176
n=int(input())
a=[]
for i in range(n):
  x,l=map(int,input().split())
  a.append((x+l,2*l))
a.sort()
ans=1
x,l=a[0]
for i in range(1,n):
  xx,ll=a[i]
  if x<=xx-ll:
    ans+=1
    x,l=xx,ll
print(ans)

Measured memory_bytes: 16988
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 



int main() {
  int n, m, q; cin >> n >> m >> q;
  vvi a(n+1, vi(n+1));
  rep(i, m) {
    int l,r; cin >> l >> r;
    a[l][r]++;
  }
  vvi sum(n+1, vi(n+1, 0));
  rep(l, n+1) {
    rep(r, n) {
      sum[l][r+1] += sum[l][r] + a[l][r+1];  
    }
  } 
  // for (int i = 1; i <= n; i++) {
	// 	for (int j = 1; j <= n; j++) sum[i][j] = sum[i][j - 1] + a[i][j];
	// }

  auto solve = [&] {
    int l,r; cin >> l >> r;
    int ans = 0;
    for (int i=l; i<=r; i++) ans += sum[i][r] - sum[i][l-1];
    cout << ans << endl;
  };

  rep(i,q) solve();
  return 0;

}

Measured memory_bytes: 5544
#include <bits/stdc++.h>
#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 irep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
int main(){
    int w,h,n;
    cin>>w>>h>>n;
    vector<int> x(n),y(n),a(n);
    rep(i,n) cin>>x.at(i)>>y.at(i)>>a.at(i);
    int minx=0,maxx=w,miny=0,maxy=h;
    rep(i,n){
        if(a.at(i)==1) minx=max(minx,x.at(i));
        if(a.at(i)==2) maxx=min(maxx,x.at(i));
        if(a.at(i)==3) miny=max(miny,y.at(i));
        if(a.at(i)==4) maxy=min(maxy,y.at(i));
    }
    cout<<max(0,maxx-minx)*max(0,maxy-miny)<<endl;
}



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

int main()
{
  set<int> a;
  int n;
  cin >> n;
  bool ans = true;
  for (int i = 0; i < n; i++)
  {
    int num;
    cin >> num;
    if (a.find(num) == a.end())
    {
      a.insert(num);
    }
    else
    {
      ans = false;
      break;
    }
  }
  cout << (ans ? "YES" : "NO") << endl;
}


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

#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

   int N,A,B;
   cin>>N>>A>>B;
   ll ans = 0;
   for(int i=1;i<=N;i++){
      int sum = 0;
      int n = i;
      while(n!=0){
         sum += n%10;
         n/=10;
      }
      if(A<=sum&&sum<=B)ans += i;
   }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 256
s=input()

first_two=int(''.join(s[:2]))
last_two=int(''.join(s[2:]))

if 1<=first_two<=12 and 1<=last_two<=12:
  print('AMBIGUOUS')
elif 1<=last_two<=12:
  print('YYMM')
elif 1<=first_two<=12:
  print('MMYY')
else:
  print('NA')

Measured memory_bytes: 9016
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+:---test
3
3 1 2
2 5 4
3 6
---+/
/+---test
4
2 3 4 1
13 5 8 24
45 9 15
---+/
/+---test
2
1 2
50 50
50
---+/

void main(string[] args) {
  readln;

  const A = readln.split.map!(x => x.to!long-1).array;
  const B = readln.split.map!(to!long).array;
  const C = readln.split.map!(to!long).array;

  const N = A.length;

  long ans = B[A[0]];
  foreach (i; 1..N) {
    ans += B[A[i]];

    if (A[i-1]+1 == A[i]) {
      ans += C[A[i-1]];
    }
  }
  ans.writeln;
}


Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=1e5;
int n;
int a[maxn+8][3],rev[2];
ll mve[2];

int read()
{
    int x=0,f=1;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
    return x*f;
}

struct Binary_Index_Tree
{
    int tree[maxn+8];
    void insert(int x){for (;x<=n;x+=x&(-x)) tree[x]++;}
    int find(int x){int sum=0;for (;x;x-=x&(-x)) sum+=tree[x];return sum;}
}S[2];

int main()
{
    n=read();
    for (int i=1;i<=n;i++) a[i][0]=read();
    for (int i=1;i<=n;i++) a[i][1]=read();
    for (int i=1;i<=n;i++) a[i][2]=read();
    bool flag=1;
    for (int i=n;i;i--)
	{
	    int cnt=abs(a[i][0]-a[i][1])+abs(a[i][2]-a[i][1]);
	    if (cnt!=2)
		{
		    flag=0;
		    break;
		}
	    int x=min(a[i][0],a[i][2]);
	    if (x%3!=1||((((x+2)/3)^i)&1))
		{
		    flag=0;
		    break;
		}
	    if (a[i][0]>a[i][1]) rev[i&1]++;
	    mve[i&1]+=S[i&1].find((x+2)/3);
	    S[i&1].insert((x+2)/3);
	}
    //printf("%lld %d\n",mve[1],rev[1]);
    if ((!flag)||((mve[0]^rev[1])&1)||((mve[1]^rev[0])&1)) puts("No");
    else puts("Yes");
    return 0;
}


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

class P
{
    static void Main()
    {
        string[] s = Console.ReadLine().Split();
        Console.WriteLine(s[0].Last() == s[1][0] && s[1].Last() == s[2][0] ? "YES" : "NO");
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
int a[233333],b[233333],A[233333],B[233333],n,tmp,t1,t2,ans=0;
long long bb[32];
inline int in(){  
    int W=1,X=0;  
    char Ch=0;  
    while(!isdigit(Ch)){  
        if(Ch=='-') W=-1;  
        Ch=getchar();  
    }  
    while(isdigit(Ch))  
        X=(X<<3)+(X<<1)+(Ch^'0'),Ch=getchar();  
    return X*W;  
}

inline void out(int X,char *S){    
    if(X<0) putchar('-'),X=-X;    
    if(X>9)  out(X/10,"");    
    putchar(X%10+'0');    
    printf(S);    
}  

inline void getbits(){
	bb[0]=1;
	for(int i=1;i<=32;i++)
		bb[i]=bb[i-1]<<1;
}

int main(){
	n=in();
	for(int i=1;i<=n;i++)	
		a[i]=in();
	for(int i=1;i<=n;i++)
		b[i]=in();
	getbits();
	for(int i=0;i<30;i++){
		for(int j=1;j<=n;j++)
			A[j]=a[j]%bb[i+1],B[j]=b[j]%bb[i+1];
		sort(B+1,B+n+1);
		tmp=0;
		for(int j=1;j<=n;j++){
			t1=lower_bound(B+1,B+n+1,bb[i+1]-A[j])-lower_bound(B+1,B+n+1,bb[i]-A[j]);
			t2=lower_bound(B+1,B+n+1,bb[i+2]-A[j])-lower_bound(B+1,B+n+1,bb[i+1]+bb[i]-A[j]);
			tmp+=t1+t2;
			tmp&=1;
		}
		ans+=1ll*bb[i]*tmp;
	}
	out(ans,"");
}

Measured memory_bytes: 3328
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

vector<pair<int, int> > g[100000];

pair<int, int> dfs(int v, int par = -1) {
  pair<int, int> ret = {0, v};
  for (auto &x : g[v]) {
    int w, cost;
    tie(w, cost) = x;
    if (w == par)
      continue;
    auto tmp = dfs(w, v);
    ret = max(ret,  {cost+tmp.first, tmp.second});
  }
  return ret;
}

int solve() {
  auto v = dfs(0);
  auto w = dfs(v.second);
  return w.first;
}

int main() {
  int n;
  scanf(" %d", &n);
  REP (i, n-1) {
    int x, y, d;
    scanf(" %d %d %d", &x, &y, &d);
    g[x].push_back(make_pair(y, d));
    g[y].push_back(make_pair(x, d));
  }
  int ret = solve();
  printf("%d\n", ret);
  
  return 0;
}

Measured memory_bytes: 14944
S = input()
S_rev = S[::-1]
# amari = [0]
a = 0
from collections import defaultdict
d = defaultdict(int)
d[0]+=1
for i,s_r in enumerate(S_rev):
    x = pow(10,i,2019)
    # print(x)
    a = (a+int(s_r)*x)%2019
    # amari.append(a)
    d[a] += 1


ans = 0
for k in d.keys():
    n = d[k]
    ans += n*(n-1)//2
print(ans)

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

using ll = long long; 
using P = pair<int,int>;

int main() {

  int N;
  string S, T;
  cin >> N >> S >> T;

  
  rep(i,N){
    cout << S.at(i) << T.at(i);
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 256
import java.lang.StringBuilder
import java.util.*

fun main(args: Array<String>){
    val sc:Scanner = Scanner(System.`in`)

    val length = sc.nextInt()
    val S: String = sc.next()
    val T: String = sc.next()

    val sb = StringBuilder()

    for(i in 0..length-1){
        val s = S.substring(i,i+1)
        val t = T.substring(i,i+1)
        sb.append(s)
        sb.append(t)
    }

    println(sb.toString())

    sc.close()
}

Measured memory_bytes: 29352
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.run();
    }
    
    // 変数一覧
    String s;
    char[] ch;
    char[] ch1;
    char[] ch2;

    public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        s = sc.next();
        ch = s.toCharArray();
        sc.close();

        // 解答処理
        solve();
    }
    
    private void solve() {
        int n = ch.length;
        boolean c1 = true;
        boolean c2 = true;
        boolean c3 = true;

        ch1 = new char[(n - 1) / 2];
        ch2 = new char[(n - 1) / 2];
        for (int i = 0; i < (n - 1) / 2; i++) {
            ch1[i] = ch[i];
        }
        for (int i = 0; i <= n - (n + 3) / 2; i++) {
            ch2[i] = ch[i - 1 + ((n + 3) / 2)];
        }
        c1 = check(ch);
        c2 = check(ch1);
        c3 = check(ch2);
        if (c1 && c2 && c3) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
    
    private boolean check(char[] target) {
        boolean res = true;
        for (int i = 0; i < target.length / 2; i++) {
            if (target[i] != target[target.length - i - 1]) {
                res = false;
            }
        }
        return res;
    }
}

Measured memory_bytes: 21844
a[2][101],n,m,i,j,c,p;main(s){for(;scanf(m="%d",&n),n;printf(m>210?"NA\n":"%d\n",m)){for(a[0][n]=a[1][n]=i=2;i--;)for(j=0;j-n;scanf(m,a[i]+j++));for(i=2;i--;m>c?m=c:0)for(j=i,c=p=0;s=a[j][p],c<220&&s==2|n+~p;)s-2?s-1|a[j][p+1]-1?p+=2,j=1&~j,++c:++p:--p;}}

Measured memory_bytes: 0
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		String ans[] = {"Bad", "Good"};
		int an = 1;
		for(int i = 0; i < s.length() - 1; ++i) {
			if(s.charAt(i) == s.charAt(i + 1)) {
				an = 0;
				break;
			}
		}
		
		System.out.println(ans[an]);
	}
}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	ll N;
	cin >> N;
	ll A[N + 1];
	for(ll i = 0; i < N + 1; i++) cin >> A[i];
	if(N == 0) {
		if(A[0] == 1)
			cout << 1 << "\n";
		else
			cout << -1 << "\n";
		return 0;
	}
	ll lower[N + 2], sum[N + 1];
	sum[N] = A[N];
	lower[N] = (A[N] + 1) / 2;
	lower[N + 1] = (A[N] + 1) / 2;
	for(ll i = N - 1; i >= 0; i--) {
		sum[i] = sum[i + 1] + A[i];
		lower[i] = (lower[i + 1] + A[i] + 1) / 2;
	}
	// for(int i = 0; i < N + 1; i++) cout << i << " " << lower[i] << " " << sum[i] << "\n";

	ll ans = A[N], tmp = 1;
	for(ll i = 0; i < N + 1; i++) {
		// cout << i << " " << tmp << " " << lower[i + 1] << "\n";

		if(tmp < lower[i + 1]) {
			cout << -1 << "\n";
			return 0;
		}
		if(i == N) break;
		tmp = min(tmp, sum[i]);
		ans += tmp;
		tmp -= A[i];
		tmp *= 2;
	}

	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 5968
#include <stdio.h>

char ABCD[10];

int main(){

	scanf("%s",ABCD);

	int i,j,k;

	char op[2]={'-','+'};

	for(i=-1;i<=1;i+=2){
	for(j=-1;j<=1;j+=2){
		for(k=-1;k<=1;k+=2){
			int A=ABCD[0]-'0';
			int B=ABCD[1]-'0';
			int C=ABCD[2]-'0';
			int D=ABCD[3]-'0';
			char op1,op2,op3;

			if(i==-1){op1=op[0];}
			else{op1=op[1];}

			if(j==-1){op2=op[0];}
			else{op2=op[1];}

			if(k==-1){op3=op[0];}
			else{op3=op[1];}

			if(A+(i*B)+(j*C)+(k*D)==7){

			printf("%d%c%d%c%d%c%d=7\n",A,op1,B,op2,C,op3,D);
			return 0;
			}
		}
	}
	}

	return 0;
}

Measured memory_bytes: 128
import itertools
n= int(input())
pl = list(map(int,input().split()))
ql = list(map(int,input().split()))

lst = []
for v in itertools.permutations(range(1,n+1)):
    lst.append(''.join([str(i) for i in v]))

print(abs(lst.index(''.join([str(i) for i in pl]))-lst.index(''.join([str(i) for i in ql]))))

Measured memory_bytes: 6040
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
int H,W;
int d[50][50][50][50];
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
int s[50][50];
main()
{
	while(cin>>W>>H,H)
	{
		int tx,ty,kx,ky;
		cin>>ty>>tx>>ky>>kx;
		tx--,ty--,kx--,ky--;
		for(int i=0;i<H;i++)for(int j=0;j<W;j++)cin>>s[i][j];
		for(int i=0;i<H;i++)for(int j=0;j<W;j++)for(int k=0;k<H;k++)for(int l=0;l<W;l++)d[i][j][k][l]=114514;
		d[tx][ty][kx][ky]=0;
		queue<pair<pair<int,int>,pair<int,int> > >P;
		P.push(make_pair(make_pair(tx,ty),make_pair(kx,ky)));
		for(int T=1;T<100;T++)
		{
			queue<pair<pair<int,int>,pair<int,int> > >Q;
			while(!P.empty())
			{
				int x1=P.front().first.first,y1=P.front().first.second;
				int x2=P.front().second.first,y2=P.front().second.second;
				P.pop();
				for(int r=0;r<4;r++)
				{
					int tx1=x1+dx[r],ty1=y1+dy[r];
					int tx2=x2-dx[r],ty2=y2-dy[r];
					if(tx1<0||tx1>=H||ty1<0||ty1>=W||s[tx1][ty1]==1)tx1=x1,ty1=y1;
					if(tx2<0||tx2>=H||ty2<0||ty2>=W||s[tx2][ty2]==1)tx2=x2,ty2=y2;
					if(d[tx1][ty1][tx2][ty2]>T)
					{
						d[tx1][ty1][tx2][ty2]=T;
						Q.push(make_pair(make_pair(tx1,ty1),make_pair(tx2,ty2)));
					}
				}
			}
			P=Q;
		}
		int ans=114514;
		for(int i=0;i<H;i++)for(int j=0;j<W;j++)
		{
			if(ans>d[i][j][i][j])ans=d[i][j][i][j];
		}
		if(ans<100)cout<<ans<<endl;
		else cout<<"NA"<<endl;
	}
}



Measured memory_bytes: 29200
N=int(input())
S=input()

f=[False for i in range(10)]
fs=[[False for j in range(10)] for i in range(10)]
fst=[[[False for k in range(10)] for j in range(10)] for i in range(10)]

ans=0
for c in S:
    x=int(c)
    for i in range(10):
        for j in range(10):
            if fs[i][j] and not fst[i][j][x]:
                fst[i][j][x]=True
                ans+=1
    for i in range(10):
        if f[i] and not fs[i][x]:
            fs[i][x]=True
    if not f[x]:
        f[x]=True

print(ans)

Measured memory_bytes: 45016
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=100005;
const ll INF=1e18;
struct Edge{
	int from,to;
	ll dist;
	Edge(int u,int v,ll d):from(u),to(v),dist(d){};
};
struct HeapNode{
	ll d;
	int u;
	bool operator < (const HeapNode& rhs) const
	{
		return d>rhs.d;
	}
}; 
struct Dijk{
	int n,m,M;
	vector<Edge> edges;
	vector<int> G[maxn];
	bool done[maxn];
	ll d[maxn];
	int p[maxn];
	void init()
	{
		for(int i=1;i<=maxn;i++)
			G[i].clear();
		edges.clear();
	}
	void AddEdge(int from,int to,int dist)
	{
		edges.push_back(Edge(from,to,dist));
		M=edges.size();
		G[from].push_back(M-1);
	}
	void dijkstra(int s)
	{
		priority_queue<HeapNode> Q;
		for(int i=1;i<=n;i++)
			d[i]=INF;
		d[s]=0;
		memset(done,0,sizeof done);
		Q.push((HeapNode){0,s});
		while(!Q.empty())
		{
			HeapNode x=Q.top();
			Q.pop();
			int u=x.u;
			if(done[u])
				continue;
			done[u]=true;
			for(int i=0;i<(int)G[u].size();i++)
			{
				Edge& e=edges[G[u][i]];
				if(d[e.to]>d[u]+e.dist)
				{
					d[e.to]=d[u]+e.dist;
					p[e.to]=G[u][i];
					Q.push((HeapNode){d[e.to],e.to});
				}
			}
		}
	}
	void Domain()
	{
		int s,u,v,q,k;
		ll dis;
		scanf("%d",&n);
		init();
		for(int i=1;i<=n-1;i++)
		{
			scanf("%d%d%lld",&u,&v,&dis);
			AddEdge(u,v,dis);
			AddEdge(v,u,dis);
		}
		scanf("%d%d",&q,&k);
		dijkstra(k);
		for(int i=1;i<=q;i++) {
			scanf("%d%d",&u,&v);
			printf("%lld\n",d[u]+d[v]);
		}
	}
};
int main()
{
	Dijk a;
	a.Domain();
	return 0;
}

Measured memory_bytes: 14060
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

using namespace std;

typedef long long ll;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;

#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)
#define pi pair<int,int>
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define mod 1000000007
#define pai acos(-1)
#define N 100005


int main ()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int n,x,t;cin>>n>>x>>t;
   int d=(n-1)/x+1;
   cout<<t*d<<endl;

   return 0;
}



Measured memory_bytes: 3648
#!python3

# input
S = input()


def main():
    x = S[0] == 'A'
    y = S[2:-1].count('C') == 1
    z = sum([1 for s in S if 'A' <= s <= 'Z']) == 2
    if x and y and z:
        ans = "AC"
    else:
        ans = "WA"
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int hoge(int n, int s, vector<int> seq = {}) {
  int sum = 0;

  if (seq.size() != n) {
    int start = seq.empty() ? 0 : *seq.rbegin() + 1;
    for (int i = start; i < 10; ++i) {
      vector<int> tmp = seq;
      tmp.push_back(i);
      sum += hoge(n, s, tmp);
    }
  } else {
    do {
      int s2 = 0;
      for (int i = 0; i < n; ++i)
        s2 += seq[i] * (i + 1);
      sum += int(s2 == s);
    } while (next_permutation(seq.begin(), seq.end()));
  }

  return sum;
}

int main() {
  int n, s;

  while (cin >> n >> s)
    cout << hoge(n, s) << endl;
}


Measured memory_bytes: 3144
def resolve():
  a, b, c, x, y = map(int, input().split())
  ans = a * x + b * y
  ans = min(ans, c * max(x, y) * 2)
  if x > y:
    ans = min(ans, 2 * c * y + a * (x - y))
  else:
    ans = min(ans, 2 * c * x + b * (y - x))

  print(ans)
  return

if __name__ == "__main__":
  resolve()


Measured memory_bytes: 3060
S=input()
def dfs(s,i):
  if i==len(S)-1:
    return sum(map(int,s.split("+")))
  return dfs(f"{s}{S[i+1]}",i+1)+dfs(f"{s}+{S[i+1]}",i+1)
print(dfs(S[0],0))

Measured memory_bytes: 9088
#include <algorithm>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

struct Line {
  int y1, x1, y2, x2;
};

struct Interval {
  int s, t;
  bool operator<(const Interval &other) const {
    return t - s < other.t - other.s;
  }
};

void compress(int &H, int &W, vector<Line> &lines) {
  vector<int> ys = {{0, H}}, xs = {{0, W}};
  for (auto &line : lines) {
    ys.push_back(line.y1);
    xs.push_back(line.x1);
    ys.push_back(line.y2);
    xs.push_back(line.x2);
  }
  sort(ys.begin(), ys.end());
  ys.erase(unique(ys.begin(), ys.end()), ys.end());
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  for (auto &line : lines) {
    line.y1 = lower_bound(ys.begin(), ys.end(), line.y1) - ys.begin();
    line.x1 = lower_bound(xs.begin(), xs.end(), line.x1) - xs.begin();
    line.y2 = lower_bound(ys.begin(), ys.end(), line.y2) - ys.begin();
    line.x2 = lower_bound(xs.begin(), xs.end(), line.x2) - xs.begin();
  }
  H = ys.size() - 1;
  W = xs.size() - 1;
}

int edgeIndex(int H, int W, int y, int x) {
  if (y == 0) return W - x;
  if (x == 0) return W + y;
  if (y == H) return W + H + x;
  if (x == W) return W + H + W + (H - y);
  return -1;
}

vector<Interval> getEdgeIntervals(int H, int W, const vector<Line> &lines) {
  vector<Interval> intervals;
  for (auto &line : lines) {
    int s = edgeIndex(H, W, line.y1, line.x1);
    int t = edgeIndex(H, W, line.y2, line.x2);
    if (s != -1 && t != -1) {
      if (s > t) swap(s, t);
      intervals.push_back({s, t});
    }
  }
  return intervals;
}

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) {}
  bool unionSet(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};

int main() {
  int H, W, N;
  cin >> H >> W >> N;
  vector<Line> lines;
  for (int i = 0; i < N; i++) {
    int y1, x1, y2, x2;
    cin >> y1 >> x1 >> y2 >> x2;
    lines.push_back({y1, x1, y2, x2});
  }
  compress(H, W, lines);
  int size = 2 * (H + W);
  vector<Interval> intervals = getEdgeIntervals(H, W, lines);
  sort(intervals.begin(), intervals.end());
  UnionFind uf(size);
  bool res = true;
  for (auto &interval : intervals) {
    if (uf.size(interval.s) > 1 || uf.size(interval.t) > 1) {
      res = false;
      break;
    }
    for (int i = interval.s; i <= interval.t;) {
      int skip = uf.size(i);
      uf.unionSet(interval.s, i);
      i += skip;
    }
  }
  cout << (res ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 5240
import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in);

    public static void main(String[] args) {
        String num;
        int len;
        while(Integer.parseInt(num = scn.next()) > 0 | (len = scn.nextInt()) > 0) {
            Map<String, Integer> map = new HashMap<>();
            num = String.format("%0" + len + "d", Integer.parseInt(num));
            map.put(num, 0);
            int idx = 1;
            for(;;) {
                List<Character> list = new ArrayList<>();
                for(char elm : num.toCharArray()) {
                    list.add(elm);
                }

                Collections.sort(list);
                int min = characterListToInt(list);
                Collections.reverse(list);
                int max = characterListToInt(list);

                num = String.format("%0" + len + "d", max - min);
                Integer rslt;
                if((rslt = map.get(num)) == null) {
                    map.put(num, idx++);
                } else {
                    System.out.println(rslt + " " + Integer.parseInt(num) + " " + (idx - rslt));
                    break;
                }
            }
        }
    }

    private static int characterListToInt(List<Character> list) {
        StringBuilder sb = new StringBuilder();
        for(char elm : list) {
            sb.append(elm);
        }
        return Integer.parseInt(sb.toString());
    }
}

Measured memory_bytes: 29940
#include<cstdio>
const static int MAX_H = 50;
const static int MAX_W = 50;
bool is_black[MAX_H+2][MAX_W+2];
int x[4] = {-1, 0, 1, 0}, y[4] = {0, -1, 0, 1};

int main(){
    unsigned H, W;
    scanf("%u %u", &H, &W);
    for (size_t i = 1; i <= H; i++){
        scanf("\n");
        for (size_t j = 1; j <= W; j++){
            char s;
            scanf("%c", &s);
            is_black[i][j] = s == '#';
        }
    }
    bool isolated;
    for (int i = 1; i <= H; i++){
        for (int j = 1; j <= W; j++){
            if(!is_black[i][j]) continue;
            isolated = true;
            for (size_t k = 0; k < 4; k++){
                if(is_black[i + x[k]][j + y[k]]){
                    isolated = false;
                    break;
                }
            }
            if(isolated){
                printf("No\n");
                return 0;
            }
        }
    }
    printf("Yes\n");
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define DBG(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const ll p = 1e9+7;
const ll INF = 1LL << 60;

int main(){
  ll n;
  cin>>n;
  set<ll> st;
  st.insert(n);
  for(int m=2;;m++){
    ll fn;
    if(n%2)fn=3*n+1;
    else fn=n/2;
    if(st.count(fn)){
	 cout<<m<<endl;
	 break;
    }
    st.insert(fn);
    n=fn;
  }
  return 0;
}


Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

s = input()
n = len(s)
if s[0]=="0" or s[-2]=="0" or s[-1]=="1":
    print("-1")
elif any(s[i]!=s[-2-i] for i in range(n-1)):
    print("-1")
else:
    i = 1
    ps = set([i])
    es = []
    for c in s[1:]:
        i += 1
        if c=="0":
            ps.add(i)
        else:
            for u in ps:
                es.append("%s %s" % (u,i))
            ps = set([i])
    for u in ps:
        if u!=n:
            es.append("%s %s" % (u, n))
    write("\n".join(es))

Measured memory_bytes: 68708
class Tree():

    def __init__(self):
        self.parent = -1
        self.depth = 0
        self.child = []

n = int(input())
tree = [Tree() for i in range(n)]
for i in range(n):
    cmd = list(map(int, input().split()))
    node = tree[cmd[0]]
    node.child.extend(cmd[2:])
    for j in cmd[2:]:
        tree[j].parent = cmd[0]

for t in tree:
    d, p = 0, t.parent
    while p != -1:
        d += 1
        p = tree[p].parent
    t.depth = d

for i in range(n):
    t = tree[i]
    if t.parent == -1:
        state = "root"
    elif t.child:
        state = "internal node"
    else:
        state = "leaf"
    print("node {}: parent = {}".format(i, t.parent), "depth = {}".format(
        t.depth), state, "[{}]".format(", ".join(map(str, t.child))), sep=", ")

Measured memory_bytes: 42484
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(c,itr) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define INF 1e9
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
int main(){
	int n;
	cin>>n;
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(i%2==1){
			cnt++;
		}
	} 
	double ans=cnt;
	ans/=n;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
using namespace std;
int k;
//const ll N=2e5+5;
//vector<ll> adj[N];

void solve()
{
ll n;
cin>>n;
vector<ll> v(n);
ll mx=INT_MIN;
for(int i=0;i<n;i++) {cin>>v[i];mx=max(mx,v[i]);}
ll ans=0;
for(int i=0;i<n;i++)
{
    ll x=v[i];
    while(x)
    {
        if(x>0) {ans++;x--;}
        for(int j=i-1;j>=0;j--)
            if(v[j]==0) break;
            else v[j]--;
        for(int j=i+1;j<n;j++)
            if(v[j]==0) break;
            else v[j]--;
    }
}
cout<<ans;


}
int main()
{   ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    for(int i=1;i<=t;i++)
    {
        solve();
    }
}


Measured memory_bytes: 256
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 n : u64 = read();
    let k : u64 = read();
    let mut h : Vec<u64> = (0..n).map(|_| read()).collect();

    //降順
    //h.sort_by(|x, y| x.cmp(y).reverse());
    h.sort();

    for _ in 0..k {
        h.pop();
    }

    let ans : u64 = h.iter().fold(0, |sum, i| sum + i);

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


Measured memory_bytes: 6524
x = int(input())


def prime(n):
    flag = ''
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            break
    else:
        flag = 'prime_number'

    return(flag)


while(prime(x) != 'prime_number'):
    x += 1

print(x)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
  long p = 1e9+7;
long ncrmodp(int n,int r){
  long ans = 1;
  long tmp = 1;
  for(int i=n-r+1;i<=n;i++){
    ans *= i;
    ans %= p;
  }
  for(int i=2;i<=r;i++){
    tmp *= i;
    tmp %= p;
  }
  for(long bit = 1;bit<=p-2;bit*=2){
    if(bit & (p-2)){
      ans *= tmp;
      ans %= p;
    }
    tmp *= tmp;
    tmp %= p;
  }

  return ans;
  
}


int main(){
    int x,y;
    cin >> x >> y;
    if((x+y)%3 != 0)cout << 0 << endl;
    else if(x > y*2 || y > x*2)cout << 0 << endl;
    else{
      int n = (x+y)/3;
      int r;
      for(int i=0;i<=n;i++){
        if(2*i + abs(x-y) == n){
          r = i;
          break;
        }
      }
      cout << ncrmodp(n,r)<<endl;
      
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
typedef long long ll;

int main()
{
    int n;
    scanf("%d",&n);
    vector<int>x(n);
    for(int i=0;i<n;i++){
        scanf("%d",&x[i]);
    }
    int minn=INF;
    for(int i=1;i<=100;i++){
        int sum=0;
        for(int j=0;j<n;j++){
            sum+=(i-x[j])*(i-x[j]);
        }
        minn=min(minn,sum);
    }
    cout<<minn<<endl;
}


Measured memory_bytes: 256
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    N, K = read_int_list()
    H = read_int_list()
    res = 0
    if K < N:
      H.sort(reverse=True)
      del H[0:K]
      res = sum(H)
    print(res)

main()


Measured memory_bytes: 27936
#include<iostream>
using namespace std;
double x[3],y[3],xp,yp;
int solve(){
	int tes=0,i,j;
	for(i=0,j=2;i<3;j=i++){
		if(((yp>y[i]&&yp<=y[j])||(yp<=y[i]&&yp>y[j]))&&xp<=(x[i]-x[j])*(yp-y[i])/(y[i]-y[j])+x[i])
			tes++;
	}
	
	return tes%2==1;
}
int main(){
	while(cin>>x[0]>>y[0]>>x[1]>>y[1]>>x[2]>>y[2]>>xp>>yp){
		if(solve()==1)
			cout<<"YES"<<endl;
		else
		cout<<"NO"<<endl;
	}
	return 0;
}

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

int main()
{
	double a, b;
	string str;
	vector<double> st;
	while (cin >> str) {
		if (str == "+") {
			b = st.back(); st.pop_back();
			a = st.back(); st.pop_back();
			st.push_back(a + b);
		}
		else if (str == "-") {
			b = st.back(); st.pop_back();
			a = st.back(); st.pop_back();
			st.push_back(a - b);
		}
		else if (str == "*") {
			b = st.back(); st.pop_back();
			a = st.back(); st.pop_back();
			st.push_back(a * b);
		}
		else if (str == "/") {
			b = st.back(); st.pop_back();
			a = st.back(); st.pop_back();
			st.push_back(a / b);
		}
		else
			st.push_back(stof(str));
	}
	for (auto i : st)
		cout << fixed << setprecision(6) << i << endl;
	return 0;
}

Measured memory_bytes: 3236
#include <bits/stdc++.h>
#define llint long long
#define rg register
#define RI register int
#define RC register char
#define rg register
#define ed putchar('\n')
#define space putchar(' ')
#define Pair pair<int,int >
using namespace std;
	
template <typename tp> inline void read(tp &x)
{	
	x=0;
	RI f=1;
	RC c=getchar();
	while(c<'0' || c>'9') {if(c=='-') f=-1;c=getchar();}
	while(c>='0' && c<='9') {x=(x<<1)+(x<<3)+(c^48);c=getchar();}
	x*=f;
}	
	
template <typename tp> inline void print(tp x)
{	
	if(x<0) x=-x,putchar('-');
	if(x>9) print(x/10);
	putchar(x%10+'0'); 
}

#define int long long
const int N=1e6+10;
int len;
int k;
char s[N];
int ans;
int stk[N],pos;

signed main()
{
	scanf("%s",s+1);
	read(k);
	int len=strlen(s+1);
	for(RI i=2;i<=len;++i) 
		if(s[i]==s[i-1]) 
			stk[++pos]=i; 
	stk[0]=-10;
	int base=0,flg=1;
	for(RI i=1;i<=pos;++i)
	{
		++base;
		if(stk[i]==stk[i-1]+1)
		{
			if(flg) --base,flg=0;
			else flg=1;
		}
		else 
			flg=1;
	}
	if(k==1)
	{
		print(base);
		return 0;
	}
	for(RI i=len+1;i<=len*3;++i) s[i]=s[i%len==0?len:i%len]; 
	pos=0;
	for(RI i=2;i<=len*3;++i) if(s[i]==s[i-1]) stk[++pos]=i;
//	for(RI i=1;i<=len*3;++i) putchar(s[i]),bl;ed;
	int es=0;flg=1;
	for(RI i=1;i<=pos;++i)
	{
		++es;
		if(stk[i]==stk[i-1]+1)
		{
			if(flg) --es,flg=0;
			else flg=1;
		}
		else flg=1;
	}
	int delta=es-base,tp=k-1; 
	llint ans;
	if(!(tp&1))
	{
		ans=1ll*delta*(tp/2)+base;
		print(ans);
		return 0;
	}
	for(RI i=len+1;i<=len+len;++i) s[i]=s[i-len]; 
	pos=0;
	for(RI i=2;i<=len+len;++i) if(s[i]==s[i-1]) stk[++pos]=i;
	es=0;
	flg=1;
	for(RI i=1;i<=pos;++i)
	{
		++es;
		if(stk[i]==stk[i-1]+1)
		{
			if(flg) --es,flg=0;
			else flg=1;
		}
		else flg=1;
	}
	int delta2=es-base;
	if(tp==1)
	{
		print(es);
		return 0;
	}
	ans=1ll*delta*(tp/2)+base+delta2;
	print(ans);
	return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
vector<string> uvs;
pair<int,string> solve(void){
  string answer="";
  for(string &s:uvs){
    int ol=min(answer.size(),s.size());
    for(;ol>0;--ol){
      bool flag=true;
      REP(i,ol) if(answer[answer.size()-ol+i]!=s[i]){
	flag=false;
	break;
      }
      if(flag) break;
    }	       
    for(auto i=s.begin()+ol;i!=s.end();++i) answer.push_back(*i);
  }
  return make_pair(answer.size(),answer);
}
int main(void)
{
  for(;;){
    int n;
    cin >> n;
    if(!n) return 0;
    vector<pair<int,string> > vs(n);
    uvs.clear();
    REP(i,n){
      string s;
      cin >> s;
      vs[i]=make_pair(-(int)s.size(),s);
    }
    SORT(vs);
    REP(i,n){
      bool flag=true;
      REP(j,i) REP(k,vs[i].first-vs[j].first){
	string tmp=vs[j].second;
	string r(tmp.begin()+k,tmp.begin()+k-vs[i].first);
	if(vs[i].second==r) flag=false;
      }
      if(flag) uvs.push_back(vs[i].second);
    }
    SORT(uvs);
    pair<int,string> answer(1000,"");
    do{
      answer=min(answer,solve());
    }while(next_permutation(uvs.begin(),uvs.end()));
    cout << answer.second << endl;
  }
}

Measured memory_bytes: 3156
#include <stdio.h>
#define N 10000
#define M 500

int ls(int s[],int n,int key);

int main(){
  int n,q,key;
  int s[N];
  int count=0;
  int i;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if(ls(s,n,key)==1) count++;
  }
  printf("%d\n",count);
  return 0;
}

int ls(int s[],int n,int key){
  int i=0;
  s[n]=key;
  while(s[i]!=key){
    i++;
    if(i==n) return 0;
  }
  return 1;
}

Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
	Scanner in = new Scanner(System.in);

	int[] a = new int[3];

	for(int i=0; i<a.length; i++){
	    a[i]=in.nextInt();
	}
	Arrays.sort(a);
	for(int i=0; i<a.length; i++){
	    System.out.print(a[i]);
	    if(i != a.length-1)System.out.print(" ");
	    else System.out.println();
	}

   }
}



Measured memory_bytes: 26160
#include<bits/stdc++.h>
using namespace std;
#define MN 200005
#define LL long long
#define mp make_pair
#define fir first
#define sec second
#define pii pair<int,int>
inline void chkmax(int &a,int b){if(a<b)a=b;}
inline void chkmin(int &a,int b){if(a>b)a=b;}
inline int read(){
	   int a=0,fh=1;char c=getchar();
	   while(c>'9'||c<'0'){if(c=='-')fh=-1;c=getchar();}
	   while('0'<=c&&c<='9'){
		   a=a*10+c-48;
		   c=getchar();
	   }
	   return a*fh;
}
int n,m,f[105][105];
char ch[105][105];
int qwq[105][105][105][105];
bool chk(int x,int y,int a,int b){
	if(qwq[x][y][a][b])return qwq[x][y][a][b]-1;
	if(x==a&&y==b)return 1;
	if(x>a||y>b)return 0;
	int op=0;
	if(ch[x][y+1]=='#')op|=chk(x,y+1,a,b);
	if(ch[x+1][y]=='#')op|=chk(x+1,y,a,b);
	qwq[x][y][a][b]=op+1;
	return op;
}
int main(){
	n=read();m=read();
	for(int i=1;i<=n;++i){
		scanf("%s",ch[i]+1);
	}
	memset(f,0x3f,sizeof(f));
//	f[1][1]=(ch[1][1]=='#');
	f[1][0]=0;ch[1][0]='.';
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j){
			f[i][j]=min(f[i][j-1]+(ch[i][j-1]!=ch[i][j]),f[i-1][j]+(ch[i-1][j]!=ch[i][j])); 
		}			
	printf("%d\n",(f[n][m]+(ch[n][m]=='#'))/2);
	return 0;
}

















Measured memory_bytes: 256
#include<cstdio>
#include<set>
#include<functional>
#include<utility>
#include<algorithm>
using namespace std;

int main(){
    unsigned N;
    scanf("%u", &N);
    pair<unsigned, unsigned> red[N];
    set<pair<unsigned, unsigned> > blue;
    unsigned a, b;
    for(int i = 0; i < N; ++i){
        scanf("%u %u", &red[i].first, &red[i].second);
    }
    sort(red, red + N, greater<pair<unsigned, unsigned> >());
    unsigned c, d;
    for(int i = 0; i < N; ++i){
        scanf("%u %u", &c, &d);
        blue.emplace(d, c);
    }
    unsigned answer = 0;
    for(auto i : red){
        for(auto j : blue){
            if(j.second > i.first && j.first > i.second){
                answer++;
                blue.erase(j);
                break;
            }
        }
    }
    printf("%u\n", answer);
	return 0;
}

Measured memory_bytes: 3276
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <map>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <bitset>
#include <functional>
using namespace std;
const constexpr int INF = 1e9;
typedef pair<int, int> P;
int N, A, B, C, D, E, F;
int a[200001];
string X;
struct Node{
    int from, to, cost;
};
void solve(){
    int odd=0;
    for(int i=0; i<N; ++i){
        int a; cin >> a;
        if(a%2!=0) odd++;
    }
    if(odd%2!=0) cout << "NO" << endl;
    else cout << "YES" << endl;
}
int main() {
    cin >> N;
    solve();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <set>
using namespace std;

#define rep(i,a) for(long long i = 0 ; i < a ; i ++)
#define vi vector<long long>

int main(void){
  int w,h;
  cin>>w>>h;
  long long p, q;
  vector<pair<long long,int> > pa(w+h);
 
  rep(i,w){
    cin>>p;
    pa[i] = make_pair(p,1);
  }
  rep(i,h){
    cin>>q;
    pa[w + i] = make_pair(q,2);
  }
  p = h + 1, q = w + 1;
 
  sort(pa.begin(),pa.end());
  long long ret = 0;
  rep(i,pa.size()){
    if(pa[i].second == 1){ // y
      ret += p * pa[i].first;
      q--;
      if(q == 0)break;
    //  cout<<p * pa[i].first<<" ";
    } else { // x
      ret += q * pa[i].first;
      p--;
      if(p == 0)break;
    //  cout<<q * pa[i].first<<" ";
    }   
  }
  cout<<ret<<endl;
}

Measured memory_bytes: 3456
N = int(input())

a = {
    0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f', 6:'g', 7: 'h', 8: 'i', 9: 'j', 10: 'k', 11: 'l', 12: 'm', 13: 'n',
    14: 'o', 15: 'p', 16: 'q', 17: 'r', 18: 's', 19: 't', 20: 'u', 21: 'v', 22: 'w', 23: 'x', 24: 'y', 25: 'z'
    }
m = []
q = N - 1
while True:
    q, mod = divmod(q, 26)
    m.append(a[mod])
    if q == 0:
        print(''.join(reversed(m)))
        exit()
    q -= 1


Measured memory_bytes: 9224
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n = int(input())
dict_x = {}
for i in range(1, n + 1):
    a = i % 10
    if a == 0:
        continue
    b = (i // 10**(len(str(i))-1) ) % 10
    if str(a) + "_" + str(b) in dict_x:
        dict_x[str(a) + "_" + str(b)] += 1
    else:
        dict_x[str(a) + "_" + str(b)] = 1
count = 0
for key in dict_x:
    a, b = key.split("_")
    if str(b) + "_" + str(a) in dict_x:
        t1 = dict_x[key]
        t2 = dict_x[str(b) + "_" + str(a)]
        count += t1 * t2
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    int B[N - 1], A[N];
    for (int i = 0; i < N - 1; i++)
    {
        cin >> B[i];
    }
    A[0] = B[0];
    A[1] = B[0];
    for (int i = 1; i < N - 1; i++)
    {
        A[i] = min(A[i], B[i]);
        A[i + 1] = B[i];
    }
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        ans += A[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    int n;
    cin >> n;
    while( n > 0){
        vector<int> v(n);
        for(int i = 0; i < n; ++i){
            cin >> v[i];
        }
        int max_ = *max_element(v.begin(), v.end());
        int min_ = *min_element(v.begin(), v.end());
        int min_cnt = 0;
        int max_cnt = 0;
        int cnt = 0;
        long long sum = 0;
        for(int j = 0; j < n; ++j){
            int s = v[j];
            if(s == max_) {
                max_cnt++;
            } else if(s == min_) {
                min_cnt++;
            } else {
                sum += s;
                cnt++;
            }
        }
        if(max_cnt > 1) {
            sum += max_;
            cnt++;
        }
        if(min_cnt > 1) {
            sum += min_;
            cnt++;
        }

        cout << (sum/cnt) << endl;
        cin >> n;
    }
}

Measured memory_bytes: 1192
S = input()
 
while len(S) > 0:
  if "dreameraser" in S:
    S = S.replace("dreameraser","")
  elif "dreamerase" in S:
    S = S.replace("dreamerase","")
  elif "dreamer" in S:
    S = S.replace("dreamer","")
  elif "dream" in S:
    S = S.replace("dream","")
  elif "eraser" in S:
    S = S.replace("eraser","")
  elif "erase" in S:
    S = S.replace("erase","")
  else:
    break
    
if len(S) == 0:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3188
#include<stdio.h>
#include<string.h>
    
#define N 1000000

char HashMap[N][15];
int n;
    
int insert(char* string){
  int h,i,key;
  key=makekey(string);
  for(i=0;;i++){
    h=hash(key,i);
    if(strcmp(HashMap[h],string)==0){
      return 1;
    }
    else if(strlen(HashMap[h])==0){
      strcpy(HashMap[h],string);
      return 0;
    }
  }
}
    
int convert(char c){
    
  if(c=='A') return 1;
  else if(c=='C') return 2;
  else if(c=='G') return 3;
  else if(c=='T') return 4;
  else return 0; 
}
    
int makekey(char* string){
  int p=1,sum=0;
  int i;
    
  for(i=0;i<strlen(string);i++){
    sum+=p*convert(string[i]);
    p=p*7;
  }
    
  return sum;
}
    
int hash(int key, int i){
  return (h1(key)+i*h2(key))%N;
}
    
int h1(int key){
  return key%N;
}
    
int h2(int key){
  return 1+key%(N-1);
}
    
int find(char* string){
  int j,key,h;
  key=makekey(string);
  for(j=0;;j++){
    h=hash(key,j);
    if(strcmp(HashMap[h],string)==0){
      return 1;
    }else if(strlen(HashMap[h])==0){
      return 0;
    }
    
  }
  return 0;
}
    
int main(){
    int i,t;
    char com[20];
    char string[N];
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
      scanf("%s", com);
      scanf("%s",string);
    
          if ( com[0] == 'f' ){
            t=find(string);
            if ( t != 0) printf("yes\n");
            else printf("no\n");
          } else if ( com[0] == 'i' ){
	   
	    insert(string);
	   
	    
          } 
    }
    
      return 0;
}



Measured memory_bytes: 16280
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define MAX(a, b, c) max(max(a, b), c)
using namespace std;

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

  int a = stoi(s.substr(0,2));
  int b = stoi(s.substr(2,2));

  bool a_flag = false;
  bool b_flag = false;
  
  if(a < 1 || 12 < a) a_flag = true;
  if(b < 1 || 12 < b) b_flag = true;
  if(a_flag&&b_flag) cout << "NA" << endl;
  else if(a_flag) cout << "YYMM" << endl;
  else if(b_flag) cout << "MMYY" << endl;
  else cout << "AMBIGUOUS" << endl;
  
}

Measured memory_bytes: 256
#include <cstdio>
#define ll long long
int main(){
	ll r, d, x;
	scanf("%lld %lld %lld", &r, &d, &x);
	for (int i = 0; i < 10; i++){
		x = r * x - d;
		printf("%lld\n", x);
	}
}

Measured memory_bytes: 128
I=lambda:input()
L=lambda:list(map(int,I().split()))
m,d=L()
a=0
for i in range(1,m+1):
  for j in range(10,d+1):
    if i==(j//10)*(j%10)and j//10>1 and j%10>1:a+=1
print(a)

Measured memory_bytes: 3060
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math
import re

sys.setrecursionlimit(1000000)

def GCD(a, b):
    num1 = max(a, b)
    num2 = min(a, b)
    rem = 1
    while rem > 0:
        rem = num1 % num2
        num1 = num2
        num2 = rem
    return num1

N, X = map(int, raw_input().split())
x_ = map(int, raw_input().split())
x = [abs(num - X) for num in x_]

ans = x[0]
for num in x:
    ans = GCD(ans, num)

print ans

Measured memory_bytes: 11540
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

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


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int a, b, c, d;
    int totalYen= 0;
    cin>> a>> b>>c>>d;
    for (int i = 0; i< a; i++){
        if (i<b){
            totalYen+= c;
        }
        else {
            totalYen+=d;
        }
    }
    cout<< totalYen;
    return 0;
}

Measured memory_bytes: 256