akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
	int N, M, Q;
	std::cin >> N >> M >> Q;

	std::vector<std::vector<int>> rails(N);

	for (int i = 0; i < M; ++i) {
		int l, r;
		std::cin >> l >> r;
		--l, --r;

		rails.reserve(M);
		rails[l].push_back(r);
	}

	for (auto&& vec : rails)
		std::sort(vec.begin(), vec.end());

	for (int i = 0; i < Q; ++i) {
		int p, q;
		std::cin >> p >> q;
		--p, --q;

		int ans = 0;
		for (int j = p; j <= q; ++j)
			ans += static_cast<int>(std::upper_bound(rails[j].begin(), rails[j].end(), q) - rails[j].begin());

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

Measured memory_bytes: 2176
N, M = map(int, input().split())
E = [[] for _ in range(N)]
for m in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    E[a].append(b)
    E[b].append(a)

check = [False] * N
check[0] = True
def dfs(v):
    if sum(check) == N:
        return 1
    ans = 0
    for u in E[v]:
        if check[u]:
            continue
        check[u] = True
        ans += dfs(u)
        check[u] = False
    return ans
print(dfs(0))


Measured memory_bytes: 3064
# AOJ 0065 Trading
# Python3 2018.6.15 bal4u

cnt = [0]*1001
f = [0]*1001

while True:
	try: c, d = list(map(int, input().split(',')))
	except: break
	f[c] = 1
	cnt[c] += 1

	
while True:
	try: c, d = list(map(int, input().split(',')))
	except: break
	if f[c] == 1: f[c] = 2
	cnt[c] += 1

for c in range(1, 1001):
	if f[c] == 2: print(c, cnt[c])


Measured memory_bytes: 5612
int main(int argc, const char * argv[]) {
    // insert code here...
    int N, X, T;
    int num=0;
    //printf("数字を入力してください。\n");
    scanf("%d%d%d", &N, &X, &T);
    while(1){
        N=N-X;
        //printf("N = %d\n", N);
        num+=T;
        if(N<=0){
            break;
        }
    }
    printf("%d\n", num);
    return 0;
}


Measured memory_bytes: 2108
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize, a: [usize; n], b: [usize; n], c: [usize; n - 1]);

    let mut score = 0;
    let mut pre_b = a[0];
    for v in a {
        score += b[v - 1];
        if pre_b + 1 == v - 1 {
            score += c[pre_b];
        }
        pre_b = v - 1;
    }

    println!("{}", score);
}


Measured memory_bytes: 2136
void main(){
	int a, b, c;
	readf("%d %d %d\n", &a, &b, &c);
	writeln( (b-a==c-b)?"YES":"NO" );
}
     
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;      
// 1要素のみの入力
T inelm(T= int)(){
	return to!(T)( readln().chomp() );
}
     
// 1行に同一型の複数入力
T[] inln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split())ln ~= elm.to!T();
	return ln;
}


Measured memory_bytes: 2740
import java.util.*;
import java.awt.*;

class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = Integer.parseInt(sc.next());
        int[] p = new int[n];
        int ans=0;
        for(int i = 0; i < n; i++){
            p[i] = Integer.parseInt(sc.next());
        }
        for(int i = 1; i < n-1; i++){
            if(p[i-1] < p[i] && p[i] < p[i+1]){
                //System.out.println(p[i]);
                ans++;
            }else if(p[i+1] < p[i] && p[i] < p[i-1]){
                //System.out.println(p[i]);
                ans++;
            }
        }
        System.out.println(ans);
    }
}


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


int main()
{	
	int n,a[2]={3600,60};
	cin>>n;
	for(int i=0;i<2;i++)
	{
		cout<<n/a[i]<<":";
		n%=a[i];
	}
	cout<<n<<endl;
	return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

    int n;
    cin>>n;
    ll arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    ll ans=0;
    ll a=arr[0];
    for(int i=0;i<n;i++)
    {
        ans+=(max(0LL,a-arr[i]));
        a=max(a,arr[i]);
    }
    cout<<ans<<endl;



    return 0;
}

Measured memory_bytes: 5184
int main(void) {
	char i[4], S;
	scanf("%s", &i);
	if (i[0]==i[1]&&i[1]==i[2]&&i[2]=='R') {
		printf("3");
	}
	else if (i[0]==i[1]&&i[1]=='R') {
		printf("2");
	}
	else if (i[1] == i[2]&&i[2] == 'R') {
		printf("2");
	}
	else if (i[0] == i[2]&&i[2] == 'R') {
		printf("1");
	}
	else if (i[1] == 'R') {
		printf("1");
	}
	else if (i[2] == 'R') {
		printf("1");
	}
	else if (i[0] == 'R') {
		printf("1");
	}
	else {
		printf("0");
	}
	return 0;
}

Measured memory_bytes: 1608
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<ctime>
#include<vector>
#include<queue>
#include<map>
#include<deque>
#include<stack>
#include<algorithm>
#define N 100005
using namespace std;
const int INF=0x7fffffff;
const double Pi=acos(-1);
char Ch[N];
int main()
{
	int i,n;
	scanf("%s",Ch+1);
	n=strlen(Ch+1);
	for(i=1;i<=n;i++)//Ö»¿¼ÂÇÕâÁ½ÖÖ×î¼òµ¥Çé¿ö 
	{
		if(Ch[i]==Ch[i+1]&&i+1<=n)
		{
			printf("%d %d\n",i,i+1);
			return 0;
		}
		if(Ch[i]==Ch[i+2]&&i+2<=n)
		{
			printf("%d %d\n",i,i+2);
			return 0;
		}
	}
	printf("-1 -1\n");
	return 0;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  in(int, n);
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  int ans = 0;
  rep(i, n - 2) {
    vector<int> v(p.begin() + i, p.begin() + i + 3);
    sort(all(v));
    if (v[1] == p[i + 1]) ++ans;
  }
  out(ans);
}


Measured memory_bytes: 3628
fun main(args: Array<String>) {
    val (a, b) = getLongs()
    if (a == 1L || b == 1L) {
        println(1)
    } else {
        println((a * b + 1) / 2)
    }
}

fun getInt() = readLine()!!.toInt()
fun getInts() = readLine()!!.split(" ").map { it.toInt() }
fun getLong() = readLine()!!.toLong()
fun getLongs() = readLine()!!.split(" ").map { it.toLong() }

Measured memory_bytes: 37740
#include "bits/stdc++.h"
#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define ffor(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) ffor(i,0,n)
#define All(obj) (obj).begin(),(obj).end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define c(a) cout<<a<<"\n";
using namespace std;


int main() {
	speed;
	int n, d;
	cin >> n >> d;
	vector<vector<int>>x(n, vector<int>(d));
	rep(i, n) {
		rep(j, d) {
			cin >> x[i][j];
		}
	}
	int ans=0;
	rep(i, n) {
		ffor(j,i+1, n) {
			int norm = 0;
			rep(k, d) {
				int diff = abs(x[i][k] - x[j][k]);
				norm += diff * diff;
			}
			bool flag = false;
			for (int k = 0; k <= norm;++k) {
				if (k*k == norm) { flag = true; }
			}
			if (flag)++ans;
		}
	}
	c(ans);
	ed;
	return 0; 
}


Measured memory_bytes: 256
def knapsack(points):
    days = len(points)

    # dp[i][j] is the max points we can get at day i and choosing activity j
    dp = [[0] * 3 for _ in range(days)]
    dp[0] = points[0]
    for i in range(1, days):
        for j in range(3):
            dp[i][j] = points[i][j] + max([dp[i-1][k] for k in range(3) if k != j])
    return max(dp[-1])


if __name__ == "__main__":
    N = int(input())
    points = []
    for _ in range(N):
        points.append([int(x) for x in input().split()])

    print(knapsack(points))


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


            int32_t main()
            {
         
         
                #ifndef ONLINE_JUDGE
                freopen("input.txt", "r", stdin);
                freopen("output.txt", "w", stdout);
                #endif
         
                ios_base::sync_with_stdio(false);
                cin.tie(NULL);
         

                int m,n,i,sum=0;
                cin>>m>>n;

                int a[n];

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


                for(i=0;i<n;i++)
                    sum=sum+a[i];

                if(sum>m)
                    cout<<"-1"<<endl;

                else if(sum==m)
                    cout<<"0"<<endl;

                else if(sum<m)
                    cout<<m-sum<<endl;





            }

Measured memory_bytes: 3772
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
x=i2()
z=[]
for i in range(n):
 z.append([x[i],i])
y=sorted(z)
s1=y[n//2-1]
s2=y[n//2]
yy=[0 for i in range(n)]
for i in range(n):
 if i<=n//2-1:
   yy[y[i][1]]=s2
 else:
   yy[y[i][1]]=s1
for i in yy:
 print(i[0])

Measured memory_bytes: 125140
#include <stdio.h>

int main(void) {
    int nen,tuki,hi;
    while(scanf("%d %d %d",&nen,&tuki,&hi)!=EOF){
        if(nen<1868){
            printf("pre-meiji\n");
        }else if(nen==1868&&tuki<=9&&hi<8){
            printf("pre-meiji\n");
        }else if(nen<1912||(nen==1912&&tuki<=7&&hi<=29)){
            printf("meiji %d %d %d\n",nen-1867,tuki,hi);
        }else if(nen<1926||(nen==1926&&tuki<=12&&hi<=24)){
            printf("taisho %d %d %d\n",nen-1911,tuki,hi);
        }else if(nen<1989||(nen==1989&&tuki<=1&&hi<=7)){
            printf("showa %d %d %d\n",nen-1925,tuki,hi);
        }else{
            printf("heisei %d %d %d\n",nen-1988,tuki,hi);
        }
    }
    
    return 0;
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; -i)
#define INF (1 << 30)

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

int main() {
	char w[100];
	bool flag = 0;
	scanf("%s", w);
	if(strlen(w) % 2) printf("No\n");
	else {
		sort(w, w + strlen(w));
		for(int i = 0; i < strlen(w); i += 2) {
			if(w[i] != w[i + 1]) {
				flag = 0;
				break;
			}
			else flag = 1;
		}
		if(flag) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s, t;
	cin >> s >> t;
	string un = "UNRESTORABLE";
	if (s.size() < t.size())cout << un << endl;
	else {
		string ans = string('z', 100);
		REP(i, s.size() - t.size()+1) {
			int f = 1;
			string tmp = s;
			REP(j, t.size()) {
				if (s[i + j] == '?')tmp[i + j] = t[j];
				else if (s[i + j] != t[j])f = 0;
			}
			if (f) {
				REP(j, tmp.size()) {
					if (tmp[j] == '?')tmp[j] = 'a';
				}
				ans = min(ans, tmp);
			}
		}
		if (ans == string('z', 100))cout << un << endl;
		else cout << ans << endl;
	}
	
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
string magnitude(string & x, string & y)
{
  if( x.size() > y.size() )
  	return "GREATER";
  else if( x.size() < y.size() )
    return "LESS";
  else{
    for(int i = 0; i < x.size(); i++)
      if( x[i] > y[i] )
        return "GREATER";
      else if( x[i] < y[i] )
        return "LESS";
    return "EQUAL";
  }
}
    
int main()
{
  	string a, b;
  	cin >> a >> b;
  	cout << magnitude(a,b);
	return 0;
}

Measured memory_bytes: 3024
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <fstream>

#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
using namespace std;
using ll = long long;
//constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

ll GCD(ll a, ll b) {
    if(b==0) return a;
    else return GCD(b, a%b);
}

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

class BMultiplication2 {
public:
	void solve(std::istream& in, std::ostream& out) {
	        ll mx = 1e18;
            ll n;
            in>>n;
            ll res=1;
            vector<ll> v(n);
            rep(i,n) in>>v[i];
            sort(all(v));
            rep(i,n){
                ll tmp = v[i];
                if(tmp==0){
                    out<<0<<endl;
                    return;
                }
                if(res*tmp >mx || res*tmp < res){
                    out<<-1<<endl;
                    return;
                }
                res*=tmp;
            }
            out<<res<<endl;

	}
};


int main() {
	BMultiplication2 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main() {
    int64_t N;
    cin >> N;
    vector<int64_t> A(N),B(N),C(N);
    for ( int64_t i = 0; i < N; ++i){
        cin >> A.at(i);
    }
    for ( int64_t i = 0; i < N; ++i){
        cin >> B.at(i);
    }
    for ( int64_t i = 0; i < N; ++i){
        cin >> C.at(i);
    }
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    sort(C.begin(),C.end());
    
    int64_t res = 0;
    for ( int64_t i = 0; i < N; ++i){
        int64_t b = B.at(i);
        // bより小さいAの要素数
        auto aitr = lower_bound(A.begin(),A.end(),b);
        int64_t a = aitr - A.begin();
        // bより大きいCの要素数
        auto citr = upper_bound(C.begin(),C.end(),b);
        int64_t c = C.end() - citr;
        //cout << "b " << b << " a " << a << " c " << c << endl;
        res = res + a * c;
    }
    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2560
H, W = map(int, input().split())
grid = [list(input().strip()) for _ in range(H)]

ans = [[0] * W for _ in range(H)]

if grid[0][0] == "#":
    ans[0][0] = 1

for i in range(H):
    for j in range(W):
        if i == 0 and j == 0:
            continue

        r = H*W
        d = H*W
        if j > 0 and grid[i][j] != grid[i][j-1] and grid[i][j-1] == ".":
            r = 1 + ans[i][j-1]
        elif j > 0:
            r = ans[i][j-1]

        if i > 0 and grid[i][j] != grid[i-1][j] and grid[i-1][j] == ".":
            d = 1 + ans[i-1][j]
        elif i > 0:
            d = ans[i-1][j]
        ans[i][j] = min(r, d)

print(ans[H-1][W-1])

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

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

    vector<int> L(2 * n);
    for (int i = 0; i < 2 * n; i++)
    {
        cin >> L.at(i);
    }

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

    int ans = 0;

    for (int i = 0; i < 2 * n; i += 2)
    {
        ans += min(L.at(i), L.at(i + 1));
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
    string in;
    cin >> in;
    int ret = 0;
    for (size_t i = 0; i < 4; i++)
    {
        if (in[i] == '+')
            ++ret;
        else
            --ret;
    }
    cout << ret << endl;
    return 0;
}

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

int main(){
    long long int a, b, x;
    scanf("%lld %lld %lld", &a, &b, &x);
    long long int m = b/x;
    long long int n = a/x;
    if(a%x==0){
        printf("%lld\n", m - n + 1);
    }else{
        printf("%lld\n", m - n);
    }
    
    return 0;
}

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

int main() {
    int N, L;
    cin >> N >> L;
    int res = N * (2 * L + N - 1) / 2;
    if(L + N - 1 < 0) cout << res - (L + N - 1) << endl;
    else if(L <= 0) cout << res << endl;
    else cout << res - L << endl; 
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        int count=0;
        Scanner s = new Scanner(System.in);
        String w = s.next();
        while(true){
            String t = s.next();
            if (t.equals("END_OF_TEXT")) break;
            t = t.toLowerCase();
            if (t.equalsIgnoreCase(w)) count++;
        }
        System.out.println(count);
    }
}


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

using namespace std;

using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for (auto &i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    vl x(5);
    cin >> x;
    rep(i, 5) {
        if (x[i] == 0) {
            cout << i + 1 << '\n';
            return;
        }
    }
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}


Measured memory_bytes: 3592
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n;
    int i;
    cin >> n >> i;
    cout << n - i + 1 << endl;
}

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

int main()
{
    long n;
    cin>>n;
    long a[n];
    for(long i=0;i<n;i++){
        cin>>a[i];
    }
    long ans=0;
    long min1 = a[0];
    for(long i=0;i<n;i++){
        if(a[i]<=min1){
            ans++;
            min1 = a[i];
        }
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 1792
import itertools
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

l = 0
r = 0

for i, j in enumerate(itertools.permutations(range(1,N+1)), start=1):
    if j == P and j == Q:
        l, r = i, i
    elif j == P:
        l = i
    elif j == Q:
        r = i
    else:
        pass

print(abs(l-r))

Measured memory_bytes: 3064
#include<iostream>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<utility>
#include<map>
#include<vector>

using namespace std;

int main(void)
{
  int a,b;

  cin>>a>>b;

  if(a==1)a=14;
  if(b==1)b=14;

  if(a<b)
    puts("Bob");
  else if(a>b)
    puts("Alice");
  else
    puts("Draw");
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(NULL);
#ifdef LOCAL
#define dbg(...) {cerr << "> "; ZZ(#__VA_ARGS__,__VA_ARGS__);}
template <typename Arg1> void ZZ(const char* val1, Arg1&& arg1) { cerr << val1 << ": " << arg1 << endl; }
template <typename Arg1, typename... Args> void ZZ(const char* vals, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(vals + 1, ',');
    std::cerr.write(vals, comma - vals) << ": " << arg1<<" , ";
    ZZ(comma+1, args...);
}
#else
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;

inline int lcm(int a, int b) {
	return a * b / __gcd(a, b);
}

signed main(){
    IOS;
    int n, m;
    cin >> n >> m;
    int p = 1;
    set<int> s;
    for (int i = 0; i < n; i++) {
    	int a;
    	cin >> a;
    	a /= 2;
    	s.insert(a);
    }
    for (auto i : s) {
    	p = lcm(p, i);
    	if (p > m) return cout << 0, 0;
    }
    for (auto i : s)
    {
    	if ((p / i) % 2 == 0) return cout << 0, 0;
    }
    dbg(p)
	int mm = m / p;
	cout << (mm+1)/2 << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int calc_gcd(int a, int b)
{
  if (b == 0)
    return a;
  return calc_gcd(b, a%b);
}

int main()
{
  string s;
  
  cin >> s;
/*  
  AAAA|ABCBC
  AAAA|BCABC
  AAAB|CAABC
  AABC|AAABC
  ABCA|AAABC
  BCAA|AAABC
  BCAA|AABCA
  BCAA|ABCAA
  BCAA|BCAAA
  BCABCAAAA
  BCBCAAAAA
*/    
  long int ans = 0;
  int len = s.size();
  int repeat_A = 0;
  for (int i=0;i<len;++i) {
    if (s[i] == 'A') {
      repeat_A++;
    } else if (s[i] == 'B' && s[i+1] == 'C') {
      ans += repeat_A;
      i += 1;
    } else {
      repeat_A = 0;
    }
  }
  
  cout << ans << endl;
  //cout << s << endl;

  return 0;
}


Measured memory_bytes: 640
import sys
read = sys.stdin.read

N, *A = map(int, read().split())
mod = 10 ** 9 + 7

hats = [[0] * 3 for _ in range(N + 1)]
answer = 1

for i in range(N):
    answer *= hats[i].count(A[i])
    answer %= mod
    flag = True
    for j in range(3):
        if hats[i][j] == A[i] and flag:
            hats[i + 1][j] = A[i] + 1
            flag = False
        else:
            hats[i + 1][j] = hats[i][j]

print(answer)

Measured memory_bytes: 20384
/******************************************
*    AUTHOR:         CHIRAG AGARWAL       *
*    INSTITUITION:   BITS PILANI, PILANI  *
******************************************/
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL; 
typedef long double LD;
const int MAX=1e5+5;
vector<int> adj[MAX];

int st[MAX];

void dfs(int s,int p)
{
    int cm=0;
    for(int i=0;i<adj[s].size();i++)
    {
        int u=adj[s][i];
        if(u!=p)
        {
            cm++;
            dfs(u,s);
            st[s]^=(st[u]+1);
        }
    } 
}
int main() 
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<n;i++)
    {
        int a,b;
        scanf("%d %d",&a,&b);
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    if(adj[1].size()==1)
    {
        printf("Alice\n");
        return 0;
    }
    int ans=0;
    for(int i=0;i<adj[1].size();i++)
    {
        dfs(adj[1][i],1);
        ans^=(st[adj[1][i]]+1); 
    }    
    if(!ans)
    {
        printf("Bob\n");
    }
    else
    {
        printf("Alice\n");
    }
    return 0;
}

Measured memory_bytes: 9984
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define MAX 5002

class Disjoint_Sets{
public:
	ll* parent;
	ll* size;
	Disjoint_Sets(ll n){
		parent = new ll[n];
		size = new ll[n];
		For(i,0,n) parent[i]=i;
		For(i,0,n) size[i]=1;
	}
	void merge(ll a,ll b){
		ll parent_a = find(a);
		ll parent_b = find(b);
		if(parent_a==parent_b) return;
		if(size[parent_a]<size[parent_b]){
			parent[parent_a] = parent_b;
			size[parent_b] += size[parent_a];
			size[parent_a] = 0;
		}else{
			parent[parent_b] = parent_a;
			size[parent_a] += size[parent_b];
			size[parent_b] = 0;
		}
	}
	ll find(ll a){
		if(parent[a]==a){
			return a;
		}
		parent[a]=find(parent[a]);
		return parent[a];
	}
}; 

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n,m;cin>>n>>m;
	ll p[n];For(i,0,n){
		cin>>p[i];
		p[i]--;
	}
	Disjoint_Sets d(n);
	For(i,0,m){
		ll x,y;cin>>x>>y;x--;y--;
		d.merge(x,y);
	}
	ll ans=0;
	For(i,0,n){
		if(d.find(i)==d.find(p[i])) ans++;
	}
	cout<<ans<<endl;










	
}

Measured memory_bytes: 2560
/* You are being watched. */


//~ while (clock() <= 69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")

using namespace std;

//~ #include <ext/pb_ds/assoc_container.hpp>
//~ #include <ext/pb_ds/tree_policy.hpp>
//~ using namespace __gnu_pbds;
//~ template <typename T>
//~ using ordered_set =
  //~ tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) (x).begin(), (x).end()
#define show(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
//using li = __int128;
//using uli = unsigned __int128;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

void solve() {
  char c; cin >> c;
  if(c >= 'A' and c <= 'Z') print('A');
  else print('a');
}

int main() {
  int t; t = 1;
  while(t--) solve();
}




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

int n;

int main() {
  scanf("%d", &n);

  if (n < 3) return 0 * printf("No\n");
  
  if (n % 4 == 3) {
    printf("Yes\n");
    for (int i = 1; i < n*2; ++i) printf("%d %d\n", i, i+1);
    return 0;
  }
  
  if (__builtin_popcount(n) == 1) return 0 * printf("No\n");
  
  printf("Yes\n");
  
  if (n % 4 == 0) {
    int tmp = 1 << __builtin_ctz(n);
    int a = tmp;
    int b = n ^ a;
    
    vector<int> v = {a, b};
    for (int i = 1; i < n; ++i) if (i != a && i != b) v.push_back(i);
    
    for (int i = 1; i < v.size(); ++i) printf("%d %d\n", v[i-1], v[i]);
    printf("%d %d\n", v.back(), v[0] + n);
    for (int i = 1; i < v.size(); ++i) printf("%d %d\n", v[i-1] + n, v[i] + n);
    
    printf("%d %d\n", n, a);
    printf("%d %d\n", b, n+n);
    
    return 0;
  }
  
  int nn = (n & ~3);
  for (int i = 2; i < nn; ++i) printf("%d %d\n", i-1, i);
  printf("%d %d\n", nn-1, n+1);
  for (int i = 2; i < nn; ++i) printf("%d %d\n", i-1 + n, i + n);
  
  if (n % 4 == 1) {
    printf("%d %d\n", n, n-1);
    printf("%d %d\n", n-1, 1);
    printf("%d %d\n", 1, n + n);
    printf("%d %d\n", n + n, n-1 + n);
    
    return 0;
  }
  
  if (n % 4 == 2) {
    printf("%d %d\n", n, n-2);
    printf("%d %d\n", n-2, 2);
    printf("%d %d\n", 2, n + n);
    printf("%d %d\n", n + n, n-2 + n);
    
    printf("%d %d\n", n-1, n-2);
    printf("%d %d\n", 3, n-1 + n);
  }

  return 0;
}


Measured memory_bytes: 3320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii  pair<int,int>
#define vpii vector<pii>
#define vll  vector<ll>
#define vi  vector<int>
#define pb push_back
#define f  first
#define s  second

int main() {

   int a,b;
   cin>>a>>b;
   
   cout<<(a*a-b);
    

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;
int dp[1000009][2];

int main(){
  string s;
  cin>>s;
  reverse(s.begin(),s.end());
  s+='0';
  int n=s.size();
  rep(i,n+1)rep(j,2)dp[i][j]=INF;
  dp[0][0]=0;
  
  rep(i,n){
    rep(j,2){
      int x=s[i]-'0';
      x+=j;
      rep(a,10){
        int ni=i+1,nj=0;
        int b=a-x;
        if(b<0){
          nj++;
          b+=10;
        }
        dp[ni][nj]=min(dp[ni][nj],dp[i][j]+a+b);
      }
    }
  }

  cout<<dp[n][0]<<endl;

  return(0);
}


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

using namespace std;

int main() {
  int X, A, B;
  cin >> X >> A >> B;

  int e = -A + B;
  if (e <= 0) {
    cout << "delicious" << endl;
  } else if (X + 1 <= e){
    cout << "dangerous" << endl;
  } else {
    cout << "safe" << endl;
  }

  return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, Q;
    cin >> N >> Q;

    fenwick_tree<ll> fw(N);

    REP(i, N){
        ll a;
        cin >> a;
        fw.add(i, a);
    }

    REP(i, Q){
        ll check;
        cin >> check;

        if(check == 0){
            ll p, x;
            cin >> p >> x;

            fw.add(p, x);

        }
        else{
            ll l, r;
            cin >> l >> r;

            cout << fw.sum(l, r) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 8212
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define N 10001
int a[N], d;
ll f[N][101];
ll dfs(int len, int pre, int top) {
    if (!len) return pre == 0;
    if (!top && f[len][pre] != -1) return f[len][pre];
    int up = top ? a[len] : 9;
    ll res = 0;
    for (int i = 0; i <= up; i++)
        res = (res + dfs(len - 1, (pre + i) % d, top && (i == up))) % mod;
    if (!top) f[len][pre] = res;
    return res;
}
char c[N];
int main() {
    memset(f, -1, sizeof(f));
    scanf("%s%d", c + 1, &d);
    int n = strlen(c + 1);
    for (int i = n, j = 1; i; i--, j++) a[j] = c[i] - '0';
    cout << (dfs(n, 0, 1) - 1 + mod) % mod << endl;
    return 0;
}

Measured memory_bytes: 8960
k = gets.to_i
result = 0
MEMO = {}
1.upto(k) do |i|
  MEMO[i] ||= {}
  MEMO[i][i] = i
  (i+1).upto(k) do |j|
    MEMO[i][j] = i.gcd(j)
  end
end

def gcd a,b,c  
  ab = MEMO[a][b] || MEMO[b][a]
  return 1 if ab == 1
  return MEMO[ab][c] || MEMO[c][ab]
end
result += 1 + (k - 1) * (k-1) * 3 +  (k-1) * 3
list = (2..k).to_a
list.each do |a|
  list.each do |b|
    ab = a.gcd(b)
    if ab == 1
      result += k - 1
    else
      list.each do |c|
        result += ab.gcd(c)
      end
    end
  end
end
puts result

Measured memory_bytes: 15168
#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<set>
#include<map>
#include<bitset>
#include<ctime>
#include<queue>
using namespace std;
#define int long long
#define pii pair <int, int>
#define XX first
#define YY second

// constants:
const int mn = 200005;
const int mod = 1000000007;
const long long inf = 4444444444444444444;
const int sminf = 1111111111;
const bool is_multitest = 0;
const bool is_interactive = 0;

// i/o methods:
const bool input_from_file = 0;
const bool output_to_file = 0;
#define filename ""
#define in_extension "inp"
#define out_extension "out"

// data preprocessing: (e.g.: divisor generating, prime sieve)
void preprocess()
{
    
}

// global variables:
int n;
string s;
vector <int> A;
int to_int(string s) {
    int find_point = -1;
    for (int i=0; i<s.size(); i++) if (s[i]=='.') find_point = i;
    if (find_point==-1) s+=".000000000";
    else {
        for (int i=s.size(); i<=find_point+9; i++) s.push_back('0');
    }

    int ret = 0;
    for (char c:s) {
        if (c=='.') continue;
        else ret = ret*10 + c-'0';
    }
    return ret;
}

pii factorize25(int u) {
    int c2 = 0, c5=0;
    while (u%2==0) {
        c2++;
        u/=2;
    }
    while (u%5==0) {
        c5++;
        u/=5;
    }
    return {c2, c5};
}

int cnt[55][55];
// main solution goes here:
void execute(int test_number)
{
    cin>>n;
    for (int i=0; i<n; i++) {
        cin>>s;
        A.push_back(to_int(s));
    }

    for (int i=0; i<n; i++) {
        pii p = factorize25(A[i]);
        cnt[p.XX][p.YY] ++;
    }

    int ans = 0;
    for (int i1 = 0; i1 < 55; i1++) for (int j1=0; j1<55; j1++) {
        for (int i2=0; i2<55; i2++) for (int j2=0; j2<55; j2++) {
            if (i1+i2 < 18 || j1+j2 < 18) continue;
            if (i1==i2 && j1==j2) ans += cnt[i1][j1] * (cnt[i1][j1]-1);
            else ans += cnt[i1][j1] * cnt[i2][j2];
        }
    }
    cout<<ans/2;
}
// REMEMBER TO CHOOSE TEST METHODS
// PLEASE REMOVE cout AND cerr DEBUG LINES BEFORE SUBMITTING PROBLEMS
// Solution by low_



















signed main()
{
#ifdef lowie
    if (!is_interactive)
    {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
#else
    if (input_from_file) freopen(filename"."in_extension, "r", stdin);
    if (output_to_file) freopen(filename"."out_extension, "w", stdout);
#endif
    if (!is_interactive)
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }

    preprocess();
    int ntest;
    if (is_multitest) cin >> ntest;
    else ntest = 1;

    for (int testno = 1; testno <= ntest; testno++)
    // use for instead of while to serve facebook hacker cup test format
    {
        execute(testno); // only start coding in this function, not in main
    }
}
// Template by low_
// Contact me via mail: ttuandung1803@gmail.com
// ...or codeforces: www.codeforces.com/profiles/low_
// ...or if you're interested in food: www.instagram.com/lowie.exe/

Measured memory_bytes: 5332
#include<iostream>
using namespace std;
int main()
{int k,x,s,t;
cin>>k>>x;
s=x-k+1;
if(s<-1000000)
{t=-1000000-s;
s=-1000000;
for(int i=k;i>=k*2-1-t;i--)
{cout<<s<<" ";
s++;
};
};
if(s>=-1000000)
{
for(int i=k*2-1;i>0;i--)
{cout<<s<<" ";
s++;
};
};
return 0;
};

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <functional>
/*
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
*/
using namespace std;
#define int         long long
#define double      long double
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vpii        vector<pii>
#define mi          map<int,int>
#define vii         vector<vector<int>>
#define mpii        map<pii,int>
#define piii        pair<int,pair<int,int> >
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define PI          3.141592653589
#define bs(v,n)     binary_search(all((v)),(n))
#define lb(v,n)     lower_bound(all((v)),(n))
#define ub(v,n)     upper_bound(all((v)),(n))
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define rf(s)       for(auto &c : s)
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++) //use Iterator
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define ef else if

/*template<class T>
T big(T a, T b) { return a>b ? a : b; }
int gcd(int a, int b) {  if (a == 0)  return b; return gcd(b % a, a); } 
int lcm(int a, int b) { return (a*b)/gcd(a,b); } 
bool mod(double a,double b) {return a/b - floor(a/b);}
int occurs(vi v,int n)  {  auto it=lb(v,n);auto it1=ub(v,n);int x=it1-it;return x;}
int logb(int base, int x) {return (log(x) / log(base));}
int pow(int n, int m){
    int ans=1;
    fo(i,0,m){
        ans*=n;
    }return ans;
}
int factors(int ans){
    int count=0;
    for (int i=1; i<=sqrt(ans); i++) { 
        if (ans%i == 0) 
        {if (ans/i == i) count++;
            else count+=2;} 
    }
    return count;     
}
bool isSubSequence(string str1, string str2, int m, int n)  // str1<str2
{ 
  
    if (m == 0) return true; 
    if (n == 0) return false; 
  
  	if (str1[m-1] == str2[n-1]) 
        return isSubSequence(str1, str2, m-1, n-1); 
  
    return isSubSequence(str1, str2, m, n-1); 
} */

signed main()
{
tezz;
int a,b,p;
cin>>a>>b;
p=max({2*a-1,2*b-1,a+b});
cout<<p<<endl;
return 0;
}

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

string part(string str, unsigned int num)
{
	string ret = str.substr(0, 1);
	int count = 0;

	for (unsigned int i = 0; i < str.size() - 1; i++) {
		if (str[i] == 'a' || str[i] == 'i' || str[i] == 'u' || str[i] == 'e' || str[i] == 'o') {
			ret += str.substr(i + 1, 1);
		}
	}

	if (ret.size() > num) {
		ret = ret.substr(0, num);
	}

	return ret;
}

int solve(vector<string> strings, unsigned int num)
{
	int ans = -1;
	bool flag = true;
	vector<string> parts;

	for (unsigned int i = 0; i < strings.size(); i++) {
		string temp = part(strings[i], num);
		parts.push_back(temp);
	}

	for (unsigned int i = 0; i < parts.size(); i++) {
		for (unsigned int j = i + 1; j < parts.size(); j++) {
			if (parts[i] == parts[j]) {
				flag = false;
				goto End;
			}
		}
	}
End:

	if (flag == true) {
		ans = num;
	}

	return ans;
}

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

		if (n == 0) {
			break;
		}

		vector<string> strings(n);
		unsigned int maxx = 0;
		for (int i = 0; i < n; i++) {
			cin >> strings[i];
			unsigned int str_size = strings[i].size();
			maxx = max(maxx, str_size);
		}

		int ans = -1;
		
		for (unsigned int i = 1; i <= maxx; i++) {
			ans = solve(strings, i);
			if (ans != -1) {
				break;
			}
		}

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

Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
const int m=2e5+1;
long long a[m],b[m];
main(){
    int n; cin >> n;
    for(int i=0;i<n;i++) cin >> a[i] >> b[i];
    double press=0ll;
    for(int i=n-1;i>=0;i--){
        if(a[i])
            press = b[i]*ceil((a[i]+press)/b[i])-a[i];
    }
    cout << fixed << setprecision(0) << press << endl;
}

///??????? f u 
/* why tf zero is a multiple ?? */

Measured memory_bytes: 1920
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		int MAX = 1000000;
		boolean[] prime = new boolean[MAX + 1];
		for (int i = 4; i <= MAX; i += 2) {
			prime[i] = true;
		}
		for (int i = 3; i <= Math.sqrt(MAX); i += 2) {
			if (!prime[i]) {
				for (int j = i * 3; j <= MAX; j += i * 2) {
					prime[j] = true;
				}
			}
		}
		while (true) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			if ((n | m) == 0)
				break;
			int[] a = new int[n];
			int min = Integer.MAX_VALUE;
			boolean[] f = new boolean[m + 1];
			f[0] = true;
			for (int i = 0; i < n; i++) {
				int s = scanner.nextInt();
				min = Math.min(s, min);
				a[i] = s;
			}
			int max = 0;
			for (int i = min; i <= m; i++) {
				if (!f[i])
					for (int j = 0; j < n; j++) {
						if (i - a[j] >= 0 && f[i - a[j]]) {
							f[i] = true;
							break;
						}
					}
				if (f[i] && !prime[i])
					max = i;
			}
			System.out.println(max == 0 ? "NA" : max);

		}

	}
}

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

ll ans=0;
ll num[52];
ll save[52];

void search(int n, int x){
    ll sum=num[n];
    if(n==0){
        ans++;
        return;
    }
    if(x==1) return;
    if(x==(sum+1)/2){
        ans+=save[n]+1;
        return;
    }
    if(x==sum){
        ans+=2*save[n]+1;
        return;
    }
    if(x<(sum+1)/2) search(n-1,x-1);
    else{
        ans+=save[n]+1;
        search(n-1,x-2-(num[n]-3)/2);
    }
}

signed main(){
    int n,x;
    cin >> n >> x;
    num[0]=1;
    for(int i=1;i<=50;i++){
        num[i]=num[i-1]*2+3;
    }

    save[0]=0;
    for(int i=1;i<=50;i++) save[i]=save[i-1]*2+1;

    search(n,x);

    cout << ans << endl;


}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main (void)
{
  int a,b,c,tmp;
  scanf("%d %d %d",&a,&b,&c);
  if (a>b) {
    tmp=a;
    a=b;
    b=tmp;
  }
  if (b>c) {
    tmp=b;
    b=c;
    c=tmp;
  }
  if (a>b) {
    tmp=a;
    a=b;
    b=tmp;
  }
  printf("%d %d %d\n",a,b,c);

  return 0;
}



Measured memory_bytes: 2104
//Island war: https://abc103.contest.atcoder.jp/tasks/abc103_d
//solution by ravibitsgoa : Ravishankar Joshi, from BITS Pilani, Goa campus, India
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n, m;
    cin>>n>>m;
    pair<int, int> req[m];
    for(int i=0; i<m; i++)
        cin >> req[i].first >> req[i].second;
    sort(req, req+m);
    int right = 0, count=0;
    for(int i=0; i<m; i++) {
        if(right == 0) {
            right = req[i].second;
        } else {
            if(req[i].first >= right) {
                count++;
                right = req[i].second;
            }
            if(right > req[i].second)
                right = req[i].second;
        }
    }
    cout << count+1;
}

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

int main(){
    int i = 1;
    int x;
    
    while(1){
        cin >> x;
        if ( x == 0) break;
        
        cout << "Case"<< " " << i << ":" << " " << x << endl;
        
        i++;
    }
    
    return 0;
}


Measured memory_bytes: 3072
n = int(input())
a = []
x = []
y = []
for i in range(n):
    ai = int(input())
    a.append(ai)
    xi = []
    yi = []
    for j in range(ai):
        xij, yij = map(int, input().split(' '))
        xi.append(xij)
        yi.append(yij)
    x.append(xi)
    y.append(yi)
ans = 0
for case in range(2**n):
    truth_t = 0  #正直者の真の数
    truth = 0    #正直者の確認した数
    for i in range(n):  #人ごとに矛盾が生じないか確認
        if (case>>i)&1:  #正直者であれば証言に矛盾がないか確認
            truth_t+=1
            proof=0
            for j in range(a[i]):
                if ((case>>(x[i][j]-1))&1)==y[i][j]:
                    proof+=1
            if proof==a[i]:
                truth += 1
    if truth==truth_t:
        if ans<truth:
            ans = truth
print(ans)


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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  cout << max(a*b,c*d) << endl;
  return 0;
}

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

using namespace std;
vector<int> adj[100002];
int p[100002]={0};
bool vis[100002];
void initial()
{
    for(int i=0;i<100002;i++)
    {
        vis[i]=false;
    }
}
int dfs(int s)
{
    int max=-1,k;
    //cout<<vis[3]<<".. ";
    vis[s]=true;
    //cout<<s<<" ";
    for(int i=0;i<adj[s].size();i++)
    {
        //cout<<s<<"->";
        //cout<<adj[s][i]<<"\n";
        if(vis[adj[s][i]]==false)
        {
            
            k=dfs(adj[s][i]);
        }
        else
        {
            k=p[adj[s][i]];
        }
       // cout<<s<<"="<<k+1<<endl;
        if(k>max)max=k;
    }
    //cout<<endl;
    p[s]=max+1;
    return max+1;
}
int main() {
    int n,m,i,j,k,l,u,v;
    cin>>n>>m;
    initial();
    for(i=0;i<m;i++)
    {
        cin>>u>>v;
        //cout<<u<<" "<<v<<endl;
        adj[u].push_back(v);
    }
    l=0;
    dfs(1);
    for(i=1;i<=n;i++)
    {
        
        if(vis[i]==false)
        {
            k=dfs(i);
        }
        else
        {
            k=p[i];
        }
        //cout<<k<<" ";
        if(k>l)l=k;
    }
    //cout<<adj[3].size();
    cout<<l;
}

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

int main() {
  int r,b,g,n;
  cin >> r >> g >> b >> n;
  int count=0;
  for(int i=0;i<=n;i+=r) {
    for(int j=0;j<=n-i;j+=g) {
      if((n-i-j)%b==0) {
        count++;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<queue>
#define For(i,j,k)	for(ll i=j;i<=k;++i)
#define Dow(i,j,k)	for(ll i=k;i>=j;--i)
#define ll long long
using namespace std;
inline ll read()
{
    ll t=0,f=1;char c=getchar();
    while(c<'0'||c>'9')	{if(c=='-')	f=-1;	c=getchar();}
    while(c>='0'&&c<='9')	t=t*10+c-'0',c=getchar();
    return t*f;
}
inline void write(ll x){if(x>=10)	write(x/10);putchar(x%10+'0');}
inline void writeln(ll x){write(x);puts("");}
inline void write_p(ll x){write(x);putchar(' ');}
string s1,s;
int len;
bool flag;
inline void check()
{
	if(s!=s1)	return;
	puts("YES");exit(0);	
}
int main()
{
	cin>>s;
	if(s.length()>9)	{puts("NO");return 0;}
	if(s[s.length()-1]=='A')	flag=1;
	s1="KIHABAR";if(flag)	s1+='A';
	check();
	s1="KIHBAR";if(flag)	s1+='A';
	check();
	s1="KIHABR";if(flag)	s1+='A';
	check();
	s1="KIHBR";if(flag)	s1+='A';
	check();
	s1="AKIHBR";if(flag)	s1+='A';
	check();
	s1="AKIHABR";if(flag)	s1+='A';
	check(); 
	s1="AKIHBAR";if(flag)	s1+='A';
	check();
	s1="AKIHABAR";if(flag)	s1+='A';
	check();
	
	puts("NO");
}

Measured memory_bytes: 256
from collections import Counter
x = int(input())
a = list(map(int,input().split()))
c = Counter(a)

suma = sum([v for v in c.values()])
lenc = len(c)
b = suma - lenc
if b % 2 == 0:
    print(lenc)
else:
    print(lenc - 1)

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

int main(){
  int N,a,b,c,d;
  
  cin >> N;
  a = N%10;
  b = (N-a)%100;
  c = (N-a-b)%1000;
  d = (N-a-b-c);
  
  if((a==b/10 && a==c/100)||(b/10==c/100 && b/10==d/1000))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256