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

int upb(int n)
{
  int ret=0;
  while(n>0) ret++, n/=2;
  return ret;
}

int main()
{
  for (int n; cin>>n, !(n==0); ){

    vector<vector<int> > pats(n*n+1);
    vector<vector<int> > tmp(n, vector<int>(n, 0));
    for (int i=0; i<n; i++){
      for (int j=0; j<n; j++){
	for (int k=i; k<n; k++){
	  for (int l=j; l<n; l++){
	    for (int a=i; a<=k; a++)
	      for (int b=j; b<=l; b++)
		tmp[a][b]=1;
	    int bd=0;
	    for (int a=0; a<n; a++){
	      for (int b=0; b<n; b++){
		bd=(bd<<1)|tmp[a][b];
	      }
	    }
	    pats[upb(bd)].push_back(bd);
	    for (int a=i; a<=k; a++)
	      for (int b=j; b<=l; b++)
		tmp[a][b]=0;
	  }
	}
      }
    }

    int bd=0;
    for (int i=0; i<n; i++){
      for (int j=0; j<n; j++){
	int t; cin>>t;
	bd=(bd<<1)|t;
      }
    }

    queue<pair<int, int> > mm;
    vector<bool> close(1<<(n*n), false);
    mm.push(make_pair(0, bd));
    close[bd]=true;
    while(!mm.empty()){
      int dep=mm.front().first;
      int cbd=mm.front().second;
      mm.pop();
      //cout<<cbd<<endl;
      int ub=upb(cbd);
      for (int i=0; i<pats[ub].size(); i++){
	int nbd=cbd^pats[ub][i];
	if (nbd==0){
	  for (int i=0; i<=dep; i++)
	    cout<<"myon";
	  cout<<endl;
	  goto _exit;
	}
	//cout<<"*** "<<nbd<<endl;
	if (close[nbd]) continue;
	close[nbd]=true;
	mm.push(make_pair(dep+1, nbd));
      }
    }
  _exit:;
  }
  return 0;
}

Measured memory_bytes: 5732
import pprint
N, M, X = [int(i) for i in input().split()]

books = {}
for i in range(N):
    hoge = list(map(int, input().split()))
    books[i] = hoge

Achievement = False  # 達成

for n in range(2 ** N):
    conditions = [0 for m in range(M + 1)]  # 条件
    for i in range(N):
        if ((n >> i) & 1):
            for m in range(M + 1):
                conditions[m] += books[i][m]

    # 条件が達成しているか判定
    count = 0
    for m in range(1, M + 1):
        if conditions[m] < X:
            break
        count += 1
    if count == M:
        if Achievement == False:
            Achievement = True
            min = conditions[0]
        elif min > conditions[0]:
            min = conditions[0]

if Achievement == False:
    print(-1)
else:
    print(min)


Measured memory_bytes: 9856
import math
k = int(input()) - 1
moto = list(range(0,49)) + [50]
ka = k%50
for i in range(ka):
  syo = moto.index(min(moto))
  moto[syo] += 51
  for j in range(50):
    moto[j] -= 1
k = k//50
for j in range(50):
  moto[j] += k
print(50)
print(" ".join(map(str,moto)))

Measured memory_bytes: 3064
a=input()
s = {a[0],a[1],a[2],a[3]}
if len(s) == 2:
  b = s.pop()
  flag1 = a.count(b)
  c = s.pop()
  flag2 = a.count(c)
  if flag1 ==2 and flag2 == 2:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }


int main() {
  i64 A, V, B, W, T;
  cin >> A >> V >> B >> W >> T;
  if(A > B) swap(A, B);
  i64 a = A + V * T;
  i64 b = B + W * T;
  if(a < b) {
    cout << "NO" << endl;
  }
  else {
    cout << "YES" << endl;
  }
}


Measured memory_bytes: 3632
using System;
using System.Linq;

namespace lineAralgebra
{


	class Program
	{
		static void Main(string[] args)
		{
			var N = int.Parse(Console.ReadLine());
			var S = Console.ReadLine();

			var deleteCount = 0;
			
			for(var i = 0; i < S.Length; i++) {
				for(var j = i + 1; j < S.Length; j++) {
					if (S[i] == S[j]) deleteCount++;
					else {
						break;
					}
					i = j -1;
				}		
			}

			System.Console.WriteLine(N - deleteCount);
		}
	}
}
//                            0       2      4

Measured memory_bytes: 11232
#include <bits/stdc++.h>
#define  ENDL  '\n'
#define N 10000007
using namespace std;
typedef unsigned long  long int ulli;
bool prime[N];
ulli cantdiv[N];
void primos();
int main()
{
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  ulli resp=1;
  cin>>n;
  primos();
  for(int i=2; i<=n;  ++i)
  {
    resp+=(cantdiv[i]+2)*i;
  }
  cout<<resp;
  return 0;
}

void primos()
{
  for(int i=2; i<=N/2; ++i)
  {
    for(int j=i*2; j<N; j+=i)
    {
      cantdiv[j]++;
    }
  }
  cantdiv[1]=1;
  return;
}


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

using namespace std;

struct Process {
  string name;
  int time;
};

int main () {
  int n, q;
  Process P[1000000];

  cin >> n >> q;

  for (int i = 0; i < n; i++) {
    cin >> P[i].name >> P[i].time;
  }

  int count = 0;
  int origin = n;

  for (int i = 0; i < n; i++) {
    P[i].time -= q;
    if (P[i].time <= 0) {
      count += q + P[i].time;
      cout << P[i].name << " " << count << endl;
    } else {
      n++;
      P[n-1] = P[i];
      count += q;
    }
  }

}

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

int main() {
  vector<int> a(10000), b(10000);
  vector<char> op(10000);
  int idx = 0;
  while(true) {
    cin >> a.at(idx) >> op.at(idx) >> b.at(idx);
    if(op.at(idx) == '?') break;
    idx++;
  }
  idx = 0;
  while (op.at(idx) != '?') {
    if (op.at(idx) == '+') cout << a.at(idx) + b.at(idx) << endl;
    else if (op.at(idx) == '-') cout << a.at(idx) - b.at(idx) << endl;
    else if (op.at(idx) == '*') cout << a.at(idx) * b.at(idx) << endl;
    else if (op.at(idx) == '/') cout << a.at(idx) / b.at(idx) << endl;
    idx++;
  }
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pi = pair<int,int>;
using mp = map<int,int>;
using ump = unordered_map<int,int>;
#define MOD 1000000007

#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main(){
    fastio;
    string za, za1;    cin>>za>>za1;
    char ch=za1[za1.length()-1];
    if(za1==za+ch)
        cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;

return 0;
}


Measured memory_bytes: 3656
s = input().replace("RL","R,L").replace("LR","L,R").split(",")
s = list(map(len, s))
t = list()
for x, y in zip(s[::2], s[1::2]):
    t += [0]*(x-1) + [(x+1)//2+y//2, x//2+(y+1)//2] + [0]*(y-1)
print(*t)

Measured memory_bytes: 7384
#include<set>
#include<cstdio>
#include<algorithm>
using namespace std;

const int Maxn=1e5;
const int Maxv=1e5+5;
const int INF=0x3f3f3f3f;

int N;
int cnt[2][Maxv+5];
int m[2],n[2];

int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	scanf("%d",&N);
	for(int i=1;i<=N;i++) {
		int v;
		scanf("%d",&v);
		cnt[i&1][v]++;
		if(m[i&1]<cnt[i&1][v]) {
			m[i&1]=cnt[i&1][v];
			n[i&1]=v;
		}
	}
	sort(cnt[0],cnt[0]+Maxv);
	sort(cnt[1],cnt[1]+Maxv);
	int ans=0;
	if(n[0]!=n[1])
		ans=N-m[0]-m[1];
	else ans=N-max(m[0]+cnt[1][Maxv-2],m[1]+cnt[0][Maxv-2]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;

int main()
{
    int A;
    cin >> A;
    cout << "Christmas ";
    rep0(i, 25 - A)
    {
        cout << "Eve ";
    }
}


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

int cnt=0;
int num[5];

int main() {
	for(int i=0;i<=2;i++)
		scanf("%d",&num[i]);
	sort(num,num+3);
	while(num[0]!=num[1]||num[1]!=num[2]) {
		cnt++;
		if(num[2]==num[1]) num[0]+=2;
		else num[0]++,num[1]++;
		sort(num,num+3);
	}
	printf("%d\n",cnt);
	return 0;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1000000000000;

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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int a, b, q; cin >> a >> b >> q;
    vector<ll> s(a), t(b);
    for(int i=0;i<a;i++) cin >> s[i];
    for(int i=0;i<b;i++) cin >> t[i];
    for(int i=0;i<q;i++){
        ll x; cin >> x;
        auto sr = lower_bound(s.begin(), s.end(), x);
        ll psl = -INF, psr = INF;
        if(sr == s.begin()) psr = *sr;
        else if(sr == s.end()) psl = *(--sr);
        else{
            psr = *sr;
            psl = *(--sr);
        }
        auto tr = lower_bound(t.begin(), t.end(), x);
        ll ptl = -INF, ptr = INF;
        if(tr == t.begin()) ptr = *tr;
        else if(tr == t.end()) ptl = *(--tr);
        else{
            ptr = *tr;
            ptl = *(--tr);
        }

        // cout << psl << " " << psr << endl;
        // cout << ptl << " " << ptr << endl;

        // (s, t) = (l, l), (l, r), (r, l), (r, r)
        ll ans = INF;
        ll dll = max(x - psl, x - ptl);
        ans = min(ans, dll);
        ll dlr = min(2 * (x - psl) + (ptr - x), (x - psl) + 2 * (ptr - x));
        ans = min(ans, dlr);
        ll drl = min(2 * (psr - x) + (x - ptl), (psr - x) + 2 * (x - ptl));
        ans = min(ans, drl);
        ll drr = max(psr - x, ptr - x);
        ans = min(ans, drr);
        cout << ans << endl;
    }
}

Measured memory_bytes: 2944
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

s = STR()
if s[2] == s[3] and s[4]== s[5]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 60140
#include<stdio.h>

int main(void){
    int w, h, x, y, r;
    scanf("%d%d%d%d%d", &w, &h, &x, &y, &r);
    if(r<=x && (w-r)>=x)
        if(r<=y && (h-r)>=y){
            printf("Yes\n");
            return 0;
        }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 2080
using System;
using System.Collections.Generic;
class Solve{
    int N;
    int[] a;
    public Solve(){}
    public static int Main(){
        new Solve().Calc();
        return 0;
    }
    void Calc(){
        getinput();
        int c = 2;
        long count = a[0]-1;
        for(int i=1;i<N;i++){
            if(a[i] > c){
                count+=(a[i]-1)/c;
            }
            else if(a[i] == c){
                c++;
            }
        }
        Console.WriteLine(count);
    }
    void getinput(){
        N = int.Parse(Console.ReadLine());
        a = new int[N];
        for(int i=0;i<N;i++){
            a[i] = int.Parse(Console.ReadLine());
        }
    }    
}

Measured memory_bytes: 7128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char s[100];

int main(){
    scanf("%s",s);
    puts(s[1]==s[2]&&(s[0]==s[1]||s[3]==s[2]) ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 


using namespace std; 

int main(){

	int n;
	const double eps=1e-8;
	while(true){

		cin>>n;

		if(n==0) return 0;

		int ans=1;
		vector< double > x(n),y(n);

		for(int i=0;i<n;i++) cin>>x[i]>>y[i];

		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				const double d=hypot(x[i]-x[j],y[i]-y[j]);
				if(d>2.0+eps) continue;

				const double mx=(x[i]+x[j])/2.0;
				const double my=(y[i]+y[j])/2.0;
				const double dvx=(x[i]-x[j])/d;
				const double dvy=(y[i]-y[j])/d;

				const double cx1=mx+dvy*sqrt(1.0-d*d/4.0);
				const double cy1=my-dvx*sqrt(1.0-d*d/4.0);

				const double cx2=mx-dvy*sqrt(1.0-d*d/4.0);
				const double cy2=my+dvx*sqrt(1.0-d*d/4.0);

				int res=2;
				for(int k=0;k<n;k++){
					if(k==i || k==j) continue;
//					if(hypot(x[k]-cx1,y[k]-cy1)<1.0+eps) res++;
					if((x[k]-cx1)*(x[k]-cx1)+(y[k]-cy1)*(y[k]-cy1)<1.0+eps) res++;
				}
				
				ans=max(ans,res);

				res=2;
				for(int k=0;k<n;k++){
					if(k==i || k==j) continue;
//					if(hypot(x[k]-cx2,y[k]-cy2)<1.0+eps) res++;
					if((x[k]-cx2)*(x[k]-cx2)+(y[k]-cy2)*(y[k]-cy2)<1.0+eps) res++;
				}

				ans=max(ans,res);

			}
		}

		cout<<ans<<endl;

	}

	return 0;
}

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

int main() {
	int w, h, x, y, r;
	cin >> w >> h >> x >> y >> r;
	
	if(x >= r && (w - x) >= r && y >= r && (h - y) >= r) cout << "Yes" << endl;
	else cout << "No" << endl;
}



Measured memory_bytes: 3116
import java.util.Arrays;
import java.util.Scanner;

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

		int N = sc.nextInt();
		int T = sc.nextInt();

		int[] cs = new int[N];
		for (int i = 0; i < N; i++) {
			int c = sc.nextInt();
			if (sc.nextInt() <= T) {
				cs[i] = c;
			} else {
				cs[i] = 1001;
			}
		}
		Arrays.sort(cs);

		System.out.println(cs[0] <= 1000 ? cs[0] : "TLE");

		sc.close();
	}
}


Measured memory_bytes: 22996
import collections
n=int(input())
lst=[]
for i in range(n):
    lst.append(input())
cnt=collections.Counter(lst)
ma=0
for val in cnt.values():
    val=int(val)
    if(val>ma):
        ma=val
li=[]
for key,val in cnt.items():
    val=int(val)
    if(val==ma):
        li.append(key)
li.sort()
for i in li:
    print(i)

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

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

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

int main(){
    int n;
    cin >> n;
    unsigned long long ans=0;
    for(int i=0;i<n;i++){
        unsigned long long a;
        cin >> a;
        if(i==0)ans=a;
        ans=lcm(ans,a);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3576
package main

import (
	"fmt"
	"sort"
)


func main() {
	var n int
	fmt.Scanf("%d", &n)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))

	alice, bob := 0, 0
	for i, t := range a {
		if i % 2 == 0 {
			alice += t
		} else {
			bob += t
		}
	}

	fmt.Println(alice - bob)
}


Measured memory_bytes: 512
n = gets.to_i
v = gets.split.map(&:to_i)

ev = []
ov = []

n.times do |i|
	if i.even?
		ev << v[i]
	else
		ov << v[i]
	end
end

e = {}
o = {}

ev.size.times do |i|
  e[ev[i]] = (e[ev[i]] || 0) + 1
  o[ov[i]] = (o[ov[i]] || 0) + 1
end

e = e.sort_by {|k, v| -v}
o = o.sort_by {|k, v| -v}

e1 = e.shift
e2 = (e.shift || 0)
o1 = o.shift
o2 = (o.shift || 0)


if e1[0] == o1[0]
	puts n - [(e1[1] + (o2[1] || 0)), ((e2[1] || 0) + o1[1])].max
else
	puts n - (e1[1] + o1[1])
end


Measured memory_bytes: 21128
#include <iostream>
#include <vector>
#include <algorithm>

typedef long long long64;

long64 inline distance(long64 s, long64 t, long64 p)
{
	long64 d = abs(s - t);
	long64 d1 = abs(p - s);
	long64 d2 = abs(p - t);

	if (d1 < d2)
		return d1 + d;
	else
		return d2 + d;
}

//void inline find(long64& l, long64& r, long64 p, std::vector<long64>& array)
//{
//	auto it_s = std::lower_bound(array.begin(), array.end(), p);
//	if (it_s == array.end()) {
//		r = l = array.size() - 1;
//	}
//	else {
//		r = std::distance(array.begin(), it_s);
//		if (it_s != array.begin()) {
//			it_s--;
//			if (it_s == array.end()) {
//				l = r;
//			}
//			else {
//				l = std::distance(array.begin(), it_s);;
//			}
//		}
//		else {
//			l = r = 0;
//		}
//	}
//};

int main()
{
	size_t s_num, t_num, p_num;
	std::cin >> s_num >> t_num >> p_num;

	std::vector<long64> s(s_num);
	std::vector<long64> t(t_num);
	std::vector<long64> p(p_num);

	for (size_t i = 0; i < s_num; i++)
	{
		std::cin >> s[i];
	}

	for (size_t i = 0; i < t_num; i++)
	{
		std::cin >> t[i];
	}

	for (size_t i = 0; i < p_num; i++)
	{
		std::cin >> p[i];
	}

	std::sort(s.begin(), s.end());
	std::sort(t.begin(), t.end());

	for (size_t i = 0; i < p.size(); i++)
	{
		long64 min_s = abs(s[0] - p[i]);
		typedef std::vector<long64>::iterator it;
		it it_s_l;
		it it_s_r;
		it it_t_l;
		it it_t_r;

		auto end = s.end();

		auto find = [](it& l, it& r, long64 p, std::vector<long64>& array)
		{
			r = l = std::lower_bound(array.begin(), array.end(), p);
			if (r == array.end())
			{
				r--;
				l--;
			}
			else {
				if (l != array.begin()) {
					l--;
				}
				else {
					r = l = array.begin();
				}
			}
		};

		find(it_s_l, it_s_r, p[i], s);
		find(it_t_l, it_t_r, p[i], t);

		long64 mins[4] = {};
		mins[0] = distance(*it_s_l,*it_t_l, p[i]);
		mins[1] = distance(*it_s_l, *it_t_r, p[i]);
		mins[2] = distance(*it_s_r, *it_t_l, p[i]);
		mins[3] = distance(*it_s_r, *it_t_r, p[i]);


		long64 min = mins[0];
		for (size_t i = 0; i < 4; i++) {
			if (min > mins[i]) {
				min = mins[i];
			}
		}

		std::cout << min << std::endl;
	}

	return 0;
}

Measured memory_bytes: 3712
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
//    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

long long  factorial(long long n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}

int min(int a, int b) {
    if (a > b)
        return b;
    else
        return a;
}

int distance(int a, int b) {
  return abs(a-b)*abs(a-b);
}

//int ()



int main()
{
  int a ,b, c, d, e, X, Y;
//  long long  a, b, c, d, e, X, Y;
  //  double  c;
//  int  A[200003]={};
  long long  A[100003]={};
  long long  B[100003]={};
  int  C[100003][11]={};

  int  flg=0;

//  long long  a, b, c, d, X, Y;
  char s[101][101]={};
  char t[101]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  long long p,q;
//  int flag=0;
//  int tmp=0;
//  char tmp[101]={};
//  long long min=10000000000;
//  long long min=100000001;
  int len=0;
  int l=0;
  int r=1000001;
  int cnt=0;
  int num=0;
  int num1=0;
  int num2=0;
  int ans=0;
  int max=0;
  int sum=0;
  int addr=0;
  int ptn=0;
  long long  tmp=0;
//  bool on_off[100]={};
  
//  char alp[26]={'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'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
  scanf("%d", &a);
  scanf("%lld", &A[0]);
  A[0]=A[0]-1;
  for(i=1;i<a;i++){
    scanf("%lld", &A[i]);
    if(A[i-1]<A[i]) A[i]=A[i]-1;
    else if(A[i-1]>A[i]){
      printf("No\n");
      return 0;
    }
  }
      
  printf("Yes\n");
 
  

    
//    printf("%s %d %d\n", s[i],C[i][0],C[i][1]);
   // printf("%d\n", C[i][1]);
/*  for(i=0;i<addr;i++){
//  scanf("%lld%lld", &B[0][i],&B[1][i]);
//    ans=ans+A[i];
    printf("%lld ", A[i]);
  }
*/
//    printf("%d ", cnt);
   

return 0;
}


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


int main() {
  string S;
  cin >> S;
  if (S[0] == 'S') cout << "Cloudy" << endl;
  if (S[0] == 'C') cout << "Rainy" << endl;
  if (S[0] == 'R') cout << "Sunny" << endl;
}


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

int main(){
	int N;
	cin >> N;
	vector<double> L(N);
	for(int i=0; i<N; i++) cin >> L.at(i);
	sort(L.begin(), L.end());

	long ans = 0;
	for(int i=0; i<N-2; i++){
		for(int j=i+1; j<N-1; j++){
			if(L.at(i)!=L.at(j)){
				for(int k=j+1; k<N; k++){
					if(L.at(j)!=L.at(k)){
						double buf1 = L.at(i) + L.at(j);
						double buf2 = L.at(k);
						if(buf1 > buf2){
							ans++;
						}else if(buf1<buf2){
							break;
						}
					}
				}
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,M,num=-1;
  cin >>N>>M;
  
  vector<vector<int>> a(M, vector<int>(2));
  
  for(int i=0;i<M;i++){
    int x,y;
    cin >>x>>y;
    a.at(i).at(0)=x;
    a.at(i).at(1)=y;
  }
  
  if(N==1){
    for(int i=0;i<10;i++){
      bool ans = true;
      for(int j=0;j<M;j++){
        if(a.at(j).at(1)!=i){
          ans = false;
        }
      }
      if(ans){
        num =i;
        break;
      }
    }
  }
  else if(N==2){
    for(int i=10;i<100;i++){
      bool ans = true;      
      for(int j=0;j<M;j++){
        if(a.at(j).at(1)!=(i/(int)pow(10,2-a.at(j).at(0)))%10){
          ans = false;
        }
      }
      if(ans){
        num = i;
        break;
      }
    }
  }
  else{
     for(int i=100;i<1000;i++){
      bool ans = true;      
      for(int j=0;j<M;j++){
        if(a.at(j).at(1)!=(i/(int)pow(10,3-a.at(j).at(0)))%10){
          ans = false;
        }
      }
      if(ans){
        num = i;
        break;
      }
    }
  }
  
  cout << num << endl;
  
  return 0;
        
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

class UnionFind{
  int n;
  vector<int> data;
public:
  UnionFind(int _n):n(_n),data(_n,-1){}
  bool link(int a, int b){ //if new link, then true.
    int ra=find_root(a);
    int rb=find_root(b);
    if(ra!=rb){
      if(data[rb]<data[ra]) swap(ra,rb);
      data[ra]+=data[rb];
      data[rb]=ra;
    }
    return (ra!=rb);
  }
  bool check(int a, int b){ //if same set, then true.
    return (find_root(a)==find_root(b));
  }
  int find_root(int a){
    return ((data[a]<0)?a:(data[a]=find_root(data[a])));
  }
};

int N, M;
vector<pair<int,int>> G;

int main(){

  cin >> N >> M;
  rep(i,M){
    int a, b;
    cin >> a >> b;
    G.push_back(make_pair(a,b));
  }

  int ret = 0;
  rep(i,G.size()){
    UnionFind uf(N+1);
    rep(j,G.size()){
      if(i==j) continue;
      uf.link(G[j].first, G[j].second);
    }
    bool flg = true;
    REP(j,1,N+1){
      if(uf.find_root(1) != uf.find_root(j)) flg = false;
    }
    if(!flg) ret++;
  }
  
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
long long Cn_2(int i){
	return 1LL * i * (i - 1) / 2; 
}
int main()
{
	map < int, int > m; 
	int n; cin >> n; 
	int a[n]; for(int & i : a) cin >> i, ++ m[i]; 
	
	long long sum = 0; 
	for(auto i : m)
		if(i.second >= 2)
			sum += Cn_2(i.second); 

	for(int i : a)	
		cout << sum - Cn_2(m[i]) + Cn_2(m[i] - 1) << "\n"; 

	return 0; 
}

Measured memory_bytes: 8320
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll MOD = 1e9+7;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill((T*)array, (T*)(array+N),val);}

void chmax(pll &a, pll b){
	if(a.first<b.first) a.second = max(a.first,b.second), a.first = b.first;
	else a.second = max(a.second,b.first);
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int n; cin>>n;
	vector<ll> a(1<<n); vector<pll> dp(1<<n);
	rep(bit,1<<n){
		cin>>a[bit];
		dp[bit] = {a[bit],-INF};
	}
	rep(i,n) rep(bit,1<<n) if(bit&(1<<i)) chmax(dp[bit],dp[bit^(1<<i)]);
	ll res = -INF;
	rep(bit,1<<n){
		ll tmp = dp[bit].first + dp[bit].second;
		res = max(res,tmp);
		if(bit) cout<<res<<endl;
	}
  return 0;
}


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

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

	ll n;
	cin >> n;

	ll	digit;
	ll count;
	digit = 1;
	count = -1;
	while (n / digit)
	{
		digit *= 10;
		count++;
	}
	ll nine;
	nine = n / (digit / 10) - 1 + 9 * count;
	ll temp;
	temp = n;
	ll original;
	original = 0;
	while (temp)
	{
		original += temp % 10;
		temp /= 10;
	}
	ll subtle;
	subtle = 0;
	n -= n % 10;
	n--;
	while (n)
	{
		subtle += n % 10;
		n /= 10;
	}
	cout << max({original, nine, subtle}) << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
 
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<VVLL> VVVLL;

#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())
 
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_LARGE = 1000000100;
 
 
//debug func
template<typename T>
void vecprint(vector<T> v) {
    for(auto x : v) {
        cerr << x << " ";
    }
    cerr << endl;
}
 
template<typename T>
void vecvecprint(vector<vector<T>> vv) {
    REP(i, SIZE(vv)) {
        REP(j, SIZE(vv[i])) {
            cerr << vv[i][j] << " ";
        }
        cerr << endl;
    }
}
 
template<typename T>
void pqprint(priority_queue<T> q) {
    while(!q.empty()) {
        cerr << q.top() << " ";
        q.pop();
    }
    cerr << endl;
}
 
template<typename T>
void qprint(queue<T> q) {
    while(!q.empty()) {
        cerr << q.front() << " ";
        q.pop();
    }
    cerr << endl;
}
 
template<typename T>
void vecqprint(vector<queue<T>> v) {
    for(int i = 0; i < v.size(); i++) {
        qprint(v[i]);
    }
}
 
template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k, const Iterator last)
{
   /* Credits: Thomas Draper */
   if ((first == last) || (first == k) || (last == k))
      return false;
   Iterator itr1 = first;
   Iterator itr2 = last;
   ++itr1;
   if (last == itr1)
      return false;
   itr1 = last;
   --itr1;
   itr1 = k;
   --itr2;
   while (first != itr1)
   {
      if (*--itr1 < *itr2)
      {
         Iterator j = k;
         while (!(*itr1 < *j)) ++j;
         iter_swap(itr1,j);
         ++itr1;
         ++j;
         itr2 = k;
         rotate(itr1,j,last);
         while (last != j)
         {
            ++j;
            ++itr2;
         }
         rotate(k,itr2,last);
         return true;
      }
   }
   rotate(first,k,last);
   return false;
}

inline double get_time_sec(void){
    return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count())/1000000000;
}

template<typename T>
T gcd(T a, T b) {
    if(a > b) swap(a, b);
    if(a == 0) return b;
    else return gcd(b%a, a);
}

template<typename T>
map<T, T> prime_list(T n) {
    map<T, T> ret;
    for(T i = 2; i*i <= n; i++) {
        if(n % i == 0) {
            ret[i] = 0;
            while(n % i == 0) {
                n /= i;
                ret[i]++;
            }
        } 
    }
    if(n != 1) ret[n]++;
    return ret;
}

int main(void) {
    int r;
    cin >> r;
    cout << r*r << endl;
}

Measured memory_bytes: 256
/*  
*  Sachin Mittal
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define M 998244353
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define rep(i,j,n) for(int i=j;i<n;i++)
#define F first
#define S second
#define lb lower_bound
#define mem0(dp) memset(dp,0,sizeof(dp))
#define mem1(dp) memset(dp,-1,sizeof(dp))
#define pb push_back
#define sz(s) (int)(s.size())
#define debug(x) cout << #x << " = " << x << '\n';


void solve()
{
  int n;
  cin >> n;
  map<string, int> s;
  rep(i, 0, n){
    string c;
    cin >> c;
    s[c]++;
  }
  cout << "AC x " << s["AC"] << '\n';
  cout << "WA x " << s["WA"] << '\n';
  cout << "TLE x " << s["TLE"] << '\n';
  cout << "RE x " << s["RE"] << '\n';
}

int32_t main(){
ios_base::sync_with_stdio(false); 
cin.tie(0); cout.tie(0);
int tst = 1;
//cin >> tst;
while(tst--)
{
  solve();
}
}

Measured memory_bytes: 3656
#include<stdio.h>
#include<string.h>

int main(void){
	int i,l,p;
	char s[16],t[16]={0};
	scanf("%s",&s);
	l = strlen(s);
	p = 0;
	for(i = 0;i < l;i++){
		if(s[i] == '0'){t[p] = '0';p++;}
		if(s[i] == '1'){t[p] = '1';p++;}
		if(s[i] == 'B'){if(p != 0){t[p-1] = 0;p--;}}
	}
	printf("%s\n",t);
	return 0;
}

Measured memory_bytes: 128
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

h, w, k = map(int, input().split())
c = []
black = 0
for _ in range(h):
    c.append(list(input()))
for i in c:
    black += i.count("#")

cnt = 0
for i in range(2**h):
    s = set()
    delete = 0
    i_bin = bin(i)[2:].zfill(h)
    for x in range(h):
        if i_bin[x] == "1":
            for y in range(w):
                if c[x][y] == "#":
                    delete += 1
                    s.add(x)
    for j in range(2**w):
        delete_ = delete
        j_bin = bin(j)[2:].zfill(w)
        for y in range(w):
            if j_bin[y] == "1":
                for x in range(h):
                   
                    if x not in s and c[x][y] == "#":
                        delete_ += 1
        if black - delete_ == k:
            cnt += 1
print(cnt)



Measured memory_bytes: 74228
#pragma target("avx")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define rep(i,b,e) for(ll i=b; i<e; i++)
#define be(vec) vec.begin(),vec.end()
#define print(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define scan(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	char s[3];
	rep(i, 0, 3) s[i] = getchar();
	std::sort(s, s+3);
	if(strcmp(s, "abc")) puts("No");
	else puts("Yes");
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, A: int, B: int):
    print(min(N * A, B))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
N = gets.to_i
xys = Array.new(N)
N.times do |i|
  a = gets.to_i
  xys[i] = a.times.map { gets.split.map(&:to_i) }
end

def comb(n, acc = [])
  if n == 0
    return [acc]
  end
  acc2 = acc.dup
  acc.push(true)
  acc2.push(false)
  ret1 = comb(n - 1, acc)
  ret2 = comb(n - 1, acc2)
  ret1 + ret2
end

def is_ok?(bl, xys)
  bl.each.with_index do |b, i|
    next unless b
    list = xys[i]
    list.each do |x, y|
      x -= 1
      return false if y == 1 && bl[x] == false
      return false if y == 0 && bl[x] == true
    end
  end
  true
end

comb1 = comb(N)
ans = 0
comb1.each do |bl|
  if is_ok?(bl, xys)
    c = bl.count { |b| b }
    ans = c if c > ans
  end
end
puts ans


Measured memory_bytes: 15484
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-6;
const ll LINF = 100200300400500600ll;
const int INF = 1001001001;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
const int dx[4] = {0,1,0,-1};
const int dy[4] = {-1,0,1,0};
const int mod = 1000000007;
#define Yes(ifeq) cout<<(( ifeq )? "Yes":"No")<<endl;

void Main(){
  int n,x,y;
  cin>>n>>x>>y;
  x--; y--;
  vi ans(n,0);
  rep(i,n) rep(j,n) if(i<j) {
    int k = min(abs(i-x) + abs(j-y) + 1 , j-i);
    ans[k]++;
  }
  srep(i,1,n){
    cout<<ans[i]<<endl;
  }
} signed main(int argc,char** argv)
{fastio; myio; myloopset Main();}


Measured memory_bytes: 256
from operator import itemgetter
N,M = map(int, input().split())

l = []
for i in range(N):
    l.append(list(map(int, input().split())))

l.sort(key=itemgetter(0))
sum = 0
for i in range(len(l)):
    a,b = map(int, l[i])
    if M - b >= 0:
        sum += a * b
        M -= b
    else:
        sum += a * M
        M = 0

    if M == 0:
        break

print(sum)

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

sum=0
for i in range(n):
    sum=sum+b[i]
    if i>0 and a[i-1] == a[i]-1:
        sum=sum+c[a[i]-2]
print(sum)

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

int main() {
    vector< vector<int> > c;
    for (int i = 0; i < 3; i++) {
        vector<int> ci;
        for (int j = 0; j < 3; j++) {
            int cij;
            cin >> cij;
            ci.push_back(cij);
        }
        c.push_back(ci);
    }

    vector<int> a;
    a.push_back(0);
    a.push_back(c.at(1).at(0) - c.at(0).at(0));
    a.push_back(c.at(2).at(0) - c.at(0).at(0));
    vector<int> b;
    b.push_back(c.at(0).at(0));
    b.push_back(c.at(0).at(1));
    b.push_back(c.at(0).at(2));

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            if (a.at(i) + b.at(j) != c.at(i).at(j)) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
c = []
c.append(list(map(int, input().split())))
c.append(list(map(int, input().split())))
c.append(list(map(int, input().split())))
a = []

for i in range(3):
  a.append([c[i][0] - c[i][1], c[i][1] - c[i][2]])

if a[0] == a[1] and a[0] == a[2]:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys
from collections import Counter

def solve(n: int, S: "List[str]"):
    counter_list = [Counter(S[i]) for i in range(n)]

    a = dict(counter_list[0].items())
    a_keys = list(counter_list[0].keys())
    for cl in counter_list[1:]:
        for key,value in list(cl.items()):
            if key in a_keys and a[key]>value:
                a[key] = value

    for cl in counter_list[1:]:
        for key in list(a.keys()):
            if key not in list(cl.keys()):
                a.pop(key)
    
    answer = ""
    for key,value in a.items():
        answer += key*value
    answer = list(answer)
    answer.sort()
    print("".join(answer))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    S = [next(tokens) for _ in range(n)]  # type: "List[str]"
    solve(n, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int n, pre[4001][3];
string s;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> s;
	s = ' ' + s;
	long long sum = 0;
	for(int i = 1; i <= n; i++)
		if(s[i] == 'R')
			pre[i][0] = pre[i - 1][0] + 1, pre[i][1] = pre[i - 1][1], pre[i][2] = pre[i - 1][2];
		else if(s[i] == 'G')
			pre[i][1] = pre[i - 1][1] + 1, pre[i][0] = pre[i - 1][0], pre[i][2] = pre[i - 1][2];
		else pre[i][2] = pre[i - 1][2] + 1, pre[i][0] = pre[i - 1][0], pre[i][1] = pre[i - 1][1];
	for(int i = 1; i <= n; i++)
		for(int j = 1; j < i; j++)
			if(s[i] != s[j]){
				set<int> st = {'R', 'G', 'B'};
				st.erase(s[i]), st.erase(s[j]);
				int k = (*st.begin() == 'B') ? 2 : (*st.begin() == 'G'); 
				sum += pre[i - 1][k] - pre[j][k];
				if((i - j - 1) % 2 && s[j + (i - j) / 2] == *st.begin()) sum -= 1;
			}
	cout << sum << "\n";
	return 0;
}

Measured memory_bytes: 3720
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
int main()
{	
	char x[105];
	int h = 0,w = 0;
	scanf("%d %d",&h,&w);
	for(int i = 1;i <= h;i ++)
	{	scanf("%s",x);
		printf("%s\n",x);
		printf("%s\n",x);
		}
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

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

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin>>n;
	cout<<(n*(n-1))/2<<"\n";
	return 0;
}





























Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    ll cur = N;
    ll k = -2;
    string ans = "";
    if(cur == 0){
        cout << 0 << endl;
        return 0;
    }
    while(cur != 0){
        ll r = cur % k;
        if(r != 0){
            ans = "1" + ans;
            cur--;
        }else{
            ans = "0" + ans;
        }
        cur /= k;
        //cout << cur << endl;
        //k *= (-2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

class State {
public:
	int cost;
	int x, y;
	int next;//0??§?¬?????¶??§????,1??§?¬?????¶??§????

	State(int c, int _x, int _y, int n) :cost(c), x(_x), y(_y), next(n){}

	/*
	bool operator < (const State& obj) const
	{
		return cost < obj.cost;
	}
	*/

	bool operator > (const State& obj) const
	{
		return cost > obj.cost;
	}
};

const int INF = 1 << 29;
const int MAXW = 30;
const int MAXH = 60;
const int dx[9] = { 1,1,1,1,1,2,2,2,3 };//leftx+dx or rightx-dx
const int dy[9] = { -2,-1,0,1,2,-1,0,1,0 };//lefty+dy or righty+dy

int w, h;

bool isranged(int x, int y)
{
	return (x >= 0 && x < w&&y >= 0 && y < h);
}

int main()
{
	while (true) {
		cin >> w >> h;

		if (w == 0 && h == 0) {
			break;
		}

		char grid[MAXH][MAXW];
		int dp[MAXH][MAXW][2];
		priority_queue<State, vector<State>, greater<State>> pq;

		rep(i, h) {
			rep(j, w) {
				rep(k, 2) {
					dp[i][j][k] = INF;
				}
			}
		}

		rep(i, h) {
			rep(j, w) {
				cin >> grid[i][j];
			}
		}

		rep(i, w) {
			if (grid[h - 1][i] == 'S') {
				pq.push(State(0, i, h - 1, 0));
				pq.push(State(0, i, h - 1, 1));
				dp[h - 1][i][0] = 0;
				dp[h - 1][i][1];
			}
		}

		while (pq.empty() == false) {
			State temp = pq.top();
			pq.pop();

			if (temp.cost > dp[temp.y][temp.x][temp.next]) {
				continue;
			}

			if (grid[temp.y][temp.x] == 'T') {
				continue;
			}

			if (temp.next == 0) {
				rep(i, 9) {
					int nx = temp.x + dx[i];
					int ny = temp.y + dy[i];

					char tmp = grid[ny][nx];
					if (tmp == 'X') {
						continue;
					}

					int nc = 0;
					if (tmp != 'S' && tmp != 'T') {
						nc = tmp - '0';
					}

					if (isranged(nx, ny) == true) {
						if (dp[ny][nx][1] > temp.cost + nc) {
							dp[ny][nx][1] = temp.cost + nc;
							pq.push(State(dp[ny][nx][1], nx, ny, 1));
						}
					}
				}
			}
			else {
				rep(i, 9) {
					int nx = temp.x - dx[i];
					int ny = temp.y + dy[i];

					char tmp = grid[ny][nx];
					if (tmp == 'X') {
						continue;
					}

					int nc = 0;
					if (tmp != 'S' && tmp != 'T') {
						nc = tmp - '0';
					}

					if (isranged(nx, ny) == true) {
						if (dp[ny][nx][0] > temp.cost + nc) {
							dp[ny][nx][0] = temp.cost + nc;
							pq.push(State(dp[ny][nx][0], nx, ny, 0));
						}
					}
				}
			}
		}

		int ans = INF;

		rep(i, w) {
			if (grid[0][i] == 'T') {
				rep(j, 2) {
					ans = min(ans, dp[0][i][j]);
				}
			}
		}

		if (ans == INF) {
			cout << -1 << endl;
		}
		else {
			cout << ans << endl;
		}
	}

	return 0;
}

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

int main() {
  int r, d, x;
  cin >> r >> d >> x;
  for (int i = 0; i < 10; i++) {
    x = r * x - d;
    cout << x << '\n';
  }

  return 0;
}


Measured memory_bytes: 3512
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>

using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = n - 1; i >= 0; i--)

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)


#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

string S;

int main(){
  cin >> S;
  int f = stoi(S.substr(0, 2));
  int b = stoi(S.substr(2, 2));

  if(f > 12 || f == 0) {
    if(b > 12 || b == 0) {
      cout << "NA" << endl;
    } else {
      cout << "YYMM" << endl;
    } 
  } else {
    if (b > 12 || b == 0) {
      cout << "MMYY" << endl;
    } else {
      cout << "AMBIGUOUS" << endl;
    }
  }
  

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int n = 0;
  int a[100];
  int i;

  scanf("%d", &n);

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

  for(i = n - 1; i > 0; i--)
    printf("%d ", a[i]);

  printf("%d\n", a[i]);

  return 0;
}

Measured memory_bytes: 596
import sys
sys.setrecursionlimit(10**6)

#a = int(input())
#b = list(map(int, input().split()))
a, b = map(int, input().split())
#s = input()
#s,t = input().split()
#a = [int(input()) for _ in range(n)]
#
#readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]

if a > b:
    print(2*a-1)
elif a == b:
    print(2*a)
else:
    print(2*b-1)

Measured memory_bytes: 9164
// Vacation
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define times(t) int t; cin >> t; while(t--)
#define mod 1000000007
#define pb push_back
#define mp make_pair

void solve() {
	int n; cin >> n;
	int arr[n][3], dp[n+1][3];
	for(int i=0; i<n; i++) {
		cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
	}
	dp[0][0] = arr[0][0];
	dp[0][1] = arr[0][1];
	dp[0][2] = arr[0][2];
	for(int i=1; i<=n; i++) {
		dp[i][0] = arr[i][0] + max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = arr[i][1] + max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = arr[i][2] + max(dp[i-1][1], dp[i-1][0]);
	}
	cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << endl;
	return;
}

int main() {
	IOS;
	// #ifndef ONLINE_JUDGE
	// freopen("C:/Gen code/CompProg/input.txt", "r", stdin);
	// freopen("C:/Gen code/CompProg/output.txt", "w", stdout);
	// #endif
	solve();
	return 0;
}

Measured memory_bytes: 5924