akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int flag=0;
  cin>>s;
  for(long long int i=0;i<s.length();i++){
    if((s[i]=='R')&&(i%2!=0))
      flag=1;
    if((s[i]=='L')&&(i%2==0))
      flag=1;
  }
  if(flag)
    cout<<"No"<<endl;
  else
    cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  string S,T="Heisei";
  cin>>S;
  if(S[5]=='1') T="TBD";
  else if((int)(S[6] - '0')>=5) T="TBD";
  cout<<T<<endl;
return 0;}

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

using namespace std;

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

	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	sort(a,a+n);
	cout << a[n-1] - a[0];
	return 0;
}

Measured memory_bytes: 3644
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		/*
		 ** Constraint* *
		    1≤a,b,c≤10000
		 	a≤b
		 */
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] streamLine = br.readLine().split(" ");
		int[] intArray = toIntArray(streamLine);
		
		int sum = 0;
		for (int i = intArray[0]; i <= intArray[1]; i++) {
			if (intArray[2] % i  == 0) {
				sum++;
			}
		}
		
		System.out.println(sum);
		
	}
	
	public static int[] toIntArray(String[] strArray) {
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}
}


Measured memory_bytes: 24428
N = int(input())
A = list(map(int,input().split()))

import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

L = [0 for i in range(N+1)]
R = [0 for j in range(N+1)]

for i in range(N):
    L[i+1] = fractions.gcd(L[i],A[i])
    R[N-1-i] = fractions.gcd(R[N-i],A[N-i-1])

M = 0
for i in range(N):
    M = max(M,fractions.gcd(L[i],R[i+1]))

print(M)

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

D = [[] for i in range(N+2)]

for i in range(N) :
  a = input().split()
  D[i].append(int(a[0]))
  D[i].append(int(a[1]))
  a.clear()

D[N].append(0)
D[N].append(1)

D[N+1].append(0)
D[N+1].append(1)
  
#print('N = ', N)
#print('D = ', D)

judge = 'No'

for i in range(N) :
  if D[i][0] == D[i][1] and D[i+1][0] == D[i+1][1] and D[i+2][0] == D[i+2][1] :
    judge = 'Yes'

print(judge)



Measured memory_bytes: 9220
x, k, d = map(int, input().split())

x = abs(x)
#0に最も近い距離になる。
ans = x % d
#ansへの移動回数分、kから引く
if k- (x//d) < 0:
    print(x - k*d)
    exit()
else:
    k -= x//d

if k % 2 == 0:
    print(ans)
else:
    t1 = abs(ans-d)
    t2 = abs(ans+d)
    print(min(t1, t2))

Measured memory_bytes: 9184
# coding: utf-8

import math

#ans^2 = A^2 +B^2 - 2ABconDiffを使用
line = input().split(" ")
A = int(line[0])
B = int(line[1])
H = int(line[2])
M = int(line[3])

ans = 0

#Aの刺す分
ang_a = H * 5 + M/12
#Bの刺す時間
ang_b = M

if ang_a == ang_b:
    ans = A - B

else:
    diff = abs(ang_a-ang_b)
    theta = (diff / 60) * 360
    ans_pow = A**2 + B**2 - 2 * A * B * math.cos(math.radians(theta))
    ans = ans_pow**0.5

print(ans)



Measured memory_bytes: 9496
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n;
    cin >> n;
    int ac = 0,wa = 0,tle = 0,re = 0;
    for(int i = 0;i < n;i++){
         string s;
         cin >> s;
         if(s == "AC"){
               ac++;
         }else if(s == "WA"){
               wa++;
         }else if(s == "TLE"){
               tle++;
         }else if(s =="RE"){
               re++;
         }
          
          
    }
    cout << "AC x " << ac << endl;
          cout << "WA x " << wa << endl;
          cout << "TLE x " << tle << endl;
          cout << "RE x " << re << endl;

          
}


Measured memory_bytes: 3572
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

long long calc_cost (vector<int> X, int pos, long long current_min, bool compare_with_min = true) {
  long long ret = 0;
  for (int i=0; i<X.size(); i++){
    ret += pow(X[i] - pos, 2);
    if (compare_with_min && ret > current_min) {
      return -1;
    }
  }
  return ret;
}

int main(){
  int N;
  cin >> N;
  vector<int> X(N);
  for (int i=0; i<N; i++){
    cin >> X[i];
  }
  sort(X.begin(), X.end());
  long long ans = 0;
  for (int i = X[0]; i<X.back(); i++) {
    if (i == X[0]) {
      ans = calc_cost(X, i, 0, false);
    } else {
      long long ans_temp = calc_cost(X, i, ans);
      if (ans_temp != -1) {
        ans = ans_temp;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  using ll = long long;
  ll n = size(s);
  ll n0 = count(begin(s), end(s), '0');
  ll n1 = count(begin(s), end(s), '1');
  auto res = 0LL;
  for (int i = 1; i <= n1; ++i) {
    res += i / 2;
  }
  vector<ll> cnt(n + 1);
  for (int i = n; i--; ) {
    if (s[i] == '1') {
      cnt[i] = 1 + cnt[i + 1];
    }
  }
  int gi = -1;
  for (int i = 0; i < n; ++i) {
    if (s[i] == '0') continue;
    ++gi;
    if (i and s[i - 1] == '1') continue;
    DEBUG(i, cnt[i], gi);
    res += cnt[i] / 2 * (n0 + 1);
    if (cnt[i] & 1) {
      int odd = (i + 1) / 2 - gi / 2;
      res += n0 + 1 - odd;
    }
  }
  cout << res << '\n';
}


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

using namespace std;
using ll = long long;


ll cur;

class Union_Find{
private:
    std::vector<long long> data; //data[i] : 頂点iの親
public:
    Union_Find(ll n){
        data.resize(n,-1);
    }
    //頂点iの親を返す
    ll root(ll i){
        if(data[i] < 0)return i;
        else return data[i] = root(data[i]);
    }
    //連結
    void unit(ll i,ll j){
        i = root(i);j = root(j);
        if(i != j){
            data[i] += data[j];
            data[j] = i;
        }
    }

    //頂点iの属する集合の頂点数
    ll size(ll i){
        i = root(i);
        return -data[i];
    }
};

int main()
{
    ll n, m;
    cin >> n >> m;
    Union_Find uni(n);
    vector<ll> a(m), b(m);
    for(ll i = 0; i < m; i++){
        cin >> a[i] >> b[i]; a[i]--, b[i]--;
    }
    cur = (ll)(n - 1) * n / 2;
    vector<ll> ans(m);

    for(ll i = 0; i < m; i++) {
        ll x = a.back(), y = b.back();
        a.pop_back(), b.pop_back();
        ans[m - i - 1] = cur;
        if(uni.root(x) == uni.root(y))continue;
        cur -= (uni.size(y) * uni.size(x));
        uni.unit(x, y);
    }
    for(auto i : ans)cout << i << endl;
}

Measured memory_bytes: 4480
using System;

class Solution
{
    public int Proc(int N, int L)
    {
        int min = L;
        int sum = 0;
        for (int i = 0; i < N; i++)
        {
            int val = i + L;
            sum += i + L;
            if (val * val < min * min) min = val;
        }

        sum -= min;

        return sum;
    }
}

class Program
{
    static string[] GetVals(string splitChar)
    {
        var src = Console.ReadLine();
        return src.Split(new string[] { splitChar }, StringSplitOptions.None);
    }

    static string[] GetVals(char splitChar)
    {
        var src = Console.ReadLine();
        return src.Split(splitChar);
    }

    static string GetVal()
    {
        return Console.ReadLine();
    }

    static void Write(object o)
    {
        Console.WriteLine(String.Format("{0}", o));
    }

    static int ParseI(string val) { return int.Parse(val); }
    static double ParseD(string val) { return double.Parse(val); }

    static void Main(string[] args)
    {
        var s = GetVals(' ');
        Write(new Solution().Proc(int.Parse(s[0]), int.Parse(s[1])));

        //Write(new Solution().Proc(5, 2));//B
        //Write(new Solution().Proc(3 ,-1));//G
        //Write(new Solution().Proc(30 ,-50));//B

        //GetVal();
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <cmath>
using namespace std;
//イントとダブルが入り乱れるときはどちらかに統一しよう。

int max(int x,int y){
  if(x>y) return x;
  return y;
}

int min(int x,int y){
  if(x<y) return x;
  return y;
}

int findSumOfDigits(int n){
  int sum = 0;
  while(n>0){
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main(){
  int n;
  cin >> n;
  if(n%findSumOfDigits(n)==0)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
r, c, k = map(int, input().split())
items = [[0] * (c+1) for _ in range(r+1)]
for _ in range(k):
    R, C, V = map(int, input().split())
    items[R][C] = V

dp1 = [[0] * (c+1) for _ in range(r+1)]
dp2 = [[0] * (c+1) for _ in range(r+1)]
dp3 = [[0] * (c+1) for _ in range(r+1)]

for i in range(1, r+1):
    for j in range(1, c+1):
        v = items[i][j]
        dp1[i][j] = max(dp1[i][j-1], dp1[i-1][j] + v, dp2[i-1][j] + v, dp3[i-1][j] + v)
        dp2[i][j] = max(dp2[i][j-1], dp1[i][j-1] + v)
        dp3[i][j] = max(dp3[i][j-1], dp2[i][j-1] + v)

ans = max(dp1[r][c], dp2[r][c], dp3[r][c])
print(ans)

Measured memory_bytes: 358048
#include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define sd second
#define ll long long

using namespace std;

const int maxn = 200100;
const int C = 27;
const int oo = 1e9;

int n,k,a[maxn];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
   // freopen("in.txt","r",stdin);
    cin>>n>>k;
    for (int i=1;i<=n;i++) {
        int x;
        cin>>x;
        a[x]++;
    }
    int sum=0;
    for (int i=1;i<=n;i++) sum+=(a[i]!=0);
    sort(a+1,a+n+1);
    int num = sum - k,now=1,res=0;
    while (num>0) {
        if (a[now]!=0) {
            num--;
            res+=a[now];
        }
        now++;
    }
    cout<<res;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
int dt[105][105];

int main( void ) {
    int n, m;
    cin >> n >> m;
    for( int i = 0; i < n; ++i ) {
        for( int j = 0; j < m; ++j ) {
            cin >> dt[i][j];
            dt[i][m] += dt[i][j];
            dt[n][j] += dt[i][j];
            dt[n][m] += dt[i][j];
        }
    }
    for( int i = 0; i <= n; ++i ) {
        for( int j = 0; j <= m; ++j ) {
            cout << dt[i][j] << ( j == m ? '\n' : ' ' );
        }
    }
    return 0;
}



Measured memory_bytes: 3124
#include<bits/stdc++.h>
typedef long long ll;
const int N=55,M=200005;
inline void upi(ll&a,const ll&b){a>b?a=b:0;}
int n,x,d,p[N],sz[N],i,j,k,xb,z;
ll f[M],m[N];
struct atom{
	int p,cnt;ll v;
	bool operator<(const atom&rhs)const{
		return 1ll*p*rhs.v<1ll*rhs.p*v;
	}
}a[N];
int main(){
	scanf("%d%d%d%lld",&n,&x,&d,m+1);
	for(i=2;i<=n;++i)scanf("%lld%d",m+i,p+i);
	for(i=n;i;--i){
		sz[p[i]]+=++sz[i],m[p[i]]+=m[i];
		a[i]=(atom){sz[i],std::max(0,d-50),m[i]};
	}a[1].cnt=1<<30;z=d<50?d:50;
	memset(f,10,sizeof f);
	for(i=n;i<M;i+=n)f[i]=1ll*(i/n)*m[1];f[0]=0;
	for(i=2;i<=n;++i){
		static int q[M];int t,w;
		static ll of[M];memcpy(of,f,sizeof f);
		for(j=0;j<sz[i];++j){
			t=1,w=1;q[1]=j;
			for(k=j+sz[i];k<M;k+=sz[i]){
				if(k-q[t]>z*sz[i])++t;
				if(t<=w)upi(f[k],of[q[t]]+(k-q[t])/sz[i]*(ll)m[i]);
				while(t<=w && of[k]-k/sz[i]*(ll)m[i]<of[q[w]]-q[w]/sz[i]*(ll)m[i])--w;
				q[++w]=k;
			}
		}
	}
	int ans=0;
	std::sort(a+1,a+n+1);
	for(i=0;i<M && f[i]<=x;++i){
		int z=x-f[i],al=i;
		for(j=n;j && z;--j){
			int u=std::min(a[j].cnt,int(z/a[j].v));
			al+=u*a[j].p;z-=a[j].v*u;
		}
		ans=std::max(ans,al);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4096
import sys

def bfs():
    global V, D

    D[1] = 0
    children = V[1]
    d = 1
    while len(children) != 0 :
        new = []
        for child in children:
            if D[child] == -1:
                D[child] = d
                new += V[child]
        children = new
        d += 1

lines = sys.stdin.readlines()
n = int(lines[0])
V = [[] for _ in range(n + 1)]

for i in range(1, n + 1):
    v = map(int, lines[i].split())
    V[v[0]] = v[2:]
D = [-1] * (n + 1)
bfs()

for i in range(1, n + 1):
    print i, D[i]

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

int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
        cin >> A[i];

    int res = gcd(A[0], A[1]);
    for (int i = 2; i < N; i++)
        res = gcd(res, A[i]);

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

Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    int n,p,q,x,y,m;
    scanf("%d",&n);
    if (n>=1 && n<=100)
    {


        x=n*800;
        if(n/15 >= 1)
        {
            p=n/15;
            q=p*200;
            y=x-q;
            printf("%d\n",y);
        }
        else
        {
            printf("%d\n",x);
        }
    }
    else

        return 0;
}

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

int n, m;

int parent[N], sz[N];
set<int> con[N];

void make_set(int v) {
    parent[v] = v;
    sz[v] = 1;
    con[v].insert(v);
}

int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (sz[a] < sz[b])
            swap(a, b);
        parent[b] = a;
        sz[a] += sz[b];
        con[a].insert(con[b].begin(), con[b].end());
    }
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
		cin >> a[i];
		make_set(i);
	}
    
    vector<pair<int, int>> pairs(m);
    for (auto& i : pairs) {
		cin >> i.first >> i.second;
		i.first--; i.second--;
		union_sets(i.first, i.second);
	}
    
    int ans = 0;
    for (int i = 0; i < n; i++) {
		int g = find_set(i);
		if (con[g].find(a[i] - 1) != con[g].end()) {
			ans++;
		}
	}
    
    cout << ans;
    return 0;
}


Measured memory_bytes: 39552
from bisect import bisect_right

s = input()
t = input()

n = len(s)

mp = [[] for _ in range(26)]
s += s
for i in range(len(s)):
    mp[ord(s[i]) - ord('a')].append(i)

ans = 0
now = -1
for i in range(len(t)):
    a = ord(t[i]) - ord('a')
    nxt = bisect_right(mp[a], now)
    if len(mp[a]) == nxt:
        print(-1)
        exit()

    ans += mp[a][nxt] - now
    now = mp[a][nxt]
    if now >= n:
        now -= n

print(ans)


Measured memory_bytes: 17928
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			int n = Integer.parseInt(br.readLine());
			
			if( n == 0){
				break;
			}
			
			String str = br.readLine();
			
			for(int i = 0; i < n; i++){
				str = translate(str);
			}
			
			System.out.println(str);
		}
	}
	
	static String translate(String str){
		char current = '\0';
		int count = 0;
		
		StringBuffer sb = new StringBuffer();
		for(int i = 0; i <= str.length() ; i++){
			if(i == str.length()) {
				if(current != '\0'){
					sb.append(count);
					sb.append(current);
				}
				break;
			}
			char c = str.charAt(i);
			
			if(c != current) {
				if(current != '\0'){
					sb.append(count);
					sb.append(current);
				}
				count = 1;
				current = c;
			}
			else if(c == current){
				count++;
			}
			
			//System.out.println("count "+count+" current "+current);
		}
		
		return sb.toString();
	}

}

Measured memory_bytes: 27420
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	std::vector<int> v = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	int x, y;
	std::cin >> x >> y;
	if (v[x] == v[y])
		std::cout << "Yes\n";
	else
		std::cout << "No\n";
}


Measured memory_bytes: 384
//mcxi???1111???mcxi (????????????????¨?????????¨????????????, ??¨????????¨?\????
#include <iostream>
#include <string>
using namespace std;

int pow10[4];

void init() {
	pow10[0] = 1;
	for (int i = 1; i <= 3; i++) pow10[i] = pow10[i - 1] * 10;
}

int Value(char c) {
	if (c == 'm') return 1000;
	if (c == 'c') return 100;
	if (c == 'x') return 10;
	if (c == 'i') return 1;
	return 0;
}

int decode(string s) {
	int ret = 0;
	for (int i = 0; i < s.length(); i++) {
		if (!Value(s[i])) continue;
		
		int val;
		if (i == 0 || Value(s[i - 1]) > 0) val = 1;
		else val = s[i - 1] - '0';
		ret += val * Value(s[i]);
	}
	return ret;
}

string encode(int x) {
	int val[4];
	int i;
	string ret;
	
	for (i = 0; i < 4; i++) val[i] = (x / pow10[i]) % 10;
	for (i = 3; i >= 0; i--) {
		if (val[i] == 0) continue;
		if (val[i] > 1) ret += val[i] + '0';
		ret += "ixcm"[i];
	}
	return ret;
}

int main() {
	int n;
	cin >> n;
	init();
	for (int i = 0; i < n; i++) {
		string s, t;
		cin >> s >> t;
		int a = decode(s);
		int b = decode(t);
		cout << encode(a + b) << endl;
	}
	return 0;
}

Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    //#ifndef ONLINE_JUDGE
    //    freopen("take.in","r",stdin);
    //    freopen("give.out","w",stdout);
    //#endif
    ll n,k;
    cin>>n>>k;
    ll a[n+1];
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    ll winner[k+10];
    winner[k+1]=2;
    for(ll i=k;i>=1;i--)
    {
        bool on=0;
        for(ll j=1;j<=n;j++)
        {
            if(i+a[j]<=k+1 and winner[i+a[j]]==2)
            {
                on=1;
                break;
            }
        }
        if(on) winner[i]=1;
        else winner[i]=2;
    }
    if(winner[1]==1) cout<<"First"<<endl;
    else cout<<"Second"<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n, k;
    cin >> n >> k;
    VI a(n);
    REP(i,n) a[i] = in();
    sort(ALL(a));
    int ans = 1e9 + 10;
    REP(i,n-k+1){
        ans = min(ans, a[i+k-1] - a[i]);
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    long long int k,n;
    cin>>k>>n;
    vector<int>a(n);
    vector<int>b(n);
    for(int i=0;i<n;i++){
       cin>>a.at(i);
    }
    sort(a.begin(),a.end());
    for(int i=0;i<n;i++){

        if(i!=n-1)b.at(i)=a.at(i+1)-a.at(i);
        else b.at(i)=k-a.at(i)+a.at(0);
    }
    sort(b.begin(),b.end());
    long long int c;
    c=k-b.at(n-1);
    cout<<c<<endl;

}

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

int main() {
  int n; cin >> n; vector<ll> a(n); rep(i,n) cin >> a[i];
  vector<string> b(n, "");
  rep(i, 32) {
    int cnt = 0;
    rep(j, n) {
      if (a[j] & 1) cnt++; 
    }
    rep(j,n) {
      if (cnt & 1)
      {
        char c = !(a[j] & 1) + 48;
        b[j] += c;
      }
      else
      {
        char c = (a[j] & 1) + 48;
        b[j] += c;
      }
      a[j] >>= 1;
    }
  }
  vector<ll> ans(n);
  rep(i,n) {
    std::string s = b[i];
    reverse(s.begin(), s.end());
    unsigned long long value = std::bitset<64>(s).to_ullong();
    std::cout << value << std::endl;
    // for (int j=0; j<b[i].size(); j++) {
    //   ans[i] += 
    // }
  }
  return 0;
}

Measured memory_bytes: 28244
#include<stdio.h>

int main(){
  int n = 0;
  char str[100001] = {};
  int i = 0;
  int now = 0;
  
  scanf(" %s",str);
  for(i=0;i<100001;i++){
    if(str[i] == '\0'){
      break;
    }
  }
  n = i;
  //printf("%d",n);
  now = n-1;
  while(now != -1){
    if(now >= 6 && str[now-6] ==  'd' && str[now-5] ==  'r' && str[now-4] ==  'e'
       &&   str[now-3] ==  'a' && str[now-2] ==  'm' && str[now-1] ==  'e' 
       &&   str[now] ==  'r'){
      now -= 7;
      //printf("A");
    }else if(now >= 5  && str[now-5] ==  'e' && str[now-4] ==  'r' 
             && str[now-3] ==  'a' && str[now-2] ==  's' && str[now-1] ==  'e' 
             && str[now] ==  'r' ){
      now -= 6;
      //printf("B");
    }else if(now >= 4  && str[now-4] ==  'e' && str[now-3] ==  'r' 
             && str[now-2] ==  'a' && str[now-1] ==  's' 
             && str[now] ==  'e'){
      //printf("C");
      now -= 5;
    }else if(now >= 4  && str[now-4] ==  'd' && str[now-3] ==  'r' 
             && str[now-2] ==  'e' && str[now-1] ==  'a' 
             && str[now] ==  'm'){
      //printf("D");
      now -= 5;
    }else{
      break;
    }
  }
  if(now == -1){
    printf("YES");
  }else{
    printf("NO");
  }
  return 0;
}
  
  

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

int main(){
	vector<int> a(3);
	cin >> a[0] >> a[1] >> a[2];
	sort(a.begin(), a.end());
	cout << abs(a[1] - a[0]) + abs(a[2] - a[1]) << endl;
}

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

int main() {
  int n;
  cin >> n;
  map<int,int> m;
  rep(i,n){
    int a;
    cin >> a;
    m[a]++;
  }
  int ans = 0;
  for(auto i:m){
    if(i.first>i.second) ans += i.second;
    else ans += i.second-i.first;
  }
  cout << ans << endl;
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll X, Y;
    cin >> X >> Y;
    ll ans = 1;
    X *= 2;
    while(X <= Y)
    {
        ans++;
        X *= 2;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include<complex>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i > 0; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> pr;
typedef complex<double> com;


int main(){
	int a, b, n;
	cin >> a >> b >> n;
	int x1=0, x2=a, y1=0, y2=b;
	rep(i, n) {
		int p1, p2, q;
		cin >> p1 >> p2 >> q;
		if (q == 1) {
			x1 = max(x1, p1);
		}
		if (q == 2){
			x2 = min(x2, p1);
		}
		if (q == 3) {
			y1 = max(y1, p2);
		}
		if (q == 4) {
			y2 = min(y2, p2);
		}
	}
	cout << max(0,x2 - x1)*max(0,y2 - y1);
	return 0;
}
//Ctrl+Aを使わない

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int A,B,C;cin>>A>>B>>C;
    if(A==B && B==C)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
//#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}


inline void solve(){

    int n;
    int l[2005];

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

    sort(l,l+n);

    ll sum = 0;

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < i; j++) {
            int x = lower_bound(l,l+n,l[i]+l[j]) - l;
            sum += max(x-i-1,0);
        }
    }
    
    cout << sum << endl;

}
struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <queue>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<template<class...> class ContT, class ValueT, size_t Dim>
struct vec_type
{
    using type = ContT<typename vec_type<ContT, ValueT, Dim-1>::type>;
};

template<template<class...> class ContT, class ValueT>
struct vec_type<ContT, ValueT, 0>
{
    using type = ValueT;
};

template<class ValueT, size_t Dim = 1>
using vec_t = typename vec_type<std::vector, ValueT, Dim>::type;


template<class ValueT, size_t Dim, class = typename std::enable_if<Dim == 0>::type>
auto make_vec(ValueT value = ValueT()) -> ValueT
{
    return value;
}

template<class ValueT, size_t Dim, class... Rest>
auto make_vec(size_t size0, Rest... rest)
{
    auto vec = make_vec<ValueT, Dim-1>(rest...);
    return std::vector(size0, vec);
}

int diffabs(int l, int r)
{
    if (l < r) return r-l;
    else return l-r;    
}


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

int main()
{
    int N, M;
    cin >> N >> M;
    vvi g(N);
    for (int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }    

    vi H(N, -1);
    queue<int> bq;
    bq.push(0);
    while (bq.size() > 0)
    {
        int n = bq.front();  bq.pop();
        for (int h : g[n])
        {
            if (H[h] < 0)
            {
                H[h] = n;
                bq.push(h);
            }
        }
    }
    
    cout << "Yes" << endl;
    for (int i = 1; i < N; ++i)
    {
        cout << H[i]+1 << endl;
    }
}

Measured memory_bytes: 10216
#168 B
K = int(input())
S = input()

if len(S) <= K:
	print(S)
else:
	print(S[:K] + '...')


#168 A
#n_last = int(list(input())[-1])

#if n_last in [3]:
#	print('bon')
#elif n_last in [0,1,6,8] :
#	print('pon')
#else:
#	print('hon')



Measured memory_bytes: 9144
#include<cstdio>

int main(){
    int count[1199];
    // for(int i = 0; i < 1201; i++){
    //     count[i] = 0;
 	// }
    char ch;
    while(scanf("%c",&ch) != EOF){
        if(ch >= 'a' && ch <= 'z'){
            count[ch - 'a']++;
        }
        else if(ch >= 'A' && ch <= 'Z'){
            count[ch - 'A']++;
        }
    }
    for(int j = 0;j < 26; j++){
        printf("%c : %d\n",j + 'a',count[j]);
    }
    return 0;
}


Measured memory_bytes: 2712
#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define min(a,b) (a<b?a:b)
#define ll long long
//#define file
using namespace std;

struct type{
	char a[6001];
	int n;
	void add(char ch) {a[++n]=ch;}
} ans,s,Ans;
int a[6001][3],c[6001][2],n,i,j,k,l,sum,tot,s1,s2;
char st[6001];
bool bz;

bool pd(type a,type b)
{
	int i;
	
	fo(i,1,min(a.n,b.n))
	if (a.a[a.n-i+1]!=b.a[b.n-i+1])
	return a.a[a.n-i+1]<b.a[b.n-i+1];
	return a.n<b.n;
}

int main()
{
	#ifdef file
	freopen("agc026e.in","r",stdin);
	#endif
	
	scanf("%d",&n);
	scanf("%s",st+1);
	
	fo(i,1,n+n)
	{
		if (!sum)
		{
			++tot;
			a[tot][0]=i;
			a[tot][2]=st[i]=='b';
		}
		sum+=(st[i]=='a')?1:-1;
		if (!sum) a[tot][1]=i;
	}
	
	fd(l,tot,1)
	if (!a[l][2])
	{
		if (!bz)
		{
			s1=s2=0;
			fo(i,a[l][0],a[l][1])
			{
				if (st[i]=='a')
				++s1,c[s1][0]=i;
				else
				++s2,c[s2][1]=i;
			}
			
			k=(a[l][1]-a[l][0]+1)/2,j=0;
			fo(i,1,k)
			if (j<c[i][0])
			ans.add('b'),ans.add('a'),j=c[i][1];
		}
	}
	else
	{
		bz=1;Ans=ans;
		fd(i,(a[l][1]-a[l][0]+1)/2,0)
		{
			s=ans;
			s1=s2=0;
			fd(j,a[l][1],a[l][0])
			{
				if (st[j]=='a')
				{++s1;if (s1<=i) s.add('a');}
				else
				{++s2;if (s2<=i) s.add('b');}
			}
			if (pd(Ans,s)) Ans=s;
		}
		ans=Ans;
	}
	
	fd(i,ans.n,1) putchar(ans.a[i]);
	putchar('\n');
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cout <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cout <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
#define jeb() fflush(stdout);

using namespace std;

int ans[505][505];

int main () {
	make(k);
	if (k == 1) {
		printf("1\n1\n");
		return 0;
	}
	if (k == 2) {
		printf("2\n1 1\n2 2\n");
		return 0;
	}
	int n = (k+1)/2;
	while (n%2 != 0) n++;
	int act = 1;
	FOR(i,0,n) {
		int c1, c2;
		if (2*(n-i) == (k+1-act)) {
			c1 = act;
			c2 = act+1;
			act+=2;
		} else {
			c1 = c2 = act;
			act++;
		}
		int ax = 0, ay = i;
		if (c2 == k+1) c2 = k;
		FOR(j,0,n) {
			int c = c1;
			if (j%2 == 0) c = c2;
			ans[ax][ay] = c;
			ax = (ax+1)%n;
			ay = (ay+1)%n;
		}
	}
	printf("%d\n", n);
	FOR(i,0,n) {
		FOR(j,0,n) {
			printf("%d ", ans[i][j]);
		}
		printf("\n");
	}
}	




Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;constexpr ll INF=1LL<<60,MOD=1e9+7;//998244353;
void solve();int main(){cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();return 0;}
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d>0?i<n:i>n;i+=d)
#define endl "\n"
#ifdef __LOCAL
#include "ostreams.h"
#endif
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> vector<T> make_vector(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_vector(size_t a,Ts... ts){return vector<decltype(make_vector(ts...))>(a,make_vector(ts...));}
void print(){cerr<<endl;} template<class T,class... Ts> void print(const T& a,const Ts&... ts){cerr<<a<<' ';print(ts...);}

void solve(){
    ll x, y; cin >> x >> y;
    cout << (abs(x - y) <= 1 ? "Brown" : "Alice") << endl;
}

Measured memory_bytes: 256
from functools import reduce
from fractions import gcd
from collections import defaultdict
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N = int(input())
    B = list(map(int, input().split()))

    ans = []
    for _ in range(N):
        x = -1
        for j in range(len(B)):
            if B[j] == j + 1:
                x = j
        if x == -1:
            break
        ans.append(B.pop(x))
    
    if len(B) == 0:
        for i in reversed(range(N)):
            print(ans[i])
    else:
        print(-1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 65260
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

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

    int chara_count[30] = {0};
    rep(i, s.size()) chara_count[s[i] - 'a'] ++;

    bool flag = false;
    rep(i, 'z' - 'a' + 1){
        if(chara_count[i] == 0){
            cout << (char)(i + 'a') << endl;
            flag = true;
            break;
        }
    }

    if(!flag) cout << "None" << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define eps 1e-8
#define pi 3.14159265358979
#define LL long long
#define MP make_pair
#define PH push
#define PB push_back
#define PII pair<int,int>
#define VI vector<int>
#define X first
#define Y second
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
#define sqr(x) ((x)*(x))
#define CL(a) memset(a,0,sizeof a)
#define fr(i,n) for(int i=1;i<=n;i++)
#define FR(i,S,n) for(int i=S;i<=n;i++)
#define dr(i,n) for(int i=n;i;i--)
#define DR(i,n,S) for(int i=n;i>=S;i--)
#define SZ(x) ((int)(x).size())
#define rd(x) scanf("%d",&x)
#define pr(x) printf("%d",x)
const int N=1111;
const int M=100000007;
LL Pw(LL a,LL b,LL p){LL v=1;for(;b;b>>=1,a=a*a%p)if(b&1)v=v*a%p;return v;}
using namespace std;
int n,m,A,B;char s[N][N];
int main(){
	rd(n);rd(m);rd(A);rd(B);
	fr(i,n)fr(j,m)s[i][j]='.';
	if((A+B)*2>n*m)return puts("NO"),0;
	if(m&1)fr(i,n-1)if(s[i][m]=='.'&&s[i+1][m]=='.'&&B)s[i][m]='^',s[i+1][m]='v',B--;
	if((n&1)&&(B&1)&&n>1&&m>2)s[n-1][m-2]='^',s[n][m-2]='v',B--;
	fr(i,n-1)fr(j,m)if(s[i][j]=='.'&&s[i+1][j]=='.'&&B)s[i][j]='^',s[i+1][j]='v',B--;
	fr(i,n)fr(j,m-1)if(s[i][j]=='.'&&s[i][j+1]=='.'&&A)s[i][j]='<',s[i][j+1]='>',A--;
	if(A||B)puts("NO");else{
		puts("YES");
		fr(i,n){
			fr(j,m)putchar(s[i][j]);
			puts("");
		}
	}
}

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

#define MAX_N 50000
#define MAX_M 20
#define INF 1000000

int n, m;
int coins[MAX_M];
int t[MAX_N];

int main()
{
	cin >> n >> m;
	for(int i=0; i<m; i++) cin >> coins[i];
	
	for(int i=0; i<=n; i++) t[i]=INF;
	t[0] = 0;

	for(int i=0; i<m; i++)
		for(int j=coins[i]; j<=n; j++)
			t[j] = min(t[j], t[j-coins[i]]+1);

	cout << t[n] << endl;
	
	return 0;
}

Measured memory_bytes: 1356
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  string S; cin >> S;
  int ans = 0;
  REP(i, 1000){
    string s = to_string(i);
    if(s.size() == 1) s = "00" + s;
    if(s.size() == 2) s = "0" + s;
    int k = 0;
    REP(j, N){
      if(S[j] == s[k]){
        k++;
        if(k == 3){
          ans++;
          break; // このbreakはどのループを抜けるのか
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include<stdio.h>

#define INFTY 1000000000

long cnt;

void merge(int A[], int left, int mid, int right){
  int n1,n2,i,j,k;

  n1 = mid - left;
  n2 = right - mid;

  int L[n1], R[n2];

  for(i=0; i<n1; i++) L[i]=A[left+i];
  for(i=0; i<n2; i++) R[i]=A[mid+i];

  L[n1] = INFTY;
  R[n2] = INFTY;

  i=0,j=0;

  for(k=left; k<right; k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    }else{
      A[k] = R[j];
      j++;
			cnt += (n1 - i);
    }
  }
}


void mergeSort(int A[], int left, int right){
  if(left+1 < right){
    int mid = (left+right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main(void){
  int n,i;
  scanf("%d",&n);

  int S[n];
  for(i=0; i<n; i++) scanf("%d", &S[i]);

  mergeSort(S, 0, n);

  printf("%ld\n",cnt);

  return 0;
}



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

int main(){
    int a, b, c;
    cin>>a>>b>>c;
    int count;
    for(int i=a;i<=b;i++){
        if(c%i==0){
            count++;
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 3112
def dfs(s,flag):
    if s>upbd:
        return 0
    ret =1 if flag==7 else 0
    ret+=dfs(s*10+3,flag|1)    
    ret+=dfs(s*10+5,flag|2)
    ret+=dfs(s*10+7,flag|4)
    return ret

upbd=int(input())
print(dfs(0,0))

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

void merge(int *A, int left, int mid, int right, int *count){
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    int *L, *R;
    L = (int *)malloc(sizeof(int) * (n1 + 1));
    R = (int *)malloc(sizeof(int) * (n2 + 1));
    for(i = 0; i < n1; i++){
        L[i] = A[left + i];
    }
    for(i = 0; i < n2; i++){
        R[i] = A[mid + i];
    }
    L[n1] = INT_MAX;
    R[n2] = INT_MAX;
    i = 0;
    j = 0;
    for(k = left; k < right; k++){
        (*count)++;
        if(L[i] <= R[j]){
            A[k] = L[i];
            i++;
        }
        else{
            A[k] = R[j];
            j++;
        }
    }
    free(L);
    free(R);
}

void mergeSort(int *A, int left, int right, int *count){
    int mid;
    if(left + 1 < right){
        mid = (left + right) / 2;
        mergeSort(A, left, mid, count);
        mergeSort(A, mid, right, count);
        merge(A, left, mid, right, count);
    }
}

int main(){
    int n, i, count = 0;
    int *A;
    scanf("%d", &n);
    A = (int *)malloc(sizeof(int) * n);
    for(i = 0; i < n; i++){
        scanf("%d", &A[i]);
    }
    mergeSort(A, 0, n, &count);
    for(i = 0; i < n; i++){
        printf("%d", A[i]);
        if(i != n - 1){
            printf(" ");
        }
    }
    printf("\n%d\n", count);
    free(A);
    return 0;
}


Measured memory_bytes: 5468
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringJoiner;
import java.util.StringTokenizer;
import java.util.function.IntUnaryOperator;
import java.util.function.LongUnaryOperator;

class Main {
    static In in = new In();
    static Out out = new Out();
    static long mod = 1000000007;
    static long inf = 0xfffffffffffffffL;

    void solve() {
        int n = in.nextInt();
        long[][] c = new long[10][10];
        for (int i = 1; i <= n; i++) {
            String t = String.valueOf(i);
            int first = t.charAt(t.length() - 1) - '0';
            int last = t.charAt(0) - '0';
            c[first][last]++;
        }
        long ans = 0;
        for (int i = 1; i < 10; i++) {
            for (int j = 1; j < 10; j++) {
                ans += c[i][j] * c[j][i];
            }
        }
        out.println(ans);
    }

    public static void main(String[]$) {
        new Main().solve();
        out.flush();
    }
}

class In {
    private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 0x10000);
    private StringTokenizer tokenizer;

    String next() {
        try {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
        } catch (IOException ignored) {
        }
        return tokenizer.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    char[][] nextCharArray(int n, int m) {
        char[][] a = new char[n][m];
        for (int i = 0; i < n; i++) {
            a[i] = next().toCharArray();
        }
        return a;
    }

    int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    int[] nextIntArray(int n, IntUnaryOperator op) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsInt(nextInt());
        }
        return a;
    }

    long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextLong();
        }
        return a;
    }

    long[] nextLongArray(int n, LongUnaryOperator op) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsLong(nextLong());
        }
        return a;
    }
}

class Out {
    private static PrintWriter out = new PrintWriter(System.out);

    void println(Object... a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (Object obj : a) {
            joiner.add(String.valueOf(obj));
        }
        out.println(joiner);
    }

    void flush() {
        out.flush();
    }
}


Measured memory_bytes: 32340
#include<set>
#include<map>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int f(multimap<int,string> a,int b,int e){
  int sm=0;
  multimap<int,string>::iterator it=a.begin();
  for(;it!=a.end()&&(*it).first+30<=e;it++){
    if((*it).first>=b+30){
      b=(*it).first;
      sm++;
    }
  }
  return sm;
}
int main(){
  int i;
  int m,n;
  int sm;
  multimap<int,string> a;
  multiset<int> b;
  multiset<int>::iterator it,jt;
  while(cin>>n&&n){
    a.clear();
    for(i=0;i<n;i++){
      int t,u;
      string s;
      cin>>s>>t>>u;
      a.insert(make_pair(u%100+u/100*60+t*1440,s));
    }
    cin>>m;
    b.clear();
    for(i=0;i<m;i++){
      string s;
      cin>>s;
      multimap<int,string>::iterator it=a.begin();
      for(;(*it).second!=s;it++);
      b.insert((*it).first);
    }
    if(m>1){
      it=jt=b.begin();
      jt++;
      for(;jt!=b.end();){
	if(*jt-*it<30)
	  break;
	it++;
	jt++;
      }
      if(jt!=b.end()){
	cout<<-1<<endl;
	continue;
      }
    }
    if(m){
      sm=m;
      it=jt=b.begin();
      jt++;
      sm+=f(a,0,*it);
      for(;jt!=b.end();){
	sm+=f(a,*it,*jt);
	it++;
	jt++;
      }
      sm+=f(a,*it,20000);
    }else{
      sm=m;
      sm+=f(a,0,20000);
    }
    cout<<sm<<endl;    
  }
  return 0;
}

Measured memory_bytes: 984
#include <stdio.h>
#include <math.h>

int main()
{
  int X;
  scanf("%d", &X);
  
  double max = 0.0;
  for(int i=1; i<32; i++)
    for(int j=2; j<10; j++)
    {
      double num = pow(i, j);
      if((long int)num <= X && max <= num)
        max = num;
    }
  
  printf("%d\n", (int)max);
}

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

using namespace std;

#define int long long

void solve() {
    string s;
    cin >> s;
    bool ch1 = 0, ch2 = 0, ch3 = 0;
    string s1 = s;
    reverse(s1.begin(), s1.end());
    if (s == s1) ch1 = 1;
    if (s.substr(0, s.size() / 2) == s1.substr((s.size() + 1) / 2, s.size() / 2)) ch2 = 1;
    if (s1.substr(0, s.size() / 2) == s.substr((s.size() + 1) / 2, s.size() / 2)) ch3 = 1;
    if (ch1 && ch2 && ch3) cout << "Yes";
    else cout << "No";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 256