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

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

  vector<pair<int, int>> ans(m);
  vector<vector<pair<int, int>>> py(n);

  for (int i = 0; i < m; i++) {
    int p, y;
    cin >> p >> y;
    py[p - 1].emplace_back(y, i);
  }

  for (int p = 0; p < n; p++) {
    sort(begin(py[p]), end(py[p]));
    int s = py[p].size();
    for (int num = 0; num < s; num++) {
      ans[py[p][num].second] = {p + 1, num + 1};
    }
  }

  for (auto&& e : ans) {
    cout << setfill('0') << setw(6) << e.first
         << setfill('0') << setw(6) << e.second << endl;
  }
}


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

int main()
{
    int n, max, sec;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i,n) cin >> a[i];
    b = a;
    sort(b.rbegin(), b.rend());
    max = b[0]; sec = b[1];
    rep(i,n) {
        if (a[i] == max) cout << sec << endl;
        else cout << max << endl;
    }
    return 0;
}


Measured memory_bytes: 3200
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
S = [input() for i in range(n)]
SS = set(S)
print(len(SS))

Measured memory_bytes: 96668
from random import randint
from time import time
t1=time()

d=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(d):
	r=list(map(int,input().split()))
	s.append(r)

def score(T):
	last=[0]*26
	happy=0
	for i in range(d):
		last[T[i]-1]=i+1
		happy+=s[i][T[i]-1]
		for j in range(26):
			happy-=(i+1-last[j])*c[j]
	return happy

t=[]
for i in range(d):
	t.append(i%26+1)

t2=time()
while t2-t1<1.8:
	tt=t.copy()
	x=int((1.8-(t2-t1))*3)+1
	for i in range(x):
		tt[randint(1,d)-1]=randint(1,26)
	if score(tt)>score(t):
		t=tt.copy()
	t2=time()
for x in t:
	print(x)


Measured memory_bytes: 83728
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <cmath>
 
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)

using Graph = vector<vector<int>>;

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {
  ll N, x;
  cin >> N;
  
  x = (10000 - N)%1000; 
  
  cout << x << endl;
  
}

Measured memory_bytes: 3652
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int dp[201][201];
int t[201],u[201],v[201],w[201];
int N,D,ans=0;
int main(){
  cin>>N>>D;
  for(int i=1;i<=N;i++)cin>>t[i];
  for(int i=1;i<=D;i++){
    cin>>u[i]>>v[i]>>w[i];
    if(t[1]<u[i]||v[i]<t[1])dp[1][i]=-1;
    else dp[1][i]=0;
  }
  for(int i=2;i<=N;i++){
    for(int j=1;j<=D;j++){
      dp[i][j]=-1;
      if(t[i]<u[j]||v[j]<t[i])continue;
      for(int k=1;k<=D;k++){
	if(dp[i-1][k]==-1)continue;
	dp[i][j]=max(dp[i][j],dp[i-1][k]+abs(w[k]-w[j]));
      }
      ans=max(ans,dp[i][j]);
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1320
# coding: utf-8
# 133C
"""
L<=i<=j<=R
(i×j)mod 2019
0≤L<R≤2×10^9
"""

def solve(L, R):
    if R - L > 2019:
        return 0
    
    tmp = 2019
    for i in range(L, R):
        for j in range(R, i, -1):
            if (i * j) % 2019 < tmp:
                tmp = (i * j) % 2019
    return tmp
 
L, R = map(int, input().split())
print(solve(L, R))


Measured memory_bytes: 3060
from fractions import gcd

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


def gcd2(x, y):
    if not x:
        return y
    if not y:
        return x
    return gcd(x, y)


L, R = [0] * (N+1), [0] * (N+1)
for i in range(1, N+1):
    L[i] = gcd2(L[i-1], A[i-1])
    R[N-i] = gcd2(R[N-i+1], A[N-i])

ans = 0
for i in range(N):
    ans = max(ans, gcd2(L[i], R[i+1]))

print(ans)


Measured memory_bytes: 16152
n, a, b, c = map(int, input().split())

target = [a, b, c]
l = [int(input()) for _ in range(n)]

ans = 10**9

for i in range(1, 4 ** n):
    q = bin(i)[2:].zfill(n * 2)
    pattern = [q[2 * j:2 * j + 2] for j in range(n)]
    k = [[], [], []]
    for j in range(n):
        t = int(pattern[j], 2)
        if t == 0:
            continue
        k[t-1].append(l[j])
    if len(k[0]) * len(k[1]) * len(k[2]) == 0:
        continue
    cost = 0
    for j in range(3):
        cost += abs(sum(k[j]) - target[j]) + (len(k[j]) - 1) * 10
    ans = min(cost, ans)

print(ans)


Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int h,n; cin>>h>>n;
    vector<int> dp(20000,inf);
    dp[0]=0;
    vector<pp> ma(n);
    rep(i,n){
        int a,b; cin>>a>>b;
        ma[i]=mk(a,b);
    }
    rep(i,h){
        if(dp[i]==inf) continue;
        for(auto q : ma){
            if(dp[i+q.first]>dp[i]+q.second)
            dp[i+q.first]=dp[i]+q.second;
        }
    }
    int ans=inf;
    for(int i=h;i<20000;i++) ans=min(ans,dp[i]);
    cout<<ans<<endl;
}

Measured memory_bytes: 384
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
names = dict()
for _ in range(n):
    s = input().rstrip()
    if s not in names:
        names[s] = 1
    else:
        names[s] += 1

max_val = 0
for key in names.keys():
    if names[key] > max_val:
        max_val = names[key]
        ans = [key]
    elif names[key] == max_val:
        ans.append(key)

ans.sort()
for item in ans:
    print(item)

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

#define F first
#define S second
#define pb push_back
#define ld  double
#define ll long long
#define int long long


using namespace std;

const int MAXN = 101 * 1001  , MOD = 1e9 + 7 , sq = 333  ;

map<pair<int,int> , int > m ;

set < pair < int , int > > s ;

int a[100] ;

int32_t main()
{
   ios::sync_with_stdio(0);cin.tie(0);
   int h,w, n ;
   cin >> h >> w >> n ;
   a[0] = (h-2)*(w-2);
   for(int i = 0 ; i < n ; i ++ )
   {
       int x , y ;
       cin >> x >> y ;
       x--;
       y--;
       for(int q = 0 ; q < 3 ; q ++ )
       {
           for(int e = 0 ; e < 3 ; e ++ )
           {
               int X = q+x ,Y = e+y ;
               if(X>=h||Y>=w||X<2||Y<2)
                    continue ;
              //  cout<<'*'<<X<<' '<<Y<<'\n';
               a[m[{X,Y}]]--;
               m[{X,Y}]++;
               a[m[{X,Y}]]++;
           }
       }
       //cout<<'\n';
   }
   for(int i = 0 ; i < 10 ; i ++ )
    cout<<a[i]<<'\n';



}


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

typedef struct _data
{
	int n;
	string s;
} data;

int n_d(string *s, int n)
{
	int i = 0;
	while (i < n)
	{
		if (s[i] == s[n])
			return 0;
		i++;
	}
	return 1;
}

int main()
{
	int n,m;
	cin >> n;
	string s[n];
	rep(i, n)
		cin >> s[i];
	cin >> m;
	string t[m];
	rep(i, m)
		cin >> t[i];
	_data s1[n];
	_data t1[m];
	int nb[n];
	int i = 0,j,k;
	int ans = 0;
	while(i < n)
	{
		nb[i] = 0;
		j = 0;
		while (j < n)
		{
			if(s[j] == s[i] )
			{
				nb[i] += 1;
			}
			j++;
		}
		k = 0;
		while (k < m)
		{
			if(t[k] == s[i])
			{
				nb[i] -= 1;
			}
			k++;
		}
		// cout << i << ' ' << nb[i] << endl;
		ans = max(ans, nb[i]);
		i++;
	}
	cout << ans << endl;
	return (0);
}


Measured memory_bytes: 256
L=[]
R=[]
N,K,C=map(int,input().split())
S=list(input())
s=S[::-1]
i=0
while len(L)<K:
    if S[i]=='o':
        L.append(i+1)
        if i+C<N:
            for j in range(1,C+1):
                S[i+j]='x'
    i+=1
k=0
while len(R)<K:
    if s[k]=='o':
        R.append(N-k)
        if k+C<N:
            for l in range(1,C+1):
                s[k+l]='x'
    k+=1
R=R[::-1]
ans=[]
for i in range(K):
    if L[i]==R[i]:
        ans.append(L[i])
print(*ans)

Measured memory_bytes: 28304
import java.util.Scanner;

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

		int num = 1;
		for (int i = 0; i < N; i++) {
			if (num * 2 <= num + K) {
				num *= 2;
			} else {
				num += K;
			}
		}

		System.out.println(num);
	}
}

Measured memory_bytes: 21716
# import numpy as np
N = int(input())

mydict = {}

for i in range(N):
    moji = input()
    if moji in mydict:
        mydict[moji] = mydict[moji] + 1
    else:
        mydict[moji] = 1

values = list(mydict.values())
list.sort(values, reverse=True)

max_value = values[0]
keys = list()
for key, value in mydict.items():
    if value == max_value:
        keys.append(key)
list.sort(keys)

for i in keys:
    print(i)


Measured memory_bytes: 32988
#include <atcoder/all>
#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 t;
  cin >> t;
  rep(ti, t) {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    cout << atcoder::floor_sum(n, m, a, b) << endl;
  }
  return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        String s = sc.next();
        if(s.length() > k) {
            s = s.substring(0, k) + "...";
        }
        System.out.println(s);
    }
}


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

int main(void){
    string n;
    cin >> n;
    long c=0;
    for(long i=0; i<n.size()-1; i++){
        if(n[i+1]!='9'){
            if(c==0)n[i]--;
            c=10-n[i+1];
            n[i+1]='9';
        }
    }
    long sum=0;
    for(long i=0; i<n.size(); i++){
        sum += n[i]-'0';
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Main {
	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		String w = scanner.next();
		String[] s = w.split("");
		Map<String, Integer> map = new HashMap<>();

		for (int i = 0; i < s.length; i++) {
			String target = s[i];
			if (map.containsKey(target)) {
				map.put(target, map.get(target) + 1);
			} else {
				map.put(target, 1);
			}
		}

		for (int i : map.values()) {
			if (i % 2 != 0) {
				System.out.println("No");
				return;
			}
		}

		System.out.println("Yes");
	}
}

Measured memory_bytes: 21972
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]

ans = 0
for i in range(n):
    characteristics = 0
    for j in range(m):
        characteristics += a[i][j] * b[j]
    if characteristics + c > 0:
        ans += 1

print(ans)


Measured memory_bytes: 3060
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

s = []
s.append(min(a) + min(b))

for i in range(M):
    x_i, y_i, c_i = map(int, input().split())
    minus = a[x_i - 1] + b[y_i - 1] - c_i
    s.append(minus)

print(min(s))


Measured memory_bytes: 18736
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace ConsoleApp1
{
    class HashMap<K, V> : Dictionary<K, V>
    {
        public new V this[K key]
        {
            get
            {
                V o;
                return TryGetValue(key, out o) ? o : default(V);
            }
            set { base[key] = value; }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Sol();
        }

        public void Sol()
        {

            int N = int.Parse(Console.ReadLine());
            int[] A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var map = new HashMap<int,int>();
            foreach (int i in A)
            {
                map[i]++;
            }

            int eat = 0;
            foreach (KeyValuePair<int,int> keyValuePair in map)
            {
                eat += keyValuePair.Value - 1;
            }

            if (eat % 2 == 1)
                eat++;
            Console.WriteLine(N-eat);

        }
    }
}

Measured memory_bytes: 24160
import math
n,m,d=map(int, input().split())
mid=math.floor(n/2)
if d==0:
    ans=(1/n)*(m-1)
else:
    if mid<=d:
        ans=((mid*2)/(n**2))*(m-1)
    else:
        x=d+1
        ans=((d*2+(n-d*2)*2)/(n**2))*(m-1)
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    int ret = 0;
    for (int i = 0; i < (int)s.size(); ++i) {
        if (s[i] != t[i])
            ret++;
    }
    cout << ret << "\n";
    return 0;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.first,", ",x.second,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll N; cin >> N;
	vector<pll> data (N);
	F0R(i, N) {
		string S; cin >> S;
		ll total = 0;
		ll deep = 0;
		for (char c : S) {
			if (c == '(') ++total;
			if (c == ')') --total;
			deep = min(deep, total);
		}
		data[i] = {deep, total};
	}

	ll sum = 0;
	for (pll d : data) sum += d.second;

	if (sum != 0) {
		print("No");
		return 0;
	}

	sort(data.begin(), data.end(), [] (const auto& lhs, const auto& rhs) {
		if ((lhs.second >= 0) ^ (rhs.second >= 0)) {
			return lhs.second >= 0;
		} else if (lhs.second >= 0) {
			return lhs.first > rhs.first;
		} else {
			return lhs.second - lhs.first > rhs.second - rhs.first;
		}
	});

	ll total = 0;
	for (pll d : data) {
		if (total + d.first < 0) {
			print("No");
			return 0;
		}
		total += d.second;
	}
	print("Yes");
}

Measured memory_bytes: 18596
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

using namespace std;

#define LL long long

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

vector<int> a;
int main() {
	char c = getchar();
	while (c >= '0' && c <= '9') {
		a.push_back(c - '0');
		c = getchar();
	}
	int n = a.size();
	int **f = new int*[n];
	for (int i = 0; i < n; ++i) {
		f[i] = new int[11];
	}
	for (int i = 0; i < 11; ++i) {
		f[0][i] = min(i, 11 - i);
	}
	for (int i = 1; i < n; ++i) {
		f[i][10] = f[i - 1][a[i - 1] + 1];
		for (int j = 0; j < 10; ++j) {
			f[i][j] = min(f[i - 1][a[i - 1]] + j, f[i - 1][a[i - 1] + 1] + (10 - j));
		}
	}
	cout << f[n - 1][a[n - 1]] << endl;
	return 0;
}

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

using namespace std;

#define INF 1e9
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

ll X;

void solve(){
    if(X < 1200)
        cout << "ABC" << endl;
    else
        cout << "ARC" << endl;
}

int main(){
    cin >> X;

    solve();
}


Measured memory_bytes: 256
N, M = map(int, input().split())
AC = []
for _ in range(M):
    a, b = map(int, input().split())
    c_list = list(map(int, input().split()))
    AC.append([a, c_list])

AC = sorted(AC, key=lambda x:x[0])
dp = [10**9]*2**N
dp[0] = 0
for m in range(M):
    a, c_list = AC[m]
    c_bi = 0
    for c in c_list:
        c_bi += 2**(c-1)
    for i in range(2**N):
        dp[i|c_bi] = min(dp[i|c_bi], dp[i]+a) # コストaで行ける場所

ans = dp[-1]
if ans > 10**8:
    print(-1)
else:
    print(dp[-1])

Measured memory_bytes: 3384
#include <stdio.h>

int main()
{
  int i,n;
  int a[1000];
  scanf("%d", &n);
  double sum;
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    sum+=1./(double)a[i];
  }
  printf("%f\n",1./sum);  
  return 0;
}

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

int euc(int x,int y){
  //ensure that x>=y
  if(x%y==0){
    return y;
  }else{
    return euc(y,x%y);
  }
}

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> A(N,0);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  sort(A.begin(),A.end());
  if(N==1){
    if(A[0]==K){
      cout << "POSSIBLE" << endl;
    }else{
      cout << "IMPOSSIBLE" << endl;
    }
    return 0;
  }
  int gc = euc(A[1],A[0]);
  for(int i=1;i<N;i++){
    gc = euc(A[i],gc);
  }
  if(K>A[N-1]||K%gc>0){
    cout << "IMPOSSIBLE" << endl;
  }else{
    cout << "POSSIBLE" << endl;
  }
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<math.h>
#include<assert.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384
int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int nHr(int a,int b){return nCr(a+b-1,b);}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;}
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}
int sankaku(int x){return ((1+x)*x)/2;}
void swap(int *a,int *b){int c;c=(*a);(*a)=(*b);(*b)=c;}
//大きい順
int compareInt(const void* a, const void* b){int aNum = *(int*)a;int bNum = *(int*)b;return bNum - aNum;}

int main(void){
    char edi[10];
    char exp[10];
    scanf("%s",edi);
    int i=0,j=0;
    int cnt=0;
    while(edi[cnt]!='\0'){
        cnt++;
    }
    for(i=0;i<cnt;i++){
        if(edi[i]=='0'){
            exp[j]='0';
            j++;
        }else if(edi[i]=='1'){
            exp[j]='1';
            j++;
        }else if(j!=0){
            j--;
        }
    }
    for(int t=0;t<j;t++){
        printf("%c",exp[t]);
    }
   
}


Measured memory_bytes: 128
import sys
MOD = 10**9 + 7

def mod_inv(n, m):
    return pow(n, m-2, m)

def nCr_mod_m(n, r, m):
    if r < 0 or n < r:
        return 0
    # n!
    fact = fact_prev = 1 # 0! = 1! = 1
    for i in range(2, n+1):
        fact = fact_prev * i % m
        fact_prev = fact
    # n!^(-1)
    fact_inv = [0]*(max(r, n-r)+1)
    fact_inv[0] = fact_inv[1] = 1  # 1 = 1 mod m
    for i in range(2, max(r, n-r)+1):
        fact_inv[i] = fact_inv[i-1] * mod_inv(i, m) % m
    return (fact * fact_inv[r] % m) * fact_inv[n-r] % m

def main():
    X, Y = map(int, input().split())
    if ((X+Y)%3 != 0) or (min(X,Y)*2 < max(X,Y)):
        print(0)
        sys.exit()

    base = (X + Y) // 3
    x = X - base
    y = Y - base

    print(nCr_mod_m(x+y, x, MOD))
main()

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

int main() {
  int a,b;
  cin>>a>>b;
  string vec[a];
  for(int i=0;i<a;i++){
    cin>>vec[i];
  }
  int ans[a][b];
  for(int i=0;i<a;i++){
    for(int j=0;j<b;j++){
      ans[i][j]=0;
    }
  }
  for(int i=0;i<a;i++){
    for(int j=0;j<b;j++){
      if(vec[i][j]=='#'){
        ans[i][j]=5000;
        if(i>0){
          if(j>0){
            ans[i-1][j-1]++;
          }
          if(j<b-1){
            ans[i-1][j+1]++;
          }
          ans[i-1][j]++;
        }
        if(i<a-1){
          if(j>0){
            ans[i+1][j-1]++;
          }
          if(j<b-1){
            ans[i+1][j+1]++;
          }
          ans[i+1][j]++;
        }
        if(j>0){
          ans[i][j-1]++;
        }
        if(j<b-1){
          ans[i][j+1]++;
        }
      }
    }
  }
  for(int i=0;i<a;i++){
    for(int j=0;j<b;j++){
      if(ans[i][j]>=5000){
        cout<<'#';
      }
      else{
        cout<<ans[i][j];
      }
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    while 1:
        line = input()
        if line == '#':break
        right = ['q','a','z','w','s','x','e','d','c','r','f','v','t','g','b']
        left = ['y','h','n','u','j','m','i','k','o','l','p']
        ans = 0
        if line[0] in left:current ,other= left,right
        else:current,other = right,left
        for moji in line:
            if  not moji in current:
                ans +=1
                current ,other= other,current
            else: pass
        print(ans)

Measured memory_bytes: 7476
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;string S;
  cin>>N>>S;
  int dp[10][S.size()+1];
  for(int j=0;j<10;j++)dp[j][S.size()]=0;
  for(int i=S.size()-1;i>=0;--i){
    for(int j=0;j<10;++j){
      dp[j][i]=dp[j][i+1];
    }
    dp[S[i]-'0'][i]++;
  }
  int i_0,i_1,sum=0;
  for(int i=0;i<10;++i){
    for(i_0=0;;){
      if(i_0==S.size())break;
      if(S[i_0]-'0'==i)break;
      i_0++;
    }
    if(i_0==S.size())continue;
    for(int j=0;j<10;++j){
      for(i_1=i_0+1;;){
        if(i_1==S.size())break;
        if(S[i_1]-'0'==j)break;
        i_1++;
      }
      if(i_1==S.size())continue;
      for(int k=0;k<10;++k)sum+=(dp[k][i_1+1]==0 ? 0:1);
    }
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rbf(a, x) for (auto& a : x)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define drep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define Maxe(x) *max_element(all(x))
#define Mine(x) *min_element(all(x))
#define Size(x) ((ll)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
#define Fi first
#define Se second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    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;
    }

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo
//mint,dijkstra,gyakugen
    vector<long long> divisor(long long n) {
        vector<long long> ret;
        for (long long i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                ret.emplace_back(i);
                if (i * i != n) ret.emplace_back(n / i);
            }
        }
        sort(ret.begin(), ret.end()); // 昇順に並べる
        return ret;
    }

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll n;
        cin>>n;
        vl A(n);
        rep(i,n)cin>>A[i];
        sort(all(A));
        umap<ll,ll> M;
        ll res=0;
        rep(i,n){
            if(M[A[i]])continue;
            if(i<n-1&&A[i]==A[i+1]){
                M[A[i]]++;
                continue;
            }
            bool c=true;
            vl x=divisor(A[i]);
            rbf(p,x){
                if(M[p]){
                    c=false;
                    break;
                }
            }
            M[A[i]]++;
            if(c)res++;
        }
        cout<<res<<"\n";
    }

Measured memory_bytes: 33356
#include<stdio.h>
#include<algorithm>
int main() {
	int a[3];
	while (scanf("%d %d", &a[0], &a[1])) {
		if (a[0] == 0 && a[1] == 0)
			break;
		std::sort(a, a + 2);
		printf("%d %d\n", a[0], a[1]);
	}
	return 0;
}

Measured memory_bytes: 2740
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		int sum = 0;
		for(int i=0;i<4;i++) {
			sum += sc.nextInt();
		}
		System.out.println(sum/60);
		System.out.println(sum%60);
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl
#define Vecpr(K,L1,L2,N) vector<pair<L1,L2>> K(N)
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,R) vector<vector<L>> K(N, vector<L>(M,R))
#define pint pair<lli,lli>
#define Lower(v,X) lower_bound(v.begin(),v.end(),X)-v.begin();
#define mod 1000000007
#define MAX 5100000
#define ceili(x,y) (x+y-1)/y  
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main(){
  lli A,B,C,D,E,L,R,X,Y,W,H,N,M,K,sum=0,num=0,flag=0;string S,T;
  cin >> N;
  Vec(P,pint,N,pint(0,0));
  rep(i,0,N)cin >> P[i].second >> P[i].first;
  Sort(P);
  rep(i,0,N){
    sum+=P[i].second;
    if(sum>P[i].first){
      flag++;
      break;
    }
  }
  if(flag)Out("No");
  else Out("Yes");
}

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

typedef long long int ll;

ll check(ll n)
{
	// cout << "in\n";
	// cout << n << endl;
	ll i,j,k,l,m;

	j = 0;
	m = 0;

	while(n > 0)
	{
		k = n;
		// cout << k << '\n';
		j = 0;
		while(k>0)
		{
			if(k%2 == 1)
				j++;

			k = k/2;
		}

		n = n%j;
		m++;

	}

	// cout << m << '\n';
	// cout << "out\n";

	return m;
	

}

/* Iterative Function to calculate (x^y)%p in O(log y) */
ll power(ll x, ll y, ll p)  
{  
    ll res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  
  
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll i,j,t,k,l,m,n,c,r,d;

	string x;

	cin >> n;

	cin >> x;

	// cout << x << endl;

	ll ones = 0;

	for(i=0;i<n;i++)
	{
		if(x[i] == '1')
			ones++;
	}

	if(ones == 0)
	{
		for(i=0;i<n;i++)
			cout << 1 << '\n';
		return 0;
	}

	if(ones == 1)
	{
		for(i=0;i<n;i++)
		{
			if(x[i] == '1')
				cout << 0 << '\n';
			else
			{
				if(x[n-1] == '1')
					cout << 2 << '\n';
				else
				{
					if(i == (n-1))
						cout << 2 << '\n';
					else
						cout << 1 << '\n';
				}
			}
		}

		return 0;
	}

	l = ones-1;
	k = ones+1;

	// cout << ones << endl;
	{
		
	};;

	m = 1;
	t = 0;

	for(i=(n-1);i>=0;i--)
	{
		if(x[i] == '1')
		{
			t = t+m%l;
			t = t%l;

		}

		m = (m*2)%l;

	}

	// cout << t << endl;
	m = 1;
	c = 0;
	for(i=(n-1);i>=0;i--)
	{
		if(x[i] == '1')
		{
			c = c+m%k;
			c = c%k;

		}

		m = (m*2)%k;

	}

	// cout << c << endl;

	// cout << check(7) << endl;
	for(i=0;i<n;i++)
	{
		if(x[i] == '1')
		{

			cout << check((t-power(2,n-i-1,l)+l)%l)+1 << '\n';
		}
		else
		{
			cout << check((c+power(2,n-i-1,k))%k)+1 << '\n';
		}
	}





	

	
	

}

Measured memory_bytes: 3784
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int i, N, M, p[100001];
	char S[100001][3];
	scanf("%d %d", &N, &M);
	for (i = 1; i <= M; i++) scanf("%d %s\n", &(p[i]), S[i]);
	
	
	int result[100001] = {};
	for (i = 1; i <= M; i++) {
		if (result[p[i]] > 0) continue;
		else if (S[i][0] == 'A') result[p[i]] = 1 - result[p[i]];
		else result[p[i]]--;
	}
	
	int correct = 0, penalty = 0;
	for (i = 1; i <= N; i++) {
		if (result[i] > 0) {
			correct++;
			penalty += result[i] - 1;
		}
	}
	
	printf("%d %d\n", correct, penalty);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
	Scanner scanner = new Scanner(System.in);
	int n = scanner.nextInt();
	int m = scanner.nextInt();
	scanner.close();

	int numberOfEvenPairs = (n * (n - 1)) / 2 + (m * (m - 1)) / 2;

	System.out.println(numberOfEvenPairs);

    }
}

Measured memory_bytes: 22864
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;
using gragh = vector<vector<int>>;

int main() {
    vector<int>ans(3,0);
    for (int i = 0; i < 3; ++i) {

        ans[i] = i+1;
    }

    int A;
    int B;
    cin>>A;
    cin>>B;

    for (int j = 0; j < 3; ++j) {
        if(ans[j] != A && ans[j] != B){
            cout<<ans[j]<<endl;
        }
    }

}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#define INF 1000000007
#define P pair<int,int>

using namespace std;

char maze[51][51];
int s[51][51];
int H,W;
int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};

int bfs(){
    for(int i=0;i<50;i++){
        for(int j=0;j<50;j++){
            s[i][j] = INF;
        }
    }
    queue<P> que; 
    que.push(P(0,0));
    s[0][0]=0;
    while(!que.empty()){
        P p =que.front();que.pop();
        for(int i=0;i<4;i++){
            int nx = p.first+dx[i];int ny=p.second+dy[i];
            if(nx>=0&&nx<H&&ny>=0&&ny<W&&maze[nx][ny]=='.'&&s[nx][ny]==INF){
                que.push(P(nx,ny));
                s[nx][ny]=s[p.first][p.second]+1;
            }
        }
    }
    return s[H-1][W-1];
}

int main(){
    cin >>H>>W;
    int count=0;
    for (int i=0;i<H;i++){
        for (int j=0;j<W;j++){
            cin >>maze[i][j];
            if (maze[i][j]=='#') count++;
        }
    }
    if (bfs()==INF) cout<<-1<<endl;
    else cout<<H*W-count-bfs()-1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>//输入输出要用的文件。 
#include<cmath>//sqrt要用的文件。 
using namespace std;
long long n,ans;//10的10次方超int。 
int s;
int main(){
    scanf("%lld",&n);//long long的scanf要用lld。 
    for(int i=sqrt(n);i>0;--i) //从平方根开始搜索，用n除以搜到的第一个数，计算出它的位数就是答案。 
        if(n%i==0){
            ans=n/i;
            break;
        }
    while(ans>0){//计算位数。 
        ++s;
        ans/=10;
    }
    printf("%d\n",s);//s为int型变量。 
    return 0;
}//完美结束。 

Measured memory_bytes: 256
//       In the name of         ****                      God                     ****

/*

Copyright (C)          JadedBeast

                                   Morocco

created : 10/3/2019

*/

#include <bits/stdc++.h>
using namespace std;
#define time cout << "\ntime: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
#define W 100099
inline void Boost() {
	cin.tie(0);cin.sync_with_stdio(0);
	cout.tie(0);cout.sync_with_stdio(0);
}
static	long long n,w;
long long DP[101][W],knap[101][2];

long long dp(int i,int value){
	if(value==0)
		return 0;
	if(value<0 || i>=n)
		return 69696969696;

	if(DP[i][value]!=-1)
		return DP[i][value];

	return DP[i][value]=min(knap[i][0]+dp(i+1,value-knap[i][1]),dp(i+1,value));


}



int main(void){
	Boost();

	cin >>n >> w;
	
	for(int i=0 ;i<n ;i++)
		for(int j=0 ; j<2 ;j++)
			cin >>knap[i][j];

	memset(DP,-1,sizeof(DP));

	for(int i=W;i>=0;i--){
        long long x=dp(0,i);
        if(x<=w){
            cout<<i<<endl;
        	break;
        	}
    	}

	//cout <<ans<<endl;

   return 0;
}


Measured memory_bytes: 79360
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <boost/lexical_cast.hpp>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

bool ok(int N, int M, const vec<int> &s, const vec<int> &c, const string &t) {
  if (t.length() != N) {
    return false;
  }
  for (int j = 0; j < M; j++) {
    if (t[s[j] - 1] != boost::lexical_cast<char>(c[j])) {
      return false;
    }
  }
  return true;
}

string solve(int N, int M, const vec<int> &s, const vec<int> &c) {
  for (int i = 0; i < 1000; i++) {
    string t = boost::lexical_cast<string>(i);
    if (ok(N, M, s, c, t)) {
      return t;
    }
  }
  return string("-1");
}

int main() {
  int N, M;
  cin >> N >> M;
  vec<int> s(M), c(M);
  REP(i, M) { cin >> s[i] >> c[i]; }
  cout << solve(N, M, s, c) << endl;
  return 0;
}


Measured memory_bytes: 3636
main(){float w;for(;~scanf("%f",&w);)puts(w>48?w>51?w>54?w>57?w>60?w>64?w>69?w>75?w>81?w>91?"heavy":"light heavy":"middle":"light middle":"welter":"light welter":"light":"feather":"bantam":"fly":"light fly");return 0;}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
const LL M = 1000000007;
void show(VEC<VEC<int>> A) {
  REP(i, 0, A.size()) {
    REP(j, 0, A[i].size()) { cerr << A[i][j] << " "; }
    cerr << endl;
  }
  cerr << endl;
}
LL gbit(LL n, LL i) { return (n >> i) & 1; }

int main() {
  LL N;
  cin >> N;
  VEC<LL> A(N);
  REP(i, 0, N) cin >> A[i];
  LL bit_lim = 61;
  // LL lim = pow(2, 60);
  VEC<LL> B(bit_lim, 0);
  VEC<VEC<LL>> bit_cs(bit_lim, VEC<LL>(N));
  REP(bit, 0, bit_lim) {
    bit_cs[bit][0] = gbit(A[0], bit);
    REP(i, 1, N) { bit_cs[bit][i] = gbit(A[i], bit) + bit_cs[bit][i - 1]; }
  }
  // show(bit_cs);
  REP(bit, 0, bit_lim) {
    REP(i, 0, N) {
      LL one_num_raw = bit_cs[bit][N - 1] - bit_cs[bit][i];
      LL one_num;
      if (gbit(A[i], bit) == 0) {
        one_num = one_num_raw;
      } else {
        one_num = N - i - 1 - one_num_raw;
      }
      B[bit] = (B[bit]+one_num)%M;
    }
  }
  LL sum = 0;
  REP(bit, 0, bit_lim) {
    // LL c = 0;
    // LL adding = (1LL << bit);
    // REP(i, 0, B[bit]) { c = (c + adding) % M; }
    LL c = (B[bit] * ((1LL << bit)%M)) % M;
    sum = (sum + c) % M;
  }
  cout << sum << endl;

  return 0;
}
int seeing_olphe() {//AC
  ULL N;
  cin >> N;
  VEC<ULL> A(N);
  REP(i, 0, N) cin >> A[i];
  ULL bit_lim = 60;
  VEC<ULL> B(bit_lim, 0);
  REP(bit, 0, bit_lim) {
    LL zeros = 0;
    LL ones = 0;
    REP(i, 0, N) {
      if (gbit(A[i], bit)) {
        ones++;
      } else {
        zeros++;
      }
    }
    // zeros=(N-ones);
    B[bit] = (zeros * ones) % M;
  }
  ULL sum = 0;
  REP(bit, 0, bit_lim) {
    ULL c = (1ULL << bit) % M;
    c = (B[bit] * c) % M;
    sum = (sum + c) % M;
  }
  cout << sum << endl;
  return 0;
}


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

#define ll long long

using namespace std;

int n, k;
int d[10];

bool check(int x) {
  while (x) {
    if (d[x % 10]) return 0;
    x /= 10;
  }
  return 1;
}

main() {
  scanf("%d %d", &n, &k);
  for (int i = 0, x; i < k; i++) {
    scanf("%d", &x);
    d[x] = 1;
  }
  for (int i = n; i <= 1e6; i++) {
    if (check(i)) {
      cout << i;
      return 0;
    }
  }
  assert(false);
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <functional>
#include <unordered_map>
#include <set>

#include <cassert>
using namespace std;

int main(void){

	string s;
	cin >> s;
	vector<short> nx(1,0),ny(1,0);

	int dx,dy;
	cin >> dx >> dy;

	int ofx=0;
	int i;
	for(i=0;i<s.size();++i){
		if(s[i]=='T'){
			dx = abs(dx);
			dy = abs(dy);
			i+=1;
			break;
		}else{
			dx-=1;
		}
	}
	
	int d = 1; //0=x,1=y,最初は1回方向転換済みなのでy
	int cnt=0;
	for(;i<s.size();++i){
		auto &n = (d==0)?nx:ny;
		if (s[i]=='T'){
			if(cnt>0){
				for(int k=0;k<n.size();++k){ n[k] += cnt; }
				cnt=0;
			}
			d = 1 - d;
			continue;
		}

		// 'F'
		auto dd = (d==0)?dx:dy;
		if(s[i-1]=='T'){
			set<short> nnext;
			for(int k=0;k<n.size();++k){
				const auto &v = n[k];
				auto in1=v+1,in2=v-1;
				nnext.insert(in1);
				nnext.insert(in2*-1);
			}
			n.resize(0);
			n.reserve(nnext.size());
			for(auto it=nnext.begin();it!=nnext.end();++it){ n.push_back(*it); }
		}else{
			cnt+=1;
		}
	}

	if(cnt>0){
		auto &n = (d==0)?nx:ny;
		for(int k=0;k<n.size();++k){ n[k] += cnt; }
	}
	for(int i=0;i<nx.size();++i){nx[i]=abs(nx[i]);} sort(nx.begin(),nx.end());
	for(int i=0;i<ny.size();++i){ny[i]=abs(ny[i]);} sort(ny.begin(),ny.end());

	if(binary_search(nx.begin(),nx.end(),dx) && binary_search(ny.begin(),ny.end(),dy)){
		std::cout << "Yes" << endl;
	}else{
		std::cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 512
n, q = map(int, input().split())
s = input()

ac = [0] * n
for i in range(1, n):
    ac[i] = ac[i-1] + int(s[i-1:i+1] == "AC")

for _ in range(q):
    l, r = map(int, input().split())
    print(ac[r-1] - ac[l-1])

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

const ll MOD = 1e9 + 7;

int main()
{
    int n;
    cin >> n;
    ll ans = 1;
    repl(i, 1, n + 1) {
        ans %= MOD;
        ans *= i;
    }
    ans %= MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
#include <functional>
using namespace std;
typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA cerr << "AAAAA" << endl
#define debug_ cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    cout << #v << endl;                \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    cout << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

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

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

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>; // クラスカル法とかで、{cost, {from, to}}的に使う。
const ll LINF = 1001002003004005006ll;
const ll INF = 1001001001;
const double pi = acos(-1);

int main()
{
    char s;
    cin >> s;
    if (s - 'A' >= 0 && s - 'A' <= 26)
    {
        cout << "A" << endl;
    }
    else
    {
        cout << "a" << endl;
    }

    return 0;
}

Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int X = sc.nextInt();

		int ans = (X / 500) * 1000 + ((X % 500) / 5) * 5 ;

		System.out.println(ans);
	}

}

Measured memory_bytes: 21972
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc= new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		if(a+b<a-b){
			if(a-b<a*b){
				System.out.println(a*b);
			}else {
				System.out.println(a-b);
			}
		}else {
			if(a+b<a*b){
				System.out.println(a*b);
			}else {
				System.out.println(a+b);
			}
			
		}

	}
}

Measured memory_bytes: 21716
#include <iostream>
using namespace std;
bool list[101];

int main(){
    int n;
    cin >> n;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            list[i*j]=true;
        }
    }
    if(list[n]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

struct Edge { int v, w; };

int N;
vector<Edge> edge[100005];
int ans[100005];

void dfs(int v, int p) {
    for (const Edge& e : edge[v]) {
        if (e.v == p) continue;
        ans[e.v] = (e.w % 2 ? 1 - ans[v] : ans[v]);
        dfs(e.v, v);
    }
}

int main() {
    cin >> N;
    for_(i,0,N-1) {
        int u, v, w;
        cin >> u >> v >> w;
        --u; --v;
        edge[u].push_back({v, w});
        edge[v].push_back({u, w});
    }

    ans[0] = 0;
    dfs(0, -1);
    for_(i,0,N) cout << ans[i] << endl;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
 string S;
  cin>>S;
  string k="2019/04/30";

 for(ll i=0;i<9;i++) {

if(S[i]-k[i]>0) {
cout<<"TBD"<<endl;

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

Measured memory_bytes: 3608
#!/usr/bin/env python3
import collections
MOD = 10**9 + 7

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

C = collections.Counter(A)
ret = 2**(N//2)
if N % 2 == 0:
    for i in range(1, N, 2):
        if C[i] != 2:
            ret = 0
            break
else:
    if C[0] != 1:
        ret = 0
    for i in range(2, N, 2):
        if C[i] != 2:
            ret = 0
            break

print(ret % MOD)


Measured memory_bytes: 20680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0, i_l = (int)n; i < i_l; i++)
#define loop(i, a, b) for (int i = a; i < (int)(b); i++)

//
int N;
string s;

char reversed(char c) {
    return c == 'S' ? 'W' : 'S';
}


string solve(char first, char second) {
    char ans[N];
    ans[0] = first;
    ans[1] = second;

    loop(i, 2, N + 2) {
        int j0 = (i % N);
        int j1 = ((i - 1) % N);
        int j2 = ((i - 2) % N);

        char c1 = s[j1];
        char a1 = ans[j1];
        char a2 = ans[j2];

        if (c1 == 'o') {
            if (a1 == 'W') {
                ans[j0] = reversed(a2);
            } else {
                ans[j0] = a2;
            }
        } else {
            if (a1 == 'W') {
                ans[j0] = a2;
            } else {
                ans[j0] = reversed(a2);
            }
        }
    }
    if (ans[0] == first && ans[1] == second) {
        return string(ans, N);
    }
    return "";
}


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

    for (int i = 0; i < 4; i++) {
        char c1 = (i / 2 == 0) ? 'S' : 'W';
        char c2 = (i % 2 == 0) ? 'S' : 'W';
        string a = solve(c1, c2);
        if (a.length() > 0) {
            cout << a << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#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 ll long long
bool lun(ll x)
{
	ll lst=x%10;
	while(x)
	{
		ll p=x%10;
		x/=10;
		if(abs(p-lst)>1)
		{
			return false;
		}
		lst=p;
	}
	return true;
}
string nws(int v)
{
	string kk;
	kk+='1';
	rep(i,1,v-1)kk+='0';
	return kk;
}
int main(int argc, char** argv) {
	int k;
	cin>>k;
	int fs;
	if(k<=10)cout<<k;
	else
	{
		string now="11";
		k-=11;
		int v=2;
	while(k)
	{
		int fg=0;
		rep2(i,now.length()-1,1)
		{
			
			if(now[i]!=now[i-1]+1&&now[i]!='9'&&!fg)
			{
				now[i]++;
				rep(j,i+1,now.length()-1)now[j]=max(now[j-1]-1,(int)'0');
				fg=1;
				break;
			}
		}	
		
		if(!fg)
		{	if(now[0]=='9')
			now=nws(++v);
			else {
			now[0]++;rep(i,1,now.length()-1)now[i]=max(now[i-1]-1,(int)'0');}
		}
	//cout<<now<<" "<<fg<<endl;
		k--;
	}
	cout<<now;
	}
	return 0;
}

Measured memory_bytes: 256