akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c;
    cin>>a>>b>>c;
    
    int ans = 0;
    for(int i = a; i <=b; i++){
        if(c%i==0){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
long long gcd(long long x, long long y) {
    if (x == 0) return y;
    if (y == 0) return x;
    return gcd(y, x%y);
}

int main(void){
  long long a,b;
  cin >> a >> b;
  
  long long g = gcd(a,b);
  vector<long long>p;
  
  for(int i=1;i<=sqrt(g);i++){
    if(g % i == 0){
        p.push_back(i);
        p.push_back(g / i);
  }
  }
  
  /*for(int i= 0;i<p.size();i++){
      cout << p[i] << " ";
  }*/
  
  sort(p.begin(),p.end());
  int ans = 0;
  
  for(int i=1;i<p.size();i++){
    if(p[i] != 0){
      for(int j = i+1;j<p.size();j++){
        if(gcd(p[i],p[j]) != 1) p[j] = 0;
      }
    }
  }
  
  for(int i=0;i<p.size();i++){
    if(p[i] != 0) ans ++;
  }
  
  if(g == 1) cout << 1 << endl;
  else cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int k, n;
  cin >> n >> k;
  unordered_map< int, int > cnt;
  for (int i=0; i<n; ++i) {
    int a;
    cin >> a;
    if (cnt.count(a)==0) cnt[a] = 1;
    else cnt[a]++;
  }
  vector< int > v;
  for (auto it : cnt) {
    v.push_back(it.second);
  }
  sort(v.begin(), v.end(), greater< int >());
  if (v.size() <= k) {
    cout << 0 << endl;
    return 0;
  }
  int ans = 0;
  for (int i=k; i<v.size(); ++i) ans += v[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 10312
#include <stdio.h>

#define W_LIM 150


int main(void){
	int n;
	int curW;
	int ev[256];
	int evTime[256];
	int evCnt;
	int broken;
	
	
	while (scanf("%d", &n), n){
		evCnt = 0;
		// read events
		for (int i=0; i<n; i++){
			int m,a,b;

			scanf("%d %d %d", &m, &a, &b);
			ev[evCnt] = m;
			evTime[evCnt] = a;
			evCnt++;
			ev[evCnt] = -m;
			evTime[evCnt] = b;
			evCnt++;
		}
		// sort eventTable
		for (int i=0; i<evCnt; i++){
			int min=i, minT=evTime[i], tmp;
			for (int j=i+1; j<evCnt; j++){
				if (evTime[j]<minT) minT = evTime[min=j];
			}
			evTime[min] = evTime[i]; evTime[i] = minT;
			tmp = ev[min]; ev[min] = ev[i]; ev[i] = tmp;
		}
		
		// simulate
		curW = 0;
		broken = 0;
		for (int i=0; i<evCnt; i++){
			curW += ev[i];
	//		printf("t:%d  ev:%d  curW:%d\n", evTime[i], ev[i], curW);
			// ????????????????????????????????????????????????????????§???????????????
			if (evTime[i+1]==evTime[i]) continue;
			if (curW > W_LIM) broken = 1;
		}
		puts(broken?"NG":"OK");
//		for (int i=0; i<evCnt; i++){
//			printf("t:%d  ev:%d\n", evTime[i], ev[i]);
//		}
	}
	return 0;
}

Measured memory_bytes: 1012
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vec> mat;
vec G[200001];
int V,color[200001];
bool dfs(int v,int c){
    color[v]=c;
    rep(i,G[v].size()){
        if(color[G[v][i]]==c) return false;
        if(color[G[v][i]]==0&&!dfs(G[v][i],-c)) return false;
    }
    return true;
}
int main(){
    int n,a,b;
    cin>>n;
    rep(i,n-1) cin>>a>>b,G[a].push_back(b),G[b].push_back(a);
    dfs(1,1);
    int x=0,y=0;
    rep(i,n){
        if(color[i+1]==1) x++;
        else y++;
    }
    int Z=-1;
    if(x<y) swap(x,y),Z=1;
    int X=(n+2)/3,Y=(n+1)/3;
    vec ans(200001);
    int xx=0,yy=0,zzz=0;
    if(y<Y){
        rep(i,n){
            if(color[i+1]==Z) ans[i+1]=3*zzz+3,zzz++;
            else{
                if(xx<X) ans[i+1]=3*xx+1,xx++;
                else if(yy<Y) ans[i+1]=3*yy+2,yy++;
                else ans[i+1]=3*zzz+3,zzz++;
            }
        }
        rep(i,n) cout<<ans[i+1]<<" ";
        return 0;
    }
    rep(i,n){
        if(color[i+1]==Z){
            if(yy<Y) ans[i+1]=3*yy+2,yy++;
            else ans[i+1]=3*zzz+3,zzz++;
        }
        else{
            if(xx<X) ans[i+1]=3*xx+1,xx++;
            else ans[i+1]=3*zzz+3,zzz++;
        }
    }
    rep(i,n) cout<<ans[i+1]<<" ";
}


Measured memory_bytes: 19200
#include<stdio.h>
int main(){
	char t[99];
	double s[99],v;
	int p=0,f,c;
	while(~scanf("%[^ \n]",t)){
		f=0;
		if(t[1]==0) {
			if(t[0]=='+')
				s[p-2]+=s[p-1],p--;
			else if(t[0]=='-')
				s[p-2]-=s[p-1],p--;
			else if(t[0]=='*')
				s[p-2]*=s[p-1],p--;
			else if(t[0]=='/')
				s[p-2]/=s[p-1],p--;
			else
				f=1;
		} else
			f=1;
		if(f) {
			sscanf(t,"%lf",&v);
			s[p++]=v;
		}
		c=getchar();
		if(c=='\n')
			printf("%f\n",s[--p]+0.);
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

const int MOD = 1e9 + 7;

int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  char map[h][w];
  int count[h][w];
  for (int i = 0; i < h; i++)
    scanf("%s", map[i]);
  count[0][0] = 1;
  for (int j = 1; j < w; j++) {
    if (map[0][j] == '.')
      count[0][j] = count[0][j - 1];
    else
      count[0][j] = 0;
  }
  for (int i = 1; i < h; i++) {
    if (map[i][0] == '.')
      count[i][0] = count[i - 1][0];
    else
      count[i][0] = 0;
    for (int j = 1; j < w; j++) {
      if (map[i][j] == '.')
        count[i][j] = (count[i - 1][j] + count[i][j - 1]) % MOD;
      else
        count[i][j] = 0;
    }
  }
  printf("%d\n", count[h - 1][w - 1]);
  return 0;
}


Measured memory_bytes: 4992
until (n = gets.to_i).zero?
  costs = n.times.map { gets.split.tap {|a| a[1] = a[1].to_i} }.to_h
  
  m = gets.to_i
  recipe = Hash.new {|hash, key| hash[key] = []}
  m.times do
    given = gets.split
    recipe[given[0]] += given[2..-1]
  end
  goal = gets.chomp
  
  try = ->(parent) {
    r = recipe[parent]
    c = costs[parent]
    if r.empty?
      c
    else
      made = r.map {|child| try.(child)}.sum
      [made, c].min
    end
  }
  puts try.(goal)
end


Measured memory_bytes: 6892
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N = inputI()

res = 0
for i in range(1,N+1):
  if i%3==0 or i%5==0:
    pass
  else:
    res +=i
    
print(res)


Measured memory_bytes: 72800
package main
 
import (
	"fmt"
	"strconv"
)

func main() {

	GuessTheNumber()


}

//GuessTheNumber test
func GuessTheNumber() {

	var N, M int

	fmt.Scan(&N, &M)

	s := make([]int, M)
	c := make([]int, M)

	for i := 0; i < M; i++ {

		fmt.Scan(&s[i], &c[i])
	}

	if M==0{

		if N==1{

			fmt.Println(0)

		}else if N==2{

			fmt.Println(10)

		}else if N==3{

			fmt.Println(100)

		}

		return
	}

	result := make([]int, N)

	for i := 0; i < N; i++ {

		result[i] = -1
	}

	keta := 0
	number := 0

	for i := 0; i < M; i++ {

		keta = s[i]
		number = c[i]

			if result[keta-1] == -1 {

				result[keta-1] = number

			} else {

				if result[keta-1] == number {

				} else {

					fmt.Println(-1)
					return
				}
			}
	}


		if N > 1{

			if result[0]==0{

				fmt.Println(-1)
				return
			
			}else if result[0] == -1{

				result[0]= 1
			}

		}else{
			
			if result[0] == -1{

				result[0]=0
			}
		
		}

		for i:=1;i<N;i++{

			if result[i] == -1{

				result[i]=0
			}
		}

		var stresult  string

		for i:=0;i<N;i++{

			stresult += strconv.Itoa(result[i])
		}

		fmt.Println(stresult)
	
}

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

int main(){
  
  int a,b,c = 0,d = 0;
  cin >> a >> b;
  
  for(int i=0; i<=a; i++){
    
    c += i-1;
    
  }
  
  for(int i=0; i<=b; i++){
    
    d += i-1;
    
  }
    
    cout << c+d+2 << endl;
  
}


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

const int N = 1e5 + 1;

int g[N];

int n;
vector<int> V[N];

void init(){
    memset(g, -1, sizeof(g));
    long long s = 0;
    for(int i=1; ;i++){
        s = s + i;
        if(s >= N)  break;
        g[s] = i;
    }
}

void solve(int stg, int base, int num){
    if(num == 0){
        return;
    }
    for(int i=0; i<num; i++){
        V[stg].push_back(base + i);
        V[stg+1+i].push_back(base + i);
    }
    solve(stg+1, base + num, num - 1);
}

int main(){
    init();
    while(~scanf("%d", &n)){
        if(g[n] != -1){
            puts("Yes");
            printf("%d\n", g[n]+1);
            solve(0, 1, g[n]);
            for(int i=0; i<=g[n]; i++){
                printf("%d", V[i].size());
                for(int j=0; j<V[i].size(); j++){
                    printf(" %d", V[i][j]);
                }
                puts("");
                V[i].clear();
            }
        } else {
            puts("No");
        }
    }
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  if (n == 1) {
    cout << "Hello World";
    return 0;

  } else {
    int a, b;
    cin >> a >> b;
    cout << a + b;
    return 0;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
// const ll RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
// gp_hash_table<int, int> table;

#define ll long long int
#define vii vector< ll >
#define pb push_back
#define pii pair<ll,ll>
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define ins insert
#define ld long double
#define lp(l,r) for(i=l;i<=r;++i)

#define lpj(l,r) for(j=l;j<=r;++j)
#define lpr(l,r) for(i=r;i>=l;--i)
#define lprj(l,r) for(j=r;j>=l;--j)

#define swap(a,b){ auto _t=a;a=b,b=_t;}
#define flush() cout.flush()
#define popcount __builtin_popcount



// typedef __int128 bign;


#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define MD          1000000007
#define M 			100011
#define LN 			14
#define fftmod      998244353
#define EPS         (double)1e-10

ll md=MD;
ll inf=1e18;

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


inline ll exp(ll a,ll b){ll r=1LL;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b/=2;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;if(a==0)return b;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}

using cd=complex<double>;
const double PI=acos(-1);

inline ll rand(ll l,ll r){
	return l+rng()%(r-l+1);
}

ll a[M];
int main(){


    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

   // ifstream fin("input.txt");ofstream fout("outut.txt");
    ll t,i,j,m,n,s,z,k,p,T;string s1,s2;ll q;ll x,y;
    cin>>n;
    lp(1,n)cin>>a[i];
    sort(a,a+n+1);
    if(a[n/2]==a[n/2+1])cout<<"0\n";
    else cout<<a[n/2+1]-a[n/2]<<"\n";







    return 0;
}


Measured memory_bytes: 1024
def election(a,b):
    candidate=[0 for i in range(a)]
    index=0
    bowl=b
    while True:
        if bowl==0:
            bowl+=candidate[index]
            candidate[index]=0
        else:
            bowl-=1
            candidate[index]+=1

        if candidate[index]==b:
            break

        if index==a-1:
            index=0
        else:
            index+=1

    return index


while True:
    n,p=[int(i) for i in input().split(" ")]
    if n==0 and p==0:
        break
    else:
        print(election(n,p))
        

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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(){
    int n;
    cin >> n;
    V<int> ans(10005);
    Rep(x,100)Rep(y,100)Rep(z,100) {
        int i = x*x + y*y + z*z + x*y + y*z + z*x;
        if(i > 10000) continue;
        ans[i-1]++;
    }
    rep(i,n) {
        cout << ans[i] << endl;
    }
}

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

int main()
{
  int n, w;
  cin >> n >> w;
  int ans = 1;
  for (int i = 1; i <= n; ++i) {
    if(i == 1) ans *= w;
    else ans *= w-1;
  }
  cout << ans << endl;
  
  return 0;
}
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int m1,d1,m2,d2;
int v[]={31,28,31,30,31,30,31,31,30,31,30,31};
int main()
{
    cin>>m1>>d1;
    cin>>m2>>d2;
    if(d1==v[m1-1])
        cout<<1;
    else
        cout<<0;
    return 0;
}

Measured memory_bytes: 256
N = int(raw_input())
A = raw_input().split()
B = raw_input().split()
C = raw_input().split()


satis = 0
for i in range(N):
    satis = satis + int(B[int(A[i])-1])
    if i >0:
        if int(A[i]) == int(A[i-1])+1:
            satis = satis + int(C[int(A[i])-2])

print satis



Measured memory_bytes: 2568
import math

n = int(input())
xv = [int(xi) for xi in input().split()]
yv = [int(yi) for yi in input().split()]

print(sum([abs(xi-yi) for (xi, yi) in zip(xv, yv)]))
print(math.sqrt(sum([pow(abs(xi-yi), 2) for (xi, yi) in zip(xv, yv)])))
print(math.pow(sum([pow(abs(xi-yi), 3) for (xi, yi) in zip(xv, yv)]), 1/3))
print(max([abs(xi-yi) for (xi, yi) in zip(xv, yv)]))

Measured memory_bytes: 7848
import math
N = int(input())

stations = []
for n in range(N-1):
  tmp = tuple(map(int, input().split()))
  stations.append(tmp)

for index in range(len(stations)):
  time = 0
  sum_time = 0
  for c, s, f in stations[index:]:
    if time <= s:
      time = s + c
    else:
      diff = time - s
      count = math.ceil(diff/f)
      time = s + f*count + c
  print(time)
print(0)

Measured memory_bytes: 3188
#include<iostream>
#include<string>
using namespace std;
string s;
int main(){
	cin >> s;
	for(int i = 0; i < s.length();i++)
		if(s[i] == '7') {
			cout << "Yes" << endl;
			return 0;
		}
	cout  << "No" << endl;
}


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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#ifdef BTK
#include<dvector.h>
#define DEBUG if(1)
#else
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
    
int main(){
    LL res=0;
    int N;
    cin>>N;
    REP(i,N){
        int l,r;
        cin>>l>>r;l--;
        res+=r-l;

    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
t = list(map(int,input()))
p = ['+','+','+']
q = ['','','']
for i in range(8):
    if i & 1:
        c = t[0] + t[1]
        p[0] = '+'
    else:
        c = t[0] - t[1]
        p[0] = '-'
    if i & (1<<1):
        c += t[2]
        p[1] = '+'
    else:
        c -= t[2]
        p[1] = '-'
    if i & (1<<2):
        c += t[3]
        p[2] = '+'
    else:
        c -= t[3]
        p[2] = '-'
    if c == 7:
        q[0] = p[0]
        q[1] = p[1]
        q[2] = p[2]
print(str(t[0]) + q[0] + str(t[1]) + q[1] + str(t[2]) + q[2] + str(t[3]) + '=7')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
ll n,k,a[100010],b[100010];

int main(){
	cin >> n >> k;
	REP(i,0,n) cin >> a[i];
	REP(i,0,n) b[i+1]+=b[i]+a[i]*(a[i]>0);
	REP(i,0,n) a[i+1]+=a[i];
	RREP(i,n,1) a[i]=a[i-1]; a[0]=0;
	
	ll ma=0;
	REP(i,0,n-k+1) ma=max(ma,max(b[n]-(b[i+k]-b[i])+(a[i+k]-a[i]),b[n]-(b[i+k]-b[i])));
	cout << ma << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////


int main() {

	ll A, B, C, D;
	cin >> A >> B >> C >> D;

	if (A + B > C + D) { cout << "Left"; }
	if (A + B == C + D) { cout << "Balanced"; }
	if (A + B < C + D) { cout << "Right"; }


	system("PAUSE");

	

}


Measured memory_bytes: 504
#include<iostream>
#include<vector>
using namespace std;
#define MAXN 50
#define MAXM 50

int N,M;
vector<vector<int> > G(MAXN,vector<int>(MAXN,0));
vector<bool> visited(MAXN,false);
int a[MAXM],b[MAXM];

void dfs(int s,vector<bool>& visited){
  visited[s]=true;
  for(int j=0;j<N;j++)if(G[s][j]==1){
    if(!visited[j]) dfs(j,visited);
  }
}
int main(){
  cin>>N>>M;
  for(int i=0;i<M;i++){
    cin>>a[i]>>b[i];
    a[i]--;b[i]--;
    G[a[i]][b[i]]=1;
    G[b[i]][a[i]]=1;
  }
  int ans=0;
  for(int i=0;i<M;i++){
    G[a[i]][b[i]]=0;
    G[b[i]][a[i]]=0;
    fill(visited.begin(),visited.end(),false);
    int cnt=0;
    for(int j=0;j<N;j++){
      if(!visited[j]){
        dfs(j,visited);
        cnt++;
      }
    }
    if(cnt>=2) ans++;
    G[a[i]][b[i]]=1;
    G[b[i]][a[i]]=1;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

rui_A = [0 for _ in range(N)]
rui_B = [0 for _ in range(M)]



rui_A[0] = A[0]
for i in range(N-1):
    rui_A[i+1] = rui_A[i] + A[i+1]

rui_B[0] = B[0]
for i in range(M-1):
    rui_B[i+1] = rui_B[i] + B[i+1]

rui_A.insert(0,0)

max_book = 0
for i in range(len(rui_A)):
    nokori = K - rui_A[i]
    if nokori >= 0:
        B_posi = bisect.bisect_right(rui_B,nokori)
        if max_book < B_posi + i:
            max_book = B_posi + i
print(max_book)

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

void print(vector<int> v){
    for(const auto& i : v)
        cout << i << " ";
    cout << "\n";
}
const int INF = 1e9 + 5;
int main(int argc, char ** argv){
    int n;
    cin >> n;
    vector<int> s(n);
    vector<int> dp(n, INF);
    dp[0] = 0;
    for(int i = 0; i < n; ++i){
        cin >> s[i];
    }
    for(int i = 0;i < dp.size();++i){
        for(int j : {i+1,i+2}){
            if(j < n)
                dp[j] = min(abs(s[i] - s[j]) + dp[i], dp[j]);
        }
    }
    printf("%d\n", dp[n-1]);
    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#define N 100005
using namespace std;
int fac[N],s[N];
int main(){
	int n,m;
	cin>>n>>m;
	int ans1=0,ans2=0;//ans1记录通过题数，ans2记录罚时 
	while(m--){
		int a;
		string b;
		cin>>a;
		cin>>b;
		if(b=="WA"){
			if(fac[a])
			continue;
			else
			s[a]++;
		}
		else{
			if(fac[a])
			continue;
			else{
				fac[a]=1;
				ans1++;
				ans2+=s[a];
			}
		}
	}
	cout<<ans1<<' '<<ans2<<endl;
	return 0;
}

Measured memory_bytes: 1024
from fractions import gcd

def lcm_base(x, y):
  return x * y // gcd(x, y)

d = int(input())
nums = list(map(int, input().split(' ')))

lcm_num = 1
for n in nums:
  lcm_num = lcm_base(lcm_num, n)

ans = 0
mod = 10**9 + 7
for n in nums:
  ans += lcm_num//n
print(ans % mod)

Measured memory_bytes: 6108
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>(b);i--)
#define pb push_back

typedef long long ll;
using namespace std;
int MOD = 1000000007;
int N, m;
ll s;
int A[100000];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> N ;
  FOR(i, 0, N){
    cin >> A[i];
  }
  sort(A, A + N);
  m = A[N - 1];
  s = 0;
  FOR(i, 0, N){
    s += A[i];
  }
  FOR(i, 0, N){
    m = A[N - i - 1];
    s -= m;
    if(s * 2 < m){
      cout << i + 1 << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 768
// https://atcoder.jp/contests/dp/tasks/dp_i

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define mod 1000000007
#define gcd __gcd
#define inf INT_MAX
#define minf INT_MIN
#define pb push_back
#define all(v) v.begin(),v.end()
#define print(v) for(auto x:v) cout<<x<<" "; cout<<"\n";
#define printn(v) for(auto x:v) cout<<x<<"\n";
#define F first
#define S second
#define mp make_pair

double dp[3000][3000];

//dp[i][x] : probability of getting atleast x heads after tossing i coins
double coin(vector<double>&pr, int i, int x) {
	if (x == 0) return 1;
	if (i == 0) return 0;

	if (dp[i][x] > -1) return dp[i][x];

	return dp[i][x] = pr[i] * coin(pr, i - 1, x - 1) + (1 - pr[i]) * coin(pr, i - 1, x);
}

int32_t main() {
	fastio;
	memset(dp, -1, sizeof dp);
	int n; cin >> n;
	vector<double>pr(n + 1);
	for (int i = 1; i <= n; i++) cin >> pr[i];
	cout << fixed << setprecision(10);
	cout << coin(pr, n, (n + 1) / 2) << endl;
}

Measured memory_bytes: 74308
#include <bits/stdc++.h>
#define inf (long long)(1e18)
using namespace std;

struct dat {
  long long cos;
  bool isr;
  string now;
  bool operator<(const dat& r) const { return cos > r.cos; }
};

using P = pair<string, bool>;

long long n;
vector<string> s, rs;
vector<long long> c;
map<P, long long> mp;
priority_queue<dat> pq;

long long solve();

int main() {
  cin >> n;
  s.resize(n);
  c.resize(n);
  rs.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> s[i] >> c[i];
    rs[i] = s[i];
    reverse(rs[i].begin(), rs[i].end());
  }
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = inf;
  for (int i = 0; i < n; ++i)
    if (s[i] == rs[i])
      res = min(res, c[i]);
    else {
      pq.push({c[i], 0, s[i]});
      if (mp.find(P(s[i], 0)) != mp.end())
        mp[P(s[i], 0)] = min(mp[P(s[i], 0)], c[i]);
      else
        mp[P(s[i], 0)] = c[i];
    }
  while (pq.size()) {
    auto [cos, isr, now] = pq.top();
    pq.pop();
    if (res < cos) break;
    if (mp[P(now, isr)] != cos) continue;
    for (int i = 0; i < n; ++i) {
      string nxt = isr ? s[i] : rs[i];
      long long nextcost = cos + c[i];
      int mlen = min(nxt.size(), now.size());
      bool nxtch = isr;
      if (nxt.substr(0, mlen) != now.substr(0, mlen)) continue;
      if (abs((int)nxt.size() - (int)now.size()) <= 1) {
        res = min(res, nextcost);
        continue;
      }
      if (nxt.size() > now.size()) {
        nxt = nxt.substr(mlen, nxt.size() - mlen);
        nxtch = !nxtch;
      } else
        nxt = now.substr(mlen, now.size() - mlen);
      {
        string tmp = nxt;
        reverse(tmp.begin(), tmp.end());
        if (tmp == nxt) {
          res = min(res, nextcost);
          continue;
        }
      }
      P np(nxt, nxtch);
      if (mp.find(np) == mp.end() || mp[np] > nextcost) {
        mp[np] = nextcost;
        pq.push({nextcost, nxtch, nxt});
      }
    }
  }
  if (res == inf) return -1;
  return res;
}


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

class union_find{
public:
    union_find(int N){
        parent = new int[N];
        for(int i = 0; i < N; i++) parent[i] = i;
    }

    int root(int x){
        if(parent[x] == x) return x;
        else return (parent[x] = root(parent[x]));
    }

    bool same(int x, int y){
        return root(x) == root(y);
    }

    void unite(int x, int y){
        x = root(x);
        y = root(y);
        parent[y] = x;
    }

private:
    int *parent;
};

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    for(int i = 0; i < m; i++) cin >> a[i] >> b[i];

    int ans = 0;
    for(int i = 0; i < m; i++){
        union_find data(n+1);
        for(int j = 0; j < m; j++){
            if(j == i) continue;
            data.unite(a[j], b[j]);
        }
        bool islinking = true;
        for(int j = 1; j <= n; j++){
            for(int k = j+1; k <= n; k++){
                if(!data.same(j, k)) islinking = false;
            }
        }
        if(!islinking) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int iinf = 1 << 28;
const long long llinf = 1ll << 60;
const double PI = 3.14159265;

void work() {
    int v[3][3];
    int n;
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) cin >> v[i][j];
    }
    cin >> n;
    for (int k = 0; k < n; ++k) {
        int a; cin>>a;
        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < 3; ++j) {
                if (v[i][j] == a) v[i][j] = 0;
            }
        }
    }
    if (!v[0][0] && !v[0][1] && !v[0][2]) { cout << "Yes" << endl; return; }
    if (!v[1][0] && !v[1][1] && !v[1][2]) { cout << "Yes" << endl; return; }
    if (!v[2][0] && !v[2][1] && !v[2][2]) { cout << "Yes" << endl; return; }
    if (!v[0][0] && !v[1][0] && !v[2][0]) { cout << "Yes" << endl; return; }
    if (!v[0][1] && !v[1][1] && !v[2][1]) { cout << "Yes" << endl; return; }
    if (!v[0][2] && !v[1][2] && !v[2][2]) { cout << "Yes" << endl; return; }
    if (!v[0][0] && !v[1][1] && !v[2][2]) { cout << "Yes" << endl; return; }
    if (!v[0][2] && !v[1][1] && !v[2][0]) { cout << "Yes" << endl; return; }
    cout << "No" << endl;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    work();

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int n,s,g,m;
string t,t1;
int main(void){
    cin>>n;
    g=n;
    cout<<s<<endl;
    cin>>t;
    while(t!="Vacant"){
        m=(s+g)/2;
        cout<<m<<endl;
        cin>>t1;
        if((t1==t)^(s%2==m%2))g=s;
        s=m;
        t=t1;
    }
}


Measured memory_bytes: 852
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { 
		Scanner input = new Scanner(System.in);
		long N = input.nextLong();
		boolean found=false;
		for (long h = 1;h<=3500;h++) {
			for (long w = 1; w <= 3500; w++) {
				long Num = N*h*w;
				long Den = 4*h*w-N*w-N*h; //n=Nhw/(4hw-Nw-Nh) -> Analysis in programming handbook
				//if (Den<=0) break;
				if (Den>0&&Num%Den==0) {
					long ans = Num/Den;
					System.out.println(h+" "+ans+" "+w);
					found=true;
					break;
				}
			}
			if (found) break;
		}
	}	
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int c[3][3];
    rep(i,3){
        rep(j,3){
            cin >> c[i][j];
        }
    }
    vector<int> v;
    rep(i,3){
        v.push_back(i);
    }
    int tmp[6] = {};
    int cnt = 0;
    do{
        rep(i, 3){
            tmp[cnt] += c[i][v[i]];
        } 
        cnt++;
    } while (next_permutation(v.begin(), v.end()));
    bool flag = true;
    rep(i,5){
        if(tmp[i]!=tmp[i+1]){
            flag = false;
        }
    }
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

const int N=800005;

int n,v,tot,cnt;
int x[N],R[22][N],L[22][N],b[22],id[N],p1[N],p2[N],f[N],g[N],ans[N];

void init(){
	int i,j,k,l;
	memset(L,0x3f,sizeof(L));
	for (i=0;i<tot;i++){
		for (j=1;j<=n;j=k+1){
			k=j;
			while (k<n&&x[k+1]-x[k]<=b[i]) k++;
			for (l=j;l<=k;l++){
				L[i][l]=j; R[i][l]=k;
			}
		}
	}
	for (i=1;i<=n;i=k+1){
		k=i; cnt++;
		while (k<n&&x[k+1]-x[k]<=b[tot]) k++;
		for (l=i;l<=k;l++){
			id[l]=cnt;
			p1[cnt]=i; p2[cnt]=k;
		} 
	}
}

void work(){
	int i,j,sz,s,ss,l,r;
	sz=(1<<tot)-1;
	for (i=0;i<=sz;i++) f[i]=n+1;
	for (s=0;s<=sz;s++){
		for (j=0;j<tot;j++)
			if (!((s>>j)&1)){
				ss=s|(1<<j);
				f[ss]=min(f[ss],L[j][f[s]-1]);
				g[ss]=max(g[ss],R[j][g[s]+1]);
			}
	}
	for (s=0;s<=sz;s++){
		l=g[s]; r=f[sz^s];
		if (l+1>=r){
			for (i=1;i<=n;i++) ans[i]=1;
			return;
		}
		if (p1[id[l+1]]<=l+1&&p2[id[l+1]]>=r-1) ans[id[l+1]]=1;
	}
}

int main(){
	int i;
	scanf("%d%d",&n,&v);
	for (i=1;i<=n;i++) scanf("%d",&x[i]);
	b[0]=0;
	while (v){
		b[++tot]=v;
		v/=2;
	}
	sort(b,b+tot+1);
	init();
	work();
	for (i=1;i<=n;i++)
		if (ans[id[i]]) printf("Possible\n");
	else printf("Impossible\n");
	return 0;
}

Measured memory_bytes: 137600
/*
  mail: mleautomaton@foxmail.com
  author: MLEAutoMaton
  This Code is made by MLEAutoMaton
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
char s[100010];
int main(){
	scanf("%s",s+1);
	for(int i=1;i<strlen(s+1);i++){
		if(s[i]==s[i+1])return puts("Bad"),0;
	}
	puts("Good");
	return 0;
}


Measured memory_bytes: 256
import copy
n = int(input())
a = [int(x) for x in input().split()]
b = copy.copy(a)
b.sort()
m = (b[n//2] + b[n//2 - 1]) // 2
for i in range(n):
  if m < a[i]:
    print(b[n//2 - 1])
  else:
    print(b[n//2])


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

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

    int tmp = n;
    int sum = 0;
    while(true){
        if(tmp < 10){
            sum += tmp;
            break;
        }
        sum += (tmp % 10);
        tmp /= 10;
    }

    if(n % sum == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<double> D(N);
    for (int i = 0; i < N; ++i) cin >> D[i];
    vector<double> pos(N);
    for (int i = 0; i < N; ++i) {
        // i番目の円柱の中心位置を決める
        double now_pos = D[i];
        for (int j = 0; j < i; ++j) {
            double d = 2.0 * sqrt(D[i] * D[j]);
            now_pos = max(now_pos, pos[j] + d);
        }
        pos[i] = now_pos;
    }
    double ans = 0.0;
    for (int i = 0; i < N; ++i) {
        ans = max(ans, pos[i] + D[i]);
    }
    cout << fixed << setprecision(6);
    cout << ans << endl;
    return 0;
}


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

using namespace std;
using ll = long long;


int main()
{
    int n;
    cin >> n;
    vector<ll> dp(n + 1);
    dp[0] = 2, dp[1] = 1;
    for(int i = 2; i <= n; i++)dp[i] = dp[i - 1] + dp[i - 2];
    cout << dp[n] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i, n)      for (int i = 0; i < (n); i++)
#define repr(i, n)     for (int i = (n) - 1; i >= 0; i--)
#define repe(i, l, r)  for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r) - 1; i >= (l); i--)
#define repi(i, l, r)  for (int i = (l); i <= (r); i++)
#define repir(i, l, r) for (int i = (r); i >= (l); i--)
#define range(a) a.begin(), a.end()
void init_io() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(15); }
 
using namespace std;
using ll = long long;

void chmin(ll &x, ll y) {
  x = min(x, y);
}

int main() { init_io();
  int N, K; cin >> N >> K;
  vector<int> H(N);
  rep(i, N) cin >> H[i];
  vector<int> dict(H);
  dict.push_back(0);
  sort(range(dict));
  dict.erase(unique(range(dict)), dict.end());
  rep(i, N) H[i] = lower_bound(range(dict), H[i]) - dict.begin();
  static ll dp[310][310];
  constexpr ll inf = 1e18;
  rep(j, 310) rep(k, 310) dp[j][k] = inf;
  dp[0][0] = 0;
  rep(i, N) {
    rep(j, K+1) rep(k, dict.size() - 1) {
      chmin(dp[j][k+1], dp[j][k] + dict[k+1] - dict[k]);
    }
    rep(j, K+1) reper(k, 1, dict.size()) {
      chmin(dp[j][k-1], dp[j][k]);
    }
    repr(j, K+1) rep(k, dict.size()) if (k != H[i]) {
      dp[j+1][k] = dp[j][k];
      dp[j][k] = inf;
    }
  }
  ll ans = inf;
  rep(j, K+1) rep(k, dict.size()) chmin(ans, dp[j][k]);
  cout << ans << endl;
}


Measured memory_bytes: 1024
import scala.io.Source
import Math.sqrt

object Main{
  def main(args: Array[String]){
    val lines = for{
      in <- Source.stdin.getLines
    }yield if(prime(in.toInt)) in else Nil

    println(lines.filter(_ != Nil).length)
  }

  def prime(n: Int): Boolean = (2 to sqrt(n).toInt).forall(n % _ != 0)
}

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

#define N_MAX 100002
#define ll long long

using namespace std;

int n;

ll m;

vector <int> edges[N_MAX];

vector <int> sons[N_MAX];

bool visited[N_MAX];

void dfs (int node)
{
    visited[node] = true;
    for(int u : edges[node])
        if(visited[u] == false)
        {
            sons[node].push_back(u);
            dfs(u);
        }
}

ll up[N_MAX], down[N_MAX];

void computeDown (int node)
{
    down[node] = 1;
    for(int u : sons[node])
    {
        computeDown(u);
        down[node] = down[node] * (down[u] + 1) % m;
    }
}

ll dw[N_MAX];

void computeUp (int node)
{
    up[node] = (up[node] + 1) % m;
    dw[sons[node].size()] = 1;
    for(int i = sons[node].size() - 1; i >= 0; i--)
        dw[i] = dw[i + 1] * (down[sons[node][i]] + 1) % m;
    ll dw1 = 1;
    for(int i = 0; i < sons[node].size(); i++)
    {
        int u = sons[node][i];
        up[u] = dw1 * dw[i + 1] % m * up[node] % m;
        dw1 = dw1 * (down[u] + 1) % m;
    }
    for(int i = 0; i < sons[node].size(); i++)
        computeUp(sons[node][i]);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i < n; i++)
    {
        int u, v;
        cin >> u >> v;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    dfs(1);
    computeDown(1);
    computeUp(1);
    for(int i = 1; i <= n; i++)
        cout << down[i] * up[i] % m << "\n";
    return 0;
}


Measured memory_bytes: 16768
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const double pi = 3.1415926;
int main()
{
    int a,b;
    cin  >>  a >> b;
    if(a<10&&b<10)
        cout <<a*b << endl;
    else
        cout << -1 <<endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def input_str(row):
    res = []
    for _ in range(row):
        res.append(raw_input().split())
    return res

ipt = input_str(2)
N, T = [int(i) for i in ipt[0]]
t = sorted([int(i) for i in ipt[1]])

total = 0
for i, ti in enumerate(t[:-1]):
    if t[i+1] - t[i] > T:
        total += T
    else:
        total += t[i+1] - t[i]

print total + T


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

int main() {
    int a[10];
    for (int i = 0; i < 4; ++i) {
        scanf("%d", a + i);
    }
    std::sort(a, a + 4);
    if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9) {
        puts("YES");
    } else {
        puts("NO");
    }
    return 0;
}

Measured memory_bytes: 764
n = int(input())
ans = 10**20
a = n ** 0.5
a = int(a)
for i in range(a+1):
  if i ==0:
    continue
  if n % i != 0:
    continue
  j = n/i
  j = int(j)
  ans = i+j-2
print(ans)
  

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
//std::ios::sync_with_stdio(0); std::cin.tie(0);
ll a[212345];
ll b[212345];
ll c[212345];
ll d[212345];
int main() {
	ll n;
	cin >> n;
	ll i, t, ans;
	for (i = 0; i < n; ++i) {
		cin >> a[i];
	}
	b[0] = a[0];
	for (i = 1; i < n; ++i) {
		b[i] = (a[i] ^ b[i - 1]);
	}
	if (n > 1)
		c[n - 1] = a[n - 1];
	for (i = n - 2; i >= 0; i--) {
		c[i] = (a[i] ^ c[i + 1]);
	}
	for (i = 1; i < n - 1; ++i) {
		d[i] = (b[i - 1] ^ c[i + 1]);
	}
	d[0] = c[1];
	if (n > 1)d[n - 1] = b[n - 2];
	for (i = 0; i < n; ++i)cout << d[i] << " ";
	return 0;
}

Measured memory_bytes: 9792
macro_rules! scan_sub {
    ( $itr:ident, $t:ty ) => {
        let mut buf = String::new();
        let $itr = {
            while buf.trim().len() == 0 {
                buf = String::new();
                std::io::stdin().read_line(&mut buf).unwrap();
            }
            buf.split_whitespace().map(|n| n.parse::<$t>().unwrap())
        };
    };
}

macro_rules! scan {
    ( $x:ident; Vec<$t:ty> ) => {
        scan_sub!(itr, $t);
        let $x = itr.collect::<Vec<_>>();
    };
    ( $( $x:ident ),*; $t:ty ) => {
        scan_sub!(itr, $t);
        let mut itr = itr;
        $(
            let $x = itr.next().unwrap();
        )*
    };
}

fn main() {
    scan!(x; usize);
    let a = x / 500;
    let b = (x - a * 500) / 5;

    println!("{}", 1000 * a + 5 * b);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>

using namespace std;

int main(){
    int N,A,B;
    int P[110];
    cin>>N>>A>>B;
    for(int i=0;i<N;i++)cin>>P[i];
    int fir=0;
    int sec=0;
    int tri=0;

    for(int i=0;i<N;i++){
        if(P[i]<=A)fir++;
        if(P[i]>=A+1 && P[i]<=B)sec++;
        if(P[i]>=B+1)tri++;
    }
    cout<<min({fir,sec,tri})<<endl;
    

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<(n);i++)
const int MOD = 1e9 + 7 ;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=100005;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int a,b;
      cin>>a>>b;
      if(a<=5) cout<<0;
      else if(a>5&&a<=12) cout<<b/2;
      else cout<<b;     
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 110
using namespace std;
int n,a[maxn];
int main()
{
    scanf("%d%d",&n,&a[1]);
    int len=1;
    int ans=0;
    for(int i=2;i<=n;++i)
    {
        scanf("%d",&a[i]);
        if(a[i]==a[i-1]) len++;
        else
        {
            ans+=len/2;
            len=1;
        }
    }
    ans+=len/2;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

template <int mod = (int)(1e9 + 7)>
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

const int MOD = 1e9 + 7;

using mint = ModInt<MOD>;

int main(){
    int s, size;
    mint res=0, now=s-3;
    cin >> s;
    size=s-5;
    vector<mint> rui;
    rep(i, s+1){
        rui.push_back(1);
    }
    rui[0]=0;
    if(s-3<0){
        cout << 0 << endl;
        return 0;
    }
    res=1;
    rep2(i, 1, s/3){
        rep2(j, 1, size+1){
            res+=rui[j]; 
            rui[j] += rui[j-1];
        }
        size -= 3;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3648
use itertools::Itertools;

fn main() {
    proconio::input!(n: usize, station: [(u32, u32, u32); n - 1]);
    let ans = (0..n)
        .map(|i| {
            station[i..]
                .iter()
                .fold(0, |now, &(c, s, f)| c + s.max((now + f - 1) / f * f))
                .to_string()
        })
        .collect_vec()
        .join("\n");
    println!("{}", ans);
}


Measured memory_bytes: 2204
#include <stdio.h>
int main(){
	int n,m,i,t,l,r;
	scanf("%d%d",&n,&m);
	if(n%2==0)n--;
	t=(n-1)/2;
	if(t==1)return 0*printf("1 2\n");//特判
	if(t&1){//t是奇数
		l=t/2,r=l+2;
		for(i=1;i<=m;i++){
			printf("%d %d\n",l,r);
			l--,r++;
			if(l==0)l=(t+n)/2,r=l+1;
		}
	}else{//t是偶数
		l=t/2,r=l+2;
		for(i=1;i<=m;i++){
			printf("%d %d\n",l,r);
			l--,r++;
			if(l==0)l=(t+1+n)/2,r=l+1;
		}
	}
	return 0;
}

Measured memory_bytes: 3220
#include <stdio.h>

int main() {
  int H,W,h,w;
  scanf("%d %d",&H,&W);
  scanf("%d %d",&h,&w);
  int paint=0;
  paint += h*W; //行を選んだ時塗られるマスの数
  paint += w*(H-h); //列を選ぶと降られるマス
  int ans=H*W;
  ans -= paint;
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main()
{
    ll x; cin >> x; ll cnt = 0;
    if(x >= 500)
    {
        ll d = x / 500;
        cnt += d * 1000;
        x -= d * 500;
    }
    //cout << x;
    if(x >= 5)
    {
        ll d = x / 5;
        cnt += d * 5;
        x -= cnt;

    }
    cout << cnt << '\n';



}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
const long long mod = 1e9 + 7;
typedef long long ll;
typedef priority_queue<int> PQ;
typedef vector<long long> VL; // VL a(n);
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VL> VLL; // VII a(n,VI(m)) n * m
typedef pair<ll, ll> PL;
typedef map<ll, ll> MP; // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp
// operator << (cout,a);
// chmin(min,a)

int main() {
  ll n,k,m,x=0,y=0,z = 0,h=0,w=0,ans=0,sum = 0, Max = -1, Min = 3e9+1;
  string s,t;
  bool ok=true;
  cin >> n >> k;
  VL a(n),b(200001);
  rep(i,n) {
    cin >> a[i];
    if(b[a[i]] == 0){
      sum++;
    }
    b[a[i]]++;
  }
  sort(ALL(b));
  rep(i,200001){
    if(k >= sum){
      pri(ans);
      return 0;
    }
    if(b[i] > 0){
      ans += b[i];
      sum--;
    }
  }
  return 0;
}

Measured memory_bytes: 3328