akhauriyash/Code-Regression huggingface dataset:
N, Q = map(int, input().split())
nodes = [[] for _ in range(2*(10**5)+1)]
for _ in range(N-1):
    a, b = map(int, input().split())
    nodes[a] += [b]

PX = [0 for _ in range(2*(10**5)+1)]
for _ in range(Q):
    p, x = map(int, input().split())
    PX[p] += x


node_cnts = [0] * (2*(10**5)+1)

q = [(1, PX[1])]
while q:
    node, count = q.pop()
    node_cnts[node] = count
    for n in nodes[node]:
        subtree_nodes = q.append((n, count + PX[n]))


print(*node_cnts[1:N+1], sep=' ')


Measured memory_bytes: 57964
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int x;
    cin >> x;
    cout << !x << endl;
}

Measured memory_bytes: 3192
# exec(open('test.py').read()) 
 
N = int(input())
S = input()

ans = 0

if N>2:
	for i in range(N-2):
		if S[i] == 'A'and S[i+1] == 'B' and S[i+2] == 'C':
			i += 3
			ans += 1

print(ans)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

constexpr Int INF = 1e18;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	Int v, e; cin >> v >> e;
	vector<vector<Int>> a(v, vector<Int>(v, INF));
	for(Int i=0; i<e; ++i){
		Int s, t, d; cin >> s >> t >> d;
		a[s][t] = d;
	}
	for(Int i=0; i<v; ++i)
		a[i][i] = 0;
	for(Int k=0; k<v; ++k)
		for(Int i=0; i<v; ++i)
			for(Int j=0; j<v; ++j)
				a[i][j] = min(a[i][j], a[i][k]+a[k][j]);
	for(Int i=0; i<v; ++i)
		if(a[i][i] < 0){
			cout << "NEGATIVE CYCLE\n";
			return 0;
		}
	for(Int i=0; i<v; ++i)
		for(Int j=0; j<v; ++j)
			cout << (a[i][j] > INF / 2 ? "INF" : to_string(a[i][j])) << " \n"[j+1==v];
}


Measured memory_bytes: 3368
import java.util.*;

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

        long n = sc.nextLong();
        List<String> list = new ArrayList<String>();
        for(long i = 0; i < n; i++){
            String s = sc.next();
            char temp[] = s.toCharArray();
            Arrays.sort(temp);
            list.add(new String(temp));
        }
        Collections.sort(list);


        Map<String, Long> map = new HashMap<String, Long>();
        for(String s : list) {
            if(map.containsKey(s)) {
                map.put(s, (map.get(s)+1));
            } else {
                map.put(s, 1L);
            }
        }

        long sum = 0;
        for(long c : map.values()) {
            // System.out.println("c="+c);
            for(long i = c - 1; i > 0; i--) {
                sum += i;
                // System.out.println("sum="+sum);
            }
        }

        // System.out.println(map.toString());
        System.out.println(sum);

    }
}


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

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

	int location = 0;
	bool found = false;
	if(s.size() == 2 && s[0] == s[1]){
		cout << 1 << " " << 2 << endl;	
		return 0;
	} 
	for(int i = 0; i < s.length() - 2; i++){
		if(s[i] == s[i + 1]){
			location = i;
			found = true;
			break;
		}else if(s[i] == s[i + 2]){
			location = i;
			found = true;
		}
	}
	if(s[s.length() - 2] == s[s.length() - 1]){
		found = true;
		location = s.length() - 3;
	}

	if(!found) cout << -1 << " " <<  -1 << endl;
	else cout << location + 1 << " " << location + 3 << endl;

	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#include<vector>
#define EPS (1e-10)
#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0
using namespace std;

class Point
{
public:
  double x,y;
  Point(double x =0,double y=0):x(x),y(y){}
  Point operator + (Point p){return Point(x+p.x,y+p.y); }
  Point operator - (Point p){return Point(x-p.x,y-p.y); }
  Point operator * (double a){return Point(x*a,y*a); }
};

double dot(Point a,Point b)
{
  return a.x*b.x + a.y*b.y;
}

double cross(Point a,Point b)
{
  return a.x*b.y - a.y*b.x;
}

double norm(Point a)
{
  return a.x*a.x+a.y*a.y;
}

int ccw(Point p0,Point p1,Point p2)
{
  Point a = p1-p0;
  Point b = p2-p0;
  if(cross(a,b) > 0)return COUNTER_CLOCKWISE;
  if(cross(a,b) < 0)return CLOCKWISE;
  if(dot(a,b) < 0)return ONLINE_BACK;
  if(norm(a) < norm(b))return ONLINE_FRONT;
  return ON_SEGMENT;
}

bool isIntersect(Point p1,Point p2,Point p3,Point p4)
{
  return (ccw(p1,p2,p3) * ccw(p1,p2,p4) <= 0 &&
          ccw(p3,p4,p1) * ccw(p3,p4,p2) <= 0 );
}

Point getCrossPoint(Point a1,Point a2,Point b1,Point b2)
{
  Point base = b2 - b1;
  double d1 = abs(cross(base,a1-b1));
  double d2 = abs(cross(base,a2-b1));
  double t = d1/(d1+d2);
  return a1+(a2-a1)*t;
}

double getArea(Point p1,Point p2,Point p3)
{
  vector<Point> p;
  p.resize(3);
  p[0] = p1,p[1] = p2,p[2] = p3;
  double sum = 0;
  for(int i=0;i<3;i++)
    sum += cross(p[i],p[(i+1)%3]);
  return fabs(sum)/2.0;
}

int main()
{
  int x1,y1,x2,y2;
  while(cin >> x1 >> y1 >> x2 >> y2,(x1|y1|x2|y2))
    {
      Point a(x1,y1);
      Point b(x2,y2);
      cin >> x1 >> y1 >> x2 >> y2;
      Point c(x1,y1);
      Point d(x2,y2);
      cin >> x1 >> y1 >> x2 >> y2;
      Point e(x1,y1);
      Point f(x2,y2);

      if(!isIntersect(a,b,c,d) || !isIntersect(c,d,e,f) || !isIntersect(e,f,a,b))
	{
	  cout << "kyo" << endl;
	  continue;
	}
      Point c1,c2,c3;
      c1 = getCrossPoint(a,b,c,d);
      c2 = getCrossPoint(c,d,e,f);
      c3 = getCrossPoint(e,f,a,b);
      double area = getArea(c1,c2,c3);

      if(area >= 1900000)
	cout << "dai-kichi" << endl;
      else if(area >= 1000000)
	cout << "chu-kichi" << endl;
      else if(area >= 100000)
	cout << "kichi" << endl;
      else if(area > 0)
	cout << "syo-kichi" << endl;
      else 
	cout << "kyo" << endl;
    }
  return 0;
}

Measured memory_bytes: 1192
# coding: utf-8
N=int(input())
K=int(input())
def operation(x):
  if x<=K/2:
    return x*2
  else:
    return (K-x)*2
    
x=input().split(" ")
sum=0
for i in range(N):
  sum+=int(operation(int(x[i])))
print(sum)



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

int main(void){
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;

    int dx=tx-sx,dy=ty-sy;

    cout << string(dy,'U') << string(dx,'R');
    cout << string(dy,'D') << string(dx,'L');
    cout << 'L' << string(dy+1,'U') << string(dx+1,'R') << 'D';
    cout << 'R' << string(dy+1,'D') << string(dx+1,'L') << 'U' << endl;

    return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int d;
    cin >> d;
    vi c(26);
    rep(i, 26) cin >> c[i];
    vector<vi> s(d, vi(26));
    rep(i, d) rep(j, 26) cin >> s[i][j];
    vi last(26);
    ll sum = 0;
    rep1(i, d) {
        ll cm = 0;
        rep(j, 26) cm += c[j] * (i - last[j]);
        pii m(-INF, -1);
        rep(j, 26) {
            ll sat = s[i-1][j] - cm + c[j] * (i - last[j]);
            m = max(m, {sat, j});
        }
        sum += m.first;
        last[m.second] = i;
        cout << (m.second + 1) << endl;
    }
    return 0;
}


Measured memory_bytes: 3680
from collections import Counter

n = int(input())
A = [input() for _ in range(n)]
A = Counter(A)
maxw = []

v, i = zip(*A.most_common())
wordcnt = i.count(max(i))
for j in range(wordcnt):
    maxw.append(v[j])
maxw.sort()

for k in maxw:
    print(k)


Measured memory_bytes: 57932
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    h,w,k=map(int,input().split())
    S=[input() for _ in range(h)]
    final_ans=10**10
    for row_lis in range(1<<(h-1)):
        lst=[0]*h
        q,ans=0,0
        for r in range(h-1):
            if (row_lis>>r)&1==0:
                lst[r+1]=q
            else:
                q+=1
                lst[r+1]=q
                ans+=1
        data=[0]*h
        for j in range(w):
            for i in range(h):
                data[lst[i]]+=int(S[i][j])
                if data[lst[i]]>k:
                    ans+=1
                    break
            else:
                continue
            data=[0]*h
            for i in range(h):
                data[lst[i]]+=int(S[i][j])
                if data[lst[i]]>k:
                    break
            else:
                continue
            break
        else:
            final_ans=min(final_ans,ans)
    print(final_ans)


if __name__=='__main__':
    main()

Measured memory_bytes: 43228
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,pii> pipii;
typedef long long ll;
typedef pair<ll,ll> pll;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e18;
const ll MOD=1e9+7;
struct edge{
    int to;
    int cost;
};

int main(){
    int H,W,K;cin>>H>>W>>K;K--;
    vector<vector<ll> > DP(H+1,vector<ll>(W,0));
    DP[0][0]=1;
    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            for(int bit=0;bit<(1<<(W-1));++bit){
                bool ok=true;
                for(int k=0;k<W-2;++k){
                    if((bit&(1<<k))&&(bit&(1<<(k+1)))){
                        ok=false;break;
                    }
                }
                if(!ok) continue;
                int nj=j;
                if(bit&(1<<j)) nj=j+1;
                else if(j>0&&(bit&(1<<(j-1)))) nj=j-1;
                DP[i+1][nj]+=DP[i][j];
                DP[i+1][nj]%=MOD;
            }
        }
    }
    cout<<DP[H][K]<<endl;
    return 0;
}

Measured memory_bytes: 3584
i1 = input()
i1 = i1.split()
types = int(i1[0])
select = int(i1[1])

i2 = input()
i2 = [int(n) for n in i2.split()]
i2.sort(reverse=True)

summary = sum(i2)
threshold = summary / (select * 4)
#print("i2=", i2)
#print("summary=", summary)
#print("threshold=", threshold)

if i2[select-1] < threshold :
    print("No")
else:
    print("Yes")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
#define zmrl(x) (int)((x).size())
#define pb push_back
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int x; cin>>x;
    cout << !x;
    return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    ll cnt1 = 0, cnt2 = 0;
    for (int i = 1; i <= n; i++) {
        if (2 * i % k == 0) {
            if (i % k != 0) cnt2++;
            else cnt1++;
        }
    }

    cout << cnt1 * cnt1 * cnt1 + cnt2 * cnt2 * cnt2 << endl;
    return 0;
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, '%d', $n);
$keys = explode(',', 'S,H,C,D');
$card = array(
    'S' => array_fill(0, 13, 0),
    'H' => array_fill(0, 13, 0),
    'C' => array_fill(0, 13, 0),
    'D' => array_fill(0, 13, 0)
);

while (($line = trim(fgets(STDIN)))) {
    sscanf($line, '%s %d', $key, $n);
    $card[$key][$n - 1]++;
}

foreach ($keys as $key) {
    foreach ($card[$key] as $n => $m) {
        if (!$m) {
            printf('%s %d%s', $key, $n + 1, PHP_EOL);
        }
    }
}

Measured memory_bytes: 6652
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(int argc, char **argv)
{
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        int n;
        cin >> n;
        vector<pair<int64_t, int64_t>> a(n);
        for (int i = 0; i < n; i++) {
                cin >> a[i].second >> a[i].first;
        }
        sort(a.begin(), a.end());
        int64_t s = 0;
        for (int i = 0; i < n; i++) {
                s += a[i].second;
                if (s > a[i].first) {
                        cout << "No" << endl;
                        return 0;
                }
        }
        cout << "Yes" << endl;
        return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<pair<ll, ll>> cnt(n);
    vector<vector<ll>> acnt(50, vector<ll>(50, 0));
    rep(i, n) {
        string s;
        cin >> s;
        ll period = -1, tmp = 0;
        rep(j, len(s)) {
            if (s[j] == '.') {
                if (period == -1) period = j;
                continue;
            }
            tmp = tmp * 10 + (s[j] - '0');
        }
        ll rem = (period == -1) ? 9 : (9 - (len(s) - period - 1));
        rep(j, rem) tmp *= 10;
        ll two = 0, fiv = 0;
        while(tmp % 2 == 0) {
            two++;
            tmp /= 2;
        }
        while(tmp % 5 == 0) {
            fiv++;
            tmp /= 5;
        }
        cnt[i] = make_pair(two, fiv);
        acnt[two][fiv]++;
    }
    ll ans = 0;
    rep(i, n) {
        ll two = max(0LL, 18 - cnt[i].first);
        ll fiv = max(0LL, 18 - cnt[i].second);
        reps(j, two, 50) {
            reps(k, fiv, 50) {
                ll mns = ((cnt[i].first == j) && (cnt[i].second == k)) ? -1 : 0;
                ans += acnt[j][k] + mns;
            }
        }
    }
    cout << (ans / 2) << endl;
    return 0;
}


Measured memory_bytes: 6360
#include <stdio.h>
int main(){

  int i,ka,kb;
  char a[101],b[101];

  scanf("%s %s",a,b);

  for(i = 0; a[i] != '\0'; i++) ka=i+1;
  for(i = 0; b[i] != '\0'; i++) kb=i+1;

  if(ka > kb){

    printf("GREATER\n");
    return 0;
  
  }

  if(ka < kb){

    printf("LESS\n");
    return 0;

  }

  for(i = 0; i < ka; i++){

    if(a[i] > b[i]){

      printf("GREATER\n");
      return 0;
      
    }

    if(a[i] < b[i]){
      
      printf("LESS\n");
      return 0;

    }

  }

  printf("EQUAL\n");

  return 0;

}


Measured memory_bytes: 128
#include<iostream>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
char s[105],t[105];
bool cmp(char a,char b)
{
    return a>b;
}
int main()
{
    cin>>s>>t;
    int l1=strlen(s),l2=strlen(t);
    sort(s,s+l1);
    sort(t,t+l2,cmp);
    //cout<<s<<" "<<t<<endl;
    //cout<<t[l2-1]<<" "<<s[0]<<endl;
    if(t[l2-1]>s[0]) cout<<"Yes"<<endl;
    else
    {
        if(strcmp(t,s)>0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Thu Jan  3 21:44:08 2019
//
package main

import (
	"fmt"
)

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func main() {
	var s string
	fmt.Scan(&s)

	minVal := len(s)
	for i := range s {
		if i+1 < len(s) && s[i] != s[i+1] {
			n := max(i+1, len(s)-i-1)
			if n < minVal {
				minVal = n
			}
		}
	}

	fmt.Println(minVal)
}


Measured memory_bytes: 1280
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  int n;
  vector<vector<long>> ve(4);
  long w,w1,ww,maxv=0,v,sum[4][100]={};
  scanf("%d %ld",&n,&w);
  for(int i=0;i<n;i++){
    scanf("%ld %ld",&ww,&v);
    if(i==0)
      w1=ww;
    v*=-1;
    ve[ww-w1].push_back(v);
  }
  for(int i=0;i<4;i++)
    sort(ve[i].begin(),ve[i].end());
  for(int i=0;i<4;i++){
    for(int j=0;j<ve[i].size();j++){
      sum[i][j+1]=sum[i][j]+ve[i][j];
    }
  }
  for(int i=0;i<=ve[0].size();i++)
    for(int j=0;j<=ve[1].size();j++)
      for(int k=0;k<=ve[2].size();k++)
        for(int l=0;l<=ve[3].size();l++)
          if((i*w1)+(j*(w1+1))+(k*(w1+2))+(l*(w1+3))<=w&&maxv>sum[0][i]+sum[1][j]+sum[2][k]+sum[3][l]){
            maxv=sum[0][i]+sum[1][j]+sum[2][k]+sum[3][l];
          }
  printf("%ld\n",-1*maxv);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  ll X; cin >>X;
  for (ll i=0; i<1000; i++){
    ll a5 = i*i*i*i*i;
    for (ll j=0; j<=i; j++){
      ll a5 = i*i*i*i*i;
      ll b5 = j*j*j*j*j;
      if (a5 - b5 == X){
        cout <<i <<" " <<j <<endl;
        return 0;
      }else if (a5 + b5 == X){
        cout <<i <<" " <<-j <<endl;
        return 0;
      }else if (-a5 - b5 == X){
        cout <<-i <<" " <<j <<endl;
        return 0;
      }else if (-a5 + b5 == X){
        cout <<-i <<" " <<-j <<endl;
        return 0;
      }
    }
  }
}

/*
*/

Measured memory_bytes: 3624
n,m=map(int,input().split())
broken=[0]*m
for i in range(m):
  broken[i]=int(input())
broken=set(broken)
  
dp=[0]*(n+1)
dp[0]=1
dp[1]=1 if 1 not in broken else 0

for i in range(2,len(dp)):
  if i in broken:
    dp[i]=0
  else:
    dp[i]=(dp[i-2]+dp[i-1])%1000000007
  
print(dp[-1])


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

public class Main{
    public static void main(String[] args) throws IOException{
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        int count;


        while((count = Integer.parseInt(line = br.readLine())) != 0){
            line = br.readLine();
            StringBuilder result = new StringBuilder();

            for(int i = 0; i < count; i++){
                line = metamorphose(line);
            }

            System.out.println(line);
        }
    }

    private static String metamorphose(String line){
        StringBuilder result = new StringBuilder();
        int count = 1;

        for(int i = 0; i < line.length(); i++){
            char now = line.charAt(i);
            char next = ' ';
            if(i != line.length()-1) next = line.charAt(i+1);
            
            if(i == line.length()-1){
                construct(result,count,now);
                break;
            }

            if(now == next){
                count++;
            }else if(now != next){
                construct(result,count,now);
                count = 1;
            }

        }
        return result.toString();
    }

    private static void construct(StringBuilder result , int count , char now){
                result.append(count); 
                result.append(now);
    }

}

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

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

int main(){
    int N;
    cin >> N;
    vector<int> p(N);
    int count = 0;
    int prev = 0;
    rep(i,N){
        int cur;
        cin >> cur;
        if(cur != i+1){
            count++;
        }
    }

    if(count <=2){
        cout << "YES";
    }else{
        cout << "NO";
    }

}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int[] a = new int[3];
		a[0] = sc.nextInt();
		a[1] = sc.nextInt();
		a[2] = sc.nextInt();
		Arrays.sort(a);
		
		// 計算
		int result = a[2] - a[0];
		
		// 出力
		System.out.println(result);
	}
}


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

template <typename T>
vector<T> dijkstra(vector<Int> ss,vector<vector<pair<Int, T> > > & G,T INF){
  using P = pair<T, Int>;
  Int n=G.size();
  vector<T> d(n,INF);
  vector<Int> b(n,-1);
  priority_queue<P,vector<P>,greater<P> > q;
  for(Int s:ss){
    d[s]=0;
    q.emplace(d[s],s);
  }
  while(!q.empty()){
    P p=q.top();q.pop();
    Int v=p.second;
    if(d[v]<p.first) continue;
    for(auto& e:G[v]){
      Int u=e.first;
      T c=e.second;
      if(d[u]>d[v]+c){
	d[u]=d[v]+c;
	b[u]=v;
	q.emplace(d[u],u);
      }
    }
  }
  return d;
}


template<typename T1,typename T2> void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,m,k;
  cin>>n>>m>>k;
  
  using P = pair<Int, Int>;
  vector<vector<P> > G(n);
  for(Int i=0;i<m;i++){
    Int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    G[a].emplace_back(b,c);
    G[b].emplace_back(a,c);
  }

  vector<Int> ss(k);
  for(Int i=0;i<k;i++) cin>>ss[i],ss[i]--;

  const Int INF = 1e15;
  auto dp=dijkstra(ss,G,INF);

  Int ans=0;
  for(Int v=0;v<n;v++){
    chmax(ans,dp[v]);
    for(auto e:G[v]){
      Int u,c;
      tie(u,c)=e;
      chmax(ans,(dp[v]+dp[u]+c+1)/2);
    }
  }
  
  cout<<ans<<endl;
  return 0;
}



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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	string S;
	cin >> S;
	vector<ll> a(4, 0);
	REP(i, S.size()){
		if(S[i]=='N') a[0]++;
		if(S[i]=='S') a[1]++;
		if(S[i]=='E') a[2]++;
		if(S[i]=='W') a[3]++;
	}
	bool flag = true;
	if(a[0]==0&&a[1]!=0) flag = false;
	if(a[0]!=0&&a[1]==0) flag = false;
	if(a[2]==0&&a[3]!=0) flag = false;
	if(a[2]!=0&&a[3]==0) flag = false;
	cout << (flag?"Yes":"No") << endl;
    return 0;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
map<long long, long long> kouho;
vector<long long> sosuu;
long long gogo[1000000];
long long sol(long long now) {
	long long ans = 1;
	for (int i = 0; i < sosuu.size(); ++i) {
		if (now % sosuu[i] == 0) {
			if (now % (sosuu[i] * sosuu[i]) == 0) {
				ans *= sosuu[i];
				if (ans > 1e11) {
					return ans;
				}
				now /= (sosuu[i] * sosuu[i]);
			}
			else {
				ans *= sosuu[i];
				if (ans > 1e11) {
					return ans;
				}
				ans *= sosuu[i];
				if (ans > 1e11) {
					return ans;
				}
				now /= sosuu[i];
			}
			i--;
		}
	}
	long long geko = sqrt(now);
	if (geko * geko == now) {
		if (gogo[geko] == 0) {
			//prime number
			if (ans > 1e18 / geko) {
				return 1e18;
			}
			return ans * geko;
		}
	}
	if (ans > 1e18 / now) {
		return 1e18;
	}
	ans *= now;
	if (ans > 1e18 / now) {
		return 1e18;
	}
	ans *= now;
	return ans;
}
int main() {
	for (long long i = 2; i < 1000000; ++i) {
		if (gogo[i] == 0) {
			if (i < 10000) {
				sosuu.push_back(i);
			}
			for (long long q = 2; i * q < 10000; ++q) {
				gogo[i * q] = 1;
			}
		}
	}
	long long n;
	cin >> n;
	long long ans = 0;
	REP(i, n) {
		long long a;
		cin >> a;
		for (long long q = 0; q < sosuu.size(); ++q) {
			long long geko = sosuu[q] * sosuu[q] * sosuu[q];
			if (geko > a) {
				break;
			}
			if (a % geko == 0) {
				a /= geko;
				q--;
			}
		}
		if (a == 1) ans = 1;
		else kouho[a]++;
	}
	for (auto i = kouho.begin(); i != kouho.end(); ++i) {
		long long nya = sol(i->first);
		if (kouho.find(nya) == kouho.end()) {
			ans += i->second;
			i->second = 0;
			continue;
		}
		ans += max(i->second, kouho[nya]);
		kouho[nya] = 0;
		i->second = 0;
 	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8576
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int n;
vector<string> a;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    map<string, int> m;
    int maxa = 0;
    for (int i = 0; i < n; i++)
    {
        string temp;
        cin >> temp;
        a.push_back(temp);
        m[temp]++;
        chmax(maxa, m[temp]);
    }
    vector<string> ans;
    for (auto x : m)
    {
        if (x.second == maxa)
        {
            ans.push_back(x.first);
        }
    }
    sort(ALL(ans));
    for (int i = 0; i < ans.size(); i++)
        cout << ans[i] << "\n";
}


Measured memory_bytes: 27120
#include<bits/stdc++.h>
using namespace std;
using int64 = long long;
const int mod = 1e9 + 7;
const long long INF = 1e18;
#define PI 3.141592653589793
  int main()
{
  
  int W=0,A,B,C,D;
  cin>>W;
  D=W%10;W/=10;
  C=W%10;W/=10;
  B=W%10;W/=10;
  A=W%10;
  for(int i=0; i<2; i++){
    for(int j=0; j<2; j++){
      for(int k=0; k<2; k++){
        W=A;
        if(i==0)W=A-B;
        else W=A+B;
        if(j==0)W=W-C;
        else W=W+C;
        if(k==0) W=W-D;
        else W=W+D;
        if(W==7){
          cout<<A<<(i==0?"-":"+")
          <<B<<(j==0?"-":"+")
          <<C<<(k==0?"-":"+")
          <<D
          <<"=7";
          return 0;
        }
      }
    }
  }
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000

using namespace std;
int main() {
	string a, b;
	cin >> a>> b;
	string ans;
	if (a.length() > b.length())ans = "GREATER";
	else if (a.length() < b.length())ans = "LESS";
	else rep(i, a.length()) {
		if ((int)a[i] > (int)b[i]) {
			ans = "GREATER";
			break;
		}
		if ((int)a[i] < (int)b[i]) {
			ans = "LESS";
			break;
		}
		ans = "EQUAL";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
a, b, c, x = [int(input()) for i in range(4)]

count = 0

for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      sum = 500 * i + 100 * j + 50 * k
      if sum == x :
        count += 1
print(count)

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;  cin >> s >> t;
    vector<int> p(26), q(26);
    rep(i, s.size()) {
      p[s[i] - 'a']++;
    }
    rep(i, t.size()) {
      q[t[i] - 'a']++;
    }
    sort(p.begin(), p.end());
    sort(q.begin(), q.end());
    rep(i, 26) {
      if (p[i] != q[i]) {
        cout << "No" << '\n';
        return 0;
      }
    }
    cout << "Yes" << '\n';

    return 0;
}


Measured memory_bytes: 916
#include <iostream>

using namespace std;

int main() {
    int a, b, n;
    while (cin >> a >> b >> n) {
        a %= b;
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += (a * 10) / b;
            a = (a * 10) % b;
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 0
def cumsum(l):
    c = [0] * len(l)
    for i in range(len(l)):
        c[i] = c[i-1] + l[i]
    return c

N, K = map(int, input().split())
a = [int(i) for i in input().split()]
c = [0] + cumsum(a)
s = [bin(c[j+i] - c[j]).replace('0b','').zfill(40) for i in range(1, N+1) for j in range(N-i+1)]
ans = 0

for i in range(40):
    t = [j for j in s if j[i] == '1']
    if len(t) >= K:
        ans += 2**(39-i)
        s = t
print(ans)

Measured memory_bytes: 55720
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int n; 
ll a[200100];
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	cin>>n;
	rep(i,n)cin>>a[i];
	ll res=a[0];
	forn(i,1,n-1)res^=a[i];
	rep(i,n)
	{
		ll b=res^a[i];
		cout<<b<<" ";
	 } 
	return 0;
}



Measured memory_bytes: 5192
import sys

n, k = map(int, sys.stdin.readline().split())
r, s, p = map(int, sys.stdin.readline().split())
t = sys.stdin.readline().rstrip()
point = dict([('r', r), ('s', s), ('p', p)])

def hand(opponent):
    if opponent == 'r':
        return 'p'
    elif opponent == 's':
        return 'r'
    elif opponent == 'p':
        return 's'

def main():
    res = 0
    for i in range(k):
        cur = hand(t[i])
        res += point[cur]
        prev = cur
        for j in range(i+k, n, k):
            cur = hand(t[j])
            if cur == prev:
                cur = 'any'
            else:
                res += point[cur]
            prev = cur
    return res

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yay(n) cho(n,"Yay!",":(")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
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(a>b){a=b;return 1;}return 0;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<(ostream&o,const T&t){return o<<t;}
template<class T>istream&operator>(istream&i,T&t){return i>>t;}
#ifndef LOCAL
struct ostdmy{
template<class T>ostdmy&operator<<(const T&t){return*this;}
template<class T>ostdmy&operator<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int a,b,c,d,e,k;
    cin>a>b>c>d>e>k;
    Yay(e-a<=k);
    return 0;
}


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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  cout << ((b % a == 0) ? a + b : b - a ) << '\n';
  return 0;
}


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

using namespace std;

typedef long long ll;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector <int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }    
    map <int, int> cnt_a, cnt_b;
    for (int i = 0; i < n; i += 2) {
        cnt_a[a[i]]++;
        cnt_b[a[i + 1]]++;
    }
    vector <pair <int, int> > x, y;
    vector <bool> vis_a(1e6, false), vis_b(1e5, false);
    for (int i = 0; i < n; i += 2) {
        if (!vis_a[a[i]]) {
            x.push_back({n / 2 - cnt_a[a[i]], a[i]});
            vis_a[a[i]] = true;
        }
        if (!vis_b[a[i + 1]]) {
            y.push_back({n / 2 - cnt_b[a[i + 1]], a[i + 1]});
            vis_b[a[i + 1]] = true;
        }
    }
    x.push_back({n / 2, 1e6});
    y.push_back({n / 2, 1e6});
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    if (x[0].second != y[0].second) {
        cout << x[0].first + y[0].first << '\n';
    } else {
            cout << min(x[0].first + y[1].first, x[1].first + y[0].first);
    }
    return 0;
}

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

int main(){
    int N;
    string S;
    cin >> N >> S;

    for(int i = 0; i < S.size(); i++){
        int A = (int)S.at(i) + N;
        if(A > 90){
            A -= 26;
        }
        cout << (char)A;
    }
    cout << endl;
}

Measured memory_bytes: 3492
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Word
import qualified Data.ByteString as BSW
import qualified Data.ByteString.Char8 as BS
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as U

-- Input: s t
-- Output: arr
--   arr ! (i,j) == length of lcs of (drop i s, drop j t)
--   (arr ! i) ! j == length of lcs of (drop i s, drop j t)
lcsTableV :: BS.ByteString -> BS.ByteString -> V.Vector (U.Vector Word16)
lcsTableV s t = V.scanr' (\ !x !v ->
                            U.scanr (\(!y,!w,!u) !l -> if x == y
                                                         then u + 1
                                                         else max w l
                                     ) 0 (U.zip3 t' (U.init v) (U.tail v))
                         ) (U.replicate (n+1) 0) (V.fromListN m $ BSW.unpack s)
  where !m = BS.length s
        !n = BS.length t
        !t' = U.fromListN n (BSW.unpack t)

lcsTable2 :: BS.ByteString -> BS.ByteString -> UArray (Int,Int) Word16
lcsTable2 s t = runSTUArray $ do
  let !m = BS.length s
      !n = BS.length t
  arr <- newArray ((0,0),(m,n)) 0
  forM_ [m-1,m-2..0] $ \ !i -> do
    let !x = BSW.index s i
        loopY !j !v
          -- v = readArray arr (i,j+1)
          | j >= 0 = do
              let !y = BSW.index t j
              if x == y
                then do l2 <- readArray arr (i+1,j+1)
                        let !l = l2 + 1
                        writeArray arr (i,j) l
                        loopY (j-1) l
                else do l0 <- readArray arr (i+1,j)
                        let !l = max l0 v
                        writeArray arr (i,j) l
                        loopY (j-1) l
          | otherwise = return ()
    loopY (n-1) 0
  return arr

main = do
  s <- BS.getLine
  t <- BS.getLine
  -- BS.length s <= 3000, BS.length t <= 3000, BS.all isAsciiLower s, BS.all isAsciiLower t
  let !table = lcsTableV s t
      !m = BS.length s
      !n = BS.length t
  let recon !i !j | i >= m || j >= n = Nothing
                  | x == y = let !i' = i+1 ; !j' = j+1
                             in Just (x, (i', j'))
                  | (table V.! (i+1)) U.! j >= (table V.! i) U.! (j+1) = recon (i+1) j
                  | otherwise = recon i (j+1)
        where x = BSW.index s i
              y = BSW.index t j
      (result, _) = BSW.unfoldrN (fromIntegral $ (table V.! 0) U.! 0) (\(!i,!j) -> recon i j) (0,0)
  BS.putStrLn result


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

using namespace std;

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

#define MP make_pair
#define F first
#define S second

enum { INQ, SIT, LEAVE };
int now; bool fiveempty, twoempty;
int ans[100], seats[17];
map<int, deque<pair<int, int> > > mp;
inline int num(int i) {return i%5==1?5:2;}
inline int eattime(int i) {return 17*(i%2)+3*(i%3)+19;}

void update_emptyseats() {
  bool fe = 0, te = 0;
  rep(i, 13)
    if(seats[i]==-1 &&
       seats[i+1]==-1 &&
       seats[i+2]==-1 &&
       seats[i+3]==-1 &&
       seats[i+4]==-1) { fe = 1; }
  rep(i, 16)
    if(seats[i]==-1 && seats[i+1]==-1) { te = 1; }
  fiveempty = fe, twoempty = te;
}

void sit(int id) {
  ans[id] = now-5*id;
  mp[now+eattime(id)].push_front(MP(id, (int)LEAVE));
  
  if(num(id) == 5) rep(i, 13)
                     if(seats[i]==-1 &&
                        seats[i+1]==-1 &&
                        seats[i+2]==-1 &&
                        seats[i+3]==-1 &&
                        seats[i+4]==-1) {
                       rep(j, 5) seats[i+j] = id;
                       update_emptyseats(); return;
                     }
  
  if(num(id) == 2) rep(i, 16)
                     if(seats[i]==-1 && seats[i+1]==-1) {
                       rep(j, 2) seats[i+j] = id;
                       update_emptyseats(); return;
                     } 
}

void leave(int id) {
  rep(i, 17) {
    if(seats[i] == id) {
      rep(j, num(id)) { seats[i+j] = -1; }
      update_emptyseats();
      return;
    }
  }
}

int main() {
  
  rep(i, 100) mp[5*i].push_back(MP(i, (int)INQ));
  queue<int> waitingQ;
  fiveempty = twoempty = 1;
  memset(seats, -1, sizeof seats);
  while(!mp.empty()) {
    now = mp.begin()->F;
    deque<pair<int, int> >& Q = mp.begin()->S;
    int id = Q.front().F;
    int act = Q.front().S; Q.pop_front();
    if(act == SIT) {
      sit(id);
      if( !waitingQ.empty()
          && ( (num(waitingQ.front()) == 5 && fiveempty)
               || (num(waitingQ.front()) == 2 && twoempty) )
      ) {
        Q.push_front(MP(waitingQ.front(), (int)SIT));
        waitingQ.pop();
      }
    }
    else if(act == INQ) {
      if(!waitingQ.empty()) { waitingQ.push(id); }
      else if(num(id) == 5 && fiveempty) { sit(id); }
      else if(num(id) == 2 && twoempty) { sit(id); }
      else { waitingQ.push(id); }
    }
    else if(act == LEAVE) {
      leave(id);
      if( !waitingQ.empty()
          && ( (num(waitingQ.front()) == 5 && fiveempty)
               || (num(waitingQ.front()) == 2 && twoempty) )
      ) { Q.push_front(MP(waitingQ.front(), (int)SIT)); waitingQ.pop(); }
    }
    if(Q.empty()) mp.erase(mp.begin());
  }
  for(int N; cin >> N;) cout << ans[N] << endl;
  
  return 0;
}

Measured memory_bytes: 1272
n=int(input())
s=input()
if n%2==1:
    print("No")
    exit()
a=s[0:len(s)//2] 
b=s[len(s)//2 if len(s)%2 == 0 else ((len(s)//2)+1):]

if a.__eq__(b):
    print("Yes")
    exit()
else:
    print("No")

Measured memory_bytes: 8952
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(v) (v).begin(), (v).end()

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

  if (s.size() < t.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  int substring_i = -1;
  for (int i = 0; i <= s.size()-t.size(); ++i) {
    string ss = s.substr(i, t.size());

    bool is_match = true;
    for (int j = 0; j < ss.size(); ++j) {
      if (ss[j] == '?') continue;
      else if (ss[j] != t[j]) is_match = false;
    }
    if (!is_match) continue;

    substring_i = i;
  }

  if (substring_i == -1) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  s.replace(s.begin()+substring_i, s.begin()+substring_i+t.size(), t);
  replace(ALL(s), '?', 'a');
  cout << s << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define scl(x) scanf("%lld",x);
int n,m,i,c[100005],a,b,v,k,t[100005];
set<int> g[100005];
vector<int>first_half;
vector<int>second_half;
vector<int>total;
int par[209],group[209];
int arra[150000];
vector<int>arr;
map<char,int>cp;
map<ll,ll>mp;
deque<char>stp1;
deque<char>stp2;
map<int,int>pos;
map<string,int>check;
map<string,string>server;
vector<string>ans1;
vector<string>ans2;
vector<string>ans3;
string server1[1009];
string ip1[1009];
string server2[1009];
string ip2[1009];
ll cashier[109];
ll fir[10009];
ll sec[100009];
ll dice[109];
vector<ll>element;
map<ll,ll>skysc;
map<string,ll>iteams;
map<ll,ll>equal1;
map<ll,ll>equalcnt;
ll complete[200009][29];
map<ll,ll>vis_pos;
map<char,ll>haiku;
vector<string>original;
vector<string>sorted;
vector<char>stps;
map<string,ll>mps;
map<string,ll>cnteql;
map<string,ll>eql;
deque<char>tem;
map<string,ll>tot;
map<string,ll>vislr;
vector<ll>arry;
vector<ll>colr;
vector<ll>primes;
vector<ll>primesdiv;
map<ll,ll>summand;
map<ll,ll>vps;
map<ll,ll>cnt;
ll solve[200009][4];
int main()
{
  ll a=4,b=0,c,d,e,f,g,h=2,i,j,k,l,p,q,r=10,s,t,m,n,sum=0,x;
  string str;
  cin>>str;
  d=str.size();
  if(str[d-1]=='3')
    cout<<"bon"<<'\n';
   else if(str[d-1]=='2'||str[d-1]=='4'||str[d-1]=='5'||str[d-1]=='7'||str[d-1]=='9')
    cout<<"hon"<<'\n';
    else
    cout<<"pon"<<'\n'; 
  
  
  
   
   
  
     
     	
  	
}

Measured memory_bytes: 8472