akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long N;
	cin >> N;
	vector<long long> V(N);
	for (int i = 0; i < N; i++) cin >> V[i];
	sort(V.begin(), V.end());
	V.erase(unique(V.begin(), V.end()), V.end());
	if (V.size() == N) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	int co = 0;
	for (int i = a; i <= b; i++) {
		string s = to_string(i);
		bool b = false;
		for (int j = 0; j < s.size(); j++) {
			if (s[j] != s[s.size() - j - 1]) {
				b = true;
				break;
			}
		}
		if (b == false) {
			co++;
		}
	}
	cout << co << endl;
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    int S;
    scanf("%d",&S);
    int h,m,s;
    h=S/3600;
    m=(S%3600)/60;
    s=(S%3600)%60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}


Measured memory_bytes: 2088
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;

int n, cnt[4];
ll res, w, nw, table[4][110];

bool compare(ll d1, ll d2){ return d1 > d2; }
int main(){
	int i, j, k;
	ll a, s, now, nsum, idx;
	scanf("%d %lld %lld %lld", &n, &w, &a, &s); nw = a;
	table[0][cnt[0]++] = s;
	for(i = 1; i < n; i++){
		scanf("%lld %lld", &a, &s);
		a -= nw;
		table[a][cnt[a]++] = s;
	}
	for(i = 0; i < 4; i++){
		sort(table[i], table[i] + cnt[i], compare);
		for(j = 1; j <= 100; j++) table[i][j] += table[i][j - 1];
	}
	for(i = 0; i <= cnt[0]; i++){
		now = nw * i; nsum = 0;
		if(i) nsum = table[0][i - 1];
		if(now > w) break;
		for(j = 0; j <= cnt[1]; j++){
			if(now + j * (nw + 1) > w) break;
			now += j * (nw + 1);
			if(j) nsum += table[1][j - 1];
			for(k = 0; k <= cnt[2]; k++){
				if(now + k * (nw + 2) > w) break;
				now += k * (nw + 2);
				if(k) nsum += table[2][k - 1];
				idx = min(100ll, (w - now) / (nw + 3));
				if(idx) nsum += table[3][idx - 1];
				res = max(res, nsum);
				now -= k * (nw + 2);
				if(idx) nsum -= table[3][idx - 1];
				if(k) nsum -= table[2][k - 1];
			}
			now -= j * (nw + 1);
			if(j) nsum -= table[1][j - 1];
		}
	}
	printf("%lld", res);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
 
int main() {
    int n;
    cin >> n;
    int inf[4] = {};
    int room[4][3][10] = {};
    for (int i = 0; i < n; ++i){
        for (int j = 0; j < 4; ++j){
            cin >> inf[j];
        }
        room[inf[0]-1][inf[1]-1][inf[2]-1] += inf[3];
    }

    for (int i = 0; i < 4; ++i)
    {
        for (int j = 0; j < 3; ++j)
        {
            for (int k = 0; k < 10; ++k)
            {
                cout << " " <<room[i][j][k];
            }
            cout << endl;
        }
        if(i < 3) cout << "####################" << endl;
    }
    return 0;
}

Measured memory_bytes: 1164
main :: IO ()
main = do
  [n, l] <- map read . words <$> getLine
  print $ solve n l

solve :: Int -> Int -> Int
solve n l = sum [l .. r] - a
  where
    r = l + n - 1
    a | l >= 0    = l
      | r <= 0    = r
      | otherwise = 0

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

public class Main {

	static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {

        int n = scan.nextInt();
        int m = scan.nextInt();

        long[][] a = {{1, 1, 1}, {1, 1, -1}, {1, -1, 1}, {-1, 1, 1}, {-1, -1, 1}, {-1, 1, -1}, {1, -1, -1}, {-1, -1, -1}};
        long[][] sum = new long[8][n];

        for (int i = 0; i < n; i++) {
            long x = scan.nextLong();
            long y = scan.nextLong();
            long z = scan.nextLong();
            for (int j = 0; j < 8; j++) {
                sum[j][i] = a[j][0] * x + a[j][1] * y + a[j][2] * z;
            }
        }

        long ans = 0;
        for (int i = 0; i < 8; i++) {
            Arrays.sort(sum[i]);
            long lower = 0, upper = 0;
            for (int j = 0, c = n - 1; j < m; j++, c--) {
                lower += sum[i][j];
                upper += sum[i][c];
            }
            ans = Math.max(ans, Math.max(Math.abs(lower), Math.abs(upper)));
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 28616
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    static ArrayList<Integer> primes;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            primes = new ArrayList<>();
            int c = 0;
            for (int i = 1; i <= n * 2; i++) {
                boolean isP = isPrime(i);
                if (isP) {
                    primes.add(i);
                }
                if (n < i && isP) {
                    c++;
                }
            }
            System.out.println(c);
        }
    }

    public static boolean isPrime(int n) {
        if (n == 1) {
            return false;
        }
        if (n == 2) {
            return true;
        }
        for (int p: primes) {
            if (n % p == 0) {
                return false;
            }
        }
        return true;
    }
}

Measured memory_bytes: 60168
#include<bits/stdc++.h>
using namespace std;
main()
{
long long int n, k;
cin >> n >> k;	
long long int a[n], i;
for(i=0;i<n;i++)
cin >> a[i];
sort(a, a+n);
long long int sum = 0;
for(i=0;i<k;i++)
sum+=a[i];
cout << sum << endl;
return 0;
}

Measured memory_bytes: 3632
#include <cmath>
#include <iostream>
#include <string>
#include <utility>

using namespace std;

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

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

  int aki = a - b;
  if (aki >= c)
    cout << "0" << endl;
  else
    cout << c - aki << endl;

	return 0;
}


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

int main(){
  int r, c;
  cin>>r>>c;

  int a[101][101] = {};
  for(int i=0;i<r;i++)
    for(int j=0;j<c;j++) cin>>a[i][j];

  for(int i=0;i<r;i++){
    int sum = 0;
    for(int j=0;j<c;j++) sum += a[i][j];
      a[i][c] = sum;
  }

  for(int j=0;j<c;j++){
    int sum = 0;
    for(int i=0;i<r;i++) sum += a[i][j];
      a[r][j] = sum;
  }

  for(int i=0;i<r;i++)
    for(int j=0;j<c;j++) a[r][c] += a[i][j];

  for(int i=0;i<=r;i++){
    for(int j=0;j<=c;j++){
      if(j) cout<<" ";
      cout<<a[i][j];
    }
    cout<<endl;
  }

  return 0;
}


Measured memory_bytes: 3156
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class232
    {
        static void Main()
        {
            string S = Console.ReadLine();
            long ans = 0;
            for(int i = 0;i<(1<<S.Length-1); i++)
            {
                long sum = 0;
                long num = long.Parse(S[0].ToString());
                for(int j = 0; j < S.Length - 1; j++)
                {
                    if ((i & (1 << j)) > 0)
                    {
                        sum += num;
                        num = long.Parse(S[j + 1].ToString());
                    }
                    else
                    {
                        num *= 10;
                        num += long.Parse(S[j + 1].ToString());
                    }
                }
                sum += num;
                ans += sum;
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
# coding:utf-8

import sys
import math
import time
import numpy as np
import collections

#X = str(raw_input()).split()
X = int(raw_input())

k = X
flag = 0


while True:
  flag = 0
  for p in xrange(2, int(math.sqrt(k))+1):
    if k % p == 0:
        flag = 1
        break
  if(flag == 0):
    ans = k
    break
  k += 1



print(str(ans));


Measured memory_bytes: 17632
#include <iostream>
#include <string>
#include <fstream>

int main(){
    int hit = 0, out= 0, score = 0, data_set_num;
    std::string event, str;
    std::cin >> data_set_num;
    std::cin.ignore();

    while(data_set_num){
        std::cin >> event;
        if(event == "HIT"){
            ++hit;
            if(hit == 4){
                ++score;
                --hit;
            }
        }else if(event == "HOMERUN"){
            score += (hit + 1);
            hit = 0;
        }else if(event == "OUT"){
            ++out;
        }

        if(out == 3){
            std::cout << score << std::endl;
            hit = 0;
            score = 0;
            out = 0;
            --data_set_num;
        }
    }

    return 0;
}

Measured memory_bytes: 3148
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            var ans = int.MaxValue;
            for (int i = s.Min(); i <= s.Max(); i++)
            {
                ans = Min(ans,
                    s.Select(x => (int)Pow(x-i,2)).Sum()
                    );
            }
            WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13396
import sys
from collections import deque

S = deque(list(input()))

prev = deque([])
accum = deque([])
count = 0

while(True):
    s = S.popleft()
    if prev == "":
        prev = [s]
        count += 1
        continue
    accum.append(s)
    if prev != accum:
        prev = accum
        accum = deque([])
        count += 1
        if len(S) == 0:
            break
        continue
    if prev == accum and len(S) == 0:
        break

print(count)


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

bool hantei(vector<string>& W) {
  int l = W.size();

  rep(i, 0, l-1) {
    if ( W[i].back() != W[i+1].front() ) return false;
  }

  rep(i, 0, l) {
    rep(j, i+1, l) {
      if ( W[i] == W[j] ) return false;
    }
  }

  return true;
}

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

  vector<string> W(N);
  rep(i, 0, N) cin >> W[i];

  cout << ( hantei(W) ? "Yes" : "No" ) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
#include <numeric>
#define ll long long
#define INF INT_MAX 
using namespace std;
int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(B/A>=C){
        cout << C << endl;
    }else{
        cout << B/A << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
k = int((n*2)**.5)
if k*(k+1)//2 != n:
  print("No")
  exit()
print("Yes")
print(k+1)
l = [set() for _ in range(k+1)]
t = 0
for i in range(k):
  for j in range(i+1):
    t += 1
    l[i].add(t)
    l[j].add(t)
  l[-1].add(t)
for x in l:
  print(k," ".join(map(str,x)))

Measured memory_bytes: 21796
#include<bits/stdc++.h>
using namespace std;
#define int long
using pi=pair<int,int>;
signed main(){
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    b = abs(a - b), --n;
    for (int x = 0; x <= n;++x)
        if (c * (n - x) - d * x <= b && b <= d * (n - x) - c * x) return cout << "YES", 0;
    cout << "NO";
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int a = (s[0]-'0'), b = (s[1]-'0'), c = (s[2]-'0'), d = (s[3]-'0');
	rep(op1,2)rep(op2,2)rep(op3,2){
		int val = a;
		if(op1) val += b;
		else val -= b;
		if(op2) val += c;
		else val -= c;
		if(op3) val += d;
		else val -= d;
		if(val == 7){
			cout << a << (op1 ? "+" : "-") << b << (op2 ? "+" : "-") << c << (op3 ? "+" : "-") << d << "=7" << endl;
			return 0;
		}
	}
	return 0;
}

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e14
#define MOD 1000000007

int main()

{

    ll x1,x2,x3,x4,y1,y2,y3,y4;
    cin >> x1 >> y1 >> x2 >> y2;
    x3 = x2-(y2-y1);
    x4 = x1-(y2-y1);
    y3=y2+(x2-x1);
    y4=(x2-x1)+y1;
    cout << x3 << " " << y3 << " " << x4 << " " << y4;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
const ll M=11;
ll a[M][M];
inline ll read()
{
	ll x=0,f=1; char ch=0;
	while(!isdigit(ch)) f=(ch=='-'?-1:1),ch=getchar();
	while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*f;
}
int main()
{
	ll n=read(),m=read(),ans=0;
	for(register ll i=1;i<=n;i++){
		for(register ll j=1;j<=m;j++){
			a[i][j]=read();
		}
	}
	for(register ll i=1;i<=n;i++)
		for(register ll j=i+1;j<=n;j++){
			ll tmp=0,t;
			for(register ll k=1;k<=m;k++){
				tmp+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
			}
			t=tmp;
			tmp=sqrt(tmp);
			if((tmp*tmp)==t) ans++;
		}
	printf("%lld\n",ans);
	return 0;	
}

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int x, a, b; cin >> x >> a >> b;
    cout << ((abs(a - x) < abs(b - x)) ? "A" : "B") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
const int N = 1000001;
using namespace std;


void f() {

}


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


    int d, t, s;
    cin >> d >> t >> s;
    cout << (t * s >= d ? "Yes" : "No");

}

Measured memory_bytes: 3648
#include <iostream>
#define rep(i, n)   for(int i = 0; i < (n); i++) 
using namespace std;

int main(){
    int n;  cin >> n;
    if((n-n%100)/100 == n%10){
	cout << "Yes" << endl;
    }else{
	cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <atcoder/dsu>
#include <iostream>
#include <vector>

using namespace std;
int main() {
    int n, m;
    cin >> n >> m;
    atcoder::dsu g(n);
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        g.merge(u, v);
    }
    cout << g.groups().size() - 1;
}


Measured memory_bytes: 8792
// 2197_SumOfConsecutiveIntegers.cpp
#include <bits/stdc++.h>
using namespace std;
int n;

bool dfs(int i, int n) {
  if (i > n) return false;
  else if(i == n) return true;
  else return dfs(i + 1, n - i);
}

void solve() {
  int result = 0;
  for(int i = 1; i <= n / 2; ++i) {
    if(dfs(i, n)) result++;
  }
  cout << result << endl;
}
int main() {
  while(cin >> n && n) {
    solve();
  }
  return 0;
}



Measured memory_bytes: 3052
local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max
local p = io.read("*n")
local q, r = io.read("*n", "*n")
local s = p + q + r
s = s - mma(p, mma(q, r))
print(s)


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 #define int long long
#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second

 
 
using namespace __gnu_pbds;
using namespace std;
 const int mod=1e9+7;
 // const int mod=998244353;
const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#define read(n) int n; cin>>n;
#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i; 
int multiply(int a, int b, int in_mod){return (a*b)%in_mod;} 
int mult_identity(int a){return 1;}


auto power(auto a, int b, int in_mod)
{
    auto prod=mult_identity(a);
    auto mult=a%in_mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod=multiply(prod,mult, in_mod);
        }
        mult=multiply(mult, mult,in_mod);
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int in_mod)
{

    return power(q, in_mod-2,in_mod);
}

// const int MAXN=5e5+10;
// vector<int> fac(MAXN);
// vector<int> infac(MAXN);
// void build_factorial()
// {
//     fac[0]=1;
//     infac[0]=1;
//     for(int i=1;i<MAXN;i++)
//     {
//         fac[i]=(fac[i-1]*i)%mod;
//         infac[i]=mod_inv(fac[i], mod);
//     }
// }



// void solve()
// {
//     int h, w, n;
//     cin>>h>>w>>n;
//     vector<pair<int, int> > bad;
//     for(int i=0;i<n;i++)
//     {
//         int r, c;
//         cin>>r>>c;
//         bad.pb({r,c});
//     } 
//     sort(all(bad));
//     bad.pb({h, w});



//     int ways[n+1];
//     for(int i=0;i<=n;i++)
//     {

//         ways[i] = (fac[bad[i].fi+bad[i].se-2]*infac[bad[i].fi-1])%mod * infac[bad[i].se-1]%mod;
//         for(int j=0;j<=i;j++)
//         {
//             if(bad[j].fi<=bad[i].fi && bad[j].se<=bad[i].se)
//             {
//                 ways -= 
//             }
//         }
//     }
// }


void solve()
{
    int x;
    cin>>x;
    int start = 100;
    int teime=1;
    while(start*1.01<x)
    {
        start = (start*1.01);
        teime++;
    }
    cout<<teime<<endl;
}

 
 
signed main()
 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        if(fopen("INPUT.txt","r"))
        {
            freopen ("INPUT.txt" , "r" , stdin);
            freopen ("OUTPUT.txt" , "w" , stdout);
        }
    #endif
    auto clk=clock(); 
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // -------------------------------------Code starts here---------------------------------------------------------------------     
 
    int t=1;
    // cin>>t;
    for(int test=1;test<=t;test++)
    {
        // cout<<"Case #"<<test<<": ";
        solve();
        // cout<<endl;
 
    }
 
    // -------------------------------------Code ends here------------------------------------------------------------------
 
 
    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
    return 0;
 }


Measured memory_bytes: 3808
using System;
using static System.Console;
using static System.Convert;

class Program
{
    static void Main(string[] args)
    {
        var input = ReadLine().Split(' ');
        var num = ToInt32(input[0]);
        var length = ToInt32(input[1]);
        var strs = new string[num];
        for(var i = 0; i < num; i++)
        {
            strs[i] = ReadLine();
        }
        Array.Sort(strs);
        for(var i = 0; i < num; i++)
        {
            Write(strs[i]);
        }
        WriteLine();
    }
}

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

int main(){
    int N,T;
    scanf("%d%d",&N,&T);
    int c[N],t[N];
    for(int i = 0;i < N;i++){
        scanf("%d%d",&c[i],&t[i]);
    }

    int overTc[N];
    int j = 0;
    for(int i = 0;i < N;i++){
        if(t[i] <= T){
            overTc[j] = c[i];
            j++;
        }
    }

    if(j == 0){
        printf("TLE");
        return 0;
    }
    
    for(int i = 0;i < j;i++){
        if(overTc[0] > overTc[i])overTc[0] = overTc[i];
    }
    printf("%d\n",overTc[0]);
    return 0;
}


Measured memory_bytes: 256
def main():
    a,b = map(int, input().split())
    n = (b-a+1)#要素数
    k = n//2

    if n%2==0:
        if a%2==0:
            if k%2==0:
                res = 0
            else:
                res =1
        else:
            k = (n-2)//2
            if k%2 == 1:
                res=(a^b^1)
            else:
                res = a^b
    else:
        if a%2 == 0:
            if k%2 == 0:
                res = (b)
            else:
                res = b^1
        else:
            if k%2==1:
                res = a^1
            else:
                res = a
    print(res)





if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
using namespace std;
using ll=long long;
//using R=double;

const int INF = 10000000;
typedef pair<int, int> p;

int main(){
	ll A,B,C;
	cin >> A >> B >> C;

	ll result = 0;
	ll amari = 0;

	if(B+1 > C){
		cout << B+C << endl;
		return 0;
	}else{
		result = B + B + 1;
		amari = C - B - 1;
		if(A > amari){
			result += amari;
		}else{
			result += A;
		}
	}

	cout << result << endl;

	return 0;
}


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

int a, b, c, d, len, k;

int cal(int a, int b) {
	if (!a || !b) return a + b;
	if (a < b) swap(a, b);
	return (a - 1) / (b + 1) + 1;
}

bool check(int mid) {
	int l = mid / (k + 1) * k + mid % (k + 1), r = mid / (k + 1) - (mid % (k + 1) == 0);
	if (l > a) return 0;
	return cal(a - l, b - r) <= k;
}

void workleft(int l, int r) {
	for (int i = l; i <= r; i++)
		putchar(i % (k + 1) ? 'A' : 'B');
}

void workright(int l, int r) {
	for (int i = l; i <= r; i++)
		putchar((a + b - i + 1) % (k + 1) ? 'B' : 'A');
}

int main() {
	int T;
	scanf("%d", &T);
	while (T--) {
		scanf("%d%d%d%d", &a, &b, &c, &d);
		len = a + b;
		k = cal(a, b);
		int l = 0, r = len + 1;
		while (l < r) {
			int mid = l + r >> 1;
			if (check(mid)) l = mid + 1;
			else r = mid;
		}
		l--;
		if (d <= l) workleft(c, d);
		else if (c > l) workright(c, d);
		else workleft(c, l), workright(l + 1, d);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> PP;
typedef long long ll;

ll inf = 1e9+7;
ll func[200010] = {0};
ll inv[200010] = {0};

ll mult(ll n, ll m){
	if(m==1) return n%inf;
	else if(m%2==0){
		ll t = mult(n,m/2);
		return (t*t)%inf;
	}else{
		ll t = mult(n,m-1);
		return (t*n)%inf;
	}
}

void factorial(ll N){
	for(ll i=0;i<=N;i++){
		if(i==0){
			func[i] = 1;
			inv[i] = 1;
		}
		else{
			func[i] = (i*func[i-1])%inf;
			inv[i] = mult(func[i],inf-2);
		}
	}
}

ll comb(ll n,ll k){
	if(k==0 || n==k) return 1;
	else return (((func[n]*inv[k])%inf)*inv[n-k])%inf;
}


int n,q;
int p[200010] = {0},r[200010] = {0},s[200010] = {0};
void init(int N){
	for(int i=0;i<=N;++i){
		p[i] = i;
		s[i] = 1;
	}
}
 
int root(int a){
	if(p[a] == a) return a;
	return (p[a] = root(p[a]));
}
 
bool is_same_set(int a,int b){
	return root(a) == root(b);
}
 
void unite(int a, int b){
	a = root(a);
	b = root(b);
	if(a==b) return;
	if(r[a]<r[b]){
		p[a] = b;
		s[b] += s[a];
		s[a] = s[b];
	}else{
		p[b] = a;
		s[a] += s[b];
		s[b] = s[a];
		if(r[a] == r[b]) r[a]++;
	}
}

int N,X,Y;
int C[200010],W[200010];
vector<vector<P>> cols(200010);
vector<P> mins;
int main(){
	cin >> N >> X >> Y;
	init(N);
	factorial(N);
	for(int i=1;i<=N;i++){
		cin >> C[i] >> W[i];
		cols[C[i]].push_back({W[i],i});
	}
	for(int i=1;i<=N;i++){
		if(cols[i].size()!=0){
			sort(cols[i].begin(),cols[i].end());
			mins.push_back(cols[i][0]);
		}
	}
	sort(mins.begin(),mins.end());
	int n = mins.size();
	for(int i=1;i<n;i++){
		if(mins[0].first+mins[i].first<=Y){
			unite(mins[0].second,mins[i].second);
//			cout << mins[i].second << endl;
		}
	}
	for(int i=1;i<=N;i++){
		if(s[root(cols[C[i]][0].second)]==1) continue;
		if(cols[C[i]][0].first+W[i]<=X) unite(cols[C[i]][0].second,i);
		else{
			if(C[i]!=C[mins[0].second] && mins[0].first+W[i]<=Y) unite(mins[0].second,i);
			else if(C[i]==C[mins[0].second] && n>=2 && mins[1].first+W[i]<=Y) unite(mins[1].second,i);
		}
	}
	ll sum = 0;
	map<int,ll> m;
	for(int i=1;i<=N;i++){
		if(s[root(i)]!=1){
			sum++;
			m[C[i]]++;
		}
	}
	ll ans = 1;
	for(auto x:m){
		(ans *= comb(sum,x.second))%=inf;
		sum -= x.second;
	}
	cout << ans << endl;
}

Measured memory_bytes: 25204
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> vec;

vec Add(vec,vec);
vec Power(vec,int);
vec Formula();
vec Ar();
vec v[26];
string s;
int n,p,k,h,a;

int main(){
  char c;
  cin>>n>>k;
  while(k--){
    cin>>c>>h;
    for(int i=0;i<n;i++) v[c-'A'].push_back(i);
    for(int i=0;i<h-1;i++)
      for(int j=0;j<n-1;j++){
	cin>>a;
	if(a) swap(v[c-'A'][j],v[c-'A'][j+1]);
      }
  }
  cin>>k;
  while(k--){
    cin>>s;
    s+='$';
    p=0;
    vec ans=Formula();
    for(int i=0;i<n;i++){
      if(i) cout<<' ';
      cout<<ans[i]+1;
    }
    cout<<endl;
  }
  return 0;
}

vec Add(vec A,vec B){
  vec res=vec(n);
  for(int i=0;i<n;i++) res[i]=A[B[i]];
  return res;
}

vec Power(vec A,int x){
  vec res;
  for(int i=0;i<n;i++) res.push_back(i);
  while(x){
    if(x%2) res=Add(res,A);
    x/=2;
    A=Add(A,A);
  }
  return res;
}

vec Formula(){
  vec res=Ar();
  while(s[p]=='+') p++,res=Add(res,Ar());
  return res;
}

vec Ar(){
  if(s[p]=='('){
    p++;
    vec res=Formula();
    p++;
    return res;
  }
  if('0'<=s[p]&&s[p]<='9'){
    int num=0;
    while('0'<=s[p]&&s[p]<='9') num=num*10+s[p]-'0',p++;
    vec res=Ar();
    return Power(res,num);
  }
  if('A'<=s[p]&&s[p]<='Z') return v[s[p++]-'A'];
}

Measured memory_bytes: 1264
s = input()
a, b = s[:2], s[2:]

MMYY = (1 <= int(a) <= 12) and (0 <= int(b) <= 99)
YYMM = (0 <= int(a) <= 99) and (1 <= int(b) <= 12)

if MMYY:
    if YYMM:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if YYMM:
        print('YYMM')
    else:
        print('NA')


Measured memory_bytes: 3060
x,y,a,b,c=map(int,input().split())
AC=[]
for a in map(int,input().split()):
  AC.append((a,1))
for a in map(int,input().split()):
  AC.append((a,2))
for a in map(int,input().split()):
  AC.append((a,0))
AC.sort(reverse=1)

red=0
green=0
cnt=0
res=0
for a,c in AC:
  if c==0:
    res+=a
    cnt+=1
  elif c==1:
    if red<x:
      res+=a
      red+=1
      cnt+=1
  else:
    if green<y:
      res+=a
      green+=1
      cnt+=1
  if cnt==x+y:
    print(res)
    exit(0)

Measured memory_bytes: 118508
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    int dp[n];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    {
        int option1=dp[i-1]+abs(a[i]-a[i-1]);
        int option2=dp[i-2]+abs(a[i]-a[i-2]);
        dp[i]=min(option1,option2);
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
b,s,o,i;main(a){for(scanf("%d",&i);i<25&&~scanf("%s",&a);b=a%3?a&1?o?b:(s=!printf("%d\n",b>3?s+b-3:s)):b+1:!(s+=++b))  o=a&1?-~o%3:o;return 0;}

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

int main() {
  int N, digit, r, fN, Ncopy;
  cin >> N; //100
  r = 10;
  for (int i = 0; i < 8; i++){
    if (N / r == 0){
      digit = i + 1;
      break;
    }
    else {
      r *= 10;
    }
  } //digit=3
  fN = 0;
  Ncopy = N;
  for (int i = 0; i < digit; i++){
    fN += Ncopy % 10;
    Ncopy /= 10;
  }
  if (N % fN == 0){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

class D {
    static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    static void Main(string[] args) {
        int N, K;
        Input(out N, out K);
        int[] P;
        InputArray(out P);
        double[] SUM = new double[N + 1];
        SUM[0] = 0;
        for(int i = 1; i <= N; i++) {
            SUM[i] = SUM[i - 1] + (1 + P[i - 1]) / 2.0;
        }
        double max = 0;
        for(int i = 0; i < N - (K - 1); i++) {
            double sum = SUM[i + K] - SUM[i];
            if(max < sum) {
                max = sum;
            }
        }
        Console.WriteLine(max);
    }
    static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T));
    static void Input<A>(out A a) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
    }
    static void Input<A, B>(out A a, out B b) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
    }
    static void Input<A, B, C>(out A a, out B b, out C c) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
    }
    static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
    }
    static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
    }
    static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
        f = ChangeT<F>(words[5]);
    }
    static void InputArray<T>(out T[] array) {
        array = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Select(s => ChangeT<T>(s)).ToArray();
    }
    static void Print<T>(T s) => Out.WriteLine(s);
    static void Print<T>(params T[] s) => Out.WriteLine(string.Join(" ", s));
    static void Print<T>(IEnumerable<T> e) => Out.WriteLine(string.Join(" ", e));
}

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

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

	for (int i = 0; i < S.length(); i++) {
		int len = S.length() - i;
		if (len % 2 == 0 && i>0) {
			//文字数が偶然のとき
			string S1 = S.substr(0, len / 2);
			string S2 = S.substr(len / 2, len / 2);
			//cout << S1 << " " << S2 << endl;
			if (S1 == S2) {
				cout << len << endl;
				return 0;
			}
		}

	}
}




Measured memory_bytes: 3580
#include <iostream>
#include <vector>

int main()
{
	int n, k;
	std::cin >> n >> k;
	
	std::vector<bool> sunukes(n);
	int d;
	int a;
	for (int i = 0; i < k; i++) {
		std::cin >> d;
		for (int j = 0; j < d; j++) {
			std::cin >> a;
			sunukes[a - 1] = true;
		}
	}
	
	int cnt = 0;
	for (auto sunuke : sunukes) {
		if (!sunuke) {
			cnt++;
		}
	}
	std::cout << cnt << std::endl;
	
	return 0;
}


Measured memory_bytes: 3164
#include <cstdio>
#include <iostream>
#include <cctype>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

string dp[71][70];
char c[70][72];
int W, H;

bool bt_str(string& a, string& b){
    if( a.size() > b.size() ) return true;
    return a.size() == b.size() && a > b;
}

string bigger(string a, string b){
    return bt_str(a, b) ? a : b;
}

int main(){
    for(; scanf("%d %d", &W, &H), W;){
        for(int x = 0; x < H; x++){
            fill(c[x], c[x]+W, 0);
            fill(dp[x], dp[x]+W, "");
            scanf(" %s", c[x]);
        }
        fill(dp[H], dp[H]+W, "");
        string best = "";
        for(int x = 0; x < H; x++){
            for(int y = 0; y < W; y++){
                if(isdigit(c[x][y])){
                    dp[x+1][y] = dp[x][y]+string(1,c[x][y]);
                    if(y){
                        dp[x+1][y] = bigger(dp[x+1][y],
                                            dp[x+1][y-1]+string(1,c[x][y]));
                    }
                    if(dp[x+1][y] == "0"){
                        dp[x+1][y] = "";
                    }
                    best = bigger(best, dp[x+1][y]);
                }
            }
        }
        cout << best << endl;
    }
    return 0;
}

Measured memory_bytes: 1416
#include<iostream>
using namespace std;
int main(){
	string s;
	cin>>s;
	int a,b,c,d;
	a=s[0]-'0';
	b=s[1]-'0';
	c=s[2]-'0';
	d=s[3]-'0';
	int res=a+b+c+d;
	int m[4];
	char mm[4];
	int res1;
	for(int i=0;i<=7;i++){
		mm[1]='+';
		mm[2]='+';
		mm[3]='+';
		m[1]=i%2;
		m[2]=(i/2)%2;
		m[3]=(i/4)%2;
		res1=res;
		if(m[1]==0){
		res1-=(2*b);
		mm[1]='-';}
		if(m[2]==0){
		res1-=(2*c);
		mm[2]='-';}
		if(m[3]==0){
		res1-=(2*d);
		mm[3]='-';}
		if(res1==7){
		cout<<a<<mm[1]<<b<<mm[2]<<c<<mm[3]<<d<<"=7";return 0;}
	}
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n) { cin >> a[i]; }
  ll c = 0, ans = n;
  REP(i, n) {
    if (a[i] == c + 1) {
      ans--;
      c++;
    }
  }
  if (c == 0) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
} 

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    string s;
    cin >> s;
    int ans = 0;
    rep(i,4) {
        if(s[i] == '2') ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <bitset>
#include <iomanip>
#include <deque>
#include <tuple>
#include <algorithm>

using namespace std;

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

    cin >> a >> b >> c;

    cout << (a*b > c ? c : a*b) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	long long N, k;
	cin >> N >> k;
	long long  A[N];
	for (long long i = 0; i < N; i++) {
		cin >> A[i];
	}
	long long ans = 1000000000;
	sort(A, A + N);
	for (long long i = 0; i < N-k+1; i++) {
		long long time1, time2 = 1000000000;
		if (A[i] > 0) {
			time1 = A[i + k - 1];
		}
		else if (A[i + k - 1] < 0) {
			time1 = -A[i];
		}
		else {
			time1 = (A[i + k - 1] - A[i]) * 2 - A[i + k - 1];
			time2 = (A[i + k - 1] - A[i]) * 2 + A[i];
			time1 = min(time1, time2);
		}
		ans = min(ans, time1);
	}
	cout << ans << endl;
}

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

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

Measured memory_bytes: 3096
from operator import itemgetter

N,M = map(int,input().split())
PS = [list(map(str,input().split())) for i in range(M)]

for i in range(M) :
    PS[i][0] = int(PS[i][0])

submits = [["null"] for i in range(N)]
for i in range(M) :
    submits[PS[i][0]-1][0] = PS[i][0]-1
    submits[PS[i][0]-1].append(PS[i][1])

ac = 0
pena = 0
for i in range(len(submits)) :
    if submits[i][0] == "null" :
        continue

    flag = False
    wabuf1 = 0
    for j in range(1,len(submits[i])) :
        if submits[i][j] == "AC" :
            ac += 1
            flag = True
            break
        else :
            wabuf1 += 1
    if flag == True :
        pena += wabuf1

print(ac,pena)

Measured memory_bytes: 46876
import math

a,b,C=list(map(int,input().split()))

C_radian=math.radians(C)

S=a*b*math.sin(C_radian)/2
L=a+b+(a**2+b**2-2*a*b*math.cos(C_radian))**0.5
h=b*math.sin(C_radian)

print(S)
print(L)
print(h)

Measured memory_bytes: 7888
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

template<typename T>
unordered_map<T,int> PrimeFactorize(T x){
	unordered_map<T,int> res;
	for(T i = 2; i*i <= x; i++){
		while(x%i == 0){
			res[i]++;
			x /= i;
		}
	}
	if(x != 1) res[x]++;
	return res;
}

const LL mod = 1e9+7;

int main()
{
	ios_init();
	int n;
	while(cin >> n) {
		unordered_map<int,int> mp;
		FOR(i,1,n+1){
			auto res = PrimeFactorize(i);
			for(auto&& e : res) {
				mp[e.F] += e.S;
			}
		}
		LL ans = 1;
		for(auto&& e : mp) {
			DEBUG(e);
			ans *= e.S+1;
			ans %= mod;
		}
		cout << ans << endl;
	}
	return 0;
}


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

int main()
{
	string s,s2;
	cin>>s;
	ll int l=s.length();
	for(int i=0;i<l;i++)
	{
		s2+='x';
	}
	cout<<s2<<endl;
	
	

		

}


	
  
  

		
		
		
		
		
		
	
	
	 
		
		
	
	
	

	


	
	
	
   



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N, M;
  cin >> N >> M;
  long ans = 0;
  if(N * 2 < M) {
    ans += N;
    M -= N * 2;
    ans += M / 4;
  } else {
    ans += M / 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	static int[] arr = new int[110];
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i=0;i<n;i++)
			arr[i] = sc.nextInt();
		int res = bubbleSort(n);
		print(n);
		System.out.println(res);
		
	}
	
	public static int bubbleSort(int n){
		int cnt = 0;
		boolean f = true;
		for(int i=0;f;i++) {
			f = false;
			for(int j=n-1;j>=i+1;j--) {
				if(arr[j]<arr[j-1]) {
					swap(j);
					f = true;
					cnt++;
				}
			}
		}
		return cnt;
	}
	
	public static void swap(int j) {
		int t = arr[j];
		arr[j] = arr[j-1];
		arr[j-1] = t;
	}
	
	public static void print(int n) {
		for(int i=0;i<n;i++) {
			if(i==0) System.out.print(arr[i]);
			else System.out.print(" "+arr[i]);
		}
		System.out.println();
	}
}


Measured memory_bytes: 26388
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int main(){
  const int n = getInt();
  const int m = getInt();

  vector<int> v(n, 1);

  REP(i,m) v[getInt()] = 0;

  int cnt = 0;
  while(v.size() > 1) {
    vector<int> next;
    REP(i,v.size()/2){
      if(v[2 * i] * v[2 * i + 1] != 0) cnt++;
      next.push_back(max(v[2 * i], v[2 * i + 1]));
    }
    v.swap(next);
  }

  printf("%d\n", cnt);
  return 0;
}

Measured memory_bytes: 2680
#include <cstdio>
using namespace std;
int main() {
  int n;
  char s[110];
  scanf("%d", &n);
  scanf("%s", s);
  if (n % 2) {
    printf("No\n");
    return 0;
  }
  for (int i = 0; i < n / 2; i++) {
    if (s[i] != s[i + n / 2]) {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
}

Measured memory_bytes: 128
// A - Airplane

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const int MOD = 1e9 + 7;

int main(){
	int P, Q, R;
	cin >> P >> Q >> R;

	int ans = 99999;

	ans = min(P + Q, min(Q + R, R + P));

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    ll k; cin >> k;
    vector <ll> okasis(n, 0);
    REP(_, k){
        ll d; cin >> d;
        REP(__, d){
            ll a; cin >> a;
            a--;
            okasis[a]++;
        }
    }
    ll ans = 0;
    REP(i, n){
        ans += okasis[i] == 0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(){
	char a[4];
	int ans=0;
	cin>>a;
	for(int i=0;i<4;i++){
		if(a[i]=='+'){
			ans=ans+1;
		}
		else{
			ans=ans-1;
		}
		
	}
	cout<<ans;
	return 0;
} 

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

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

fn main() {
    let _n = read::<usize>();
    let mut aa = read_vec::<usize>();
    let mut bb = read_vec::<usize>();

    let mut ans = 0;

    for (i, b) in bb.iter_mut().enumerate() {
        if aa[i] < *b {
            ans += aa[i];
            *b -= aa[i];
            let sub = std::cmp::min(aa[i+1], *b);
            aa[i+1] -= sub;
            ans += sub;
         } else {
                ans += *b;
        }
    }

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

Measured memory_bytes: 9972
# ABC065 C Reconciled?

import math

n, m = map(int, input().split())
A = 10**9 + 7

if abs(n-m) > 1:
    print("0")
elif n == m:
    print(((math.factorial(m)**2)*2)%A)
else:
    print((math.factorial(m)*math.factorial(n))%A)

Measured memory_bytes: 5184
#include <iostream>
using namespace std;
int n;
int AC=0, WA=0, TLE=0, RE=0;
int main() {
    cin >> n;
    for (int i=1; i <=n; i++) {
        string s;
        cin >> s;
        if (s=="AC") {
            AC += 1;
        }
        else if (s=="WA") {
            WA += 1;
        }
        else if (s == "TLE") {
            TLE += 1;
        }
        else {
            RE += 1;
        }

    }
    cout << "AC x " << AC << endl;
    cout << "WA x " << WA << endl;
    cout << "TLE x " << TLE << endl;
    cout << "RE x " << RE << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <iomanip>
#include <stdio.h>
using namespace std;

int main()
{
	int num[200]={0};
	int n;
	int x;
	int a=0;
	
	while(1){
		cin >> n >> x;
		if(n == 0 && x==0)	break;
		for(int i=1; i<=n; i++)
			for(int j=i+1; j<=n; j++)
				for(int k=j+1; k<=n; k++)
					if(i+j+k == x)
						num[a]++;
		a++;
	};
		
	for(int i=0; i<a; i++)
		cout << num[i] << endl;
	
	return 0;
}



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

int main() {
  int N, M;
  int sum=0;
  cin >> N >> M;
  vector<int> vec(110);
  for (int i = 0; i < N; i++) {
      cin >> vec.at(i);
      sum+=vec.at(i);
}
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());



  double evaluate=(double)sum/(4*M);


  if(vec.at(M-1)>=evaluate){
      cout << "Yes" << endl; 
  }
  else{
      cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
using namespace std;
long long int gcd(long long int x,long long int  y){
   if(y==0)return x;
   return gcd(y,x%y);
}
int main(){
IOS;
int l,ma=0,k;
string s,t;
cin>>s>>t;
for(int i=0;i<s.size()-t.size()+1;i++){
    l=0;
    k=i;
    for(int j=0;j<t.size();j++,k++){
      if(s[k]==t[j])l++;
    }
ma=max(ma,l);
}
cout<<t.size()-ma;
return 0;
}
/*sjleepy*/


Measured memory_bytes: 3648
def input(f):
    global v, e, r
    global s, t, w
    
    v, e, r = map(int, f.readline().split())
    s = []
    t = []
    w = []
    for _ in range(e):
        s_, t_, w_ = map(int, f.readline().split())
        s.append(s_)
        t.append(t_)
        w.append(w_)

def solve(v, edges, r):
    best = [(10**18, -1) for _ in range(v)]
    for s, t, w in edges:
        best[t] = min(best[t], (w, s))
    best[r] = (0, -1)
    
    group = [0] * v
    comp = [0] * v
    used = [0] * v
    cnt = 0
    for i in range(v):
        if used[i]:
            continue
        
        chain = []
        cur = i
        
        while not used[cur] and cur != -1:
            chain.append(cur)
            used[cur] = 1
            cur = best[cur][1]
        
        if cur != -1:
            cycle = 0
            for x in chain:
                group[x] = cnt
                if x == cur:
                    cycle = 1
                    comp[cnt] = 1
                if not cycle:
                    cnt += 1
            if cycle:
                cnt += 1
        else:
            for x in chain:
                group[x] = cnt
                cnt += 1
    
    if cnt == v:
        return sum(map(lambda x: x[0], best))
    
    next_edges = []
    for s, t, w in edges:
        gs = group[s]
        gt = group[t]
        if gs == gt:
            continue
        if comp[gt]:
            next_edges.append((gs, gt, w - best[t][0]))
        else:
            next_edges.append((gs, gt, w))
    
    res = sum(best[x][0] for x in range(v) if x != r and comp[group[x]])
    return res + solve(cnt, next_edges, group[r])

with open('/dev/stdin') as f:
    input(f)

    edges = []
    for i in range(e):
        edges.append((s[i], t[i], w[i]))
    res = solve(v, edges, r)

    print(res)


Measured memory_bytes: 7236
#include<iostream>
#include<cmath>

using namespace std;


int main(){
    int W,H,N;
    cin>>W>>H>>N;

    int xmin=0,xmax=W,ymin=0,ymax=H;


    for(int i=0;i<N;++i){
        int x,y,Q;
        cin>>x>>y>>Q;
        if(Q==1){
            if(xmin<x)
            xmin=x;

        }else if(Q==2){
            if(xmax>x)
            xmax=x;
        }else if(Q==3){
            if(ymin<y)
            ymin=y;
        }else{
            if(ymax>y)
            ymax=y;
        }


    }

    if(ymax-ymin<0||xmax-xmin<0){
        cout<<0<<endl;
    }else{
        cout<<(ymax-ymin)*(xmax-xmin)<<endl;
    }



}


Measured memory_bytes: 256