akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(){
    int H;
    int W;
    cin >> H >> W;
    int N;
    cin >> N;
    int squ = 0;
    int color;
    int inkvalue = 0;
    int colornum = 0;
    int colors[N];
    int squs[W][H];
    int nowX = 0;
    int nowY = 0;
    int direc = 3;
    int train = 0;
    for(int i = 0; i < N; i++){
        cin >> color;
        colors[i] = color;
    }
    if(W == 1){
        direc = 6;
    }
    for(int i = 0; i < H * W; i++){
        squ += 1;
        if(inkvalue == 0){
            inkvalue = colors[colornum];
            colornum += 1;
        }
        squs[nowX][nowY] = colornum;
        if(direc == 0){
            nowY -= 1;
            if(nowY <= train + 1){
                train += 1;
                direc = 3;
            }
        }else if(direc == 3){
            nowX += 1;
            if(nowX >= W - 1 - train){
                direc = 6;
            }
        }else if(direc == 6){
            nowY += 1;
            if(nowY >= H - 1 - train){
                direc = 9;
            }
        }else if(direc == 9){
            nowX -= 1;
            if(nowX <= train){
                direc = 0;
            }
        }
        inkvalue -= 1;
    }
    for(int i1 = 0; i1 < H; i1++){
        for(int i2 = 0; i2 < W; i2++){
            cout << squs[i2][i1] << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

int haiku[45];
int num[6]={5,7,5,7,7,0};

void solve(int n){
  int s=0,e=0,cnt=0,sum=haiku[0];
  int dast=0;
  
  rep(i,n-4){
    dast=cnt=0;
    s=e=i;
    sum=haiku[i];
    
    while(s!=n&&e!=n){
      if(debug)cout<<"s: "<<s<<"  e:"<<e<<"  cheack( "<<cnt<<" ): "<<num[cnt]<<"  dast: "<<dast<<"  cnt: "<<cnt<<endl;
      if(cnt==5)break;
      if(sum==num[cnt]){
	s=e=e+1;sum=haiku[s];cnt++;
      }else if(sum<num[cnt]){
	e++;sum+=haiku[e];
      }else if(sum>num[cnt]){
	break;
      }
    }
    if(debug)cout<<endl;
    if(debug)cout<<"s: "<<s<<"  e:"<<e<<"  cheack( "<<cnt<<" ): "<<num[cnt]<<"  dast: "<<dast<<"  cnt: "<<cnt<<endl;
    if(cnt==5){
      cout<<i+1<<endl;
      break;
    } 
  }
}


int main(){
  int n;
  string s;
  while(cin>>n){
    if(n==0)break;
    rep(i,n){cin>>s;haiku[i]=s.size();}
    solve(n);
  }
}

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

int n, m;
int X[N], Y[N];
ll d[N];

const int dx[5] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
const char dc[5] = {'R', 'L', 'U', 'D'};

void getp(ll x, ll y) {
    for(int i = m; i; i--) {
        int now = d[i];
        for(int j = 0; j < 4; j++) {
            ll curx = x + d[i] * dx[j], cury = y + d[i] * dy[j];
            if(abs(curx) + abs(cury) < now) {
                cout << dc[j];
                x = curx, y = cury;
                break;
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    int sign = 1, mx = 0;
    for(int i = 1; i <= n; i++) cin >> X[i] >> Y[i];
    for(int i = 2; i <= n; i++) {
        if((abs(X[i] + Y[i]) & 1) != (abs(X[i - 1] + Y[i - 1]) & 1))
            sign = 0;
        mx = max(mx, abs(X[i]) + abs(Y[i]));
    }
    if(!sign) {cout << -1; return 0;}
    for(d[m = 1] = 1; d[m] << 1 <= mx; ++m, d[m] = d[m - 1] << 1);
    if(abs(X[1] + Y[1]) & 1) sign = 0;
    cout << m + sign << '\n';
    if(sign) cout << 1 << ' ';
    for(int i = m; i; i--) cout << d[i] << " \n"[i == 1];
    for(int i = 1; i <= n; i++) {
        if(sign) cout << 'R';
        getp(X[i] - sign, Y[i]);
        cout << '\n';
    }
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

type Edge struct {
	to, cost int
}

// 辺のリストで表現されるグラフ
type Graph struct {
	Edges [][]Edge // Edge[i][j]: 頂点iのj番目の辺
	Pred  []int    // 遷移元
	Cost  []int    // 始点からの最小コスト
}

// 頂点数nのリスト型グラフを返す
func NewGraph(n int) *Graph {
	g := &Graph{
		Edges: make([][]Edge, n),
		Pred:  make([]int, n),
		Cost:  make([]int, n),
	}
	for i := 0; i < n; i++ {
		g.Edges[i] = make([]Edge, 0)
		g.Pred[i] = -1
		g.Cost[i] = 1 << 60
	}
	return g
}

// 辺の追加
func (g *Graph) AddEdge(from, to, cost int) {
	g.Edges[from] = append(g.Edges[from], Edge{to, cost})
}

// value: 頂点の番号
// priority: 始点からのコスト
type Elem struct {
	value    interface{}
	priority int
	index    int
}

type PriorityQueue []*Elem

func (pq PriorityQueue) Len() int {
	return len(pq)
}

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].priority < pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index, pq[j].index = i, j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	elem := x.(*Elem)
	elem.index = n
	*pq = append(*pq, elem)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(*pq)
	elem := old[n-1]
	old[n-1] = nil
	elem.index = -1
	*pq = old[0 : n-1]
	return elem
}

// 0-indexed
func (g *Graph) DijkstraSearch(origin int) {
	// init
	g.Cost[origin] = 0
	done := make([]bool, len(g.Edges))
	pq := make(PriorityQueue, 0)
	heap.Init(&pq)
	heap.Push(&pq, &Elem{
		value:    origin,
		priority: 0,
	})

	// seaech
	for pq.Len() > 0 {
		v := heap.Pop(&pq).(*Elem)
		from := v.value.(int)
		done[from] = true
		for _, edge := range g.Edges[from] {
			to := edge.to
			if done[to] {
				continue
			}
			// 隣接頂点の最小コストを更新
			nextCost := v.priority + edge.cost
			if nextCost < g.Cost[to] {
				g.Cost[to] = nextCost
				g.Pred[to] = from
				heap.Push(&pq, &Elem{
					value:    to,
					priority: nextCost,
				})
			}
		}
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()
	g := NewGraph(n)
	for i := 0; i < n-1; i++ {
		a, b := nextInt()-1, nextInt()-1
		g.AddEdge(a, b, 1)
		g.AddEdge(b, a, 1)
	}

	// マス1からの距離
	g.DijkstraSearch(0)
	cost1 := make([]int, n)
	for i := 0; i < n; i++ {
		cost1[i] = g.Cost[i]
	}

	// 初期化
	for i := 0; i < n; i++ {
		g.Pred[i] = -1
		g.Cost[i] = 1 << 60
	}

	// マスNからの距離
	g.DijkstraSearch(n - 1)
	costN := make([]int, n)
	for i := 0; i < n; i++ {
		costN[i] = g.Cost[i]
	}

	f, s := 0, 0
	for i := 1; i < n-1; i++ {
		if cost1[i] <= costN[i] {
			f++
		} else {
			s++
		}
	}

	if f > s {
		puts("Fennec")
	} else {
		puts("Snuke")
	}
}


Measured memory_bytes: 18560
#include<bits/stdc++.h>
using namespace std;
int main(void) {
  int a,b,c,d,n=0;
  cin >> a >> b;
  string ans = "No";
  c=b;
  while(c>0) {
    d += (c % 10);
    c /= 10;
    ++n;
  }
  a = a * pow(10,n);
  int m = a + b;
  for(int i=0;i<1000;++i) {
    if(sqrt(m) == i) ans = "Yes";
  }
   cout << ans << endl;
}

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

int X, Y;
int main(){
    cin >> X >> Y;
    int z = X*2;
    for(z; z <= X*4; z+=2){
        if(z == Y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3604
n, m = map(int, input().split())
v = list(map(int, input().split()))
v.sort()
a = [0 for i in range(m-1)]
for i in range(m - 1):
    a[i] = v[i + 1] - v[i]
a.sort()
ans = 0
for i in range(m - n):
    ans += a[i]
print(ans)


Measured memory_bytes: 13968
import heapq
 
"""
https://juppy.hatenablog.com/entry/2019/02/18/%E8%9F%BB%E6%9C%AC_python_%E3%83%97%E3%83%A9%E3%82%A4%E3%82%AA%E3%83%AA%E3%83%86%E3%82%A3%E3%82%AD%E3%83%A5%E3%83%BC%28heapq%29%E3%82%92%E7%94%A8%E3%81%84%E3%81%9F%E3%83%97%E3%83%AA%E3%83%A0%E6%B3%95
"""
 
def dijkstra_heap(s,edge):
    #始点sから各頂点への最短距離
    d = [10**10]*n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d
 
################################
N = int(input())
n = N
w = N
 
edge = tuple([] for i in range(n))
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(w-1):
    a,b = map(int,input().split())
    edge[a-1].append([1,b-1])
    edge[b-1].append([1,a-1])

dist_zero = dijkstra_heap(0,edge)
dist_n = dijkstra_heap(N-1,edge)
"""
print(dist_zero)
print(dist_n)
"""
b = 0
w = 0

for black,white in zip(dist_zero,dist_n):
    if black > white:
        w += 1
    else:
        b += 1

if b > w:
    print("Fennec")
else:
    print("Snuke")  

Measured memory_bytes: 48900
#include <stdio.h>
typedef long long int ll;
constexpr int kMod = int(1E9 + 7);
int a[30][30];
ll dp[2][1 << 21];
int main() {
	int n;
	bool f = false;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]);
	dp[!f][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) if (a[i][j]) {
			for (int k = 0; k < (1 << n); k++) if ((1 << (j - 1)) & k) dp[f][k] += dp[!f][k ^ (1 << (j - 1))];
		}
		for (int j = 0; j < (1 << n); j++) dp[f][j] %= kMod;
		f = !f;
		for (int j = 0; j < (1 << n); j++) dp[f][j] = 0;
	}
	printf("%lld\n", dp[!f][(1 << n) - 1]);
}


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

int main() {
    int N, Y;
    cin >> N >> Y;
    int res10000 = -1, res5000 = -1, res1000 = -1;
    for (int a = 0; a <= N; ++a) {  // 10000円の枚数を 0 〜 N で調べる
        for (int b = 0; b + a <= N; ++b) {  // 5000円の枚数を 0 〜 N-a で調べる
            int c = N - a - b;  // 1000円の枚数は決まる
            int total = 10000*a + 5000*b + 1000*c;
            if (total == Y) {  // 答えが見つかったら
                res10000 = a;
                res5000 = b;
                res1000 = c;
            }
        }
    }

    // 答えを出力 (見つかっていなくても -1 -1 -1 になるので OK です)
    cout << res10000 << " " << res5000 << " " << res1000 << endl;
}



Measured memory_bytes: 256
n = int(input())
b = list(map(int,input().split()))

ans = []
def solve(b,i):
    if i == 0:
        return True
    for j in range(i-1,-1,-1):
        if b[j] > j+1:
            return False
        if b[j] == j+1:
            p = b[:j] + b[j+1:]
            if solve(p,i-1):
                ans.append(j+1)
                return True

    return False

solve(b,n)
if len(ans) == n:
    for i in range(n):
        print(ans[i])
else:
    print(-1)

Measured memory_bytes: 40176
# coding: utf-8
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
ans=[]
l=0
while l<N-1:
    #print(cnt,ans)
    if A[l]==A[l+1]:
        ans.append(A[l])
        if len(ans)==2:
            break
        else:
            l+=2
    else:
        l+=1
#print(A)
if len(ans)<=1:
    print(0)
else:
    print(ans[0]*ans[1])

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn int

typedef long long ll;
typedef pair<ll,ll> p;


int main()
{
  string s;
  cin >> s;
  for (int i = 0; i < 3; i++)
  {
    if(s[i] == '1') s[i] = '9';
    else s[i] = '1';
  }
  cout << s << endl;

}


Measured memory_bytes: 384
#include <stdio.h>

int main() {
	int N, ret = 0;
  	int V[20], C[20];
  
  	scanf("%d\n",&N);
  
  	for(int i = 0; i < N; i++){
    	scanf("%d ",&V[i]);
    }
  
  	for(int i = 0; i < N; i++){
    	scanf("%d ",&C[i]);
    }
  
  	for(int i = 0; i < N; i++){
    	if(V[i] - C[i] > 0){
        	ret += V[i] - C[i];
        }
    }
  
  	printf("%d\n",ret);
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

const int Maxn = (int)1e5+10;
const ll INF = (ll)1e15;
ll d[Maxn];

int n, m, k;

class edge {
public:
    int from, to;
    ll cost;

    edge(int t, ll c) : from(-1), to(t), cost(c) {}

    edge(int f, int t, ll c) : from(f), to(t), cost(c) {}

    bool operator<(const edge &e) const {
        return cost < e.cost;
    }

    bool operator>(const edge &e) const {
        return cost > e.cost;
    }
};

int main() {
    /*
    ios::sync_with_stdio(false);
    cin.tie(0);
     */
    cin >> n;
    vector<vector<edge>> g(n);
    for (int i = 0; i < n - 1; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        g[a].emplace_back(b, c);
        g[b].emplace_back(a, c);
    }
    cin >> m >> k;
    k--;

    fill(d, d + n, INF);
    queue<int> que;
    d[k] = 0;
    que.push(k);
    while(!que.empty()){
        int p = que.front();que.pop();
        for(auto &e : g[p]){
            if (d[e.to] == INF){
                d[e.to] = d[p] + e.cost;
                que.push(e.to);
            }
        }
    }

    while(m--){
        int x, y;
        cin >> x >> y;
        --x, --y;
        cout << d[x] + d[y] << endl;
    }
}

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

#define INF ll_MAX

typedef long long ll;

using namespace std;

int main(void){
	int n,k;
	string s;
	cin >> n >> s >> k;
	
	for(int i = 0;i < n;i++){
		if(s[k-1] != s[i]){
			s[i] = '*';
		}
	}
	cout << s << endl;

	return 0;
}

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

int main() {
	int n;
	cin >> n;
	string s, t;
	cin >> s;
	cin >> t;
	int x = 0;
	for (int i = 0; i < n; i++) {
		if (s == t) {
			x = i;
			break;
		}
		else if (s.length() == 1) {
			x = n;
			break;
		}
		else {
			s = s.substr(1);
			t = t.substr(0, t.length() - 1);
		}
	}
	cout << 2 * n - (n - x) << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
cnt = [1] * (n + 1)
in_r = [0] * (n + 1)
in_r[1] = 1
for _ in range(m):
    x, y = map(int, input().split())
    cnt[x] -= 1
    cnt[y] += 1
    if in_r[x] == 1:
        in_r[x] = min(cnt[x], 1)
        in_r[y] = 1
ans = sum(in_r)
print(ans)

Measured memory_bytes: 4596
def inv(x):
    global p
    res=1
    prod=x
    e=p-2
    while e>0:
        if e%2==1:
            res=(res*prod)%p
        prod=(prod*prod)%p
        e//=2
    return res

def fact(x):
    if x<1:
        return 1
    global p
    res=1
    for i in range(2, x+1):
        res=(res*i)%p
    return res

def combi(n,r):
    if r<0 or r>n:
        return 0
    else:
        a=fact(n)
        b=inv(fact(r))
        c=inv(fact(n-r))
        return(((a*b)%p)*c)%p

N,K=map(int,input().split())
p=1000000007

for i in range(1,K+1):
    print((combi(K-1,i-1)*combi(N-K+1,i))%p)

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

using namespace std;

int P[101010];
vector <int> V[101010];
int n, ans;

int f(int p)
{
	vector <int> K;
	int i, ret;
	
	ret = V[p].size();
	
	for(i=0;i<V[p].size();i++){
		K.push_back(-f(V[p][i]));
	}
	
	sort(K.begin(), K.end());
	
	for(i=0;i<K.size();i++){
		ret = max(ret, i-K[i]+1);
	}
	
	return ret;
}

int main()
{
	int i;
	
	scanf("%d", &n);
	
	for(i=2;i<=n;i++){
		scanf("%d", P+i);
		V[P[i]].push_back(i);
	}
	
	printf("%d\n", f(1));
	
	return 0;
}

Measured memory_bytes: 15488
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<stdio.h>
#include<iostream>
#include<numeric>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (c - a + b > 0)
		cout << c - a + b << endl;
	else
		cout << 0 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int const MAXN = 1e5 + 5;
char s[MAXN][5];
char T[MAXN];

int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  int n, A, B, C;
  cin >> n >> A >> B >> C;
  for (RI i = 1; i <= n; ++i) cin >> s[i];
  for (RI i = 1; i <= n; ++i) {
    if (s[i][0] == 'A' && s[i][1] == 'B') {
      if (!A && !B) return puts("No"), 0;
      if (A == B) {
        if (i == n) T[i] = 'A', ++A, --B;
        else if (s[i + 1][0] == 'A' && s[i + 1][1] == 'B') T[i] = 'A', ++i, T[i] = 'B';
        else if (s[i + 1][0] == 'A' && s[i + 1][1] == 'C') T[i] = 'A', --B, ++C, ++i, T[i] = 'C';
        else if (s[i + 1][0] == 'B' && s[i + 1][1] == 'C') T[i] = 'B', --A, ++C, ++i, T[i] = 'C';
      }
      else if (A < B) ++A, --B, T[i] = 'A';
      else --A, ++B, T[i] = 'B';
    }
    
    else if (s[i][0] == 'A' && s[i][1] == 'C') {
      if (!A && !C) return puts("No"), 0;
      if (A == C) {
        if (i == n) T[i] = 'A', ++A, --C;
        else if (s[i + 1][0] == 'A' && s[i + 1][1] == 'C') T[i] = 'A', ++i, T[i] = 'C';
        else if (s[i + 1][0] == 'A' && s[i + 1][1] == 'B') T[i] = 'A', --C, ++B, ++i, T[i] = 'B';
        else if (s[i + 1][0] == 'B' && s[i + 1][1] == 'C') T[i] = 'C', --A, ++B, ++i, T[i] = 'B';
      }
      else if (A < C) ++A, --C, T[i] = 'A';
      else --A, ++C, T[i] = 'C';
    }
    
    else if (s[i][0] == 'B' && s[i][1] == 'C') {
      if (!B && !C) return puts("No"), 0;
      if (B == C) {
        if (i == n) T[i] = 'B', ++B, --C;
        else if (s[i + 1][0] == 'B' && s[i + 1][1] == 'C') T[i] = 'B', ++i, T[i] = 'C';
        else if (s[i + 1][0] == 'A' && s[i + 1][1] == 'B') T[i] = 'B', --C, ++A, ++i, T[i] = 'A';
        else if (s[i + 1][0] == 'A' && s[i + 1][1] == 'C') T[i] = 'C', --B, ++A, ++i, T[i] = 'A';
      }
      else if (B < C) ++B, --C, T[i] = 'B';
      else --B, ++C, T[i] = 'C';
    }
  }
  puts("Yes");
  for (RI i = 1; i <= n; ++i)
    putchar(T[i]), puts("");

  return 0;
}

// created by Daniel yuan


Measured memory_bytes: 4160
import java.util.*;

/**
 * Mの素因数分解をする．
 * 
 * 
 * @author glycine
 *
 */
public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] tokens = in.nextLine().split(" ");
		int N = Integer.parseInt(tokens[0]);
		int M = Integer.parseInt(tokens[1]);

		List<Integer> yakusuu = new ArrayList<>();
		yakusuu.addAll(getYakusuu(M));
		Collections.sort(yakusuu);
		Collections.reverse(yakusuu);
		int limit = Math.floorDiv(M, N);
		int result = -1;
		for(int i = 0; i < yakusuu.size(); ++i) {
			if(yakusuu.get(i) <= limit) {
				result = yakusuu.get(i);
				break;
			}
		}
		System.out.println(result);
		in.close();
	}

	private static Set<Integer> getYakusuu(int M) {
		Set<Integer> result = new HashSet<>();
		result.add(1);
		result.add(M);
		for (int i = 2; i <= Math.sqrt(M); ++i) {
			if (M % i == 0) {
				result.add(i);
				result.add(M / i);
			}
		}
		return result;
	}
}

Measured memory_bytes: 22740
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())

scr = 0
#k回目までの処理
for i in range(k):
    if t[i] == "r":
        scr += p
    elif t[i] == "s":
        scr += r
    elif t[i] == "p":
        scr += s
#print(scr)

#k＋１回目以降の処理
#前に出した手のせいで勝てない場合は、次の手の邪魔にならないような手を出す
for i in range(k, n):
    if t[i] == t[i - k]:
        scr += 0
        t[i] = "q"
    else:
        if t[i] == "r":
            scr += p
        elif t[i] == "s":
            scr += r
        elif t[i] == "p":
            scr += s

print(scr)


Measured memory_bytes: 9952
N = int(input())
T,X,Y = [],[],[]
for i in range(N):
  t,x,y = map(int,input().split())
  T.append(t)
  X.append(x)
  Y.append(y)
if N == 1:
  trans_count = X[0] + Y[0]
  time = T[0]
  if (time - trans_count) % 2 == 0 and time - trans_count >= 0:
    print("Yes")
  else:
    print("No")
  exit()
for i in range(N-1):
  trans_count = abs(X[i+1] - X[i]) + abs(Y[i+1] - Y[i])
  time = T[i+1] - T[i]
  if (time - trans_count) % 2 != 0 or time - trans_count < 0:
    print("No")
    break
  elif i == N-2:
    print("Yes")

Measured memory_bytes: 11808
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    int n,INF=1e9+1;
    cin>>n;
    vector<int> A(n),dp(n+1,INF);
    rep(i,n) cin>>A[i];
    reverse(A.begin(),A.end());
    dp[0]=-1;
    rep(i,n) dp[upper_bound(dp.begin(),dp.end(),A[i])-dp.begin()]=A[i];
    cout<<lower_bound(dp.begin(),dp.end(),INF)-dp.begin()-1;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace StartFinish
{
 

    class Program
    {
        static void Main(string[] args)
        {
            int x = int.Parse(Console.ReadLine());
            Console.WriteLine(x*x*x);
        }
        
    }
}

Measured memory_bytes: 9192
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
	
	int N, K;
	
	int sum[4][4][200];
	
	int dic[200];
	
	cin >> N >> K;
	
	for(int i = 0; i <= N; i++){
		dic[i] = 0;
		for(int j = 0; j < 4; j++){
			for(int k = 0; k < 4; k++){
				sum[k][j][i] = 0;
			}
		}
	}
	
	int a, b;
	
	for(int i = 0; i < K; i++){
		cin >> a >> b;
		dic[a] = b;
	}
	
	if(dic[1] != 0){
		sum[0][dic[1]][1] = 1;
	}else{
		sum[0][1][1] = 1;
		sum[0][2][1] = 1;
		sum[0][3][1] = 1;
	}
	
	for(int i = 2; i <= N; i++){
		if(dic[i] != 0){
			for(int j = 0; j < 4; j++){
				for(int k = 1; k <= 3; k++){
					if(j != k || k != dic[i]){
						sum[k][dic[i]][i] += sum[j][k][i - 1];
						sum[k][dic[i]][i] = sum[k][dic[i]][i] % 10000;
					}
				}
			}
		}else{
			for(int j = 0; j < 4; j++){
				for(int k = 1; k <= 3; k++){
					for(int l = 1; l <= 3; l++){
						if(j != k || k != l){
							sum[k][l][i] += sum[j][k][i - 1];
							sum[k][l][i] = sum[k][l][i] % 10000;
						}
					}
				}
			}
		}
	}
	
	int ans = 0;
	
	for(int j = 0; j < 4; j++){
		for(int k = 0; k < 4; k++){
			ans += sum[j][k][N];
			ans = ans % 10000;
		}
	}
	
	/*
	for(int i = 1; i <= N; i++){
		for(int j = 0; j < 4; j++){
			for(int k = 0; k < 4; k++){
				printf("%d ", sum[j][k][i]);
			}
			printf("\n");
		}
		printf("\n");
	}
	*/
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 1156
let () = Scanf.scanf "%d %d\n" @@ fun n m ->
    let cnt = Array.make n 0 in
    for _ = 1 to m do
        Scanf.scanf "%d %d\n" @@ fun a b ->
        cnt.(a-1) <- cnt.(a-1)+1;
        cnt.(b-1) <- cnt.(b-1)+1;
    done;
    cnt |> Array.map (Printf.printf "%d\n") |> ignore


Measured memory_bytes: 384
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define int long long
#define F(i,L,R) for(int i=L;i<R;++i)
#define FE(i,L,R) for(int i=L;i<=R;++i)
#define getI(a) scanf("%lld",&a)
#define getII(a,b) scanf("%lld%lld",&a,&b)
#define getIII(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define VgetI(n) int (n); scanf("%lld",&(n))
#define VgetII(n,m) int (n),(m); scanf("%lld%lld",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define qq cout<<"QQ\n";
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define INF 2000000000
main(){
	int n;
	while(~getI(n)){
		int ans=0;
		FE(a,1,n) ans+=(n/a)-(n%a==0);
		printf("%lld\n",ans);
	}
}


Measured memory_bytes: 3824
n, m = gets.split.map(&:to_i)
claims = readlines.map(&:chomp).map{|s| s.split(" ").map(&:to_i)}

claims.sort_by! { |claim| claim[1] }
answer = 0
last_end = 0
claims.each do |claim|
  next if claim[0] < last_end

  last_end = claim[1]
  answer += 1
end
puts answer


Measured memory_bytes: 28792
#include<iostream>
using namespace std;
int main(){
	int n,h,w;
	cin>>n>>h>>w;
	int a[n],b[n],l;
	for(int i=0;i<n;i++){
		cin>>l;
		a[i]=l;
		cin>>l;
		b[i]=l;
	}
	int count=0;
	for(int i=0;i<n;i++){
		if (a[i]>=h&&b[i]>=w)
			count++;
	}
	cout<<count;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <functional>
#include <queue>
#include <map>
using namespace std;
typedef long long W;

const W INF = 1LL << 50;

struct edge {
	int to;
	W cost;
};
typedef pair<W, int> P;
typedef vector<vector <edge > > Graph;

void dijkstra(int s, const Graph& G, vector<W>& d) {
	priority_queue< P, vector<P>, greater<P> > que;
	fill(d.begin(), d.end(), INF);
	d[s] = 0;
	que.push(P(0, s));
	while(!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		for(int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

W wf[310][310];
string a[3000], b[3000];
W dist[3000];
string st_name[310];

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

	int N, M, cap;
	while(cin >> N >> M >> cap, N | M | cap) {
		map<string, int> city;
		string src, dst;
		cin >> src >> dst;
		city[src] = -1;
		city[dst] = -1;

		for(int i = 0; i < N; i++) {
			cin >> a[i] >> b[i] >> dist[i];
			city[a[i]] = -1;
			city[b[i]] = -1;
		}

		int C = 0;
		for(auto& p : city) {
			city[p.first] = C++;
		}

		map<string, int> station;
		for(int i = 0; i < M; i++) {
			cin >> st_name[i];
			station[st_name[i]] = i;
		}
		station[src] = M;
		station[dst] = M + 1;
		st_name[M] = src;
		st_name[M + 1] = dst;
		M += 2;

		for(int i = 0; i < M; i++)
			for(int j = 0; j < M; j++)
				wf[i][j] = i == j ? 0 : INF;

		Graph G(C);
		for(int i = 0; i < N; i++) {
			G[city[a[i]]].push_back(edge{ city[b[i]], dist[i] });
			G[city[b[i]]].push_back(edge{ city[a[i]], dist[i] });
		}

		vector<W> d(C);
		for(int i = 0; i < M; i++) {
			dijkstra(city[st_name[i]], G, d);
			for(int j = 0; j < M; j++) {
				if(i == j) continue;
				if(d[city[st_name[j]]] <= cap * 10) {
					wf[i][j] = wf[j][i] = d[city[st_name[j]]];
				}
			}
		}

		for(int k = 0; k < M; k++)
			for(int i = 0; i < M; i++)
				for(int j = 0; j < M; j++)
					wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j]);

		W ans = wf[station[src]][station[dst]];
		if(ans == INF) ans = -1;
		cout << ans << endl;
	}



}

Measured memory_bytes: 5096
#include<iostream>
//#include<CastingInterop.h>
#include<string>
#include<array>
#include<math.h>
#include<sstream>
using namespace std;

int main()
{

	int num1,num3;
	cin >> num1;
	
	
		num3 = sqrt(num1);
			if (num3 % 10 != 0)
			{
				
				num3 = sqrt(num1);
				cout << num3 * num3;

			}
			else
			{
				cout << num3 * num3;
			}
}

Measured memory_bytes: 3636
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

void Add(int p, int q, int c);

typedef struct {
    int Num, Route;
} Sta;


typedef struct {
    Sta Station;
    int Fee;
} Node;

bool operator<(const Node &a, const Node &b) {
    return a.Fee > b.Fee;
}

bool operator<(const Sta &a, const Sta &b) {
    if (a.Num == b.Num)

        return a.Route < b.Route;
    else
        return a.Num < b.Num;
}

map<Sta, vector<int>> L;
vector<vector<int>> R;

int main() {
    int N, M;
    cin >> N >> M;
    R = vector<vector<int>>(N);
    for (int i = 0; i < M; i++) {
        int p, q, c;
        cin >> p >> q >> c;
        p--;
        q--;
        Add(p, q, c);
        Add(q, p, c);
    }
    priority_queue<Node> pq;
    set<Sta> set;
    pq.push({{0, 0}, 0});
    while (pq.size()) {
        Node n = pq.top();
        pq.pop();
        if (set.count(n.Station)) {
            continue;
        }
        set.insert(n.Station);
        if (n.Station.Num == N - 1) {
            cout << n.Fee << endl;
            return 0;
        }
        if (n.Station.Route == 0) {
            for (int i:R[n.Station.Num]) {
                pq.push({{n.Station.Num, i}, n.Fee + 1});
            }
        } else {
            for (int i:L[n.Station]) {
                pq.push({{i, n.Station.Route}, n.Fee});
            }
            pq.push({{n.Station.Num, 0}, n.Fee});
        }
    }

    cout << "-1" << endl;
    return 0;
}

void Add(int p, int q, int c) {
    Sta pos = {p, c};
    L[pos].push_back(q);
    R[p].push_back(c);
}

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

using namespace std;

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

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


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

int main() {
  int n, m;
  cin >> n >> m;
  
  vector<int> vec(n);

  for (int i=0; i<m; i++){
    int a,b;
    cin >> a >> b;
    vec.at(a-1)++;
    vec.at(b-1)++;
  }
  
  for (int i=0; i<n; i++){
    cout << vec.at(i) << endl;
  }
}


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

using namespace std;

const int M = 1e9+7;
string s;
long long dp[110000][13];

int main()
{
  cin >> s;
  int len = s.length();
  
  dp[0][0] = 1;
  
  for (int i = 0; i < len; i++) {
    for (int rem = 0; rem < 13; rem++) {
      if (s[i] != '?') {
        int next_rem = (rem * 10 + (s[i] - '0')) % 13;
        dp[i+1][next_rem] += dp[i][rem];
        dp[i+1][next_rem] %= M;
      } else {
        for (int num = 0; num < 10; num++) {
          int next_rem = (rem * 10 + num) % 13;
          dp[i+1][next_rem] += dp[i][rem];
          dp[i+1][next_rem] %= M;
        }
      }
    }
  }
  
  cout << dp[len][5] << endl;
  return 0;
}

Measured memory_bytes: 10752
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int A = scn.nextInt(), B = scn.nextInt();
		int ans = ((B-1)%(A-1)==0)?(B-1)/(A-1):(B-1)/(A-1) + 1;

		System.out.println(ans);
	}

}

Measured memory_bytes: 21716
<?php
fscanf(STDIN,"%d %d %d %d %d",$W, $H, $x, $y, $r);
if($x-$r<0 || $y-$r<0 || $x+$r>$W || $y+$r>$H) {
    echo "No";
} else {
    echo "Yes";
}
?>

Measured memory_bytes: 15204
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

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 GCD(T a, T b) { return b ? GCD(b, a % b) : a; }
template<class T>
inline T LCM(T a, T b) { return (a + (b - 1)) / b; }
template<class T>
inline T round_int(T a, T b) {return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

void add(ll& a, ll b) {
	a += b;
	if (a >= mod) a -= mod;
}

ll dp[210000][5];

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

	dp[0][0] = 1;

	rep(i, s.size()) {
		rep(j, 5) {
			if (s[i] == '?') add(dp[i + 1][j], dp[i][j] * 3 % mod);
			else add(dp[i + 1][j], dp[i][j]);
		}

		if (s[i] == 'A' || s[i] == '?') add(dp[i + 1][1], dp[i][0]);
		if (s[i] == 'B' || s[i] == '?') add(dp[i + 1][2], dp[i][1]);
		if (s[i] == 'C' || s[i] == '?') add(dp[i + 1][3], dp[i][2]);
	}
	cout << dp[s.size()][3] << endl;
}

Measured memory_bytes: 4608
#include <stdio.h>
int main(void){
    int N = 0;
    scanf("%d", &N);
    int A[2][100] = {0};
    int i = 0;
    for(i = 0; i < 2; i++){
        for(int j = 0; j < N; j++){
            scanf("%d", &A[i][j]);
        }
    }

    int maxcandy = 0;
    for(int k = 1; k <= N; k++){
        int candy = 0;
        i = 0;
        for(int j = 0; j < k; j++){
            candy += A[i][j];
        }
        i++;
        for(int j = k-1; j < N; j++){
            candy += A[i][j];
        }
        if(maxcandy <= candy) maxcandy = candy;
    }
    
    printf("%d\n", maxcandy);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    map<int, int> d;
    rep(i, n) {
        int a;
        cin >> a;
        if(a == 0) {
            cout << 0 << endl;
            return 0;
        }
        d[a]++;
        if(d[a] > 2) {
            cout << 0 << endl;
            return 0;
        }
    }
    vector<int> one, two;
    for(auto u : d) {
        if(u.first == 12) {
            two.push_back(12);
            continue;
        }
        if(u.second==1) one.push_back(u.first);
        if(u.second==2) two.push_back(u.first), two.push_back(24-u.first);
    }
    int ans = 0;
    rep(bit, 1 << size(one)) {
        vector<int> now = two;
        now.push_back(0);
        rep(i, size(one)) {
            if(1&bit>>i) {
                now.push_back(one[i]);
            }else{
                now.push_back(24-one[i]);
            }
        }
        int tmp = 12;
        rep(i, size(now)) rep(j, size(now)) if(i != j) {
            chmin(tmp, min(24 - abs(now[i] - now[j]), abs(now[i] - now[j])));
        }
        chmax(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<set>
#include<utility>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<stack>
#include<iomanip>

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

#define P pair<int, int>

typedef long long ll;

using namespace std;

#include <string>
#include <cctype>
typedef string::const_iterator State;
class ParseError {};


int main() {
	int r, b, w, g;
	cin >> r >> b >> w >> g;
	cout << r + w + b + g << endl;

	return 0;
}


Measured memory_bytes: 3100
n,m = map(int, input().split(" "))
result = [-1]*n
judge = 1
for i in range(m):
  s,c=map(int, input().split(" "))
  if result[s-1] == -1 or result[s-1] == c:
    result[s-1] = c
  else:
    judge = 0

if result[0] == 0 and n>=2:
  judge = 0
elif n>=2:
  if result[0]==-1:
    result[0] = 1
  for i in range(1,n):
    if result[i] == -1:
      result[i] = 0
elif n==1:
  if result[0]==-1:
    result[0]=0

if judge == 0:
  print("-1")
else:
  print("".join([str(x) for x in result]))


Measured memory_bytes: 3064
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A,B,i,ans=0;cin>>A>>B;
	for(i=A;i<=B;i++){
		if(((i/1000)%10)==((i/10)%10)&&i/10000==i%10){ans++;}
		
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
//I love Nanami Chiaki
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fst first
#define snd second
const int inf=1e9+7;
const int mod=1e9+7;
//const int maxn=;
int main(){
	int k,a,b,c,ans=0;;cin>>a>>b>>c>>k;
	if (k>=a) k-=a,ans=a;
	else ans=k,k=0;
	if (k>=b) k-=b;
	else k=0;
	ans-=k;cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3620
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn level(a: usize, b: usize) -> u32 {
    let x = a ^ b;
    x.trailing_zeros() + 1
}

fn main() {
    let n = read::<usize>();
    for i in 0..(n - 1) {
        for j in (i + 1)..n {
            print!("{} ", level(i, j));
        }
        println!();
    }
}


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

const long long MOD = 1000000007;

auto solve(long long N, long long M){
    long long minor = min(N, M);
    long long major = max(N, M);

    long long p = 1;
    for(long long i = 1; i <= minor; i++) {
        p = (p * i) % MOD;
    }

    if(N == M) {
        return (2 * p * p) % MOD;
    }
    else if(abs(N - M) == 1) {
        return (p * ((p * major) % MOD)) % MOD;
    }

    return 0LL;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    auto result = solve(N, M);
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
  private static int solve(int a, int b, int c, int d) {
    int maxBeginTime = Math.max(a, c);
    int minEndTime = Math.min(b, d);
    return Math.max(0, minEndTime - maxBeginTime);
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int a = reader.nextInt();
    int b = reader.nextInt();
    int c = reader.nextInt();
    int d = reader.nextInt();
    out.println(solve(a, b, c, d));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(string, S);
  VAR(int, Q);
  deque<char> d;
  each(x, S) d.push_back(x);
  bool rvs = false;
  rep(i, 0, Q) {
    VAR(int, t);

    if (t == 1) {
      rvs = !rvs;
    } else {
      VAR(int, f);
      VAR(char, c);
      if (rvs) {
        f = 1 + (f % 2);
      }
      if (f == 1) {
        d.push_front(c);
      } else {
        d.push_back(c);
      }
    }
  }
  if (rvs) reverse(all(d));
  each(x, d) {
    cout << x;
  }
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n,k;
    cin >> n >> k;
    vector<vector<ll>> s(n);
    rep(i,n){
        ll t,d;
        cin >> t >> d;
        --t;
        s.at(t).push_back(d);
    }

    for(i = 0;i < n;++i){
        sort(all(s.at(i)), greater<ll>());
        if(s.at(i).empty()) s.at(i).push_back(-1e14);
    }
    sort(all(s), [&](vector<ll> a, vector<ll> b){
        return a.at(0) > b.at(0);
    });

    ll ans = 0;
    priority_queue<ll> pq;
    rep(i,k){
        ans += s.at(i).at(0);
        for(j = 1;j < s.at(i).size();++j) pq.push(s.at(i).at(j));
    }
    for(i = k;i < n;++i){
        for(j = 0;j < s.at(i).size();++j) pq.push(s.at(i).at(j));
    }

    ll tmp = ans;
    ans += k*k;
    for(ll x = k - 1;x >= 1;--x){
        ll v = s.at(x).at(0);
        ll w = pq.top();
        if(v < w){
            pq.pop();
            tmp += w;
            pq.push(v);
            tmp -= v;
        }else break;
        ans = max(ans, tmp + x*x);
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int R[n];
  for (int i=0; i<n; i++) {
    cin >> R[i];
  }
  int maxv=R[1]-R[0];
  int minv=R[0];
  for (int i=1; i<n; i++) {
    maxv=max(maxv,R[i]-minv);
    minv=min(minv,R[i]);
  }
  cout << maxv << endl;
  return 0;
}



Measured memory_bytes: 3884