akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>

char solve(char mass[])
{
        const int ROW = 8, COL = 3;
        const int bingo[][COL] =
                {{0, 1, 2}, {0, 3, 6}, {0, 4, 8}, {1, 4, 7},
                 {2, 5, 8}, {2, 4, 6}, {3, 4, 5}, {6, 7, 8}};
        int cnt;
        char ans = 'd';

        for (int i = 0; i < ROW; i++) {
                cnt = 0;
                int pos = bingo[i][0];
                if (mass[pos] == 's') {
                        continue;
                }
                for (int j = 1; j < COL; j++) {
                        if (mass[pos] != mass[bingo[i][j]]) {
                                continue;
                        }
                        cnt++;
                        if (cnt == 2) {
                                ans = mass[bingo[i][j]];
                                break;
                        }
                }
        }
        return ans;
}

int main()
{
        char mass[10];

        while (scanf("%9s", mass) != EOF) {
                printf("%c\n", solve(mass));
        }

        return 0;
}

Measured memory_bytes: 2752
def cmb(n, r):
    if n == 1: return 0
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

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

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

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

    return result

n = int(input())
S = [input() for _ in range(n)]
S_sorted = ["".join(sorted(s)) for s in S]
S_sorted = sorted(S_sorted)

ans = 0
cnt = 1
for i in range(1, len(S_sorted)):
    if S_sorted[i] == S_sorted[i-1]:
        cnt += 1
    else:
        ans += cmb(cnt, 2)
        cnt = 1

if cnt > 1:
    ans += cmb(cnt, 2)

print(int(ans))











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

int main(){
    int N, K;
    cin >> N >> K;
    int i;
    int a = K;
    for(i=1;;i++){
        if(N/a == 0)
            break;            
        a *= K;
    }
    cout << i << endl;
    return 0;
}

Measured memory_bytes: 256
import sys


def bubble_sort(a):
    count = 0
    flag = True
    while flag:
        flag = False
        for j in range(len(a) - 1, 0, -1):
            if a[j] < a[j - 1]:
                count += 1
                a[j], a[j - 1] = a[j - 1], a[j]
                flag = True
    return count


n = int(sys.stdin.readline())
a = [int(v) for v in sys.stdin.readline().strip().split()]
count = bubble_sort(a)
print(' '.join(map(str, a)))
print(count)



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

int main() {
  int n;
  cin >> n;
  vector<long long> v(n);
  
  for(int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    v.at(i) = a;
  }
  
  long long ans = 0;
  
  for(int i = 0; i < n - 1; i++) {
    if(v.at(i) > v.at(i + 1)) {
      ans += v.at(i) - v.at(i + 1);
      v.at(i + 1) = v.at(i);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4748
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional> // std::function<void(int)>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> b(n+2,inf);
    for(int i=1;i<n;i++)cin>>b[i];
    int res=0;
    for(int i=0;i<n;i++){
        res+=min(b[i],b[i+1]);
    }
    cout<<res<<endl;
}

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

int n,m,col,ans;
int a[200010],b[200010],f[410],used[410];
bitset<512> g[410];

int check(int p)
{int i,j;
 
 col++;
 used[p]=col;
 for(i=m;i>=1;i--)
 {	if(used[a[i]]==col && used[b[i]]==col) return 0;
 	if(used[a[i]]==col)
 		used[b[i]]=col;
 	else if(used[b[i]]==col)
 		used[a[i]]=col;
 }
 for(i=1;i<=n;i++)
 	if(used[i]==col) g[p][i]=1;
 return 1;
}	

int main()
{int i,j,x,y,fx,fy;
 bitset<512> w;
 
 scanf("%d%d",&n,&m);
 for(i=1;i<=m;i++)
 	scanf("%d%d",&a[i],&b[i]);
 for(i=1;i<=n;i++)
 	f[i]=check(i);
 	
 //cout<<f[1]<<" "<<f[2]<<" "<<f[3]<<endl;	
 	
 for(i=1;i<=n;i++)
 	for(j=i+1;j<=n;j++)
 		if(f[i] && f[j])
		{	w=(g[i]&g[j]);
			ans+=w.none();
		}
 printf("%d\n",ans);
 return 0;
}

Measured memory_bytes: 1024
while True:
  H, W = list(map(int, input().split()))
  if H == 0 and W == 0:
    break
  else:
    for i in range(H):
      if i % 2 == 0:
        print(('#.' * 150)[:W])
      else:
        print(('.#' * 150)[:W])
    print()


Measured memory_bytes: 5608
#include<iostream>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
    string s;
    cin>>s;
    bool flag=false;
    rep(i,s.size()-1)
    {
        if(s[i]!=s[i+1])
        {
            flag=true;
            break;
        }
    }
    if(flag)cout<<"Yes\n";
    else cout<<"No\n";

    return 0;
}

Measured memory_bytes: 256
#include<iostream>

int main(){
    
    size_t a, b, c;
    std::cin >> a >> b >> c;

    if(a + b + c > 21){
        std::cout << "bust" << std::endl;
    }else{
        std::cout << "win" << std::endl;
    }
    
    return 0;
}


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

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if ((a * 100 + b * 10 + c) % 4 == 0) cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	long a, b, c, d;
	cin >> a >> b >> c >> d;
	if ((((a - 1) / d) + 1) >= (((c - 1) / b) + 1) )
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}

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

int main() {
  int n,m;cin>>n>>m;
  vector<int>a(n),b(n),c(m),d(m);
  rep(i,n)cin>>a[i]>>b[i];
  rep(i,m)cin>>c[i]>>d[i];
  rep(i,n){
    int ans=1e9,x;
    rep(j,m){
      int cnt=abs(a[i]-c[j])+abs(b[i]-d[j]);
      if(cnt<ans){
        ans=cnt;
        x=j+1;
      }
    }
    cout<<x<<endl;
  }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define FOR(i,a,b)  for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n)    FOR(i,0,n)
#define RER(i,n)    FOR(i,0,(n+1))
#define pb          push_back
#define mp(a,b)     make_pair((a),(b))
#define mset(m,v)   memset(m,v,sizeof(m))
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pair<ll, ll> > vpll;
typedef vector<string> vs;
typedef long double ld;
const double EPS    = 1e-10;
const int INF       = 1e+9;
const double PI     = acos(-1);


auto main() -> int
{
    int n, k, x, y;
    cin >> n >> k >> x >> y;

    cout << min(n, k) * x + max(n-k, 0) * y << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>
#include <sstream>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

/*
0のアスキー　"48"
*/

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) x.begin(),x.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

int main(){
    int N;
    cin >> N;
    vector<int> d1(N),d2(N);

    for(int i = 0;i < N;i++)
        cin >> d1.at(i) >> d2.at(i);
    bool fla = false;
    int res = 0;
    for(int i = 0;i < N;i++){
        if(d1.at(i) == d2.at(i) and res < 2){
            res++;
        }else if(d1.at(i) == d2.at(i) and res == 2){
            fla = true;
            break;
        }
        else{
            res = 0;
        }
    }

    if(fla)
        cout << "Yes" << endl;
    else
    {
        cout << "No" << endl;
    }
         
}

Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100111;
const int inf=1000000007;
const long long INF=1000000000000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


int main(){
	ll x,y,sum=0;
	cin>>x>>y;
	if(x+y<=1)print("Brown");
	else{
		if(abs(x-y)>1)print("Alice");
		else print("Brown");
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl

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

  int A,B; cin>>A>>B;
  if(A==1)A=14;
  if(B==1)B=14;

  if(A>B)cout << "Alice" <<endl;
  else if(A<B)cout << "Bob" <<endl;
  else cout << "Draw" << endl;

  return 0;
}


Measured memory_bytes: 256
void main() {
    int n = readln.chomp.to!int;
    int[] l = readln.split.to!(int[]);
    writeln(l.sum > 2 * l.reduce!max ? "Yes" : "No");
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons;

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,i,f,g,cnt=0,j;
    char c[20],d[20],e[20];
    scanf("%s%s",c,d);
    scanf("%d%d",&a,&b);
    scanf("%s",e);
    f=strlen(c);
    g=strlen(e);
    if(f==g)
    {
        for(i=0;i<f;i++)
        {
            if(c[i]==e[i])
                cnt++;
        }
    }
    if(cnt==f)
        printf("%d %d\n",a-1,b);
    else
        printf("%d %d\n",a,b-1);
    return 0;
}



Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
int main(){
  int c7=0,c5=0,n;
  for(int i=0;i<3;i++){
    scanf("%d",&n);
    if(n==7)
      c7++;
    else if(n==5)
      c5++;
  }
  if(c7==1&&c5==2)
    printf("YES\n");
  else
    printf("NO\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

int main()
{
   FAST/**/
   
   ll x;
   cin>>x;
   
   ll ans = 0;
   ans = 1000*(x/500);
   x%=500;
   ans+=5*(x/5);
   cout<<ans;
   
   
   return 0;        
}  
   

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	ll A,B,C;
	scan(A);scan(B);scan(C);
	C=min(C,A+B+1);
	prin(B+C);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;



int main() {
	string s, t;
	cin >> s >> t;
	int a,b;
	cin >> a >> b;
	string u;
	cin >> u;
	if (u == s) {
		a--;
	}
	else {
		b--;
	}
	cout << a << " " << b << endl;
}





Measured memory_bytes: 256
A = int(input())

alp = [chr(i) for i in range(97, 97+26)]

def Base_10_to_n_alp(X, n):
    X = X-1
    if (int(X/n)):
        return Base_10_to_n_alp(int(X/n), n)+alp[X%n]
    return alp[X%n]

print(Base_10_to_n_alp(A,26))


Measured memory_bytes: 9172
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
const ll INF = 5e15;
const ll MOD = 1e9 + 7;
ll dp[200][11];
int main(){
    ll H, W, K;
    cin >> H >> W >> K;
    dp[0][0] = 1;
    for(ll i = 1; i <= H; i++){
        for(ll now = 0; now < W; now++){
            for(ll b = 0; b < (1 << (W - 1)); b++){
                bool correct = 1;
                for(ll d = 0; d < W; d++){
                    if((b & (1 << d)) && (b & (1 << (d + 1)))) {
                        correct = 0;
                        break;
                    }
                }
                if(!correct) continue;
                if(b & (1 << now)) dp[i][now + 1] = (dp[i][now + 1] + dp[i - 1][now]) % MOD;
                else if(now && (b & (1 << (now - 1)))) dp[i][now - 1] = (dp[i][now - 1] + dp[i - 1][now]) % MOD;
                else dp[i][now] = (dp[i][now] + dp[i - 1][now]) % MOD;
            }
        }
    }
    cout << dp[H][K - 1] << endl;
    return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  if ((a + b) % 2 == 0) cout << (a + b) / 2 << endl;
  else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 3568
# coding: utf-8
# Your code here!
# 幅優先探索（行きがけ）
import collections
import sys
import copy
import re
import math


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    s = S()

    if s[-1] == "s":
        ans = s+"es"
        print(ans)
    else:
        ans = s+"s"
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9880
#include <algorithm>
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;

int main(){
    long long People[5],N,P=0;
    long long Total=0;
    cin >> N;
    for(int i=0;i<5;i++){
        cin >>People[i];
    }
    sort(People,People+5);
    if(N%People[0]==0){
        P=N/People[0];
    }else{
        P=N/People[0]+1;
    }
    if(People[0]>=N){
        Total = 5;
    }else{
        Total = P + 4;
    }
    cout << Total << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
using namespace std;
/*階乗*/
ll factorial(ll n){
    if(n==0){
        return 1;
    }
    else{
        return n*factorial(n-1);
    }
}

/* ユークリッドの互除法 最大公約数*/
/*ll gcd(ll a, ll b) {
	ll r;
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
*/


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

/*二点間の距離*/
double dist(pair<double,double> a,pair<double,double> b){
	return sqrt(pow((a.first - b.first) ,2) + pow((a.second - b.second),2));
}

//繰り返し自乗法
double ism(double aa,ll p){
    double ap=aa;
    double ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans*=ap;
        }
        p/=2;
        ap=ap*ap;
    }
    return ans;

}
//繰り返し自乗法(アマリトリバージョン)
ll ismm(ll aa,ll p,ll m){
    ll ap=aa;
    ll ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans=(ans*ap)%m;    
        }
        p/=2;              
        ap=(ap*ap)%m;
    }
    return ans;

}
/*
ll solve(ll i,ll m,vector<ll>t,ll n){
    if(m==0){
        return 1;
    }
    if(i>=n){
        return 0;
    }
    
    
    cout<<i+1<<" "<<m<<endl;
    cout<<i+1<<" "<<m-t[i]<<endl;
    ll res=solve(i+1,m,t,n)||solve(i+1,m-t[i],t,n);
    return res;
}
*/

//小数点12桁
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;


int main()
{
    ll n,k,count=0;
    cin>>n>>k;
    while(n>k-1){
        n=n/k;
        count++;
    }
    cout<<count+1<<endl;
    

    

}

Measured memory_bytes: 764
import fractions
from functools import reduce


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


N, X=map(int,input().split( ))
x=list(map(int,input().split( )))
def minus_d(x):
	x = abs(x-X)
	return x

def percent_d(x):
	x = x % d
	return x

dis = list(map(minus_d, x))
ans = gcd_list(dis)
print(ans)


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

int main(){
int n, a, b, c, d;
cin >> n;

a = n/1000;
b = (n-a*1000)/100;
c = (n-a*1000-b*100)/10;
d = (n-a*1000-b*100-c*10);

if(a == b &&b== c  || b == c&&c == d )cout << "Yes" << endl;
else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
	int c;

	while (1) {
		c = getchar();
		if (c == EOF)
			break;
		if ('A' <= c && c <= 'Z')
			putchar(c + 32);
		else if ('a' <= c && c <= 'z')
			putchar(c - 32);
		else
			putchar(c);
	}
	return 0;
}



Measured memory_bytes: 2032
n,k=map(int,input().split())
h=list(map(int,input().split()))
d=[float('inf')]*n
d[0]=0
for i in range(1,n):
    d[i]=min(d[j]+abs(h[i]-h[j]) for j in range(max(0,i-k),i))
print(d[n-1])

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

using namespace std;

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

inline bool inrange(int x, int y) {
  return (0<=x&&x<8) && (0<=y&&y<8);
}

string F[8];
//char F[8][9];
bool used[8][8];
int turn;

bool debug;

int dx, dy;
int dfs(int x, int y, char me, int cnt) {

  x += dx, y += dy;
  if(!inrange(x, y)) { return 0; }
  if(F[y][x] == '.') { return 0; }
  if(F[y][x] == me) {
    return cnt;
  }
  used[y][x] = 1;
  int r = dfs(x, y, me, cnt+1);
  if(r == 0) { used[y][x] = 0; }
  return r;
}

#define DREP(i, a, b, c, d)                                 \
  for(int i=turn&1?a:c; turn&1?i>=b:i<=d; turn&1?i--:i++)

int main() {
  /*
  rep(i, 8) rep(j, 8){
    cin >> F[i][j];
  }
  //  */
  rep(i, 8) cin >> F[i];
  
  int ucnt = 0;
  for(turn=0; turn<=64; turn++) {
    int pl;
    bool u[8][8] = {};
    int mx = 0;
    DREP(i, 7, 0, 0, 7)
      DREP(j, 7, 0, 0, 7) {
      if(F[i][j] == '.') {
        rep(a, 8) rep(b, 8) used[a][b] = 0;
        used[i][j] = 1;
        int r = 0;
        for(dy=-1; dy<2; dy++) for(dx=-1; dx<2; dx++) {
          if(dx == 0 && dy == 0) { continue; }
          r += dfs(j, i, "ox"[turn&1], 0);
        }            
        
        if(mx < r) {
          memcpy(u, used, sizeof u);
          mx = r;
          pl = turn&1;
        }
        
      }
    }
    if(mx > 0) {
      rep(i, 8) rep(j, 8)
        if(u[i][j]) { F[i][j] = "ox"[pl]; }
      
      ucnt = 0;
    }
    else {
      if(ucnt) { break; }
      ucnt ++;
    }
  }
  
  rep(i, 8) {
    rep(j, 8) {
      cout << F[i][j];
    }
    cout << endl;
  }
  
  return 0;
}

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

int main() {
	int n, k;
	cin >> n >> k;
	int num = 1;
	for (int i = 0; i < n; i++) {
		num = min(num * 2, num + k);
	}
	cout << num << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/perl
#abc083_d.pl
#Wed Jan 10 20:31:35 2018
#

use warnings;
use strict;

my $s = <STDIN>;
chomp $s;

my @target = split("",$s);

my $num = 1;
my $answer = 9999999;

while ($num<=$#target){
	if ($target[$num] != $target[$num-1]){
		my $answercand = 0;
		if ($#target-$num+1 > $num){
			$answercand = $#target-$num+1;
		}else{
			$answercand = $num;
		}
		if ($answer > $answercand){
			$answer = $answercand;
		}
	}
	$num++;
}

if ($answer == 9999999){
	$answer = $#target+1;
}

print $answer,"\n";

Measured memory_bytes: 16512
N = gets.to_i
A = gets.split(" ").map(&:to_i).sort

while A.size > 1 do 
    (A.size - 1).times do |i|
        A[i + 1] %= A[0]
    end
    A.select! {|x| x != 0}
    A.sort!
end

puts A[0]



Measured memory_bytes: 10112
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

typedef long long ll;
typedef unsigned long long ull;

void solve(ll a, ll b)
{
  if (a > b) swap(a, b);
  //常に a <= b

  if (b - a <= 1) {
    cout<<2 * (a - 1)<<endl;
  } else {
    ll c = (int) sqrt(a * b);
    if (c * c == a * b) c--;

    if (c * (c + 1) >= a * b) {
      cout<<2 * (c - 1)<<endl;
    } else {
      cout<<2 * c - 1<<endl;
    }
  }
}


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

  ll a[q], b[q];
  REP(i,q) cin>>a[i]>>b[i];

  REP(i,q) solve(a[i], b[i]);

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(a+b>c+d) printf("Left\n");
    if(a+b<c+d) printf("Right\n");
    if(a+b==c+d) printf("Balanced\n");
    return 0;
}



Measured memory_bytes: 128
N, M = [int(x) for x in input().split()]
students = []
checkpoints = []

for i in range(N):
	students.append([int(x) for x in input().split()])
for i in range(M):
	checkpoints.append([int(x) for x in input().split()])
def distance(s, c):
  return abs(s[0]- c[0]) + abs(s[1]- c[1])

for s in students:
	mind = 10**10
	mini = -1
	for i, c in enumerate(checkpoints):
		d = distance(s, c)
		if d < mind:
			mind = d
			mini = i+1
	print(mini)




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

using namespace std;

typedef long long int ll;

int num[6000];
int p[6000];

int main()
{
    ios::sync_with_stdio(false);
    int n=5,x;
    for(int i=1;i<=n;++i){
        cin>>x;
        if(x==0){
            cout<<i;
            return 0;
        }
    }
    cout<<"Die";
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;

// tourist set
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << '\n'; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set 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; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<'\n'
#define p2(s, t) cout << (s) << " " << (t) << '\n'
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << '\n'
#define p_yes() p("Yes")
#define p_no() p("No")
#define SZ(x) ((int)(x).size())
#define SORT(A) sort(ALL(A))
#define RSORT(A) sort(ALL(A), greater<ll>())

void no(){p_no(); exit(0);}
void yes(){p_yes(); exit(0);}

const ll mod = 1e9 + 7;
const ll inf = 1e18;
const double PI = acos(-1);

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

    // input
    string s; cin >> s;
    if(s[0]==s[1] && s[1]==s[2]){
      p_yes();
    }
    else if(s[1]==s[2] && s[2]==s[3]){
      p_yes();
    }
    else{
      p_no();
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define NIL -1
#define MAX 10000

struct Node { int parent, left, right; };
Node T[MAX];
int D[MAX], H[MAX];

void setDepth(int u, int d)
{
    if ( u == NIL ) return;
    D[u] = d;
    setDepth(T[u].left, d+1);
    setDepth(T[u].right, d+1);
}

int setHeight(int u)
{
    int hl = 0, hr = 0;
    if(T[u].left != NIL)
        hl = setHeight(T[u].left) + 1;
    if (T[u].right != NIL)
        hr = setHeight(T[u].right) + 1;
    return H[u] = (hl > hr ? hl : hr);
}

int getSibling(int u)
{
    if (T[u].parent == NIL) return NIL;
    if (T[T[u].parent].right == u && T[T[u].parent].left != NIL) return T[T[u].parent].left;
    if (T[T[u].parent].left == u && T[T[u].parent].right != NIL) return T[T[u].parent].right;
    return NIL;
}

void print(int u){
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].parent);
    printf("sibling = %d, ", getSibling(u));
    int deg = 0;
    if(T[u].right != NIL) ++deg;
    if(T[u].left != NIL ) ++deg;
    printf("degree = %d, ", deg);
    printf("depth = %d, ", D[u]);
    printf("height = %d, ", H[u]);

    if(T[u].parent == NIL) printf("root\n");
    else if (T[u].right == NIL && T[u].left == NIL) printf("leaf\n");
    else printf("internal node\n");

}

int main()

{
    int n, id, l, r, root;

    // cin >> n;
    scanf("%d", &n);
    rep(i, n) T[i].parent = NIL;

    rep(i, n){
        cin >> id >> l >> r;
        // scanf("%d %d %d", &id, &l, &r);
        T[id].left = l;
        T[id].right = r;
        if(l != NIL) T[l].parent = id;
        if(r != NIL) T[r].parent = id;

    }

    rep(i, n) if(T[i].parent == NIL) root = i;

    setDepth(root, 0);
    setHeight(root);

    rep(i, n) print(i);

    return 0;
}


Measured memory_bytes: 3240
#include <cstdio>
#include <cstring>
typedef long long LL;
#define MAX(a,b) ((a)>=(b)?(a):(b))
int p[100],q[100],r[100],b[100];
LL memo[100];
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 solve(int n) {
	if(memo[n]!=-1) return memo[n];
	LL L,R;
	if(r[n]==-1) L=1; else L=solve(r[n]);
	if(b[n]==-1) R=1; else R=solve(b[n]);
	LL tmp=lcm(L*p[n],R*q[n]);
	return memo[n]=(tmp/p[n]+tmp/q[n]);
}
int main() {
	int n;
	while(scanf("%d",&n),n) {
		for(int i=0;i<n;i++) {
			scanf("%d %d %d %d",&p[i],&q[i],&r[i],&b[i]);r[i]--;b[i]--;
		}
		memset(memo,-1,sizeof(memo));
		LL ans=0;
		for(int i=0;i<n;i++) {
			ans=MAX(ans,solve(i));
		}
		printf("%lld\n",ans);
	}
}

Measured memory_bytes: 1028
s = list(input())
ans = 0
for i in range (len(s)):
         if i % 2 == 0:
                  if s[i] == "L":
                           ans = 1
         else:
                  if s[i] == "R":
                           ans = 1
if ans == 1:
         print("No")
else:
         print("Yes")


Measured memory_bytes: 3064
fn main() {
    proconio::input! {
        n: proconio::marker::Chars,
    }
    let mut sum = 0usize;
    for c in n {
        sum += c.to_string().parse::<usize>().unwrap();
    }
    let ans = if sum % 9 == 0 { "Yes" } else { "No" };
    println!("{}", ans);
}


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

#define dv(i) for (int c=0; c<(int)(i).size(); c++) cout<<(i)[c]<<(c==(int)(i).size()-1?"\n":" ")
#define da(i) for (int c=0; c<(int)(sizeof((i))/sizeof((i)[0])); c++) cout<<(i)[c]<<(c==(int)(sizeof((i))/sizeof((i)[0]))-1?"\n":" ")
#define ds(i) for (auto f: i) cout<<f<<"\n";
#define dm(i) for (auto f: i) cout<<f.first<<" "<<f.second<<"\n"
#define F0R(i,a,b) for (int i=a; i<(b); i++)
#define FOR(i,a) for (int i=0; i<(a); i++)
#define F0Rd(i,a,b) for (int i=(b)-1; i>=a; i--)
#define FORd(i,a) for (int i=(a)-1; i>=0; i--)

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define sz(x) (int) x.size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define alp(i) i,i + sizeof(i) / sizeof(i[0])
#define memp(i,x) std::memset(i, x, sizeof i)
#define fils(i,x) std::fill(all(i), x)
#define filp(i,x) std::fill(alp(i), x)
#define dr4 {0, 1, 0, -1}
#define dc4 {1, 0, -1, 0}
#define dr8 {-1, -1, -1, 0, 1, 1, 1, 0}
#define dc8 {-1, 0, 1, 1, 1, 0, -1, -1}
#define inBounds(a,b,c,d) (a >= 0 && a < c && b >= 0 && b < d)

string rem(string s) {if(s[s.size()-1]=='\r')s.erase(s.size()-1);return s;}
vector<string> split(string s, char delim) {replace(s.begin(),s.end(),delim,' ');stringstream ss(s); string buf;vector<string> v;while (ss>>buf) v.push_back(buf);return v;}

const int MOD = 1000000007;
const double EPS = 1e-6;

#ifndef KMPC
    const int MAXN = -1;
#else
    const int MAXN = -1;
#endif

inline vi ints(int x) { vi A(x); FOR(i,x) cin >> A[i]; return A; }
inline vl lls(int x) { vl A(x); FOR(i,x) cin >> A[i]; return A; }
inline vs strs(int x) { vs A(x); FOR(i,x) cin >> A[i]; return A; }

int tc() {
    int A, B; cin >> A >> B; cout << A * B << '\n';

    return 0;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    
    int A, B; cin >> A >> B; cout << A * B << '\n';
 
    return 0;
}

Measured memory_bytes: 3584
N,K = map(int,input().split())
A = list(map(int,input().split()))
A = [i-1 for i in A]

flag = [False]*N
from collections import deque

q = deque([])
q.append(0)
flag[0] = True
now = 0
while True:
  now = A[now]
  if flag[now]:
    break
  else:
    flag[now] = True
    q.append(now)
    
l = list(q)
if K<len(l):
  print(l[K]+1)

else:
  for i,x in enumerate(l):
    if x==now:
      l = l[i:]
      K -= i
      break
  
  print(l[K%len(l)]+1)

Measured memory_bytes: 32320
n = gets.chomp!.to_i
ls = gets.split(" ").map(&:to_i)


min = ls[0]
count = 1
for i in 1..n-1 do
  if ls[i] < min
    #print("#{ls[i]}:#{min}\n")
    min = ls[i]
    count += 1
  end
end

p count

Measured memory_bytes: 15236
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<list>
#define LL long long
#define FF(i,a,b) for(int i=a;i<=b;++i)
#define RR(i,a,b) for(int i=a;i>=b;--i)
#define SC(x) scanf("%d",&x)
#define SCC(x,y) scanf("%d%d",&x,&y)
#define SCCC(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define SS(x) scanf("%s",x)
#define PR(x) printf("%d\n",x)
#define CL(a,b) memset(a,b,sizeof(a))
#define ll rt<<1
#define rr rt<<1|1
#define mid int m=(x+((y-x)>>1))
#define lson x,m,rt<<1
#define rson m+1,y,rt<<1|1
#define lowbit(x) (x&-x)
#define PB push_back
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)
#define fi freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
using namespace std;

const int N = 1e5 + 10;
const int inf = 1e9;

int h, w;
LL ans;
void go(int n, int m)
{
    FF(i, 1, m-1)
    {
        LL a1 = 1LL*n*i;
        int curm = m-i;
        if(curm%2==0 || n%2==0){
            LL a2 = 1LL * curm * n / 2;
            LL cur = abs(a1 - a2);
            ans = min(ans, cur);
        }
        else{
            int mi = min(curm, n), ma = max(curm, n);
            LL a2 = 1LL * mi * (ma/2);
            LL a3 = 1LL * mi * (ma - ma/2);
            LL c1 = abs(a1-a2), c2 = abs(a1-a3), c3 = abs(a2-a3);
            LL cur = max(c1, max(c2, c3));
            ans = min(ans, cur);
        }
    }
}
int main()
{
#ifndef ONLINE_JUDGE

#endif

    SCC(h, w);
    ans = 1e18;
    go(h, w);
    go(w, h);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second

ll gcd(ll a,ll b){//最大公約数を求める
    if(a<b){
        swap(a,b);
    }

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

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0;i < n;i++)
    {
        cin >> v.at(i);
    }

    int x = gcd(v.at(0),v.at(1));

    for(int i=2;i < n-1;i++)
    {
        if(x==1){
            cout << 1 << endl;
            return 0;
        }

        x = gcd(x,v.at(i));
    }

    cout << x << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
 
using namespace std;
 
#define MAX 100
typedef pair<int,int> P;
 
int main(){
    int a, b, c, N;
 
    while(cin >> a >> b >> c, a){
	cin >> N;
	int x, y, z, r;
	bool I[MAX], J[MAX], K[MAX];
 
	for(int i = 0 ; i < MAX ; i++){
	    I[i] = J[i] = K[i] = false;
	}
 
	vector<P> A[MAX], B[MAX], C[MAX];
	for(int i = 0 ; i < N ; i++){
	    cin >> x >> y >> z >> r; 
	    x--, y = y-a-1, z = z-a-b-1;
 
	    if(r == 1){
		I[x] = J[y] = K[z] = true;
	    }
	    A[x].push_back(P(y,z));
	    B[y].push_back(P(x,z));
	    C[z].push_back(P(x,y));
	}
 
	for(int i = 0 ; i < a ; i++){
	    if(I[i]){
		cout << 1 << endl;
	    }else{
		bool flg = false;
		for(int j = 0 ; j < A[i].size() ; j++){
		    if(J[A[i][j].first] && K[A[i][j].second]){
			flg = true;
			break;
		    }
		}
		cout << (flg?0:2) << endl;
	    }
	}
 
	for(int i = 0 ; i < b ; i++){
	    if(J[i]){
		cout << 1 << endl;
	    }else{
		bool flg = false;
		for(int j = 0 ; j < B[i].size() ; j++){
		    if(I[B[i][j].first] && K[B[i][j].second]){
			flg = true;
			break;
		    }
		}
		cout << (flg?0:2) << endl;
	    }
	}
	for(int i = 0 ; i < c ; i++){
	    if(K[i]){
		cout << 1 << endl;
	    }else{
		bool flg = false;
		for(int j = 0 ; j < C[i].size() ; j++){
		    if(I[C[i][j].first] && J[C[i][j].second]){
			flg = true;
			break;
		    }
		}
		cout << (flg?0:2) << endl;
	    }
	}
    }
    return 0;
}

Measured memory_bytes: 3176
TT = int(input())
import heapq

for loop in range(TT):

    N = int(input())

    L = []
    R = []

    abmax = 0

    for i in range(N):

        k,l,r = map(int,input().split())

        if l >= r:
            L.append( (k,l,r) )
            abmax += l
        else:
            R.append( (N-k,r,l) )
            abmax += r

    L.sort()
    R.sort()

    q = []
    for i in range(len(L)):

        k,nowc,nexc = L[i]
        heapq.heappush( q , nowc-nexc )

        while len(q) > k:
            tmp = heapq.heappop(q)
            abmax -= tmp

    q = []
    for i in range(len(R)):

        k,nowc,nexc = R[i]
        heapq.heappush( q , nowc-nexc )

        while len(q) > k:
            tmp = heapq.heappop(q)
            abmax -= tmp

    print (abmax)


Measured memory_bytes: 116172
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define nl cout<<endl
 
#define pii pair<ll,ll>
#define vi  vector<ll>
#define vii vector<pii>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()
 
#define pb push_back
#define ff first
#define ss second
#define hell 1000000007
 
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
#define N 300009
 
ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
int main()
{	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	string s;cin>>s;
	if(s=="AAA" or s=="BBB")
	cout<<"No"<<endl;
	else
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
/**
 * Author: Behradm
 * Created: 03-05-2020 16:38:19
 * In the Name of God
**/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define LOCAL

#ifdef LOCAL
	#define debugi(x) cerr << "{" << #x << "}: " << (x) << '\n'
	#define debug(v, begin, end) cerr << "{ | "; for(auto i = begin; i < end; i++){cerr << #v << "[" << i << "]: " << v[i] << " | ";} cerr << " }\n"
	#define debugp(a, b) cerr << "\n{ " << a << " " << b << " }\n"
#else
	#define debugi(x) 42
	#define debug(v, begin, end) 42
	#define debugp(a, b) 42 
#endif

const int maxn = 1e5+1;
bool cnt[maxn];

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	cout.tie(0);
	cout.precision(6);
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < k; i++){
		int d;
		cin >> d;
		for (int j = 0; j < d; j++){
			int a;
			cin >> a;
			cnt[a] = true;
		}
	}

	int res = 0;
	for (int i = 1; i <= n; i++){
		if (!cnt[i])
			res++;
	}
	cout << res << '\n';
	return 0;
}



Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

///////////////////////////



int main() {

	ll N;
	cin >> N;
	vector<ll> A(N + 1), B(N + 1);
	repn(i, N) cin >> A[i] >> B[i];

	ll mn = INF;
	ll id = 0;
	repn(i, N) {
		if (mn > B[i]) {
			mn = B[i];
			id = i;
		}
	}

	cout << A[id]+mn;
	

	system("PAUSE");
}


Measured memory_bytes: 2040
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int K,R,L;
double P,E,T;

double f(int cur,double R,double L){
	if(T-E<=R && L<=T+E)return 1;
	if(L<=T-E || T+E<=R)return 0;
	double H=(R+L)/2;
	if(cur==K)return abs(H-T)<=E;
	if(H>=T)return (1-P)*f(cur+1,R,H) + P*f(cur+1,H,L);
	else return (1-P)*f(cur+1,H,L) + P*f(cur+1,R,H);
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>K>>R>>L>>P>>E>>T;
	cout<<fixed<<setprecision(16)<<f(0,R,L)<<endl;
}

Measured memory_bytes: 1304
#include<stdio.h>

int main()
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(a+b==c+d){
        printf("Balanced\n");
    }
    else if(a+b>c+d){
        printf("Left\n");
    }
    else{
        printf("Right\n");
    }


    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <list>
#include <set>
using namespace  std;

constexpr int INF = std::numeric_limits<int>::max();

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, C;
    cin >> N >> M >> C;

    vector<int> B(M);
    for (int &b: B) {
        cin >> b;
    }

    int ans = 0;
    while (N--) {
        int x = C;
        for (int i = 0; i < M; i++) {
            int a;
            cin >> a;
            x += a * B[i];
        }

        if (x > 0) {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream> 
#include<algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring> 
using namespace std;
const int N=1e5+10;
const int INF=1e9;
int n,m,s,t,dis[N][3];
vector<int> G[N];
void bfs(){
	memset(dis,-1,sizeof(dis));
	dis[s][0]=0;
	queue<pair<int,int> >que;
	que.push({s,0});
	while(!que.empty()){
		pair<int,int> u=que.front();que.pop();
		for(int i=0;i < G[u.first].size();i++){
			if(dis[G[u.first][i]][(u.second+1)%3]<0){
				dis[G[u.first][i]][(u.second+1)%3]=dis[u.first][u.second]+1;
				que.push({G[u.first][i],(u.second+1)%3});
			}
		}
	}
	
}
int main(){
	cin>>n>>m;
	int u,v;
	while(m--){
		cin>>u>>v;
		G[u].push_back(v);
	}
	cin>>s>>t;
	bfs();
	if(dis[t][0]==-1)puts("-1");
	else cout<<dis[t][0]/3<<endl;
	return 0;
}


Measured memory_bytes: 6912
#include<stdio.h>
#include<math.h>
#define PI 3.141592653

void koch(int n, double p1x,double p1y,double p2x,double p2y){


  if(!n)return;
  double sx,sy,tx,ty,ux,uy;

  sx = (2*p1x+p2x)/3;
  sy = (2*p1y+p2y)/3;
  tx = (p1x+2*p2x)/3;
  ty = (p1y+2*p2y)/3;

  ux = (tx-sx)*cos(PI/3)-(ty-sy)*sin(PI/3)+sx;
  uy = (tx-sx)*sin(PI/3)+(ty-sy)*cos(PI/3)+sy;

  koch(n-1,p1x,p1y,sx,sy);
  printf("%f %f\n",sx,sy);
  koch(n-1,sx,sy,ux,uy);
  printf("%f %f\n",ux,uy);
  koch(n-1,ux,uy,tx,ty);
  printf("%f %f\n",tx,ty);
  koch(n-1,tx,ty,p2x,p2y);
  
}

int main(){
  int n;

  scanf("%d",&n);
  printf("%f %f\n",0.0,0.0);
  koch(n,0.0,0.0,100.0,0.0);
  printf("%f %f\n",100.0,0.0);
  return 0;
}



Measured memory_bytes: 2092
from collections import deque
N,M = list(map(int, input().split()))
ab = deque([[] for i in range(N+1)])
for _ in range(M):
  A= list(map(int, input().split()))
  ab[A[0]].append(A[1])
  ab[A[1]].append(A[0])

ans = [0]*(N+1)
done = [0]*(N+1)
done[0]=1
done[1]=1

stack = deque([1])

while stack:
  x = stack.pop()
  temp = deque([])
  for i in ab[x]:
    if done[i] == 0:
      done[i] += 1
      ans[i] = x
      stack.appendleft(i)

print('Yes')
for i in range(2,len(ans)):
  print(ans[i])




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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

void solve(int n)
{
	vvi d(n,vi(n));
	if(n%2==0){
		rep(i,n) rep(j,n) if(j!=i&&j!=n-1-i)
			d[i][j]=1;
	}
	else{
		rep(i,n-1) d[i][n-1]=d[n-1][i]=1;
		rep(i,n-1) rep(j,n-1) if(j!=i&&j!=n-2-i)
			d[i][j]=1;
	}
	vector<tuple<int,int>> res;
	rep(i,n) repi(j,i+1,n) if(d[i][j])
		res.emplace_back(i,j);
	cout<<res.size()<<endl;
	for(auto t:res)
		cout<<get<0>(t)+1<<' '<<get<1>(t)+1<<endl;
}

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int n;cin>>n&&n;){
		solve(n);
	}
}


Measured memory_bytes: 384