akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
int dp[500001][4]; // 0 のこってない。1ひとつのこっている。2 -1個のこっている。3まるまるのこっている
const int INF = 1e9;

int main(){
    
    int N;
    cin >> N;
    int S[500000];
    for(int i = 0; i < N; i++){
        char c;
        cin >> c;
        S[i] = c - '0';
    }
    vector<int> v;
    int ans = 0;
    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(S[i] == 1) cnt++;
        if(i == 0) continue;
        if((S[i-1] == 0 && S[i] == 0) || i == N-1){
            if(i == N-1 && cnt != 0) v.push_back(cnt);
            if(v.size() > 1){ 
                if(v[1] == 1){
                    dp[1][0] = v[0];
                    dp[1][1] = 0;
                    dp[1][2] = -INF;
                    dp[1][3] = 0;
                }else{
                    dp[1][0] = v[1];
                    dp[1][1] = v[1]-1;
                    dp[1][2] = v[0];
                    dp[1][3] = 0;
                }
                for(int j = 2; j < v.size(); j++){
                    if(v[j] == 1){
                        dp[j][0] = max({dp[j-1][1]+1,   dp[j-1][2]+v[j-1]-1,    dp[j-1][3]+v[j-1]});
                        dp[j][1] = max({dp[j-1][0],     dp[j-1][1],             dp[j-1][2],         dp[j-1][3]});
                        dp[j][2] = -INF;
                        dp[j][3] = max({dp[j-1][0], dp[j-1][1], dp[j-1][2], dp[j-1][3]});
                    }else{
                        dp[j][0] = max({dp[j-1][1]+v[j],    dp[j-1][2]+v[j],        dp[j-1][3]+v[j]});
                        dp[j][1] = max({dp[j-1][1]+v[j]-1,  dp[j-1][2]+v[j]-1,      dp[j-1][3]+v[j]-1});
                        dp[j][2] = max({dp[j-1][1]+1,       dp[j-1][2]+v[j-1]-1,    dp[j-1][3]+v[j-1]});
                        dp[j][3] = max({dp[j-1][0],         dp[j-1][1],             dp[j-1][2],             dp[j-1][3]});
                    }
                }
                int s = v.size();
                ans += max({dp[s-1][0], dp[s-1][1], dp[s-1][2], dp[s-1][3]});
            }   
            v.clear();
        }
        if(S[i-1] == 1 && S[i] == 0){
            v.push_back(cnt);
            cnt = 0;
        }
    }
    cout << ans << endl;
}

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

int degree[110];

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

	int ans=0,tmp;
	rep(i,n){
		cout << "lst " << i << endl << flush;
		cin >> degree[i];
		rep(loop,degree[i]) cin >> tmp;
		ans+=degree[i]*(degree[i]-1);
	}

	cout << "ans " << ans << endl << flush;
	return 0;
}

Measured memory_bytes: 3108
import sys
rr = lambda: sys.stdin.readline().strip()
rri = lambda: int(rr())
rrs = lambda: [int(_) for _ in rr().split()]

N, A_, B_, C_, D_ = rrs()
A, B, C, D = [i-1 for i in [A_, B_, C_, D_]]
S = rr()

for i in range(A, max(C, D)):
	if S[i] == '#' and S[i+1] == '#':
		print('No')
		sys.exit()

if C < D:
	print('Yes')
	sys.exit()

if S[B-1] == '.' and S[B+1] == '.':
	print('Yes')
	sys.exit()

if S[B+1] == '.' and S[B+2] == '.':
	print('Yes')
	sys.exit()
	
for i in range(B, D-1):
	if S[i] == '#':
		if S[i+1] == '.' and S[i+2] == '.' and S[i+3] == '.':
			print('Yes')
			sys.exit()

print('No')
sys.exit()

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

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> b(M);
  for (int i = 0; i < M; i++) cin >> b[i];
  vector<vector<int>> a(N, vector<int>(M));
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++) cin >> a[i][j];

  int ans = 0;
  for (int i = 0; i < N; i++) {
    int n = C;
    for (int j = 0; j < M; j++)
      n += a[i][j] * b[j];
    if (0 < n) ans++;
  }
  cout << ans << endl;
}


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

#include <boost/range/adaptors.hpp>
#include <boost/range/combine.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t n;
    cin >> n;

    cout << (1000 - n % 1000) % 1000 << endl;
}

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

const int MAXW = 31;
const int MAXH = 31;
const int INF = 1<<28;
int W, H;
int G[MAXH][MAXW];
int C[4];

struct State {
  int i, j, d, cost;
  bool operator < (const State &s) const {
    return cost > s.cost;
  }
};

int bfs() {
  static int di[] = {0,1,0,-1};
  static int dj[] = {1,0,-1,0};
  priority_queue<State> que;
  int cost[MAXH][MAXW][4];
  que.push((State){0,0,0});
  fill(cost[0][0], cost[MAXH][0], INF);
  cost[0][0][0] = 0;
  while(!que.empty()) {
    const State s = que.top();
    que.pop();
    if(cost[s.i][s.j][s.d] < s.cost) continue;
    if(s.i == H-1 && s.j == W-1) return s.cost;
    for(int k = 0; k < 4; ++k) {
      State t = s;
      t.cost += ( G[s.i][s.j] == k ? 0 : C[k] );
      t.d = (t.d + k) % 4;
      t.i += di[t.d];
      t.j += dj[t.d];
      if(t.i < 0 || t.i >= H) continue;
      if(t.j < 0 || t.j >= W) continue;
      if(cost[t.i][t.j][t.d] > t.cost) {
        que.push(t);
        cost[t.i][t.j][t.d] = t.cost;
      }
    }
  }
  return INF;
}

int main() {
  while(cin >> W >> H && (W|H)) {
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        cin >> G[i][j];
      }
    }
    for(int i = 0; i < 4; ++i) cin >> C[i];
    cout << bfs() << endl;
  }
  return 0;
}

Measured memory_bytes: 1344
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    vvi ret(H, vi(W, 0));
    vvi sub(h, vi(w, 0));
    sub[0][0]         = h * w * 500 - 1;
    sub[h - 1][w - 1] = -h * w * 500;
    int sum           = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            ret[i][j] = sub[i % h][j % w];
            sum += ret[i][j];
        }
    }
    if (sum > 0) {
        cout << "Yes"
             << "\n";
        for (int i = 0; i < H; ++i) {
            print(ret[i]);
        }
    } else {
        cout << "No"
             << "\n";
    }
    return 0;
}

Measured memory_bytes: 2688
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var ABM = ReadLongArray();
            var As = ReadLongArray();
            var Bs = ReadLongArray();
            long ret = As.Min() + Bs.Min();
            for (int i = 0; i < ABM[2]; i++)
            {
                var xyc = ReadIntArray();
                ret =  Math.Min(As[xyc[0] - 1] + Bs[xyc[1] - 1] - xyc[2],ret);
            }

            Console.WriteLine(ret);
        }
        private static readonly Func<string> Read = () => Console.ReadLine();
        private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split();
        private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine());
        private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine());
        private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
        private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
        private static readonly Action<string> Cw = str => Console.WriteLine(str);
    }
}

Measured memory_bytes: 37724
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
using namespace std;

/* debug macros */
#ifdef WAFDAYO
#define DBG_PRINT(s, t, u) { std::cerr << s << " \e[2m=\e[m \e[1m" << t << "\e[m" << u; }
#else
#define DBG_PRINT(s, t, u) {}
#endif
#define dbg(x) DBG_PRINT(#x, x, std::endl)
#define dbgc(x) DBG_PRINT(#x, x, ", ")
#define idbg(x, i) DBG_PRINT(#x "[" << i << "]", x[i], std::endl)
#define idbgc(x, i) DBG_PRINT(#x "[" << i << "]", x[i], ", ")

/* IO utilities */
struct read_item { read_item() {}; template<class T> operator T() { T t; std::cin >> t; return t; } };

/* types and constants */
typedef long long i64;
const i64 inf = (i64)1.05e18;
// const int inf = (int)1.05e9;

int main() {

	const int n = read_item();
	const int k = read_item();
	const i64 s = read_item();

	vector<i64> ans;

	if(s > n - k) {
		for(int i = 0; i < k; i++) {
			ans.push_back(s);
		}
		for(int i = k; i < n; i++) {
			ans.push_back(1);
		}
	} else {
		for(int i = 0; i < s + k - 1; i++) {
			ans.push_back(1);
		}
		for(int i = s + k - 1; i < n; i++) {
			ans.push_back(s + 1);
		}
	}

	for(int i = 0; i < n; i++) {
		printf("%lld%c", ans[i], i == n - 1 ? '\n' : ' ');
	}

	return 0;
}

/* wafdayo~~~ */


Measured memory_bytes: 2164
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
using namespace std;
typedef long long  ll;


/** Problem0208 : Room Numbers of a Hospital **/
int main()
{
	string list="01235789";
	int n;
	while (cin >> n, n) {
		string ans;
		while (1) {
			ans+=(n%8)+'0';
			n/=8;
			if (n == 0) break;
		}
		reverse(ans.begin(), ans.end());
		rep(i, ans.length()) {
			cout << list[ans[i]-'0'];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
n, m = gets.split.map(&:to_i)
array = []
m.times { array << gets.split.map(&:to_i) }

max = 0
if n == 1
  array_n = (0..9).to_a
elsif n == 2
  array_n = (10..99).to_a
else
  array_n = (100..999).to_a
end

ans = []
array_n.each do |num|
  num_s = num.to_s
  flag = true
  array.each do |digit, n|
    if num_s[digit - 1].to_i != n
      flag = false
    end
  end
  ans << num if flag
end

puts ans.empty? ? -1 : ans.min


Measured memory_bytes: 1788
import bisect
#####segfunc######                                                              
def segfunc(x,y):
    return x+y

def init(init_val):
    #set_val                                                                    
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built                                                                      
    for i in range(num-2,-1,-1):
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2])
    
def update(k,x):
    k+=num-1
    seg[k]=x
    while k+1:
        k=(k-1)//2
        seg[k]=segfunc(seg[k*2+1],seg[k*2+2])

def query(p,q):
    if q<=p:
        return ide_ele
    p+=num-1
    q+=num-2
    res=ide_ele
    while q-p>1:
        if p&1==0:
            res=segfunc(res,seg[p])
        if q&1==1:
            res=segfunc(res,seg[q])
            q-=1
        p=p//2
        q=(q-1)//2
    if p==q:
        res=segfunc(res,seg[p])
    else:
        res=segfunc(segfunc(res,seg[p]),seg[q])
    return res

ide_ele=0
n,k=map(int,input().split())
num=2**(n).bit_length()
seg=[ide_ele]*2*num
a=[]
for i in range(n):
    p=int(input())
    a.append(p-k)
d=[0]
for i in range(n):
    d.append(d[-1]+a[i])
b=sorted(d)
a=[]
for i in d:
    p=bisect.bisect_left(b,i)
    a.append(p)
#init(p)
ans=0
a.reverse()
update(a[0],1)
for i in range(n):
    ans+=query(a[i+1],1+n)
    update(a[i+1],query(a[i+1],a[i+1]+1)+1)
print(ans)
#query(0,i)

exit()


Measured memory_bytes: 86996
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <utility>
#include <cstdlib>
#include <cmath>
#define INF 987654321
#define INT_MAX 2147483647
#define MIN(a, b) ((a) < (b) ? a : b)
#define MAX(a, b) ((a) > (b) ? a : b)

using namespace std;



int main() {
    
    long int N, D;

    cin >> N >> D;
    long int x, y;
    long int cnt = 0;
    for(int i = 0; i < N; i++) {
        cin >> x >> y;
        if(x*x + y*y <= D*D) cnt++;
        x = 0; y = 0;
    }
    cout << cnt;

}


Measured memory_bytes: 3164
l = list(map(int, input().split()))

total = 0
sum = 0
for i in range(1, l[0] + 1):
  sum = 0
  n = i
  while i > 0:
    sum += i % 10
    i //= 10
  if sum >= l[1] and sum <= l[2]:
    total += n

print(total)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.12f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 1010101;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// mod.m での a の逆元 a^ { -1 } を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x /gcd(x, y) * y );
}

//union-find木について
ll par[101010];
ll rank2[101010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 0;
	}
}

ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(ll x, ll y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rank2[x] < rank2[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rank2[x] == rank2[y]) {
			rank2[x]++;
		}
	}
}


ll dx[8] = { 1,-1,0,0,1,1,-1,-1 };
ll dy[8] = { 0,0,1,-1,1,-1,1,-1 };
char c[2010][2010];
ll sum[2010][2010];
vector<vector<ll>>to, cost;
ll dist[101010];
bool flag[101010];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	vector<string>s(n);
	vector<ll>a(n);
	map<string, ll>mp;
	rep(i, n) {
		cin >> s[i] >> a[i];
		mp[s[i]]++;
	}
	for (auto p : mp) {
		vector<pair<ll, ll>>ans;
		rep(i, n) {
			if (p.first == s[i])ans.push_back(make_pair(a[i], i + 1));
		}
		sort(ans.rbegin(), ans.rend());
		rep(i, ans.size()) {
			cout << ans[i].second << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3600
#include <stdio.h>
#include <stdlib.h>
int compare_int(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}
int main(void){
  int n, a[100000] = {0};
  scanf("%d", &n);getchar();
  for(int i = 0; i < n; i++){
    scanf("%d", &a[i]);getchar();
  }
  qsort(a, n, sizeof(int), compare_int);
  while(n > 1){
    for(int i = 1; i < n; i++){
      a[i] %= a[0];
      if(a[i] == 0){
        a[i] = a[n - 1];
        a[n - 1] = 0;
        n--;
        i--;
      }
    }
    qsort(a, n, sizeof(int), compare_int);
  }
  printf("%d\n", a[0]);
  return 0;
}

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

typedef long long ll;
ll vis[10000005]={0};
void prime(){
	vis[1]=1;
	for(ll i=2;i<=10000000;i++){
		for(ll j=2;i*j<=10000000&&j<=i;j++){
			if(i==j){
				vis[i*j]++;
			}
			else {
				vis[i*j]+=2;
			}
		}
		vis[i]+=2;
	}
	return;
}

int main()
{
	prime();
	ll n;
	cin>>n;
	ll sum=0;
	for(ll i=1;i<=n;i++){
		sum+=(i*vis[i]);
//		cout<<i<<" "<<vis[i]<<endl;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 81748
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(n*a>=b){
      System.out.println(b);
    }else{
      System.out.println(n*a);
    }
  }
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
  int H,W; cin>>H>>W;
  vector<string> S(H); rep(i,H)cin>>S.at(i);
  vector<vector<int>> L(H,vector<int> (W,-1));
  vector<vector<int>> R(H,vector<int> (W,-1));
  vector<vector<int>> B(H,vector<int> (W,-1));
  vector<vector<int>> U(H,vector<int> (W,-1));
  rep(i,H){
    rep(j,W){
      if(S.at(i).at(j)=='.'){
        if(j>0&&S.at(i).at(j-1)!='#')L.at(i).at(j)=L.at(i).at(j-1)+1;
        else L.at(i).at(j)=1;
      }
    }
    for(ll j = W-1; j>= 0; j--){
      if(S.at(i).at(j)=='.'){
        if(j<W-1&&S.at(i).at(j+1)!='#')R.at(i).at(j)=R.at(i).at(j+1)+1;
        else R.at(i).at(j)=1;
      }
    }
  }
  rep(i,W){//横へスライド
    rep(j,H){
      if(S.at(j).at(i)=='.'){
        if(j>0&&S.at(j-1).at(i)!='#')U.at(j).at(i)=U.at(j-1).at(i)+1;
        else U.at(j).at(i)=1;
      }
    }
    for(int j = H-1; j>= 0; j--){
      if(S.at(j).at(i)=='.'){
        if(j<H-1&&S.at(j+1).at(i)!='#')B.at(j).at(i)=B.at(j+1).at(i)+1;
        else B.at(j).at(i)=1;
      }
    }
  }
  ll res = 0;
  rep(i,H){
    rep(j,W){
      if(S.at(i).at(j)=='#')continue;
      ll tmp = L.at(i).at(j)+R.at(i).at(j)+U.at(i).at(j)+B.at(i).at(j)-3;
      res = max(res,tmp);
    }
  }
  cout<<res<<endl;
}

Measured memory_bytes: 67200
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll M = 1e9 + 7;

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

  set<string> v;

  string x = "";
  string prev = "";
  int ans = 0;
  rep(i,s.size()) {
    x.push_back(s[i]);
    if (x == prev) continue;
    prev = x;
    x = "";
    ans++;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3720
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define repi(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,a) repi(i,0,a)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define repit(i,a) for(__typeof((a).begin()) i=(a).begin();i!=(a).end();i++)

#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())

#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

int main()
{
    int N, Q;
    while(cin >> N >> Q, N || Q){
	string str;
	int n, m;
	vi years;
	map<int,pair<int,string> > name;
	rep(i,N){
	    cin >> str >> n >> m;
	    years.pb(m);
	    name[m] = mp(n,str);
	}
	sort(all(years));
	rep(i,Q){
	    int y;
	    cin >> y;
	    if(name.find(y) != name.end()) cout << name[y].second << ' ' << name[y].first << endl;
	    else{
		vi::iterator itr = lower_bound(all(years),y);
		if(itr == years.end()) cout << "Unknown\n";
		else{
		    if(*itr < y || *itr - name[*itr].first >= y){
			cout << "Unknown\n";
		    }
		    else cout << name[*itr].second << ' ' << name[*itr].first - *itr + y << endl;
		}
	    }
	}
    }
    return 0;
}

Measured memory_bytes: 1356
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits> 

struct AB
{
    long A;
    long B;
    AB(long A1, long B1)
    {
        A=A1;
        B=B1;
    }
    bool operator <(const AB &another) const
    {
        return A<another.A;
    };
};

int main()
{
    long N,M;
    std::cin >> N >> M;
    std::vector<AB> ABs;
    for(long i=0; i<N; i++){
        long A,B;
        std::cin >> A >> B;
        ABs.push_back(AB(A,B));
    }
    std::sort(ABs.begin(),ABs.end());

    std::priority_queue<long> queue;
    long result=0;
    long depth=0;
    for(long i=1; i<=M; i++){
        while(ABs[depth].A<=i && depth<N){
            queue.push(ABs[depth].B);
            depth++;
        }
        if(queue.size()>0){
            result+=queue.top();
            queue.pop();
        }
    }
    std::cout << result << std::endl;
    return 0;
}

Measured memory_bytes: 3568
#ifdef __unix__
#include <bits/stdc++.h>
#else
#include <iostream>
#include <algorithm>
#include <math.h>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <unordered_set>
#include <stack>
#endif


#define fastIO ios_base::sync_with_stdio(0), cin.tie(NULL)
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl '\n'
#define mkp make_pair
/*#define NUMTOSTR(x)  (unsigned char)((x) + 48);*/
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long  ull;
using namespace std;
int main(){
	fastIO;
	char inp[0xF];
	cin >> inp;
	if (inp[0] == 'S') cout << "Cloudy";
	else if (inp[0] == 'C') cout << "Rainy";
	else cout << "Sunny";
	return 0;
}


Measured memory_bytes: 3508
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
    let v: Vec<T> = read_vec();
    assert_eq!(v.len(), 2);
    (v[0], v[1])
}

use std::collections::HashMap;

const MOD: usize = 998244353;
fn main() {
    let n: usize = read();
    let mut d: Vec<usize> = read_vec();

    if d[0] != 0 {
        println!("0");
        return;
    }
    d.sort();
    let v = split_same_element(&d);
    //println!("{:?}", v);
    if let Some(&x) = v.get(&0) {
        if x != 1 {
            println!("0");
            return;
        }
    } else {
        println!("0");
        return;
    }

    let mut ans: usize = 1;
    let m = d[n - 1];
    //println!("{}", m);
    for i in 1..m + 1 {
        if !v.contains_key(&i) {
            println!("0");
            return;
        }
        let a: usize = *v.get(&i).unwrap();
        let b: usize = *v.get(&(i - 1)).unwrap();
        ans *= mod_pow(b, a);
        ans %= MOD;
    }

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

fn mod_pow(a: usize, b: usize) -> usize {
    let mut result = 1;
    for _ in 0..b {
        result = result * a % MOD;
    }
    return result;
}

fn split_same_element<T: Eq + Copy + std::hash::Hash>(v: &Vec<T>) -> HashMap<T, usize> {
    let mut res = HashMap::new();
    for &e in v {
        *res.entry(e).or_insert(0) += 1;
    }

    res
}


Measured memory_bytes: 12540
<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
list($A,$B) = explode(" ",trim(fgets(STDIN)));
$P = explode(" ",trim(fgets(STDIN)));
//$h = explode(" ",trim(fgets(STDIN)));

$res[0]=0;
$res[1]=0;
$res[2]=0;
foreach($P as $v) {
  if ($v <= $A) {
    $res[0]++;
    continue;
  }
  if ($v <= $B) {
    $res[1]++;
    continue;
  }
  $res[2]++;
}
printf("%d\n",min($res));


Measured memory_bytes: 4856
#include <iostream>
#include <queue>
#include "stdio.h"

using namespace std;

int s, g, V, P;

struct Road{
    Road(int t, int c)
        : to(t), cost(c) {};

    int to;
    int cost;
};

int d[20];
vector<Road> roads[100];
typedef pair<int, int> PII;


int dijkstra(int start, int goal);

int main(int argc, char const *argv[]){
    int n, m, a, b, c, d;
    cin>>n;
    cin>>m;

    for (int i = 0; i < m; i++){
        scanf("%d,%d,%d,%d", &a, &b, &c, &d);  
            roads[a].push_back(Road(b, c));
            roads[b].push_back(Road(a, d));
    }

    scanf("%d,%d,%d,%d", &s, &g, &V, &P);  

    V -= dijkstra(s, g);
    V -= dijkstra(g, s);

    cout<<V-P<<endl;
    
    return 0;
}


int dijkstra(int start, int goal){
    fill(d, d+20, 1000000);
    priority_queue<PII, vector<PII>, greater<PII> > que;
    d[start] = 0;
    que.push(PII(0, start));

    while (!que.empty()){
        PII p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (int i = 0; i < roads[v].size(); i++)
        {
            Road r = roads[v][i];
            if (d[r.to] > d[v] + r.cost)
            {
                d[r.to] = d[v] + r.cost;
                que.push(PII(d[r.to], r.to));
            }
        }
    }

    return d[goal];
}

Measured memory_bytes: 3136
# -*- coding:utf-8 -*-
if __name__ == "__main__":
    n = int(input())
    x = [ (number, index) for number, index in zip(list(map(int, input().split())),range(n)) ]
    x.sort(key=lambda tmp:tmp[0])
    indexDic = { index[1]: xindex for index, xindex in zip(x,range(n)) }
    center = int(n/2)
    for tmp in range(n):
        ignoreIndex = indexDic[tmp]
        if ignoreIndex+1 <= center:
            print(x[center][0])
        else:
            print(x[center-1][0])

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

int a, b;

int main()
{
    scanf("%d %d", &a, &b);
    int m = min(a, b), n = max(a, b);
    for (int i = 1; i <= n; i++)
    {
        printf("%d", m);
    }
    printf("\n");
    return 0;
}


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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    string ans="No";
    if ((abs(a-c) <= d) || ((abs(a-b) <= d) && (abs(b-c) <= d))) ans = "Yes";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  int ans = 2 * k;
  for (int i = 1; i < n; i++)
    if (s[i] == 'L')
      if (s[i - 1] == 'L')
        ans++;
  for (int i = 0; i < n - 1; i++)
    if (s[i] == 'R')
      if (s[i + 1] == 'R')
        ans++;
  cout << min(n - 1, ans) << endl;
}

Measured memory_bytes: 512
package main

import (
	"fmt"
)

// 2018-08-22T11:27:13+0800
// 2018-08-22T12:13:55+0800 Giving up.
// 2018-08-22T12:17:56+0800 Got inspired.
// 2018-08-22T12:24:14+0800 TLE @see https://arc062.contest.atcoder.jp/submissions/3056076
// 2018-08-22T12:27:13+0800
func main() {
	var N int
	fmt.Scanf("%d", &N)
	//T := make([]int, N)
	//A := make([]int, N)
	ta, tb := 0, 0
	a, b := 0, 0
	for i := 0; i < N; i++ {
		fmt.Scanf("%d%d", &ta, &tb)
		if ta > a {
			a = ta
		}
		if tb > b {
			b = tb
		}
		t := max(a/ta, b/tb)
		for ii := t; ; ii++ {
			if a <= ii*ta && b <= ii*tb {
				a = ii * ta
				b = ii * tb
				break
			}
		}
	}
	fmt.Println(a + b)
}

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

func minMul(a, b int) int {
	c := maxMod(a, b)
	return a * b / c
}
func maxMod(a, b int) int {
	if a == 0 {
		return b
	}
	return maxMod(b, a%b)
}

Measured memory_bytes: 512
#import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline




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



N,X,Y=acinput()



dist=[[-1 for j in range(N+1) ] for i in range(N+1)]


for i in range(1,N):
    for j in range(i,N+1):
        a=abs(i-X)
        b=abs(j-Y)
        dist[i][j]=min(j-i,a+b+1)
        

res=[0]*(N+1)
for i in range(N):
    for j in range(i, N+1):
        res[dist[i][j]]+=1
        

for i in range(1,N):
    print(res[i])

#print(np.array(dist))
#print(res)

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

int main(){
    int n,m,cnt;
    cnt = 0;
    int cnt2 = 0;
    int ans = 0;
    cin >> n >> m;
    vector<int> v(n);
    vector<vector<int>> s(m,vector<int>(2));
    for(int i=0;i<n;i++) v[i] = i+1;
    for(int i=0;i<m;i++){
        cin >> s[i][0] >> s[i][1];
    }
    do{
      for(int i=0;i<n-1;i++){
          for(int j = 0;j<m;j++){
              if((s[j][0] == v[i] && s[j][1] == v[i+1])or(s[j][0] == v[i+1] && s[j][1] == v[i]))cnt++;
          }
          if(cnt == 1)cnt2++;
          cnt = 0;
      }
      if(cnt2 == n-1 && v[0] == 1)ans++;
      cnt2 = 0;
    }while(next_permutation(v.begin(), v.end()));
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, k = na()

m = [0] * k
for i in range(1, n + 1):
    m[i%k] += 1

ans = 0
for a in range(k):
    b = (k - a) % k
    c = (k - a) % k
    if (b + c) % k != 0:
        continue
    ans += m[a] * m[b] * m[c]

print(ans)

Measured memory_bytes: 4596
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	var w string
	cnt := 0

	stdin := bufio.NewScanner(os.Stdin)

	fmt.Scanf("%s", &w)
	for {
		stdin.Scan()
		text := stdin.Text()

		if text == "END_OF_TEXT" {
			break
		}
		words := strings.Split(text, " ")
		for i := 0; i < len(words); i++ {
			if words[i] == "" {
				continue
			}

			if w == strings.ToLower(words[i]) {
				cnt++
			}
		}
	}

	fmt.Println(cnt)
}


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

double same(double x, double y) {
	return abs(x - y) < pow(10, -20);
}

ll nCk(ll n, ll k) {
	ll ans = 1;
	for (ll i = 0;i < k;i++) {
		ans *= (ll)n - i;
		ans /= i + 1;
	}
	return ans;
}

int main() {
	int N, A, B, cnt = 0, k = 0;
	cin >> N >> A >> B;
	vector<ll> X(N);
	ll V = 0, ans = 0, C = 0;
	for (int i = 0;i < N;i++)cin>>X[i];
	sort(all(X));
	reverse(all(X));
	for (int i = 0;i < A;i++) {
		V += X[i];
		if (X[i] == X[0])cnt++;
	}
	if (cnt >= A) {
		cnt = 0;
		for (int i = 0;i < N;i++)if (X[i] == X[0])cnt++;
		for (int i = min(cnt, B);i >= A;i--) {
			ans += nCk(cnt, i);
		}
	}
	else {
		cnt = 0;
		for (int i = 0;i < A;i++)
			if (X[i] == X[A - 1])cnt++;
		k = cnt;
		for (int i = A;i < N;i++)
			if (X[i] == X[A - 1])k++;
		ans = nCk(k, cnt);
	}
	printf("%.8f\n", (double)V / A);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;

  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }

  string ans = "";
  while (n) {
    if (n % 2 != 0) {
      n--;
      ans = "1" + ans;
    } else
      ans = "0" + ans;
    n /= -2;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
/*------------------------------------
.....Bismillahir Rahmanir Rahim.......
created by muslim.time: 2:24:23 pm....
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld long double
#define   pb push_back
#define  sz(x)  (int)x.size()
#define  ff first
#define  ss second
#define  pii  pair<int,int>
using namespace std;

inline void solve(){ 
    map <int,bool> mp; 
    int yen; cin>> yen;
    int n; cin>>n;
    while (n--){
        int a; cin>>a;
        mp[a]=true;
    }
    while (1){
        string s=to_string(yen);
        int l=s.size();
        bool ok=true;
        for (int i=0;i<l;i++){
            if (mp[s[i]-'0']) {
                ok=false;
                break;
            }
        }
        if (ok) break;
        yen++;
    }
    cout << yen << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
typedef vector<bool> VB;
typedef vector<VB> VVB;
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};

bool check(VVB& G)
{
  for(int i=1;i<=10;i++)
    for(int j=0;j<10;j++)
      if(G[i][j])
	return false;
  return true;
}

void next(VVB& G,int bit)
{
  for(int i=0;i<10;i++)
    G[0][i] = ((bit>>i)&1)?1:0; 
}

void execute(VVB&G,VVB& ans)
{
  ans.resize(11);
  for(int i=1;i<11;i++)
    {
      ans[i].resize(10);
      for(int j=0;j<10;j++)
	ans[i][j] = false;
    }

  for(int i=1;i<11;i++)
    {
      for(int j=0;j<10;j++)
	{
	  if(G[i-1][j])
	    {
	      G[i][j] = !G[i][j];
	      ans[i][j] = true;
	      for(int k=0;k<4;k++)
		{
		  int nx = j + dx[k];
		  int ny = i + dy[k];
		  if(!(0 <= nx && nx < 10 && 0 <= ny && ny <= 10))
		    continue;
		  G[ny][nx] = !G[ny][nx];
		}

	    }
	}
    }

}

int main()
{
  int n;
  cin >> n;
  while(n-- > 0)
    {
      VVB G;
      G.resize(11);
      G[0].resize(10);
      for(int i=1;i<=10;i++)
	{
	  G[i].resize(10);
	  for(int j=0;j<10;j++)
	    {
	      bool b;
	      cin >> b;
	      G[i][j] = b;
	    }
	}


      for(int m=0;m<=(1<<10)-1;m++)
	{
	  VVB pre_G = G;
	  VVB ans;
	  next(G,m);

	  execute(G,ans);

	  if(check(G))
	    {
	      for(int i=1;i<=10;i++)
		{
		  for(int j=0;j<10;j++)
		    {
		      cout << ans[i][j];
		      j == 9?cout << endl:cout << " ";
		    }
		}
	      break;
	    }
	  G = pre_G;
	}


    }
  return 0;
}

Measured memory_bytes: 1212
//
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define MOD 1000000007
#define PI 3.14159265
#define EPS 1e-9
#define Pi acos(-1.0)
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;

/*CODE START HERE*/

string a, b;

int main(){
    ios::sync_with_stdio(0);
    cin >> a >> b;

    if(b.size() > a.size()){
        cout << "LESS\n";
    }else if(a.size() > b.size()){
        cout << "GREATER\n";
    }else if(a == b){
        cout << "EQUAL\n";
    }else if(a > b){
        cout << "GREATER\n";
    }else{
        cout << "LESS\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1e9+7LL;

int f(int a){
    int k = 0;
  	while((k+1)*(k+2)/2<=a) k++;
  	return k;
}

int main() {
    ll N; cin >> N;
  	ll n = N;
    ll ans = 0;
    ll i = 2;
    while(n>=i*i){
        if(N%i==0){
            ll cnt = 0;
            while(N%i==0){
                N = N/i;
                cnt++;
            }
            ans += f(cnt);
        }
      	i++;
    }
  	if(N != 1) ans++;

    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <stdio.h>

struct node {
    int value;
    int left;
    int right;
};

struct node tree[1000000];
int n;

void Preorder(int now)
{   
    static int first = 0;
    if(first==0) printf("Preorder\n");
    first = 1;

    if(now == -1){
        return;
    }

    printf(" %d", now);
    Preorder(tree[now].left);
    Preorder(tree[now].right);

}

void Inorder(int now)
{   
    static int first = 0;
    if(first==0) printf("Inorder\n");
    first = 1;

    if (now == -1){
        return;
    }

    Inorder(tree[now].left);
    printf(" %d", now);
    Inorder(tree[now].right);

}

void Postorder(int now)
{   
    static int first = 0;
    if(first==0) printf("Postorder\n");
    first = 1;

    if(now == -1){
        return;
    }

    Postorder(tree[now].left);
    Postorder(tree[now].right);
    printf(" %d", now);

}

int main()
{
    int i;
    int value,left,right;
    int root;

    scanf("%d",&n);
    for(i=0;i<n;i++) tree[i].value = -1;

    for(i=0;i<n;i++){
        scanf("%d %d %d",&value,&left,&right);
        tree[value].left=left;
        tree[value].right=right;
        if(left!=-1) tree[left].value = value;
        if (right!=-1) tree[right].value = value;
    }
    
    for(i=0;i<n;i++){
        if(tree[i].value == -1) root = i;
    }

    Preorder(root);
    printf("\n");
    Inorder(root);
    printf("\n");
    Postorder(root);
    printf("\n");

    return (0);
}


Measured memory_bytes: 2104
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))


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

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

int main(){
    int N;
    int A, B;
    cin >> N;
    if(N == 1) cout << "Hello World" << endl;
    else {
        cin >> A >> B;
        cout << A + B << endl;
    }
    return 0;
}


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

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

vector<int> apos[200005];
vector<int> cntp(200005);

signed main() {
  SPEED;
  ll n, k; cin >> n >> k;
  vector<int> x(n);
  rep(i, n) {
    cin >> x[i];
    apos[x[i]].push_back(i);
  }

  int loop = 0;
  cntp[0] = 0;
  rep(i, n*2) {
    debug(i);
    int pos = cntp[i];
    while (pos < n) {
      debug(pos);
      auto a = x[pos];
      auto it = upper_bound(apos[a].begin(), apos[a].end(), pos);
      if (it == apos[a].end()) {
        if (apos[a].size() > 1) {
          auto it2 = apos[a].begin();
          cntp[i+1] = ((*it2)+1)%n;
        } else {
          cntp[i+1] = (pos+1);
        }
        break;
      } else {
        pos = ((*it)+1);
      }
    }

    debug(i, cntp[i+1]);
    if (cntp[i + 1] == 0) {
      loop = i+1;
      break;
    }
  }
  debug(loop);
  k = k%loop;
  if (k==0) {
    cout << endl;
    return 0;
  }

  set<int> st;
  vector<int> vec;
  for(int i=cntp[k-1]; i<n; i++) {
    int p = x[i];
    if (st.find(p) == st.end()) {
      vec.push_back(p);
      st.insert(p);
    } else {
      while(vec.back() != p) {
        st.erase(vec.back());
        vec.pop_back();
      }
      st.erase(p);
      vec.pop_back();
    }
  }

  for(auto e: vec) {
    cout << e << ' ';
  }
  cout << endl;
}

Measured memory_bytes: 24180
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);


int main(){

	IOS
	//freopen("output.txt", "w", stdout);
    
	//freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    //this can be opted out if you want to print the output to the sublime console
	ll n;
	cin>>n;
	std::vector<ll> v(3);
	fo(i,3) cin>>v[i];
	
	std::vector<string> s(n);
	string tmp;
	fo(i,n){
		cin>>s[i];


	}
	ll t1,t2;
	ll aa,bb;
	//dbg3(v[0],v[1],v[2]);
	
	std::vector<ll> ans;
	fo(i,n){
		tmp=s[i];
		aa=(ll)(s[i][0]-'A');
		bb=(ll)(s[i][1]-'A');
		//dbg2(aa,bb);
		//dbg2(v[aa],v[bb]);
		if(v[aa]<=0&&v[bb]<=0){
			cout<<"No"<<endl;
			return 0;
		}
		else if(v[aa]==1&&v[bb]==1&&v[3-(aa+bb)]==0){
			if(i==n-1) {ans.pb(aa); break;}
			t1=s[i+1][0]-'A';
			t2=s[i+1][1]-'A';
			if(aa==t1||aa==t2){
				v[bb]--;
				v[aa]++;
				ans.pb(aa);

			}
			else{
				v[aa]--;
				v[bb]++;
				ans.pb(bb);
			}
		
		}
		else if(v[aa]>=v[bb]){
			v[aa]--;
			v[bb]++;
			ans.pb(bb);

		}
		else {
			v[aa]++;
			v[bb]--;
			ans.pb(aa);
		}
		//dbg2(v[aa],v[bb]);
	}
	cout<<"Yes"<<endl;
	fo(i,n){
		cout<<char(ans[i]+'A')<<endl;
	}




	
}

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

#define For(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e9

typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;

vector<char> boin = {'a','i','u','e','o'};
vector<char> alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

const int MAX_N = 100000;
int par[MAX_N];

void init(int n){
    Rep(i,n)par[i] = i;
}

int find(int x){
    if(par[x] == x){
        return x;
    }else{
        return par[x] = find(par[x]); //renew par[x]
    }
}

bool same(int x,int y){
    return find(x) == find(y);
}

void unate(int x,int y){
    int a = find(x);
    int b = find(y);
    if(a == b) return; // if same parent: nothing
    par[a] = b; // else unate them
}

int main(){
    int n,m;
    cin >> n >> m;
    init(n);
    vector<int> p(n);
    Rep(i,n){
        cin >> p[i];
        p[i]--;
    }
    vector<priority_queue<int>> memo(n,priority_queue<int>());
    vector<priority_queue<int>> nums(n,priority_queue<int>());
    Rep(i,m){
        int x,y;
        cin >> x >> y;
        x--;
        y--;
        unate(x,y);
    }
    Rep(i,n){
        //cout << i+1 << sp << find(i)+1 << endl;
        memo[find(i)].push(i);
        nums[find(i)].push(p[i]);
    }
    int ans = 0;
    Rep(i,n){
        while(!memo[i].empty() && !nums[i].empty()){
            int x,y;
            x = memo[i].top();
            y = nums[i].top();
            if(x == y){
                ans++;
                memo[i].pop();
                nums[i].pop();
            }else if(x > y){
                memo[i].pop();
            }else{
                nums[i].pop();
            }
        }
    }
    cout << ans << endl;
    //cin >> n;
}

Measured memory_bytes: 13568
# coding: utf-8
"""this is python work script"""

def solver(s):
    """solve this problem"""
    s_li = list(s)
    for i, word in enumerate(s_li):
        if word == '?':
            s_li[i] = 'D'
    answer = ''.join(s_li)
    return answer

def main():
    """main function"""
    S = input().rstrip()
    answer = solver(S)
    print(answer)

if __name__ == '__main__':
    main()


Measured memory_bytes: 10848
#include<stdio.h>
int main(void){
	int a,b,c,tmp=0;
	
	scanf("%d %d %d",&a,&b,&c);
	
	if(a>c){
		tmp=a;
		a=c;
		c=tmp;
	}
	if(a>b){
		tmp=a;
		a=b;
		b=tmp;
	}
	if(b>c){
		tmp=b;
		b=c;
		c=tmp;
	}
	printf("%d %d %d\n",a,b,c);
	return 0;
}


Measured memory_bytes: 2132
let search d lst =
  let rec iter i = function
    | [] -> i - 1
    | hd :: tl when hd <= d -> i - 1
    | hd :: tl -> iter (i+1) tl
  in iter 1 lst

let section lst v1 v2 = 
  let sod = List.fold_left (+.) 0.0 lst in
  let dlst = List.fold_right (fun x s -> (x +. List.hd s) :: s) lst [0.0] in
  let d2 = sod /. (v1 +. v2) *. v2 in
  search d2 dlst
  
let _ = 
  try
    while true do
      let ls, v1, v2 = Scanf.scanf "%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n" (fun l1 l2 l3 l4 l5 l6 l7 l8 l9 l10 v1 v2 -> [l1;l2;l3;l4;l5;l6;l7;l8;l9;l10], v1, v2) in
      Printf.printf "%d\n" (section ls v1 v2)
    done
  with
    End_of_file -> ()
        

Measured memory_bytes: 2416
#include<stdio.h>
#include<math.h>
#define N 6
  
typedef struct{
  double x;
  double y;
}XY;
  
void koch(int,XY,XY);
  
int main()
{
  int n,i;
  
  XY p1 = {0.0,0.0},p2 = {100.0,0.0};
  scanf("%d",&n);
  printf("%.8f %.8f\n",p1.x,p1.y);
  koch(n,p1,p2);
  printf("%.8f %.8f\n",p2.x,p2.y);
  
  return 0;
}
  
void koch(int n,XY p1,XY p2)
{
  XY s,t,u;
  
  if(n == 0) return;
  
  s.x = (2 * p1.x + 1 * p2.x) / 3;
  s.y = (2 * p1.y + 1 * p2.y) / 3;
  t.x = (1 * p1.x + 2 * p2.x) / 3;
  t.y = (1 * p1.y + 2 * p2.y) / 3;
  u.x = (t.x - s.x) * 1 / 2 - (t.y - s.y) * sqrt(3) / 2 + s.x;
  u.y = (t.x - s.x) * sqrt(3) / 2 + (t.y - s.y) * 1 / 2 + s.y;
  
  koch(n-1,p1,s);
  printf("%.8f %.8f\n",s.x,s.y);
  
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  
  koch(n-1,t,p2);
}

Measured memory_bytes: 640
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val s = sc.next
  val cs: Seq[Char] = s.toCharArray.toList

  def solve(cs: Seq[Char], acc: String): String = cs match {
    case x +: xs =>
      x match {
        case 'B' => if (acc.isEmpty) solve(xs, "") else solve(xs, acc.substring(0, acc.length - 1))
        case z => solve(xs, acc + z)
      }
    case _ => acc
  }

  val ans = solve(cs, "")

  println(ans)
}


Measured memory_bytes: 25500