akhauriyash/Code-Regression huggingface dataset:
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
#include<functional>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;


vector<vector<pair<int, ll>>> g;
vector<vector<int>> rev;
constexpr ll inf = 1e18;


int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n, m;
  ll p;
  cin >> n >> m >> p;
  g.resize(n);
  rev.resize(n);

  for(int i = 0; i < m; i++) {
    int a, b , c;
    cin >> a >> b >> c;
    a--, b--;
    g[a].emplace_back(b, p - c);
    rev[b].emplace_back(a);
  }

  vector<int> reachable(n);

  function<void(int)> dfs = [&](int i) {
    if(reachable[i]) return;
    reachable[i] = 1;
    for(auto j : rev[i]) dfs(j);
  };

  dfs(n-1);
  assert(reachable[0]);

  int loop = 0;
  bool update = 1;
  vector<ll> dist(n, inf);
  dist[0] = 0;
  while(update) {
    update = 0;
    if(loop >= n + 1) {
      cout << -1 << endl;
      return 0;
    }
    loop++;

    for(int i = 0; i < n; i++) if(reachable[i]) if(dist[i] < inf) {
      for(auto p : g[i]) {
        ll j, c;
        tie(j, c) = p;
        if(not reachable[j]) continue;
        if(dist[j] > dist[i] + c) {
          dist[j] = dist[i] + c;
          update = 1;
        }
      }
    }
  }
  cout << max<ll>(-dist[n-1], 0) << endl;
  return 0;
}


Measured memory_bytes: 768
// A.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main(int argc, char* argv[]) {
    int n;
    cin >> n;
    int a, g;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        if (i) {
            g = gcd(g, a);
        } else {
            g = a;
        }
    }
	cout << g << endl;
	return 0;
}


Measured memory_bytes: 3592
import sys
input = sys.stdin.readline

N = int(input())
graph = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

q = []
checked = [-1]*N
for n in range(N):
    if len(graph[n]) == 1:
        q.append(n)
        checked[n] = 0

ok = False
while q:
    posiq = []
    for p in q:
        update = False
        for np in graph[p]:
            if checked[np] == -1:
                checked[np] = checked[p] + 1
                update = True
                posiq.append(np)
            elif checked[np] == checked[p] + 1:
                ok = True
                break
            elif checked[np] == checked[p]:
                update = True
        if not update:
            ok = True
            break
    
    q = set()
    for p in posiq:
        for np in graph[p]:
            if checked[np] == -1 and not np in q:
                c = 0
                for mp in graph[np]:
                    if checked[mp] == -1:
                        c += 1
                    if c >= 2: break
                if c <= 1:
                    q.add(np)
    for np in q:
        checked[np] = checked[p] + 1

print("First" if ok else "Second")            


Measured memory_bytes: 24272
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

N = int(input())
vec = [[] for _ in range(N)]
for _ in range(N - 1) :
  a, b = map(int, input().split())
  vec[a-1].append(b-1)
  vec[b-1].append(a-1)
  
q = [(0, -1, 0)]
dist = [0] * N
cnt = [0, 0]
while q :
  cur, pre, cost = q.pop()
  dist[cur] = cost
  cnt[cost] += 1
  for nex in vec[cur] :
    if nex != pre :
      q.append((nex, cur, cost ^ 1))

one = 1
two = 2
three = 3
if cnt[0] < (N + 2) // 3 :
  for i in range(N) :
    if dist[i] == 0 :
      dist[i] = three
      three += 3
    elif one <= N :
      dist[i] = one
      one += 3
    elif two <= N :
      dist[i] = two
      two += 3
    else :
      dist[i] = three
      three += 3
      
elif cnt[1] < (N + 1) // 3 :
  for i in range(N) :
    if dist[i] == 1 :
      dist[i] = three
      three += 3
    elif one <= N :
      dist[i] = one
      one += 3
    elif two <= N :
      dist[i] = two
      two += 3
    else :
      dist[i] = three
      three += 3
      
else :
  for i in range(N) :
    if dist[i] == 0 and one <= N :
      dist[i] = one
      one += 3
    elif dist[i] == 1 and two <= N :
      dist[i] = two
      two += 3
    else :
      dist[i] = three
      three += 3
      
print(*dist)

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

int main() {
  long long N, A[5];
  cin >> N >> A[0] >> A[1] >> A[2] >> A[3] >> A[4];
  sort(A, A + 5);
  cout << (N + A[0] - 1) / A[0] + 4 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>

using namespace std;

const int mod = 1000000007;

#define NMAX 200002

// Aho-Corasick
const int K = 30;

struct vertex {
  int next[K];
  bool leaf;
  int p;
  char pch;
  int link;
  int go[K];
};
 
vertex t[NMAX+1];
int sz;
 
void init() {
	t[0].p = t[0].link = -1;
	memset(t[0].next, 255, sizeof(t[0].next));
	memset(t[0].go, 255, sizeof(t[0].go));
	sz = 1;
}
 
int add_string(char *s) {
	int v = 0;
	for (int i=0; s[i]; ++i) {
		int c = s[i]-'a';
		if (t[v].next[c] == -1) {
			memset(t[sz].next, 255, sizeof(t[sz].next));
			memset(t[sz].go, 255, sizeof(t[sz].go));
			t[sz].link = -1;
			t[sz].p = v;
			t[sz].pch = c;
			t[v].next[c] = sz++;
		}
		v = t[v].next[c];
	}
	t[v].leaf = true;
  return v;
}

int go(int v, int c);

int get_link(int v) {
	if (t[v].link == -1) {
		if (v == 0 || t[v].p == 0)
			t[v].link = 0;
		else
			t[v].link = go(get_link(t[v].p), t[v].pch);
  }
	return t[v].link;
}
 
int go(int v, int c) {
	if (t[v].go[c] == -1) {
		if (t[v].next[c] != -1)
			t[v].go[c] = t[v].next[c];
		else
			t[v].go[c] = v==0 ? 0 : go(get_link(v), c);
  }
	return t[v].go[c];
}
// Aho-Corasick end

void preprocess(int *val, int idx, char *seq, int t) {
	if (idx == 3) {
		seq[t] = '\0';
		//cout << seq << endl;
		add_string(seq);
		return;
	}

	if (val[idx] == 0) {
		preprocess(val, idx+1, seq, t);
	} else {
		int v = val[idx];
		for (int i=1; i<=v; i++) {
			seq[t] = i + 'a';
			val[idx] = v - i;
			preprocess(val, idx, seq, t+1);
		}
		val[idx] = v;
	}
}

int pot[44], dp[NMAX][44];

int solve(int v, int q) {
	if (t[v].leaf) return pot[q];
	if (!q) return 0;

	int &ret = dp[v][q];
	if (ret != -1) return ret;
	ret = 0;

	for (int i=1; i<=10; i++) {
		ret += solve(go(v, i), q-1);
		if (ret >= mod) ret -= mod;
	}

	return ret;
}

int main() {
	int n, val[3];
	char seq[20];
	cin>>n>>val[0]>>val[1]>>val[2];
	
	init();
	preprocess(val, 0, seq, 0);
	//cout << sz << endl;

	pot[0] = 1;
	for (int i=1; i<=n; i++)
		pot[i] = ((long long)pot[i-1] * 10LL) % mod;

	memset(dp, -1, sizeof(dp));
	cout << solve(0, n) << endl;

	return 0;
}

Measured memory_bytes: 43008
#include<stdio.h>
#define R 0
#define W 1
#define MAX 200000

int searchW(char list[], int n, int s) {
  int i;

  for (i=s; i<n; i++) {
    if (list[i]=='W') return i;
  }
  return -1;
}

int searchR(char list[], int s) {
  int i;

  for(i=s; 0<=i; i--) {
    if(list[i] == 'R') return i;
  }
  return -1;
}

int main() {
  int n;
  char list[MAX];
  int i, j;
  int nR, nW;
  char temp;
  int count=0;

  scanf("%d", &n);
  scanf("%s", list);

  i=0; j=n-1;
  while(1) {
    nW = searchW(list, n, i);
    nR = searchR(list, j);
    if(nW == -1 || nR == -1 || nW>=nR) break;
    list[nW] = 'R';
    list[nR] = 'W';
    count++;
    i = nW;
    j = nR;
    //printf("%s\n", list);
  }
  printf("%d", count);
  return 0;
}

Measured memory_bytes: 2332
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <string>
using namespace std;

int N, M;
int H[1502], W[1502];

int sum_h(int i, int j){
	return (H[i] - H[j+1]);
}

int sum_w(int i, int j){
	return (W[i] - W[j+1]);
}

int main(){
	while( cin >> N >> M, N || M ){
		vector<int> h(N), w(M);
		for(int i=0; i < N ; i++ ) cin >> h[i];
		for(int i=0; i < M ; i++ ) cin >> w[i];
		
		// テァツエツッテァツゥツ催・ツ陳?
		fill(H, H + 1500, 0);
		fill(W, W + 1500, 0);
		for(int i=0 ; i < N ; i++ ) H[0] += h[i];
		for(int i=0 ; i < M ; i++ ) W[0] += w[i];
		for(int i=1 ; i < N ; i++ ) H[i] = H[i-1] - h[i-1];
		for(int i=1 ; i < M ; i++ ) W[i] = W[i-1] - w[i-1];
		
		for(int i=0 ; i < N ; i++ ){
			for(int j = i+1 ; j < N ; j++ ){
				h.push_back( sum_h(i, j) );
			}
		}
		for(int i=0 ; i < M ; i++ ){
			for(int j = i+1 ; j < M ; j++ ){
				w.push_back( sum_w(i, j) );
			}
		}
		
		map<int,int> memo;
		for(int i=0 ; i < h.size() ; i++ ){
			if( memo.count( h[i] ) ){
				memo[h[i]]++;
			}else{
				memo[h[i]] = 1;
			}
		}
		int ans = 0;
		for(int i=0 ; i < w.size() ; i++ ){
			if( memo.count( w[i] ) ){
				ans += memo[w[i]];
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 18508
package main
import (
	"fmt"
)

func main(){
	var n int
	fmt.Scan(&n)
	s := make([]int, n)
	for i:=0; i<n; i++{
		var x int 
		fmt.Scan(&x)
		s[i] = x
	}
	var q int
	fmt.Scan(&q)
	t := make([]int, q)
	for i:=0; i<q; i++{
		var x int
		fmt.Scan(&x)
		t[i] = x
	}
	ans := 0
	for _, x := range t{
		for _, y := range s{
			if x==y{
				ans++
				break
			}
		}
	}
	fmt.Println(ans)
}


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

int main(){
	string s;
	cin >> s;
	if(s == string("SUN")) {
		cout << 7 << endl; 
	}else if(s == string("MON")){
		cout << 6 << endl; 
	}else if(s == string("TUE")){
		cout << 5 << endl; 
	}else if(s == string("WED")){
		cout << 4 << endl; 
	}else if(s == string("THU")){
		cout << 3 << endl; 
	}else if(s == string("FRI")){
		cout << 2 << endl; 
	}else if(s == string("SAT")){
		cout << 1 << endl; 
	}
	return 0;
}


Measured memory_bytes: 256
N = int(input())
S = []
for i in range(N):
    s = ''.join(sorted(input()))
    S.append(s)

from collections import Counter
c = Counter()
for s in S:
    c[s] += 1

ans = 0

def h(n):
    return (n * (n - 1))//2
for k,v in c.items():
    ans += h(v)

print(ans)

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

int n, m;
int f[100][100];

int dfs(vector<int> &v)
{
    // cout << sum << endl;
    // printv(v);
    int sz = v.size();
    int last = v[sz - 1], res = 0;
    for (int i = 0; i < sz; i++)
    {
        if (sz == 1)
            break;
        int mi = INF;
        for (int j = 0; j < sz; j++)
        {
            if (i == j)
                continue;
            if (f[v[i]][v[j]] == 0)
            {
                v.pop_back();
                return 0;
            }
            mi = min(mi, f[v[i]][v[j]]);
        }
        res += mi;
    }
    for (int i = last + 1; i < n; i++)
    {
        v.push_back(i);
        res = max(res, dfs(v));
    }
    v.pop_back();
    return res;
}

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

    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int u, v, x;
        cin >> u >> v >> x;
        u--;
        v--;
        f[u][v] = f[v][u] = x;
    }
    int res = 0;
    for (int i = 0; i < n; i++)
    {
        vector<int> v;
        v.push_back(i);
        res = max(res, dfs(v));
    }
    cout << res << endl;
}



Measured memory_bytes: 3248
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	string s,t;
	cin>>s>>t;
	sort(s.begin(),s.end());
	sort(t.begin(),t.end(),cmp);
	if(s<t)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

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

using namespace std;

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

using ll = long long;
using pint = pair<int, int>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
    s << '[';
	for (int i = 0; i < len; ++i) {
		s << v[i]; if (i < len-1) s << ", ";
	}
    s << ']';
	return s;
}



ll com[61][61];
void buildcomb(){
	for(int i = 0; i <= 60; ++i){
		for(int j = 0; j <= i; ++j){
			if(j == 0 or i == j){
				com[i][j] = 1LL;
		  	}
			else{
				com[i][j] = com[i-1][j-1] + com[i-1][j];
			}
    	}
	}
}


int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

	buildcomb();

    int n, a, b;
	cin >> n >> a >> b;

	double mean = 0.0;

	vector<ll> v(n);
	rep(i, n){
	    cin >> v[i];
	}


	sort(v.rbegin(), v.rend());
	rep(i, a){
	    mean += v[i];
	}
	mean /= a;
	cout << setprecision(20) << fixed << mean << endl;


	int X = 0, Y = 0;
	rep(i, n){
	    if(v[i] == v[a-1]){
			if(i < a) {
				++Y;
			}
			++X;
		}
	}

	if(v[0] != v[a-1]){
		cout << com[X][Y] << endl;
	}
	else{
		ll ans = 0;
		for(int i = a; i <= b; ++i){
			ans += com[X][i];
		}
		ppp(ans);
	}

    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()
T = list(set(S))
i = 1
ans = 0
while i < N:
  S1 = S[0:i]
  S2 = S[i:N]
  con = 0
  for j in range (len(T)):
     if S1.find(T[j]) > -1 and S2.find(T[j]) > -1:
        con += 1
  if con > ans:
    ans = con
  i += 1
print(ans)

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

using namespace std;
const int N = 10e6 * 3;

void solve()
{

int n,m;
long long k;
cin >> n >> m >> k;
vector <int> a(n);
vector <int> b(m);
vector <long long> aa(n+1);
vector <long long> bb(m+1);

aa[0]=0;
bb[0]=0;
for (int i=0; i<n; i++){cin >>a[i]; aa[i+1]=aa[i] + a[i];}
for (int i=0; i<m; i++){cin >>b[i]; bb[i+1]=bb[i] + b[i];}

int rs=0;
int bbb=m;
for (int i=0; i<=n; i++)
{
   int now=aa[i];
    int l=0, r=m;
    while (l<r)
    {
        //cout << l << "_" << r << "  ";
        int md = (l+r+1)/2;
        if (now+bb[md]>k) r=md-1; else l = md;
    }
//        cout << l << "_" << r << "  ";










    if (aa[i] + bb[l]<=k)
    rs = max(rs,i+l);
 //   cout << i << " " << rs << "\n";
}
cout << rs << "\n";

}

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

}


Measured memory_bytes: 7888
import sys
input = sys.stdin.readline
from collections import deque
import math

def solve():
  n,h = (int(i) for i in input().split())
  amax = -99
  b = []
  for i in range(n):
    ta,tb = (int(i) for i in input().split())
    amax = max(amax,ta)
    b.append(tb)

  b = deque(sorted(b,reverse=True))
  
  damage = 0
  ct = 0
  while damage < h:
    if len(b):
      throw = b[0]
    else:
      throw = -99
      
    if throw > amax:
      b.popleft()
      ct += 1
      damage += throw
      continue
    else:
      sabun = h-damage
      ct += math.ceil(sabun/amax)
      damage += amax*math.ceil(sabun/amax)
  print(ct)
solve()

Measured memory_bytes: 8876
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

void main() {
    int N;
    scan(N);
    auto adj = new int[][](N, 0);
    foreach (i ; 0 .. N) {
        auto line = readln.split.to!(int[]);
        auto u = line[0] - 1;
        foreach (v ; line[2 .. $]) {
            v--;
            adj[u] ~= v;
        }
    }

    debug {
        //writeln(adj);
    }

    auto d = new int[](N);
    auto f = new int[](N);
    d[] = -1;
    f[] = -1;

    int time;

    void dfs(int v) {
        time++;
        d[v] = time;

        foreach (u ; adj[v]) {
            if (d[u] == -1) {
                dfs(u);
            }
        }

        time++;

        f[v] = time;
    }

    foreach (i ; 0 .. N) {
        if (f[i] == -1) dfs(i);
    }

    foreach (i ; 0 .. N) {
        writefln("%s %s %s", i + 1, d[i], f[i]);
    }
}









void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}



Measured memory_bytes: 2508
#include<bits/stdc++.h>
using namespace std;
char s1[1007],s2[1007];
bool cmp(char x,char y){
    return x>y;
}
int main(){
    gets(s1);
    gets(s2);
    int len1=strlen(s1);
    int len2=strlen(s2);
    sort(s1,s1+len1);
    sort(s2,s2+len2,cmp);
    for(int i=0;i<max(len1,len2);i++){
        if(s1[i]<s2[i]){
            cout<<"Yes";
            return 0;
        }
        else if(s1[i]>s2[i]){
            cout<<"No";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 384
import scala.io.Source.stdin

object Main {
  type Vector = (Double,Double)
  def v(x:Vector,y:Vector):Vector = (x,y) match { case ((x0,y0),(x1,y1)) => (x1-x0,y1-y0) }
  def cross(x:Vector,y:Vector) = (x,y) match { case ((x0,y0),(x1,y1)) => x0*y1-x1*y0 }

  def main(args:Array[String]) = {
    val b = new StringBuilder

    for(l<-stdin.getLines.map(s=>s.split(",").map(_.toDouble))) {
      val v01 = v((l(0),l(1)), (l(2),l(3)))
      val v02 = v((l(0),l(1)), (l(4),l(5)))
      val v03 = v((l(0),l(1)), (l(6),l(7)))
      val v10 = v((l(2),l(3)), (l(0),l(1)))
      val v12 = v((l(2),l(3)), (l(4),l(5)))
      val v13 = v((l(2),l(3)), (l(6),l(7)))
      if(cross(v02, v01)*cross(v02,v03) < 0
          && cross(v13,v12)*cross(v13,v10) < 0)
        b.append("YES\n")
      else
        b.append("NO\n")
    }
    print(b.result)
  }
}

Measured memory_bytes: 43756
H=int(input())+1
A=[0]+list(map(int,input().split()))
def h(i):
 l=2*i;r=l+1
 g=i
 if l<H and A[g]<A[l]:g=l
 if r<H and A[g]<A[r]:g=r
 if g>i:A[i],A[g]=A[g],A[i];h(g)
for i in range(H//2,0,-1):h(i)
print(' '+' '.join(map(str,A[1:])))


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(T x,T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> T modinv(T x,const T mod){return modpow(x,mod-2,mod);}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD=1e9+7;
const ll MAX=5e6;

struct Combination {
  vector<ll> fac,inv,finv;
  
  Combination() : fac(MAX),inv(MAX),finv(MAX) {
    fac[0]=fac[1]=1;
    inv[1]=1;
    finv[0]=finv[1]=1;
    FOR(i,2,MAX) {
      fac[i] = fac[i-1]*i%MOD;
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
      finv[i] = finv[i-1]*inv[i]%MOD;
    }
  }

  ll calc(ll n, ll k) {
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
  }
};

int main() {
  // X,Yまでの移動通り（MOD）
  // (2,1)と進む回数、(1,2)と進む回数をa,bとするとa+bCb
  ll X,Y;cin>>X>>Y;
  ll a=0,b=0;
  while (Y*2>X) {
    Y-=2;
    X--;
    b++;
  }

  if (Y*2!=X || X<0 || Y<0) {
    OUT(0);
    return 0;
  }

  a=Y;
  Combination c = Combination();
  OUT(c.calc(a+b,b));

  return 0;
}

Measured memory_bytes: 117376
#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<int,int> &a, 
        const pair<int,int> &b) 
{ 
    return (a.second < b.second); 

} 
#define ll long long int
int main()
{
    int n;
    cin >> n;
    std::vector<int> a;
    std::vector<int> b;

    for( int i = 0; i < n; i++  )
    {
        int ta, tb;
        cin >> ta >> tb;
        a.push_back(ta);
        b.push_back(tb);

    }
    std::sort(a.begin(), a.end());
    std::sort(b.begin(), b.end());

    int ans;

    if( n % 2 == 1  )
    {
        ans = b.at( n / 2  ) - a.at( n / 2  ) + 1;

    }
    else
    {
        ans = b.at( n / 2 - 1  ) + b.at( n / 2  ) - a.at( n / 2 - 1  ) - a.at( n / 2  ) + 1;

    }
    cout << ans;    
}


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

using namespace std;

int main() {
    int H, W;
    bool flag;
    string s[50];
    int dx[] = {0, 1, 0, -1};
    int dy[] = {-1, 0, 1, 0};

    cin >> H >> W;
    for (int i = 0; i < H; i++) cin >> s[i];


    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (s[i][j] == '.') continue;

            flag = false;
            for (int k = 0; k < 4; k++) {
                int y = i+dy[k];
                int x = j+dx[k];

                if (x >= 0 && x < W &&
                    y >= 0 &&y < H && s[y][x] == '#') {
                    flag = true;
                    break;
                }
            }

            if (!flag) {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
//		 static int mod =  (int) 998244353;
		 static List<ArrayList<Integer>> list= new ArrayList<ArrayList<Integer>>();
		 public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);
	        int H = sc.nextInt();
	        int W = sc.nextInt();
	        int[][] c = new int[H][W];
	        for(int i=0;i<H;i++) {
	        	for(int j=0;j<W;j++) {
	        		c[i][j]=sc.nextInt();
	        	}
	        }
	        StringBuffer ans = new StringBuffer();
	        int cnt=0;
	        for(int i=0;i<H;i++) {
	        	for(int j=0;j<W;j++) {
	        		if(c[i][j]%2==1) {
	        			if(j==W-1) {
	        				if(i!=H-1) {
	        					c[i+1][j]++;
	        					ans.append(i+1);
	        					ans.append(" ");
	        					ans.append(j+1);
	        					ans.append(" ");
	        					ans.append(i+2);
	        					ans.append(" ");
	        					ans.append(j+1);
	        					ans.append("\n");
	        					cnt++;
	        				}
	        			} else {
        					c[i][j+1]++;
        					ans.append(i+1);
        					ans.append(" ");
        					ans.append(j+1);
        					ans.append(" ");
        					ans.append(i+1);
        					ans.append(" ");
        					ans.append(j+2);
        					ans.append("\n");
        					cnt++;
	        			}
	        		}
	        	}
	        }
	        System.out.println(cnt);	        
	        System.out.print(ans);
		 }

	}

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

using namespace std;

int main() {
  int n, cnt = 0;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  for(int i = 1; i < n - 1; i++) {
    if((a[i] > a[i - 1] && a[i] < a[i + 1]) || (a[i] < a[i - 1] && a[i] > a[i + 1]))
      cnt++;
  }
  cout << cnt << endl;
}


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

int main(){
  	string s[3];
	cin >> s[0] >> s[1] >> s[2];

  	int turn=0;
  	while(!s[turn].empty()){
    	char tmp=s[turn][0];
      	s[turn].erase(0,1);
      	if(tmp=='a'){
        	turn=0;
        }else if(tmp=='b'){
        	turn=1;
        }else{
        	turn=2;
        }
    }
  
  	if(turn==0){
    	cout << 'A';
    }else if(turn==1){
    	cout << 'B';
    }else{
    	cout << 'C';
    }
	return 0;
}

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

int main(){
char in;
cin>>in;
char A='A';
char T='T';
char C='C';

if(in==A)
cout<<"T"<<endl;
else if(in==T)
cout<<"A"<<endl;
else if(in==C)
cout<<"G"<<endl;
else
cout<<"C"<<endl;
}


Measured memory_bytes: 256
import itertools
N = int(input())
rng = int(-(-N**0.5//1))
pat_list = list(itertools.product(range(1,rng),repeat=3))
cnt_list = [0 for i in range(rng**2*6)]
for X, Y, Z in pat_list:
    cnt_list[X**2+Y**2+Z**2+X*Y+Y*Z+Z*X] += 1

for i in range(1, N+1):
    print(cnt_list[i])

Measured memory_bytes: 79024
import sys
def win(c, line):
	for i in range(0, 9, 3):
		if all(p == c for p in line[i:i + 3:1]):
			return True
	for i in range(3):
		if all(p == c for p in line[i:i + 9:3]):
			return True
	if all(p == c for p in line[0::4]): return True
	if all(p == c for p in line[2:8:2]): return True
	return False;
while True:
	line = raw_input()
	if line == "0":
		break
	line += raw_input() + raw_input()
	for c in ['b', 'w']:
		if win(c, line):
			print c
			break
	else:
		print 'NA'

Measured memory_bytes: 5212
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

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

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

typedef long long ll;

using namespace std;
int dp[10001][100][2];

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string num;
  int d;
  cin>>num>>d;
  int mod=1e9+7;
  int l=num.length();
  dp[0][0][1]=1;
  rep(i,l)
  {
    int ni=num[i]-'0';
    rep(j,d)
    {
      rep(k,10)
      {
        dp[i+1][(j+k)%d][0]+=dp[i][j][0];
        dp[i+1][(j+k)%d][0]%=mod;
      }
      rep(k,ni)
      {
        dp[i+1][(j+k)%d][0]+=dp[i][j][1];
        dp[i+1][(j+k)%d][0]%=mod;
      }
      dp[i+1][(j+ni)%d][1]+=dp[i][j][1];
      dp[i+1][(j+ni)%d][1]%=mod;
    }
  }
  cout<<((ll)mod+dp[l][0][0]+dp[l][0][1]-1)%mod<<endl;
  return 0;

}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;

#define ll long long

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define alll(it,A) for(it=A.begin();it!=A.end();it++)

#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define mp make_pair
#define pb push_back
#define all(A)  A.begin(),A.end()
#define ft first
#define sd second

#define pll pair<ll,ll>
#define pii pair<int,int>
#define V vector<ll>
#define VP vector<pll>
#define SP set<pll>
#define VB vector<bool>
#define S set<ll>
#define MS multiset<ll>
#define VV vector<V>
#define VS vector<S>
#define PQi priority_queue< int >
#define PDQi priority_queue< int ,vector< int > ,greater< int > >
#define PQl priority_queue< ll >
#define PDQl priority_queue< ll ,V,greater< ll > >
//#define inf 1e5
#define mod 1000000007
bool isprime(ll n){
    ll i;
    if(n==2||n==3)return 1;
    ll flag=0;
    for(i=2;i<=sqrt(n)+1;i++){
        if(n%i==0){
            flag=1;
            break;
        }
    }
    if(flag)return 0;
    else return 1;
}
//ll cost[200001];
//V adj[200001];
//ll d[200001]={0};
//ll dam[200001]={0};
//V rdj[200001];
//ll visited[200001]={0};
//ll par[200001]={0},rnk[200001]={0};
//ll find(ll a){
//	if(par[a]==a)return par[a];
//	return find(par[a]);
//}
//void unionf(ll a,ll b){
//	a=find(a);
//	b=find(b);
//	//if(a==b)continue;
//	if(rnk[a]>rnk[b]){
//		par[b]=a;
//		rnk[a]+=rnk[b];
//	}
//	else{
//		par[a]=b;
//		rnk[b]+=rnk[a];
//	}
//}
ll kadane(ll a[],ll n){
    ll sumtill=0,maxtill=0,start=0,ending=0,start1=0;
    rep(i,0,n){
        sumtill+=a[i];
       // err1(sumtill);
        if(sumtill>maxtill){
            maxtill=sumtill;
            start=start1;
            ending=i;
        }
        if(sumtill<0){
            start1=i+1;
            sumtill=0;
        }
    }
    return maxtill;
}
ll pow1(ll a,ll b,ll mod1){
    int res=1;
    if(b<0) b+=mod1-1;
    while(b>0){
        if(b&1){
        	res=(res*a)%mod1;
		}
        a=(a*a)%mod1;
        b>>=1;
    }
    return res%mod1;
}
int main(){
	fast
    ll t;
    //cin>>t;
    t=1;
    while(t--){
            ll n;
            cin>>n;
            ll a[n+1];
            rep(i,1,n+1)cin>>a[i];
            ll pre[n+1];
            ll sum=0;
            pre[0]=0;
            rep(i,1,n+1){
                sum+=a[i];
                pre[i]=sum;
            }
            ll dp[n+1][n+1];
            rep(i,0,n+1)rep(j,0,n+1)dp[i][j]=10e18;
            rep(i,1,n+1)dp[i][i]=0;
            repb(i,n-1,1){
                rep(j,i+1,n+1){
                    rep(k,1,j-i+1){
                    if(i!=j-1)dp[i][j]=min(dp[i][j],pre[j]-pre[i-1]+dp[i][j-k]+dp[j-k+1][j]);
                   else dp[i][j]=pre[j]-pre[i-1];
                    }
                }
            }
            cout<<dp[1][n];
    }
    return 0;
}



Measured memory_bytes: 4892
#include<stdio.h>
double p,d[3010][3010]={1};
int main(){
  int n,i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%lf",&p);
    for(j=0;j<=i;j++){
      d[i+1][j+1]+=d[i][j]*p;
      d[i+1][j  ]+=d[i][j]*(1-p);
    }
  }
  for(i=p=0;i<n/2+1;i++)p+=d[n][n/2+1+i];
  printf("%.10lf\n",p);
  return 0;
}


Measured memory_bytes: 46336
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		Set<String> set = new HashSet<String>();
		for (int n = s.nextInt(); n-- > 0;) {
			set.add(s.next());
		}
		for (int m = s.nextInt(), b = 0; m-- > 0;) {
			String id = s.next();
			System.out.println((!set.contains(id) ? "Unknown "
					: b++ % 2 < 1 ? "Opened by " : "Closed by ")
					+ id);
		}

	}
}

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

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

    int a, b, c, d, num;
    cin >> num;
    d = num % 10; num /= 10;
    c = num % 10; num /= 10;
    b = num % 10; num /= 10;
    a = num % 10;

    if (a + b + c + d == 7) {
        cout << a << '+' << b << '+' << c << '+' << d << "=7" << endl;
    }
    else if (a + b + c - d == 7) {
        cout << a << '+' << b << '+' << c << '-' << d << "=7" << endl;
    }
    else if (a + b - c + d == 7) {
        cout << a << '+' << b << '-' << c << '+' << d << "=7" << endl;
    }
    else if (a + b - c - d == 7) {
        cout << a << '+' << b << '-' << c << '-' << d << "=7" << endl;
    }
    else if (a - b + c + d == 7) {
        cout << a << '-' << b << '+' << c << '+' << d << "=7" << endl;
    }
    else if (a - b + c - d == 7) {
        cout << a << '-' << b << '+' << c << '-' << d << "=7" << endl;
    }
    else if (a - b - c + d == 7) {
        cout << a << '-' << b << '-' << c << '+' << d << "=7" << endl;
    }
    else if (a - b - c - d == 7) {
        cout << a << '-' << b << '-' << c << '-' << d << "=7" << endl;
    }

    return 0;

}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new MyInputStream(Console.In, ' '));
            Console.Out.Flush();
        }

        public void Solve(MyInputStream cin)
        {
            var group = new List<int[]>(){
                new int[] {1,3,5,7,8,10,12},
                new int[] {4,6,9,11},
                new int[] {2}
            };
            var x = cin.ReadInt();
            var y = cin.ReadInt();
            
            if (group.FindIndex(ary => ary.Contains(x)) == group.FindIndex(ary => ary.Contains(y)))
                WriteLine("Yes");
            else WriteLine("No");
        }
    }

    public class MyInputStream
    {
        private readonly System.IO.TextReader _stream;
        private char separator = ' ';
        private Queue<string> inputStream;
        public MyInputStream(System.IO.TextReader s, char separator = ' ')
        {
            this.separator = separator;
            this._stream = s;
            inputStream = new Queue<string>();
        }
        public string Read()
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = _stream.ReadLine().Split(separator);
            for (int i = 0; i < tmp.Length; ++i)
                inputStream.Enqueue(tmp[i]);
            return inputStream.Dequeue();
        }
        public string ReadLine() { return _stream.ReadLine(); }
        public int ReadInt() { return int.Parse(Read()); }
        public long ReadLong() { return long.Parse(Read()); }
        public double ReadDouble() { return double.Parse(Read()); }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read(); return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt(); return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong(); return ret;}
    }
}



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

int N;
string S;
int main(){
    cin>>N>>S;
    int ans=1e7;
    
    int se[N+1]={};
    for(int i=0;i<N;i++){
        se[i+1]=se[i];
        if(S[i]=='#')se[i+1]++;
    }
    for(int i=0;i<=N;i++){
        int t=2*se[i]+N-i-se[N];
        ans=min(ans,t);
    }
    cout<<ans<<endl;
}

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

int main(){
  long long N, A, B;
  cin >> N >> A >> B;
  long long ans;
  if((B-A)%2==0) ans=(B-A)/2;
  else{
    long long C = min((A-1),(N-B));
    long long D;
    if(C==A-1) D=B-1;
    else D=N-A;
    ans=(C+1+D)/2;
  }
  cout << ans << endl;
}

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

string S, T; pair<int, int> dp[3009][3009];

int main() {
	cin >> S >> T;
	for (int i = 0; i <= 3000; i++) { for (int j = 0; j <= 3000; j++) dp[i][j] = make_pair(-1, -1); }
	dp[0][0] = make_pair(0, -1);
	for (int i = 0; i < S.size(); i++) {
		for (int j = 0; j < T.size(); j++) {
			if (S[i] == T[j]) {
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], make_pair(dp[i][j].first + 1, 0));
			}
			dp[i + 1][j] = max(dp[i + 1][j], make_pair(dp[i][j].first, 1));
			dp[i][j + 1] = max(dp[i][j + 1], make_pair(dp[i][j].first, 2));
		}
	}
	int maxn = -1; pair<int, int> maxid = make_pair(-1, -1);
	for (int i = 0; i <= S.size(); i++) {
		for (int j = 0; j <= T.size(); j++) {
			if (dp[i][j].first > maxn) {
				maxn = dp[i][j].first;
				maxid = make_pair(i, j);
			}
		}
	}
	string V;
	while (maxid != make_pair(0, 0)) {
		if (dp[maxid.first][maxid.second].second == 0) {
			maxid.first--; maxid.second--;
			V += S[maxid.first];
		}
		if (dp[maxid.first][maxid.second].second == 1) maxid.first--;
		if (dp[maxid.first][maxid.second].second == 2) maxid.second--;
	}
	reverse(V.begin(), V.end());
	cout << V << endl;
	return 0;
}

Measured memory_bytes: 70912
//#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<set>
#include<stack>
#include<iomanip>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<T>>;
template<typename T =ll,typename U =ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e9;
template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;

void a(){
    string s;
    cin >> s;
    if(s=="ARC") cout << "ABC" << endl;
    else cout << "ARC" << endl;
}
void b(){
    ll n,k; cin >> n >> k;
    map<ll,ll> memo;
    rep(i,k){
        ll d; cin >> d;
        rep(j,d){
            ll A; cin >> A;
            memo[A]++;
        }
    }
    cout << n-memo.size() << endl;
}

void c(){

}

void d(){
    
}
void e(){}
void f(){}
int main(){
    b();
    return 0;
}

Measured memory_bytes: 3636
// ARC095C.cpp
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 15;

int n, m, order[MAX_N], best_match, mpoint[MAX_N];
char mp[MAX_N][MAX_N], *lmp[MAX_N];

bool check(int pos)
{
    if (pos == m + 1)
        return true;
    if (mpoint[pos])
        return check(pos + 1);
    int cnt = 0;
    for (int i = pos; i <= m; i++)
        if (mpoint[i] == 0)
            cnt++;
    for (int i = pos; i <= m; i++)
        if (mpoint[i] == 0)
        {
            bool flag = true;
            for (int j = 1; j <= n; j++)
                flag &= (mp[j][i] == mp[order[j]][pos] && mp[order[j]][i] == mp[j][pos]);
            if (i == pos)
            {
                if (flag && (cnt & 1))
                {
                    mpoint[pos] = i;
                    if (check(pos + 1))
                        return true;
                    mpoint[pos] = 0;
                }
            }
            else if (flag)
            {
                mpoint[pos] = i, mpoint[i] = pos;
                if (check(pos + 1))
                    return true;
                mpoint[pos] = mpoint[i] = 0;
            }
        }
    return false;
}

bool dfs(int pos)
{
    if (pos == n + 1)
        return check(1);
    if (order[pos] != 0)
        return dfs(pos + 1);
    int cnt = 0;
    for (int i = pos; i <= n; i++)
        if (order[i] == 0)
            cnt++;
    for (int i = pos; i <= n; i++)
        if (order[i] == 0)
        {
            order[pos] = i, order[i] = pos;
            if (((cnt & 1) || (i != pos)) && dfs(pos + 1))
                return true;
            order[pos] = order[i] = 0;
        }
    return false;
}

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        scanf("%s", mp[i] + 1);
    if (dfs(1))
        puts("YES");
    else
        puts("NO");
    return 0;
}

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

int main(){
	int n,m,num[10000],me[10000],me2,d;
	while(true){
		cin>>n>>m;
		if(n==0 && m==0){
			break;
		}
		me2=1;
		d=0;
		for(int i=1;i<=n;i++){
			cin>>num[i];
		}
		for(int i=1;i<=m;i++){
			cin>>me[i];
		}
		while(me2<n){
			d++;
			me2 += me[d];
			if(me2<n){
				me2 += num[me2];
			}
		}
		cout<<d<<endl;
	}
	return 0;
}

Measured memory_bytes: 1180
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector<int> vi;
typedef pair<int, int> pi;
#define SQ(a) (a) * (a)
#define mod 1000000007
#define w(x) int x; cin>>x; while(x--)
#define deb(x) cout << #x << " = " << x << '\n'
#define deb2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"
 
void solve(){
    int n;
    cin>>n;
    ll int a[n];
    ll int sum=0;

    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    sum=0;
    ll int curr=0;
    ll int ans=0;
    for(int i=n-1;i>=0;i--){
        ans= (ans+a[i]*sum)%mod;
        sum= (sum+a[i])%mod;
    }
    cout<<ans;
}
 
int main(int argc, char const *argv[])
{
 
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    solve();
    return 0;
}


Measured memory_bytes: 5172
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N,A,B,n;
  cin>>N>>A>>B>>n;
  vector<int> C(N);
  C[0]=n;
  int ans=0;
  for(int i=1;i<N;i++){
    cin>>C[i];
    ans+=min((C[i]-C[i-1])*A,B);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3976
#ABC-141-D
def main():
    n=int(input())
    s=str(input())
    
    dp=[[0]*n for _ in range(n)]
    
    for i in range(n):
        for j in range(i,n):
            if i==j:
                dp[i][j]==i
                
            elif i==0:
                if s[i]==s[j]:
                    dp[i][j]=1
            
            else:
                 if s[i]==s[j]:
                    dp[i][j]=dp[i-1][j-1]+1
    
    ans=0
    for i in range(n):
        for j in range(i,n):
            ans=max(ans,min(j-i,dp[i][j]))
            
    print(ans)
    
main()

Measured memory_bytes: 230280
N = int(input())
A, B = map(int, input().split())
P = list(map(int, input().split()))
ans1 = 0
ans2 = 0
ans3 = 0  
for i in P:
    if A>=i:
        ans1 = ans1 + 1
    if A+1 <= i <= B:
        ans2 = ans2 + 1
    if B+1 <= i:
        ans3 = ans3 + 1 


print(min(ans1,ans2,ans3))


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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<

typedef long long ll;
typedef pair<int, int> point;

set<int> s;

int main() {

  int n, m; cin >> n >> m;

  int gcd, mx; cin >> gcd;
  mx = gcd;

  REP(i, n - 1) {
    int x; cin >> x;
    gcd = __gcd(gcd, x);
    mx = max(mx, x);
  }

  if(m <= mx && m % gcd == 0) {
    cout << "POSSIBLE";
  }
  else {
    cout << "IMPOSSIBLE";
  }

}


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

int main()
{
    while(1)
    {
        int n,x;
        cin >> n >> x;
        
        if(n == 0 &&x == 0) break;
        
        int cnt = 0;
        
        for(int a = 1;a <= n;a++)
        {
            for(int b = a+1;b <= n;b++)
            {
                for(int c = b+1;c <= n;c++)
                {
                    if(a+b+c == x)
                    {
                        cnt++;
                    }
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
object Main {
  def main(args: Array[String]): Unit = {
    val source = readLine.split(" ").toList.map(_.toInt)
//    if ((source(1) / source(0)) < source(2))
    println(source(1) / source(0) match {
      case res if res < source(2) => res
      case _ => source(2)
    })
  }
}

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

constexpr int mod = 1e5;

int main() {
    int n;
    while(cin >> n, n) {
        map<int, int> rec;
        for(int i=0; i<n; ++i) {
            int m, a, b;
            cin >> m >> a >> b;
            rec[a] += m;
            rec[b] -= m;
        }
        int sum = 0;
        bool ok = true;
        for(auto& p : rec) {
            sum += p.second;
            ok &= sum <= 150;
        }
        if(ok) {
            cout << "OK" << endl;
        } else {
            cout << "NG" << endl;
        }
    }
}


Measured memory_bytes: 3024
from collections import Counter
N = int(input())
a_array = list(map(int, input().split()))

a = Counter(a_array)

if len(a) == 1 and a[0] == N:
    print("Yes")
    exit()

if len(a) == 2 and N % 3 == 0 and a[0] == N // 3:
    print("Yes")
    exit()


if len(a) == 3:
    i_array = []
    for i, x in a.items():
        i_array.append(i)
        if x != N // 3:
            print("No")
            exit()
    else:
        if i_array[0] ^ i_array[1] == i_array[2]:
            print("Yes")
            exit()
        else:
            print("No")
            exit()
else:
    print("No")
    exit()


Measured memory_bytes: 60784
def main():
    N, A, B, C, D = list(map(int, input().split(' ')))
    S = input()
    if C == D:
        print('No')
    elif C < D:
        for s in [S[(A-1):C], S[(B-1):D]]:
            for i in range(len(s) - 1):
                if s[i:(i+2)] == '##':
                    print('No')
                    return
        print('Yes')
    else:
        # A B D C
        s = S[(A-1):C]
        for i in range(len(s) - 1):
            if s[i:(i + 2)] == '##':
                print('No')
                return
        s = S[(B-2):(D+1)]
        ok = False
        for i in range(1, len(s) - 1):
            if s[(i-1):(i+2)] == '...':
                ok = True
                break
        print('Yes' if ok else 'No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 3572