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

using namespace std;

set<int> product(set<int> &a, set<int> &b)
{
    set<int> ret;

    for (set<int>::iterator it = b.begin(); it != b.end(); it++)
        if (a.find(*it) != a.end())
            ret.insert(*it);

    return ret;
}

int main()
{
    int n;

    while (cin >> n, n) {
        vector<set<int> > mem(n);
        int k, l, cnt = 0;
        
        for (int i = 1; i <= n; i++) {
            int m, p;
            
            cin >> m;
            while (m--) {
                cin >> p;

                mem[p - 1].insert(i);
                
            }
        }

        cin >> k;
        cin >> l;

        set<int> ans = mem[l - 1];
        k--;
        while (k--) {
            cin >> l;
            ans = product(ans, mem[l - 1]);
        }
        
        int leak;
        for (set<int>::iterator it = ans.begin(); it != ans.end(); it++) {
            cnt++;
            leak = *it;
        }

        if (cnt == 1)
            cout << leak << endl;
        else
            cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 1640
from collections import Counter
import sys
input = sys.stdin.readline

N = int(input())
Sss = [input().rstrip() for _ in range(N)]

cnt = Counter(Sss)

num = max(cnt.values())

anss = []
for key in sorted(cnt.keys()):
    if cnt[key] == num:
        anss.append(key)

print('\n'.join(anss))


Measured memory_bytes: 38716
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=1e5+5;

int32_t main()
{
	IOS;
	string s;
	cin>>s;
	int n=s.size();
	for(int i=0;i+1<n;i++)
	{
		if(s[i]==s[i+1])
		{
			cout<<i+1<<" "<<i+2;
			return 0;
		}
	}
	for(int i=0;i+2<n;i++)
	{
		if(s[i]==s[i+2])
		{
			cout<<i+1<<" "<<i+3;
			return 0;
		}
	}
	cout<<"-1 -1";
	return 0;
}


Measured memory_bytes: 512
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 2e5 + 10;
int n , K , a[N];
ll sum[N] , ans;

void solve(int l,int r){
    if(l == r) return;
    int m = (l + r) >> 1;
    solve(l , m);
    solve(m + 1 , r);
    for(int i=m+1,j=l;i<=r;++i){
        for(;j<=m&&sum[j]<=sum[i];++j);
        ans+=j-l;
    }
    inplace_merge(sum+l,sum+m+1,sum+r+1);
}

int main(){
    scanf("%d%d",&n,&K);
    rep(i,1,n+1) scanf("%d",a + i) , sum[i] = sum[i-1] + a[i];
    rep(i,1,n+1) sum[i] -= ll(K) * i;
    solve(0 , n);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3792
def gcd1(x,y):
    m = x % y
    if m == 0:
        return y
    else:
        return gcd1(y,m)
def gcd(x,y):
    if x < y:
        _ = x
        x = y
        y = _
    return gcd1(x,y)

A,B,K = map(int,input().split())
GCD = gcd(A,B)

count = 0
k = GCD
ans = 0
while count < K:
    if GCD % k == 0:
        count+=1
        ans = k
    k -= 1

print(ans)

Measured memory_bytes: 3188
#include<iostream>
#include<map>
using namespace std;
#define df 0
typedef long int li;
const li MAX=10000000000;
#define rep(i,n) for(int i=0;i<n;i++)




int main(){
  if(df) printf("*debug mode*\n");

  int n,k; cin >>n >>k;
  li s;
  if(k%2==0){
    k/=2;
    s=n/k;
    s=(s*s+3)/4*s;
  }
  else{
    s=(li)(n/k)*(n/k)*(n/k);
  }
  cout << s;
}

/// confirm df==0 ///


Measured memory_bytes: 256
import collections,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,Q = LI()
ab = [LI() for _ in [None]*(N-1)]
px = [LI() for _ in [None]*(Q)]
ans = [0]*(N+1) #1_indexed
graph = {i:collections.deque() for i in range(1,N+1)} #1_indexed
for a,b in ab:
        graph[a].append(b)
        graph[b].append(a)
for p,x in px:
    ans[p] += x
seen = [0]*(N+1) #1_indexed
stack = []
def dfs():
    seen[1] = 1
    stack.append(1)
    while stack:
        s = stack.pop()
        if not graph[s]:
            continue
        for j in range(len(graph[s])):
            g_NO = graph[s].popleft()
            if seen[g_NO]:
                continue
            seen[g_NO] = 1
            stack.append(g_NO)
            ans[g_NO] += ans[s]
dfs()
print(*ans[1:])

Measured memory_bytes: 260528
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::{i32, i64, u32, u64, usize, f64};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{VecDeque, HashMap, BTreeMap, HashSet, BTreeSet};
#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::mem::{swap};

fn main() {
    input!{
        n: usize,
        txy: [(i32, i32, i32); n],
    }
    let mut txy = txy;
    txy.insert(0, (0, 0, 0));
    if txy.windows(2).map(|w| (w[0], w[1]))
        .all(|((t1, x1, y1), (t2, x2, y2))| {
            let md = (x2 - x1).abs() + (y2 - y1).abs();
            let remt = t2 - t1 - md;
            remt >= 0 && remt % 2 == 0
    }) { println!("Yes") }
    else { println!("No") }
}


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

using i64 = int64_t;

int main(){
    vector<int> v;
    for(int i=0;i<5;++i){
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    sort(v.begin(), v.end());
    int ans = INT_MAX;
    do{
        int sum = 0;
        for(int i=0;i<4;++i){
            sum += v[i];
            if(v[i]%10 != 0){
                sum += 10 - (v[i]%10);
            }
        }
        sum += v.back();
        ans = min(ans, sum);
    }while(next_permutation(v.begin(), v.end()));
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))
if len(b)>3:
  print("No")
elif len(b)==3:
  if b[0]^b[1]^b[2]==0:
    if a.count(b[0])==a.count(b[1]) and a.count(b[1])==a.count(b[2]):
      print("Yes")
    else:
      print("No")
  else:
    print("No")
elif len(b)==2:
  b=sorted(b)
  if b[0]==0:
    if a.count(b[0])==n//3 and a.count(b[1])==2*n//3:
      print("Yes")
    else:
      print("No")
  else:
    print("No")
else:
  if b[0]==0:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 14212
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin >> s;
	for(int i = 0; i < s.length(); i++)
	{
		for(int j = i + 1; j < s.length(); j++)
		{
			if(s[i] == 'C' && s[j] == 'F')
			{
				cout<<"Yes\n"; return 0;
			}
		}
	}
	cout << "No\n";
}


Measured memory_bytes: 764
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
from collections import deque
import itertools
import heapq
#import bisect
from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint

#oo=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
# ko=list("abcdefghijklmnopqrstuvwxyz")

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori

def soinsubunkai_e(n,m): #高速素因数分解 m[n]=nを割ることの出来る最小の素数
    a = set()
    i = 1
    while n>1:
        a.add(m[n])
        n=n//m[n]
    nokori=n
    a.add(nokori)
    return a

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


def era(n): #b[n]=nを割ることの出来る最小の素数　の配列を生成　エラトステネスの篩
    b=[i for i in range(n+1)]
    for i in range(2,int(math.sqrt(n)+10)):
        j=1
        temp=i*j
        while temp<=n:
            b[temp]=min(i,b[temp])
            temp+=i
    return b


def main():
    #l,r,d=map(int,input().split())
    n=int(input())
    a=[]
    b=[]
    for i in range(n):
        x,y=map(int,input().split())
        a.append(x-y)
        b.append(x+y)
    a=sorted(a)
    b=sorted(b)
    aa=abs(a[0]-a[-1])
    bb=abs(b[0]-b[-1])
    print(max(aa,bb))












if __name__ == "__main__":

    main()


Measured memory_bytes: 108364
import queue
n,k=map(int,input().split())
l=list(map(int,input().split()))
el=queue.deque(maxlen=k)
ans = 0
m = 0
for i in l[:]:
    if len(el) == k:
        el.append((1+i)/2)
        m = m-m_e+el[-1]
    else:
        el.append((1+i)/2)
        m +=el[-1]
    ans = m if m>ans else ans
    m_e = el[0]
print(ans)

Measured memory_bytes: 26328
def main():
    while True:
        line = input().split()
        num = line[0]
        digit = int(line[1])
        if digit == 0: break
        if num == '0':
            print("0 0 1")
            continue

        num = addzero(num, digit)

        numlist = [num]

        for i in range(20):
            nextt = nextnum(numlist[i])

            j = isnew(numlist, nextt)

            if not(j == -1):
                print(j, int(nextt), (i + 1) - j)
                break
            else: numlist.append(nextt)
        
def nextnum(strr):
    listt = []
    length = len(strr)
    for item in strr:
        listt.append(item)
    maxlist = listt.copy()
    minlist = listt.copy()
    maxlist.sort(reverse = True)
    minlist.sort(reverse = False)
    while True:
        if minlist == ['0']: break
        elif minlist[0] == '0':
            r = minlist.remove('0')
        else: break
    maxnum = int("".join(maxlist))
    minnum = int("".join(minlist))

    diststr = str(maxnum - minnum)
    diststr = addzero(diststr, length)

    return diststr

def addzero(strr, digit):
    return ("0" * (digit - len(strr)) + strr)

def isnew(listt, elem):
    for j in range(len(listt)):
        if listt[j] == elem: return j
    return -1

def StoI(strr):
    while True:
        for item in strr:
            if strr == '0': break
            elif minlist[0] == '0':
                r = minlist.remove('0')
            else: break

main()



Measured memory_bytes: 5608
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
int main(){
    int i,n;
    string a;
    getline(cin,a);
    for(i=0; i<a.size(); i++){
             if ('a' <= a[i] && a[i] <= 'z')
             a[i] += 'A' - 'a';
    }
    cout<< a<<endl;
    return 0;
}

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

int main() {
	int A[5];
	int x = 0;
	for (int i = 1; i <= 5; i++) {
		cin >> A[i];
	}
	for (int i = 1; i <= 5; i++) {
		if (A[i] == 0) x = i;
	}
	cout << x;
	return 0;
}

Measured memory_bytes: 3636
import java.io.InputStream;
import java.io.PrintStream;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static class Value {
        int type;
        int value;
        Value(int type, int value) {
            this.type = type;
            this.value = value;
        }

        public int getType() {
            return type;
        }

        public int getValue() {
            return value;
        }
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int X = scan.nextInt();
        int Y = scan.nextInt();
        int A = scan.nextInt();
        int B = scan.nextInt();
        int C = scan.nextInt();

        PriorityQueue<Value> pq = new PriorityQueue<>(Comparator.comparing(Value::getValue).reversed());

        for(int i = 0 ; i < A; i++) {
            pq.offer(new Value(0, scan.nextInt()));
        }
        for(int i = 0 ; i < B; i++) {
            pq.offer(new Value(1, scan.nextInt()));
        }
        for(int i = 0 ; i < C; i++) {
            pq.offer(new Value(2, scan.nextInt()));
        }

        long ans = 0;
        long ac = 0;
        long bc = 0;
        long cc = 0;
        for(; ac+bc+cc < X+Y;) {
            Value v = pq.poll();
            switch (v.getType()) {
                case 0:
                    if(ac < X){
                        ans += v.getValue();
                        ac++;
                    }
                    break;

                case 1:
                    if(bc < Y){
                        ans += v.getValue();
                        bc++;
                    }
                    break;

                case 2:
                    ans += v.getValue();
                    cc++;
                    break;
            }
        }

        os.println(ans);

    }

}

Measured memory_bytes: 164288
#include <stdio.h>

int main(void) {
	int N;
	scanf("%d", &N);
	int a, b;
	a = N/2;
	b = N%2;
	switch(b){
		case 0:printf("%d", a);
		break;
		case 1:printf("%d", a+1);
		break;
	}
	return 0;
}


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

int main() {
  int n;
  while (cin >> n, n) {
    int sum=0;
    for (int i=0; i<n*(n-1)/2; i++) {
      int x;
      cin >> x;
      sum += x;
    }
    cout << sum / (n-1) << endl;
  }
}

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

int main() {
  int n;
  cin >> n;
  vector<long long> A(n, 0);
  for (int i = 0; i<n; i++) cin >> A[i];
  long long cnt1=0, acm1=0, cnt2=0, acm2=0;
  for(int i = 0; i<n; i++) {
    acm1+=A[i];
    acm2+=A[i];
    if(i%2) {
      if(acm1>0);
      else {
        cnt1 += abs(acm1) + 1;
        acm1 = 1;
      }
      if(acm2<0);
      else {
        cnt2 += abs(acm2) + 1;
        acm2 = -1;
      }
    }
    else {
      if(acm1<0);
      else {
        cnt1 += abs(acm1) + 1;
        acm1 = -1;
      }
      if(acm2>0);
      else {
        cnt2 += abs(acm2) + 1;
        acm2 = 1;
      }
    }
  }
  cout << min(cnt1, cnt2) << "\n";
}

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

void printvec(vector<int>);

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

  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  int c = 0;
  for (int i = 0; i < n; i++) {
    int minj = i;
    for (int j = i; j < n; j++) {
      if (a.at(j) < a.at(minj)) {
        minj = j;
      }
    }
    if (i != minj) {
      swap(a.at(i), a.at(minj));
      c++;
    }
  }
  printvec(a);
  cout << c << endl;
}

void printvec(vector<int> vec) {
  for (int i = 0; i < vec.size(); i++) {
    if (i) cout << " ";
    cout << vec.at(i);
  }
  cout << endl;
}


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

void chmin(int &a, int b) {
    if (a > b) a = b;
}

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

    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    vector<int> dp(n, 1e+9);
    dp[0] = 0;

    for (int i = 1; i < n; i++) {
        chmin(dp[i], dp[i - 1] + abs(h[i - 1] - h[i]));
        if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i - 2] - h[i]));
    }

    cout << dp.back() << endl;
    return 0;
}

Measured memory_bytes: 1024
n, m = gets.split.map(&:to_i)
g = Array.new(n){[]}
m.times do
    a, b = gets.split.map(&:to_i)
    a -= 1
    b -= 1
    g[a] << b
    g[b] << a
end
n.times do |i|
    p g[i].size
end

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

int main(){
  int a,k,snk,z=0;
  cin >> a>>k;
  vector<int>d(k);
  int b[200][200];
  int ans[200];
  for(int i=0;i<200;i++){
    ans[i]=0;
  }
  for(int i=0;i<k;i++){
    cin >> d.at(i);
    for(int j=0;j<d.at(i);j++){
      cin>>snk;
      ans[snk]++;
    }
  }
  for(int i=1;i<=a;i++){
    if(ans[i]==0)z++;
  }
  cout <<z;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

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

    if(a == 22) cout << "Christmas Eve Eve Eve" << endl;
    if(a == 23) cout << "Christmas Eve Eve" << endl;
    if(a == 24) cout << "Christmas Eve" << endl;
    if(a == 25) cout << "Christmas" << endl;
}

Measured memory_bytes: 764
import sys
input = sys.stdin.readline
from collections import *

N = int(input())
s = input()[:-1]
cnt = defaultdict(int)

for S in range(1<<N):
    red, blue = [], []
    
    for i in range(N):
        if (S>>i)&1:
            red.append(s[i])
        else:
            blue.append(s[i])
    
    cnt[(''.join(red), ''.join(blue))] += 1

s = s[::-1]
ans = 0

for S in range(1<<N):
    red, blue = [], []
    
    for i in range(N):
        if (S>>i)&1:
            red.append(s[i])
        else:
            blue.append(s[i])
    
    ans += cnt[(''.join(blue), ''.join(red))]

print(ans)

Measured memory_bytes: 235856
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;

int main(){

    lint n;
    cin >> n;
    vector<lint> d(n);
    for(lint i = 0; i < n; ++i){
        cin >> d[i];
    }

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

    lint k;
    if(n%2)k = n/2+1;
    else k = n/2;

    cout << d[k]-d[k-1] << endl;

}

Measured memory_bytes: 1024
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int S = sc.nextInt();

		int h = S / (60 * 60);
		int m = (S - h*60*60) / 60;
		int s = S - h*60*60  - m*60;
		System.out.println(h + ":" + m + ":" + s);

	}
}




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

int main(){
    string s;
    cin >> s;
    int c = 1e9;
    int f = - 1e9;
    for (int i = 0; i < s.size(); i++){
        if (s[i] == 'C') c = min(c, i);
    }
    for (int i = 0; i < s.size(); i++){
        if (s[i] == 'F') f = max(f, i);
    }
    if (c == 1e9 || f == - 1e9) cout << "No" << endl;
    else if (c < f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;
typedef long long lint;

#define RPT(i, b, e) for (int i = ((int)b); i <= ((int)e); i++)
#define RPT0(i, n) RPT(i, 0, ((int)n) - 1)
#define RPT1(i, n) RPT(i, 1, (n))
#define EACH(it, v) for (const auto& it : v)
#define ALL(v) v.begin(), v.end()

void resolve()
{
    int N;
    cin >> N;
    vector<int> X(N);
    RPT0(i, N) cin >> X[i];

    sort(ALL(X));

    if (X[0] == 1) {
        if (N >= 2 && X[1] == 1)
            cout << 0 << endl;
        else
            cout << 1 << endl;
        return;
    }

    vector<bool> b(1000001, true);
    EACH(it, X)
    {
        if (!b[it]) continue;
        int idx = it * 2;
        while (idx <= 1000000) {
            b[idx] = false;
            idx += it;
        }
    }

    int cnt = 0;
    for (int i = 0; i < X.size(); i++) {
        if (!b[X[i]]) continue;
        auto it_lo = lower_bound(X.begin(), X.end(), X[i]);
        auto it_up = upper_bound(X.begin(), X.end(), X[i]);
        auto idx_lo = distance(X.begin(), it_lo);
        auto idx_up = distance(X.begin(), it_up);
        if ((idx_up - idx_lo) == 1) cnt++;
    }

    cout << cnt << endl;
}

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


Measured memory_bytes: 4332
#include<bits/stdc++.h>
    using namespace std;
    #define ll double
    
int main(){
    ll n,k,c=0;
    cin>>n>>k;
    vector<ll> a(n);
  	for(ll i=0;i<n;i++){ cin>>a[i];
                        if(a[i]>=k) c++;
                       }
  cout<<c<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
    int i,n;
    int emax1,emax2,omax1,omax2;
    int ep1,ep2,op1,op2;
    int num[100100],evennum[114514],oddnum[114514];
    scanf("%d",&n);
    emax1=emax2=omax1=omax2=0;
    for(i=0;i<114514;i++)
    {
        evennum[i]=oddnum[i]=0;    
    }
    for(i=0;i<n;i++)
    {
        scanf("%d",&num[i]);
        if(i%2)
        {
            evennum[num[i]]++;
            if(evennum[num[i]]>emax1)
            {
                emax1=evennum[num[i]];
                ep1=num[i];
            }
            else if(evennum[num[i]]>emax2)
            {
                emax2=evennum[num[i]];
                ep2=num[i];
            }
        }
        else
        {
            oddnum[num[i]]++;
            if(oddnum[num[i]]>omax1)
            {
                omax1=oddnum[num[i]];
                op1=num[i];
            }
            else if(oddnum[num[i]]>omax2)
            {
                omax2=oddnum[num[i]];
                op2=num[i];
            }
        }
    }
    if(ep1!=op1)
    {
        printf("%d\n",n-emax1-omax1);
    }
    else if(emax1+omax2>emax2+omax1)
    {
        printf("%d\n",n-emax1-omax2);
    }
    else
    {
        printf("%d\n",n-emax2-omax1);    
    }
    return 0;
}


Measured memory_bytes: 1536
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	X := ReadInt()

	l := -1
	r := int(1e9)
	for r-l > 1 {
		c := (l + r) / 2
		if (1+c)*c/2 >= X {
			r = c
		} else {
			l = c
		}
	}
	fmt.Println(r)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


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

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

    int n = s.size();

    stack<char> st;

    rep(i, n) {
        if(s[i] == 'B' && st.size()!=0) st.pop();
        else if(s[i] == 'B' && st.size()==0) continue;
        else st.push(s[i]);
    }

    int m = st.size();
    vector<char> ch(m);
    rep(i, m) {
        ch.at(i) = st.top();
        st.pop();
    }

    rep(i, m) {
        cout << ch.at(m-1-i) ;
    }
    cout << endl;

  return 0;
}

Measured memory_bytes: 256
# 入力をint型にする
N = int(input())

ans = 0
for i in range(1,N+1):
  if i%3!=0 and i%5!=0:
    ans += i

print(ans)

# Pythonの全て
# https://qiita.com/KoyanagiHitoshi/items/3286fbc65d56dd67737c#56-%E7%B5%B6%E5%AF%BE%E5%80%A4abs

Measured memory_bytes: 9160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
   ll n;
   cin>>n;
   vector<int>d(n);
   for(int i=0;i<n;i++){
       cin>>d[i];
   }
   ll sum = 0;
   for(int i=0;i<n-1;i++){
       for(int j =i+1;j<n;j++){
           sum += d[i]*d[j];
       }
   }
   cout<<sum<<endl;
}



Measured memory_bytes: 256
if __name__ == '__main__':
    b, c = map(int, input().split())
    b1 =""
    c1 = ""
    for i in range(c):
        b1 = b1 + str(b)

    for i in range(b):
        c1 = c1 + str(c)

    if int(b) < int(c):
        print(b1)
    else:
        print(c1)





Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  string s;
  cin >> s;
  s.at(5) = s.at(13)= ' ';
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
ABCD=input()
L=list(ABCD)

def bfs(i,j,a,c):#i,hidari,migi
  if i==3:
    if j+int(L[3])==7:
      c+=[L[0]+a[0]+L[1]+a[1]+L[2]+"+"+L[3]+"=7"]
    elif j-int(L[3])==7:
      c+=[L[0]+a[0]+L[1]+a[1]+L[2]+"-"+L[3]+"=7"]
    return 
    
  else:
    bfs(i+1,j+int(L[i]),a+"+",c)
    bfs(i+1,j-int(L[i]),a+"-",c)
    return c
  

d=[]

ans=bfs(1,int(L[0]),"",d)
print(d[0])

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

typedef long long lint;
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const lint inv = MOD - 2;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

string solve(void){
    int c[5][5];
    rep(i, 3){
        rep(j, 3){
            cin >> c[i][j];
        }
    }
    int a[5] = {0}, b[5];
    rep(j, 3){
        b[j] = c[0][j];
    }
    rep(i, 3){
        a[i] = c[i][0] - b[0];
    }
    rep(i, 3){
        rep(j, 3){
            if(c[i][j] != a[i] + b[j]){
                return "No";
            }
        }
    }
    return "Yes";
}

int main(){
    string ans = solve();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1e9+7;
int main() {
    int n,m;
    while(cin >> n >> m) {
        if(abs(n-m) >= 2) {
            puts("0");continue;
        } else if(n == m) {
            LL ans = 1;
            for(LL i = 2;i <= n;i++) {
                ans *= i;ans %= MOD;
            }
            ans *= ans;ans %= MOD;
            ans *= 2;ans %= MOD;
            cout << ans << endl;
        } else {
            if(n < m) swap(n,m);
            LL ans = 1;
            for(LL i = 2;i <= n-1;i++) {
                ans *= i;
                ans %= MOD;
            }
            ans *= ans;ans %= MOD;
            ans *= n;ans %= MOD;
            cout << ans << endl;
        }
    }
    return 0;
}

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

int main(){
    int h, a; cin >> h >> a;
    int cnt = 0;
    while(h > 0) {
        h -= a;
        cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#define _USE_MATH_DEFINES
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)

int main() {
	int a, b;
	cin >> a >> b;
	int wa, sa, sek, ans;
	wa = a + b;
	sa = a - b;
	sek = a * b;
	ans = max(wa, sa);
	ans = max(ans, sek);
	cout << ans << endl;
	return 0;
}

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

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

  string s;
  int K;
  cin >> s >> K;

  set<string> s_substring;
  for(int i = 0; i < s.size(); i ++) {
    string tmp;
    for(int j = i; j < min((int)s.size(), i + 5); j++) {
      tmp.push_back(s[j]);
      s_substring.insert(tmp);
    }
  }

  set<string>::iterator itr = s_substring.begin();
  advance(itr, K-1);

  cout << *itr << endl;

  return 0;
}

Measured memory_bytes: 4792
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
//#include <algorithm>

long buffer[10] = {0};
long iCount = 0;

static void print_array( long keta )
{
    long i;
    for(i=0; i<keta; i++) {
        printf("%d", buffer[i]);
    }
    printf("\n");
}

static void make_array( long n, long keta, long iCurr, long Number, long abUsed[3] )
{
    if(keta==iCurr) {
        if( Number <= n && abUsed[0] && abUsed[1] && abUsed[2] ) {
            //print_array( keta );
            iCount ++;
        }
    }
    else {
        long Number2 = 0;

        // 3
        {
            buffer[iCurr] = 3;
            Number2 = Number * 10 + 3;
            long abUsed2[3] = {1, abUsed[1], abUsed[2] };
            make_array( n, keta, iCurr+1, Number2, abUsed2 );
        }

        // 5
        {
            buffer[iCurr] = 5;
            Number2 = Number * 10 + 5;
            long abUsed2[3] = {abUsed[0], 1, abUsed[2] };
            make_array( n, keta, iCurr+1, Number2, abUsed2 );
        }

        // 7
        {
            buffer[iCurr] = 7;
            Number2 = Number * 10 + 7;
            long abUsed2[3] = {abUsed[0], abUsed[1], 1 };
            make_array( n, keta, iCurr+1, Number2, abUsed2 );
        }
    }
    return;
}

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    long keta_max = (long)(log10( (double)n )) + 1;

    iCount = 0;
    long keta;
    for(keta=1; keta<=keta_max; keta++) {
        long abUsed[3] = {0, 0, 0};
        make_array( n, keta, 0, 0, abUsed );
    }
    printf("%d\n", iCount);

    return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  vvi G(N);
  vp E(N-1);
  rep(i,N-1) {
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    E[i] = P(a,b);
  }
  int K = 0;
  rep(i,N) {
    if(i == 0) {
      K = max(K,sz(G[i]));
    } else {
      K = max(K,sz(G[i])+1);
    }    
  }
  vi color(N,1);
  queue<int> que;
  que.push(0);
  while(!que.empty()) {
    int k = que.front();
    que.pop();
    int co = 1;
    rep(i,sz(G[k])) {
      if(color[k] == co && k != 0) {
        co++;
      }
      color[G[k][i]] = co;
      que.push(G[k][i]);
      co++;
    }
  }
  cout << K << endl;
  rep(i,N-1) {
    cout << color[E[i].second] << endl;
  }
  return 0;
}

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

public class Main {

	static class Point {
		double x;
		double y;
		public Point(double x, double y) {
			this.x = x;
			this.y = y;
		}
		public String toString() {
			return String.format("%.8f %.8f", x, y);
		}
	}
	
	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		reader.close();
		Point start = new Point(0, 0);
		Point end = new Point(100, 0);
		System.out.println(start);
		getKochCurve(0, n, start, end);
		System.out.println(end);
	}

	private static void getKochCurve(int i, int n, Point start, Point end) {		
		if (i < n) {
			Point firstPoint = getPoint(start, end, 1.0/3.0);
			Point thirdPoint = getPoint(start, end, 2.0/3.0);
			Point secondPoint = getSecondPoint(start, end, firstPoint, thirdPoint);
			getKochCurve(i + 1, n, start, firstPoint);
			System.out.println(firstPoint);
			getKochCurve(i + 1, n, firstPoint, secondPoint);
			System.out.println(secondPoint);
			getKochCurve(i + 1, n, secondPoint, thirdPoint);
			System.out.println(thirdPoint);
			getKochCurve(i + 1, n, thirdPoint, end);
		}
	}

	private static Point getPoint(Point start, Point end, double multi) {
		double deltaX = (end.x - start.x) * multi;
		double deltaY = (end.y - start.y) * multi;
		return new Point(start.x + deltaX, start.y + deltaY);
	}

	private static Point getSecondPoint(Point start, Point end, Point first, Point third) {
		double x, y;
		if (first.y == third.y) {
			double deltaX = third.x - first.x;
			double len = Math.sqrt(Math.pow(deltaX, 2));		
			double height = Math.sqrt((Math.pow(len, 2) - Math.pow(len / 2.0, 2)));
			x = start.x + (end.x - start.x) / 2;
			if (start.x < end.x) {
				y = first.y + height;
			} else {
				y = first.y - height;
			}
		} else if (start.x < end.x && start.y < end.y) {
			x = start.x;
			y = third.y;
		} else if (start.x < end.x && start.y > end.y) {
			x = end.x;
			y = first.y;
		} else if (start.x > end.x && start.y < end.y) {
			x = end.x;
			y = first.y;
		} else {
			x = start.x;
			y = third.y;
		}
		return new Point(x, y);
	}
}


Measured memory_bytes: 40704
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9+ 7;
const int INF = 1e9;

int main() {
    ll N;
    cin >> N;
    set<ll> ans;
    auto check = [](ll base, ll temp) {
        while (base % temp == 0 && base > 1) base /= temp;
        return base % temp;
    };
    {
        ll base = N - 1;
        for (ll i = 1; i * i <= base; i++) {
            if (base % i != 0) continue;
            if (i != 1 && check(N, i) == 1) ans.insert(i);
            if (base != 1 && check(N, base / i) == 1) ans.insert(base / i);
        }
    }
    for (ll i = 1; i * i <= N; i++) {
        if (N % i != 0) continue;
        if (i != 1 && check(N, i) == 1) ans.insert(i);
        if (check(N, N / i) == 1) ans.insert(N / i);
    }
    cout << ans.size() << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

void quickSort(int numbers[], int array_size);
void q_sort(int numbers[], int left, int right);

int main(void){
    int i, j, k, n;
    int l[10000] = {0};
    int count = 0;
    
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &l[i]);
    }

    quickSort(l, n);

    for(i = 0; i < n; i++){
        for(j = i+1; j < n; j++){
            for(k = j+1; k < n; k++){
                if(l[k] + l[j] > l[i]) count++;
            }
        }
    }

    printf("%d\n", count);

    return 0;

}


void quickSort(int numbers[], int array_size){
    q_sort(numbers, 0, array_size - 1);
}



void q_sort(int numbers[], int left, int right){
    int pivot, l_hold, r_hold;

    l_hold = left;
    r_hold = right;
    pivot = numbers[left];
    while (left < right)
    {
        while ((numbers[right] <= pivot) && (left < right))
            right--;
        if (left != right)
        {
            numbers[left] = numbers[right];
            left++;
        }
        while ((numbers[left] >= pivot) && (left < right))
            left++;
        if (left != right)
        {
            numbers[right] = numbers[left];
            right--;
        }
    }
    numbers[left] = pivot;
    pivot = left;
    left = l_hold;
    right = r_hold;
    if (left < pivot)
        q_sort(numbers, left, pivot-1);
    if (right > pivot)
        q_sort(numbers, pivot+1, right);
}
    


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;



int main(void) {
  int n;
  cin >> n;
  set<int> a;
  rep(i,n){
    int p;
    cin >> p;
    if(a.count(p))a.erase(p);
    else a.insert(p);
  }
  cout << a.size() << endl;
  
}




Measured memory_bytes: 4864
#  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_B
#   : python3
#  2018.12.10 yonezawa

#from collections import deque
import sys
input = sys.stdin.readline
#import cProfile
from math import cos,sin,radians,sqrt

def Reflection(p1,p2):
    (x,y) = p2
    (tx,ty) = Projection(p1,(x,y))
    rx = (tx - x) * 2 + x 
    ry = (ty - y) * 2 + y
    return (rx,ry)


def Projection(p1,p2):
    (x1,y1,x2,y2) = p1
    if (x1*x1+y1*y1 > x2*x2 + y2*y2):
        (x1,y1,x2,y2) = (x2,y2,x1,y1)
    (x3,y3) = p2

    tx = x2 -x1
    ty = y2 -y1
    l = sqrt(tx*tx+ty*ty)

    nx = tx / l
    ny = ty / l
    pl = nx * (x3 - x1)  + ny * (y3 - y1)
    return (nx * pl + x1, ny * pl + y1 )


def main():
    (x1,y1,x2,y2) = map(int,input().split())
    for i in range(int(input())):
        (x3,y3) = map(int,input().split())
        print('{:.10f} {:.10f}'.format(*Reflection((x1,y1,x2,y2),(x3,y3))))

    
if __name__ == '__main__':
    main()
    #pr = cProfile.Profile()
    #pr.runcall(main)
    #pr.print_stats()


Measured memory_bytes: 5748
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int, int> P;

int n;
int m;
int p, q, r;

int main(){
	for(;;){
		scanf("%d", &n);
		if(n == 0) break;
		scanf("%d", &m);
		scanf("%d %d %d", &p, &q, &r);
		vector<P> va;
		vector<P> vb[3];
		va.push_back(P(1, n));
		for(int i = 0; i < m; i++){
			int x, y;
			scanf("%d %d", &x, &y);
			int cnt = 0;
			int layer = 0;
			for(int j = 0; j < va.size(); j++){
				int cnt2 = cnt + va[j].second - va[j].first + 1;
				if(layer == 0){
					if(cnt2 > y){
						vb[layer].push_back(P(va[j].first, va[j].first + x - cnt - 1));
						layer++;
						vb[layer].push_back(P(va[j].first + x - cnt, va[j].first + y - cnt - 1));
						layer++;
						vb[layer].push_back(P(va[j].first + y - cnt, va[j].second));
					}else if(cnt2 == y){
						vb[layer].push_back(P(va[j].first, va[j].first + x - cnt - 1));
						layer++;
						vb[layer].push_back(P(va[j].first + x - cnt, va[j].second));
						layer++;
					}else if(cnt2 > x){
						vb[layer].push_back(P(va[j].first, va[j].first + x - cnt - 1));
						layer++;
						vb[layer].push_back(P(va[j].first + x - cnt, va[j].second));
					}else if(cnt2 == x){
						vb[layer].push_back(P(va[j].first, va[j].second));
						layer++;
					}else{
						vb[layer].push_back(P(va[j].first, va[j].second));
					}
				}else if(layer == 1){
					if(cnt2 > y){
						vb[layer].push_back(P(va[j].first, va[j].first + y - cnt - 1));
						layer++;
						vb[layer].push_back(P(va[j].first + y - cnt, va[j].second));
					}else if(cnt2 == y){
						vb[layer].push_back(P(va[j].first, va[j].second));
						layer++;
					}else{
						vb[layer].push_back(P(va[j].first, va[j].second));
					}
				}else{
					vb[layer].push_back(P(va[j].first, va[j].second));
				}
				cnt = cnt2;
			}
			va.clear();
			for(int j = 2; j >= 0; j--){
				for(int k = 0; k < vb[j].size(); k++){
					va.push_back(vb[j][k]);
				}
				vb[j].clear();
			}
		}
		int res = 0;
		int cnt = 1;
		for(int i = 0; i < va.size(); i++){
			int cnt2 = cnt + va[i].second - va[i].first;
			int lb = max(va[i].first + p - cnt, va[i].first), rb = min(va[i].second + q - cnt2, va[i].second);
			res += max(0, min(rb, r) - lb + 1);
			cnt = cnt2 + 1;
		}
		printf("%d\n", res);
	}
	return 0;
}


Measured memory_bytes: 2784
#include <iostream>
#include <stdio.h>

typedef long long ll;

using namespace std;

#define rep(i,n) for(int i=0;i!=(n);++i)



int main(int argc, const char * argv[]) {
    
    int N;
    
    cin>>N;
    
    int Ans[N+1];
    for(int i=0;i!=N+1;++i){
        Ans[i]=0;
    }
    
    for(int x=1;x<=100;++x){
        for(int y=1;y<=100;++y){
            for(int z=1;z<=100;++z){
                ll tmp=x*x+y*y+z*z+x*y+y*z+z*x;
                if(tmp<=N){
                    Ans[tmp]++;
                }
            }
        }
    }
    
    for(int i=1;i<=N;++i){
        cout<<Ans[i]<<endl;
    }

}


Measured memory_bytes: 3628
class Node
  attr_reader :id, :left, :right
  attr_accessor :parent

  def initialize(id)
    @id = id
    @parent = nil
    @left = nil
    @right = nil
  end

  def left=(child)
    child.parent = self
    @left = child
  end

  def right=(child)
    child.parent = self
    @right = child
  end

  def sibling
    return nil unless parent

    [parent.left, parent.right].compact.find {|node| node.id != id }
  end

  def degree
    [left, right].compact.size
  end

  def depth
    ret = 0
    p = parent
    while p
      ret += 1
      p = p.parent
    end
    ret
  end

  def height
    left_height = left ? left.height + 1 : 0
    right_height = right ? right.height + 1 : 0
    [left_height, right_height].max
  end

  def type
    if parent.nil?
      'root'
    elsif left || right
      'internal node'
    else
      'leaf'
    end
  end

  def to_s
    parent_id = parent ? parent.id : -1
    sibling_id = sibling ? sibling.id : -1
    "node #{id}: parent = #{parent_id}, sibling = #{sibling_id}, degree = #{degree}, depth = #{depth}, height = #{height}, #{type}"
  end
end

if $PROGRAM_NAME == __FILE__
  n = gets.to_i

  nodes = Array.new(n) {|id| Node.new(id) }

  n.times do
    id, left_id, right_id = gets.chomp.split.map(&:to_i)
    parent = nodes[id]
    parent.left = nodes[left_id] if left_id != -1
    parent.right = nodes[right_id] if right_id != -1
  end

  nodes.each do |node|
    puts node
  end
end

Measured memory_bytes: 8768
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, M := sc.nextInt(), sc.nextInt()
	S := make([]int, M)
	C := make([]string, M)
	for i := 0; i < M; i++ {
		S[i] = sc.nextInt()
		C[i] = sc.nextStr()
	}
	ans := -1
	for i := 0; i < pow(10, N); i++ {
		str := strconv.Itoa(i)
		if len(str) < N {
			continue
		}
		ok := true
		for j := 0; j < M; j++ {
			if string(str[S[j]-1]) != C[j] {
				ok = false
				break
			}
		}
		if ok {
			ans = i
			break
		}
	}

	fmt.Fprintln(wtr, ans)
}


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

int main(){
  int n,m,x;
  cin >>n>>m>>x;
  vector<int>nedan(n);
  int tmp=-1;
  vector<vector<int>>a(n,vector<int>(m));
  for(int i=0;i<n;i++){
    cin >>nedan.at(i);
    for(int j=0;j<m;j++){
      cin >>a.at(i).at(j);
    }
  }
  for(int i=0;i<(1<<n);i++){
    int cost=0;
    vector<int>d(m,0);
    for(int j=0;j<n;j++){
      if(i>>j&1){
        for(int k=0;k<m;k++)
          d.at(k)+=a.at(j).at(k);
        cost+=nedan.at(j);
      }
    }
    sort(d.begin(),d.end());
    if(d.at(0)>=x){
      if(tmp==-1)
        tmp=cost;
      else
        tmp=min(tmp,cost);
    }
  }
  cout << tmp<<endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<set>
#include<unordered_set>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<tuple>
#include<iomanip>
#include<climits>
#define ll long long int
#define mod 1000000007
#define pi acos(-1)
using namespace std;

int main()
{
  // ios_base::sync_with_stdio(false);
  // cin.tie(NULL);
  // cout.tie(NULL);
  int n;
  cin>>n;
  int hash[10][10];
  for(int i=0;i<=9;i++)
  {
    for(int j=0;j<=9;j++)
    {
      hash[i][j]=0;
    }
  }
  //cout<<"aa";
  int digit=0;
  for(int i=1;i<=n;i++)
  {

    if(i<10)
      digit=1;
    else if(i<100)
      digit=2;
    else if(i<1000)
      digit=3;
    else if(i<10000)
      digit=4;
    else if(i<100000)
      digit=5;
    else
      digit=6;
    // if(i>=17)
    //  cout<<digit<<" ";
    int l = i%10;
    int r = i/((int)(pow(10,digit-1)+0.5));
    hash[r][l]++;
   // cout<<l<<" "<<r<<endl;
  }
  ll ans=0;
  for(int i=1;i<=9;i++)
  {
    for(int j=i;j<=9;j++)
    {
      if(i!=j)
        ans = ans+ (ll)(2*(hash[i][j]*hash[j][i]));
      else
        ans = ans+ (ll)(pow(hash[i][j],2)+0.5);
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256