akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main() {
	string str;
	cin >> str;
	int a = 0, b = 0;
	for (int i = 0; i < str.length(); i++) {
		if (str[i] == 'A') {
			a++;
		} else {
			b++;
		}
	}
	if (a > 0 && b > 0)
		cout << "Yes\n";
	else
		cout << "No\n";
}

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

int main() {
    int k, x;
    cin >> k >> x;
    if (500*k >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i,n) cin >> l.at(i);
    sort(l.begin(), l.end());
    int ans = 0;
    rep(i,n-2) {
        for (int j = i+1; j < n-1; ++j) {
            if (l.at(i) == l.at(j)) continue;
            for (int k = j + 1; k < n; ++k) {
                if (l.at(j) == l.at(k)) continue;
                if (l.at(i) + l.at(j) > l.at(k)) {
                    ++ans;
                }
            }
        }
    }

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

Measured memory_bytes: 3568
n = int(input())
a = input()
b = input()
c = input()
ans = 0
for i in range(n):
  if a[i].count(b[i]) + b[i].count(c[i]) + c[i].count(a[i]) != 3:
    ans += 2 - (a[i].count(b[i]) + b[i].count(c[i]) + c[i].count(a[i]))
print(ans)

Measured memory_bytes: 3064
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES

#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <functional>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <iterator>
#include <bitset>
#include <complex>
#include <limits>
#include <random>


using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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 (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;

const double EPS = 1e-9;

int DP1[51][21], DP2[51][21];

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

	int N;
	cin >> N;

	string S;
	vector<pii> DV(N, mp(0, 0));

	const int M = 1000000000;

	rep(i, 0, N)
	{
		cin >> S;
		string fs = S, bs;
		rep(j, 0, SZ(S))
		{
			if (S[j] == '.')
			{
				fs = S.substr(0, j);
				bs = S.substr(j + 1);
				break;
			}
		}
		while (SZ(bs) < 9)bs += '0';
		fs += bs;
		int v = stoll(fs);

		if (v == 0)
		{
			DV[i].first = 50, DV[i].second = 20;
		}
		else
		{
			while (v % 2 == 0)
			{
				DV[i].first++;
				v /= 2;
			}
			while (v % 5 == 0)
			{
				DV[i].second++;
				v /= 5;
			}
		}
	}

	rep(i, 0, N)
	{
		rep(t, 0, 51)rep(f, 0, 21)
		{
			int nt = min(50LL, t + DV[i].first), nf = min(20LL, f + DV[i].second);
			DP2[nt][nf] += DP1[t][f];
		}
		DP1[DV[i].first][DV[i].second]++;
		//cout << "a" << endl;
	}

	int ans = 0;
	rep(t, 0, 51)rep(f, 0, 21)
	{
		if (min(t, f) >= 18)ans+=DP2[t][f];
	}

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

Measured memory_bytes: 6344
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>

int main()
{
	int h, w, m;
	std::cin >> h >> w >> m;
	std::vector<std::pair<int, int>> bomb;
	std::vector<int> by(h), bx(w);
	int x, y;
	for (int i = 0; i < m; i++) {
		std::cin >> y >> x;
		x--; y--;
		bomb.push_back({ x, y });
		bx[x]++;
	}
	
	std::list<std::pair<int, int>> bomb1(bomb.begin(), bomb.end());
	x = std::distance(bx.begin(), std::max_element(bx.begin(), bx.end()));
	bomb1.remove_if([x](const std::pair<int, int> &e) {
		return e.first == x;
	});
	for (auto [x, y] : bomb1) by[y]++;
	y = std::distance(by.begin(), std::max_element(by.begin(), by.end()));
	int max = bx[x] + by[y];
	
	bomb1.assign(bomb.begin(), bomb.end());
	bx.assign(w, 0);
	by.assign(h, 0);
	for (auto [x, y] : bomb1) by[y]++;
	y = std::distance(by.begin(), std::max_element(by.begin(), by.end()));
	bomb1.remove_if([y](const std::pair<int, int> &e) {
		return e.second == y;
	});
	for (auto [x, y] : bomb1) bx[x]++;
	x = std::distance(bx.begin(), std::max_element(bx.begin(), bx.end()));
	max = std::max(max, bx[x] + by[y]);
	
	std::cout << max << std::endl;
	
	return 0;
}


Measured memory_bytes: 16984
require "prime"

n = gets.to_i
x = 1.upto(n).map.inject(:*).prime_division

w = [[4,4,2],[4,2,4],[2,4,4],[14,4],[4,14],[24,2],[2,24],[74]]
ans = 0
w.each{|e|
  t = [*0...x.size].combination(e.size).to_a
  t.each{|y|
    if e.size.times.map{|i|x[y[i]][1] >= e[i]}.all?
      ans += 1
    end
  }
}

p ans


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

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

    int cnt = 0;
    rep(i,3)
        if(s[i] == t[i]) ++cnt;

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		// solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		// String[] strArr = str.split(" ");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		int ans = 700;
		for (int i = 0; i < 3; i++) {
			if (str.charAt(i) == 'o')
				ans += 100;
		}
		System.out.println(ans);

	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}


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

#define MOD (1000000007)

int arr[2010][2010] = {};

ll comb(ll n, ll r)
{
  if (n < 0 || r < 0)
    cout << n << "," << r << endl;
  if (arr[n][r] != 0)
    return arr[n][r];
  else if (r == 0)
  {
    arr[n][r] = 1;
    return arr[n][r];
  }
  else if (r == 1)
  {
    arr[n][r] = n;
    return arr[n][r];
  }
  else if (n <= r)
  {
    arr[n][r] = 1;
    return arr[n][r];
  }
  else
  {
    arr[n][r] = (comb(n - 1, r - 1) + comb(n - 1, r)) % MOD;
    return arr[n][r];
  }
}

int main()
{
  ll n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++)
  {
	if (n-k+1 < i)
      cout << 0 << endl;
    else
    cout << (comb(n - k + 1, i) * comb(k - 1, i - 1)) % MOD << endl;
  }
}


Measured memory_bytes: 14336
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b-1);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<string>three={
    "aa.",
    "..b",
    "..b",
  };
  vector<string>four={
    "aabd",
    "ccbd",
    "efgg",
    "efhh"
  };
  vector<string>five={
    "abbcc",
    "ad..f",
    "gd..f",
    "g.hhj",
    "kkllj"
  };
  vector<string>seven={
    ".aabbd.",
    "ee...df",
    "g.cc..f",
    "g...n.h",
    "i...n.h",
    "ij...kk",
    ".jllmm."
  };
  ll n;cin>>n;
  if(n==2){
    cout<<-1<<endl;
    return 0;
  }
  if(n==7){
    rep(i,n)cout<<seven[i]<<endl;
    return 0;
  }
  if(n==11){
    rep(i,4)cout<<four[i]<<"......."<<endl;
    rep(i,7)cout<<"...."<<seven[i]<<endl;
    return 0;
  }
  vector<string>res(n);
  rep(i,n){
    res[i]="";
    rep(j,n)res[i]+='.';
  }
  ll s=0;
  if(n==3){
    rep(i,3)cout<<three[i]<<endl;
    return 0;
  }
  if(n==6){
    rep(i,3)cout<<three[i]<<"..."<<endl;
    rep(i,3)cout<<"..."<<three[i]<<endl;
    return 0;
  }
  ll a=n%4,b=(n-n%4*5)/4;

  if(n==13){a=1;b=2;}

  rep(i,a){
    rep(j,5)rep(k,5){
      res[j+s][k+s]=five[j][k];
    }
    s+=5;
  }
  rep(i,b){
    rep(j,4)rep(k,4){
      res[j+s][k+s]=four[j][k];
    }
    s+=4;
  }
  rep(i,n)cout<<res[i]<<endl;




  return 0;

}


Measured memory_bytes: 2304
N = int(input())
T = 0
A = 0
for _ in range(N):
    t, a = map(int, input().split())
    i = max(T//t, A//a, 1)
    while T > i*t or A > i*a:
        i += 1
    T = i*t
    A = i*a
    
print(T+A)

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

using namespace std;

using i64 = int64_t;
const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

vector<int> scc(vector<vector<int>>& edges){
    int n = edges.size();
    vector<vector<int>> rev(n);
    for(int i = 0; i < n; ++i)
        for(auto& x : edges[i])
            rev[x].emplace_back(i);
    vector<i64> dfs_num(n, -1);
    vector<i64> flag(n, 0);
    int num = 0;
    function<void(int)> dfs = [&](int pos){
        flag[pos] = 1;
        for(auto& xx : edges[pos])
            if(!flag[xx])
                dfs(xx);
        dfs_num[pos] = num++;
    };
    for(int i = 0; i < n; ++i)
        if(!flag[i])
            dfs(i);
    vector<int> dfs_inv(n);
    for(int i = 0; i < n; ++i)
        dfs_inv[n - 1 - dfs_num[i]] = i;
    num = 0;
    vector<int> scc_vec(n, -1);
    function<void(int)> rdfs = [&](int pos){
        scc_vec[pos] = num;
        for(auto& t : rev[pos])
            if(scc_vec[t] == -1)
                rdfs(t);
    };
    for(int i = 0; i < n; ++i)
        if(scc_vec[dfs_inv[i]] == -1){
            rdfs(dfs_inv[i]);
            ++num;
        }
    return scc_vec;
}

signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<vector<int>> edges(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        edges[i].emplace_back((i + a[i]) % n);
    }
    auto ret = scc(edges);
    vector<int> cnt(n);
    for(auto& x : ret)
        ++cnt[x];
    int ans = 0;
    for(auto& x : cnt)
        if(x >= 2)
            ans += x;
    cout << count_if(a.begin(), a.end(), [&](auto x){return x % n == 0;}) + ans << endl;
}



Measured memory_bytes: 22640
#include<iostream>
#include<map>

using namespace std;

int main() {
	int a, b, c;
	map<int, int> m;
	cin >> a >> b >> c;
	m[a]++,m[b]++,m[c]++;
	m[5] == 2 && m[7] == 1 ? cout << "YES" << endl : cout << "NO" << endl;
}

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

using namespace std;

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <iostream>
#include <stdio.h>

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pairll;

#define sll(x) scanf("%lld",&x);
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout)

#define ff first
#define ss second

inline ll ADD(ll a, ll b, ll mod)
{
    return (a + b + mod + mod)%mod;
}

inline ll SUBS(ll a, ll b, ll mod)
{
    return (a-b+mod + mod) %mod;
}

inline ll MUL(ll a, ll b, ll mod)
{
    return (a*b + mod)%mod;
}

ll bigMod(ll base, ll power, ll mod)
{
    if(!power) return 1;
    if(!base) return 0;

    ll temp = bigMod(base, power/2, mod);

    if(power%2 == 0)
    {
        return (temp*temp)%mod;
    }
    else return (((temp*temp)%mod)*base)%mod;
}

inline ll modInverse(ll a, ll modp)
{
    return bigMod(a, modp -2, modp);
}

inline ll modInverseExtended(ll a, ll m) 
{ 
    ll m0 = m; 
    ll y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
        // q is quotient 
        ll q = a / m; 
        ll t = m; 
  
        // m is remainder now, process same as 
        // Euclid's algo 
        m = a % m, a = t; 
        t = y; 
  
        // Update y and x 
        y = x - q * y; 
        x = t; 
    } 
  
    // Make x positive 
    if (x < 0) 
       x += m0; 
  
    return x; 
} 
  
int getOdd(int n, int r)
{
    if(n == r) return 1;
    else if(n % 2 == 0 && r%2==1) return 0;
    return getOdd(n/2,r/2);
}

void autoinput()
{
    READ; 
    //WRITE;
}

int main()
{
    //autoinput();

    ll n; cin >> n;

    ll arr[n+1];
    ll arra[n+1];

    bool one = false;
    for(ll i = 0; i < n; i++)
    {
        int in;
        scanf("%1d",&in);
        arr[i] = in - 1;
        if(in == 2){
            if(!one) memset(arra, 0, sizeof arra);
            one = true;
            arra[i] = 1;
        }
        else if(!one)
        {
            arra[i] = arr[i]/2;
        }
    }

    ll cur = 0;

    for(ll i = 0; i < n; i++)
    {
        //cout << getOdd(n-1,i);
        //cout << arra[i];
        cur ^= arra[i] * getOdd(n-1,i);
    }
    if(!one) cur *= 2;
    
    cout << cur << endl;
}



Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
#define MAX_V 1000
struct edge {
    int to, cap, rev;
};
vector<edge> G[MAX_V];
vector<bool> used;
void add_edge(int from, int to, int cap) {
    // G[to].size()をrevに保持することでG[edge.to][edge.rev]で逆辺の構造体にアクセスできる
    G[from].push_back((edge){to, cap, (int)G[to].size()});
    G[to].push_back((edge){from, 0, (int)G[from].size() - 1});
}
int dfs(int v, int t, int f) {
    if(v == t) {
        return f;
    }
    used[v] = true;
    for(int i = 0; i < (int)G[v].size(); i++) {
        edge &e = G[v][i];
        if(!used[e.to] && e.cap > 0) {
            int d = dfs(e.to, t, min(f, e.cap));
            // d==0ならtにたどり着かない
            if(d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}
int max_flow(int s, int t) {
    int flow = 0;
    for(;;) {
        used.assign(MAX_V, 0);
        int f = dfs(s, t, MOD);
        if(f == 0) {
            return flow;
        }
        flow += f;
    }
}
int main() {
    int n;
    cin >> n;
    vector<vector<int>> red(n, vector<int>(2));
    for(int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        red[i][0] = a;
        red[i][1] = b;
    }
    vector<vector<int>> blue(n, vector<int>(2));
    for(int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        blue[i][0] = a;
        blue[i][1] = b;
    }
    for(int i = 0; i < n; i++) {
        add_edge(0, i + 1, 1);
    }
    for(int i = 0; i < n; i++) {
        add_edge(i + n + 1, 2 * n + 1, 1);
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            if(red[i][0] < blue[j][0] && red[i][1] < blue[j][1]) {
                add_edge(i + 1, j + n + 1, 1);
            }
        }
    }
    cout << max_flow(0, 2 * n + 1) << endl;
}


Measured memory_bytes: 3756
#include<stdio.h>

int main(void){

char str[1005];
int i,sum;
while(1){
	for(i=0;i<1005;i++)str[i]='\n';
scanf("%s",str);
if(str[0]=='0'){break;}
sum=0;
i=0;
while(1){
	if(str[i]=='\n'){break;}
	switch(str[i]){
	case '9':sum++;
	case '8':sum++;
	case '7':sum++;
	case '6':sum++;
	case '5':sum++;
	case '4':sum++;
	case '3':sum++;
	case '2':sum++;
	case '1':sum++;
	}
	i++;
}
	printf("%d\n",sum);
}

	return 0;
}

Measured memory_bytes: 536
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n,m = 1,max=0;
  cin >> n;
  for(int i = 1;i <= n;++i){
    int tmp_i = i;
    int tmpmax = 0;
    while(true){
      if(tmp_i%2 == 0){
        ++tmpmax;
        tmp_i /= 2;
      }else{
        if(tmpmax > max){
          max =tmpmax;
          m = i;
        }
        break;
      }
    }
  }
  cout << m <<endl;
  return 0;
}

Measured memory_bytes: 256
module Main where
import Debug.Trace
import Data.List
import qualified Data.Sequence as S
import qualified Data.ByteString.Char8 as B
import Data.Int
import Data.Char
import Data.Array
import Data.Maybe
import qualified Data.Map as M
import Data.Ord
import Data.Functor
import Control.Applicative
import Control.Monad

solve :: [Int] -> Int -> Int
solve l n = count where
    (count, _) = msort l n

merge :: Int-> (Int, [Int]) -> (Int, [Int]) -> (Int, [Int])
merge ln (lc, ll) (rc, rl) = iter ln (lc + rc) [] ll rl where
    iter _ c ml [] rl = (c, reverse ml ++ rl)
    iter _ c ml ll [] = (c, reverse ml ++ ll)
    iter d c ml ll@(l:ls) rl@(r:rs) 
        | l <= r   = d `seq` iter (d-1) c (l:ml) ls rl
        |otherwise = c `seq` iter d (c+d) (r:ml) ll rs
    
msort :: [Int] -> Int-> (Int, [Int])
msort l 1 = (0, l)
msort l n = merge ln (msort ll ln) (msort rl rn) where
        (ln, rn) = (div n 2, n - ln)
        (ll, rl) = splitAt ln l

readIntLn:: IO Int
readIntLn = (fst . fromJust . B.readInt) <$> B.getLine

readIntList:: IO [Int]
readIntList = map (fst . fromJust . B.readInt) . B.words <$> B.getLine

main :: IO() 
main = do
    n <- readIntLn
    l <- readIntList
    print $ solve l n



Measured memory_bytes: 46996
program main;
var 
    a,b,k : QWord;
begin
    readln(a,b,k);
    if ( a >= k ) then 
        a := a-k
    else 
        begin
            k := k-a;
            a := 0;
        if ( b > k ) then 
            b := b-k
        else 
            b := 0;     
        end;
    writeln(a,' ',b);
end.

Measured memory_bytes: 1384
#include<stdio.h>

int main(void)
{
int W,H,x,y,r,f;

scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

f=0;
if(x+r>W)f=1;
if(y+r>H)f=1;
if(r>x)f=1;
if(r>y)f=1;

if(f==0)printf("Yes\n");
else printf("No\n");

return 0;
}


Measured memory_bytes: 2112
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<vector<vector<vector<int>>>> vvvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<vector<vector<vector<ll>>>> vvvvl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;


const int MAX = 10000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  int X, Y;
  cin >> X >> Y;
  int xcount = 0;
  int ycount = 0;
  while(X > 0 && Y > 0){
    if(X >= Y){
      X -= 2;
      Y -= 1;
      xcount ++;
    }
    else{
      X -= 1;
      Y -= 2;
      ycount ++;
    }
  }
  if(X != 0 || Y != 0){
    cout << 0 <<endl;
    return 0;
  }  

    // 前処理
    COMinit();

    // 計算例
    cout << COM(xcount+ycount, xcount) << endl;
  /*
  //cout << xcount << " " << ycount <<endl;
  ll goukei = xcount + ycount;
  ll sum = 1;
  int x = min(xcount, ycount);
  for(int i = 0; i < x; i++){
    sum *= goukei - i;
    sum %=  1000000007;
  }
  for(int i = 0; i < x; i++){
    sum /= (i+1);
  }
  cout << sum <<endl;
  */
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; string s; cin>>n>>s;
	int ans=0;
	for(int i=1;i<s.size();++i){
		string s2=s.substr(i);
		vector<bool>a(26,false),b(26,false);
		for(int j=0;j<i;++j){
			a.at(s.at(j)-'a')=true;
		}
		for(int j=0;j<s2.size();++j){
			b.at(s2.at(j)-'a')=true;
		}
		int tmp=0;
		for(int j=0;j<26;++j){
			if(a.at(j)&&b.at(j))++tmp;
		}
		ans=max(ans,tmp);
	}
	cout<<ans<<"\n"s;
}


Measured memory_bytes: 256
N = input()
X = [0]*N
Y = [0]*N
for i in range(N):
  X[i],Y[i] = map(int, raw_input().split())

p = (X[0]+Y[0])%2
for i in range(1,N):
  if p!=(X[i]+Y[i])%2:
    print -1
    exit(0)

if p==0:
  print 33
  print 1,
else:
  print 32
for i in range(32)[::-1]:
  print 1<<i,
print


for i in range(N):
  if p==0:
    w = "L"
    X[i] += 1
  else:
    w = ""
  for j in range(32)[::-1]:
    if abs(X[i])>abs(Y[i]):
      if X[i]>0:
        w += "R"
        X[i] -= 1<<j
      else:
        w += "L"
        X[i] += 1<<j
    else:
      if Y[i]>0:
        w += "U"
        Y[i] -= 1<<j
      else:
        w += "D"
        Y[i] += 1<<j
  print w


Measured memory_bytes: 2808
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;

struct Shop {
    int id;
    string city;
    int price;

    bool operator<(const Shop &another) const {
        // return city < another.city;
        if (city != another.city) {
            return city < another.city;
        } else {
            return price > another.price;
        }
    };
} ;

int main() {

    int N;
    cin >> N;
    
    vector<Shop> array(N);
    for (int i = 0; i < N; ++i) {
        int id = i + 1;
        string s;
        int p;
        cin >> s >> p;
        Shop shop;
        shop.id = id;
        shop.city = s;
        shop.price = p;
        array[i] = shop;
    }

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

    for (int i = 0; i < N; ++i) {
        cout << array[i].id << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int mm(int num)
{
  if (num % 2 == 0)
    return 0;
  else
    return 1;
}

int mp(int num)
{
  if (mp > 0)
  {
    return num;
  }
  else
    return -1 * num;
}

int main()
{
  int N;
  cin >> N;
  int **input;
  int length = 0;
  input = new int *[N];
  for (int i = 0; i < N; i++)
  {
    input[i] = new int[3];
    cin >> input[i][0] >> input[i][1] >> input[i][2];
  }

  //条件
  int j = 0;
  int x = 0;
  int y = 0;
  int t = 0;
  for (; j < N; j++)
  {
    if(mp(input[j][1] - x) + mp(input[j][2] - y) > input[j][0]){
      printf("No");
      break;
    }
    else if ((input[j][0]  - t - (mp(input[j][1] - x) + mp(input[j][2] - y))) % 2 == 1)
    {
      printf("No");
      break;
    }

    t = input[j][0];
    x = input[j][1];
    y = input[j][2];


  }

  if (j == N)
  {
    printf("Yes");
  }
}

Measured memory_bytes: 4096
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();
        long sum = a + (long)Math.pow(a, 2) + (long)Math.pow(a, 3);
        System.out.println(sum);
    }

}

Measured memory_bytes: 35836
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.BitSet;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int T = sc.nextInt();
		int[] x = new int[M], y = new int[M];
		for (int i = 0; i < M; i++) {
			x[i] = sc.nextInt() - 1;
			y[i] = sc.nextInt() - 1;
		}
		if (T == 1) {
			BitSet[] set = new BitSet[N];
			for (int i = 0; i < N; i++) {
				set[i] = new BitSet(N);
				set[i].set(i);
			}
			int last = -1;
			for (int i = 0; i < M && last == -1; i++) {
				set[x[i]].or(set[y[i]]);
				set[y[i]].or(set[x[i]]);
				if (set[x[i]].cardinality() == N) {
					last = x[i];
				}
			}
			if (last == -1) {
				out.println(-1);
			} else {
				BitSet me = new BitSet();
				char[] ret = new char[M];
				me.set(last);
				for (int i = M - 1; i >= 0; i--) {
					if (me.get(x[i])) {
						ret[i] = '^';
						me.set(y[i]);
					} else {
						ret[i] = 'v';
						if (me.get(y[i])) {
							me.set(x[i]);
						}
					}
				}
				out.println(new String(ret));
			}
		}
		if (T == 2) {
			if (N == 2) {
				out.println(-1);
			} else {
				char[] ret = new char[M];
				int[] relevant = new int[M];
				int relSize = 0;
				
				for (int i = 0; i < M; i++) {
					if (y[i] < 3) {
						relevant[relSize++] = i;
					} else {
						ret[i] = '^';
					}
				}
				
				int mask = 7;
				for (int i = 0; i < relSize; i++) {
					int idx = relevant[i];
					int nextMask = 0;
					if (i + 1 < relSize) {
						nextMask = (1 << x[relevant[i+1]]) | (1 << y[relevant[i+1]]);
					}
					int upMask = mask & ~(1<<y[idx]) | (1<<x[idx]);
					if (upMask != nextMask) {
						ret[idx] = '^';
						mask = upMask;
					} else {
						ret[idx] = 'v';
						mask = mask & ~(1<<x[idx]) | (1<<y[idx]);
					}
				}
				
				out.println(new String(ret));
			}
		}
		
		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 499840
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <utility>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto&e:c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){
    rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" ");
    return os;
}

int N,W,H,S,T;
int y[500], x[500];

int solve(){
    int res = 0;
    rep(i,H-T+1)rep(j,W-S+1){
        int t=0;
        rep(k,N){
            if(i <= y[k] && y[k] < i+T && j <= x[k] && x[k] < j+S) t++;
        }
        res=max(t,res);
    }
    return res;
}

int main(){
    while(cin>>N && N){
        cin >> W >> H;
        rep(i,N) cin>>x[i]>>y[i];
        rep(i,N) x[i]--, y[i]--;
        cin >> S >> T;
        cout<<solve()<<endl;
    }
}

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

using namespace std;

typedef struct {
	int val;
	int add;
} Node;

Node seg[1 << 20];

inline void evaluate(int idx)
{
	seg[idx].val += seg[idx].add;
	if (idx < (1 << 19) - 1){
		seg[idx * 2 + 1].add += seg[idx].add;
		seg[idx * 2 + 2].add += seg[idx].add;
	}
	
	seg[idx].add = 0;
}

void update(int k)
{
	seg[k].val = min(seg[k * 2 + 1].val, seg[k * 2 + 2].val);
}

void add(int a, int b, int x, int k = 0, int l = 0, int r = 1 << 19)
{
	evaluate(k);
	if (r <= a || b <= l) return;
	
	if (a <= l && r <= b){
		seg[k].add += x;
		evaluate(k);
		return;
	}
	
	add(a, b, x, k * 2 + 1, l, (l + r) / 2);
	add(a, b, x, k * 2 + 2, (l + r) / 2, r);
	update(k);
}

int n, q;
char s[300001];

void fix(set<int> *a, set<int> *b, char before, int x)
{
    a->erase(x);
    b->insert(x);
    
    int base = before == '(' ? -1 : 1;
    s[x] = before == '(' ? ')' : '(';
    
    add(x, n, 2 * base);
    
    int l = 0, r = x;
    int p;
    
    while (l != r){
        int mid = l + r >> 1;
        p = *b->lower_bound(mid);
        add(p, n, -2 * base);
        
        if (seg[0].val + seg[0].add >= 0) r = mid;
        else l = mid + 1;
        
        add(p, n, 2 * base);
    }
    
    p = *b->lower_bound(l);
    add(p, n, -2 * base);
    b->erase(p);
    a->insert(p);
    s[p] = before;
    
    printf("%d\n", p + 1);
}

int main()
{
    scanf("%d %d", &n, &q);
    scanf("%s", s);
    
    set<int> lf, rg;
    
    for (int i = 0; s[i]; i++){
        if (s[i] == '('){
            add(i, n, 1);
            lf.insert(i);
        }
        else {
            add(i, n, -1);
            rg.insert(i);
        }
    }
    
    for (int i = 0; i < q; i++){
        int x;
        scanf("%d", &x); x--;
        
        if (s[x] == '(') fix(&lf, &rg, '(', x);
        else fix(&rg, &lf, ')', x);
    }
    
    return (0);
}

Measured memory_bytes: 22916
#include <iostream>

using namespace std;

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

    int ans = 0;
    for (int i = 0; i < N; i++){
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    
    cout << ans << endl;

    return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  
  int64_t result = K;
  
  int saishoku = N;
  if (N == 1){
    
  }
  else{
    for (int i=0; i<N-1; i++){
      result *= (K-1);
    }
  }
  
  cout << result << endl;
}

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

using namespace std;

#if 1
#define DEBUG(x) do{cerr << #x << "=" << x << endl;}while(0);
#else
#define DEBUG
#endif


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

	cout << r*r << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(i) i.begin(),i.end()
template<typename T=ll>
using v =vector<T>;
template<typename T=ll> using vv = vector<v<T>>;
template<typename T=ll,typename U=ll> using p = pair<T,U>;
const ll INF = (ll)1e9;
template<typename T> T chmin(T &a,T b){a=min(a,b);}
template<typename T> T chmax(T &a,T b){a=max(a,b);}

ll f(string s,char c){
    bool k =true;
    rep(i,s.size()) if(s[i]!=c)k=false;
    if(k) return 0;
    string t(s.size()-1,'.');
    rep(i,s.size()-1){
        if(s[i]==c||s[i+1]==c)t[i]=c;
        else t[i]=s[i];
    } 
    return f(t,c)+1;
}

int main(){
    string t;
    cin >> t;
    ll _min =INF;
    for(char c='a';c<='z';c++){
        chmin(_min,f(t,c));
    }
    cout << _min << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args){
        final Scanner sc = new Scanner(System.in);
        final int a = sc.nextInt();
        final int b = sc.nextInt();
        final int c = sc.nextInt();
        final int d = sc.nextInt();

        if(Math.abs(a-c) <= d) {
            System.out.println("Yes");
            return;
        }

        int[] xs = IntStream.of(a, b, c).sorted().toArray();
        if(Math.abs(xs[0]-xs[1])<=d && Math.abs(xs[1]-xs[2])<=d) {
            System.out.println("Yes");
            return;
        }

        System.out.println("No");
    }
}

Measured memory_bytes: 26580
/*
    Created by Tejas Chaudhari
    link:
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef double lf;
typedef bool bl;
typedef vector<ll> vl;
typedef vector<lf> vd;
typedef vector<bl> vb;
typedef string st;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

#define INF (LONG_LONG_MAX / 4)
#define SORT(x) sort(x.begin(), x.end())
#define Mod % 1000000007

void re_curse() {
    ll n;
    cin>>n;
    cout<<(1000 - (n%1000)) % 1000<<endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin>>t;
    for (int i = 1; i <= t; ++i) {
        re_curse();
    }
    return 0;
}


Measured memory_bytes: 3640
N, M = map(int, input().split())
P = {(p+1):[] for p in range(N)}
ans = []
Q  = []

for i in range(M):
    p, y = map(int,input().split())
    P[p].append({'index':i, 'prefecture':p, 'year':y, 'rank':None})

for i in range(1, N+1):
    p = sorted(P[i], key=lambda x: x['year'])
    for s, j in enumerate(p, start=1):
        j['rank'] = s
    Q += p
Q = sorted(Q, key=lambda x: x['index'])
for q in Q:
    a = str(q['prefecture'])
    a = '0'*(6-len(a)) + a
    b = str(q['rank'])
    b = '0'*(6-len(b)) + b
    print(a+b)

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

const vector<int> dx = {-1, 0, 1, 0};
const vector<int> dy = {0, 1, 0, -1};

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> grid(h);
    for (int i = 0; i < h; ++i) {
        cin >> grid[i];
    }
    int ans = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (grid[i][j] == '#') continue;
            queue<pair<int, int>> q;
            vector<vector<int>> dist(h, vector<int>(w, 1001001001));
            dist[i][j] = 0;
            q.push(make_pair(i, j));
            while (!q.empty()) {
                int x = q.front().first;
                int y = q.front().second;
                q.pop();
                for (int k = 0; k < 4; ++k) {
                    int nx = x + dx[k];
                    int ny = y + dy[k];
                    if (nx < 0 or nx >= h or ny < 0 or ny >= w) continue;
                    if (grid[nx][ny] == '#') continue;
                    if (dist[nx][ny] != 1001001001) continue;
                    dist[nx][ny] = dist[x][y] + 1;
                    q.push(make_pair(nx, ny));
                }
            }
            for (int l = 0; l < h; ++l) {
                for (int k = 0; k < w; ++k) {
                    if (dist[l][k] != 1001001001) ans = max(ans, dist[l][k]);
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
    int b = 0;
	string a;
	cin >> a;
    size_t size = a.length();
    b = size;
    if (a[b-1]=='s') {
        cout << a << "es" << endl;
    }
    else {
        cout << a << "s" << endl;
    }
    return 0;
}

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


void Main()
{
  string s; cin >> s;
  int maxcnt = 0;
  int cnt = 0;
  rep(i,3) {
    if (s[i] == 'R') cnt++;
    else cnt = 0;
    maxcnt = max(maxcnt, cnt);
  }
  cout << maxcnt << endl;
}

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


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

string s;

int main(){
  cin>>s;
  int n=s.size();
  int res=0;
  rep(i,n+1){
    if(i<n&&s[i]=='0')continue;
    int sum=0;
    rep(j,n){
      if(j<i) sum+=s[j]-'0';
      else if(j==i)sum+=s[j]-'0'-1;
      else sum+=9;
    }
    maxch(res,sum);
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<map>
#include<cmath>
#include<vector>
#include<queue>
#include<cstdio>
#include<math.h>
#include<bitset>
#include<algorithm>
#include<iomanip>
#include<list>
#include<set>
#include<utility>
using namespace std;

//repetition
//------------------------------------------

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
//#define INF (1 << 30)
#define pii pair<int, int>

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

static const int INF = 1000000010;
int d[510][510];
string s[510];
int l[110];

int main() {
  int n;
  char c;
   cin >> n;
   rep(i,n){
     cin >> c;
     if(c=='Y'){
       cout << "Four" << endl;
       return 0;
     }
   }
   cout << "Three" << endl;
   return 0;
}


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

using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
#define INF 1e9

int main(){
   
    int n; cin >> n;
    vector<int> a(n);
    map<int ,int> mp;
    rep(i,n) {
        int x; cin >> x;
        mp[x]++;
    }
    int ans = 0;
    for(auto i : mp){
        if(1&i.second){
            ans++;
        }
    }
    
    cout << ans << endl;
    
    
    
    
    
}


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

int H,W;
char grid[1000][1000];
int dp[1000][1000];

signed main() {
  cin >> H >> W;
  for(int h=0; h<H; h++) for(int w=0; w<W; w++) cin >> grid[h][w];

  dp[0][0] = 1;
  for(int h=0; h<H; h++) for(int w=0; w<W; w++) {
    if(grid[h][w]=='#') continue;
    if(h+1<H && grid[h+1][w]=='.') dp[h+1][w] = (dp[h+1][w] + dp[h][w]) % (int)(1e9+7);
    if(w+1<W && grid[h][w+1]=='.') dp[h][w+1] = (dp[h][w+1] + dp[h][w]) % (int)(1e9+7);
  }
  //for(int h=0; h<H; h++) {
  //  for(int w=0; w<W; w++) cout << dp[h][w];
  //  cout << endl;
  //}
  cout << dp[H-1][W-1] << endl;
}


Measured memory_bytes: 9088
/*
 * Author - Abhas Jain
 * Code is inside the solve function
 */
 
#include <bits/stdc++.h>
 
#define F first
#define S second
#define all(c) c.begin(), c.end()
#define endl '\n'
#define pb push_back

typedef long long ll;
typedef long double ld;

using namespace std;
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
 
const ld PI = 3.141592653589793;
const ll INF = 9223372036854775807ll;
const ll mod = 1e9 + 7;

void solve() 
{
	int k;
	cin >> k;
	unordered_set<int> have;
	int cur = 0;
	for (int i = 1; ; ++i) {
		cur = ((cur * (10 % k)) % k + 7) % k;
		if (cur == 0) {
			cout << i << endl;
			return;
		}
		if (have.find(cur) != have.end()) {
			cout << -1 << endl;
			return;
		}
		have.insert(cur);
	}
}
 
int main( )
{   
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    solve();
    return 0;
}

Measured memory_bytes: 42636
/*
 * ID: ITP1_9_D
 * Problem: transformation
 */

#include <stdio.h>
#include <string.h>

int main(void)
{
    char line[1000 + 1];
    scanf("%s", line);

    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        char command[8], rline[1000 + 1];
        int a, b;
        scanf("%s %d %d", command, &a, &b);
        if (strcmp(command, "print") == 0) {
            for (int i = a; i <= b; i++)
                printf("%c", line[i]);
            printf("\n");
        } else if (strcmp(command, "reverse") == 0) {
            char temp[1000 + 1];
            for (int i = a; i <= b; i++)
                temp[i] = line[i];
            int j = b;
            for (int i = a; i <= b; i++)
                line[i] = temp[j--];
        } else if (strcmp(command, "replace") == 0) {
            scanf("%s", rline);
            int j = 0;
            for (int i = a; i <= b; i++)
                line[i] = rline[j++];
        }
    }
    return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,x,y;
ll res=1;
int main()
{
	cin >>n>>x>>y;
	if (y-x<=2 || n<x)
	{
		cout <<n+1;
		return 0;
	}
	n-=x-1;
	res=x;
	if (n%2) n--,res++;
	res+=n/2*(y-x);
	cout <<res;
	return 0;
}

Measured memory_bytes: 256
import heapq

N, M = map(int, input().split())
P = [[] for _ in range(M)]

for _ in range(N):
    A, B = map(int, input().split())
    if A <= M:
        P[A-1].append(-B)

ans = 0
hq = []
for i in range(M):
    for d in P[i]:
        heapq.heappush(hq, d)
    if len(hq) != 0:
        ans += heapq.heappop(hq)

print(abs(ans))

Measured memory_bytes: 17732
use std::io::*;
use std::str::*;

fn read<T: FromStr>(s: &mut StdinLock) -> Option<T> {
    let s = s
        .by_ref()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let stdin = std::io::stdin();
    let n = read::<u32>(&mut stdin.lock()).unwrap();

    let mut d = [0u32; 200000];
    for i in 0..n {
        unsafe {
            let baka = d.get_unchecked_mut(i as usize);
            *baka = read::<u32>(&mut stdin.lock()).unwrap();
        }
    }

    let mut ddd = d;
    ddd.sort();
    let mx = ddd.iter().max();

    for i in 0..n {
        unsafe {
            let iine = d.get_unchecked(i as usize);
            let last = ddd.get_unchecked(199999);
            let last2 = ddd.get_unchecked(199998);
            if iine == last {
                println!("{}", last2);
            } else {
                println!("{}", last);
            }
        }
    }
}


Measured memory_bytes: 7292
#include<iostream>
int i,j;main(){std::string s[8],t;for(;i<8;)getline(std::cin,s[i++]);for(t="90\n";i-->0;t+="\n")for(j=8;j-->0;)t+=s[j][7-i];for(t+="180\n";++i<8;t+="\n")for(j=8;j-->0;)t+=s[7-i][j];for(t+="270\n";i-->0;t+="\n")for(j=0;j<8;)t+=s[j++][i];std::cout<<t;}

Measured memory_bytes: 0
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h, w, n,m,k; string s,t;
char maze[60][60];
int dis[101][101]; int graph[52][52]; bool vis[52];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    vector<ll> A(N);
    ll now=0;
    rep(i,N){
        cin>>A[i];
        now ^= A[i];
    }

    rep(i,N){
        cout<<(now^A[i])<<endl;
    }



    return 0;
    

}

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

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] a=br.readLine().split(" ");
        int n=Integer.parseInt(a[0]);
        int x=Integer.parseInt(a[1]);
        while(!(n==0&&x==0)){
            List<String> l = new ArrayList<String>(); 
            int c=0;
        	for(int i=1;i<=n;i++){
            	for(int j=1;j<=n;j++){
                	for(int k=1;k<=n;k++){
                		if(i!=j&&j!=k&&k!=i&&i+j+k==x){
                			String num=null;
                			if(i<j&&j<k){
                				num=i+" "+j+" "+k;
                			}else if(i<k&&k<j){
                				num=i+" "+k+" "+j;
                			}else if(j<i&&i<k){
                				num=j+" "+i+" "+k;
                			}else if(j<k&&k<i){
                				num=j+" "+k+" "+i;
                			}else if(k<j&&j<i){
                				num=k+" "+j+" "+i;
                			}else{
                				num=k+" "+i+" "+j;
                			}
                			if(l.indexOf(num)==-1){
                				l.add(num);
                    			c++;
                			}
                		}
                	}
            	}
        	}
        	System.out.println(c);
        	a=br.readLine().split(" ");
            n=Integer.parseInt(a[0]);
            x=Integer.parseInt(a[1]);
        }
	}
}

Measured memory_bytes: 67172
S = gets.chomp.reverse
WORDS = %w[dream dreamer erase eraser].map(&:reverse)

s = S
ok = true
while s.size > 0
  ok = WORDS.any? do |w|
    s = s.sub(w, '') if s.start_with?(w)
  end
  break unless ok
end

puts ok ? 'YES' : 'NO'


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


int main()
{
    vector <int> s(13,0);
    vector <int> h(13,0);
    vector <int> c(13,0);
    vector <int> d(13,0);


    int a,k,n,nm,sum=0;
    char g;

    cin >> n;

    for(int i=0; i<n; i++)
    {
        cin >> g >> a;

        if(g=='S')
            s[a-1]=a;
        else if(g=='H')
            h[a-1]=a;
        else if(g=='C')
            c[a-1]=a;
        else if(g=='D')
            d[a-1]=a;



    }




    for(int i=0; i<13; i++)
    {

  if(s[i]==0)
    cout << 'S' << " " << i+1 << endl;

    }

    //cout << endl;

    for(int i=0; i<13; i++)
    {
  if(h[i]==0)
    cout << 'H' << " " << i+1 << endl;
    }

    // cout << endl;

    for(int i=0; i<13; i++)
    {
  if(c[i]==0)
    cout << 'C' << " " << i+1 << endl;
    }

    // cout << endl;

    for(int i=0; i<13; i++)
    {
   if(d[i]==0)
    cout << 'D' << " " << i+1 << endl;
    }



    return 0;
}


Measured memory_bytes: 3096
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int n, c, k, a[100002], u = 0, v = 0, cnt;
int main() {
	cin >> n >> c >> k; for (int i = 0; i < n; i++)cin >> a[i];
	sort(a, a + n);
	u = a[0]; v = 0;
	for (int i = 0; i <= n; i++) {
		if (i == n || (i - v) >= c || (a[i] - u) > k) { cnt++; u = a[i]; v = i; }
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 764
#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];
  }

  sort(a,a+N,greater<int>());

  int A,B;
  A=0;
  B=0;
  for(int i=0; i<N; i++){
    (i%2==0)? A+=a[i] : B+=a[i];
  }

  cout << A-B << endl;

}

Measured memory_bytes: 256