akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

#define ll long long int
#define fo(i,b,n) for(int i=(b); i<(n) ; i++)
#define xx first
#define yy second
#define pb push_back
#define sz(n) int(n.size())
#define pii pair
#define MP make_pair

#define read(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define readl(x) scanf("%lld",&x)
#define readl2(x,y) scanf("%lld%lld",&x,&y)
#define readd(x) scanf("%lf",&x)
#define readd2 scanf("%lf%lf",&x,&y)

#define pr(n) printf("%d",n)
#define prn(n) printf("%d\n",n)
#define prl(n) printf("%lld",n)
#define prln(n) printf("%lld\n",n)
#define prd(x) printf("%lf",x)
#define prdn(x) printf("%lf\n",x)

#define TC(n) printf("Case %d: ",n)

char s[1000000];
int main()
{
    scanf("%s",s);
    int len=strlen(s);
    stack<char>stk;
    fo(i,0,len){
        if(stk.empty()){
            stk.push(s[i]);
        }
        else if(s[i]=='T' && stk.top()=='S'){
            stk.pop();
        }
        else{
            stk.push(s[i]);
        }
    }
    prln(sz(stk));
    return 0;
}















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

const int MAX = 10000010;

bool p[MAX];

int main ( void )
{
	fill(p, p+MAX, true);
	p[0] = p[1] = false;
	for (int i = 2, I = sqrt(MAX)+1; i < I; ++i) {
		if (!p[i]) { continue; }
		for (int j = i+i; j < MAX; j+=i) { p[j] = false; }
	}

	int a, d, n;
	while (cin >> a >> d >> n, a|d|n) {
		int i = 0;
		while (i != n) {
			if (p[a]) { ++i; }
			a += d;
		}
		cout << a - d << endl;
	}
	return 0;
}

Measured memory_bytes: 10928
S = input()
T = input()

dcs = {}
dct = {}
for i, s in enumerate(S):
    if s in dcs and dcs[s] != T[i]:
        print("No")
        exit()
    else:
        dcs[s] = T[i]
else:
    for j, t in enumerate(T):
        if t in dct and dct[t] != S[j]:
            print("No")
            exit()
        else:
            dct[t] = S[j]
    else:
        print("Yes")

Measured memory_bytes: 9228
#include <iostream>
#include<string>
using namespace std;
int main(){
    string s;
    cin>>s;
    string t;
    cin>>t;
    int count=0;
    for(int i=0; i<3; i++){
        if(s[i]==t[i]){
            count++;
        }
    }
    cout<<count<<endl;
}



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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
vector<int> E[202020];
int M[202020];
int C[202020];
map<int,int> memo[202020];


int dfs2(int cur,int pre,int v) {
	if(memo[cur].count(v)) return memo[cur][v];
	int ret=0;
	FORR(e,E[cur]) if(e!=pre && e<v) ret+=1+dfs2(e,cur,v);
	
	return memo[cur][v]=ret;
	
}

void dfs(int cur,int pre) {
	if(cur>1) {
		M[cur]=max(pre,M[pre]);
		if(cur>M[pre]) {
			C[cur]=C[pre]+1+dfs2(cur,pre,M[cur]);
		}
		else {
			C[cur]=C[pre]+dfs2(cur,pre,M[cur])-dfs2(cur,pre,M[pre]);
		}
	}
	FORR(e,E[cur]) if(e!=pre) dfs(e,cur);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N-1) {
		cin>>x>>y;
		E[x].push_back(y);
		E[y].push_back(x);
	}
	
	dfs(1,1);
	for(i=2;i<=N;i++) cout<<C[i]<<" ";
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

using namespace std;

int main(void){
    int n;
    cin >> n;
    
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    
    int cost = 1e9;
    
    for(int x = -100; x <= 100; x++){
        int temp_cost = 0;
        for(int i = 0; i < n; i++){
            int temp = x - a[i];
            temp *= temp;
            temp_cost += temp;
        }
        
        cost = min(cost, temp_cost);
    }
    cout << cost << endl;
}


Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    void run(){
	int h = sc.nextInt();
	int m = sc.nextInt();
	int s = sc.nextInt();
	while(!(h==-1 && m==-1 && s==-1)){
	    int tape = 120*60 - (h*3600+m*60+s);
	    solve(tape);
	    solve(tape*3);
	    h = sc.nextInt();
	    m = sc.nextInt();
	    s = sc.nextInt();
	}
    }

    void solve(int t){
	int ah=0, am=0, as=0;	
	while(t >= 3600){
	    ah++;
	    t -= 3600;
	}
	while(t >= 60){
	    am++;
	    t -= 60;
	}
	as = t;
	print(ah, am, as);
    }

    void print(int ah, int am, int as){
	if(ah/10==0)
	    System.out.print("0");
	System.out.print(ah+":");
	if(am/10==0)
	    System.out.print("0");
	System.out.print(am+":");
	if(as/10==0)
	    System.out.print("0");
	System.out.println(as);
    }
}

Measured memory_bytes: 17224
n,m=map(int,input().split())
def dv(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return sorted(divisors)

for i in dv(m):
    if i>=n:
        print(m//i)
        exit()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  int arr[N];
  for(int i=0;i<N;i++){
  cin>>arr[i];
  }
  int dp[N]={0};
  dp[N-2]=abs(arr[N-1]-arr[N-2]);
  for(int i=N-3;i>=0;i--){
  dp[i]=min(abs(arr[i]-arr[i+1])+dp[i+1],abs(arr[i]-arr[i+2])+dp[i+2]);
  }
  cout<<dp[0];
  return 0;
}

Measured memory_bytes: 1024
#include <vector>
#include <iostream>
#include <string>
#include <sstream>      // std::ostringstream
using namespace std;
vector<string> StringSplit(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( std::getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

int main(){
	string s;
	cin>>s;
	vector<string> vkey = StringSplit(s,'/');
	const string str_key1= vkey[0];
	const string str_key2= vkey[1];
	const string str_key3= vkey[2];
	int y,m,d;
	y=stoi(vkey[0]);
	m=stoi(vkey[1]);
	d=stoi(vkey[2]);
	if(2019<y||4<m||30<d){
		cout <<"TBD"<<endl;
	}else{
		cout << "Heisei" <<endl;
	}
	return 0;
}

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

int main()
{
  int h,w;
  scanf("%d%d",&h,&w);
  int C[26]={0};
  for(int i=0;i<h;i++){
    char s[110];
    scanf("%s",s);
    for(int j=0;j<w;j++){
      C[s[j]-'a']++;
    }
  }
  int a1=0,a3=0,a2=0,a0=0;
  for(int t=0;t<26;t++){
    if(C[t]%4==1){
      a1++;
    }
    else if(C[t]%4==3){
      a3++;
    }
    else if(C[t]%4==2){
      a2++;
    }
    else{
      a0++;
    }
  }
  bool F;
  if(h%2==0&&w%2==0){
    F=(a1==0&&a3==0&&a2==0);
  }
  else if(h%2==1&&w%2==0){
    F=(a1==0&&a3==0&&a2<=w/2);
  }
  else if(h%2==0&&w%2==1){
    F=(a1==0&&a3==0&&a2<=h/2);
  }
  else{
    F=(a1+a3==1&&a2+a3<=(w+h-2)/2);
  }
  puts(F?"Yes":"No");
  return 0;
}


Measured memory_bytes: 256
R, G, B, N = [int(i) for i in input().split()]

count = 0
for r in range(N // R + 1):
    for g in range(N // G + 1):
        if (N - R * r - G * g) % B == 0 and (N - R * r - G * g) // B >= 0:
            count += 1

print(count)

Measured memory_bytes: 40556
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    
    S = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    print(S[int(input())-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 66156
#include <bits/stdc++.h>
using namespace std;
int s(int i)
{
	int sum=0;
	while(i>0)
	{
		sum+=i%10;
		i/=10;
	}
	return sum;
}
int main()
{
	int n,a,b;
	cin>>n>>a>>b;
	long long ans=0;
	for(int i=1;i<=n;++i)
	{
		int sum=s(i);
		if(sum>=a&&sum<=b)
			ans+=i;
	}
	cout<<ans;
	return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
const int INF = 1e9;

#define debug(x) cerr<<(#x)<<": "<<(x)<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }

class modint {
  public:
    using ll = long long;
    ll num;
    static const ll MOD = 998244353;
    static vector<modint> factorial;

    modint(): num(0) {};
    modint(ll n_): num((n_ + MOD) % MOD) {}
    modint(const modint &r): num(r.num) {}
    operator ll() const { return (num+MOD)%MOD; }
    friend istream& operator>>(istream& is, modint &r){
        ll num_;
        is >> num_;
        r = num_;
        return is;
    }
    modint operator+(const modint &r) const { return modint(num + r.num); }
    modint operator-(const modint &r) const { return modint(num - r.num); }
    modint operator*(const modint &r) const { return modint(num * r.num); }

    template<typename T>
    modint operator^(const T &r) const {
        if(r == 0) return 1;
        return (((*this)*(*this)) ^ (r/2)) * modint(r&1 ? num : 1);
    }
    modint operator/(const modint &r) const { return num * (r^(MOD-2)); }

    modint operator+=(const modint &r) { return *this = *this + r; }
    modint operator-=(const modint &r) { return *this = *this - r; }
    modint operator*=(const modint &r) { return *this = *this * r; }
    modint operator/=(const modint &r) { return *this = *this / r; }

    template<typename T>
    modint operator^=(const T &r) { return *this = *this ^ r; }

    static modint pow(const modint x, ll r) {
        return x^r;
    }

    static modint fact(int n){
        if((int)factorial.size() <= n) factorial.resize(n+1);
        if(factorial[n]) return factorial[n];
        if(n == 0) return 1;
        return factorial[n] = modint(n) * fact(n-1);
    }

    static modint C(ll n,ll r){
        return n >= r ? fact(n)/(fact(n-r)*fact(r)) : modint(0);
    }
};
vector<modint> modint::factorial;
#define fact(n) modint::fact(n)
#define C(n,r) modint::C(n,r)
#define H(a,b) C(a+b, a)


int main(void){
    int n;
    cin >> n;
    vector<int> d(n);
    map<int,int> cnt;
    rep(i,n){
        cin >> d[i];
        cnt[d[i]]++;
    }
    if (d[0] != 0) {
        cout << 0 << endl;
        return 0;
    }
    modint res = 1;
    rep1(i,n-1){
        res *= cnt[d[i]-1];
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 5376
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define ins insert
#define rs (x<<1|1) 
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define sqr(x) ((x)*(x))
#define cle(x) ((x).clear())
#define lowbit(x) ((x)&(-x))
#define SZ(x) (int((x).size()))
#define All(x) (x).begin(),(x).end()
#define ms(x,y) memset(x,y,sizeof (x))
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)]) 
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
template<class T>inline void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
inline int getgcd(int x,int y){if(!x)return y;return getgcd(y%x,x);}
inline int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=(ll)x*x%p)if(k&1)res=(ll)res*x%p;return res;}
const double pi=acos(-1);	
inline void judge(){
	freopen("input.txt","r",stdin);
} 
//********************************head*************************************
const int maxn=2e3+5;
int n,ans=1e9;
char A[maxn],B[maxn];
int l[maxn],r[maxn],mx[maxn];
void work(){
	rep2(i,0,n){
		l[i]=r[i]=0;
		while(B[(i+r[i])%n]=='0')r[i]++;
		while(B[(i-l[i]+n)%n]=='0')l[i]++;
	}
	rep2(dlt,0,n){
		int cnt=0;
		rep2(i,0,n)mx[i]=0;
		rep2(i,0,n)if(A[i]!=B[(i+dlt)%n])mx[l[i]]=max(mx[l[i]],r[i]-dlt),cnt++;
		int rmx=0,len=1e9;
		per(i,n-1,0)len=min(len,i+rmx),rmx=max(rmx,mx[i]);
		ans=min(ans,2*len+dlt+cnt);
	}
}
int main(){
	scanf("%s",A);
	scanf("%s",B);
	n=strlen(A);
	int cA=0,cB=0;
	rep2(i,0,n){
		if(A[i]=='1')cA++;
		if(B[i]=='1')cB++;
	}
	if(!cB){
		if(!cA)puts("0");
		else puts("-1");
		return 0;
	}
	work();
	reverse(A,A+n);
	reverse(B,B+n);
	work();
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,k,ans,v[55];
int main(){
	cin >> n >> k;
	for(int i=0;i<n;i++)cin >> v[i];
	for(int i=0;i<n;i++)
		for(int j=i;j<=n;j++){
			if(i+n-j>min(n,k) )continue;
			int sum=0,x=k-(i+n-j);
			multiset<int> s;
			for(int p=0;p<i;p++){
				sum+=v[p];
				if(v[p]<0)s.insert(v[p]);
			}
			for(int p=j;p<n;p++){
				sum+=v[p];
				if(v[p]<0)s.insert(v[p]);
			}
			for(multiset<int>::iterator it=s.begin();it!=s.end() and (x--)>0;it++)
				sum-=*it;
			ans=max(ans,sum);
		}
	cout << ans;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
static class Program{
	const int mod=1000000007;
	static void Main(){
		Sc sc=new Sc();
		int[] s=sc.Ia;
		int[][] a=new int[s[2]][];
		List<int[]> li=new List<int[]>();
		for(int i = 0;i<s[2];i++) {
			a[i]=sc.Ia;
			if((a[i][0]==0||a[i][0]==s[0]||a[i][1]==0||a[i][1]==s[1])&&(a[i][2]==0||a[i][2]==s[0]||a[i][3]==0||a[i][3]==s[1])){
				if(a[i][1]==0){li.Add(new int[]{a[i][0],i});}
				else if(a[i][0]==s[0]){li.Add(new int[]{a[i][1]+(int)2e8,i});}
				else if(a[i][1]==s[1]){li.Add(new int[]{(int)5e8-a[i][0],i});}
				else{li.Add(new int[]{(int)8e8-a[i][1],i});}
				if(a[i][3]==0){li.Add(new int[]{a[i][2],i});}
				else if(a[i][2]==s[0]){li.Add(new int[]{a[i][3]+(int)2e8,i});}
				else if(a[i][3]==s[1]){li.Add(new int[]{(int)5e8-a[i][2],i});}
				else{li.Add(new int[]{(int)8e8-a[i][3],i});}
			}
		}
		li.Sort((u,v)=>u[0]-v[0]);
		Stack<int> stk = new Stack<int>(new int[]{-1});
		for(int i = 0;i<li.Count;i++) {
			if(stk.Peek()!=li[i][1]){stk.Push(li[i][1]);}
			else{stk.Pop();}
		}
		Console.WriteLine(stk.Count==1?"YES":"NO");
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}

Measured memory_bytes: 35632
(defun solve (n robots)
  (declare (ignore n))
  (loop with current = most-negative-fixnum
        with count = 0
        for (left . right) in (sort robots #'< :key #'cdr)
        if (<= current left)
        do (incf count)
           (setf current right)
        finally (return count)))

#-swank
(let* ((n (read))
       (robots (loop repeat n
                     for x = (read)
                     for arm = (read)
                     collect (cons (- x arm) (+ x arm)))))
  (format t "~A~%" (solve n robots)))


Measured memory_bytes: 69732
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);


class WarshallFloyd {
public:
    int V; // 頂点数
    int E; // 辺の数
    vector<vector<ll> > d; // 最短頂点間距離
    WarshallFloyd() = default;

    WarshallFloyd(int v, int e) {
        V = v, E = e;
        d.resize(v);
        rep(i, v) d[i].resize(v);
        rep(i, v)rep(j, v)d[i][j] = inf;
        rep(i, v) d[i][i] = 0;
    };

    void add(int u, int v, ll cost) {
        d[u][v] = cost;
    }

    // v: 頂点数, d: 頂点間距離
    void solve() {
        rep(k, V)rep(i, V)rep(j, V) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }
};

// 頂点数V, 辺の数E
const ll MAX_E = 100 * 100;
ll V, E;
int a[MAX_E], b[MAX_E];
ll c[MAX_E];
WarshallFloyd wf;

void solve() {
    ll ans = 0;
    wf.solve();
    rep(i, E) if (wf.d[a[i]][b[i]] != c[i]) ans++;
    cout << ans << endl;
}


int main() {
    cin >> V >> E;
    wf = WarshallFloyd(V, E);
    rep(i, E) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--, b[i]--;
        wf.add(a[i], b[i], c[i]);
        wf.add(b[i], a[i], c[i]);
    }
    solve();
    return 0;
}

Measured memory_bytes: 384
<?php

class Dice
{
  const T = 0;
  const S = 1;
  const E = 2;
  const W = 3;
  const N = 4;
  const B = 5;

  private $numbers = null;

  // 6 numbers of dice
  // array(1, 2, 3, 4, 5, 6)
  // array(T, S, E, W, N, B)
  //
  //           first direction
  // +-+       +-+
  // |1|       |T|
  // +-+-+-+-+ +-+-+-+-+
  // |4|2|3|5| |W|S|E|N|
  // +-+-+-+-+ +-+-+-+-+
  // |6|       |B|  * T=top, B=bottom
  // +-+       +-+
  public function __construct(array $numbers)
  {
    $this->numbers = $numbers;
  }

  public function getNumber($direction)
  {
    return $this->numbers[$direction];
  }

  public function moveTo($direction) {
    switch ($direction) {
    case self::S:
      $idx = [self::N, self::T, self::E, self::W, self::B, self::S];
      break;
    case self::E:
      $idx = [self::W, self::S, self::T, self::B, self::N, self::E];
      break;
    case self::W:
      $idx = [self::E, self::S, self::B, self::T, self::N, self::W];
      break;
    case self::N:
      $idx = [self::S, self::B, self::E, self::W, self::T, self::N];
      break;
    default:
      return;
    }

    $old = $this->numbers;
    for ($i = 0; $i < 6; $i++) {
      $this->numbers[$i] = $old[$idx[$i]];
    }
  }

  function display() {
    fprintf(STDERR, "----------------------------------------" . PHP_EOL);
    fprintf(STDERR, "T(%3d)" . PHP_EOL, $this->numbers[0]);
    fprintf(STDERR, "W(%3d)S(%3d)E(%3d)N(%3d)" . PHP_EOL,
                               $this->numbers[3],
                               $this->numbers[1],
                               $this->numbers[2],
                               $this->numbers[4]);
    fprintf(STDERR, "N(%3d)" . PHP_EOL, $this->numbers[5]);
  }

  static function strToDir($str) {
    $ret = 0;
    switch ($str) {
    case "S": $ret = self::S; break;
    case "E": $ret = self::E; break;
    case "W": $ret = self::W; break;
    case "N": $ret = self::N; break;
    case "T": $ret = self::T; break;
    case "B": $ret = self::B; break;
    default:
    }
    return $ret;
  }
}

$input = trim(fgets(STDIN));
$numbers = explode(" ", $input);

$input = trim(fgets(STDIN));
$dirs  = str_split($input);

$dice = new Dice($numbers);

foreach ($dirs as $dir) {
  $dice->moveTo(Dice::strToDir($dir));
}

echo $dice->getNumber(Dice::T) . PHP_EOL;

Measured memory_bytes: 15460
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	cin >> H >> W;
	vector<string>s(H);
	for (int i = 0; i < H; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] != '#') {
				s[i][j] = '0';
			}
		}
	}
	int dir_x[] = { 1,1,1,0,-1,-1,-1,0 };
	int dir_y[] = { 1,0,-1,-1,-1,0,1,1 };
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == '#') {
				for (int k = 0; k < 8; k++) {
					int cy = i + dir_y[k];
					int cx = j + dir_x[k];
					if (cy < 0 || cy >= H || cx < 0 || cx >= W) {
						continue;
					}
					if (s[cy][cx] == '#') {
						continue;
					}
					s[cy][cx]++;
				}
			}
		}
	}
	for (int i = 0; i < H; i++) {
		cout << s[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import numpy as np
k, a, b = list(map(int, input().split()))


if b - a <= 2:
    ans = k + 1
else:
    n = 1
    if n > a:
        pass
    else:
        k -= a - n
        n = a
#     print(n, k )
    if k % 2 == 0:
        pass
    else:
        n += 1
        k -= 1
#     print(n, k )
    n += k//2 * (b - a)
    ans = n

print(ans)

Measured memory_bytes: 21408
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <map>
#include <list>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <random>
#include <queue>
#include <fstream>
#include <iterator> // std::back_inserter
#include <chrono>
#include <string>

using namespace std;


int main(int argc, char *argv[])
{
    int a,b,c;

    cin >> a >> b >> c;
    vector<int> edge = {a,b,c};

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

    if(edge[0]*edge[0] == edge[1]*edge[2]) cout << "Yes";
    else cout << "No";

    



    return 0;
}


Measured memory_bytes: 256
operators = {
	"+": (lambda a, b: a + b),
	"-": (lambda a, b: a - b),
	"*": (lambda a, b: a * b),
	"/": (lambda a, b: a / b)
}

def evaluate(tokens):
	stack = []
	for token in tokens:
		if token in operators:
			arg2 = stack.pop()
			arg1 = stack.pop()
			result = operators[token](arg1, arg2)	
			stack.append(result)
		else:
			stack.append(int(token))
	  
	return stack.pop()
  
expression = input()

tokens = expression.split()

print(evaluate(tokens))


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;

struct edge{
    int to,weight;
    edge(int to,int weight):to(to),weight(weight){}
};
using Graph = vector<vector<int>> ;
using GraphEdge = vector<vector<int>> ;

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
int main(){
    int N,M;cin >> N >> M;
    int like[31];

    memset(like, 0, sizeof(like));

    rep(i,N){
        int k;cin >> k;
        rep(j,k){
            int a;cin >> a;
            like[a]++;
        }
    }
    int ans = 0;
    Rep(i,M){
        if(like[i]==N)ans++;
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 3536
from collections import defaultdict
K = int(input())
mapping = defaultdict(list)
for j in range(10):
    mapping[(0, j)].append(str(j))

# iは何桁目かを表す
for i in range(1, 10):
    for j in range(10):
        if j == 0:
            for item in mapping[(i-1, j)]:
                mapping[(i, j)].append( str(j) + item )
            for item in mapping[(i-1, j+1)]:
                mapping[(i, j)].append( str(j) + item )
        elif j == 9:
            for item in mapping[(i-1, j-1)]:
                mapping[(i, j)].append( str(j) + item )
            for item in mapping[(i-1, j)]:
                mapping[(i, j)].append( str(j) + item )
        else:
            for item in mapping[(i-1, j-1)]:
                mapping[(i, j)].append( str(j) + item )
            for item in mapping[(i-1, j)]:
                mapping[(i, j)].append( str(j) + item )
            for item in mapping[(i-1, j+1)]:
                mapping[(i, j)].append( str(j) + str(item) )


ans = set()
for j in range(10):
    for item in mapping[(0, j)]:
        ans.add(int(item))
for i in range(1, 10):
    for j in range(1, 10):
        for item in mapping[(i, j)]:
            ans.add(int(item))
ans = sorted(list(ans))
print(ans[K])


Measured memory_bytes: 36580
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <vector>
#include <bitset>
#include <stack>
#include <iomanip>
#include <set>
#include <queue>
#include <map>


typedef long long ll;
typedef unsigned long long ull;
#define mk make_pair
#define mkt make_tuple
#define fi first
#define se second


using namespace std;
int const N = 200005;
int ans[N], a[N];

int main()
{
	int n; int m = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = n; i >= 1; i--) {
		int sum = 0;
		for (int j = i; j <= n; j += i)
			sum += ans[j];
		if (sum % 2 != a[i-1]) {
			ans[i] = 1;
			m++;
		}
	}

	cout << m << endl;
	for (int i = 0; i <= n; i++)
		if (ans[i]) cout << i << ' ';
}


Measured memory_bytes: 2432
s = input()
first = s[:2]
last = s[2:]
months = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']

if first in months:
    if last in months:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if last in months:
        print('YYMM')
    else:
        print('NA')

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

int main() {
  int N;
  cin >> N ;
  int count=1;
  vector<string> vec(N);
  for(int i=0;i<N;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
    for(int i=0;i<(N-1);i++){
    if(vec.at(i) != vec.at(i+1)){
     count=count+1; 
    }
  }
 
  cout << count << endl;
  

  return 0;
}

Measured memory_bytes: 9520
#include <iostream>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
  int c[3][3], i, j;
  for(i=0;i<3;i++)
    for(j=0; j<3; j++)
      cin >> c[i][j];
  for(i=0; i<2; i++)
    for(j=0; j<2; j++)
      if((c[i][j]-c[i+1][j])!=(c[i][j+1]-c[i+1][j+1])||(c[j][i]-c[j][i+1])!=(c[j+1][i]-c[j+1][i+1])){
	cout << "No";
	return 0;
      }
  cout << "Yes";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int N;
int A[101];

int main(){
	cin >>N;
	for(int i=0; i<N; i++){
		cin >> A[i];
	}
	
	int max = 0;
	for(int i=0; i<N; i++){
		for(int j=0; j<N; j++){
			if(abs(A[i]-A[j]) > max){
				max = abs(A[i]-A[j]);
			}
		}
	}
	
	printf("%d", max);
}

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

using u32 = uint32_t;

int main()
{
	u32 n;
	
	std::cin >> n;

	std::vector<u32> a;
	std::vector<u32> b;
	std::vector<u32> c;

	a.reserve(n);
	b.reserve(n);
	c.reserve(n);
	
	for(u32 i = 0; i<n; i++)
	{
		u32 x;
		std::cin >> x;
		a.push_back(x);
	}

	for(u32 i = 0; i<n; i++)
	{
		u32 x;
		std::cin >> x;
		b.push_back(x);
	}

	for(u32 i = 0; i<n-1; i++)
	{
		u32 x;
		std::cin >> x;
		c.push_back(x);
	}

	u32 pts = 0;

	for(u32 i = 0; i<n; i++)
	{

		pts+=b[a[i]-1];

		if(i>0)
		{
			if(a[i] - a[i-1] == 1)
			{
				//std::cout << "a[" << i << "] - "<< "a[" << i-1 << "] / C = " << c[a[i-1]-1] << "\n";
				pts+=c[a[i-1]-1];
			}
		}
	}

	std::cout << pts << "\n";
	
	return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n; cin >> n;
  map<P<int,int>,ll> mp;
  for(int i = 1; i <= n; ++i){
    string s = to_string(i);
    int h = int(s.front()-'0');
    int t = int(s.back()-'0');
    mp[{h,t}]++;
  }
  ll ans = 0;
  for(int i = 1; i < 10; ++i){
    for(int j = 1; j < 10; ++j){
      ans += mp[{i,j}]*mp[{j,i}];
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    vector<int> a(1000000,0);
    int s; cin>>s;
    a[s]++;

    for(int i=1;;i++){
        if(a[s]==2){
            cout<<i<<endl;
            return 0;
        }
        if(s%2==0){
            s/=2; a[s]++;
        }else{
            s=3*s+1; a[s]++;
        }
    }
}

Measured memory_bytes: 4096
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <array>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
const int  INF=10e7;

typedef  pair<int,int> P;


int main(){
     int a,b,h;
     cin>>a>>b>>h;
     cout<<(a+b)*h/2<<endl;
     
}

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

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

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXN 110000

ll n,m;
ll dp1[MAXN];
ll dp2[MAXN];
ll ans[MAXN];
vector<vector<int>>edges(MAXN);

void dfs1(int x=0, int p=-1){
  dp1[x]=1;
  for(auto c:edges[x]){
    if(c==p)continue;
    dfs1(c, x);
    dp1[x] = dp1[x] * dp1[c] % m;
  }
  dp1[x]++;
}

void dfs2(int x=0, int p=-1){
  if(p==-1)dp2[x]=1;
  
  int ec = edges[x].size();
  vector<ll> lprod(ec, 1);
  rep(i, ec){
    int c = edges[x][i];
    if(i)lprod[i] = lprod[i-1];
    if(c==p)continue;
    lprod[i] = lprod[i] * dp1[c] % m;
  }

  vector<ll>rprod(ec, 1);
  rrep(i, ec){
    int c = edges[x][i];
    if(i<ec-1)rprod[i] = rprod[i+1];
    if(c==p)continue;
    rprod[i] = rprod[i] * dp1[c] % m;
  }

  rep(i, ec){
    int c = edges[x][i];
    if(c==p)continue;
    dp2[c] = dp2[x];
    if(i)dp2[c] = dp2[c] * lprod[i-1] % m;
    if(i<ec-1)dp2[c] = dp2[c] * rprod[i+1] % m;
    dp2[c] = (dp2[c] +1)%m;
    dfs2(c, x);
  }
}

void dfs3(int x=0, int p=-1){
  ans[x] = dp2[x];
  for(auto c:edges[x]){
    if(c==p)continue;
    ans[x] = ans[x] * dp1[c] % m;
    dfs3(c, x);
  }
}

int main(){
  cin>>n>>m;
  rep(i, n-1){
    int x,y;cin>>x>>y;x--,y--;
    edges[x].push_back(y);
    edges[y].push_back(x);
  }

  dfs1();
  dfs2();
  dfs3();

  rep(i, n)cout<<ans[i]<<endl;

  return 0;

  rep(i, n)cout<<dp1[i]<<' ';cout<<endl;
  rep(i, n)cout<<dp2[i]<<' ';cout<<endl;

  return 0;
}

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

void main_()
{
    int N;
    cin >> N;
    map<string, int> poll_counts;
    int max_vote = 1;
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;

        // operator[]の仕様として、poll_counts[s]が存在しない場合は生成され、0で初期化される
        poll_counts[s]++;
        max_vote = max(max_vote, poll_counts[s]);
    }

    for (auto&& p : poll_counts) {
        if (p.second == max_vote) {
            cout << p.first << endl;
        }
    }
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 23808
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	int k;
    string n;
    cin>>n>>k;
    int m=n.length();
    vector<vector<vector<vector<LL>>>> dp(m+1,vector<vector<vector<LL>>>(10,vector<vector<LL>>(5,vector<LL>(2,0))));
    dp[0][0][0][0]=1;
    LL ans=0;
    cerr<<"init"<<endl;
    FOR(ii,0,m){
        //cerr<<"ii:"<<ii<<endl;
        FOR(jj,0,10){
            FOR(kk,0,4){
                FOR(ll,0,2){
                    int t=dp[ii][jj][kk][ll];
                    if(kk==k&&ll==0&&t!=0){
                        //cerr<<kk<<" "<<t<<endl;
                    }
                    FOR(nx,0,10){
                        int add=nx==0?0:1;
                        int lf=1,nn=n[m-ii-1]-'0';
                        if(nn>nx){
                            lf=0;
                        }else if (nn<nx){
                            lf=1;
                        }else{
                            lf=ll;
                        }
                        dp[ii+1][nx][kk+add][lf]+=t;
                    }
                }
            }
        }
    }
    cerr<<"dp"<<endl;
    FOR(ii,m,m+1){
        FOR(jj,0,10){
            FOR(kk,k,k+1){
                FOR(ll,0,1){
                    int t=dp[ii][jj][kk][ll];
                    //cerr<<jj<<" "<<t<<endl;
                    ans+=t;
                }
            }
        }
    }
    cout<<ans;
    





}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int a,b; cin>>a>>b;
	string s; cin>>s;
	if(s[a]!='-'){
		cout<<"No";
		return 0;
	}
	bool ok=true;
	rep(i,0,a+b){
		if(i==a) continue;
		if(s[i]=='-') ok=false;
	}
	if(ok) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
s = input()
t = input()

r1 = [-1] * 26
r2 = [-1] * 26


def char2index(char):
    return ord(char) - 97


sn = [char2index(si) for si in s]
tn = [char2index(ti) for ti in t]

flg = True
for si, ti in zip(sn, tn):
    if r1[si] >= 0:
        if r1[si] != ti:
            flg = False
            break
    else:
        r1[si] = ti
    if r2[ti] >= 0:
        if r2[ti] != si:
            flg = False
            break
    else:
        r2[ti] = si

print("Yes" if flg else "No")


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

int main() {
  int n, m;
  cin >> n >> m;
  if (n >=m) {
    cout << 0 << endl; 
    return 0;
  }
  vector<int> x(m);
  rep(i, m) cin >> x.at(i);
  sort(x.begin(), x.end());
  
  vector<int> dx(m-1);
  rep(i, m-1) {
    dx.at(i) = abs(x.at(i+1) - x.at(i));
  }
  sort(dx.begin(), dx.end());
  
  int sum = 0;
  rep(i, dx.size()-(n-1)) {
    sum += dx.at(i);
  }
  cout << sum << endl;
}


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

int main() {
  int h, w;
  while (true) {
    cin >> h >> w;
    if (h == 0 & w == 0) break;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (i % 2 == 0 && j % 2 == 0)
          cout << "#";
        else if (i % 2 == 0 && j % 2 == 1)
          cout << ".";
        else if (i % 2 == 1 && j % 2 == 0)
          cout << ".";
        else if (i % 2 == 1 && j % 2 == 1)
          cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
}


Measured memory_bytes: 3068
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 10000007;
const int inf = 1001001001;



int main(void) {
  string s;
  cin >> s;
  string t = "";
  reverse(s.begin(),s.end());
  int cnt = 0;
  while(cnt<s.size()){
    if(s.substr(cnt,5)=="maerd") cnt+=5;
    else if(s.substr(cnt,7)=="remaerd") cnt+=7;
    else if(s.substr(cnt,5) == "esare")cnt+= 5;
    else if(s.substr(cnt,6) == "resare")cnt+=6;
    else {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#include<deque>
#define rep(i,rept)	for(ll i = 0; i<(ll)rept;++i)
typedef long long ll;
using namespace std;


int main() {
	//23日目 
	ll n = 0, m = 0, x = 0, y = 0;
	cin >> n >> m >> x >> y;
	ll x_t[100] = {}, y_t[100] = {};
	rep(i, n) {
		cin >> x_t[i];
	}
	rep(i, m) {
		cin >> y_t[i];
	}
	sort(x_t, x_t + n);
	sort(y_t, y_t + m);

	bool flug = true;

	for (int i = x + 1; i <= y; i++) {

		rep(j, n) {
			if (x_t[j] >= i) {
				flug = false;
			}
		}
		rep(k, m) {
			if (y_t[k] < i) {
				flug = false;
			}
		}

		if (flug) {
			cout << "No War" << endl;
			return 0;
		}
		flug = true;

	}
	cout << "War" << endl;
	return 0;


	

}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val months = Regex("01|02|03|04|05|06|07|08|09|10|11|12")
    val (l,r) = readLine()!!.chunked(2)
    if (months.matches(l) && months.matches(r)) println("AMBIGUOUS")
    else if (months.matches(l)) println("MMYY")
    else if (months.matches(r)) println("YYMM")
    else println("NA")
}

fun String.chunked(num: Int)
        = (0 until this.length / num).map { this.substring(it * num, (it+1) * num) }

Measured memory_bytes: 32120
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

typedef long long ll;

int main ()
{
  ll min,max;
  ll sum = 0;

  cin >> min >> max;

  if ( min > max ) swap(min,max);

  if ( min == 1 ) {
    if ( max == 1 ) sum += 1;
    else sum += (max-2);
  } else if ( min == 2 ) {
    sum = 0;
  } else {
    sum += (min-2)*(max-2);
  }

  cout << sum << "\n";
}


Measured memory_bytes: 888
def main():
    n=int(input())
    a=[0 for _ in range(n)]
    b=[0 for _ in range(n)]
    c=[0 for _ in range(n)]
    for i in range(n):
        a[i],b[i],c[i] = map(int,input().split()) 
    dp=[[0 for _ in range(3)] for _ in range(n+1)]
    for i in range(n):
        dp[i+1][0]=max(dp[i][1]+b[i],dp[i][2]+c[i])
        dp[i+1][1]=max(dp[i][0]+a[i],dp[i][2]+c[i])
        dp[i+1][2]=max(dp[i][0]+a[i],dp[i][1]+b[i])
    print(max(dp[n][0],dp[n][1],dp[n][2]))
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 63552
#include <iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
using namespace std;
#define mod 1000000007
int main()
{

	long long n,f=1; cin >> n;
	for (int i = 1; i < n; ++i)
	{
		f =(f* i)%mod;
	}
	cout << (f*n)%mod;
}



Measured memory_bytes: 3620
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[500],d[500],f,g,h,i,j,flg1=0,flg2=0;
	scanf("%d",&a);
	for(i=0;i<a;i++)
		scanf("%d %d",&s[i],&d[i]);
	for(i=0;i<a;i++){
		for(f=1;f<=5;f++){
			g=f*100;
			if(g>s[i]){
				h=f;
				break;
			}
			if(g==s[i]){
				flg1=1;
				h=f;
				break;
			}
		}
		//printf("h = %d\n",h);
		f=0;
		while(1){
			if(f>180)
				break;
		//	printf("%d\n",f);
			if(f<d[i]){
				h+=5;
			}
			if(f>d[i]){
				break;
			}
			if(f==d[i]){
				flg2=1;
				break;
			}
			f+=30;
		}
		if(flg1==0&&flg2==0)
			printf("%d %d %d %d\n",h-6,h-5,h-1,h);
		else if(flg1==1&&flg2==0)
			printf("%d %d\n",h-5,h);
		else if(flg1==0&&flg2==1)
			printf("%d %d\n",h-1,h);
		else if(flg1==1&&flg2==1)
			printf("%d\n",h);
		flg1=0;
		flg2=0;
	}
	return 0;
}

Measured memory_bytes: 2712
K = input()

intk=int(K)
kcop=intk
S=0
for i in range(1,len(K)+1):
  S+=kcop%10
  kcop=kcop//10
  #print(S,kcop)
if intk%S==0:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    vector<vector<long long>> dp(N + 1, vector<long long>(W * 2, 0));
    for (int i = 0; i < N; i++) for (int tot = 0; tot <= W; tot++) {
        chmax(dp[i + 1][tot], dp[i][tot]);
        chmax(dp[i + 1][tot + w[i]], dp[i][tot] + v[i]);
    }
    cout << dp[N][W] << endl;
    return 0;
}

Measured memory_bytes: 159744
L,n = (int(i) for i in input().split())
x = [int(input()) for i in range(n)]
t,t2,y,a = [0],[0],[],0
for i in range(n):
	t.append(t[-1]+x[i])
	t2.append(L+t2[-1]-x[n-i-1])
	y.append(L-x[n-i-1])
for i in range(n):
	if (n-i-1)%2: a = max(a,y[(n-i-1)//2]+2*(t[i+(n-i-1)//2+1]-t[i]+t2[(n-i-1)//2]))
	else: a = max(a,2*(t[i+(n-i-1)//2+1]-t[i]+t2[(n-i-1)//2])-x[i+(n-i-1)//2])
for i in range(n):
	if (n-i-1)%2: a = max(a,x[(n-i-1)//2]+2*(t2[i+(n-i-1)//2+1]-t2[i]+t[(n-i-1)//2]))
	else: a = max(a,2*(t2[i+(n-i-1)//2+1]-t2[i]+t[(n-i-1)//2])-y[i+(n-i-1)//2])
print(a)

Measured memory_bytes: 36508
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
int main(){
  char s[1000],t[1000];
  int tmp;
  scanf("%s",s);
  scanf("%s",t);
  int ans =strlen(t);
  for(int i=0;i<strlen(s)-strlen(t)+1;i++){
    tmp=0;
    for(int j=0;j<strlen(t);j++){
      if(s[i+j]!=t[j]){
        tmp++;
        if(ans<=tmp){
          break;
        }
      }
    }
    if(tmp<ans){
      ans=tmp;
    }
    if(ans==0){
      break;
    }
  }

printf("%d",ans);  
return 0;
}

Measured memory_bytes: 1704
#include <iostream>

using namespace std;

int Grid[100][100];
int H, W;

void paint(int color, int loc) {
    int row, col;
    row = loc / W;
    if (row & 1) {
        col = (W - 1) - (loc - row * W);
    } else {
        col = loc - row * W;
    }
    Grid[row][col] = color;

    return;
}

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

    cin >> H >> W;

    int N;
    cin >> N;
    int temp = 0;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        for (int j = 0; j < a; ++j) {
            paint(i + 1, temp + j);
        }
        temp += a;
    }

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (j)
                cout << " ";
            cout << Grid[i][j];
        }
        cout << endl;
    }
}

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

int main(){
  string A, B;
  cin >> A >> B;
  if (A.size() < B.size()){
    cout << "LESS" << endl;
    return 0;
  }
  if (A.size() > B.size()){
    cout << "GREATER" << endl;
    return 0;
  }
  if (A.size() == B.size()){
    for(int i = 0; i < A.size(); i++){
      if(A.at(i) - '0' < B.at(i) - '0'){
        cout << "LESS" << endl;
        return 0;
      }
      if(A.at(i) - '0' > B.at(i) - '0'){
        cout << "GREATER" << endl;
        return 0;
      }
    }
    cout << "EQUAL" << endl;
    return 0;
  }
}

Measured memory_bytes: 3640
#include <iostream>

int main(int argc, char *argv[]) {
	int hotel_cost = 0;
	int days = 0;
	int cost_border_day = 0;
	int x_yen = 0;
	int y_yen = 0;

	std::cin >> days;
	std::cin >> cost_border_day;
	std::cin >> x_yen;
	std::cin >> y_yen;

	for (int i = 1; i <= days; i++) {
		if (i <= cost_border_day) {
			hotel_cost += x_yen;
		} else {
			hotel_cost += y_yen;
		}
	}
	std::cout << hotel_cost << std::endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

char S[100];
char T[100];

int main()
{
	scanf("%s", S);
	scanf("%s", T);

	int ans = 0;
	for (int i = 0; i < 3; ++i)
	{
		if (S[i] == T[i]) ans++;
	}

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

	return 0;
}


Measured memory_bytes: 128
# Wrote in Feb 29, 2020 13:32 by reetok
require 'time'
def inp(type=:to_i,spst=" ")
  return eval("gets.chomp.split(#{spst}).map(&:#{type})")
end
def inpf() return self.inp(:to_f," ") end
def inps() return self.inp(:to_s," ") end
def r_up(a, b) (a/b).ceil end
def r_down(a, b) (a/b).floor end
def sum(a) a.inject(:+) end
def big(a,b) return (a>b)? a:b end
def small(a,b) return (a<b)? a:b end
def minp(n,datatype=:to_i)
  t = []
  n.times do
    t.push(eval("gets.chomp.#{datatype.to_s}"))
  end
end
def yes() puts "Yes" end
def no() puts "No" end
def ynju(bool,yes="Yes",no="No") puts (bool ? yes : no) end
#---------------

a,b = inp
if a<b
puts "a < b"
elsif a>b
puts "a > b"
elsif a==b
puts "a == b"
end


Measured memory_bytes: 7024
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  lines.shift().split(' ').map(Number).forEach(function(key, i, a) {
    console.log(`node ${i+1}: key = ${a[i++]}, `+((i-1)?`parent key = ${a[Math.floor(i/2)-1]}, `:'')+(2*i-1<a.length?`left key = ${a[2*i-1]}, `:'')+(2*i<a.length?`right key = ${a[2*i]}, `:''));
  });
})();



Measured memory_bytes: 17300