akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
const Int Inf = 1e17;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rep(i,n) for(int(i)=0; i<n; i++)
#define rer(i,l,r) for(int i=l; i<=r; i++)
#define gnr(i,l,r) for(int i=r; i>=l; i--)
#define eb emplace_back
#define pri1(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(pri2i,n-1)cout<<a[pri2i]<<' '; cout<<a[n-1]<<'\n';}
#define prip(p) cout<<p.fi<<' '<<p.se<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

Int n,m,_,x,y,q;
string s,sb;
bool ok;
char cf,cb;

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

  cin>>n;
  if(n==0){pri1(0); return 0;}
  Int pl[20],mi[20]; pl[0]=1; mi[0]=2;
  rep(i,19)pl[i+1]=pl[i]+(1LL<<(2*(i+1)));
  rep(i,19)mi[i+1]=mi[i]+(1LL<<(2*(i+1)+1));
  if(n>0){
    rep(i,20)if(n<=pl[i]){m=2*i+1; break;}
  }else{
    rep(i,20)if(-n<=mi[i]){m=2*(i+1); break;}
  }
  V(char)ans(m); x=0;
  for(int i=m-1; i>=0; i--){
    if(i%2){
      if(x>n&&n-(x-(1LL<<i))<=pl[(i-1)/2]){
        ans[i]='1';
        x-=(1LL<<i);
      }else ans[i]='0';
    }else{
      if(x<n&&x+(1LL<<i)-n<=mi[(i-1)/2]){
        ans[i]='1';
        x+=(1LL<<i);
      }else ans[i]='0';
    }
  }
  reverse(ALL(ans));
  rep(i,m)cout<<ans[i];
  cout<<'\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define zmrl(x) (int)((x).size())
#define pb push_back
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int a,b,c,d; cin>>a>>b>>c>>d;
    int res = a*c;
    res=max(res, a*d);
    res=max(res, b*c);
    res=max(res, b*d);
    cout<<res;
    return 0;
}

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

using ll = long long;
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define INF 1e9
// constexpr ll INF = 1LL << 60;

int main(){
  int N, M, Q;
  cin >> N >> M >> Q;
  vector<vector<int>> sum(N+1, vector<int>(N+1,0));
  REP(i, M){
    int L, R;
    cin >> L >> R;
    sum[L][R]++;
  }
  REP(i, N+1){
    REP(j, N){
      sum[i][j+1] += sum[i][j];
    }
  }
  REP(j, N+1){
    REP(i, N){
      sum[i+1][j] += sum[i][j];
    }
  }
  REP(i, Q){
    int p, q;
    cin >> p >> q;
    p--, q--;
    cout << sum[q+1][q+1] - sum[q+1][p] - sum[p][q+1] + sum[p][p] << endl;
  }
  return 0;
}



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


int main(){
  ll N;
  cin>>N;
  ll ans=0;
  for(ll i=1;i<=N;i++){
    ll x=N/i;
    ans+=i*x*(x+1)/2;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;

const int N=1e7;

ll v[N+10];

ll ara[N+10];

int main()
{

   ll n,sum=0;

   cin>>n;

   for(ll i=1;i<=n;i++)
   {
       for(ll j=i;j<=n;j+=i)
       {
           ara[j]++;
       }
   }
   for(ll i=1;i<n;i++)
   {
       sum+=ara[i];
   }

   cout<<sum<<endl;
}










Measured memory_bytes: 11404
using System;
using System.Linq;

class Program
{
	static void Main(string[] args)
	{
		var input = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
		bool flag = false;

		for (int x = 0; x <= input[0]; x++)
		{
			if (flag) break;
			for (int y = 0; y <= input[0] - x; y++)
			{
				if ((1000 * x) + (5000 * y) + (10000 * (input[0] - x - y)) == input[1])
				{
					Console.WriteLine((input[0] - x - y).ToString() + " " + y.ToString() + " " + x.ToString());
					flag = true;
					break;
				}
				else if ((1000 * x) + (5000 * y) + (10000 * (input[0] - x - y)) < input[1])
				{
					break;
				}
			}
		}

		if (!flag)
		{
			Console.WriteLine("-1 -1 -1");
		}
	}
}

Measured memory_bytes: 11348
def counting_sort(A, B, k):
    n = len(A)
    C = [0]*(k+1)
    
    # 整数kがAに何回現れるかを数える(n)
    for j in range(n):
        C[A[j]] += 1    
        
    # k以下の整数がAに何回現れるかを数える(k)
    for j in range(1, k+1):
        C[j] = C[j] + C[j-1]        
    
    # Cの情報を利用して並べ替える(n)
    for j in range(n-1, -1, -1):
        B[C[A[j]] - 1] = A[j]
        C[A[j]] -= 1

n = int(input())
A = list(map(int, input().split() ))
B = [0]*len(A)

counting_sort(A, B, max(A))
print(' '.join(map(str, B)))


Measured memory_bytes: 240324
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>

using namespace std;

int main() {
  
  int X;
  cin >> X;
  
  while(true) {
    bool checker = true;
    for(int i = 2; i * i <= X; i++) {
      if(X % i == 0) {
        checker = false;
        break;
      }
    }
    if(checker) {
      break;
    }
    X++;
  }
  
  cout << X << endl;
}

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

int main(){
  int H,W;
  cin >>H >>W;
  string a[H];
  for(int i=0;i<H;i++){
    cin >> a[i];
  }
  int h[H];
  int w[W];
  for(int i=0;i<H;i++){
    h[i]=0;
    for(int j=0;j<W;j++){
      if(a[i].at(j)=='#'){
        h[i]=1;
      }
    }
  }
  for(int i=0;i<W;i++){
    w[i]=0;
    for(int j=0;j<H;j++){
      if(a[j].at(i)=='#'){
        w[i]=1;
      }
    }
  }
  for(int i=0;i<H;i++){
    if(h[i]==1){
      for(int j=0;j<W;j++){
      if(w[j]==1){
        cout<<a[i].at(j);
      }
      }
       cout << endl;
    }
  }
}
    
    
        
  


Measured memory_bytes: 256
import java.util.*;

public class Main {

	static final int mod = 998244353;
	// 木の集合
	static List<Integer> tree[];

	static class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {
		private static final long serialVersionUID = 6411527075103472113L;

		public Pair(final K key, final V value) {
			super(key, value);
		}
	}

	public static long dfs(int value) {
		long res = 1;
		for (int v : tree[value]) {
			res *= dfs(v);
			res %= (long) mod;
		}
		return (res + 1) % (long) mod;
	}

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Pair<Integer, Integer> robot[] = new Pair[n];
		tree = new List[n];
		for (int i = 0; i < n; ++i) {
			int x = sc.nextInt();
			int d = sc.nextInt();
			robot[i] = new Pair<Integer, Integer>(x, d);
		}
		sc.close();

		// xでソート
		Arrays.sort(robot, new Comparator<Pair<Integer, Integer>>() {
			public int compare(Pair<Integer, Integer> o1, Pair<Integer, Integer> o2) {
				return o1.getKey() - o2.getKey();
			}
		});

		// 木の頂点集合 但し、keyでソートされて保持される集合にする
		Set<Pair<Integer, Integer>> set = new TreeSet<Pair<Integer, Integer>>(new Comparator<Pair<Integer, Integer>>() {
			public int compare(Pair<Integer, Integer> o1, Pair<Integer, Integer> o2) {
				return o1.getKey() - o2.getKey();

			}
		});

		// 木の頂点集合＆部分木集合の構成
		for (int i = n - 1; i >= 0; --i) {
			int x = robot[i].getKey(), d = robot[i].getValue();
			tree[i] = new ArrayList<Integer>();
			while (!set.isEmpty()) {
				Pair<Integer, Integer> next = set.iterator().next();
				if (next.getKey() >= x + d)
					break;
				tree[i].add(next.getValue());
				set.remove(next);
			}
			set.add(new Pair<Integer, Integer>(x, i));
		}

		// 木dp
		long ans = 1;
		for (Pair<Integer, Integer> p : set) {
			int v = p.getValue();
			ans *= dfs(v);
			ans %= (long) mod;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 203172
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n = 0, m = 0;
  cin >> n >> m;
  vector<int> cnt(m + 1, 0);
  for(int i = 0; i < n; ++i) {
    int k = 0;
    cin >> k;
    for(int j = 0; j < k; ++j) {
      int x = 0;
      cin >> x;
      cnt[x] += 1;
    }
  }
  int ret = 0;
  for(int i = 1; i <= m; ++i) {
    if(cnt[i] == n) {
      ret += 1;
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include <iomanip>
#include<deque>
#include<stack>
#include<set>
#include <numeric>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;




int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================


	string S;
	cin >> S;

	if (S == "SUN") {
		cout << 7;
	}
	if (S == "MON") {
		cout << 7 - 1;
	}
	if (S == "TUE") {
		cout << 6 - 1;
	}
	if (S == "THU") {
		cout << 4 - 1;
	}
	if (S == "FRI") {
		cout << 3 - 1;
	}
	if (S == "SAT") {
		cout << 2 - 1;
	}
	if (S == "WED") {
		cout << 5 - 1;
	}





}




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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String s = br.readLine();
		int w = Integer.parseInt(br.readLine());

		StringBuilder ans = new StringBuilder();

		for (int i = 0; i < s.length(); i++) {
			if (i % w == 0) {
				ans.append(s.charAt(i));
			}
		}

		System.out.println(ans);

	}

}


Measured memory_bytes: 21076
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cmath>

using namespace std;

#define rep(i,b) for(int i=0; i<b; i++)

int t[200];
int c[200], l[200], h[200];

int dp[210][210];

int main(){
    int d,n; cin>>d>>n;
    rep(i,d) cin>>t[i];
    rep(i,n) cin>>l[i]>>h[i]>>c[i];

    rep(i,d){
        rep(j,n)if(l[j]<=t[i+1] && t[i+1]<=h[j]){
            rep(k,n)if(l[k]<=t[i] && t[i]<=h[k]){
                dp[i+1][j] = max(dp[i][k]+abs(c[j]-c[k]), dp[i+1][j]);
            }
        }
    }

    int ans = *max_element(dp[d-1], dp[d-1]+n);
    cout << ans << endl;
}

Measured memory_bytes: 1332
N = int(input())
A = list(map(int, input().split()))

# N が奇数なら、Aはすべて偶数であり、かつ0を除いてすべて1ペア、かつ0が1つあるはず
# N が偶数なら、Aはすべて奇数であり、かつすべて1ペア
# 上記を確認するための辞書
dic = {}

for a in A:
    if a in dic.keys():
        dic[a] += 1
    else: dic[a] = 1

flag = True
ini = N
if N % 2 == 1:
    if 0 in A:
        if dic[0] == 1:
            ini = 2
        else:
            flag = False
    else:
        flag = False
else:
    ini = 1

for i in range(ini,N,2):
    if not flag: break
    if i in dic:
        if dic[i] != 2:
            flag = False
    else: flag = False

if flag:
    print(2**(N//2)%(10**9+7))
else:
    print(0)

Measured memory_bytes: 14436
#include <stdio.h>
#include <stdlib.h>

int euk(int,int);

int main(){
  int i,j,l;
  int N;
  int X;
  scanf("%d %d",&N,&X);

  int x[N];
  for(i=1; i<=N; i++){
    scanf("%d ",&x[i-1]);
  }
  for(i=0; i<=N-1; i++){
    x[i] = abs(X - x[i]);
  }

  l = x[0];
  for(i=0; i<=N-1; i++){
    l = euk(l,x[i]);
  }
  printf("%d\n",l);
  return 0;
}

int euk(int a,int b){
  int r;
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}


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

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;

	vector< int> A(a), B(b), C(c);
	for (int &e : A) cin >> e;
	for (int &e : B) cin >> e;
	for (int &e : C) cin >> e;

	sort(begin(A), end(A));
	sort(begin(B), end(B));
	sort(begin(C), end(C));

	priority_queue< int, vector< int>, greater< int>> pq;

	LL res = 0;
	for (int i = 0; i < x; i++) {
		res += A.back();
		pq.emplace(A.back());
		A.pop_back();
	}

	for (int i = 0; i < y; i++) {
		res += B.back();
		pq.emplace(B.back());
		B.pop_back();
	}

	while (!C.empty()) {
		if (C.back() < pq.top()) {
			break;
		}

		res -= pq.top();
		res += C.back();
		C.pop_back();
		pq.pop();
	}

	cout << res << endl;
}

Measured memory_bytes: 2552
#include<bits/stdc++.h>
using namespace std;
bool a[1000];
signed main(){
  stack <int> st;
  int l;
  cin>>l;
  for(int i=1;i<=l;i++){
    int n;
    cin>>n;
    if(n>0){
      if(a[n]==0){
	st.push(n);
	a[n]++;
      }else{
	cout<<i<<"\n";
	return(0);
      }
    }else{
      if(st.empty()){
	cout<<i<<"\n";
	return(0);
      }else{
	if(st.top()==-n){
	  st.pop();
	  a[-n]=false;
	}else{
	  cout<<i<<"\n";
	  return(0);
	}
      }
    }
  }
  cout<<"OK\n";
}



Measured memory_bytes: 3096
#include<iostream>

using namespace std;
int main()
{
	int n = 0, h = 0, w = 0, a[1000], b[1000], c = 0;
	cin >> n >> h >> w;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		if (a[i] >= h) {
			if (b[i] >= w) {
				c++;
			}
		}
	}
	cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long N = Long.valueOf(scan.next());
		long M = Long.valueOf(scan.next());
		long sum = 0;
		if(M - N * 2 < 0) {
			sum = M / 2;
			N -= M / 2;
			M = 0;
		} else {
			sum += N;
			M -= N * 2;
			N = 0;
		}
		
		sum += M / 4;
		
		System.out.println(sum);
		
		scan.close();

	}

}


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

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	string s;
	cin >> s;

	int cnt_a = 0;
	int cnt_b = 0;
	int cnt = 0;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == 'c') {
			cout << "No" << endl;
			continue;
		}

		if (s[i] == 'a') {
			if (cnt < A + B) {
				cout << "Yes" << endl;
				++cnt;
			} else {
				cout << "No" << endl;
			}
		}

		if (s[i] == 'b') {
			cnt_b += 1;
			if ((cnt < A + B) && (cnt_b <= B)) {
				cout << "Yes" << endl;
				++cnt;
			} else {
				cout << "No" << endl;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 896
Module BBBBBBBB
    Sub Main(ByVal args() As String)
        Dim n As Integer = Console.ReadLine()
    	Dim ab As string = Console.ReadLine()
'    	Dim pn As string = 

    	dim a as integer= split(ab)(0) 
        dim b as integer= split(ab)(1) 
    	dim p(n) as string 
    	p = split(Console.ReadLine())


        dim q1l as integer = 0
        dim q1h as integer = a

        dim q2l as integer = a+1
        dim q2h as integer = b

        dim q3l as integer = b+1
        dim q3h as integer = 20
'     Console.WriteLine(q1l)
'     Console.WriteLine(q1h)
'     Console.WriteLine(q2l)
'     Console.WriteLine(q2h)
'     Console.WriteLine(q3l)
'     Console.WriteLine(q3h)

        dim q1 as integer =0
        dim q2 as integer =0
        dim q3 as integer =0
    
    	for i  as integer = 0 to n-1
    dim pi as integer = cint(p(i))
  '  Console.WriteLine(pi)
    
    if   q1l <= pi andalso  q1h >=pi then
      q1 += 1
    elseif q2l <= pi andalso  q2h>=pi then
      q2 += 1
    Else
            q3 +=1
    end if

        next
    
  if q1<=q2 then
    if q1<= q3 then
       Console.WriteLine(q1)
    else
      Console.WriteLine(q3)
    end if
  else
    if q2<= q3 then
       Console.WriteLine(q2)
    else
      Console.WriteLine(q3)
    end if
    end if
    
 '      Console.WriteLine(q1)
 '      Console.WriteLine(q2)
 '     Console.WriteLine(q3)


    End Sub
End Module


Measured memory_bytes: 13536
#include <iostream>

using namespace std;

int main () {
    int r, c;
    cin >> r >> c;

    int rc[r + 1][c + 1];
    for (int i = 0; i < r; i++)
        for (int j = 0; j < c; j++) cin >> rc[i][j];
    
    for (int i = 0; i < r + 1; i++) rc[i][c] = 0;
    for (int i = 0; i < c + 1; i++) rc[r][i] = 0;

    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            rc[i][c] += rc[i][j];
            rc[r][j] += rc[i][j];
            rc[r][c] += rc[i][j];
        }
    }

    for (int i = 0; i <= r; i++) {
        for (int j = 0; j <= c; j++) {
            if (j) cout << ' ';
            cout << rc[i][j];
        }
        cout << endl;
    }
}


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

int main() {
    int h, w;
    string a;
    cin >> h >> w;
    
    
    for (int i = 0; i < w + 2; i++) {
        cout << '#';
    }
    cout << endl;

    for (int i = 0; i < h; i++) {
        cin >> a;
        cout << '#' << a << '#' << endl;
    }

    for (int i = 0; i < w + 2; i++) {
        cout << '#';
    }
    cout << endl;

}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define ALL(x) x.begin(),x.end()

template<class T> using V = vector<T>;
template<class T> using V2 = V<V<T>>;



void solve(){
  vector<int> ten = {1,10,100,1000,10000,100000,1000000,10000000};
  int n; cin >> n; int ans = 0;
  FOR(i,1,n+1){
    int d;
    FOR(j,0,6){
      if(i<ten[j+1] && i >=ten[j]) {d = j+1;break;}
    }
    if(d%2==1) ans++;
  }
  cout << ans << endl;
}

int main(){
  solve();
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) throws IOException {
        execute();
    }

    private static void execute() throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println(checkBeautifulString(br.readLine()));
    }

    private static String checkBeautifulString(String string) {
        List<String> list = new ArrayList<>();
        for(char ch : string.toCharArray()) {
            String s = String.valueOf(ch);
            if (list.remove(s)) {
                continue;
            }
            list.add(s);
        }
        return list.isEmpty() ? "Yes" : "No";
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <cmath>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
using ull =unsigned long long;
const ll INF =1001001001;

//10億7。　　　100000007

//最大公約数
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*b/gcd(a,b);
}


int main(){
cout<<fixed<<setprecision(10);
//cin.tie(0); ios::sync_with_stdio(false);

  int a,s,d,f,g;
  cin>>a>>s>>d>>f>>g;
  
  if(a==0){cout<<1<<endl;}
  if(s==0){cout<<2<<endl;}
  if(d==0){cout<<3<<endl;}
  if(f==0){cout<<4<<endl;}
  if(g==0){cout<<5<<endl;}

  
}



Measured memory_bytes: 3596
def com(n,r,mod):
    k=min(r,n-r)
    C=1
    for i in range(1,k+1):
        C=(C*(n+1-i)*pow(i,mod-2,mod))%mod
    return C
x,y=map(int,input().split())
mod = 10 ** 9 + 7
n = (2 * y - x) // 3
m = (2 * x - y) // 3
if (x + y) % 3 != 0 or n<0 or m<0:
    print(0)
    exit()

print(com(n+m,n,mod))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+7 , mz = 1e9+7;
int val[N], top;

int main(){
    int n, k;
    char s[N];
    cin>>n>>k>>s;
    int x = 1;
    for(int i = 1 ; i < n ; i++){
        if( s[i] == s[i-1] ){
            x++;
            continue;
        }
        val[++top] = x;
        x = 1;
    }
    val[++top] = x;
    if( (k << 1) >= top - 1 ){
        cout<<n-1<<endl;
    }else{
        int sum = val[1] - 1,up = min(k<<1|1, top);
        for(int i = 2; i <= up; i++){
            sum += val[i];
        }
        for(int i = 2 + (k<<1); i <= top; i++){
            sum += val[i] - 1;
        }
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 768
// AOJ Volume 1 Problem 0178 TETORIS

#include <stdio.h>
#include <string.h>


int field[5002][6];

void print(void)
{
    int i, j;
    
    for (i = 10; i > 0; i--){
        for (j = 1; j <= 5; j++){
            if (field[i][j] == 0){
                printf("-");
            }
            else {
                printf("#");
            }
        }
        printf(":%d\n", field[i][0]);
    }
    for (j = 1; j <= 5; j++){
        printf("<%d>", field[0][j]);
    }
    printf("\n");
}
 
int main(void)
{
    int block;
    int i, j;
    int n, d, p, q;
    int pos;
    int cnt;

    while (1){
        scanf("%d", &n);
        
        if (n == 0){
            break;
        }
        
        for (i = 0; i <= 5; i++){
            for (j = 0; j <= 5001; j++){
                field[j][i] = 0;
            }
        }
        
        for (block = 0; block < n; block++){
            
            scanf("%d%d%d", &d, &p, &q);
            
            if (d == 2){
                // ツ縦ツづ個ブツδ債ッツクツづーツ置ツつュ
                for (i = field[0][q] + 1; i < field[0][q] + 1 + p; i++){
                    field[i][q] = 1;
                    field[i][0]++;
                }
                field[0][q] += p;
            }
            else {
                // ツ可。ツブツδ債ッツクツづ個暗環置ツづーツ仰づ淞づゥ
                pos = 0;
                for (i = q; i < q + p; i++){
                    if (pos < field[0][i]){
                        pos = field[0][i];
                    }
                }
                
                // ツブツδ債ッツクツづーツ置ツつュ
                for (i = q; i < q + p; i++){
                    field[pos + 1][i] = 1;
                    field[0][i] = pos + 1; // ツ暗環置ツ湘ョツ陛アツづ個更ツ新
                }
                field[pos + 1][0] += p;
            }
//    print();
            // ツブツδ債ッツクツづーツ湘つキ
            for (i = 5000; i >= 1; i--){
                if (field[i][0] == 5){
                    memcpy(&field[i][0], &field[i + 1][0], (5000 - i) * sizeof(int));
                }
            }
            
            // ツつサツづェツつシツづェツづ個療アツづ個暗ェツ氾板債つつ「ツ湘ェツ渉環づーツ仰づ淞づゥ
            for (i = 1; i <= 5; i++){
                for (j = 5000; j > 0 && field[j][i] == 0; j--);
                field[0][i] = j;
            }
//    print();
                
        }
        // ツ残ツづつスツブツδ債ッツクツづーツ青板つヲツづ表ツ篠ヲツつキツづゥ
        cnt = 0;
        for (i = 1; i <= 5000 && field[i][0] != 0; i++){
            cnt += field[i][0];
        }
        printf("%d\n", cnt);
    }
    
    return (0);
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
long long dp[50][51][2501];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, a;
  cin >> n >> a;
  int x[n];
  for (int i = 0; i < n; i++) cin >> x[i];
  long long res = 0;
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < n; i++) dp[i][0][0] = 1;
  dp[0][1][x[0]] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < n + 1; j++) {
      for (int k = 0; k < 2501; k++) {
        if (k - x[i] >= 0) dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i]];
        else dp[i][j][k] = dp[i - 1][j][k];
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    res += dp[n - 1][i][i * a];
  }
  cout << res << "\n";
  return 0;
}

Measured memory_bytes: 50048
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
//  cout.precision(15); cout << fixed;

int main() {
  int n, k; cin >> n >> k;
  vector<int> X(n);
  loop(i,0,n) cin >> X[i];
  int t = 0;
  loop(i,0,n) {
    t += 2 * min(X[i], abs(k-X[i]));
  }
  cout << t << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(const T a, const T b){return a>=0 ? a/b : (a+1)/b-1;}
template<class T> T div_ceil(const T a, const T b){return a>=0 ? (a-1)/b+1 : a/b;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    int n, K;
    scanf("%d%d", &n, &K);
    double sum[n+1];
    sum[0] = 0;
    rep(i, n){
        double p;
        scanf("%lf", &p);
        sum[i+1] = (p+1) / 2;
    }
    partial_sum(sum, sum+n+1, sum);
    double ans = 0;
    rep(i, n-K+1) chmax(ans, sum[i+K] - sum[i]);
    printf("%.20lf\n", ans);
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main()
{
    int n,x;
    long long int all = 0;
    scanf("%d %d", &n, &x);
    int a[n];
    for(int i = 0; i < n; i++){
        scanf("%d", a+i);
        all += a[i];
    }
    if(all < x){
        printf("%d\n", n-1);
        return 0;
    }
    qsort(a, n, sizeof(int), compare_int);
    int cnt = 0;
    while(x > 0 && cnt < n){
        if(x < a[cnt]){
            break;
        }
        x -= a[cnt];
        cnt++;
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    int ans = 3;
    bool f = false;
    int idx = 1;
    //yoko
    if(s[0] != t[0]){
        ans *= 2;
        idx++;
        f = true;
    }
    int tate = 0, yoko = 0;
    rep(i, idx, n){
        //tate
        if(s[i] == t[i]){
            if(f == false){
                tate++;
                ans = ans * 2 % mod;
            }
            f = false;
        }else{//yoko
            yoko++;
            if(f == false){
                ans = ans * 2 % mod;
            }else{
                ans = ans * 3 % mod;
            }
            f = true;
            i++;
        }
    }
    // cout << tate <<" " << yoko << endl;
    cout << ans << endl;
}

Measured memory_bytes: 256
let print_a_chess h w =
  let buf = Buffer.create 256 in
  let rec loop i j =
    if i >= h then Buffer.contents buf
    else if j = w then (Buffer.add_char buf '\n'; loop (i+1) 0)
    else (if (i+j) mod 2 = 0 then Buffer.add_char buf '#'
          else Buffer.add_char buf '.';
          loop i (j+1))
  in print_endline (loop 0 0)

let () =
  let rec loop () =
    let line = read_line () in
    let h,w = Scanf.sscanf line "%d %d" (fun h w -> h,w) in
    if (h,w) = (0,0) then ()
    else loop (print_a_chess h w);
  in loop ()

Measured memory_bytes: 2464
// id: ALDS1_3_A
// CPU: 00:00sec  Memory: KB
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <ctype.h>

#define MAX_SIZE 100
#define LEN 6

typedef int Item;
struct stack_type {
	Item *contents;
	int top;
	int size;
};
typedef struct stack_type *Stack;

Stack create(int size);
void destroy(Stack s);
void make_empty(Stack s);
bool is_full(Stack s);
bool is_empty(Stack s);
void push(Stack s, Item i);
Item top(Stack s);
Item pop(Stack s);
static void terminate(const char *message);

int main(void)
{
	Stack operands = create(MAX_SIZE);
	char str[LEN + 1];
	//FILE *fp = fopen("d:\\data\\oj\\aojALDS1_3_A.txt", "r");

	while ( fscanf(stdin, "%s", str) != EOF )
		if ( isdigit(str[0]) )
			push(operands, atoi(str));
		else {
			char operator = str[0];
			int lhs, rhs, res;

			rhs = pop(operands);
			lhs = pop(operands);

			switch ( operator ) {
				case '+':
					res = lhs + rhs;
					break;
				case '-':
					res = lhs - rhs;
					break;
				case '*':
					res = lhs * rhs;
					break;
			}

			push(operands, res);
		}

	printf("%d\n", pop(operands));

	//fclose(fp);
	destroy(operands);

	return 0;
}

Stack create(int size)
{
	Stack s = malloc(sizeof(struct stack_type));
	if ( s == NULL )
		terminate("Error in create: stack could not be created.");

	s->contents = malloc(sizeof(Item) * size);
	if ( s->contents == NULL ) {
		destroy(s);
		terminate("Error in create: fail to allocate space for contents.");
	}
	s->top = 0;
	s->size = size;

	return s;
}

void destroy(Stack s)
{
	free(s->contents);

	free(s);
}

void make_empty(Stack s)
{
	s->top = 0;
}

bool is_full(Stack s)
{
	return s->top == s->size;
}

bool is_empty(Stack s)
{
	return s->top == 0;
}

void push(Stack s, Item i)
{
	if ( is_full(s) ) {
		destroy(s);
		terminate("Error in push: stack is full.");
	}

	s->contents[s->top++] = i;
}

Item top(Stack s)
{
	if ( is_empty(s) ) {
		destroy(s);
		terminate("Error in top: stack is empty.");
	}

	return s->contents[s->top - 1];
}

Item pop(Stack s)
{
	if ( is_empty(s) ) {
		destroy(s);
		terminate("Error in pop: stack is empty.");
	}

	return s->contents[--s->top];
}

static void terminate(const char *message)
{
	printf("%s\n", message);
	exit(EXIT_FAILURE);
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(all(a));

    ll left = -LINF, right = LINF;
    while (right - left > 1){
        ll mid = (left + right) / 2;
        // 積がmid以下になるペアの数を求める
        // この数がk以上ならright, 未満ならleft
        ll sum = 0;
        for (int i = 0; i < n; ++i) {
            if (a[i] > 0) {
                ll p = mid >= 0 ? mid / a[i] : (mid - (a[i] - 1)) / a[i];
                sum += upper_bound(all(a), p) - a.begin();
            }
            else if (a[i] == 0) {
                if (mid >= 0) sum += n;
            }
            else {
                ll p = mid >= 0 ? mid / a[i] : (mid + (a[i] + 1)) / a[i];
                sum += n - (lower_bound(all(a), p) - a.begin());
            }
            if (a[i] * a[i] <= mid) sum--;
        }
        sum /= 2;
        if (sum >= k) right = mid;
        else left = mid;
    }

    cout << right << endl;
}



Measured memory_bytes: 4824
#include <bits/stdc++.h>
// #include "ane.cpp"

const int INF  = 1e9;
const long long INFLL = 1e18;
const int NMAX = 100005;
const int MMAX = 100005;
const int KMAX = 1005;
const int MOD  = 1e9 + 7;
using namespace std;

// comment to disable debug functions
#define DEBUG

// frequently used macros

#if __cplusplus >= 201103L
#define ALL(v) begin(v),end(v)
#define SORT(v) sort(begin(v), end(v))
#define FIND(v,x) find(begin(v), end(v), (x))
#else
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(v.begin(), v.end())
#define FIND(v,x) find(v.begin(), v.end(), (x))
#endif

#define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \
memset((from), 0, sizeof(from)); } while(0)
#ifdef DEBUG
#define DUMP(x) do{ std::cerr << (#x) << ": " << x << std::endl; }while(0)
#else
#define DUMP(x) do{}while(0)
#endif

// frequent used aliases
typedef long long ll;
typedef pair<int, int> p;
typedef pair<ll, int> lp;
typedef pair<ll, ll> llp;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<vec> mat;
typedef vector<vecll> matll;

// frequently used constants
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};

// frequently used structs
struct edge{
  int to,cost;
};

// printf for debug
#ifndef DEBUG
void debug(const char* format, ...){}
#else
void debug(const char* format, ...){
  va_list arg;
  va_start(arg, format);
  vprintf(format, arg);
  va_end(arg);
}
#endif

// dump vector
#ifdef DEBUG
#define DUMPV(v, c) do{       \
  printf("%s: ", #v);         \
  for (int i = 0; i < (c); ++i) \
  {                           \
  cout << (v)[i] << " ";      \
  }                           \
  cout << endl;               \
} while(0)
#else
#define DUMPV(v,c)
#endif

// std::fill of multi dimensions
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
  std::fill( (T*)array, (T*)(array+N), val );
}

// binary search
ll BSearch(ll _begin, ll _end, bool (*f)(int)){
  ll mid;
  while(_end - _begin > 1LL) {
  mid = (_begin + _end) / 2LL;
  if(f(mid)) {
    debug("BSearch: f(%d) == true\n", mid);
    _end = mid;
  }
  else
  {
    debug("BSearch: f(%d) == false\n", mid);
    _begin = mid;
  }
  }
  return _end;
}


ll N,M,K,A,B,C,D,E;
int dp[NMAX] = {};

string S;
vec v;

ll ans = {};

void solve(){
  // main algorithm

}
void debug(){
  // output debug information

}
void answer(){
  // output answer
  cout << ans << endl;
}
int main(int argc, char const *argv[])
{
  // operate inputs

  // Fill(dp, -1);
  char ch[3];
  cin >> ch[0] >> ch[1] >> ch[2];
  ans = (int)ch[0] - '0' + ch[1] - '0' + ch[2] - '0';
  solve();
  #ifdef DEBUG
  debug();
  #endif
  answer();

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define el '\n'
typedef unsigned long long int ull;
typedef  unsigned int ui;
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int a,b;
    cin>>a>>b;
    if(a>8 || b>8)
        cout<<":("<<el;
    else
        cout<<"Yay!"<<el;



    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
#define MO 1000000007
using namespace std;
int n,m,K,st,ed;
int dp[N][3];
vector<int>P[N];
struct node {
	int a,b,c;
};
void spfa(){
	memset(dp,0x3f,sizeof(dp));
	queue<node>Q;
	Q.push((node){st,0,0});
	dp[st][0]=0;
	while(!Q.empty()){
		node x=Q.front();
		Q.pop();
		if(dp[x.a][x.b]<x.c)continue;
		for(int i=0;i<P[x.a].size();i++){
			int a=P[x.a][i],b=(x.b+1)%3,c=x.c+(x.b+1)/3;
			if(dp[a][b]>c){
				dp[a][b]=c;
				Q.push((node){a,b,c});
			}
		}
	}
}
void solve(){
	scanf("%d %d",&n,&m);
	for(int a,b,i=1;i<=m;i++){
		scanf("%d %d",&a,&b);
		P[a].push_back(b);
	}
	scanf("%d %d",&st,&ed);
	spfa();
	if(dp[ed][0]==0x3f3f3f3f)dp[ed][0]=-1;
	printf("%d\n",dp[ed][0]);
}
int main(){
	solve();
	return 0;
}

Measured memory_bytes: 6912
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int a[4][4], f[4][4], n;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    FOR(i,1,3) FOR(j,1,3) cin >> a[i][j];
    cin >> n;
    FOR(i,1,n) {
        int x;
        cin >> x;
        FOR(j,1,3)
            FOR(k,1,3)
                if (a[j][k] == x) f[j][k] = 1;
    }
    FOR(i,1,3) {
        if (f[i][1] && f[i][2] && f[i][3]) {
            cout << "Yes";
            return 0;
        }
        if (f[1][i] && f[2][i] && f[3][i]) {
            cout << "Yes";
            return 0;
        }
    }
    if (f[1][1] && f[2][2] && f[3][3]) {
        cout << "Yes";
        return 0;
    }
    if (f[1][3] && f[2][2] && f[3][1]) {
        cout << "Yes";
        return 0;
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
dat = list(map(int, input().split()))

dat2 = []
m = -1
#print(dat[:k])
n = sum(dat[:k])
dat2.append(n)
m = n
mind = 0
for i in range(1, len(dat) - k ):
    #print("in/out")
    #print(dat[k+i])
    #print(dat[i])
    n += dat[k+i]
    n -= dat[i]
    dat2.append(n)
    if n > m:
        m = n
        mind = i + 1


#print(dat2)
#print(m)
#print(mind)

r = 0
for i in range(mind, mind + k):

    r += (dat[i] + 1) / 2

print(r)


Measured memory_bytes: 71792
#include <bits/stdc++.h>
#define inf 0x6fffffff
using namespace std;
const int N=5e6+10;
typedef long long ll;
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
ll gcd(ll a,ll b){return (!b)?a:gcd(b,a%b);}
int main()
{
    ll a=read(),b=read(),c=read(),d=read();
    swap(a,b);
    ll lm=c*d/gcd(c,d);b--;
    cout<<(a-a/c-a/d+a/lm)-(b-b/c-b/d+b/lm)<<endl;
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    int h,w,k;cin>>h>>w>>k;
    vector<string> cake(h);
    for(int i=0;i<h;i++)cin>>cake[i];
    vector<vector<int>> ans(h,vector<int>(w));
    int num=0;bool first;
    for(int i=0;i<h;i++){
        if(cake[i].find('#')==string::npos)continue;
        first=true;
        num++;
        for(int j=0;j<w;j++){
            if(first){
                ans[i][j]=num;
                if(cake[i][j]=='#')first=false;
            }
            else{
                if(cake[i][j]=='#')num++;
                ans[i][j]=num;
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(ans[i][j]!=0){
                int up=i,down=i;
                while(up>0){
                    up--;
                    if(ans[up][0]==0){
                        for(int k=0;k<w;k++){
                            ans[up][k]=ans[i][k];
                        }
                    }
                    else break;
                }
                while(down<h-1){
                    down++;
                    if(ans[down][0]==0){
                        for(int k=0;k<w;k++){
                            ans[down][k]=ans[i][k];
                        }
                    }
                    else break;
                }
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(j==w-1)cout<<ans[i][j]<<endl;
            else cout<<ans[i][j]<<" ";
        }
    }
}


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

int main(){
    int n,k;
    cin>>n>>k;
    int a[100]={};
    for(int i=0;i<k;i++){
        int d;
        cin>>d;
        for(int j=0;j<d;j++){
            int p;
            cin>>p;
            a[p-1]++;
        }
    }
    int num=0;
    for(int i=0;i<n;i++){
        if(a[i]==0){
            num++;
        }
    }
    cout<<num<<endl;
}


Measured memory_bytes: 3636
from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
#from functools import lru_cache   #use @lru_cache(None)
if os.path.exists('in.txt'): sys.stdin=open('in.txt','r')
if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w')
#
def input(): return sys.stdin.readline()
def mapi(arg=0): return map(int if arg==0 else str,input().split())
#------------------------------------------------------------------
x = int(input())
def power(x,y):
    res = 1
    #print(x,y)
    while y>0:
        if y%2:
            res*=x
        x*=x
        y//=2
        #print(x,y)
    return res
def bs(n):
    l = -250
    r = 250
    while r-l>=0:
        mid = (l+r)//2
        tmp = power(mid,5)
        if tmp==n:
            return True, mid
        elif tmp<n:
            #print(mid,tmp,n)
            l = mid+1
        else:
            r = mid-1
    if power(l,5)==n:
        return True,l
    elif power(r,5)==n:
        return True,r
    return False,0
for i in range(-250,250):
    key = power(i,5)-x
    f,b = bs(key)
    if f:
        print(i,b)
        break


Measured memory_bytes: 68540
# shell sort

def insertion_sort(a, n, g, cnt):
    for i in range(g, n):
        v = a[i]
        j = i - g
        while j>=0 and a[j]>v:
            a[j+g] = a[j]
            j = j - g
            cnt += 1
        a[j+g] = v

    return cnt


def shell_sort(a, n, G, cnt):
    for i in range(m):
        cnt = insertion_sort(a, n, G[i], cnt)
    return cnt


# input
N = int(input())
nums = [0]*N
for i in range(N):
    nums[i] = int(input())

# initialization
G = [1]
h = 1
while h<N:
    h = 3*h + 1
while h>1:
    h = (h - 1) // 3
    G.append(h)
G = sorted(list(set(G)), reverse=True)
m = len(G)
cnt = 0

# sorting
cnt = shell_sort(nums, N, G, cnt)

# output
print(m)
print(" ".join(map(str, G)))
print(cnt)
for i in range(N):
    print(nums[i])



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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000LL
#define MOD 1000000009
#define EPS 1E-9

const int MAX_V = 1000;
ll dp[2][MAX_V][MAX_V];
int E, V;
int a, b;
ll c, t;
int k;
int p, q, r;

int main()
{
  //  while((cin >> E >> V) && E && V){
  while(scanf(" %d %d", &E, &V) && E && V){
    rep(i, 101) rep(j, 101) dp[0][i][j] = dp[1][i][j] = INF;

    rep(i, E){
      //      cin >> a >> b >> c >> t;
      scanf(" %d %d %d %d", &a, &b, &c, &t);
      a-=1;  b-=1;
      dp[0][a][b] = dp[0][b][a] = c;
      dp[1][a][b] = dp[1][b][a] = t;
    }

    rep(b, 2) rep(k, V) rep(i, V) rep(j, V) minup(dp[b][i][j], dp[b][i][k] + dp[b][k][j]);

    //    cin >> k;
    scanf(" %d", &k);
    while(k--){
      //      cin >> p >> q >> r;
      scanf(" %d %d %d", &p, &q, &r);
      //      cout << dp[r][p-1][q-1] << endl;
      printf("%lld\n", dp[r][p-1][q-1]);
    }
  }

  return 0;
}

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

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

    vector<int> a(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    cout << a.back() - a.front() << endl;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  int h[n];
  rep(i, n) cin >> h[i];
  
  ll score[n+k];
  rep(i, n+k) score[i] = pow(10, 10);
  
  score[0] = 0;
  
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j <= k; ++j) {
      score[i+j] = min(score[i+j], score[i] + abs(h[i] - h[i + j]));
    }
  }
  
  cout << score[n-1];
  
  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int t;
  cin>>t;
  while(t--){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    int cu=0,cd=0;
    for(int i=0;i<n-1;i++){
      if(a[i]<a[i+1]) cu=max(cu,a[i+1]-a[i]);
      else cd=max(cd,a[i]-a[i+1]);
    }
    cout<<cu<<" "<<cd<<endl;
  }
  return 0;
}

Measured memory_bytes: 3008
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	if(a+b==15)cout<<"+"<<endl;
	else if(a*b==15)cout<<"*"<<endl;
	else cout<<"x"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

ll modpow(ll x, ll b){
  ll res = 1;
  while(b){
    if(b&1)res = res * x % MOD;
    x = x * x % MOD;
    b>>=1;
  }
  return res;
}

ll modinv(ll x){
  return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
  if(was_output)cout << " ";
  cout << a;
  was_output = true;
}
void outendl(){
  was_output = false;
  cout << endl;
}
ll in(){
  ll res;
  scanf("%lld", &res);
  return res;
}

template<class t>
istream& operator>>(istream&is, vector<t>&x){
  for(auto &i:x)is >> i;
  return is;
}

template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
  is >> x.first >> x.second;
  return is;
}

template<class t>
void in(t&x){
  cin >> x;
}

ll n;
ll x;

ll factorial(ll x){
  if(x<=1)return 1;
  static vector<ll> memo(n*2,-1);
  ll &it = memo[x];
  if(it>=0)return it;
  return it = x * factorial(x-1) % MOD;
}

ll C(ll a,ll b){
  return factorial(a) * modinv(factorial(b)*factorial(a-b)%MOD)%MOD;
}

void input(){
  n = in();
  x = in();
}

int cul_max(int x){
  static int res = -1;
  if(res>=0)return res;
  auto cul_left = [](int x){
                    int res = 0;
                    while(x){
                      ++res;
                      x>>=1;
                    }
                    return res;
                  };
  return res=bit(cul_left(x));
}

vvector<ll> dp_vector(){
  return vvector<ll>(n+1,vector<ll>(cul_max(x),0));
}

ll func(){
  vvector<ll> dp = dp_vector();
  vvector<ll> ndp = dp_vector();
  dp[0][0] = 1;
  rep(i,x+1){
    rep(q,2){
      rep(k,cul_max(x)){
        ll sum = 0;
        for(int j=q;j<=n;j+=2){
          sum += dp[j][k];
          sum %= MOD;
          ndp[j][k] += sum;
          ndp[j][k] %= MOD;
          if(j+1<=n){
            ndp[j+1][k^i] += sum;
            ndp[j+1][k^i] %= MOD;
          }
        }
      }
    }
    rep(j,ndp.size()){
      rep(k,ndp[j].size()){
        dp[j][k]=ndp[j][k];
        ndp[j][k]=0;
      }
    }
  }
  return dp[n][x];
}

int main(){

  input();
  cout << func() << endl;

  return 0;
}




Measured memory_bytes: 6848
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

// Thursday 3/19/20

//  

//  158 B Count Balls

int main() {
	long long value, N, A, B;
	cin >> N >> A >> B;
	value = (N / (A + B)) * A;
	long long val = (N % (A + B));
	if (val > A) {
		value += A;
	}
	else {
		value += val;
	}
	cout << value;
	return 0;
}


Measured memory_bytes: 256