akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

#define N_MAX 500001

struct node{
    int key;
    struct node *right;
    struct node *left;
    struct node *parent;
};

typedef struct node *Node;
Node root = NULL;

void insert(int k){
    Node y = NULL;
    Node x = root;
    Node z;
    
    z = malloc(sizeof(struct node));
    z->key = k;
    z->right = NULL;
    z->left = NULL;
    while(x != NULL){
        y = x;
        if(z->key < x->key){
            x = x->left;
        }else{
            x = x->right;
        }
    }
    z->parent = y;

    if(y == NULL){
        root = z;
    }else if(z->key < y->key){
        y->left = z;
    }else{
        y->right = z;
    }
}

/* 中間順アルゴリズム */
#if 0
void inorder(Node u){
    
    if(u->left != NULL){
        inorder(u->left);
    }
    printf(" %d",u->key);

    if(u->right != NULL){
        inorder(u->right);
    }
}
#endif

void inorder(Node u){
    
    if(u == NULL){
        return;
    }
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}

void preorder(Node u){
 
  printf(" %d",u->key);
   
  if(u->left != NULL){
    preorder(u->left);
  }
   
  if(u->right != NULL){
    preorder(u->right);
  }
   
}

int main(){
    int n, i, x;
    char com[20];
    scanf("%d", &n);
    
    
    for ( i = 0; i < n; i++ ){
        scanf("%s", com);
        if ( com[0] == 'i' ){
            scanf("%d", &x);
            insert(x);
        } else if ( com[0] == 'p' ){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        } 
    }
    return 0;
}






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

int main(){
	ios::sync_with_stdio(0);	cin.tie(0);		cout.tie(0);
	int n,k;
	cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; ++i) cin >> a[i];
	//dp[i] = first player win if there are i stones remaining
	vector<bool> dp(k+1);
	//for each state, the previous state is optimal
	for (int i = 0; i <= k; ++i){
		for (int j = 0; j < n; ++j){
			//if possible to reach this state by taking j stones
			//the previous state is done by opponent (it is now 1st player's turn)
			if (i >= a[j] && !dp[i-a[j]]) dp[i] = 1;
		}
	}
	cout << (dp[k] ? "First\n" : "Second\n");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{

  int x[2];


  scanf("%d", &x[0]);
  scanf("%d", &x[1]);

  int sum = 0;
  int i = 0;
  int flag = 0;

  for(i =0;i<=x[0]; i++ ){
    sum = (x[0]-i)*2 + i*4;

    if(sum==x[1]){
      flag = 1;
      break;
    }

  }

  if(flag){
    printf("Yes");
  }
  else{
    printf("No");
  }

  return 0;
}


Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
int k,i= -1;
vector<long long> vec = {};
void dfs(long long x,int a){
    vec.push_back(x);
    if(x > 1000000000) return;
    if(x == 0){
        for (int j = 1; j < 10; j++)
        {
            dfs(j,j);
        }
    }
    else{
        if(a != 0 && a!= 9){
            dfs(10*x + a-1,a-1);
            dfs(10*x + a,a);
            dfs(10*x + a+1,a+1);
        }
        if(a == 0) {
            dfs(10*x + 0,0);
            dfs(10*x + 1,1);
        }
        if(a == 9) {
            dfs(10*x + 8,8);
            dfs(10*x + 9,9);
        }
    }
}

int main(){
    cin >> k;
    dfs(0,0);
    sort(vec.begin(),vec.end());
    cout << vec[k] << endl;
}


Measured memory_bytes: 5312
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

N, x = ln()
X = ln()

A = X[:]
result = 0
for i in xrange(1, N):
    if A[i] + A[i - 1] > x:
        diff = A[i] + A[i - 1] - x
        
        A[i] -= diff
        A[i] = max(A[i], 0)
        result += diff

print result


Measured memory_bytes: 12776
#include <bits/stdc++.h>
using namespace std;
bool good(int n, vector<int> a){
	int tmp = n;
	while(tmp){
		if(a[tmp % 10] != 0){
			return false;
		}
		tmp /= 10;
	}
	return true;
}
int main() {
	int n,k; cin>>n>>k;
	vector<int> hate(10, 0);
	for(int i =0; i<k; i++){
		int x; cin>>x;
		hate[x] = 1;
	}
	while(good(n, hate) != true){
		n++;
	}
	cout<<n;
	return 0;
}

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

namespace ConsoleApplication15
{
    class Program
    {
        static void Main()
        {
            string a = Console.ReadLine();
            string b = Console.ReadLine();
            for(int c = 0; c < a.Length; c++)
            {
                for(int d = 0; d < b.Length; d++)
                {
                    if(c+d<a.Length){ if (a[c + d] != b[d]) break;
                        else if (b.Length - 1 == d) { Console.WriteLine("Yes"); goto y; } }
                    else
                    {
                        if (a[c + d-a.Length] != b[d]) break;
                        else if (b.Length - 1 == d) { Console.WriteLine("Yes"); goto y; }
                    }
                }
            }
            Console.WriteLine("No");    y:;
        }
    }
}

Measured memory_bytes: 8952
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <map>
using namespace std;
typedef long long LL;
const int MAXN = 1e5+5;
const double PI = acos(-1);
const double eps = 1e-8;
const LL MOD = 1e9+7;
int cnt[MAXN];
LL Pow(LL a, LL b){
    LL ans = 1;
    while(b){
        if(b & 1) ans = ans*a%MOD;
        b>>=1;
        a = a*a%MOD;
    }
    return ans;
}
int main(){
    //freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    int n;
    while(cin>>n){
        memset(cnt, 0, sizeof cnt);
        int ok = 0;
        for(int i=0; i<n; i++){
            int x; cin>>x;
            cnt[x]++;
        }
        if(n & 1){
            if(cnt[0] != 1) ok = 1;
            for(int i=2; i<n; i+=2){
                if(cnt[i] != 2){
                    ok = 1;
                    break;
                }
            }
        }
        else{
            for(int i=1; i<n; i+=2){
                if(cnt[i] != 2){
                    ok = 1;
                    break;
                }
            }
        }
        if(ok) puts("0");
        else{
            LL ans = Pow(2, n/2);
            printf("%lld\n", ans);
        }
    }
    return 0;
}


Measured memory_bytes: 640
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MAX 300005
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF = 1e18;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
umap<ll,ll> dp;
ll fun(ll n)
{
	if(n<=1)
		return n;
	if(dp[n])
		return dp[n];
	dp[n]=1+fun(n/2)+fun(n/2);
	return dp[n];
}
void solve()
{
	ll n;
	cin>>n;
	cout<<fun(n);
}
int main()
{
	fast();
	ll t;
	t=1;
	while(t--)
		solve();
}

Measured memory_bytes: 384
n=int(input())
count=0
b=n
while b:
    b//=10
    if b:
        count+=1
if count==0:
    print(n)
elif count==1:
    print(9)
elif count==2:
    print(n-100+1+9)
elif count==3:
    print(900+9)
elif count==4:
    print(n-10000+1+909)
elif count==5:
    print(90909)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
typedef long long ll;
ll mod=1000000007;
string s;
ll expression(State &begin);			//term or expr >> term
ll term(State &begin);					//num or S<expr>
ll number(State &begin);				//
string as(State &begin){
	string hoge;
	for(State st=s.begin();st!=s.end();st++){
		if(st==begin) hoge=hoge+" "+(*st)+" "; 
		else hoge+=(*st);
	}
	return hoge;
}
ll expression(State &begin){
//	cout << "expr  " << as(begin) << endl;
	ll ret=term(begin);
	if(*begin == '>'){
		begin--;	//>
//		if(*begin!='>') cout << "> " << as(begin) << endl;
		begin--;
		if(ret>40) ret=0*expression(begin);
		else ret=expression(begin) >> ret;
	}
	return ret;
}
ll term(State &begin){
//	cout << "term  " << as(begin) << endl;
	if(*begin == '>'){
		begin--;
		ll ret=expression(begin);
		ret*=ret;
		ret%=mod;
//		if(*begin!='<') cout << "< " << as(begin) << endl;
		begin--;	//S
//		if(*begin!='S') cout << "S " << as(begin) << endl;
//		cout << "t erm " << as(begin) << endl;
		begin--;
		return ret;
	}else{
		return number(begin);
	}
}
ll number(State &begin){
//	cout << "num   " << as(begin) << endl;
	ll ret=0,dig=1;
	while(isdigit(*begin)){
		ret+=dig*(*begin-'0');
		begin--;
		dig*=10;
	}
//	cout << "n um  " << as(begin) << endl;
	return ret;
}
int main(){
	for(;;){
		getline(cin,s);
		if(s[0]=='#') break;
		s="?"+s;
		string::iterator it;
		for(it=s.begin();it!=s.end();it++){
			if((*it)==' '){
				s.erase(it);
				it--;
			}
		}
		State begin=s.end();
		begin--;
		ll ans=expression(begin);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2976
package main
 
import (
	"fmt"
)
 
func main() {
  var x int
  
  fmt.Scanf("%d", &x)
  
  ans := 8
  if 600 <= x && x < 800{
    ans = 7
  }
  if 800 <= x && x < 1000{
    ans = 6
  }
  if 1000 <= x && x < 1200{
    ans = 5
  }
  if 1200 <= x && x < 1400{
    ans = 4
  }
  if 1400 <= x && x < 1600{
    ans = 3
  }
  if 1600 <= x && x < 1800{
    ans = 2
  }
  if 1800 <= x && x < 2000{
    ans = 1
  }
  
  fmt.Printf("%d", ans)
}

Measured memory_bytes: 1832
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    int n;cin >> n;
    string s;cin >> s;
    ll r=0,g=0,b=0;
    rep(i,n){
        if(s[i]=='R') ++r;
        else if(s[i]=='G') ++g;
        else ++b;
    }

    ll less = 0;
    for(int left=0;left<n;++left){
        for(int right=left+2;right<n;right += 2){
            int mid = (left + right) / 2;
            if(s[right]!=s[mid] && s[mid]!=s[left] && s[right]!=s[left]){
                ++less;
            }
        }
    }
    cout << r*g*b - less << endl;
}

Measured memory_bytes: 3628
let () =
  Scanf.scanf "%d\n" @@ fun n ->
  let arr = Array.init n @@ fun _ -> Scanf.scanf "%f " @@ fun f -> f in
  let deno = Array.fold_left (fun ans x -> ans +. (1. /. x)) 0. arr in
  Printf.printf "%.5f\n" (1. /. deno)

Measured memory_bytes: 3912
#include<stdio.h>
int main(void){
  int n,i,j,all=0;
  int d[100];
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&d[i]);
  }
  
  for(i=0;i<n;i++){
    for(j=1+i;j<n;j++){
      all+=d[i]*d[j];
    }
  }
  
  printf("%d",all);
  
  return 0;
}
      

Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
int check=0,N,A[200],count=0;
scanf("%d",&N);
for(int i=0;i<N;i++) 
    scanf("%d", &A[i]); //スペースを自動的に区切りとして認識する
for(int i=0;;i++)
{
    for(int j=0;j<N;j++)
    {
        if(A[j]%2==1)
        {
            check = 1; 
            break;    
        }
        else
        {
            A[j]=A[j]/2;
        }
    }
    if(check==1)
        break;
    else
    {
        count=count+1;
    }
}
printf("%d",count);
}



Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

const int N = 3010, P = 1000000007;

int a[N];
int p[N][N][2];

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; ++i)
    cin >> a[i];
  for (int i = 1; i < n; ++i)
    for (int j = i + 1; j <= n; ++j)
      if (a[i] > a[j])
        p[i][j][1] = 1;
      else if (a[i] < a[j])
        p[i][j][0] = 1;
  int pr = (P + 1) >> 1;
  int rep = q;
  while (rep--) {
    int x, y;
    cin >> x >> y;
    if (x > y) swap(x, y);
    for (int i = 1; i <= n; ++i)
      if (i < x) {
        for (int j = 0; j < 2; ++j) {
          int a = (p[i][x][j] + p[i][y][j]) * (ll)pr % P;
          p[i][x][j] = p[i][y][j] = a;
        }
      } else if (x < i && i < y) {
        for (int j = 0; j < 2; ++j) {
          int a = (p[x][i][j] + p[i][y][!j]) * (ll)pr % P;
          p[x][i][j] = p[i][y][!j] = a;
        }
      } else if (y < i) {
        for (int j = 0; j < 2; ++j) {
          int a = (p[x][i][j] + p[y][i][j]) * (ll)pr % P;
          p[x][i][j] = p[y][i][j] = a;
        }
      }
    int a = (p[x][y][0] + p[x][y][1]) * (ll)pr % P;
    p[x][y][0] = p[x][y][1] = a;
  }
  int ans = 0;
  for (int i = 1; i < n; ++i)
    for (int j = i + 1; j <= n; ++j)
      ans = (ans + p[i][j][1]) % P;
  while (q--)
    ans = ans * 2 % P;
  cout << ans << '\n';

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 70144
#include<bits/stdc++.h>
using namespace std;
int n,nw,ans,a[100005];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(i>1 && a[i]>a[i-1]){
			ans=max(ans,nw);
			nw=0;
		}
		nw++;
	}
	ans=max(ans,nw);
	cout<<ans-1;
	return 0;
}

Measured memory_bytes: 640
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define rev reverse
#define all(x) x.begin(), x.end()
#define ub upper_bound
#define lb lower_bound
#define ll long long
#define endl '\n'
#define ull unsigned long long
#define sz(x) (int)x.size()

template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const ll inf = 1e9+7;
const ll N = 1e5+1;
const ll mod = 1e9+7;
const ll P = 31;

int main() {
//    freopen("floor4.in", "r", stdin);
//    freopen("floor4.out", "w", stdout);
    IOS
    ll x;
    cin >> x;
    ll ans = 0;
    ans += ((x/500)*1000);
    ans += (((x%500)/5)*5);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def dfs(seq):
    ans = 0
    if len(seq) == n:
        kou = 0
        for u in data:
            if seq[u[1]-1] - seq[u[0]-1] == u[2]:
                kou+=u[3]
        return kou
    else:#len(seq)==N-1からの遷都を考えると良い
        for i in range(seq[-1], m+1):
            seq_next=seq+[i]
            ans = max(ans, dfs(seq_next))
        return ans

n, m, q = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(q)]

score = dfs([1])
print(score)


Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#define mx 100005
#define ll long long
#define mod 1000000007

int ar[mx];
char ch[mx];

int n,m;

void solve()
{
    ll d, a,b;
    cin>>d>>a>>b;
    ll res=b/d;
    ll res1=(a-1)/d;
    if(res-res1>0)printf("OK\n");
    else printf("NG\n");
}

int main()
{
    int t=1;
    //scanf("%d",&t);
    while(t--)solve();
    return 0;
}



Measured memory_bytes: 3640
from bisect import bisect_left
from bisect import bisect_right

N = int(input())

A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
num_a = 0
num_c = 0
res = 0
pre_b = -1


for b in B:
    if b == pre_b:
        res += num_a * num_c
        continue
    num_a = bisect_left(A, b) # a < b となるAの要素数
    pre_num_c = bisect_right(C, b)
    num_c = N - pre_num_c # c > b となるAの要素数
    res += num_a * num_c
    pre_b = b
print(res)



Measured memory_bytes: 106980
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;

#define MAX_N 100000

int N;
int a[(int)1e5];

int main() {
    cin >> N;
    rep(i, N) {
        cin >> a[i];
    }

    map<int, int> mp;
    rep(i, N) {
        mp[a[i]]++;
        mp[a[i] + 1]++;
        mp[a[i] - 1]++;
    }

    // 最大値 を求める
    long long ans = 0;
    for (auto iter = mp.begin(); iter != mp.end(); iter++) {
        if (ans < iter->second) {
            ans = iter->second;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 5120
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if ("A".equals(s)) {
			System.out.println("T");
		} else if ("T".equals(s)) {
			System.out.println("A");
		}  else if ("C".equals(s)) {
			System.out.println("G");
		}  else if ("G".equals(s)) {
			System.out.println("C");
		}
	}
}

Measured memory_bytes: 21588
from collections import Counter
N,K=map(int,input().split())
a=list(map(int,input().split()))

cnt_sum=0

counter = Counter(a).most_common()

for i in range(K):
  try:
    cnt_sum+=counter[i][1]
  except:
    break
answer=N-cnt_sum

print(answer)


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll ans = 1;
    map<ll, ll> cnt;
    rep(i, N) {
        cnt[A[i]]++;
    }
    ll next = 2;
    if (N % 2) {
        if (cnt.count(0) > 1 || cnt.count(0) == 0) {
            cout << 0 << '\n';
            return;
        }
        cnt.erase(0);
    } else {
        next = 1;
    }

    for (P p : cnt) {
        if (p.first == next && p.second == 2) {
            ans *= 2;
        } else {
            ans *= 0;
        }
        ans %= MOD;
        next = next + 2;
    }
    cout << ans << '\n';
}

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


Measured memory_bytes: 4992
#include<iostream>
using namespace std;
int main() {
  int k,s,cnt=0;
  cin >> k >> s;
  for (int a = 0; a <= k; a++){
    for(int b = 0; b <= k; b++){
      int c = s - a - b;
      if(k >= c && c >= 0){
	  cnt++;
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.LinkedHashMap;

class Main {
  public static final int WHITE = 0;
  public static final int GRAY  = 1;
  public static final int BLACK = 2;
  public static int SIZE;
  public static int TIME;

  public static void main(String... args) {
    Scanner sc = new Scanner(System.in);
    SIZE = sc.nextInt();
    Map<Node, List<Integer>> graph = new LinkedHashMap<>(SIZE);

    Node node;
    int size;
    for (int i = 0; i < SIZE; i++) {
      node = new Node(sc.nextInt());
      size = sc.nextInt();
      List<Integer> elements = new ArrayList<>(size);
      for (int j = 0; j < size; j++) {
        elements.add(sc.nextInt());
      }
      graph.put(node, elements);
    }
    dfs(graph);
    print(graph);
  }

  public static void dfs(Map<Node, List<Integer>> graph) {
    for (Map.Entry<Node, List<Integer>> entry : graph.entrySet()) {
      if (entry.getKey().color == WHITE) {
        visit(entry.getKey(), graph);;
      }
    }
  }

  public static void visit(Node node, Map<Node, List<Integer>> graph) {
    node.color = GRAY;
    node.first = ++TIME;
    for (int addr : graph.get(node)) {
      Node connect = getNode(addr, graph);
      if (connect.color == WHITE) {
        visit(connect, graph);
      }
    }
    node.color = BLACK;
    node.second = ++TIME;
  }

  public static Node getNode(int value, Map<Node, List<Integer>> graph) {
    for (Map.Entry<Node, List<Integer>> entry : graph.entrySet()) {
      if (entry.getKey().value == value) {
        return entry.getKey();
      }
    }
    return null;
  }

  public static void print(Map<Node, List<Integer>> graph) {
    StringBuilder sb = new StringBuilder();
    for (Map.Entry<Node, List<Integer>> entry : graph.entrySet()) {
      Node node = entry.getKey();
      sb.append(node.value).append(' ');
      sb.append(node.first).append(' ');
      sb.append(node.second).append(' ');
      System.out.println(sb.deleteCharAt(sb.length() - 1));
      sb.setLength(0);
    }
  }
}

class Node {
  public int value;
  public int color;
  public int first;
  public int second;

  public Node() {
    this(0);
  }

  public Node(int value) {
    this.value = value;
  }
}



Measured memory_bytes: 28748
#include <bits/stdc++.h>
using namespace std;
int cnt[1000000];
int main()
{int n,q,a=0,b=0;
cin>>n>>q;
int sum=0;
vector<pair<int,string>>v;
for(int i=0;i<q;i++)
{
    int j;
    string f;
    cin>>j>>f;
    
    if(f=="WA" && cnt[j]>=0)
    {
        cnt[j]++;
        v.push_back(make_pair(j,f));
    }
    else if(f=="AC" && cnt[j]>=0)
    {sum+=cnt[j];
    
        cnt[j]=-1;
        v.push_back(make_pair(j,f));
    }
}
for(int i=1;i<=n;i++)
{
    if(cnt[i]==-1)
    b++;
    
}
cout<<b<<" "<<sum<<endl;
}

Measured memory_bytes: 6896
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll a = in(), b = in(), c = in(), d = in();
	if (a <= c && d <= b) {
		cout << d - c << endl;
	} else if (c <= a && b <= d) {
		cout << b - a << endl;
	} else if (b <= c || d <= a) {
		cout << 0 << endl;
	} else {
		cout << min(d - a, b - c) << endl;
	}
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

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

template <class T> inline T chmax(T &a, T &b) {a = max(a, b);}
template <class T> inline T chmin(T &a, T &b) {a = min(a, b);}

constexpr int MOD = 1e9 + 7;
constexpr ll INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    ll n; cin>>n;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin>>a[i];

    ll ok = 0, ng = 1e10;
    ll mid;
    while(ng - ok > 1){ // [ok, ng)
        mid = (ok + ng) / 2;

        ll rain = mid * 2;
        for(int i=0; i<n; i++){
            ll rest = a[i] - rain / 2;
            rain = rest * 2;
        }

        if(mid * 2 <= rain){
            ok = mid;
        }   
        else{
            ng = mid;
        }
    }

    vector<ll> ans(n);
    ll rain = (ok + ng) / 2;
    rain *= 2;
    for(int i=0; i<n; i++){
        ans[i] = rain;
        ll rest = a[i] - rain / 2;
        rain = rest * 2;
    }

    for(int i=0; i<n; i++){
        cout << ans[i] << " \n"[i == n-1];
    }
}

Measured memory_bytes: 2944
#include <stdio.h>
 
int main(void) {
 
  int a, b, c, count = 0, i;
 
  scanf("%d %d %d", &a, &b, &c);
 
  for(i = a; i <= b; i++) {
     
    if(c % i == 0) {
    count = count + 1;
    }
  
 }
  
  printf("%d\n", count);
 
  return 0;
  
}

Measured memory_bytes: 596
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			String ans = stdIn.next();
			String inquire = stdIn.next();
			if(ans.equals("0") && inquire.equals("0"))
			{
				break;
			}
			int hit = 0, blow = 0;
			for(int i = 0; i < ans.length(); ++i)
			{
				if(ans.charAt(i) == inquire.charAt(i))
				{
					++hit;
				}
			}
			for(int i = 0; i < ans.length(); ++i)
			{
				for(int j = 0; j < inquire.length(); ++j)
				{
					if(ans.charAt(i) == inquire.charAt(j))
					{
						++blow;
					}
				}
			}
			System.out.println(hit + " " + (blow - hit));
		}
	}
}

Measured memory_bytes: 12000
#pragma gcc optimize("Ofast")
#include<iostream>
using namespace std;
const int N = 2000;
int ips[2][N+1]={}, dp[N+1]={}, a[2*N], v[2][N]; // ips[k][i][j] = |{x|v[k][x<=i]<v[!k][j]}|
signed main(){
    int n; char c;
    cin >> n;
    for(int i = 0; i < 2*n; v[c=='B'][a[i++]-1] = i)
        cin >> c >> a[i];
    for(int s = 0; s < 2*n; s++){
        for(int j = min(n-1,s); j >= max(0,s-n+1); j--)
            ips[1][j+1] = ips[1][j] + (v[1][s-j] < v[0][j]),
            ips[0][j+1] = ips[0][j] + (v[0][s-j] < v[1][j]);
        for(int j = min(n-1,s); j >= max(0,s-n+1); j--)
            dp[j+1] = min(dp[j+1]+ips[1][j+1], dp[j]+ips[0][s-j+1]);
    }
    for(int i = 0; i < n; i++)
        for(int j = 0; j < i; j++)
            (dp[n]+=(v[0][j] > v[0][i]))+=(v[1][j] > v[1][i]);
    cout << dp[n] << endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<time.h>
#include<iostream>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
#include<ext/rope>
#define ll long long
#define oo 0x7fffffff
using namespace std;
using namespace __gnu_cxx;
inline int read()
{
	int out=0,fh=1;
	char cc=getchar();
	while ((cc>'9'||cc<'0')&&cc!='-')
		cc=getchar();
	if (cc=='-')
		{
			fh=-1;
			cc=getchar();
		}
	while (cc>='0'&&cc<='9')
		{
			out=out*10+cc-'0';
			cc=getchar();
		}
	return out*fh;
}
int h,w;
int avr[101],avc[101];
char mm[101][101];
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	h=read(),w=read();
	int lastrow;
	for(int i=1;i<=h;++i)
		scanf("%s",mm[i]+1);
	for(int i=1;i<=h;++i)
		for(int j=1;j<=w;++j)
			{
				char buf;
				buf=mm[i][j];
				if(buf=='#')
					avr[i]=avc[j]=1;
			}
	for(int i=h;i>=1;--i)
		if(avr[i])
			{
				lastrow=i;
				break;
			}
	for(int i=1;i<=h;++i)
		{
			if(!avr[i])
				continue;
			for(int j=1;j<=w;++j)
				{
					if(!avc[j])
						continue;
					printf("%c",mm[i][j]);
				}
			if(i!=lastrow)
				printf("\n");
		}
	//fclose(stdin);
	//fclose(stdout);
	return 0;
}


Measured memory_bytes: 256
n = gets.to_i
t,a = gets.chomp.split.map(&:to_i)
h = gets.chomp.split.map(&:to_i)
digr = 999
ans = 1000


for i in 0..h.size-1
    tmp = (t - h[i] * 0.006 - a).abs
    if digr > tmp
        digr = tmp
        ans = i+1
    end
end

p ans

Measured memory_bytes: 1788
#include "bits//stdc++.h"
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int S;
	cin >> S;
	int X = S / 100;
	int Y = S % 100;
	int cnt = 0;
	if (1 <= X && X <= 12) cnt++;
	if (1 <= Y && Y <= 12) cnt++;
	if (cnt == 2) {
		cout << "AMBIGUOUS" << endl;
		return 0;
	}
	else if (cnt == 0) {
		cout << "NA" << endl;
		return 0;
	}
	if (1 <= X && X <= 12) {
		cout << "MMYY" << endl;
	}
	else {
		cout << "YYMM" << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX = 20;
vector<ll> seq_a(MAX);
typedef pair<double,double> Point;

void solve(ll target, Point p1, Point p2)
{
    if( target == 0 ) return;
    Point s, t, u;
    double th = M_PI * 60.0 / 180.0; // ラジアンを使うのは常識

    s = make_pair( ( 2.0 * p1.first + 1.0 * p2.first ) / 3.0,
                  ( 2.0 * p1.second + 1.0 * p2.second ) / 3.0 );
    t = make_pair( ( 1.0 * p1.first + 2.0 * p2.first ) / 3.0,
                  ( 1.0 * p1.second + 2.0 * p2.second ) / 3.0 );
    u = make_pair( (t.first - s.first) * cos(th) - (t.second - s.second) * sin(th) + s.first,
                   (t.first - s.first) * sin(th) + (t.second - s.second) * cos(th) + s.second );
    
    solve( target - 1, p1, s );
    printf("%.8f %.8f\n", s.first, s.second);
    solve( target - 1, s, u );
    printf("%.8f %.8f\n", u.first, u.second);
    solve( target - 1, u, t );
    printf("%.8f %.8f\n", t.first, t.second);
    solve( target - 1, t, p2) ;
}

signed main() {
    ll n; cin >> n; 
    Point p1, p2;
    p1 = make_pair(0.0,0.0);
    p2 = make_pair(100.0,0.0);
    printf("%.8f %.8f\n", p1.first, p1.second);
    solve(n, p1, p2);
    printf("%.8f %.8f\n", p2.first, p2.second);
    return 0;
}



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

#define ll int
#define nl endl
#define pi 3.14159265358979323846
#define ff first 
#define ss second
#define pb push_back
#define watch(xxx) cerr<<(#xxx)<<" is "<<xxx<<nl;

const int N=200100;

vector<int> v;
//~ int m[1000006+100];

int main(){

ll t=1; 
//~ scanf("%d",&t);

while(t--){
	ll x,y;
scanf("%d%d",&x,&y);
//~ ll f=0;

for(int i=0;i<300;i++){
	
	for(int j=0;j<300;j++) {
		if(( i+j==x )&& (2*i+4*j==y )) { cout<<"Yes"; return 0;}
	}
}
	 cout<<"No";
}
	return 0;
}


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

int main()
{
    int a;
    int b;
    
    cin >> a >> b;
    
    int d = a / b;
    
    int r = a % b;
    
    double f = (1.0 * a) / b;
    
    printf("%d %d %.8lf\n", d, r, f);
    
    return 0;
}


Measured memory_bytes: 3232
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
q = int(input())
bc = [list(map(int, input().split())) for _ in range(q)]

cnt = [0 for i in range(0, 10**5 + 1)]
for i in a:
    cnt[i] += 1

total = sum(a)

for j in range(q):
    b = bc[j][0]
    c = bc[j][1]
    cnt[c] += cnt[b]
    total += (c-b)*cnt[b]
    cnt[b] = 0
    print(total)

Measured memory_bytes: 32516
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
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;
}

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

    int N, A, D;
    cin >> N >> A >> D;
    int ans = min(A * N, D);
    std::cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
typedef struct{
    int shop_number;
    char city_name[11];
    int point;
} _info_shop;
_info_shop shop[100];
int comp_city_name(char city_name1[11], char city_name2[11]){
    
    int length1 = strlen(city_name1);
    int length2 = strlen(city_name2);
    int comp_length;
    int longer;
    if(strcmp(city_name1, city_name2) == 0){
        return -1;
    }
    if (length1 < length2){
        comp_length = length1;
        longer = 1;
    }else{
        comp_length = length2;
        longer = 0;
    }
    if(strncmp(city_name1, city_name2, comp_length) == 0){
        return longer;
    }else if(strncmp(city_name1, city_name2, comp_length) < 0){
        return 1;
    }else{
        return 0;
    }
}
int comp_point(int point1, int point2){
    if(point1 < point2){
        return 0;
    }
    return 1;
}
void exchange(int judge, int j){
    _info_shop temp;
    if (judge == 1){
        temp = shop[j];
        shop[j] = shop[j-1];
        shop[j-1] = temp;
    }
}
int main() {
    int info_num;
    int comp_name_result;
	scanf("%d",&info_num);
    for(int i = 0; i < info_num ; i++){
        shop[i].shop_number = i + 1;
        scanf("%s %d", shop[i].city_name, &shop[i].point);
    }
    for(int i = 0; i < info_num; i++){
        for(int j = info_num - 1; j > i; j--){
            if((comp_name_result = comp_city_name(shop[j].city_name, shop[j - 1].city_name)) == -1){
                exchange(comp_point(shop[j].point, shop[j-1].point), j);
            }else{
                exchange(comp_name_result, j);
            }
        }
    }
    for(int i = 0; i < info_num ; i++){
        printf("%d\n", shop[i].shop_number);
    }
}

Measured memory_bytes: 128
#include <iostream>


using namespace std;


typedef struct
{
  char a[102];
} Mat;


int main()
{
  int h, w;
  cin >> h >> w;
  Mat *mat = new Mat[h+2];

  for (int i=0; i<h+2; i++){
    for (int j=0; j<w+2; j++){
      mat[i].a[j] = '#';
    }
  }

  for (int i=1; i<h+1; i++){
    char str[w];
    cin >> str;
    for (int j=1; j<w+1; j++){
      mat[i].a[j] = str[j-1];
    }
  }

  for (int i=0; i<h+2; i++){
    for (int j=0; j<w+2; j++){
      cout << mat[i].a[j];
    }
    cout << endl;
  }

  delete mat;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
	int n,q;
	cin>>n;
	map<ll,ll> m;
	
	long long int sum=0;
	vector<int>a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];//previous sum
		m[a[i]]++;
		
	}
	sort(a.begin(),a.end());
	cin>>q;
	while(q--){
		int bef,aft;
		cin>>bef;
		cin>>aft;
		
		
		if(m.count(bef)==0){
			cout<<sum<<"\n";
		}
		else
		{
			ll rep=m[bef];
			sum+=(aft-bef)*rep;
			m.erase(bef);
			m[aft]+=rep;
			cout<<sum<<"\n";
		}
		
		
		
		
	}
	
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 7528
#include<stdio.h>
int main(void){
  int p,q,r,ans=0;
  scanf("%d%d%d",&p,&q,&r);
  ans=p+q>r+q?r+q:p+q;
  ans=ans>p+r?p+r:ans;
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 128
//To debug :  g++ -g file.cpp -o code
//to flush output : fflush(stdout) or cout.flush()
//cout<<setprecision(p)<<fixed<<var
//use 1LL<<i to for 64 bit shifting , (ll)2 because by default 2 is ll
 
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 ll_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 ll_MIN
#define sma3 -1000000000
#define mp make_pair
#define dub double
#define ivec vector<ll>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define mt make_tuple
#define MOD 998244353
#define pi acos(-1.0)
/*
#define ss second.second
#define ff first.first
#define f first
#define s second
#define sf second.first
#define fs first.second*/
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)


const int N = 1e6+1;

int c[N],ans[N];
int a[(int)2e5+3];
vector<int> v[(int)2e5+3];

int main()
{

    IOS;

    int i,x,n,v,ans=0,val,num,j;

    
    cin>>n;

    rep(i,1,n+1)
    {
        cin>>a[i];
        ++c[a[i]];
    }

    rep(i,1,n+1)
    {


        if((c[1] && a[i]!=1) || (c[a[i]]>1))
            continue;

        for(j=2;j<=(int)sqrt(a[i]);++j)
        {
            if((!(a[i]%j)))
            {
                if(c[j] || c[a[i]/j])
                    break;
            }
        }

        if(j==((int)sqrt(a[i])+1))
            ++ans;
    }

    cout<<ans<<"\n";



    return 0;
}

Measured memory_bytes: 12912
#include <iostream>
#include <vector>
#include <array>
#include <queue>

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

using namespace std;

int main()
{
    vector<int> next_list[202020];
    int N, M;
    cin >> N >> M;

    int i;
    FOR(i, M)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;

        next_list[a].push_back(b);
        next_list[b].push_back(a);
    }

    queue<int> check_rooms;
    array<int, 202020> mark;
    mark.fill(-1);

    check_rooms.push(0);
    mark[0] = 0;
    while (check_rooms.size() > 0)
    {
        int cur_room = check_rooms.front();
        check_rooms.pop();

        for (auto &next_room : next_list[cur_room])
        {
            // 決定済みの部屋はスキップ
            if (mark[next_room] != -1)
            {
                continue;
            }
            mark[next_room] = cur_room + 1;
            check_rooms.push(next_room);
        }
    }

    bool is_ok = true;
    FOR(i, N)
    {
        if (mark[i] == -1)
        {
            is_ok = false;
            break;
        }
    }
    if (is_ok)
    {
        cout << "Yes" << endl;
        for (i = 1; i < N; i++)
        {
            cout << mark[i] << endl;
        }
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 13312
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}
#define DEBUG_VLL(vec) REP(i, vec.size()) cerr<<vec[i]<<(i==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll q; cin >> q;
    while (q-->0) {
        ll a, b; cin >> a >> b;
        if (a>b) swap(a, b);
        if (a == b || a+1 == b) {
            cout << 2*a-2 << '\n';
        } else {
            ll l=1, r=10e9+1;
            while (l+1 < r) {
                ll mid = (l+r)/2;
                if (mid*mid < a*b) l = mid;
                else r=mid;
            }
            if (l*(l+1) >= a*b) cout << 2*l-2 << '\n';
            else cout << 2*l-1 << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(void) {
	using namespace std;
	int x, y;
	while (cin >> x >> y) {
		if (x == 0 && y == 0)break;
		if (x < y)cout << x << ' ' << y << endl;
		else cout << y << ' ' << x << endl;
		
	}
}

Measured memory_bytes: 3028
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fr first
#define se second
#define pb push_back

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  string S;cin>>S;
  int a=0,low=0,upp=0,sum=0;
  vector<int> gre(S.size()+1,0),lit(S.size()+1,0);
  if(S.at(0)=='<'){
    gre[1]=1;
  }
  REP(i,1,S.size()){
    if(S.at(i)=='<'){
      gre[i+1]=gre[i]+1;
    }
  }
  if(S.at(S.size()-1)=='>'){
    lit[S.size()-1]=1;
  }
  RREP(i,S.size()-2,-1){
    if(S.at(i)=='>'){
      lit[i]+=lit[i+1]+1;
    }
  }
  // debug(gre)
  // debug(lit)
  int ans=0;
  REP(i,0,S.size()+1){
    ans+=max(gre[i],lit[i]);
  }
  print(ans);

}


Measured memory_bytes: 8732
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define rep(i,a,b) for(uint32 i = (a); i < (b); ++i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(),(x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;

template<typename T>
class hashmap64 {
	std::vector<std::pair<uint64, T>> map;
	uint64 mask, count, temp;
	uint64 hash64(uint64 key) {
		key = ~key;
		key ^= key << 13;
		key ^= key >> 19;
		return key ^ (key << 17);
	}
public:
	hashmap64() :map(8192, std::make_pair(~static_cast<std::uint_fast64_t>(0), T())) {
		mask = 8191; count = 0;
	}
	hashmap64(size_t s) {
		s |= s << 1;
		s |= s >> 2;
		s |= s >> 4;
		s |= s >> 8;
		s |= s >> 16;
		s |= s >> 32;
		mask = s;
		count = 0;
		map.resize(s + 1, std::make_pair(~static_cast<std::uint_fast64_t>(0), T()));
	}
	T &operator[](uint64 suf) {
		temp = mask&hash64(suf);
		while (map[temp].first != suf) {
			temp = mask&(temp + 1);
		}
		return map[temp].second;
	}
	void insert(uint64 key, const T &value) {
		temp = mask&hash64(key);
		while (~map[temp].first) {
			if (map[temp].first == key) {
				map[temp].second = value;
				return;
			}
			temp = mask&(temp + 1);
		}
		map[temp] = std::make_pair(key, value);
		++count;
		if ((count << 1) > mask) {
			std::pair<uint64, T> mkey;
			mask = mask << 1 | 1;
			map.resize(mask + 1, std::make_pair(~static_cast<std::uint_fast64_t>(0), T()));
			for (uint64 t = 0;t <= mask >> 1;++t) {
				if (~map[t].first) {
					mkey = map[t];
					map[t].first = ~static_cast<std::uint_fast64_t>(0);
					temp = mask&hash64(mkey.first);
					while (~map[temp].first) {
						temp = mask&(temp + 1);
					}
					map[temp] = mkey;
				}
			}
		}
		return;
	}
	bool find(uint64 key) {
		temp = mask&hash64(key);
		while (~map[temp].first) {
			if (map[temp].first == key) {
				return true;
			}
			temp = mask&(temp + 1);
		}
		return false;
	}
	bool empty(void) {
		return !count;
	}
	size_t size(void) {
		return count;
	}
};

int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	hashmap64<uint32> map(15);
	uint32 n;
	std::cin >> n;
	int64 a, sum = 1e15;
	uint32 ans = 0;
	map.insert(sum, 0);
	rep(i, 0, n) {
		std::cin >> a;
		sum += a;
		if (map.find(sum)) {
			ans = std::max(ans, i + 1 - map[sum]);
		}
		else {
			map.insert(sum, i + 1);
		}
	}
	std::cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 15272
H = {}
999.times {|i| H[i**5] = i; H[-i**5] = -i}
x = gets.to_i
999.times {|a;b|
  y = a**5
  break puts [b, a]*' '  if b = H[x+y]
  break puts [b,-a]*' '  if b = H[x-y]
}

Measured memory_bytes: 14416
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 2345;
const int MOD = (int)1e9 + 7;
int A[MAXN], B[MAXN];
int dp[MAXN][MAXN][3];// 0 all, 1 use i, 2 = use j


int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    for (int i = 1; i <= N; i++) scanf("%d", &A[i]);
    for (int i = 1; i <= M; i++) scanf("%d", &B[i]);
    for (int i = 0; i <= N; i++) dp[i][0][0] = 1;
    for (int j = 0; j <= M; j++) dp[0][j][0] = 1;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
            dp[i][j][1] = dp[i][j - 1][1];
            dp[i][j][2] = dp[i - 1][j][2];
            dp[i][j][0] = (dp[i - 1][j - 1][0] + dp[i][j][1]) % MOD;
            dp[i][j][0] = (dp[i][j][0] + dp[i][j][2]) % MOD;
            if (A[i] == B[j]) {
               dp[i][j][1] = (dp[i][j][1] + dp[i - 1][j - 1][0]) % MOD;
               dp[i][j][2] = (dp[i][j][2] + dp[i - 1][j - 1][0]) % MOD;
               dp[i][j][0] = (dp[i][j][0] + dp[i - 1][j - 1][0]) % MOD;
            }
        }
    }
    printf("%d\n", dp[N][M][0]);
    return 0;
}


Measured memory_bytes: 55552