akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;
const int NMAX = 2000000;

int maximum_profit(int *r, int n) {
	int mini = r[0];
	int maxi = r[1] - r[0];
	for(int i = 1; i < n; i++) {
		maxi = max(maxi, r[i]-mini);
		mini = min(mini, r[i]);
	}

	return maxi;
}

int main(void)
{
	int *r;
	r = new int[NMAX];

	int n;
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> r[i];
		// cout << r[i] << endl;
	}

	int max = maximum_profit(r, n);
	cout << max << endl;

	delete r;
	return 0;
}


Measured memory_bytes: 3544
import java.util.Scanner;

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

        long[] cur = new long[W + 1];
        long[] pre = new long[W + 1];
        for (int i = 0; i < N; i++) {
            int w = in.nextInt();
            long v = in.nextLong();
            for (int j = w; j <= W; j++) {
                cur[j] = Math.max(pre[j], pre[j - w] + v);
            }
            System.arraycopy(cur, 0, pre, 0, W + 1);
        }
        in.close();
        System.out.println(cur[W]);
    }
}

Measured memory_bytes: 25940
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;

ll a[200005], pref[200005];

map<ll,int> mapa;

int main(){

    int n, k; cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    ll res = 0;
    mapa[0] = 1;
    for(int i = 1; i <= n; i++){
        pref[i] = (pref[i-1] + a[i] - 1 + k)%k;
        if(i-k >= 0) mapa[pref[i-k]]--;
        // cout << i << " " << mapa[pref[i]] << endl;
        res += mapa[pref[i]];
        mapa[pref[i]]++;
    }
    cout << res << endl;
	return 0;
}


Measured memory_bytes: 15872
#include<stdio.h>
#define N 1000000

int a[N];
int cnt=0;
int G[N];
int m=1;

void insertionSort(int n,int g){
	for(int i=g;i<n;i++){
		int v=a[i];
		int j=i-g;
		while(j>=0 && a[j] > v){
			a[j+g]=a[j];
			cnt++;
			j=j-g;
		}
		a[j+g]=v;
	}
	return;
}


void shellSort(int n){
	int temp=n;
	
	G[0]=1;
	
	while(1){
		G[m]=G[m-1]*3+1;
		if(G[m] > n)break;
		m++;
	}
	
	for(int i=m-1;i>=0;i--)
		insertionSort(n,G[i]);
	
	return;
}



int main(){
	int n,i;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	
	shellSort(n);
	
	
	printf("%d\n",m);
	for(i=m-1;i>0;i--)
		printf("%d ",G[i]);
	printf("%d\n",G[0]);
	
	printf("%d\n",cnt);
	
	for(i=0;i<n;i++)
		printf("%d\n",a[i]);
	
	return 0;
	
}


Measured memory_bytes: 5596
import sys
t='X'
for e in sys.stdin:
 for i in'0123456789'[(e[0]==t)*(e[1]!='+')or('+X'in e)*('+X='not in e)or(e[-2:]=='=X'):]:
  l,r=e.replace(t,i).split('=')
  if sum(map(int,l.split('+')))==int(r):print(i);break
 else:print('NA')


Measured memory_bytes: 5612
use std::io;
use std::cmp;


fn main() {
    let (n, m) = {
        let i = read::<isize>();
        (i[0], i[1])
    };

    let mut l = 0;
    let mut r = n;

    for _ in 0..m {
        let (a, b) = {
            let i = read::<isize>();
            (i[0], i[1])
        };

        l = cmp::max(l, a);
        r = cmp::min(r, b);
    }

    println!("{}", cmp::max(0, r - l + 1));
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
let inp = readLine()!.split(separator: " ").map { Int($0)! }

var a = inp[0]
var b = inp[1]
var c = inp[2]

var k = Int(readLine()!)!

while k > 0 && (b <= a || c <= b) {
  if b <= a {
    b *= 2
  } else if c <= b {
    c *= 2
  }
  k -= 1
}
print(b > a && c > b ? "Yes" : "No")

Measured memory_bytes: 8192
#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
#define pp pair<int,int>

int main(){
    int N,M;
    cin >> N >> M;
    vector< vector<pp> > A(N);
    for(int i=0; i<M; ++i) {
        int P, Y;
        cin >> P >> Y;
        A[P-1].push_back(pp(Y,i));
    }
    vector<pp> B(M);
    for(int i=0; i<N; ++i) {
        sort(A[i].begin(), A[i].end());
        for(int j=0; j < A[i].size(); ++j) {
            B[A[i][j].second] = pp(i,j);
        }
    }
    for(int i=0; i<M; ++i) {
        printf("%06d%06d\n", B[i].first + 1, B[i].second + 1);
    }
}

Measured memory_bytes: 7680
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(void)
{
string s;
cin>>s;
long long ans=0;
int size=s.size();
int count=0;
for(int i=0;i<=size;i++)
{
if(s[i-1]=='B')
{
ans+=size-i-count;
count++;
}
}
cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
using namespace std;

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

	//maybe unsigned int better

	vector < vector<long long>>  vec(N , vector< long long>( 2) ) ;

	for (int i = 0; i < N; i++) {
		cin >> vec.at(i).at(0) >> vec.at(i).at(1);
	}

	sort(vec.begin(), vec.end());

	int sum = 0;
	long long cost = 0;
	for (int i = 0; i < N ; i++) {

		if (sum + vec.at(i).at(1) <= M) {
			cost += vec.at(i).at(0) * vec.at(i).at(1);
			sum += vec.at(i).at(1);
		}
		else {
			cost += vec.at(i).at(0) * (M - sum);
			break;
		}
		
	}

	cout << cost << endl;

}

Measured memory_bytes: 5760
#include<iostream>


int *func(int N,int Y)
{
	int ans[3] = { -1,-1,-1 };
	for (int i = 0; i <= N; ++i)
	{
		for (int j = 0; j <= N - i; ++j)
		{
			int sum = i * 10000 + j * 5000;
			if ((Y - sum) / 1000 == N - i - j)
			{
				ans[0] = i;
				ans[1] = j;
				ans[2] = N - i - j;
			}
		}
	}
	
	std::cout << ans[0] << " " << ans[1] << " " << ans[2];
	return ans;

	
}
int main()
{
	int N,Y;
	std::cin >> N >> Y;

	
	func(N,Y);
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>N;
    vec a(N);
    rep(i,N) cin>>a[i];
    a.push_back((1LL << 20) - 1);
    L = 0;
    ll ans = 0, sum = a[0];
    reps(i,1,N+1){
        while(((sum ^ a[i]) != sum + a[i]) || (i == N && L < N)){
            ans += i - L;
            sum -= a[L];
            ++L;
        }
        sum += a[i];
    }
    cout<<ans<<endl;
}


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

int main(){
   int A, B, C, D;
   cin >> A >> B >> C >> D;
   while(A > 0 && C > 0){
       C -= B;
       if(C <= 0) { cout << "Yes"; return 0;}
       A -= D;
       if(A <= 0) { cout << "No"; return 0;}
   }
}

Measured memory_bytes: 3624
N, *abc = map(int, open(0).read().split())
plan = list(zip(*[iter(abc)]*3))
profit = [[0]*3 for _ in range(N)]
profit[0] = [p for p in plan[0]]
# ２つの遷移元から来たときの最大幸福値を求めていく
for day in range(1, N):
    # 次の行動 0=A 1=B 2=C
    for n_plan in range(3):
        max_plofit = max([pr + plan[day][n_plan]
            if n_plan != i
            else 0
            for i, pr in enumerate(profit[day-1])])
        profit[day][n_plan] = max_plofit      
print(max(profit[N-1]))

Measured memory_bytes: 42860
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >> c;

  if(a == b && b == c){
    if(a % 2 == 1) cout << 0 << endl;
    else cout << -1 << endl;
    return 0;
  }

  int ans = 0;
  while(a%2==0 && b%2==0 && c%2==0){
    int at = a;
    int bt = b;
    int ct = c;
    a = bt/2 + ct/2;
    b = at/2 + ct/2;
    c = at/2 + bt/2;

    ans++;
  }

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    string s;
    int a[26] = {};
    int cnt = 0;

    cin >> s;


    for (int i = 0; i < s.size(); i++) {
        a[s[i]-'A']++;
    }

    for (int i = 0; i < 26; i++) {
        if (a[i] == 2) {
            cnt++;
        }
    }

    if (cnt == 2) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }


}


Measured memory_bytes: 256
/*"永遠の物語"*/
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double D;
typedef pair<int,int> Pii;
#define mp(a,b) make_pair(a,b)
#define fir first
#define sec second
inline int min(int _a,int _b){return _a<_b?_a:_b;}
inline int max(int _a,int _b){return _a>_b?_a:_b;}
template<class _T>inline void rd(_T &_a){int _f=0,_ch=getchar();_a=0;while(_ch<'0' || _ch>'9'){if(_ch=='-')_f=1;_ch=getchar();}while(_ch>='0' && _ch<='9')_a=(_a<<1)+(_a<<3)+_ch-'0',_ch=getchar();if(_f)_a=-_a;}
const int inf=0x3f3f3f3f;
const D eps=1e-8;
const int N=1e5+5;
int a[N];
int main(){
	//clock_t start=clock();
	//freopen("test.in","r",stdin);
	//freopen("test.out","w",stdout);
	int k,f=1;LL l=2,r=2;rd(k);
	for(int i=1;i<=k;i++)rd(a[i]);
	for(int i=k;i && f;i--){f&=(l-1)/a[i]<r/a[i];l=((l-1)/a[i]+1)*a[i];r=(r/a[i]+1)*a[i]-1;}
	if(f)printf("%lld %lld",l,r);else puts("-1");
	//printf("\n%dms",(int)((double)(clock()-start)/CLOCKS_PER_SEC*1000));
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <bitset>

using ll = long long;

using namespace std;

#define MAX 200010

#define popcount(x) (int)bitset<32>(x).count()

int main() {
    int n;
    cin >> n;
    int f[MAX];
    f[0] = 0;
    for (int i=1; i<MAX; i++) {
        f[i] = f[i % popcount(i)] + 1;
    }
    string x; cin >> x;
    int pc = 0;
    for (auto &c:x) {
        if (c == '1') pc++;
    }
    // cerr << bitset<32>(x).to_ulong() << ' ' << pc << ' ' << bitset<32>(x).to_ulong() % (pc + 1) << ' ' << bitset<32>(x).to_ulong() % (pc - 1) << '\n';
    int up[n], down[n], upr = 0, downr = 0;
    up[n-1] = down[n-1] = 1;
    for (int i=n-1; i>0; i--) {
        up[i-1]   = (up[i] * 2) % (pc + 1);
        if (pc > 1) {
            down[i-1] = (down[i] * 2) % (pc - 1);
        }
    }
    for (int i=n-1; i>=0; i--) {
        if (x[i] == '1') {
            upr = (upr + up[i]) % (pc + 1);
            if (pc > 1) downr = (downr + down[i]) % (pc - 1);
        }
    }
        // cerr << upr << ' ' << downr << '\n';
    for (int i=0; i<n; i++) {
        // cerr << up[i] << ' ' << down[i] << '\n';
        if (x[i] == '0') {
            cout << f[(upr + up[i]) % (pc + 1)] + 1 << '\n';
        }
        else if (pc > 1) {
            cout << f[(downr - down[i] + pc - 1) % (pc - 1)] + 1 << '\n';
        } else {
            cout << 0 << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 6068
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int N; cin >> N;
    vector<int> A(3 * N);
    REP(i, 0, 3 * N) cin >> A[i];

    ll lsum = 0, rsum = 0;
    priority_queue<int> R;
    priority_queue<int, vector<int>, greater<int>> L;
    REP(i, 0, N) {
        lsum += A[i];
        L.push(A[i]);
    }
    REP(i, 2 * N, 3 * N) {
        rsum += A[i];
        R.push(A[i]);
    }

    vector<ll> Lsum(N + 1), Rsum(N + 1);
    REP(i, 0, N + 1) {
        Lsum[i] = lsum;
        L.push(A[N + i]);
        lsum += A[N + i]; lsum -= L.top(); L.pop();

        Rsum[N - i] = rsum;
        R.push(A[2 * N - i - 1]);
        rsum += A[2 * N - i - 1]; rsum -= R.top(); R.pop();
    }

    ll ans = -(1LL << 60);
    REP(i, 0, N + 1) ans = max(ans, Lsum[i] - Rsum[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6944
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main()
{
    int k;
    scanf("%d",&k);
    printf("%d\n",a[k-1]);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int a[1919];
int b[1919];
int c[1919];
int main() {
	int n,t;
	cin >> n >> t;
	for (int i = 0; i < n; i++) {
		cin>>a[i];
		cin >> b[i];
		c[i] = a[i] * 10000 + b[i];
	}
	sort(c, c + n);
	for (int i = 0; i < n; i++) {
		if (c[i]%10000<=t) {
			cout << c[i]/10000<< endl;
			return 0;
		}
	}
	cout << "TLE" << endl;
}

Measured memory_bytes: 256
using System;
public class Hello{
    public static void Main(){
        int n = int.Parse(Console.ReadLine());
        string s = Console.ReadLine();
        int ans = 0;
        int temp = 0;
        for(var i = 0;i < n;i++){
            switch(s[i]){
                case 'I':
                    temp++;
                    break;
                case 'D':
                    temp--;
                    break;
                default:
                break;
            }
            ans = Math.Max(ans,temp);
        }
        
        Console.WriteLine(ans);
    }
}


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

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i=0;i<n;i++){
        cin >> d[i];
    }
    sort(d.begin(),d.end());
    reverse(d.begin(),d.end());
    int ans =1;
    for(int i=0;i<n-1;i++){
        if(d[i] > d[i+1]){
            ans ++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    long long a[3];
    cin >> a[0] >> a[1] >> a[2];
    if(a[0]%2==0||a[1]%2==0||a[2]%2==0){
        cout << 0 << endl;
        return 0;
    }else{
        sort(a,a+3);
        cout << a[0]*a[1] << endl;
        return 0;
    }
}

Measured memory_bytes: 3632
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy

sys.setrecursionlimit(10**9)
mod = 998244353
inf = 10**20

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

s,t = LS()
a,b = LI()
u = S()

if u==t:
    print(a,b-1)
else:
    print(a-1,b)

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

#define ll long long
#define pb push_back
#define mp make_pair
int main() 
{
	 ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     
		string s;
		cin>>s;
		int ans=0;
		string s1,s2="";
		for(int i=0;i<(int)s.length();i++)
		{
			s1+=s[i];
			if(s1==s2)
			continue;
			
			s2=s1;
			s1="";
			ans++;
			
			
		}
		cout<<ans<<"\n";
			
				 
	
}


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

int main(){
  int A, B;
  cin >> A >> B;
  
  string ans = "Impossible";
  
  if(A %3 == 0){
    ans = "Possible";
  }
  else if(B %3 == 0){
    ans = "Possible";
  }
  else if((A + B) %3 == 0){
    ans = "Possible";
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<long, long> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
const double EPS=1e-10;


int main(){
    vector<PII>pi(3);
    REP(i,3){
        cin>>pi[i].first>>pi[i].second;
        //if(pi[i].first>pi[i].second)swap(pi[i].first,pi[i].second);
    }
    vector<int>num;
    REP(i,4)num.PB(i+1);
    do{
        int cnt=0;
        REP(i,3)REP(j,3){
            if(min(num[i],num[i+1])==min(pi[j].first,pi[j].second)&&max(num[i],num[i+1])==max(pi[j].first,pi[j].second)){
                cnt++;
            }
        }
        //cout<<" "<<cnt<<endl;
        if(cnt==3){
            cout<<"YES"<<endl;return 0;
        }
    }while(next_permutation(ALL(num)));
    cout<<"NO"<<endl;
    return 0;
}


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

int main(void){

    int a,b;
    string s,t,u;

    cin >> s;
    cin >> t;
    cin >> a;
    cin >> b;

    cin >> u;

    if(u==s){
        a = a-1;
    }else{
        b=b-1;
    }

    cout << a << " " << b << endl;


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int N;
	cin >> N;
	const int mod = 1000000007;
	ll res = 1;
	for (int i = 1;i <= N;i++) {
		res *= i;
		res %= mod;
	}

	cout << res << "\n";
	return 0;
}

Measured memory_bytes: 256
"""
https://atcoder.jp/contests/jsc2019-qual/tasks/jsc2019_qual_c

B -> 1
W -> 0

BWWWWB
100001

反転操作を３つに分解
左端からl-1まで+1
左端からr-1まで+1
rに+1

こうしておくとつまり、右端として選ぶかどうかを決めるだけでよくなる

"""

from math import factorial

N = int(input())
d = {"W":0, "B":1}
ls = [d[s] for s in input()]
r_ls = reversed(ls)
xs = []
mod = 10**9 + 7
# 全部左右とか関係なく取ったとする
for i,r in enumerate(r_ls):
    xs.append(r + i)
# 右でトルものを選ぶ(↑の操作後、mod2が1のところ)
LR = [x%2 for x in list(reversed(xs))]

# Lの数を持ちながら、Rが来たら消化＆場合の数にLの数をかける
cnt = 0 # Lの数
num = 1 # 場合の数

for lr in LR:
    if lr == 0:
        cnt += 1
    else:
        num *= cnt
        cnt -= 1
        cnt = max(0,cnt)
        num %= mod
# LとRのペアが一致していない
if cnt > 0:
    num = 0
ans = num * factorial(N)
print(ans%mod)

Measured memory_bytes: 59900
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000001
#define MOD 1e9+7

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


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

int main(int argc, char *argv[])
{
  int n, w, d;
  cin >> n >> w >> d;
  vector<pair<int,int>> ps;
  // mapping to the south-west corner 
  auto mapping0 = [](int x, int y) {
    return x - y;
  };
  // mapping in one of four directions
  auto mappingX = [w,d,&mapping0](int x, int y, int dir) {
    switch(dir) {
    case 0 : { // (-1, -1)-direction
      int o = mapping0(x, y);
      return o; // o >= 0 ? o : w + w + d + d + o; // normalization
    }
    case 1 : { // (1, -1)-direction
      int o = mapping0(w-x, y); // flipping in x
      return w - o; // o >= 0 ? w - o : w + (- o);
    }
    case 2 : { // (1, 1)-direction
      int o = mapping0(w-x, d-y); // flipping in x and y
      return w + d + o; // o >= 0 ? w + d + o : w + d + o;
    }
    case 3 : { // (-1, 1)-direction
      int o = mapping0(x, d-y); // flipping in y
      return w + d + w - o; // o >= 0 ? w + d + w - o : w + d + w + -o;
    }
    return -1;
    }
  };
  // mapping to a range
  auto make_range = [w,d,&mappingX](int x, int y, char c) {
    switch(c){
    case 'N': return make_pair(mappingX(x, y, 2), mappingX(x, y, 3));
    case 'E': return make_pair(mappingX(x, y, 1), mappingX(x, y, 2));
    case 'S': {
      int s = mappingX(x, y, 0);
      int e = mappingX(x, y, 1);
      if(s < 0) { // normalize to non-negative
        s += d + d + w + w;
        e += d + d + w + w;
      }
      return make_pair(s, e);
    }
    case 'W': {
      int s = mappingX(x, y, 3);
      int e = mappingX(x, y, 0) + w + w + d + d;
      return make_pair(s, e);
    }
    }
    return make_pair(-10, -10);
  };
  
  for(int i = 0; i < n; i++) {
    int x, y, d;
    char c;
    cin >> x >> y;
    cin >> c;
    ps.push_back(make_range(x, y, c));
  }
  // a desk = a range on walls
  // a lock = a point on walls
  // todo: put points so that every range contains a point

  // sort the ranges
  sort(ps.begin(), ps.end());

  // shrink the region (endpoint ee) by the range r
  auto wrap = [d,w](bool aug, int a) {
    return aug ? a + d + d + w + w : a;
  };

  // shrink the region (endpoint ee) by the range r
  auto shrink = [&wrap](bool aug, const pair<int,int> &r, int *ee) {
    int s = wrap(aug, r.first);
    int e = wrap(aug, r.second);
    if(s <= *ee) {
      *ee = min(*ee, e);
      return true;
    }
    return false;
  };
  // locating clocks from i's view
  auto count = [&ps,n,&shrink,&wrap](const int ii){
    int i = ii;
    int k = 0;
    int cnt = 0;
    while(k < n) {
      int e = wrap(i < ii, ps[i].second);
      int kk = k;
      k++;
      i = (i + 1) % n;
      while(k < n && shrink(i < ii, ps[i], &e)) {
        i = (i + 1) % n;
        k++;
      }
      cnt++;
    }
    return cnt;
  };
  

  int cnt = n; // at most n
  // possible starting points
  for(int i = 0; i < n; i++) {
    cnt = min(cnt, count(i));
  }
  cout << cnt << endl;
  return 0;
}




Measured memory_bytes: 3112
import math
l = list(map(int, input().split()))
l.sort()
a, b, c = l[0], l[1], l[2]

if (b-a)%2 == 0:
    ans = c-b+(b-a)//2
else:
    ans = c-b+math.ceil((b-a)/2) + 1
print(ans)

Measured memory_bytes: 3060
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  int a, b, m;
  readf("%s %s %s\n", &a, &b, &m);
  auto as = readln.chomp.split.to!(int[]);
  auto bs = readln.chomp.split.to!(int[]);
  auto cost = as.reduce!(min) + bs.reduce!(min);

  foreach (_; 0..m) {
    int x, y, c;
    readf("%s %s %s\n", &x, &y, &c);
    cost = min(cost, as[x-1] + bs[y-1] - c);
  }
  cost.writeln;
}


Measured memory_bytes: 5424
#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
void solve(){
	ll n;
	cin>>n;
	vector<ll> v(n),res;
	for(ll i=0;i<n;i++)
		cin>>v[i];
	while(!v.empty()){
		ll f=0;
		for(ll i=sz(v)-1;i>=0;i--)
			if(v[i]==i+1){
				res.push_back(i+1);
				f=1;
				break;
			}
		if(!f){
			cout<<"-1";
			return;
		}
		vector<ll> temp;
		for(ll i=0;i<sz(v);i++)
			if(i+1!=res.back())
				temp.push_back(v[i]);
		v=temp;
	}
	reverse(res.begin(),res.end());
	for(ll i=0;i<n;i++)
		cout<<res[i]<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    clock_t z=clock();
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++)
        solve();
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}

Measured memory_bytes: 3776
#include<bits/stdc++.h>
#define MOD 1000000007
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
int n;
int a[30][30];
int dp[30][8388609];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>a[i][j];
		}
	}
	int tot=0;
	for(int i=1;i<=n;i++)
		tot+=(1<<i);
	dp[0][tot]=1;
	for(int s=tot-2;s>=0;s-=2){
		int i=n-__builtin_popcount(s);
		//deal with #i man
		for(int j=1;j<=n;j++){
			if(a[i][j]&&!testbit(s,j)){
				dp[i][s]+=dp[i-1][setbit(s,j)];
				dp[i][s]%=MOD;
			}
		}
	}
	cout<<dp[n][0]<<endl;
	return 0;
}


Measured memory_bytes: 323840
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 1e6 + 5, mod = 998244353; 
int read() {
	int x = 0, f = 1; char ch;
	while(! isdigit(ch = getchar())) (ch == '-') && (f = -f);
	for(x = ch^48; isdigit(ch = getchar()); x = (x << 3) + (x << 1) + (ch ^ 48));
	return x * f;
}
template <class T> T Max(T a, T b) { return a > b ? a : b; }
template <class T> T Min(T a, T b) { return a < b ? a : b; }
int n, sum, t[N], inv[N], ans[N];
int main() {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read();
	for(int i = 1; i <= n; ++ i) t[read()] ++;
	inv[1] = 1;
	for(int i = 2; i < N; ++ i) inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
	for(int i = N - 1; i; -- i) {
		int s1 = 0, s2 = 0;
		for(int j = i; j < N; j += i) {
			s1 = (s1 + 1LL * t[j] * j % mod) % mod;
			s2 = (s2 + 1LL * t[j] * j % mod * j % mod) % mod;
		}
		ans[i] = (1LL * s1 * s1 - s2 + mod) % mod;
		for(int j = i + i; j < N; j += i) ans[i] = (ans[i] - ans[j] + mod) % mod;
	}
	for(int i = 1; i < N; ++ i) sum = (sum + 1LL * ans[i] * inv[i] % mod) % mod;
	printf("%d\n", 1LL * sum * inv[2] % mod);
	fclose(stdin);
	fclose(stdout);
	return 0;
}


Measured memory_bytes: 11904
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

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

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {//239///F.Sugoroku
	int n;
	cin>>n;
	int hun = n/100;
	n-=hun*100;
	int cnt = 0;
	for(int i=5;i>0;i--) {
		cnt+=n/i;
		n%=i;
	}
	if(cnt<=hun)cout<<1;
	else cout<<0;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


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

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int in() {int x; cin>>x; return x;}
string stin() {string s; cin>>s; return s;}
/***** MAIN *****/
signed main() {
  int a, b, n;
  cin >> a >> b >> n;
  int ans;
  if(n < b) {
    ans = a * n;
    ans /= b;
  } else {
    ans = a * (b-1);
    ans /= b;
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define sz(c)       int(c.size())
#define rep(i,a,b)  for (int i=a; i<(b); ++i)
#define per(i,a,b)  for (int i=(b)-1; i>=(a); --i)
#define fore(c,...) for (auto __VA_ARGS__:(c))
using namespace std;
typedef long long ll;



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	array<int,3> row = {}, col = {};
	int d1 = 0, d2 = 0;
	unordered_map<int,pair<int,int>> pos;
	rep(i,0,3) rep(j,0,3) {
		int x;
		cin >> x;
		pos[x] = {i,j};
	}

	int N;
	cin>>N;
	rep(i,0,N) {
		int x;
		cin >> x;
		if (!pos.count(x)) {
			continue;
		}
		int r,c;
		tie(r,c) = pos[x];
		row[r]++;
		col[c]++;
		if (r==c) d1++;
		if (r==2-c) d2++;
	}

	bool yes=d1>=3 || d2>=3;
	rep(i,0,3) if (row[i]>=3 || col[i]>=3) yes=true;
	cout<<(yes?"Yes":"No")<<'\n';
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    int i;
    int count=0;
    sc.close();

    for(i=0;i<3;i++){
      if(s.charAt(i)=='1'){
        count++;
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
int main() {
  int a, b, x;
  cin >> a >> b >> x;
  if (a <= x) {
    if (a+b >= x) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        { 
            int N = Convert.ToInt32(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(i => Convert.ToInt32(i)).ToList();
            A.Insert(0, 0);
            List<int> ballList = new List<int>(A);
            int count = 0;
            for (var i = N; i >= 1; --i)
            {
                ballList[i] = A[i];
                for (var j = i + i; j <= N; j += i)
                {
                    ballList[i] ^= ballList[j];
                }
                count += ballList[i];
            }

            Console.WriteLine(count);
            bool isFirst = true;
            for (var i = 1; i <= N; i++)
            {
                if (ballList[i] == 1)
                {
                    if (isFirst)
                    {
                        Console.Write($"{i}");
                        isFirst = false;
                    }
                    else
                    {
                        Console.Write($" {i}");
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 27220
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int ans=0;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='o'){
      ans++;
    }
  }
  if(ans+(15-s.size())>7){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,m;
  cin >> n >> m;
  int c[26];mem(c);
  rep(i,n) {
    string s;
    R s;
    c[s[0]-'A']++;
  }
  int ans=0;
  while(1) {
    sort(c,c+26,greater<int>());
    int cnt=0;
    rep(i,26) {
      if(c[i]) {
        c[i]--;
        cnt++;
      }
      if(cnt==m) break;
    }
    if(cnt==m) ans++;
    else break;
  }
  pr(ans);
}

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


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

using namespace std;

int main(){
	
	int i,n,m;
	cin>> n>> m;
	int arr[n];
	for(i = 0;i < n;i++){
		cin>> arr[i];
	}
	int sum = 0,cnt =  0;
	for(i = 0;i < n;i++)
		sum += arr[i];
	for(i = 0;i < n;i++){
		if((arr[i] *4*m) >= sum)
			cnt++;
	}
	if(cnt < m)
		cout<< "No"<<endl;
	else
		cout<<"Yes"<<endl;

}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   int a = sc.nextInt();
   int b = sc.nextInt();
   int result = 0;
   List<Integer> list = new ArrayList<Integer>();
   for(int i = 1; i <= 999; i++){
    if(i ==1){
      list.add(1);
    } else{
      list.add((1 + i)  * i / 2);
    }
   }
   for(int i = 0; i < 999; i++){
     if(list.get(i) - a == list.get(i+1) - b){
      result = list.get(i) - a;
      break;
     }
   }
   System.out.println(result);
  }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long INF = 1LL << 60;
template <class T> bool chmin(T& a, T b){if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b){if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  long long N, K;
  string S;
  cin >> N >> K >> S;
  
  vector<long long> V;
  if (S.at(0) == '0') V.push_back(0);
  for (long long i = 1, cnt = 1; i < N; i++)
  {
    if (S.at(i - 1) == S.at(i)) cnt++;
    else 
    {
      V.push_back(cnt);
      cnt = 1;
    }
    if (i == N - 1) V.push_back(cnt);
  }
  if (S.at(N - 1) == '0') V.push_back(0);
  
  long long ans = 0;
  long long M = K * 2 + 1;
  int L = V.size();
  if (M >= L) ans = N;
  else
  {
    for (int i = 0; i < L - M + 1; i += 2)
    {
      long long A = 0;
      for (int j = 0; j < M; j++)
      {
        A += V.at(i + j);
      }
      //cout << A << endl;
      chmax(ans, A);
    }
  }
  //cout << endl;
  
  //for (int i = 0; i < V.size(); i++) cout << V.at(i) << endl;
  //cout << endl;
  
  cout << ans << endl;
}

Measured memory_bytes: 1528
use std::collections::HashMap;

macro_rules! get_one {
    ($t:ty) => {{
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse::<$t>().unwrap()
    }};

    ($t:ty; $n:expr) => {
        (0..$n).map(|_| get_one!($t)).collect::<Vec<_>>()
    };
}

fn main() {
    let n = get_one!(usize);

    let hm = factor(n as i64);

    let a: i64 = hm.iter()
        .map(|(_, &v)| {
            max_triangle_num(v)
        }).sum();
    println!("{}", a)
}

fn factor(n: i64) -> HashMap<i64, i64> {
    let mut n = n;
    let mut hm = HashMap::new();
    if n == 1 {return hm};

    let mut p = 2;
    while n != 1 && n >= p * p {
        while n % p == 0 {
            n /= p;
            let count = hm.entry(p).or_insert(0);
            *count += 1;
        }
        p += 1;
    }
    if n != 1 {
        hm.insert(n, 1);
    }
    hm
}

fn max_triangle_num (n: i64) -> i64 {
    let mut m = 1;
    while m * (m + 1) / 2 <= n {
        m += 1;
    }
    return m - 1
}

#[test]
fn test_max_triangle_num() {
    assert_eq!(max_triangle_num(1), 1);
    assert_eq!(max_triangle_num(2), 1);
    assert_eq!(max_triangle_num(3), 2);
    assert_eq!(max_triangle_num(4), 2);
    assert_eq!(max_triangle_num(5), 2);
    assert_eq!(max_triangle_num(6), 3);
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){

  string s;
  cin >> s;
  rep(i,s.size())if(s[i] == '?')s[i] = 'D';
  
  


cout << s << endl;



  return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	if (v.size()) {
		os << v[0];
		for (int i = 1; i < v.size(); i++) os << " " << v[i];
	}
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N; cin >> N;
	vector<string> pat = {"AC", "WA", "TLE", "RE"};
	map<string, int> cnt;
	for (int i = 0; i < N; i++) {
		string T; cin >> T;
		cnt[T]++;
	}
	for (int i = 0; i < 4; i++) {
		cout << pat[i] << " x " << cnt[pat[i]] << endl;
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	int p[100005];
	for(int i=1;i<n+1;i++){
		cin >> p[i];
	}
	int counter = 0;
	for(int i=1;i<n;i++){
		if(p[i]==i){
			p[i] = p[i+1];
			p[i+1] = i;
			counter++;
		}
	}
	if(p[n]==n){
		p[n] = p[n-1];
		p[n-1] = n;
		counter++;
	}
	cout << counter << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
 
int main() 
{
  int h,w;
  int i,j;
  while(true){
    cin >> h >> w;
    if(h == 0 && w == 0){
      return 0;
    }
    for(i = 0;i < h;i++){
      if(i % 2 == 0){
        for(j = 0;j < w;j++){
          if(j % 2 == 0){
            cout << '#';
          }else{
            cout << '.';
          }
        }
        cout << "\n";
      }else{
        for(j = 0;j < w;j++){
          if(j % 2 == 0){
            cout << '.';
          }else{
            cout << '#';
          }
        }
        cout << "\n";
      }
    }
    cout << "\n";
  }
}


Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
typedef long long ll;
const ll p2=1<<17;
ll a[100000],seg[p2*2-1];
void update(int x){
	while(true){
		x=(x-1)/2;
		seg[x]=max(seg[x*2+1],seg[x*2+2]);
		if(x==0) return;
	}
}
ll segmax(int a,int b,int l,int r,int k){
	if(b<=l||r<=a) return 0;
	if(a<=l&&r<=b) return seg[k];
	return max(segmax(a,b,l,(l+r)/2,k*2+1),segmax(a,b,(l+r)/2,r,k*2+2));
}
int main(){
	int N;
	cin>>N;
	rep(i,N) cin>>a[i];
	rep(i,N) a[i]--;
	rep(i,N){
		seg[p2-1+a[i]]=segmax(0,a[i],0,p2,0)+a[i]+1;
		update(p2-1+a[i]);
	}
	ll mx=0;
	rep(i,N) mx=max(mx,seg[p2-1+i]);
	cout<<(ll)N*(N+1)/2-mx<<endl;
}

Measured memory_bytes: 3532
// B - Trained?
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	vi A(N); rp(i, 0, N) cin>>A[i];
	set<int> visited;
	int t = 0;
	for(int a=1; a!=2; a=A[a-1], ++t){
		if(visited.count(a)!=0){
			t = -1;
			break;
		}
		visited.insert(a);
	}
	cout<< t <<endl;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)2e9 + 7)
#define INF ((int)2e9)
#define INFLL ((LL)2e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (2 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 2, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 1) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL res = 2;
    LL sum = a;
    while(b){
        if(b&2)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

double exp(double a, LL b){
    double res = 1;
    double sum = a;
    while(b){
        if(b&1)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

PII operator+(const PII &a, const PII &b){
    return PII(a.first + b.first, a.second + b.second);
}

vector<vector<int> > xc(100001), yc(100001);

PII func(PII p){
    PII res(0, 0);
    if(!xc[p.first].empty()){
        vector<int> line = xc[p.first];
        xc[p.first].clear();
        ++res.first;
        for(auto &i:line){
            res = res + func(PII(p.first, i));
        }
    }
    if(!yc[p.second].empty()){
        vector<int> line = yc[p.second];
        yc[p.second].clear();
        ++res.second;
        for(auto &i:line){
            res = res + func(PII(i, p.second));
        }
    }
    return res;
}

signed  main(){
    string str;
    cin >> str;
    cout << str.substr(0, 5) << " " << str.substr(6, 7) << " " << str.substr(14, 5) << endl;
    return 0;
}



Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
#include<numeric>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
typedef long long ll;
const int N = 10001;
const ll mod = 1000000007 ;

ll dp[200][N];

ll solve(int now,int w,int *in){
  if (w == 0)return 1;
  if (now < 0){
    return 1;
  }

  ll &ret = dp[now][w];
  if (ret != -1)return dp[now][w];
  ret = 0;
  if (w-in[now] >= 0){//ÂgÂÂ¦ÂÃ©ÂÃÂÃ§ÂgÂÂ¤
    ret += solve(now-1,w-in[now],in);
    ret %= mod;
  }
  int sum = accumulate(in,in+now,0);
  if (sum + in[now] <= w);//ÂÂ±ÂÂ±ÂÃÂgÂÃ­ÂÃÂÂ©ÂÃÂÂ½ÂÃªÂÂÂAÂÂ¼ÂÃÂlÂÃ°ÂÂ·ÂÃÂÃÂlÂÃÂÂÂÃ±ÂÃÂÃ ÂÃÂÂ¾Â]ÂÃ©ÂÃÂÃÂAÂKÂÂ¸ÂgÂÃ­ÂÃÂÂ¢ÂÃÂÂ¢ÂÂ¯ÂÃÂÂ¢ÂB
  else {
    ret += solve(now-1,w,in);
    ret %= mod;
  }
  return ret;
}

main(){
  static int in[N];
  int n,w;
  while(cin>>n>>w && n){
    rep(i,n)cin>>in[i];
    sort(in,in+n);
    rep(i,n)rep(j,N)dp[i][j] = -1;
    if (in[0] > w){
      cout << 1 << endl;//ÂlÂÃÂÃ©ÂÃ»Â@ÂÂªÂÃÂÂ¢ÂÃÂÂ«ÂÃ1ÂÂªÂÂÂÂ¦
    }else {
      cout << solve(n-1,w,in) << endl;
    }
  }
}

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

int main() {
	int c, tc = 0, hc = 0;
	string t, h;
	cin >> c;
	for (int i = 0; i<c; i++) {
		cin >> t >> h;
		if (t>h) { tc += 3; }
		else if (t<h) { hc += 3; }
		else { tc++; hc++; }
	}

	cout << tc << " " << hc << endl;



	return 0;
}

Measured memory_bytes: 3144
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// return first index, where v[i] > k
fn ubound(v:& Vec<i64>, k:i64) -> usize {
    let mut l = 0;
    let mut r = v.len();

    while l < r {
        let m = (l+r-1) >> 1;
        if v[m] <= k {
            l = m+1;
        } else {
            r = m;
        }
    }
    l
}

fn main() {
    input! {
        n: usize,
        a: [i64; n],        // v::Vec<i64>
        b: [i64; n],        // v::Vec<i64>
    };

    let ans:i64 = (0..29).map(|k| {
        let km = (1 << (k+1))-1;
        let mut bk:Vec<i64> = b.iter().map(|bi| {
            bi & km
        }).collect();
        bk.sort();

        let t = 1 << k;
        let sa = a.iter().map(|ai| {
            let aa = ai & km;
            let b1 = ubound(&bk, t-aa-1);
            let b2 = ubound(&bk, (t<<1)-aa-1);
            let b3 = ubound(&bk, t*3-aa-1);
            ((b2-b1) + (n-b3)) as i64
        }).sum::<i64>();
        if (sa & 1) == 1 { t } else {0}
    }).sum();
    println!("{}", ans);
}

Measured memory_bytes: 13044