akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int a, b;
  cin >> a >> b;
  if (a == b)
    cout << "Draw" << endl;
  else if (a == 1)
    cout << "Alice" << endl;
  else if (b == 1)
    cout << "Bob" << endl;
  else if (a > b)
    cout << "Alice" << endl;
  else
    cout << "Bob" << endl;
}

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

int main(){
  int N, K, b = 1, cnt = 0;
  cin >> N >> K;

  while(cnt < N){
    if(b <= K){
      b = b*2;
    }else{
      b += K;
    }

    cnt++;
  }

  cout << b << endl;
  
  return 0;
}

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

template < typename K, typename V, typename A>
void  map_count (map<K, V> &mapBuff, A a){
    for(auto c : a) {
        if (mapBuff.count(c) == 0 ) {
            mapBuff.insert(make_pair(c, 1));
        } else {
            auto it = mapBuff.find(c);
            mapBuff.insert(make_pair(c, it->second++));
        }
    }
}

int main() {
    string s;
    string ans = "Yes";
    cin >> s;
    map<char, int> m;

    map_count(m,s);
    
    for(auto i = m.begin(); i != m.end(); ++i){
        if ( i->second != 2 ) {
            ans = "No";
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <climits>

const int MAXN = 200001;

int chk(int A, int B, int C)
{
    int ans = 0;
    
    if (A==B && B==C && C==A && A%2==0)
        return -1;
    else if (A==B && B==C && C==A && A%2==1)
        return 0;
    
    while(true)
    {
        if((A%2==1) || (B%2==1) || (C%2==1))
        {
            return ans;
        }
        ans++;
        int a = (B + C) / 2;
        int b = (A + C) / 2;
        int c = (A + B) / 2;
        A = a; B = b; C = c;
    }

    return 0;
}

int main()
{
    int A, B, C;
    std::cin >> A >> B >> C;
    int ans = chk(A, B, C);

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

Measured memory_bytes: 3644
#coding: utf-8
N,Y=map(int,input().split(" "))
for x in range(N+1):
  for y in range(N+1-x):
    z=N-x-y
    if 10000*x+5000*y+1000*z==Y:
      print(str(x)," ",str(y)," ",str(z))
      exit()
print("-1 -1 -1")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;



int main() {
    int n; cin >> n;
    string s; cin >> s; int ans = 0;
    for(int i = 0;i < s.length()-2;i++){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ans++;
    }
    cout << ans;
}


Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int MAXN = 2e5 + 5; 
const int INF = 0x3f3f3f3f;;
int height[MAXN], s[MAXN];
int n, m;
void setInit(){
	for(int i = 1; i <= n; i++){
		s[i] = i;
		height[i] = 0;
	}
}
int setFind(int x){
	if(x != s[x])  s[x] = setFind(s[x]);
	return s[x];
}
void setUnion(int x, int y){
	x = setFind(x);
	y = setFind(y);
	if(height[x] == height[y]){
		height[x]++;
		s[y] = x;
	}
	else{
		if(height[x] < height[y]) s[x] = y;
		else s[y] = s[x];
	}
}
int main(int argc, char *argv[]){
	scanf("%d %d", &n, &m);
	setInit();
	for(int i = 1; i <= m; i++){
		int x, y;
		scanf("%d %d", &x, &y);
		setUnion(x, y);
	}
	int cnt[MAXN];
	for(int i = 1; i <= n; i++) cnt[i] = setFind(s[i]);
	int ans = -INF;
	sort(cnt + 1, cnt + n + 1);
	int num = 1;
	for(int i = 2; i <= n; i++){
		if(cnt[i] == cnt[i - 1]) num++;
		else ans = max(ans, num), num = 1;
	}	
	cout << max(ans, num);
	return 0;
}

Measured memory_bytes: 6004
import java.io.*;
import java.util.*;
public class Main {
	static BufferedReader br;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}
		return ans;
	}
	static long[] splitL() throws IOException
	{
		String[] cmd=br.readLine().split(" ");
		long[] ans=new long[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Long.valueOf(cmd[i]);
		}
		return ans;
	}
	static long mod=1000000007;
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		br=new BufferedReader(new InputStreamReader(System.in));
		int n=cin();
		long[]arr=splitL();
		long ans=0;
		for(int i=0;i<=60;i++)
		{
			long zeros=0;
			long ones=0;
			for(int j=0;j<n;j++)
			{
				if((((long)1<<i)&arr[j])==0)
					zeros++;
				else
					ones++;
			}
			ans=(ans+((((long)Math.pow(2, i))%mod)*((long)(ones*zeros)%mod))%mod)%mod;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 79916
//defines e includes
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define rep1(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, a, b) for(int i=(int)a;i<(int)b;i++)
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define p_b pop_back
#define p_f pop_front
#define mp make_pair
#define MAX 100010
#define oo INT_MAX
using namespace std;
//tipagem de pares
typedef pair<int, int> ii;
typedef pair<char, char> cc;
typedef pair<int, char> ic;
typedef pair<char, int> ci;
//tipagem de vetores
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vii;
typedef vector<bool> vb;
//tipagem de outras estruturas
typedef queue<int> qi;
typedef deque<int> dqi;
//tipagem de tipos primitivos
typedef long long int ll;
typedef unsigned long long int ull;

int main()
{
	
	fastio;
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	
	int n, m;
	cin >> n >> m;
	vii p;
	rep1(i, m){
		int l, r;
		cin >> l >> r;
		p.pb(mp(l, r));
	}

	sort(p.begin(), p.end());
	int l = p[0].st, r = p[0].nd;
	rep2(i, 1, m){
		if(p[i].st <= r){
			l = max(l, p[i].st);
			r = min(r, p[i].nd);
		}else{
			cout << 0 << endl;
			return 0;
		}
	}
	cout << (r-l)+1 << endl;

	return 0;
}

Measured memory_bytes: 1400
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>
/*
多倍長整数, cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9+7;
constexpr long double eps = 1e-4;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	long double a, b;
	scanf("%Lf%Lf", &a, &b);
	printf("%.0Lf\n", floorl(a * b + eps));

	Please AC;
}


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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const ll MOD = 1000000007;
const ll LINF = 1e18;

int cnt[100005];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int n; cin>>n;
  vi a(n);
  rep(i,n){
    cin>>a[i];
  }
  ll ans=3;
  rep(i,n){
    if(a[i]>=1){
      ll mae=cnt[a[i]-1];
      if(mae<=0||cnt[a[i]]>2||(mae-cnt[a[i]])<=0){
        cout<<0<<endl;
        return 0;
      }
      ans=(ans*(mae-cnt[a[i]]));
    }else{
      if(cnt[a[i]]==0)ans*=1;
      else if(cnt[a[i]]==1)ans*=2;
      else if(cnt[a[i]]==2)ans*=1;
      else{
        cout<<0<<endl;
        return 0;
      }
    }
    ans=ans%MOD;
    
    cnt[a[i]]++;
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
typedef	long long ll;
typedef unsigned long long ull;
#define all(v) ((v).begin()),((v).end())
#define PI(n) ((double)acos(n))
#define clr0(n) (memset(n,0,sizeof n))
#define clr1(n) (memset(n,-1,sizeof n))
int dx8[8] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy8[8] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	// online submission
#endif
}
void fast()
{
	std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
}
int main()
{
	fast();
	int n;
	cin >> n;
	int ans=1, c = 0;
	for (int i = 2; i <= n; i+=2){
		int val = i;
		int m = 0;
		while (val % 2 == 0){
			val /= 2;
			m++;
		}
		if (m > c){
			c = m;
			ans = i;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()

    return

#B
def B():
    def f(m):
        if d[m] != None:
            return d[m]
        n = m
        for i in a:
            n = n-n%i
        d[m] = n
        return n
    k = I()
    a = LI()
    d = defaultdict(lambda : None)
    l,r = 0,1e19
    while r-l > 1:
        m = (r+l)//2
        if f(m) < 2:
            l = m
        else:
            r = m
    mi = r
    l,r = 0,1e19
    while r-l > 1:
        m = (r+l)//2
        if f(m) <= 2:
            l = m
        else:
            r = m
    ma = l
    if mi <= ma:
        if f(mi) != 2:
            print(-1)
        else:
            print(int(mi),int(ma))
    else:
        print(-1)
    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return


#Solve
if __name__ == "__main__":
    B()


Measured memory_bytes: 60016
#include <stdio.h>
int main(void)
{
	//aとbは整数、opは演算子を格納
	int a, b, op;

	//演算子が '?' ならば終了
	while(op != '?'){
		scanf("%d %c %d", &a, &op, &b);

		if(op == '+'){
			printf("%d\n", a + b);
		}
		else if(op == '-'){
			printf("%d\n", a - b);
		}
		else if(op == '*'){
			printf("%d\n", a * b);
		}
		else if(op == '/'){
			printf("%d\n", a / b);
		}
	}

	return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <cmath>
#include <string.h>

using namespace std;

#define MOD 1000000007

long long rec(int a) {
  if (a == 1)return 1;
  return a*rec(a - 1)%MOD;
}

int main() {
  int N, M;
  int c;
  int flag = 1;
  cin >> N >> M;
  c = abs(N - M);
  if (c == 0) {
	cout << 2 * rec(N)*rec(N) % MOD << endl;
  }
  else if (c == 1) {
	cout << rec(N)*rec(M) % MOD << endl;
  }
  else {
	cout << 0 << endl;
  }

}

Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
#include <stack>
#include <functional>
#include <queue>
using namespace std;
#define int long long

signed main()
{
    {
        if (fopen("input.txt", "r")) {
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        }
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
    }

    int n, a, b;
    cin >> n >> a >> b;
    if (a % 2 == b % 2)
        cout << (abs(a - b) / 2);
    else {
        int a1 = a, b1 = b;
        int k = min(a1, b1);
        a1 -= k;
        b1 -= k;
        if (a1 == 0)
            ++a1;
        if (b1 == 0)
            ++b1;
        int ans = k + abs(a1 - b1) / 2;
        int a2 = a, b2 = b;
        k = min(n - a2 + 1, n - b2 + 1);
        a1 += k;
        b1 += k;
        if (a1 > n)
            --a1;
        if (b1 > n)
            --b1;
        ans = min(ans, k + abs(a2 - b2) / 2);
        cout << ans;
    }
    return 0;
}

Measured memory_bytes: 256
// ABC134-E
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define e_b emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    multiset<int> retu;
    int n;
    cin>>n;
    rep(i,n){
        int a;
        cin>>a;
        auto itr=retu.lower_bound(a);
        if(itr!=retu.begin()) retu.erase(--itr);
        retu.insert(a);
    }
    cout<<retu.size()<<endl;
    return 0;
}

Measured memory_bytes: 8184
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
using namespace std;

int main()
{
    int n, y;
    int judge = 0, i, j, k;
    
    cin >> n >> y;

    i = n;
    do {
        
        j = 0;
        do {
            
            k = n - (i + j);
            
            if(((10 * i) + (5 * j) + k) * 1000 == y) {
                judge = 1;
            }
            
            if(judge == 0) {
                j++;
            }
            
        } while((j <= (n - i)) && (judge == 0));
        
        if(judge == 0) {
            i--;
        }
        
    } while((i >= 0) && (judge == 0));
    
    
    if(judge == 1) {
        cout << i << ' '<< j << ' ' << k << endl;
    } else {
        cout << "-1 -1 -1\n";
    }
    return 0;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var sb = new StringBuilder();
            while(true)
            {
                string input1 = Console.ReadLine();
                if(input1 == null)
                {
                    break;
                }
                sb.AppendLine(input1);
            }
            string input = sb.ToString();
            char[] chararray = input.ToCharArray();
            char[] komoji = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
            char[] omoji = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
            int[] count = new int[26];
            for (int i1 = 0; i1 < 26; i1++)
            {
                count[i1] = 0;
            }
            int lennum = input.Length;
            for (int i2 = 0; i2 < lennum; i2++)
            {
                for (int i3 = 0; i3 < 26; i3++)
                {
                    if (chararray[i2] == komoji[i3])
                    {
                        count[i3] = count[i3] + 1;
                    }
                    else if (chararray[i2] == omoji[i3])
                    {
                        count[i3] = count[i3] + 1;
                    }
                }
            }
            for (int i4 = 0; i4 < 26; i4++)
            {
                Console.WriteLine($"{komoji[i4]} : {count[i4]}");
            }
        }
    }
}



Measured memory_bytes: 15884
fun main(args: Array<String>) {
    val Q = readLine()!!.toInt()
    var query = Array(Q, {arrayOf(0, 0)})
    var vmax = 0
    for (i in 0..Q-1) {
        var (low, high) = readLine()!!.split(" ").map{it.toInt()}
        if (high>vmax) vmax = high
        query[i][0] = low
        query[i][1] = high
    }
    // generate prime numbers
    var ref = Array(vmax+1, {true})
    ref[0] = false
    ref[1] = false
    for (i in 2..vmax/2) {
        if (ref[i]==false) continue
        for (j in 2..(vmax)/i) {
            ref[i*j] = false
        }
    }
    // check
    var ans = Array(vmax+1, {0})
    for (i in 1..vmax) {
        if (ref[i]&&ref[(i+1)/2]) ans[i] = ans[i-1]+1
        else ans[i] = ans[i-1]
    }
    query.forEach {
        println(ans[it[1]]-ans[it[0]-1])
    }
}


Measured memory_bytes: 75800
#include <bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MAX 2000005
#define MOD 1000000007
#define MOD2 998244353
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define vi vector<ll>
#define vp vector<pii>
#define all(v) v.begin(),v.end()
#define sz(x) (ll)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
#define trace(x) cerr<<#x<<": "<<x<<'\n';
typedef long long ll;
using namespace std;
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

ll mexp(ll a, ll b){
    ll ans=1;
    a%=MOD;
    while(b){
        if(b&1) ans=ans*a%MOD;
        b>>=1;
        a=a*a%MOD;
    }
    return ans;
}

int main(){
    IOS
    string s;
    cin>>s;
    int n=sz(s);
    ll ans=0;
    FOR(i,0,(1<<(n-1))){
        ll x=s[0]-'0';
        FOR(j,0,n-1){
            if(i&(1<<j)){
                ans+=x;
                x=s[j+1]-'0';
            }
            else{
                x=10*x+s[j+1]-'0';
            }
        }
        ans+=x;
    }
    cout<<ans;


    cerr<<"Time: "<<1.0/CLOCKS_PER_SEC<<" ms"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main () {
	int n, k;
	scanf("%d %d", &n, &k);
	long long int angka[n];

	for (int i = 0 ; i < n ; i++) {
		scanf("%lld", &angka[i]);
	}
	for(int i = 0 ; i < n-k ; i++) {
		if (angka[i] < angka[k+i]) {
			puts("Yes");
		} else {
			puts("No");
		}		
	}
	return 0;
}

Measured memory_bytes: 3180
n,m,c = map(int, input().split())
b = list(map(int, input().split()))
total = 0
ans = 0
for i in range(n):
    total = 0
    a = list(map(int, input().split()))
    combined = [x * y for (x, y) in zip(a, b)]
    if int(sum(combined)) + c > 0:
        ans+=1
print(ans)

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

int main() {
  int A,B;
  cin >> A >> B;
     
  if ( A + B == 3){
    cout << 3 << endl;
  }else if ( A + B == 4 ){
    cout << 2 << endl;
  }else if ( A + B == 5 ){
    cout << 1 << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

ll gcd(ll a, ll b) {
	return (b == 0 ? a : gcd(b, a % b));
}

ll a, b, c, ans;
int main() {
	cin >> a >> b;
	c = gcd(a, b);
	ll cc = c;
	for (int i = 2; i <= sqrt(c); i++) {
		if (cc % i == 0) {
			ans++;
			while (cc % i == 0)cc /= i;
		}
	}
	if (cc != 1)ans++;
	cout << ans + 1 << endl;
}

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

int main() {
  int n;
  cin >> n;
  int tmp = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a != i+1) {
      tmp++;
    }
  }
  if (tmp > 2) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
}

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

int main(){
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;
    if(N < K){
        cout << N*X << endl;
    } else {
        cout << K*X + (N - K)*Y << endl;
    }
    return 0;
}


Measured memory_bytes: 256
def sieve_of_eratosthenes(n):
    pl = [i for i in range(2, n + 1)] 
    i=0
    p = pl[0]
    while p**2<=n:
        pl = [pl[j] for j in range(len(pl)) if pl[j]%p!=0 or j<=i]
        i+=1
        p=pl[i]
    return pl

pl=sieve_of_eratosthenes(55555)

N=int(input())

i=0
ans = []
while len(ans)<N:
    if pl[i]%5==1:
        ans.append(pl[i])
    i+=1

print(*ans)

Measured memory_bytes: 5528
#include <iostream>
#include <string>
#include <bitset>
   
class Baseball{
    u_int score, out_count;
    std::bitset<4> runners; 
public:
    Baseball() : score(), out_count(){} //initializer list
    ~Baseball() = default;
    void hit();
    void homerun();
    void out() {++out_count;}
    u_int getScore() {return score;}
    u_int getOutcount() {return out_count;}
};
  
void Baseball::hit(){
    runners <<= 1; //shift
    runners.set(0); //set runner
    if(runners.test(3)){
        ++score;
        runners.reset(3);
    }
}
  
void Baseball::homerun(){
    score += runners.count() + 1;
    runners.reset();
}
  
int main(){
    u_int inning;
    std::cin >> inning;
    for(u_int i = 0; i < inning; ++i){
        Baseball game;
        while(game.getOutcount() != 3){
            std::string event;
            std::cin >> event;
            if(event == "HIT"){
                game.hit();
            }
            else if(event == "HOMERUN"){
                game.homerun();
            }
            else if(event == "OUT"){
                game.out();
            }
        }
        std::cout << game.getScore() << std::endl;
    }
    return 0;
}

Measured memory_bytes: 2992
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

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

	int total = 700;
	for (int i = 0; i < S.length(); i++) {
		if (S[i] == 'o') {
			total += 100;
		}
	}

	cout << total << endl;

}





Measured memory_bytes: 3604
n,k = map(int,input().split())
k = min(k,n-1)
mod = 10**9 + 7
ans = 1
z0 = 1
z1 = 1
def inv(x):
  y = 1
  while x != 1:
    y *= mod // x + 1
    y %= mod
    x -= mod % x
  return y
for i in range(k):
  z0 *= n-i
  z0 %= mod
  z0 *= inv(i+1)
  z0 %= mod
  z1 *= n-1-i
  z1 %= mod
  z1 *= inv(i+1)
  z1 %= mod
  ans += z0 * z1
  #print(z0,z1,z0*z1,ans)
  ans %= mod
print(ans)

Measured memory_bytes: 3188
//#define _USE_MATH_DEFINES
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }
//inline int safe_mul(const int x, const int y) __attribute__ ((warn_unused_result));

int main()
{
//    freopen("in.txt","r", stdin);
//    freopen("out.txt", "w", stdout);
//    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;
    sort(begin(s), end(s));
    if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3])
        cout << "Yes\n";
    else
        cout << "No\n";
}


Measured memory_bytes: 256
function gcd(a, b){
    if(b != 0)
        return gcd(b, a%b);
    else
        return a;
}

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

function Main(arg) {
 
    var A = arg.split(" ")[0]-0;
    var B = arg.split(" ")[1]-0;

    var ans = lcm(A, B);
         
    console.log(ans);

    return;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
def main():
    N = int(input())
    if N % 2 != 0:
        print(0)
        return
    i = 1
    f2 = 0
    while (2 ** i) <= N:
        f2 += (N // (2 ** i))
        i += 1
    i = 1
    f5 = 0
    while (5 ** i) * 2 <= N:
        f5 += (N // ((5 ** i) * 2))
        i += 1
    print(min(f2, f5))


main()


Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
using namespace std;
int main (int argc, char const* argv[]) {
  int price, sum_price=0, num, sum_num=0, count=0;
  while (EOF != scanf("%d,%d",&price,&num)) {
    sum_num += num;
    sum_price += price * num;
    count++;
  }
  double avg = (double)sum_num / count;
  cout<<sum_price<<endl;
  for (int i = 0;; i += 1) {
    if (i > avg) {
      cout<<i<<endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b){if(a < b){ a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b){if(a > b){ a = b; return 1;} return 0;}

const int INF = 100000; 

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

    char a1 = a[0] - 'a' + 'A';
    char b1 = b[0] - 'a' + 'A';
    char c1 = c[0] - 'a' + 'A';


    cout << a1 << b1 << c1 << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fprint(v) for(auto x : v) cout << x << ' ';
using namespace std;
const int N = 2e5 + 2;
const int M = 1e9 + 7;
int grid[3][3];
int vis[3][3];
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++) cin >> grid[i][j];
    }
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(vis[j][k] == 0 && grid[j][k] == x) vis[j][k] = 1; 
            }
        }
    }
    for(int j = 0; j < 3; j++){
        bool ok = true;
        for(int k = 0; k < 3; k++){
            ok &= (vis[j][k] == 1);
        }
        if(ok){
            return cout << "Yes", 0;
        }
    }
    for(int j = 0; j < 3; j++){
        bool ok = true;
        for(int k = 0; k < 3; k++){
            ok &= (vis[k][j] == 1);
        }
        if(ok){
            return cout << "Yes", 0;
        }
    }
    bool ok = true;
    for(int j = 0; j < 3; j++){
        ok &= (vis[j][j] == 1);
    }
    if(ok){
        return cout << "Yes", 0;
    }
    ok = true;
    for(int j = 0; j < 3; j++){
        ok &= (vis[j][2 - j] == 1);
    }
    if(ok){
        return cout << "Yes", 0;
    }
    cout << "No";
	return 0;
}


Measured memory_bytes: 384
X, N = map(int, input().split())
P=list(map(int, input().split()))
A=[]
A.append(X)
if N==0:
   print(X)
else:
   for i in range(N+1):
      A.append(X+(1+(i//2))*(-1)**(i+1))
   for i in range(N+1):
      if A[i] not in P:
         ans=A[i]
         print(ans)
         break

Measured memory_bytes: 9188
def main():
    def gcd(a,b):
        if b>a:
            a,b=b,a
        while b:
            a,b=b, a%b
        return a
    a,b=list(map(int,input().split()))
    print(a*b//gcd(a,b))
    


            

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
using namespace std;
int main()
{
        int n,m,aux = 0,total_votes = 0;
        cin >> n >> m;
        vector<int> a(n);
        for (int i = 0; i < n; i++)
        {   
                cin >> a[i];
                total_votes += a[i];

        }   
        for (int i = 0; i < n; i++)
        {   
                if (a[i] >= ((double)total_votes/(4*m)))
                        aux++;
        }   
        if (aux >= m)
                cout << "Yes" << endl;
        else 
                cout << "No" << endl;
        return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int a1,b1,a2,b2,k,s=0;
cin>>a1>>b1>>a2>>b2>>k;
if(b1>b2)s=(a2-1-a1)*60+60+b2-b1;
else s=(a2-a1)*60+b2-b1;
cout<<s-k;
return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#pragma region Macros
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
#define LAST(X) X[X.size()-1]
#define MOD 1000000007
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
inline bool BETWEEN(int x, int min,int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}

using namespace std;
#pragma endregion
signed main() {
	int a[3];
	rep(i, 3)
		cin >> a[i];
	if ((a[0] == a[1]) && (a[1] == a[2]))
		cout << 1;
	else if ((a[0] != a[1] && a[1] != a[2]) && (a[2] != a[0]))
		cout << 3;
	else
		cout << 2;	
}

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

using namespace std;

typedef long long ll;
//const ll MOD = 1000000007;
ll Mat[10001][10001];
ll Flag[10001];
ll t = 2;

void dfs(ll a) {
  for (int j = 0; j < 10001; j++) {
    if (Mat[a][j] == 1 && Flag[j] == 0) {
      Flag[j] = t;
      t++;
      dfs(j);
    }
  }
}

int main() {
  ll N;
  cin>>N;
  map<ll, ll> con;
  vector<ll> c(N);
  vector<pair<ll,ll>> pairs(N),pairs2(N);
  for (ll i = 0; i < N; i++) {
    con[i] = 0;
  }
  for (ll i = 0; i < N - 1; i++) {
    ll a,b;
    cin>>a>>b;
    a--; b--;
    con[a]++;
    con[b]++;
    pairs2[i].first = a;
    pairs2[i].second = b;
    Mat[a][b] = Mat[b][a] = 1;
  }
  for (ll i = 0; i < N; i++) cin>>c[i];
  sort(c.rbegin(),c.rend());
  for (ll i = 0; i < N; i++) {
    pairs[i].first = con[i];
    pairs[i].second = i;
  }
  sort(pairs.rbegin(),pairs.rend());
  vector<ll> ans(N,-1);
  ans[pairs[0].second] = c[0];
  Flag[pairs[0].second] = 1;
  dfs(pairs[0].second);
  for (ll i = 0; i < N; i++) {
    ans[pairs[i].second] = c[Flag[pairs[i].second]-1];
  }
  ll sum = 0;
  for (ll i = 0; i < N - 1; i++) {
    ll res1,res2;
    res1 = ans[pairs2[i].first];
    res2 = ans[pairs2[i].second];
    sum += min(res1,res2);
  }
  cout<<sum<<endl;
  for (int i = 0; i < N; i++) {
    cout<<ans[i]<<" ";
  }
  cout<<endl;
  return 0;
}

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a>c)swap(a,c);
    if(a>b)swap(a,b);
    if(c<b)swap(c,b);
    
    cout <<a<<" "<<b<<" "<<c<<endl;

}


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

int main() {
  int N;
  cin >> N;
  double sum = 0;
  rep(i,N){
    double temp;
    cin >> temp;
    sum += 1/temp;
  }
  
  cout << fixed << setprecision(10);
  cout << 1/sum << endl;
  
  
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
	int i, n;
	i = 1;
	n = 1;

	while (n!=0)
	{
		scanf("%d", &n);

		if (n == 0)
		{
			
		}

		else
		{
			printf("Case %d: %d\n", i , n);
			i++;
		}

	}

	return 0;
}


Measured memory_bytes: 2044
#include <stdio.h>

int main(void) {
    char test[6];

    scanf("%s", test);

    if ( test[2] == test[3]) {
        if (test[4] == test[5]) {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct UnionFind {
    vector< int > data;
    
    UnionFind(int sz) {
        data.assign(sz, -1);
    }
    
    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y) return (false);
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }
    
    int find(int k) {
        if(data[k] < 0) return (k);
        return (data[k] = find(data[k]));
    }
    
    int size(int k) {
        return (-data[find(k)]);
    }
};

int main(void) {
    int N, M, K;
    cin >> N >> M >> K;
    UnionFind uf(N);
    vector<int> friends(N), block(N);
    while(M--) {
        int A, B;
        cin >> A >> B;
        --A; --B;
        uf.unite(A, B);
        friends[A]++;
        friends[B]++;
    }
    while(K--) {
        int C, D;
        cin >> C >> D;
        --C; --D;
        if(uf.find(C) == uf.find(D)) {
            block[C]++;
            block[D]++;
        }
    }

    for(int i=0; i<N; i++) {
        cout << uf.size(i) - 1 - friends[i] - block[i] << ' ';
    }
    return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define all(v) v.begin(),v.end()
#define PI acos(-1)
#define EPS 1e-15

int main() {
	int a,x ;
	cin >> a >> x;
	cout << 2*x - a << endl;
	return 0;
}





Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int n[10000],x[10000],a[10000];
  int i,j,k;
  int cnt=0;
  do{
    scanf("%d %d",&n[cnt],&x[cnt]);
    if(n[cnt]==0&&x[cnt]==0){
      break;
    }
    a[cnt]=0;
    for(i=1;i<=n[cnt]-2;i++){
      for(j=i+1;j<=n[cnt]-1;j++){
        for(k=j+1;k<=n[cnt];k++){
          if(k+j+i==x[cnt]){
            a[cnt]++;
          }
        }
      }
    }
    cnt++;
  }while(1);
  for(i=0;i<cnt;i++){
    printf("%d\n",a[i]);
  }
  return 0;
}

Measured memory_bytes: 616
# coding: utf-8
import numpy as np
 
n = int(input())
numlist = list(map(int, input().split()))
ans = 1;

if 0 in numlist:
    ans = 0
else:
    for i in numlist:
        ans *= i
        if ans > 10**18:
            ans = -1
            break
 
print(ans)

Measured memory_bytes: 39788
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll D, G;
    cin >> D >> G;
    vector<ll> p(D);
    vector<ll> c(D);
    rep(i, D) {
        cin >> p[i] >> c[i];
    }
    ll mi = MOD;
    for(ll i = 0; i < (ll)pow(2,D); i++) {
        ll score = 0;
        ll cnt = 0;
        for(ll j = 0; j < D; j++) {
            if (i >> j & 1 == 1) {
                score += p[j] * 100 * (j+1);
                score += c[j];
                cnt += p[j];
            }
        }
        if (score >= G) {
            mi = min(mi, cnt);
        } else {
            for(ll j = D-1; j >= 0; j--) {
                if ((i >> j & 1) == 0) {
                    for(ll k = 1; k < p[j]; k++) {
                        score += (j+1) * 100;
                        cnt++;
                        if (score >= G) {
                            break;
                        }
                    }
                    break;
                }
            }
            if (score >= G) {
                mi = min(mi, cnt);
            }
        }
    }
    print(mi);
    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string;

void main()
{
    auto abcd = readln.split.to!(int[]);
    auto a = abcd[0];
    auto b = abcd[1];
    auto c = abcd[2];
    auto d = abcd[3];

    if (b <= c || d <= a) {
        writeln(0);
    } else if (a <= c) {
        writeln(b < d ? b - c : d - c);
    } else {
        writeln(b < d ? b - a : d - a);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    int N, M;
    cin >> N >> M;
    vector<iint> A(M+1);
    for (int i = 0; i < M; i++) {
        cin >> A[i].second >> A[i].first;
        A[i].second--;
        A[i].first--;
    }
    A[M].first = N+1;
    A[M].second = N;
    sort(ALL(A));
    vector<int> c(N, 0);
    for (int j = A[0].first; j <= A[1].first; j++) {
        c[j] = 1;
    }
    for (int i = 1; i < M; i++) {
        if(c[A[i].first] == c[A[i].second]){
            c[A[i].first] = c[A[i].first] + 1;
            for (int j = A[i].first + 1; j <= min(A[i+1].first, N-1); j++) {
                c[j] = c[j-1];
            }
        }
        else{
            for (int j = A[i].first + 1; j <= min(A[i+1].first, N-1); j++) {
                c[j] = c[j-1];
            }
        }
    }
    printf("%d\n", c[N-1]);

}

Measured memory_bytes: 4604
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

long gcd(long m,long n){
    if(m < n){
        return gcd(n,m);
    }
    return n == 0 ? m : gcd(n,m % n);
}

vector<long> primes;

void setupPrimes(){
    const long upper = 1000000;
    long p[upper+1];
    for(long i=0;i<upper;i+=2){
        p[i] = 0;
        p[i+1] = i+1;
    }
    p[1] = 0;
    p[2] = 2;
    primes.push_back(2);
    for(long i=3;i<upper;i+=2){
        if(p[i]==0){
            continue;
        }
        primes.push_back(i);
        for(long j=3*i;j < upper;j+=(2*i)){
            p[j] = 0;
        }
    }
}

inline long sp(long n){
    return n * n;
}

int numberOfPrimes(long n){
    int num = 0;
    for(long p : primes){
        if(n==1){
            return num;
        }else if(sp(p) > n){
            return num+1;
        }
        if(n % p == 0){
            num++;
            for(;n % p==0;n /= p);
        }
    }
}

int numberOfDisjointDivisors(long a,long b){
    long g = gcd(a,b);
    long g0 = g;
    if(g==1){
        return 1;
    }
    int numberOfPrimes = 0;
    for(long p : primes){
        if(g==1 || sp(p) > g){
            break;
        }
        if(g % p == 0){
            numberOfPrimes++;
            for(;g % p==0;g /= p);
        }
    }
    if(g!=1){
        numberOfPrimes++;
    }
    return numberOfPrimes+1;
}

int main(){
    setupPrimes(); 
    long a,b;
    cin >> a;
    cin >> b;
    int ans = numberOfDisjointDivisors(a,b);
    ans = numberOfPrimes(gcd(a,b))+1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int int64_t
#define ALL(a) (a).begin(),(a).end()
signed main(){
  int r,D,X;
  cin>>r>>D>>X;
  rep(i,0,10){
    X=X*r-D;
    cout<<X<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,p;
    while(cin>>n){
         if(n%1000==0){
        cout<<0<<endl;
    }
    else
    {
        p=n-(n/1000)*1000;
        cout<<(1000-p);
    }
    }
    return 0;
}



Measured memory_bytes: 3620
def exclude(cs, s):
    return [x for i, x in enumerate(cs) if i not in s]


def createLine(line, length):
    if length <= 0 or length > len(line):
        return []
    result = []
    _createLine(line, length, [], result)
    # print(result)
    return result


def _createLine(line, length, progress, result):
    if length == 0:
        result.append(progress)
        return

    for i in range(len(line)):
        _createLine(exclude(line, [i]), length - 1,
                    progress + [line[i]], result)


N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
line = [i for i in range(1, N + 1)]
string = createLine(line, N)
print(abs(string.index(Q)-string.index(P)))


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

using namespace std;
typedef long long ll;

ll MOD = 1e9+7;

class mint{
    ll n;
public:
    mint(ll m = 0){
        n = ((m % MOD) + MOD) % MOD;
    }
    mint operator-() const {
        return mint(-n);
    }
    mint& operator+=(const mint& m){
        n += m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator-=(const mint& m){
        n += MOD - m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& m){
        n *= m.n;
        n %= MOD;
        return *this;
    }
    mint operator+(const mint& m) const{
        mint res(*this);
        res += m;
        return res;
    }
    mint operator-(const mint& m) const{
        mint res(*this);
        res -= m;
        return res;
    }
    mint operator*(const mint& m) const{
        mint res(*this);
        res *= m;
        return res;
    }
    mint pow(ll t) const{
        if(t == 0) return mint(1);
        mint m = pow(t>>1);
        m *= m;
        if(t & 1 == 1) m *= *this;
        return m;
    }
    // for prime modulo
    mint inv() const{
        return pow(MOD-2);
    }
    mint& operator/=(const mint& m){
        (*this) *= m.inv();
        n %= MOD;
        return *this;
    }
    mint operator/(const mint& m) const{
        mint res(*this);
        res /= m;
        return res;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.n;
        return os;
    }
};

ll c[26];
ll N;
string S;

int main(){
    cin >> N;
    cin >> S;
    for(auto &e : S) c[e-'a']++;
    mint ans(1);
    for(int i=0;i<26;i++) ans *= mint(c[i]+1);
    cout << ans - mint(1) << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

void solve(){
	int n,x,ans = 1,di = 0;
	cin >> n >> x;
	vector<int> li(n);
	for(int i=0;i<n;++i){
		cin >> li[i];
		di+=li[i];
		if(di <= x) ans++;
	}
	cout << ans << '\n';
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	//cin >> t;
	while(t--){ 
		solve();
	}
	return 0;
}

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

bool ispossible(ll n, ll a, ll b, ll turns, vector <ll> &h)
{
    ll offset = b * turns;

    for(ll i = 0; i < n; i++)
    {   
        ll x = h[i];
        x -= offset;

        if(x > 0)
        {
            ll cturns = 1 + ((x - 1) / (a - b));

            if(cturns > turns)
                return false;

            turns -= cturns;    
        }
    }

    return true;
}

ll solve(ll n, ll a, ll b, vector <ll> &h)
{
    ll lo = 1, hi = 1e9;

    while(lo < hi)
    {
        ll mid = (lo + hi) / 2;
        bool possible = ispossible(n, a, b, mid, h);

        if(possible)
            hi = mid;
        else
            lo = mid + 1;    
    }

    return lo;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n, a, b;
    cin >> n >> a >> b;
    vector <ll> h(n);

    for(ll i = 0; i < n; i++)
        cin >> h[i];

    cout << solve(n, a, b, h) <<"\n";  
    // cout << ispossible(n, a, b, 3, h) <<"\n";   
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;
// scanf
#pragma warning(disable: 4996)
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)
// double 平方根
#define _sqrt(x) sqrt(x)
// double 引数 x 以上で最小の整数値
#define _ceil(x) ceil(x)

int main()
{
#if 0
	string s;
	string result;

	for (uint32_t i = 0; i < 3; i++) {
		cin >> s;
		result += s[i];
	}
	printf("%s\n", result.c_str());
#else
	char s[9];
	for (uint32_t i = 0; i < 9; i++) {
		cin >> s[i];
	}
	char(*p)[4] = (char(*)[4])&s[0];
	string result;
	for (uint32_t i = 0; i < 3; i++) {
		result += p[i][0];
	}
	printf("%s\n", result.c_str());
#endif

	return 0;
	//	std::cout << "Hello World!\n"; 
}


Measured memory_bytes: 256