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

int main(){
    string S;
    cin >> S;
    if( (S[0]=='0' && S[1]!='0') || (S[0]=='1' && (S[1] == '0' || S[1] == '1' || S[1] == '2' ) ) ){
        if( (S[2]=='0' && S[3]!='0') || (S[2]=='1' && (S[3] == '0' || S[3] == '1' || S[3] == '2' ) ) ){
            cout << "AMBIGUOUS" << endl;
            return 0;
        }else{
            cout << "MMYY" << endl;
            return 0;
        }
    }else{
        if( (S[2]=='0' && S[3]!='0') || (S[2]=='1' && (S[3] == '0' || S[3] == '1' || S[3] == '2' ) ) ){
            cout << "YYMM" << endl;
            return 0;
        }else{
            cout << "NA" << endl;
            return 0;
        }        
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using ll = long long;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;

int main()
{
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A), b(B);
    rep(i, A) cin >> a.at(i);
    rep(i, B) cin >> b.at(i);
    vector<int> x(M), y(M), c(M);
    rep(i, M) cin >> x.at(i) >> y.at(i) >> c.at(i);

    // 割引券なしで買ったときに一番安い金額
    int min_a = INT_MAX, min_b = INT_MAX;
    rep(i, A)
    {
        min_a = min(min_a, a.at(i));
    }
    rep(i, B)
    {
        min_b = min(min_b, b.at(i));
    }
    int answer1 = min_a + min_b;

    // 割引券ありで買ったときに一番安い金額
    int answer2 = INT_MAX;
    rep(i, M)
    {
        answer2 = min(answer2, a.at(x.at(i) - 1) + b.at(y.at(i) - 1) - c.at(i));
    }

    cout << min(answer1, answer2) << endl;
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>  // sort, 二分探索, etc
#include <iomanip>  // setprecision (浮動小数点の出力の誤差)
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cmath>
#include <list>
#include <assert.h>
using namespace std;

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=a,i##_len=(b);i<i##_len;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define cauto const auto&
#define UNIQUE(v) (v).erase( unique(all(v), (v).end() );
#define SZ(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define SUM(v) accumulate((v).begin(), (v).end(), (ll)0)
#define INF 1000000000000
#define MOD 1000000007
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }

using ll = long long;
using ull = unsigned long long;

template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return true;}return false;}

const char newl = '\n';

ll qp(ll a,ull b){ll ans=1;do{if(b&1u)ans*=a;a*=a;}while(b>>=1u);return ans;}
ll qp(ll a,ull b,ll mod){ll ans=1;do{if(b&1u)ans=ans*a%mod;a=a*a%mod;}while(b>>=1u);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll comb(int n, int r) {
    vector<vector<ll> > v(n+1, vector<ll>(r+1, 0));
    for(int i=0;i<n+1;i++) {v[i][0]=1; if(i < r+1)v[i][i]=1; }
    for(int i=1;i<n+1;i++) {for(int j=1;j<min(i,r+1);j++) {v[i][j]=v[i-1][j-1]+v[i-1][j];}}
    return v[n][r];
}

// INT_MAX   = 2.1e+09 (2147483647)
// LONG_MAX  = 9.2e+18 (9223372036854775807)
// LLONG_MAX = 9.2e+18 (9223372036854775807)


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

    ll total = 0;
    ll cur = -1;
    rep(i, n) {
        ll x; cin >> x;
        if (cur == -1) {
            cur = x;
            continue;
        }
        total += max((ll)0, cur - x);
        cur = max(x, cur);
    }

    cout << total << newl;

    return 0;
}


Measured memory_bytes: 3116
#include<iostream>
#include<algorithm>
using namespace std;
 
int main()
{
	string str;
	int tmp;
	int ans=1e3;
	
	cin >> str;
	for(int i=2;i<str.size();i++)
	{
		tmp=(str[i-2]-'0')*100+(str[i-1]-'0')*10+(str[i]-'0');
		ans=min(ans,abs(753-tmp));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
d = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}
for i in range(N):
    s = input()
    d[s] += 1
print('AC x ' + str(d['AC']))
print('WA x ' + str(d['WA']))
print('TLE x ' + str(d['TLE']))
print('RE x ' + str(d['RE']))


Measured memory_bytes: 9196
import java.util.*;
import java.io.*;
public class Main{
    public static void main(String [] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int [][] path=new int[n][m];
        for(int i=0;i<n;i++){
            String s=sc.next();
            for(int j=0;j<s.length();j++){
                if(s.charAt(j)=='#'){
                    path[i][j]=-1;
                }
            }
        }

        for(int i=1;i<m;i++){
           if(path[0][i]!=-1){
               path[0][i]=1;
           }else{
               break;
           }
        }
        for(int i=1;i<n;i++){
            if(path[i][0]!=-1){
                path[i][0]=1;
            }else{
                break;
            }
        }
        int mod=1000*1000*1000+7;

        for(int i=1;i<n;i++){
            for(int j=1;j<m;j++){
                if(path[i][j]!=-1){
                    int x=path[i][j-1]==-1?0:(path[i][j-1]);
                    int y=path[i-1][j]==-1?0:(path[i-1][j]);
                    path[i][j]=((x%mod)+(y%mod))%mod;
                }
                
            }
        }
        System.out.println(path[n-1][m-1]);



    }
}

Measured memory_bytes: 32680
n, c, k = map(int, input().split())
t = []
for _ in range(n):
    t.append(int(input()))
t.sort()
passenger = 0
bus_flag = False
bus_launch = 0
ans = 0
for i in range(n):
    if not bus_flag:
        bus_launch = t[i] + k
        bus_flag = True

    if t[i] <= bus_launch:
        passenger += 1
        if passenger == c:
            ans += 1
            bus_flag = False
            passenger = 0
    else:
        ans += 1
        bus_launch = t[i] + k
        passenger = 1

if passenger != 0:
    ans += 1
print(ans)




Measured memory_bytes: 81120
/* dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll ,ll>
#define vll          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  300005
ll l[N],r[N];
int main()
{
	ios
	ll n,i,j;
	cin>>n;
	string s;
	cin>>s;
	for(i=0;i<n;i++){
		if(s[i]=='E')r[i]=1;
		else l[i]=1;
	}
	for(i=1;i<n;i++)
		l[i]+=l[i-1];
	for(i=n-2;i>=0;i--)
		r[i]+=r[i+1];
	ll mn=hell;
	mn=r[1];mn=min(l[n-2],mn);
	for(i=1;i<n-1;i++){
		mn=min(mn,l[i-1]+r[i+1]);
	}
	cout<<mn;
	return 0;
}

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

#define ll long long int
#define str string
#define sec .second

ll MOD = 1000000007, INFL = 1ll << 60, INF = 1 << 30;
ll A[10000000] = {};
ll X[1000000] = {};
ll rui[100002] = {}, ruin[100002] = {};
int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
vector <ll> v;
ll a = 0, b = 0, c = 0, n = 0, sum = 0, max = INF, mi = -1;
string S;
bool an = false, bn = false;

int findDigits(int n) {
	int i = 0;
	while (n > 0) {

		X[i] = n % 10;
		n /= 10;
		i++;
	}
	return i;
}


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Code Line
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'o')sum++;
	}
	if (15 - S.size() + sum >= 8)cout << "YES" << endl;
	else  cout << "NO" << endl;

	//Code Line
	return 0;
}


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

using namespace std;

typedef __int128 LL;

int main(int argc, char *argv[]) {
  std::ios_base::sync_with_stdio(false);
  int n;
  long long D;
  cin >> n >> D;
  LL X = D;
  vector<LL> a(n + 1);
  vector<LL> b(n + 2);
  for (LL i = 1; i < b.size(); i++) {
    b[i] = i * i;
  }
  LL sum = 0;
  for (int i = 0; i < n; i++) {
    long long v;
    cin >> v;
    sum += v * 5;
    a[i + 1] = a[i] + v;
  }
  LL ans = sum + X * n;
  for (int i = 1; i <= n; i++) {
    LL now = sum;
    for (int j = n - i, k = 2; j > 0; j -= i, k++) {
      now += (a[j] - a[max(j - i, 0)]) * (b[k + 1] - b[k] - 5);
    }
    ans = min(ans, now + X * i);
  }
  cout << (long long)(ans + n * X) << endl;
  return 0;
}


Measured memory_bytes: 6656
n=int(input())
a=list(map(int,input().split()))
ans=0

l=r=s=0
while l<n:
    if s^a[r]==s+a[r]:
        s+=a[r]
        if r!=n-1:
            r+=1
        else:
            break
    else:
        ans+=r-l
        s-=a[l]
        l+=1

ans+=(r-l+1)*(r-l+2)//2

print(ans)

Measured memory_bytes: 32232
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<P,int>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
signed main(){
    int n;
    cin>>n;
    vvi vec(3,vi(n));
    REP(i,3){
        REP(j,n){
            cin>>vec[i][j];
        }
        sort(all(vec[i]));
    }
    vvi sum(3,vi(n));
    int now=0;
    REP(i,n){
        while(now<n&&vec[1][i]>=vec[2][now]){
            now++;
        }
        sum[1][i]=n-now;
    }
    FOR(i,1,n){
        sum[1][i]+=sum[1][i-1];
    }
    now=0;
    int ans=0;
    REP(i,n){
        while(now<n&&vec[0][i]>=vec[1][now]){
            now++;
        }
        sum[0][i]=sum[1][n-1];
        if(now)sum[0][i]-=sum[1][now-1];
        ans+=sum[0][i];
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> sum(n+1);
    sum[0] = 0;
    rep(i,n) {
        int w;
        cin >> w;
        sum[i+1] = sum[i]+w;
    }
    int ans = 1001001001;
    rep2(i,1,n) {
        int now = abs(sum[i]-(sum[n]-sum[i]));
        ans = min(ans,now);
    }
    cout << ans << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SZ(x) (int)(x).size()
#define mset(a,x) memset(a,x,sizeof(a))
#define dbg(x) cout<<#x<<": "<<(x)<<"\n"
#define pb push_back
#define mp make_pair

ll a,b,x;

int main() {
    cin>>a>>b>>x;

    if(a==0 and b==0){
        puts("1");
        return 0;
    } else if(a==0) {
        ll c = b / x;
        cout<<c+1<<endl;
        return 0;
    }

    ll c = b / x;
    ll d = (a-1) / x;
    ll res = c - d;

    cout << res << "\n";


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int n; cin >> n;
    string s; cin >> s;
    string s2 = s;
    int cnt = 0;
    rep(i,n) {
        if(s[i]=='(') {
            cnt++;
        }else {
            if(cnt!=0) {
                --cnt;
            }else {
                s2 = '(' + s2;
            }
        }
    }
    s2 += string(cnt,')');
    cout << s2 << endl;

    return 0;
}

Measured memory_bytes: 256
s = input()
q = int(input())
t = 0
form = ""
late = ""
for i in range(q):
  l = list(input().split())
  if l[0] == "1":
    t += 1
  else:
    if t % 2 == 0:
      if l[1] == "1":
        form = l[2] + form
      else:
        late += l[2]
    else:
      if l[1] == "1":
        late += l[2]
      else:
        form = l[2] + form
if t % 2 == 0:
  ans = form + s + late
else:
  ans = late[::-1] + s[::-1] + form[::-1]
print(ans)

Measured memory_bytes: 4448
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;

int main() {
  int H,W,N;
  cin >> H >> W >> N;
  int a[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  int ans[H][W];
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < a[i]; j++) {
      int c = (cnt + j) / W;
      int d = (cnt + j) % W;   
      if (c % 2 == 1) {
        ans[c][(W-1-d)] = i+1;
      } else {
        ans[c][d] = i+1;
      }
    }
    cnt += a[i];
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3592
class Combination:
    def __init__(self,N,P=10**9+7):
        if N > 10**7:
            self.fact = lambda x: x * self.fact(x-1) % P if x > 2 else 2
            self.perm = lambda x, r: x * self.perm(x-1,r-1) % P if r > 0 else 1
            self.cmb = lambda n,r: (self.perm(n,min(n-r,r)) * pow(self.fact(min(n-r,r)) ,P-2 ,P) % P) if r > 0 else 1
        else:
            self.__fact = [1] * (N+1)
            self.__inv = [1] * (N+1)
            self.__inv_fact = [1] * (N+1)
            for i in range(2,N+1):
                self.__fact[i] = self.__fact[i-1] * i % P
                self.__inv[i] = - self.__inv[P%i] * (P//i) % P
                self.__inv_fact[i] = self.__inv_fact[i-1] * self.__inv[i] % P
            self.fact = lambda n: self.__fact[n]
            self.perm = lambda n,r: self.__fact[n] * self.__inv_fact[n-r] % P
            self.cmb = lambda n,r: (self.__fact[n] * self.__inv_fact[n-r] * self.__inv_fact[r] % P) if n >= r > 0 else 0 if r > n else 1

def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10



    

    S = II()
    cmb = Combination(S,P)
    if S <= 2:
        print(0)
        return
    ans = 0
    for i in range(1,S//3+1):
        x = S - 3*i
        ans += cmb.cmb(x+i-1,i-1)
        ans %= P
    print(ans)

    

    
main()

Measured memory_bytes: 67968
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
using System.Text;
using System.Diagnostics;

class Program
{
    static void Main()
    {
        int[] nm = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        int n = nm[0];
        int m = nm[1];
        int[][] ab = Enumerable.Repeat(0, m).Select(_ => Console.ReadLine().Split(' ').Select(int.Parse).ToArray()).ToArray();
        List<Tuple<int, int>> d = new List<Tuple<int, int>>();


        for (int i = 0; i < m; i++)
        {
            d.Add(new Tuple<int, int>(ab[i][0], ab[i][1]));
        }

        d = d.OrderBy(i => i.Item2).ToList();

        int ans = 0;
        int destroy = 0;

        for(int i = 0; i < m; i++)
        {
            if(destroy <= d[i].Item1)
            {
                destroy = d[i].Item2;
                ans++;
            }
        }

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 31412
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define all(v) (v).begin(),(v).end()
int main(){
	int n;
	cin>>n;
	vector<pair<int,int>> an(n);
	rep(i,n){
		cin>>an.at(i).second>>an.at(i).first;
	}
	sort(all(an));
	ll ans=0;
	int flag=1;
	rep(k,n){
		ans+=an.at(k).second;
		if(ans>an.at(k).first){
			flag=0;
		}
	}
	if(flag==1){
		cout<<"Yes"<<endl;
	}else if(flag==0){
		cout<<"No"<<endl;
	}
	return 0;
}

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

#define mp make_pair

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef pair<i64,int> pli;
typedef pair<int,i64> pil;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;

const int MAX_N = 50;
int n;
int a[MAX_N];

int main()
{
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  vector<pii> inst;
  auto p = minmax_element(a,a+n);
  int min_i = p.first - a, max_i = p.second - a;
  int min_v = *p.first, max_v = *p.second;
  if (min_v < 0 && max_v >= 0) {
    if (abs(min_v) >= abs(max_v)) {
      for (int i = 0; i < n; i++) {
        if (a[i] > min_v) {
          inst.push_back(mp(min_i+1,i+1));
          a[i] += min_v;
        }
      }
    } else {
      for (int i = 0; i < n; i++) {
        if (a[i] < max_v) {
          inst.push_back(mp(max_i+1,i+1));
          a[i] += max_v;
        }
      }
    }
  }

  if (a[0] >= 0) {
    for (int i = 0; i < n-1; i++) {
      if (a[i+1] < a[i]) {
        inst.push_back(mp(i+1,i+2));
        a[i+1] += a[i];
      }
    }
  } else {
    for (int i = n-1; i > 0; i--) {
      if (a[i-1] > a[i]) {
        inst.push_back(mp(i+1,i));
        a[i-1] += a[i];
      }
    }
  }

  cout << inst.size() << endl;
  for (auto p : inst) {
    cout << p.first << " " << p.second << endl;
  }

  return 0;
}


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

signed main(void){
    int n; cin >> n;
    for(int i=1;i<10;i++){
        if(n%i==0 && n/i<10){
            cout << "Yes" <<endl;
            return 0;
        } 
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define REPR(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) \
  for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define FORR(i, a, b) \
  for (int i = static_cast<int>(b) - 1; i >= static_cast<int>(a); --i)
#define ALL(f, x, ...) \
  ([&](auto &y) { return (f)(begin(y), end(y), ##__VA_ARGS__); })(x)
#define INDEX(x, xs) &x - &xs[0]

void async_io() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
const auto inf = INT_MAX / 3;
const auto pi = 2 * std::acos(0.0);
const auto eps = 1e-14;
using ll = long long int;
using ull = unsigned long long;

signed main() {
  async_io();
  int n;
  while (true) {
    cin >> n;
    if (n == 0) return 0;
    auto sum = 0;
    for (int i = 2;; i++) {
      auto base = i * (i + 1) / 2;
      if (base > n) break;
      if ((base - n) % i == 0) sum++;
    }
    cout << sum << "\n";
  }
}

Measured memory_bytes: 3004
//2019.8.3 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f
#define eps 5.6e-8
#define RG register
#define db double
#define pc(x) __builtin_popcount(x)
typedef pair<int,LL> Pair;
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pb push_back
#define gc getchar
//inline char gc() {
//    static char buf[100000],*p1,*p2;
//    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
//inline int read() {
//    res s=0,ch=gc();
//    while(ch<'0'||ch>'9')ch=gc();
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s;
//}
inline int read() {
    res s=0,ch=gc(),w=1;
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s*w;
}
inline LL Read() {
    RG LL s=0;
    res ch=gc();
    while(ch<'0'||ch>'9')ch=gc();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s;
}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
inline void swap(res &x,res &y) {
    x^=y^=x^=y;
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//clock_t start=clock();
//inline void ck(){
//    if(1.0*(clock()-start)/CLOCKS_PER_SEC>0.1)exit(0);
//}
const int N=1e5+10;
namespace MAIN {
    char str[N];
    int n;
    int a[N];
    inline void MAIN() {
        scanf("%s",str+1),n=int(strlen(str+1));
        res las=0;
        for(res i=1;i<=n;i++){
            if(str[i]=='L'&&str[i-1]=='R'){
                las=i;
                a[i]++;
            }
            else if(str[i]=='L'){
                if((i-las)&1)a[las-1]++;
                else a[las]++;
            }
        }
        las=0;
        for(res i=n;i;i--){
            if(str[i]=='R'&&str[i+1]=='L'){
                las=i;
                a[i]++;
            }
            else if(str[i]=='R'){
                if((las-i)&1)a[las+1]++;
                else a[las]++;
            }
        }
        for(res i=1;i<=n;i++)printf("%d ",a[i]);
    }
}
int main() {
//    srand((unsigned)time(NULL));
//    freopen("nothard.in","r",stdin);
//    freopen("nothard.out","w",stdout);
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 896
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
#if DEBUG
        Solve(4, 3, 3);
        for (int i = 1; i < 16; i++)
        {
            for (int j = 1; j < 16; j++)
            {
                for (int k = 0; k < 16; k++)
                {
                    var resa = Stupid(i, j, k);
                    var resb = Solve(i, j, k);
                    if (resa != resb)
                    {
                        Console.WriteLine($"{i} {j} {k}");
                    }
                }
            }
        }
#endif
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var p = a[0];
        var q = a[1];
        var r = a.Aggregate(0L, (x, y) => x ^ y) ^ p ^ q;
        Console.WriteLine(Solve(p, q, r));
    }

    static long Stupid(long p, long q, long r)
    {
        for (int i = 0; i < p; i++)
        {
            if (((p - i) ^ (q + i)) == r) return i;
        }
        return -1;
    }

    static long Solve(long p, long q, long r)
    {
        long[][] dp = Enumerable.Range(0, 2).Select(_ => new long[2] { long.MaxValue >> 1, long.MaxValue >> 1 }).ToArray();
        dp[0][0] = 0;
        for (int bit = 0; bit <= 40; bit++)
        {
            var pbit = p >> bit & 1;
            var qbit = q >> bit & 1;
            var rbit = r >> bit & 1;
            var defBit = pbit ^ qbit ^ rbit;

            long[][] newdp = Enumerable.Range(0, 2).Select(_ => new long[2] { long.MaxValue >> 1, long.MaxValue >> 1 }).ToArray();

            for (int i = 0; i <= 1; i++)
            {
                for (int j = 0; j <= 1; j++)
                {
                    var bitChange = i ^ j;
                    if (defBit != bitChange) continue;
                    var ni = i == 1 && pbit == 0 ? 1 : 0;
                    var nj = j == 1 && qbit == 1 ? 1 : 0;
                    //そのまま
                    newdp[ni][nj] = Min(newdp[ni][nj], dp[i][j]);
                    //引く
                    //既に繰り下がりが置きてる時は
                    var nni = i == 0 && pbit == 1 ? 0 : 1;
                    var nnj = j == 0 && qbit == 0 ? 0 : 1;
                    newdp[nni][nnj] = Min(newdp[nni][nnj], dp[i][j] + (1L << bit));
                }
            }
            dp = newdp;
        }
        var res = dp.Min(x => x.Min());
        if (p <= res) res = -1;
        return res;
    }
}

Measured memory_bytes: 28528
//d
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
    int N,M;
    cin >> N >> M;
    vector<vector<int>> connection(N+1,vector<int>(0));
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        connection[a].push_back(b);
        connection[b].push_back(a);
    }
    vector<int> res(N+1,0);
    vector<int> found = {1};
    while (found.size()) {
        vector<int> concern = found;
        found = {};
        for (int i : concern) {
            for (int j : connection[i]) {
                if (res[j] == 0) {
                    res[j] = i;
                    found.push_back(j);
                }
            }
        }
    }
    cout << "Yes" << endl;
    for (int i = 2; i < N+1; i++) {
        cout << res[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 10656
#include <stdio.h>

int main(){

    int N, Q;
    scanf("%d %d", &N, &Q);

    int i, j, cnt=0, flag, l, r, acnum[N], accnt[N];
    char S[N+1];

    scanf("%s", S);

    for (i=0; i<N; i++){
        if (S[i] == 'A'){
            flag = 1;
        }
        if (S[i] == 'C' && flag == 1){
            acnum[cnt] = i-1;
            cnt++;
        }
        if (S[i] != 'A'){
            flag = 0;
        }
    }

    cnt = 0;
    for (i=0; i<N; i++){
        accnt[i] = cnt;
        if (i == acnum[cnt]){
            cnt++;
        }
    }

    for(i=0; i<Q; i++){
        scanf("%d %d", &l, &r);
        printf("%d\n",accnt[r-1]-accnt[l-1]);
    }

    return 0;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

int H, W;
vector<vector<int>> G;

int cnt = 0;
void painting(int x, int y, int tar, vector<int> &A, bool &judge) {
    G[y][x] = tar + 1;
    cnt++;
    A[tar]--;
    if (A[tar] == 0)
        tar++;
    if (cnt == H * W)
        return;
    int nx, ny;
    if (judge && y == H - 1) {
        judge = 0;
        ny = H - 1;
        nx = x + 1;
    } else if (!judge && y == 0) {
        judge = 1;
        ny = 0;
        nx = x + 1;
    } else if (judge) {
        nx = x;
        ny = y + 1;
    } else {
        nx = x;
        ny = y - 1;
    }
    painting(nx, ny, tar, A, judge);
}

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

    cin >> H >> W;
    int N;
    cin >> N;
    G.assign(H, vector<int>(W));
    vector<int> A(N);
    rep(i, N) { cin >> A[i]; }

    bool judge = 1;
    painting(0, 0, 0, A, judge);

    rep(i, H) {
        rep(j, W) { cout << G[i][j] << " "; }
        cout << endl;
    }
}

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

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

    vector<queue<long long>> A(N);
    long long a;
    for (queue<long long> &q : A)
    {
        for (long long i = 0; i < N - 1; i++)
        {
            cin >> a;
            a--;
            q.push(a);
        }
    }

    vector<bool> used(N, false);
    queue<pair<long long, long long>> q;
    for (long long i = 0; i < N; i++)
    {
        long long front = A[i].front();
        if (!used[i] && !used[front])
        {
            if (A[front].front() == i)
            {
                q.push(make_pair(i, front));
                A[i].pop();
                A[front].pop();
                used[i] = true;
                used[front] = true;
            }
        }
    }

    long long sum = 0;
    long long ans = 0;
    while (!q.empty())
    {
        ans++;
        sum += q.size();
        queue<pair<long long, long long>> tmp(q);
        queue<pair<long long, long long>>().swap(q);
        used = vector<bool>(N, false);
        long long front;
        while (!tmp.empty())
        {
            long long a = tmp.front().first;
            long long b = tmp.front().second;
            tmp.pop();

            if (!A[a].empty())
            {
                front = A[a].front();
                if (!used[a] && !used[front])
                {
                    if (A[front].front() == a)
                    {
                        q.push(make_pair(a, front));
                        A[a].pop();
                        A[front].pop();
                        used[a] = true;
                        used[front] = true;
                    }
                }
            }

            if (!A[b].empty())
            {
                front = A[b].front();
                if (!used[b] && !used[front])
                {
                    if (A[front].front() == b)
                    {
                        q.push(make_pair(b, front));
                        A[b].pop();
                        A[front].pop();
                        used[b] = true;
                        used[front] = true;
                    }
                }
            }
        }
    }
    if (sum < (N * (N - 1) / 2))
    {
        ans = -1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 8960
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


ll ara[Max+10];

int main()
{



   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;

      string str;

        cin>>n;



        for(i=1; i<=n; i++)
        {
            for(j=i; j<=n; j+=i)
                ara[j]++;
        }

        for(i=1; i<n; i++)
            sum+=ara[i];

        cout<<sum<<endl;




}



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

using namespace std;

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

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

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

ll w[110];
ll v[110];
ll dp[3010][3010];

//long longしか使わない
//素数は1より大きい
int main() {
	string s, t;
	cin >> s >> t;
	ll n = s.length();
	ll m = t.length();
	rep(i, n) {
		rep(j, m) {
			if (s[i] == t[j]) {
				dp[i + 1][j + 1] = dp[i][j] + 1;
			}
			else {
				dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
			}
		}
	}
	string ans;
	while (n > 0 && m > 0) {
		if (dp[n][m] == dp[n - 1][m]) {
			n--;
		}
		else if (dp[n][m] == dp[n][m-1]) {
			m--;
		}
		else {
			ans = s[n - 1] + ans;
			n--;
			m--;
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
    int N;
    cin >> N;
    int f = 0;
    int N_stock = N;
    while (N != 0){
        f += N % 10;
        N /= 10;
    }
    if (N_stock % f== 0){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var N, M int

func main() {
	readVariables()
	ans := c2(N) + c2(M)
	fmt.Println(ans)
}

func c2(x int) int {
	if x < 2 {
		return 0
	}
	return x * (x - 1) / 2
}
func readVariables() {
	N, M = nextInt(), nextInt()

}

/* Template */

var scanner *bufio.Scanner

func init() {
	Max := 1001001
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, Max), Max)
	scanner.Split(bufio.ScanWords)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}

// MinInt returns minimum argument
func MinInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

//MaxInt returns maximum argument
func MaxInt(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

//AbsInt returns |x| for x
func AbsInt(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//ModPow calculates integer power with modulo operation
//if modulo <= 1, it powers w/o module operation
//if base < 0, return value might be negative too.
func ModPow(base, exponent, modulo int) (result int) {
	result = 1
	for exponent > 0 {
		if exponent%2 == 1 {
			result *= base
			if modulo > 1 {
				result %= modulo
			}
		}
		base *= base
		if modulo > 1 {
			base %= modulo
		}
		exponent /= 2
	}
	return
}

//Gcd
func Gcd(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = gcd(result, vals[i])
	}
	return
}

func gcd(x, y int) int {
	x, y = AbsInt(x), AbsInt(y)
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

//Lcm
func Lcm(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = lcm(result, vals[i])
	}
	return
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}


Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
typedef struct{
    int a,b;
}data;

//昇順
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
//構造体降順
int comp( const void *c1, const void *c2 )
{
  data test1 = *(data *)c1;
  data test2 = *(data *)c2;
  int tmp1 = test1.b;   /* b を基準とする */
  int tmp2 = test2.b;
  return tmp2 - tmp1;
}


int kai(int n){
    if(n==0){
        return 1;
    }
    int sum=1;
    for(int i=1;i<=n;i++){
        sum*=i;
    }
    return sum;
}

int main(){
    char alf[100001];
    scanf("%s",alf);
    int a[26]={0};
    rep(i,(int)strlen(alf)){
        a[alf[i]-'0'-49]++;
    }
    char b[26]="abcdefghijklmnopqrstuvwxyz";
    rep(i,26){
        if(a[i]==0){
            printf("%c",b[i]);
            return 0;
        }else{
            ;
        }
    }
    printf("None");
}



Measured memory_bytes: 1704
local mod = 1000000007
local mfl = math.floor

-- 10^9 + 7 only
-- (31623^2) % 1000000007 = 14122
local function bmul(x, y)
  local x0, y0 = x % 31623, y % 31623
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end

local function badd(x, y)
  return (x + y) % mod
end

local function bsub(x, y)
  return x < y and x - y + mod or x - y
end

local function modpow(src, pow)
  local res = 1
  while 0 < pow do
    if pow % 2 == 1 then
      res = bmul(res, src)
      pow = pow - 1
    end
    src = bmul(src, src)
    pow = mfl(pow / 2)
  end
  return res
end

local function modinv(src)
  return modpow(src, mod - 2)
end

local function getComb(n, k)
  local ret = 1
  for i = 1, k do
    ret = bmul(ret, n + 1 - i)
    ret = bmul(ret, modinv(i))
  end
  return ret
end

local n, k = io.read("*n", "*n")
if n - 1 <= k then
  print(getComb(n + n - 1, n))
else
  local ret = 1
  local comb1, comb2 = 1, 1
  for i = 1, k do
    local inv = modinv(i)
    comb1 = bmul(comb1, n + 1 - i)
    comb1 = bmul(comb1, inv)
    comb2 = bmul(comb2, n - i)
    comb2 = bmul(comb2, inv)
    local v = comb1
    v = bmul(v, comb2)
    -- local v = getComb(n, i)
    -- v = bmul(v, getComb(n - 1, i))
    ret = badd(ret, v)
  end
  print(ret)
end


Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        String word = scan.next();
        for(int i = 0; i < word.length(); i++) {
            int sub = word.length() - i;
            String w = word.substring(0, sub);
            if(i == 0 || sub % 2 != 0) continue;
            if(w.substring(0, sub/2).equals(w.substring(sub/2, sub))) {
                System.out.println(sub);
                return;
            }
        }
    }
}


Measured memory_bytes: 23892
N = int(input())
ans = 'No'
ls = []
for i in range(N):
    d1,d2 = map(int,input().split())
    ls.append([d1,d2])
ii = 0
for i in range(N):
    if ls[i][0] == ls[i][1]:
        ii += 1
    else:
        ii = 0

    if ii == 3:
        ans = 'Yes'
        break
print(ans)

Measured memory_bytes: 9192
#include<iostream>

int main(){
	//入力機構
	int D,N;
	std::cin>>D>>N;


	//処理機構
	int ans;
	//ちょうどN回に気をつけておけばよい
	//つまり100^Dで割り切れ、100^(D+1)で割り切れないN番目に大きい値は100^D*(N+floor(N/100))
	int d1=1,d2=1;
	for(int i=0;i<D;i++){
		d1*=100;
	}
	ans=d1*(N+N/100);//int計算なので勝手に切り下げされる

	//出力機構
	std::cout<<ans<<std::endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
main(){
  int i,j,mini=0,a,n,count=0;
  int A[100];
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }

  for(i=0;i<=n-1;i++)
    {
      mini=i;
      for(j=i;j<=n-1;j++)
	{
	  if(A[j]<A[mini])
	    {
	      mini=j;
	    }
	}
      if(A[i]>A[mini]) count++;
      a=A[i];
      A[i]=A[mini];
      A[mini]=a;
    }
  for(i=0;i<n;i++)
    {
      printf("%d",A[i]);
      if(i<n-1) printf(" ");
    }
  printf("\n");
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 604
def is_kaibun(s):
    l = len(s)
    for i in range(0, l):
        if s[i] != s[l-i-1]:
            return False
    return True

def is_strong_kaibun(s):
    n = len(s)
    s1 = s[:(n-1)//2]
    s2 = s[(n+3)//2-1:]

    return is_kaibun(s) and is_kaibun(s1) and is_kaibun(s2)


s = input()
ans = 'Yes' if is_strong_kaibun(s) else 'No'
print(ans)


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

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) {}
#endif





ll n;

int main(){
	cin >> n;
	map<ll,int> m;
	set<ll,greater<ll>> s;
	
	rep(i,n){
		ll a;
		cin >> a;
		m[a]++;
		s.insert(a);
	}
	
	ll ct = 0;
	for ( auto x : s ){
		ll b = 1;
		while ( b <= x )
			b *= 2;
		ll y = b - x;
		
		if ( s.count(y) ){
			if ( x != y ){
				while ( m[x] && m[y] ){
					m[x]--;
					m[y]--;
					ct++;
					eprintf( " %lld %lld\n", x, y );
				}
			}
			else {
				while ( m[x] >= 2 ){
					m[x] -= 2;
					ct++;
					eprintf( " %lld %lld\n", x, y );
				}
			}
		}
	}
	
	cout << ct << endl;
	
	return 0;
}




Measured memory_bytes: 25496
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define ld long double
#define pii pair<int,int>
#define fi first
#define se second
#define mex 1000005
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//vector<int> adj[mex];
//a+b=a^b+2*(a&b)

int main(){
	fast
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
	 cin>>a[i];
	sort(a,a+n);
	long long s=0;
	for(int i=0;i<k;i++)
	 s=s+a[i];
	cout<<s;  
}


Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

// #include <unordered_set>
// #include <unordered_map>

#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

#define pb push_back
#define mp make_pair

int gcd(int a, int b) {
    int c;
    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}

int lcm(int a, int b) {
    int c = gcd(a, b);
    a /= c;
    return a * b;
}

typedef std::pair<int, int> P;
typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const double EPS = 1e-10;
const double PI = acos(-1.0);


#define int long long

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


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

    vector<int> v;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    v.push_back(d);

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

    if (v[0] == 1 && v[1] == 4 && v[2] == 7 && v[3] == 9) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }


}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <iterator>
#include <random>
#include <cmath>
#include <functional>


using namespace std;
using lint = long long int;


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

	list<char> lst;
	for (int i = 0; i < s.length(); i++) {
		lst.push_back(s[i]);
	}

	bool reverse = false;
	for (int i = 0; i < qn; i++) {
		int query;
		cin >> query;
		if (query == 1) {
			reverse = !reverse;
		}
		else {
			int f;
			char c;
			cin >> f >> c;
			if (f == 1) {
				if (!reverse)
					lst.push_front(c);
				else
					lst.push_back(c);
			}
			else {
				if (!reverse)
					lst.push_back(c);
				else
					lst.push_front(c);
			}
		}
	}

	string str = "";
	if (!reverse) {
		for (auto itr = lst.begin(); itr != lst.end(); itr++) {
			str += *itr;
		}
	}
	else {
		for (auto itr = lst.rbegin(); itr != lst.rend(); itr++) {
			str += *itr;
		}
	}

	cout << str;
}



Measured memory_bytes: 10500
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int count = 0;
    rep(i, A + 1) {
        rep(j, B + 1) {
            int c = (X - i * 500 - j * 100) / 50;
            if (c > C || c < 0) continue;
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std ;

const long long mod = 1e9 + 7ll ;

const int MAX = 2e5 + 5 ;

int n ;

int add(int x , int y)
{
	if(x >= mod)
		x -= mod ;
	if(y >= mod)
		y -= mod ;
	int z = x+y ;
	if(z >= mod)
		z -= mod ;
	return z ;
}

int arr[MAX] ;
string s ;

int main()
{
	//ios_base::sync_with_stdio(0) ;
	//cin.tie(0) ;
	cin>>n ;
	cin>>s ;
	for(int i = 0 ; i < n*2 ; ++i)
	{
		if(s[i] == 'W')
			arr[i] = 0 ;
		else
			arr[i] = 1 ;
	}
	long long ans = 1ll ;
	long long moves = 0 ;

	for(int i = 0 ; i < n*2 ; ++i)
	{
		if((arr[i] + moves) % 2 != 0)
			moves++ ;
		else
		{
			ans = (ans * moves) % mod ;
			ans %= mod ;
			moves-- ;
		}
		if(moves > n || moves < 0)
			return cout<<0<<"\n" , 0 ;
	}
	if(moves != 0)
		return cout<<0<<"\n" , 0 ;
	long long fact = 1ll ;
	for(int i = 2 ; i <= n ; ++i)
	{
		fact = (fact * i) % mod ;
		fact %= mod ;
	}
	ans = (ans * fact) % mod ;
	ans %= mod ;
	return cout<<ans<<"\n" , 0;
}







Measured memory_bytes: 1284
X,K,D = map(int, input().split())

if X<0:
    X = -X
if X - K*D >= 0:
    print(X-K*D)
else:
    i = 0
    while True:
        i+=1
        X -= D
        if X < 0:
            break
    if (K-i) % 2 == 0:
        print(abs(X))
    else:
        print(D-abs(X))



Measured memory_bytes: 62788