akhauriyash/Code-Regression huggingface dataset:
n_text = input()
w_text = input()

N = int(n_text)
W = w_text.split()

W = [int(i) for i in W]

ans = 100 * 100

for T in range(N):
  ans_tmp = abs(sum(W[:T]) - sum(W[T:]))
  if ans_tmp < ans:
    ans = ans_tmp

print(ans)


Measured memory_bytes: 3060
/*
      author : nishi5451
      created: 11.08.2020 20:12:32
*/

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


int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(c-a-b<=0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define mod 1000000007


int minimumChar(string S1, string S2) {
    int n = S1.size(), m = S2.size(); 
    int ans = INT_MAX; 
    for (int i = 0; i < m - n + 1; i++) { 
        int minRemovedChar = 0; 
        for (int j = 0; j < n; j++) { 
            if (S1[j] != S2[i + j]) { 
                minRemovedChar++; 
            } 
        } 
        ans = min(minRemovedChar, ans); 
    } 
    return ans; 
} 

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s, t; cin>>s>>t;
  int mx = 0, cnt =0;
  cout<<minimumChar(t,s)<<"\n";
  return 0;
}

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

int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]>'C')cout<<(char)(s[i]-3);
		else cout<<(char)(s[i]+23);
	}
	cout<<endl;
	return 0;
}



Measured memory_bytes: 3160
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

using ll = long long;


int main() {
    ll n;

    cin >> n;

    ll minSum = LLONG_MAX;
    pair<ll, ll> comb;

    for(ll i = 1; i * i <= n; ++i) {
        
        if(n % i != 0)
            continue;
        
        ll div = n / i;
        ll sum = i + div;
        if(sum < minSum) {
            minSum = sum;
            comb = make_pair(i, div);
        }

    }
    
    cout << comb.first + comb.second - 2 << endl;

    return 0;

}

Measured memory_bytes: 256
// 2014/09/16 Tazoe

#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;

int main()
{
	int T[1000], L[1000];
	int nT = 0, nL = 0;

	while(true){
		string s;
		getline(cin, s);
//		cout << s << endl;

		if(s=="")
			break;

		for(int i=0; i<s.size(); i++){
			if(s[i]==','){
				s[i] = ' ';
				break;
			}
		}

		istringstream is(s);
		is >> T[nT++];
	}

	while(true){
		string s;
		getline(cin, s);
//		cout << s << endl;

		if(cin.eof())
			break;

		for(int i=0; i<s.size(); i++){
			if(s[i]==','){
				s[i] = ' ';
				break;
			}
		}

		istringstream is(s);
		is >> L[nL++];
	}

	sort(T, T+nT);
	sort(L, L+nL);

	T[nT++] = -1;
	L[nL++] = -1;

//	for(int i=0; i<nT; i++){
//		cout << T[i] << ' ';
//	}
//	cout << endl;

//	for(int i=0; i<nL; i++){
//		cout << L[i] << ' ';
//	}
//	cout << endl;

	for(int i=0, j=0; T[i]!=-1 && L[j]!=-1; ){
		if(T[i]<L[j]){
			i++;
			continue;
		}

		if(T[i]>L[j]){
			j++;
			continue;
		}

		int N = T[i];
		int cnt = 0;

		while(T[i]==N){
			cnt++;
			i++;
		}
		while(L[j]==N){
			cnt++;
			j++;
		}

		cout << N << ' ' << cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 1248
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
    int x;
    cin>>x;
    cout<<(!x)<<"\n";
}

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

    int t=1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n, m, K, ans, flag, lgg, rgg, f[25005][405], g[25005][405], a[25005], aft[405], vis[405];
inline int pow(int x, int k) {
    int res = 1;
    for (;k;k >>= 1, x = 1LL * x * x % mod)
		if (k & 1)
			res = 1LL * res * x % mod;
    return res;
}
int main() {
	cin >> n >> K >> m;
    for (int i = 1; i <= m; i ++)
		cin >> a[i];
    for (int i = 1; i + K - 1 <= m; i ++) {
        int tot = 0;
        for (int j = 0; j < K; j ++)
			if (vis[a[i + j]] != i) {
				vis[a[i + j]] = i;
				tot ++;
		}
        if (tot == K) {
			flag = 1;
			break;
		}
    }
    ans = 1LL * pow(K, n - m) * (n - m + 1) % mod;
    if (flag)
		return 0 * printf("%d\n", ans);
    for (int i = 1; i <= m; i ++) if(vis[a[i]]!=n+1) vis[a[i]]=n+1; else {lgg=i;break;}
    for(int i=m;i>=1;--i) if(vis[a[i]]!=n+2) vis[a[i]]=n+2; else {rgg=i;break;}
    for(int i=1;i<K;++i) f[0][i]=1,g[0][i]=i;
    for(int i=1;i<=n;++i) for(int j=1;j<K;++j)
    {
        f[i][j]=(1LL*(K-j)*f[i-1][j+1]+g[i-1][j])%mod;
        g[i][j]=(g[i][j-1]+f[i][j])%mod;
    }
    for(int i=1;i+m-1<=n;++i)
        if(lgg) ans=(ans-1LL*f[i-1][lgg-1]*f[n-(i+m-1)][m-rgg]%mod+mod)%mod;
        else for(int j=i+m,p=1;j-i<K&&j<=n+1;++j)
        {
            ans=(ans-1LL*f[i-1][j-i]*(j>n?1:g[n-j][j-i])%mod*p%mod+mod)%mod;
            p=1LL*p*(K-m-(j-(i+m)))%mod;
        }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 79488
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main(void){
    string s;
    cin >> s;
    int m = stoi(s.substr(5,2));
    int d = stoi(s.substr(8,2));
    if(m<=4 && d<=30){
        cout << "Heisei" << endl;
    }else{
        cout << "TBD" << endl;
    }
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())
S = input()
A += B
a = 0
b = 0

for i in range(N):
  if S[i] == 'a':
    if a < A:
      print('Yes')
      a += 1
    else:
      print('No')
  elif S[i] == 'b':
    if a < A and b < B:
      print('Yes')
      a += 1
      b += 1
    else:
      print('No')
  else:
    print('No')

Measured memory_bytes: 9320
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N, long K, long[] h) {
    return h.filter!(x => x >= K).count;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    long K;
    K = input.front.to!long;
    input.popFront;

    long[] h = new long[](cast(size_t) (N));
    foreach (i; 0 .. cast(size_t) (N)) {
        h[i] = input.front.to!long;
        input.popFront;
    }

    static if (is(ReturnType!solve == void))
        solve(N, K, h);
    else
        solve(N, K, h).writeln;
}


Measured memory_bytes: 5696
from collections import deque

N = int(input())
A = [list(map(int,input().split())) for _ in range(N)]

M = N*(N-1)//2

for i in range(N):
    for j in range(N-1):
        p = min(i+1,A[i][j])
        q = max(i+1,A[i][j])
        match = M-(N-p+1)*(N-p)//2+q-p-1
        A[i][j] = match
        
graph = [[] for _ in range(M)]
indegree = [0 for _ in range(M)]

for i in range(N):
    for j in range(1,N-1):
        graph[A[i][j-1]].append(A[i][j])
        indegree[A[i][j]] += 1
        
dist = [None for _ in range(M)]
queue = deque([])

for k in range(M):
    if indegree[k]==0:
        dist[k] = 0
        queue.append(k)

cycle = False

while queue:
    node = queue.popleft()
    for adj in graph[node]:
        indegree[adj] -= 1
        dist[adj] = dist[node] + 1
        if indegree[adj]==0:
            queue.append(adj)
            
if any(indegree):
    cycle = True

print(-1 if cycle else max(dist)+1)

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

using namespace std;
int x , y;
int main()
{
    cin >> x >> y;
    if(x >= 0 && x <= y)
    {
        cout << y - x;
        return 0;
    }
    int diff = abs(abs(x) - abs(y));
    int ans = diff;
    if(x >= 0 && y >= 0 && y < x)
    {
        cout << ans + 1 + (y > 0);
        return 0;
    }
    if(x < 0 && y < 0 && y < x)
    {
        cout << ans + 2;
        return 0;
    }
    if(x < 0 && y < 0 && y >= x)
    {
        cout << ans;
        return 0;
    }
    if((x >= 0 && y < 0))
    {
        cout << ans + 1;
        return 0;
    }
    if(y >= 0 && x < 0)
    {
        cout << ans + (y > 0);
        return 0;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int a;
    int b;
    int c;
    int d;
    int e;
    int f;
    int sum;
    cin>>a>>b>>c>>d>>e>>f;
    sum=a*1+b*5+c*10+d*50+e*100+f*500;
    if(sum>=1000){
        cout<<1<<endl;
    }
    else if(sum<1000){
        cout<<0<<endl;
    }
    return 0;
    
}

Measured memory_bytes: 1164
import numpy
import itertools
N=int(input())
p=list(map(int, input().split()))
q=list(map(int, input().split()))
value = 1
count=0
second_box =[]
box = [i for i in range(1,N+1)]
value = list(itertools.permutations(box))
#print(value)
def func(i):
    rs = 0
    for j in range(N):
        rs += i[j] * 10**(N-j-1)
    return rs 
  
second_box = [ func(i) for i in value]
#second_box = [a = numpy.random.choice(box,size=N,replace=False,p=None) ]

#n_second_box = [func(i) for i in second_box]
third_box = sorted(second_box,reverse=False)
#print((third_box))
a = third_box.index(func(p))
b = third_box.index(func(q))
print(abs(a-b))

Measured memory_bytes: 18896
object Main extends App {
  import scala.io.StdIn._


  val Array(height, width) = readLine.trim.split(' ').map(_.toInt)
  val state = Array.tabulate(height){_ ⇒ readLine.trim.split(' ').map(_.toInt)}
  val sortedPosition = (0 until height).flatMap(y ⇒ (0 until width).map(x ⇒ Coordinate(x, y))).sortBy(c ⇒ state(c.y)(c.x))
  val isRidge: Array[Array[Option[Int]]] = Array.tabulate(height){_ ⇒ Array.tabulate(width){_ ⇒ None:Option[Int]}}
  var res = 0
  for (c ← sortedPosition){
    val lower = c.neighbors.filter(n ⇒ (0 until height).contains(n.y) && (0 until width).contains(n.x) && state(n.y)(n.x) < state(c.y)(c.x)).map(n ⇒ isRidge(n.y)(n.x))
    if (lower.exists(_.isEmpty) || lower.flatten.toList.distinct.length >= 2){
      res += 1
    }else if (lower.flatten.toList.distinct.length == 1) {
      isRidge(c.y)(c.x) = Some(lower.flatten.head)
    }else {
      isRidge(c.y)(c.x) = Some(state(c.y)(c.x))
    }
  }
  println(res)

  case class Coordinate(x: Int, y: Int) {
    def neighbors: Iterable[Coordinate] = List(Coordinate(0, 1), Coordinate(0, -1), Coordinate(1, 0), Coordinate(-1, 0)).map(this + _)
    def +(that: Coordinate): Coordinate = Coordinate(x + that.x, y + that.y)
  }
  implicit class ScopeFunc[T](val value: T){
    def let[A](func: T ⇒ A): A = func(value)
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}


Measured memory_bytes: 556596
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define Dcout(a) cout << setprecision(20) << a << endl
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
using ll = long long;
using PAIR = pair<int, int>;
using Graph = vector<vector<int>>;
const ll INF = (1LL << 60);
const double pi=acos(-1.0);
#define debug cout << "line : " << __LINE__ << " debug" << endl
/****** Template of some basic operations *****/
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/**************************************/
/******** User-defined Function *******/

/**************************************/
/********** Main()  function **********/
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int k; cin >> k;
    
    int cur = 7%k;
    rep1(i,k){
        if(cur==0){
            cout << i << endl;
            return 0;
        }
        cur = (cur*10 + 7) % k;
    }

    cout << -1 << endl;

    return 0;
}
/********  Main() Ends Here *************/


Measured memory_bytes: 3596
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int a = N % 10;
     if( a==2 || a==4 || a==5 || a==7 || a==9 ){
      System.out.println("hon"); 
     }
    else if( a==0 || a==1 || a==6 || a==8 ){
      System.out.println("pon"); 
     }
     else{
      System.out.println("bon"); 
     }
    }
}

Measured memory_bytes: 35780
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char* argv[]){
        char buf[12*200+1]={0};
        char* p=NULL;
        int N = 0;
        long long* A = NULL;

        if(fgets(buf, sizeof(buf)-1, stdin)==NULL){
                return 1;
        }
        N = atoi(buf);

        A = (long long*)calloc(N+1, sizeof(long long));
        if(A==NULL) return 0;

        memset(buf, 0, sizeof(buf));
        if(fgets(buf, sizeof(buf)-1, stdin)==NULL){
                return 1;
        }
        p = strtok(buf, " ");
        A[0] = atoll(p);
        for(int i=1; i<N; i++){
                p = strtok(NULL, " ");
                A[i] = atoll(p);
        }

#ifdef DEBUG1
        printf("input: N=%d\n", N);
        for(int i=0; i<N; i++){
            printf("A[%d]=%lld\n", i, A[i]);
        }
#endif

        int ans=0;
        long long v=A[0];
        while(v%2==0){
                v=v/2;
                ans++;
        }

        for(int i=1; i<N; i++){
                v =A[i];
                int shift=0;
                while(v%2==0 && shift<ans){
                        v=v/2;
                        shift++;
                }
                if(shift<ans){ ans=shift; }
        }

        printf("%d\n", ans);
        return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
constexpr ll MOD = 1000000007;
using std::cout;
using std::endl;
using std::cin;
using std::sort;
using std::pair;
using std::string;
using std::stack;
using std::queue;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::multiset;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, ll b) {
	ll ans = 1;
	while (b > 0) {
		if (b % 2 == 1) {
			ans *= a;
			ans %= MOD;
		}
		b /= 2;
		a *= a;
		a %= MOD;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a - b < b) { return comb(a, a - b); }
	static unordered_map<ll, ll> memo;

	ll c = 1;
	FOR(i, a - b + 1, a + 1) {
		c *= i;
		c %= MOD;
	}
	if (memo.find(b) == memo.end()) {
		ll k = 1;
		FOR(i, 2, b + 1) {
			k *= i;
			k %= MOD;
		}
		memo[b] = pow(k, MOD - 2);
	}
	c *= memo[b];
	return c % MOD;
}
multiset<ll> prime_decomposition(ll n) {
	ll i = 2;
	multiset<ll> table{};
	while (i * i <= n) {
		while (n % i == 0) {
			n /= i;
			table.emplace(i);
		}
		++i;
	}
	if (n > 1) {
		table.emplace(n);
		return table;
	}
	return table;
}
/*
-- bit --
REP(i, (1 << n)) {
	REP(j, n) {
		cout << (1 & (i >> j));
	}
	cout << endl;
}
*/


int main() {
	ll n;
	string s;
	cin >> n >> s;
	vector<bool> si;
	si.reserve(n);
	REPC(c, s) {
		si.emplace_back((c == 'o') ? true : false);
	}

	vector<vector<bool>> mask{ {true,true} ,{ true,false }, { false,true }, { false,false } };
	vector<bool> v(n);
	REPC(f, mask) {
		v[0] = f[0];
		v[1] = f[1];
		FOR(i, 1, n - 1) {
			v[i + 1] = v[i] ^ v[i - 1] ^ si[i];
		}
		if (v[n - 1] ^ v[n - 2] ^ si[n - 1] == v[0] &&
			v[0] ^ v[1] ^ si[0] == v[n - 1]) {
			REPC(x, v) {
				cout << ((x) ? 'S' : 'W');
			}
			cout << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main(){
	int z[10],o[10];
	string s,some;
	some="";
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='0'){
			some+=s[i];
		}
		if(s[i]=='1'){
			some+=s[i];
		}
		if(s[i]=='B'){
			some=some.substr(0,some.size()-1);
		}
		
	}
	cout<<some<<endl;
	return 0;
}

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

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

  int t=0;
  for(int i=0;N[i]!='\0';i++){
    if(N[i]=='7'){
      t=1;
    }
    else{
      t=t;
    }
  }
  if(t==1){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3596
//
// Created by Abhishek Bansal on 9/02/2020.
//
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
bool inBound(int x, int y, int h, int w) {
    return x>0 && x <=h && y>0 && y <= w;
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

    int h, w, ch, cw, dh, dw; cin >> h >> w >> ch >> cw >> dh >> dw;
    char s[h+1][w+1]; bool visited[h+1][w+1];
    for(int i=1;i<=h;i++) {
        for(int j=1;j<=w;j++) {cin >> s[i][j];visited[i][j] = false;}
    }
    queue<pair<int, int>> q1;q1.push({ch, cw});visited[ch][cw] = true;
    int mag = 0;
    int col[4] = {-1, 0, 1, 0}, row[4] = {0, 1, 0, -1};
    while (!q1.empty()) {
        vector<pair<int, int>> v;bool ok = false;
        while (!q1.empty()) {
            auto p = q1.front();q1.pop();v.push_back(p);
            for(int i=0;i<4;i++) {
                int x = p.first + row[i], y = p.second + col[i];
                if (inBound(x, y, h, w)){
                    if (x == dh && y == dw) {ok = true; break;}
                    if (!visited[x][y] && s[x][y]=='.') {visited[x][y]=true;q1.push({x, y});}
                }
            }
            if (ok) break;
        }
        if (ok) break;
        if (q1.empty()) {
            mag++;
            for(auto p: v) {
                for(int x=p.first-2;x<=p.first+2;x++) {
                    for(int y=p.second-2;y<=p.second+2;y++) {
                        if (inBound(x, y, h, w)){
                            if (x == dh && y == dw) {ok = true; break;}
                            if (!visited[x][y] && s[x][y]=='.') {visited[x][y]=true;q1.push({x, y});}
                        }
                    }
                    if (ok) break;
                }
                if (ok) break;
            }
        }
        if (ok) break;
        if (q1.empty()) {mag = -1;break;}
    }
    cout << mag;
    return 0;
}

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

def main():
    kk = list(input())
    klen = len(kk)-1
    n = 10000
    k = [0]*n
    for i in range(klen-1,-1,-1):
        k[-(klen-i)] = int(kk[i])

    d = int(input())
    mod = 10**9 + 7

    #dp1[i][j] : 上からi桁目まで見てKと同じ時の、数字の総和がj(mod d)の数
    #dp2[i][j] : 上からi桁目まで見てK未満確定時の、数字の総和がj(mod d)の数
    dp1 = [[0]*d for i in range(n+1)]
    dp2 = [[0]*d for i in range(n+1)]

    dp1[0][0] = 1

    for i in range(n):
        for j in range(d):
            for r in range(10):
                if r < k[i]:
                    dp2[i+1][(j+r)%d] = (dp2[i+1][(j+r)%d] + dp1[i][j] + dp2[i][j])%mod
                elif r == k[i]:
                    dp1[i+1][(j+r)%d] = (dp1[i+1][(j+r)%d] + dp1[i][j])%mod
                    dp2[i+1][(j+r)%d] = (dp2[i+1][(j+r)%d] + dp2[i][j])%mod
                else:
                    dp2[i+1][(j+r)%d] = (dp2[i+1][(j+r)%d] + dp2[i][j])%mod



    print((dp1[n][0]+dp2[n][0]-1)%mod)

if __name__ == "__main__":
    main()

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
std::pair<int, int> d[] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};

int main() {
	int h = ri(), w = ri(), k = ri();
	std::string a[h];
	for (auto &i : a) std::cin >> i;
	int gx, gy, sx, sy;
	std::vector<std::pair<int, int> > apples;
	for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
		if (a[i][j] == 's') sx = i, sy = j;
		if (a[i][j] == 'e') gx = i, gy = j;
		if (a[i][j] == 'a') apples.push_back({i, j});
	}
	apples.push_back({gx, gy});
	apples.push_back({sx, sy});
	int m = apples.size();
	int dist[m][m];
	for (int i = 0; i < m; i++) {
		int distt[h][w];
		for (int j = 0; j < h; j++) for (int k = 0; k < w; k++) distt[j][k] = 1000000000;
		std::queue<std::pair<int, int> > que;
		que.push(apples[i]);
		distt[apples[i].first][apples[i].second] = 0;
		while (que.size()) {
			auto cur = que.front();
			que.pop();
			for (auto dd : d) {
				int new_x = cur.first + dd.first;
				int new_y = cur.second + dd.second;
				if (new_x < 0 || new_x >= h) continue;
				if (new_y < 0 || new_y >= w) continue;
				if (a[new_x][new_y] == '#') continue;
				if (distt[new_x][new_y] > distt[cur.first][cur.second] + 1) {
					distt[new_x][new_y] = distt[cur.first][cur.second] + 1;
					que.push({new_x, new_y});
				}
			}
		}
		
		for (int j = 0; j < m; j++) {
			dist[i][j] = distt[apples[j].first][apples[j].second];
		}
	}
	m -= 2;
	std::vector<std::vector<int> > dp(1 << m, std::vector<int>(m, 1000000000));
	for (int i = 0; i < m; i++) {
		dp[1 << i][i] = dist[i][m + 1];
	}
	for (int i = 0; i < 1 << m; i++) {
		for (int j = 0; j < m; j++) {
			if (dp[i][j] == 1000000000) continue;
			for (int k = 0; k < m; k++) {
				if (i >> k & 1) continue;
				dp[i | 1 << k][k] = std::min(dp[i | 1 << k][k], dp[i][j] + dist[j][k]);
			}
		}
	}
	int min = 1000000000;
	for (int i = 0; i < 1 << m; i++) {
		if (__builtin_popcount(i) < k) continue;
		for (int j = 0; j < m; j++) {
			min = std::min(min, dp[i][j] + dist[j][m]);
		}
	}
	std::cout << (min == 1000000000 ? -1 : min) << std::endl;
	return 0;
}




Measured memory_bytes: 130824
/**
 *    author:  FromDihPout
 *    created: 2020-05-22
**/

#include <bits/stdc++.h>
using namespace std;

const int INF = 1e9;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<int> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    
    int min_dist = INF;
    for (int i = 0; i <= 100; i++) {
        int dist = 0;
        for (int j = 0; j < n; j++) {
            dist += (x[j] - i) * (x[j] - i);
        }
        min_dist = min(min_dist, dist);
    }
    cout << min_dist << endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(dead_code)]
fn is_whitespace(c: &char) -> bool {
    c.is_whitespace()
}

#[allow(dead_code)]
fn is_eol(c: &char) -> bool {
    ['\r', '\n'].contains(c)
}

#[allow(unused_macros)]
macro_rules! input {
    ($var:ident, $($r:tt)*) => {
        input_inner!{$var, $($r)*}
    };

    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_mut, unused_variables, bare_trait_objects)]
        let mut next = move |f: &Fn(&char)->bool| -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|f(&c))
                .take_while(|c|!f(&c))
                .collect()
        };
        input_inner!{next, $($r)*};
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; eol ]) => {
        $next(&is_eol).split(' ').map(|x| x.parse::<$t>().unwrap()).collect::<Vec<_>>()
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

    ($next:expr, parser) => {
        $next
    };

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};

#[allow(dead_code)]
struct Edge {
    from: usize,
    to: usize,
}

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;
#[allow(dead_code)]
const M: usize = 1_000_000_007;

fn main() {
    input! {
        h: usize,
        n: usize,
        ab: [(usize, usize); n],
    }

    let mut dp = vec![1 << 50; h + 1];
    dp[0] = 0;

    for i in 0..n {
        for j in 0..h + 1 {
            let next = min(j + ab[i].0, h);
            dp[next] = min(dp[next], dp[j] + ab[i].1);
        }
    }
    println!("{}", dp[h]);
}


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

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

    int s; cin >> s;
    int ans = 4;
    while (s > 4 || s == 3) {
        s = (s & 1) ? 3 * s + 1 : s / 2;
        ans++;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
import math
D,G = map(int,input().split())
PC = [list(map(int,input().split())) for _ in range(D)]

def dfs(d,flag,point,count,tmp):
    point += flag * (PC[d-1][1]+PC[d-1][0]*d*100)
    count += flag * (PC[d-1][0])
    if flag == 0:
        tmp = d
    if d == D:
        if point < G:
            r = math.ceil((G-point)/(tmp*100))
            if r < PC[tmp-1][0]:
                res = count + r
            else:
                res = float("INF")
        else:
            res = count
        return res

    else:
        return min(dfs(d+1,1,point,count,tmp),dfs(d+1,0,point,count,tmp))

print(min(dfs(1,0,0,0,0),dfs(1,1,0,0,0)))

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL n, m, x[100002];
const LL MOD = 1000000007;

void mat_prod(LL a[3][3], LL b[3][3], LL c[3][3]) { // a = b * c;
	LL d[3][3];
	inc(i, 3) {
	inc(j, 3) {
		d[i][j] = 0;
	}
	}
	
	inc(i, 3) {
	inc(j, 3) {
	inc(k, 3) {
		(d[i][j] += b[i][k] * c[k][j]) %= MOD;
	}
	}
	}
	
	inc(i, 3) {
	inc(j, 3) {
		a[i][j] = d[i][j];
	}
	}
	
	return;
}

void mat_exp(LL a[3][3], LL b[3][3], LL c) { // a = b ^ c;
	static bool flag = true;
	static LL t[30][3][3];
	if(flag) {
		inc(i, 3) {
		inc(j, 3) {
			t[0][i][j] = b[i][j];
		}
		}
		inc(i, 30 - 1) {
			mat_prod(t[i + 1], t[i], t[i]);
		}
		flag = false;
	}
	
	inc(i, 3) {
	inc(j, 3) {
		a[i][j] = 0;
	}
	}
	inc(i, 3) { a[i][i] = 1; }
	inc(i, 30) {
		if(c & (1 << i)) {
			mat_prod(a, a, t[i]);
		}
	}
	
	return;
}

int main() {
	cin >> n >> m;
	inc1(i, m) { cin >> x[i]; }
	x[0] = 0;
	x[m + 1] = n;
	
	LL a[3][3] = { { 2, 1, 0 }, { 3, 1, 1 }, { 2, 0, 1 } };
	LL b[3][3] = { { 1, 1, 0 }, { 0, 1, 1 }, { 0, 0, 1 } };
	LL c[3][3] = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
	LL d[3][3];
	
	inc(i, m + 1) {
		mat_prod(c, b, c);
		mat_exp(d, a, x[i + 1] - x[i] - 1);
		mat_prod(c, d, c);
	}
	
	cout << (c[0][1] + c[0][2] * 2) % MOD << endl;
	
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
bool isPrime(int N){
    bool res = true;
    for(int i=2; i*i<=N; ++i) if (N%i==0) res = false;
    return res;
}
int main() {
    int Prime[(int)1e5+10];
    Prime[0] = Prime[1] = Prime[2] = 0;
    for (int i=3; i<=(int)1e5; i+=2) {
        Prime[i] = Prime[i-2];
        if (isPrime(i) && isPrime((i+1)/2)) Prime[i]++;
        Prime[i+1] = Prime[i];
    }
    int Q; cin >> Q;
    int l,r;
    for (int i=0; i<Q; ++i){
        cin >> l >> r;
        cout << Prime[r] - Prime[l-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 3968
using System;
using System.Collections.Generic;
class Program
    {
    	static void Main(string[] args)
    	{
            string[] s = Console.ReadLine().Split('/');
            
            int y = int.Parse(s[0]);
            if (y < 2019) Console.WriteLine("Heisei");
            else if (y > 2019) Console.WriteLine("TBD");
            else
            {
                int m = int.Parse(s[1]);
                int d = int.Parse(s[2]);
                if (m * 100 + d <= 430) Console.WriteLine("Heisei");
                else Console.WriteLine("TBD");
            }
        }
    }
    //mcs Main.cs
    //mono Main.exe

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    string S;
    cin >> N >> S;
    
    int count1, count2, count3;
    int max = 0;
    for(int i=0; i<N; i++){
        count3 = 0;
        for(char k='a';k<='z';k++){
            count1 = 0;
            count2 = 0;
            for(int j=0;j<=i;j++)   if(S.at(j) == k)    count1 ++;
            for(int j=i+1;j<N;j++)  if(S.at(j) == k)    count2 ++;
            if(count1 != 0 && count2 != 0)  count3 ++;
        }
        
        if(max < count3)    max = count3;
    }
    
    cout << max << endl;
}

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

int main() {
  ll n;
  cin >> n;
  ll ans = INF;
  for (ll i = 1; i * i <= n; i++) {
    ll ni = n / i;
    if (ni * i == n) {
      ans = min(ans, ni + i - 2);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 10;
const ll mod = 1e9 + 7;
int a[N], b[N], p[N];
int d[N];
int c[N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int cnt = 0;
    for (int i = 2; i <= 1000000; ++i)
    {
        if (!b[i])
        {
            p[++cnt] = i;
            a[i] = i;
        }
        for (int j = 1; j <= cnt && p[j] * i <= 1000000; ++j)
        {
            b[i * p[j]] = 1;
            a[i * p[j]] = max(p[j], a[i]);
            if (i % p[j] == 0)
                break;
        }
    }
    for (int i = 1; i <= n; ++i)
    {
        cin >> d[i];
    }
    int G = d[1];
    for (int i = 2; i <= n; ++i)
        G = __gcd(G, d[i]);
    if (G > 1)
    {
        cout << "not coprime";
    }
    else
    {
        bool cp = 0;
        for (int i = 1; i <= n && !cp; ++i)
        {
            int num = d[i];
            for (; num != 1 && !cp; )
            {
                int tmp = a[num];
                for (; num % tmp == 0; num /= tmp)
                    ;
                if (c[tmp])
                    cp = 1;
                else
                    ++c[tmp];
            }
        }
        cout << (cp ? "setwise coprime" : "pairwise coprime");
    }
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    int a, b, c;
    cin >> a >> b >> c;
    int ta = a;
    int tb = b;
    int tc = c;

    int res = 0;
    while(1){
        if(ta%2 || tb%2 || tc%2) break;
        int tea = ta/2;
        int teb = tb/2;
        int tec = tc/2;

        ta = teb + tec;
        tb = tec + tea;
        tc = tea + teb;
        
        if(ta == a && tb ==b && tc == c){
            cout << -1 << endl;
            return 0;
        }
        ++res;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds ;
#define ll long long
#define ld long double
#define pp pair<ll,pair<ll,ll> >
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define sz(a) int((a).size())
#define hell 1000000007
#define f first
#define s second
#define sll(x) scanf("%lld",&x)
#define si(x) scanf("%d",&x)
typedef tree< ll , null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update > ordered_set ;
ll t = 1 ;
void solve() 
{
    ll H , W , h , w ;
    cin >> H >> W >> h >> w ;
    cout << ( H*W + w*h - w*H - W*h ) ;
}   
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //cin>>t;
    while(t--)
        solve() ;
    return 0 ;
}


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

typedef long long ll;

int main() {
    int N, amin = 1e9 + 1, ans, a;
    cin >> N;
    rep(i, N) {
        cin >> a;
        if (a < amin) {
            amin = a;
            ans = i + 1;
        }
    }
    cout << ans << endl;
}


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

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

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

typedef long long int ll;
typedef long double ld;

#define Pb push_back
#define Mp make_pair

#define ff first
#define ss second

#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))

#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN

#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define db1(x) cout<<#x<<" : "<<x<<endl;
#define db2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define db3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;

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

void solve()
{
   int x,n;
   cin >> x >> n;
   int mn = inf;
   int mnv = inf;
   int p[105] = {0};
   for(int i=0;i<n;i++)
   {
      int y;
      cin >> y;
      p[y] = 1;
   }
   for(int i=-100;i<=101;i++)
   {
      if(p[i] == 0)
      {
         if(abs(x-i) < mn)
         {
            mn = abs(x-i);
            mnv = i;
         }
         else if(abs(x-i) == mn)
         {
            mnv = min(mnv,i);
         }
      }
   }
   cout << mnv;
}

signed main()
{
     IOS;
     //freopen("input.txt", "rt", stdin);
     //freopen("output.txt", "wt", stdout);
     int t=1;
     //cin >> t;
     while(t--)
     {
       solve();
     }
     return 0;
}
/*==============================================================================================================================================================*/


Measured memory_bytes: 3648
vx = [1, -1, 0, 0]
vy = [0, 0, 1, -1]


def isBound(n, m, x, y):
    return x < 0 or y < 0 or x >= n or y >= m


def dfs(x, y):
    global field
    global cnt
    global v

    if isBound(W, H, x, y):
        return
    if field[y][x] == '#':
        return
    if v[y][x]:
        return
    else:
        v[y][x] = True
        cnt += 1

    for i in range(4):
        nx = x + vx[i]
        ny = y + vy[i]
        dfs(nx, ny)

while True:
    W, H = map(int, raw_input().split())

    if W == 0:
        break

    field = []
    for h in range(H):
        field.append(raw_input())

    v = [[False for i in range(W)] for j in range(H)]

    cnt = 0
    for x in range(W):
        for y in range(H):
            if field[y][x] == '@':
                dfs(x, y)
    print cnt

Measured memory_bytes: 6556
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class C
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		var A = GetLongs(N);

		var L = new long[N];
		L[0] = A[0];
		for(int i = 1; i < N; i++)
			L[i] = gcd(L[i - 1], A[i]);

		var R = new long[N];
		R[N - 1] = A[N - 1];
		for(int i = N - 2; i >= 0; i--)
			R[i] = gcd(R[i + 1], A[i]);

		long max = Max(R[1], L[N - 2]);
		for(int i = 1; i < N - 1; i++)
			chmax(ref max, gcd(L[i - 1], R[i + 1]));

		WriteLine(max);
	}

	private long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 32092
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll,VL,greater<ll>> PQ_LOW;//昇順

int main(){
  int N,K;cin>>N>>K;
  vector<int> a(N,0);
  REP(i,K){
    int d;cin>>d;
    for(int j=0;j<d;j++){
      int e;cin>>e;
      e--;
      a[e]++;
    }
  }
  int ans=0;
  REP(i,N){
    if(a[i]==0){
      ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);cout.tie(NULL);
        long int n;
        vector<long int> ans(4,0);
        cin>>n;
        vector<string> verdict(4);
        verdict[0]="AC";
        verdict[1]="WA";
        verdict[2]="TLE";
        verdict[3]="RE";
        vector<string>string(n);
        for(long int i=0;i<n;i++){
                cin>>string[i];
                for(int j=0;j<4;j++){
                        if(string[i]==verdict[j]){
                                ans[j]++;
                        }
                }
                
        }
        for(int j=0;j<4;j++){
                cout<<verdict[j]<<" x "<<ans[j]<<"\n";
        }
return 0;
}
/*

        creation time:  13.09.2020 09:23:27

*/                      



Measured memory_bytes: 6308
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define pb push_back
#define mpr make_pair
#define Senky_Bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{   
    Senky_Bansal
    IIIT_ALLAHABAD
    ll n;
  cin>>n;
  ll ans=0;
  ll mx=0;
  for(int i=1;i<=n;i++)
  {
    ll a;
    cin>>a;
    if(a>=mx)
      ans++;
    mx=max(mx,a);
  }
  cout<<ans<<endl;
        






}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int N, K, Q, A[100002], T[100002] = {0};
	int i;
	
  	scanf("%d %d %d", &N, &K, &Q);
  	for(i=0;i<Q;i++){
    	scanf("%d", &A[i]);
    }
  	
  	for(i=0;i<Q;i++){
      	T[ A[i] ]++;
    }
  	
  	for(i=0;i<N;i++){
    	if(T[i+1] > Q-K){
        	printf("Yes\n");
        }else{
        	printf("No\n");
        }
    }
  
    
    return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<stdio.h>
#include<vector>
#define rep(i,n)for(int i=0;i<n;i++)
//printf("%.yf\n",x); xを小数点以下y桁で
using namespace std;
int main() {
    //C++をやるだけです。(ざこね)←ここ重要
    int a[26];
    rep(i, 26) {
        a[i] = 0;
    }
    string s;
    cin >> s;
    rep(i, s.size()) {
        char ch = s[i];
        a[s[i] - 'a']++;
    }
    bool b=false;
    rep(i, 26) {
        if (a[i] % 2 == 1) {
            b = true;
        }
    }
    cout << (b ? "No" : "Yes") << endl;
   return 0;
}


Measured memory_bytes: 256
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd"""

T1,T2=map(int,input().split())
A1,A2=map(int,input().split())
B1,B2=map(int,input().split())

A1*=T1
A2*=T2
B1*=T1
B2*=T2

if A1+A2==B1+B2:
    print("infinity")
else:
    if A1+A2<B1+B2:
        A1,B1=B1,A1
        A2,B2=B2,A2
    if A1>B1:
        print(0)
    else:
        print(((B1-A1)//(A1+A2-(B1+B2)))*2 +1-(((B1-A1)%(A1+A2-(B1+B2)))==0)*1)


Measured memory_bytes: 3064
#include<bits/stdc++.h> 
using namespace std; 
#define x first
#define y second
#define forn(i, n) for(int i = 0; i < int(n); ++i)
typedef pair<int, int> pii;


int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int A,B,C,K;
	cin>>A>>B>>C>>K;
	if(A>=K){
		cout<<K<<endl;
	}
	else if(A+B>=K){
		cout<<A<<endl;
	}
	else{
		cout<<A - (K-(A+B))<<endl;
	}
	return 0;	
}

Measured memory_bytes: 3636
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var inputs []int

	for {
		var s string
		fmt.Scanln(&s)

		if s == "0" {
			break
		}

		i, _ := strconv.Atoi(s)
		inputs = append(inputs, i)
	}

	for i, input := range inputs {
		fmt.Printf("Case %d: %d\n", i+1, input)
	}
}



Measured memory_bytes: 2352
N = int(input())
A = []
XY = []
for i in range(N):
    a = int(input())
    A.append(a)
    xy = [list(map(int,input().split())) for j in range(a)]
    XY.append(xy)
ans = 0
for i in range(2**N):
    b = [i>>j&1 for j in range(N)]
    f = 0
    for j in range(N):
        if b[j] == 1:
            for k in range(A[j]):
                x = XY[j][k][0] -1
                y = XY[j][k][1]
                if b[x] != y:
                    f = 1
                    break
        if f:
            break
    else:
        ans = max(ans,b.count(1))
print(ans)

Measured memory_bytes: 69008
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int ret = 1;
    while(true){
        if(ret << 1 > N) break;
        ret = ret << 1;
    }
    cout << ret;
    cout << endl;
    return 0;
}




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

int main(){
  int a,b,c;
  long long int x;
  cin>>a>>b>>c;
  x=a;
  
  if(a%2==0&&c%2!=0){cout<<"NO"<<endl;return 0;}
  while(x<pow(10,9)){
    if(x%b==c){cout<<"YES"<<endl;return 0;}
    x+=a;
  }
  
  cout<<"NO"<<endl;
  
  return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
while (not ((h == 0)and(w==0)) ):
    for i in range(0,h):
        if ((i==0) or (i==h-1)):
            print('#' * w)
        else:
            if (w==0):
                print()
            elif (w==1):
                print('#')
            else:
                print('#' + '.' * (w-2) + '#')
    print()
    h, w = map(int, input().split())



Measured memory_bytes: 5616
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

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

const ll INF = 1e17;
const ll MOD = 1e9+7;

int main() {
    // input, ready, resolve
    int A,B,C;
    cin >> A >> B >> C;

    if (A == B && A != C) cout << "Yes" << endl;
    else if (B == C && B != A) cout << "Yes" << endl;
    else if (C == A && C != B) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256