akhauriyash/Code-Regression huggingface dataset:
// In the Name of God
#include<bits/stdc++.h>

#define test(t) int t; cin>>t; while(t--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORE(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define ll long long int
#define em emplace_back
#define pb push_back
#define INF 1e7+5
#define MOD int(1e9+7)
#define print printf
#define in scanf
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

template<class type>
void displaySingle(type &arr)
{
	for(auto i:arr)
		cout<<i<<" ";
	cout<<endl;
}

template<class type>
void displayDouble(type &arr)
{
	for(auto &&i : arr) 
	{
		for(auto &&j : i) 
			cout << j << " ";
		cout << std::endl;
	}
}


int main()
{
	fast
	int a,b,c;
	cin>>a>>b>>c;
	int count = 0;
	FORE(i,a,b)
	{
		if(i%c == 0)
			count++;
	}
	cout<<count<<endl;
}

Measured memory_bytes: 3604
object Main {
  val sc = new java.util.Scanner(System.in)

  // x,y?????§?¨??????????????????????
  // x+y ?????¶??°??????# ?\???°??????. ????????????
  def cell(x:Int,y:Int):String = {
    (x + y) match{
      case n if n%2==0 => "#"
      case n if n%2==1 => "."
      case _ => ""
    }
  }

  def printChaseboard(h: Int,w: Int): Unit = {
      if (w != 0 || h != 0) {
        
        for( i <- 1 to h) {
          for( j <- 1 to w) {
            print(cell(i,j))
          }
          println
        }

        println
        printChaseboard(sc.nextInt, sc.nextInt)
      }
    }


  def main(args: Array[String]): Unit = {
    printChaseboard(sc.nextInt, sc.nextInt)
  }
}

Measured memory_bytes: 52744
#include<iostream>
#include<cstdio>
#include<string>

using namespace std;

int A,B,k;

int ds(int n)
{
    return (n-1)/2;
}
int sh(int n)
{
    return (n/2);
}
void Takahashi()
{
    if(A%2==1)
    {
        A=ds(A);
    }
    else
    {
        A=sh(A);
    }
    B+=A;
}
void Aoki()
{
    if(B%2==0)
    {
        B=sh(B);
    }
    else
    {
        B=sh(B);
    }
    A+=B;
}
int main()
{
    while(scanf("%d %d %d",&A,&B,&k)==3)
    {
        for(int i=1;i<=k;i++)
        {
            if(i%2==1)
            {
                Takahashi();
            }
            else
            {
                Aoki();
            }
        }
        cout<<A<<" "<<B<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<math.h>
#include<vector>
using namespace std;
#define MAX 200009
#define MOD 1000000007
#define EPS 0.0000000001
vector<int> Path;
vector<int> Graph[MAX];
bool added[MAX];
pair<int,int> Change[MAX];
int A[MAX];
int Answer[MAX];
int binsearch(int val)
{
    int first=0,last=Path.size()-1;
    int middle=(first+last)/2;
    while(first<last)
    {
        if(last-first==1&&Path[first]<val) first=last;
        else if(last-first==1) last=first;
        else if(Path[middle]<val) first=middle;
        else last=middle;
        middle=(first+last)/2;
    }
    return middle;
}
void dfs(int node,int parent=-1)
{
    if(Path.size()==0||Path[Path.size()-1]<A[node])
    {
        Path.push_back(A[node]);
        added[node]=true;
    }
    else
    {
        Change[node].first=binsearch(A[node]);
        Change[node].second=Path[Change[node].first];
        Path[Change[node].first]=A[node];
    }
    Answer[node]=Path.size();
    int i;
    for(i=0;i<Graph[node].size();i++)
    {
        if(Graph[node][i]==parent) continue;
        dfs(Graph[node][i],node);
    }
    if(added[node])
    {
        Path.pop_back();
        added[node]=false;
    }
    else
    {
        Path[Change[node].first]=Change[node].second;
    }
}
int main()
{
    int N,M,i,u,v;
    scanf("%d",&N);
    for(i=1;i<=N;i++)
    {
        scanf("%d",&A[i]);
    }
    for(i=1;i<N;i++)
    {
        scanf("%d %d",&u,&v);
        Graph[u].push_back(v);
        Graph[v].push_back(u);
    }
    dfs(1);
    for(i=1;i<=N;i++)
    {
        printf("%d\n",Answer[i]);
    }
    return 0;
}


Measured memory_bytes: 29320
def main():
  n = int(input())
  l = []
  d = {}
  res = 0
  for i in range(n):
    s = input()
    l.append(''.join(sorted(s)))
  for j in range(n):
    if d.get(l[j]) is None:
      d[l[j]] = 1
    elif d.get(l[j]) > 0:
      d[l[j]] += 1
      res += d[l[j]] - 1
    else:
      print('error!')
      quit()
  
  return res
  
if __name__ == "__main__":
  res = main()
  print(res)

Measured memory_bytes: 19472
global graph
global seen
token=0

def dfs(i):
    global token
    token+=1
    seen[i][0]=token
    for x in graph[i]:
        if seen[x][0]==0:
            dfs(x)
    token+=1
    seen[i][1]=token


n=int(input())

graph=[None for _ in range(n+1)]

for i in range(n):
    lst=list(map(int,input().split()))
    graph[lst[0]]=lst[2:]

seen=[[0,0] for _ in range(n+1)]

for i in range(1,n+1):
    if seen[i][0]==0:
        dfs(i)

for i in range(1,n+1):
    print("{} {} {}".format(i,seen[i][0],seen[i][1]))


Measured memory_bytes: 5628
#include <iostream>
#include <string>

using namespace std;

int main(int argc, const char *argv[])
{
  long long n, a, b;
  cin >> n >> a >> b;
  if (a == 0 && b == 0) {
    cout << 0 << "\n";
  } else {
    long long d = n / (a + b);
    long long e = min(n % (a + b), a);
    cout << d * a + e << "\n";
  }
}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,a,b;
  cin>>n>>a>>b;
  ll x=n/(a+b);
  ll y=min(n-x*(a+b),a);
  cout<<(x*a+y)<<endl;
  return 0;
}


Measured memory_bytes: 256
N, L = map(int, input().split())
sum = 0
"""
for i in range(N):
    sum += (L + i -1)
"""
eat  = L +1 -1
for i in range(N):
    i += 1
    sum += (L + i -1)
    if abs(eat) > abs(L + i -1):
        eat = L + i -1
sum -= eat
print(sum)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
// #include <regex> //正規表現
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007ll
#define INF 1000000000
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
// グリッドグラフの移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

string S; cin >> S;

bool fumiyasui = true;

rep(i, 0, S.size()){
    if (i % 2 == 0){
        if (S[i] == 'L') {
            cout << "No" << endl;
            return 0;
        }
    }
    if (i % 2 == 1){
        if (S[i] == 'R') {
            cout << "No" << endl;
            return 0;
        }
    }
}
cout << "Yes" << endl;

}

// 境界，出力文字列 チェック



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


class Program {

	const long mod = 1000000007;
	//public static int[] max;

	static void Main(string[] args) {

		char[] cs = new char[] { ' ', ',' };
		//int val = int.Parse(Console.ReadLine());
		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//int val = int.Parse(Console.ReadLine());
		//string str = Console.ReadLine();
		string[] strs = Console.ReadLine().Split(cs);

		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//int n = vals[0];
		//string res="";

		//int y = vals[0];
		//int x = vals[1];



		string r = "";
		for (int i = 0; i < strs.Length; i++) {
			r+=strs[i][0].ToString().ToUpper();
		}

		Console.WriteLine(r);


		return;
	}



	//　String[]  ----->  int[]
	static int[] parseAry(string[] str) {
		int[] nums = new int[str.Length];
		for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); }
		return nums;
	}
	//　String[]  ----->  long[]
	static long[] parseAryl(string[] str) {
		long[] nums = new long[str.Length];
		for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); }
		return nums;
	}



	//文字列を1文字ずつString[]に入れる
	static string[] strAry(String str) {
		string[] re = new string[str.Length];
		for (int i = 0; i < str.Length; i++) { re[i] = str[i].ToString(); }
		return re;
	}

}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define forr(i,p,n) for(int i=p;i<n;i++)
#define tam 10010
#define tamlog 12
#define offset 50000
#define mp make_pair
using namespace std;
typedef long long  ll;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<ll,ii> iii;
const ll INF=1e11;
string txt;
ll tot=0;
ll go(int pos,ll resp)
{
    if (pos==txt.size())
        tot+=resp;
    ll auxv=0;
    forr(i,pos,txt.size())
    {
        auxv*=10;
        auxv+=txt[i]-'0';
        go(i+1,resp+auxv);
        
    }
    

}
int main()
{
    cin>>txt;
    go(0,0);
    cout<<tot<<endl;


}


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

int main() {
    long long X, Y;
    cin >> X >> Y;
    long long ans = 1;
    long long num = X;
    while (num * 2LL <= Y) {
        num *= 2LL;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int binSearch(int);

int S[100000];
int n;
int main(){
  int i;
  int T[50000],q,C=0;
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i = 0; i < q; i++){
    scanf("%d",&T[i]);
  }

  for(i = 0; i < q; i++){
    if(binSearch(T[i])) C++;
  }
  printf("%d\n",C);
  return 0;
}

int binSearch(int key){
  int left = 0;
  int right = n;
  int mid;
  while( left < right){
    mid = (left + right) / 2;
    if(S[mid] == key) return 1;
    else if(key < S[mid]) right = mid;
    else left = mid + 1;
  }
  return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 112345;
int N;
ll A, B;
ll h[MAX_N];

bool possible(int K) {
  const ll g = (A-B);
  ll need = 0;
  REP(i, N) {
    ll hp = h[i];
    hp -= B * K;
    if (hp >= 0) {
      need += (hp + g - 1) / g;
      if (need > K) break;
    }
  }
  return need <= K;
}

int main2() {
  N = nextInt();
  A = nextInt();
  B = nextInt();
  REP(i, N) h[i] = nextInt();

  int hi = 1001001001;
  int lo = 0;
  while (hi - lo > 1) {
    int mid = (hi + lo) / 2;
    if (possible(mid)) hi = mid; else lo = mid;
  }
  cout << hi << endl;

  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define	LL long long
using namespace std;
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){ if (x>9) write(x/10); putchar('0'+x%10); }
const int N = 10050;
inline LL gcd(LL x,LL y){ return y ? gcd(y,x%y) : x; }
int n,a[N],ans[N+500],m;
inline void Divide(LL x){
	int i; LL t=x;
	for (i = 2; i <= x / i; ++i) if (t%i==0){ ++m; ans[m] = i; while (t%i==0) t/=i; }
	if (t>1) ++m,ans[m] = t; sort(ans+1,ans+m+1);
}
LL vval;
int b[N];
inline bool check(int p){
	int i,j; LL ret;
	if (vval%p!=0) return 0;
	for (i = 2; i * i <= p; ++i) if (p%i==0) return 0;
	//x^p-x
	for (i = 1; i <= n; ++i) b[i] = a[i]%p,b[i]<0?b[i]+=p:0;
	for (i = 1; i <= n; ++i) if (b[i]){
		if (i+p-1>n) return 0;
		b[i+p-1] += b[i];
		b[i+p-1] >= p ? b[i+p-1] -= p : 0;
	}
	return 1;
}
int main(){
	int i,v; LL v0,v1,vf1;
	read(n);
	for (i = n; i >= 0; --i) read(a[i]);
	for (v = abs(a[0]),i = 1; i <= n; ++i) v = gcd(v,abs(a[i]));
	Divide(v);
	v0 = abs(a[0]),v1 = vf1 = 0;
	for (i = 0; i <= n; ++i) v1 += a[i];
	for (i = 0; i <= n; ++i) if (i%2==0) vf1 += a[i]; else vf1 -= a[i];
	v1 = abs(v1),vf1 = abs(vf1),vval = gcd(gcd(v0,v1),vf1);
	for (i = 1; i <= n; ++i) a[i] /= v;
	for (i = 2; i <= n; ++i) if (check(i)) ans[++m] = i;
	sort(ans+1,ans+m+1); m = unique(ans+1,ans+m+1)-ans-1;
	for (i = 1; i <= m; ++i) write(ans[i]),putchar('\n');
	return 0;
}

Measured memory_bytes: 384
n, k = map(int, input().split())
s = input()
right = s.count("R")
left = s.count("L")

if min(right, left) <= k:
    print(n-1)
elif n == 1:
    print(0)
else:
    # 操作前の幸福な人の数を調べる
    happy = 0
    for i in range(n-1):
        if s[i] == s[i+1]:
            happy += 1
    #print(happy)
    # RL...LR,LR...RLを数える
    rl = s.count("RL")
    lr = s.count("LR")
    #print(rl, lr)
    min_rllr = min(rl, lr)
    max_rllr = max(rl, lr)
    if rl != 0 and lr != 0:
        if k > min_rllr:
            happy += min_rllr*2 + (max_rllr-min_rllr)
        else:
            happy += k*2
    else:
        happy += k
    print(happy)


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

#define int long long

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

int K, N;
deque<int> ans;

signed main() {
    cin >> K >> N;
    if (K % 2 == 0) {
        cout << K / 2;
        for (int i = 0; i < N - 1; i++) {
            cout << " " << K;
        }
        cout << endl;
        return 0;
    }
    for (int i = 0; i < N; i++) {
        ans.push_back((K + 1) / 2);
    }
    for (int i = 0; i < N / 2; i++) {
        if (ans.back() == 1) {
            ans.pop_back();
        } else {
            ans.back()--;
            while (ans.size() < N) {
                ans.push_back(K);
            }
        }
    }
    cout << ans.front();
    ans.pop_front();
    while (!ans.empty()) {
        cout << " " << ans.front();
        ans.pop_front();
    }
    cout << endl;
    return 0;
}


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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}


int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int k, t;
    cin >> k >> t;

    int best = 0;
    for(int i = 0; i < t; ++i){
        int j; cin >> j;
        best = max(best, max(0, j - 1 - (k - j)));
    }

    cout << best;

    return 0;
}


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

arr = list(map(int, input().split()))
sorted_arr = sorted(arr)

median_big = sorted_arr[n // 2]
median_small = sorted_arr[n // 2 - 1]

for a in arr:
    if a >= median_big:
        print(median_small)
    else:
        print(median_big)


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

using namespace std;
typedef long long ll;

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; }

int main()
{
  int A[3][3];
  for(int i=0; i<3; i++)
    for(int j=0; j<3; j++)
      cin >> A[i][j];

  int N;
  cin >> N;

  vector<int> b(N);
  for(int i=0; i<N; i++)
    cin >> b[i];

  sort(b.begin(), b.end());
  
  if(find(b.begin(), b.end(), A[0][0])!=b.end())
    {
      if(find(b.begin(), b.end(), A[0][1])!=b.end() && find(b.begin(), b.end(), A[0][2])!=b.end())
	{
	  cout << "Yes" << endl;
	  return 0;
	}
    
      if(find(b.begin(), b.end(), A[1][1])!=b.end() && find(b.begin(), b.end(), A[2][2])!=b.end())
	{
	  cout << "Yes" << endl;
	   return 0;
	}
	
      if(find(b.begin(), b.end(), A[1][0])!=b.end() && find(b.begin(), b.end(), A[2][0])!=b.end())
	{
	  cout << "Yes" << endl;
	   return 0;
	}
    }

  
  if(find(b.begin(), b.end(), A[1][0])!=b.end())
    {
      if(find(b.begin(), b.end(), A[1][1])!=b.end() && find(b.begin(), b.end(), A[1][2])!=b.end())
	{
	  cout << "Yes" << endl;
	   return 0;
	}
    }

  
  if(find(b.begin(), b.end(), A[2][0])!=b.end())
    {
      if(find(b.begin(), b.end(), A[2][1])!=b.end() && find(b.begin(), b.end(), A[2][2])!=b.end())
	{
	  cout << "Yes" << endl;
	  return 0;
	}
    
      if(find(b.begin(), b.end(), A[1][1])!=b.end() && find(b.begin(), b.end(), A[0][2])!=b.end())
	{
	  cout << "Yes" << endl;
	   return 0;
	}
	
    }

  
  if(find(b.begin(), b.end(), A[0][1])!=b.end())
    {
      if(find(b.begin(), b.end(), A[1][1])!=b.end() && find(b.begin(), b.end(), A[1][2])!=b.end())
	{
	  cout << "Yes" << endl;
	  return 0;
	}
    
    }

  
  if(find(b.begin(), b.end(), A[0][2])!=b.end())
    {
      if(find(b.begin(), b.end(), A[1][2])!=b.end() && find(b.begin(), b.end(), A[2][2])!=b.end())
	{
	  cout << "Yes" << endl;
	  return 0;
	}
    
    }

  cout << "No" << endl;
  

   
    
  

  return 0;
}


//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find
//vector.count



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
	ll a,b,p,q;cin>>a>>b;
	if(a==b){
		cout<<1<<endl;
		return 0;
	}
	for(ll i=0;i<=62;i++){
		if(b&(1LL<<i))p=i;
		if(a&(1LL<<i))q=i;
	}
	ll ans=0;
	bool f=false;
	ll r=0,s=0,t=0;
	for(ll i=p;i>=0;i--){
		if(f){
			if(b&(1LL<<i))s|=(1LL<<i);
			if(a&(1LL<<i))t|=(1LL<<i);
			r|=(1LL<<i);
		}else{
			if(((a&(1LL<<i))==0)&&(b&(1LL<<i))){
				f=true;
			}
		}
	}
	ll m=-1;
	for(ll i=0;i<=62;i++){
		if(s&(1LL<<i))m=i;
	}
	for(ll i=0;i<=m;i++){
		s|=(1LL<<i);
	}
	ans=(r-t+1LL)*2LL+(s+1LL)-max(0LL,s-t+1LL);
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int S,a,h,m,s;
	scanf("%d",&S);
	
	h=S/3600;
	a=S%3600;
	m=a/60;
	s=a%60;
	
	printf("%d:%d:%d\n",h,m,s);
}


Measured memory_bytes: 2756
from itertools import product

N, M = map(int, input().split())
A, B, C = [], [], []
for i in range(N):
    a, b, c = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)

ans = 0
for x, y, z in product([1, -1], repeat=3):
    S = []
    for a, b, c in zip(A, B, C):
        S.append(a*x + b*y + c*z)
    S.sort(reverse=True)
    ans = max(ans, sum(S[:M]))

print(ans)


Measured memory_bytes: 3188
from sys import stdin
readline = stdin.buffer.readline

def watering(h):
    ans = min(h)
    hh = list(map(lambda x: x - ans, h))
    if len(set(hh)) == 1:
        return ans
    fs = 0
    for i, n in enumerate(hh):
        if n == 0:
            if i != fs:
                hhh = hh[fs:i]
                ans += watering(hhh)
                fs = i + 1
            else:
                fs = i + 1
    else:
        hhh = hh[fs:]
        if len(hhh) > 0:
            ans += watering(hhh)
    return ans

def main():
    N = int(readline().rstrip())
    H = list(map(int, readline().rstrip().split()))
    print(watering(H))

if __name__ == "__main__":
    main()


Measured memory_bytes: 65788
#include<stdio.h>
int main(){
  int n,a[110],b[110],i,j,r,t,q[1010],c,f[110],d[30][30];
  char s[100010];
  while(scanf("%d",&n),n){
    for(i=0;i<30;i++)a[i]=b[i]=f[i]=c=0;
    for(i=0;i<900;i++)d[i/30][i%30]=0;
    for(i=0;i<n;i++){
      scanf("%s",s);
      for(j=0;s[j];j++);
      a[s[0  ]-'a']++;
      b[s[j-1]-'a']++;
      d[s[0]-'a'][s[j-1]-'a']++;
    }
    for(i=0;a[i]==0;i++);
    q[t=0]=i;
    f[i]=1;
    for(r=1;r-t;t++){
      for(i=0;i<26;i++){
	c+=d[q[t]][i];
	if(d[q[t]][i]==0||f[i])continue;
	f[i]=1;
	q[r++]=i;
      }
    }
    for(i=0;i<26&&a[i]==b[i];i++);
    //printf("%d %d\n",i,c);
    printf("%s\n",i-26||c-n?"NG":"OK");    
  }
  return 0;
}



Measured memory_bytes: 2028
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var R = int.Parse(Console.ReadLine());
            Console.WriteLine(R < 1200 ? "ABC" : R < 2800 ? "ARC" : "AGC");
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define sz(x) int(x.size())
using ll = long long;
using P = pair<int,int>;
const ll LLINF = numeric_limits<long long>::max();
const int mod = 1000000007;
const int INF = 1001001001;
 
int main()
{
    int N,M,X;
    cin >> N >>M >>X;
    vector <int> C(N);
    int  A[N][M];
    for(int i=0;i<N;i++){
        cin >> C[i];
        for(int j=0;j<M;j++){
             cin >> A[i][j];
        }
    }
    ll ans = INF;
    rep(div,1<<(N)) {
        vector<int> id(M);
        bool flag = true;
        ll cos=0; 
        //cout << "sss"<<div << endl;
        rep(i,N) {
        // cout << div;
        
            if (div>>i&1){
              cos += C[i];  
              for(int j=0;j<M;j++){
                    //cout << "j " << j  << endl;
                    //cout << "a "<<A[i][j] << endl;
                    id[j] += A[i][j];
                    //cout << "id "<<id[j] << endl;
                }       
            }
        }
        for(int j=0;j<M;j++){
            //cout << id[j] << " ";  
            if(id[j] < X){
                flag=false;
            }
        }
        //cout << endl;
        if(flag){
            ans = min(ans, cos);
        }
    }   
    if(ans == INF){
        ans =-1;
    }
    cout << ans;
 
 
 
    return 0;
}

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

#define REP(i,n) for(long long i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(long long i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9


int main(){
  int A, B;
  cin >> A >> B;
  cout << max(A+B, max(A-B, A*B)) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int A,B,K;
  scanf("%d %d %d",&A,&B,&K);
  int count=0;
  int i;
  for(i=100;i>1;i--){
    if(A%i==0 && B%i==0)
      count++;
    if(count==K)
      break;
  }
  
  printf("%d\n",i);
  
  return 0;
}

Measured memory_bytes: 128
n = int(input())
absum = []
for a in range(1,n//2+1):
    b = n-a
    asum = 0
    bsum = 0
    astr = str(a)
    bstr = str(b)
    for j in range(len(astr)):
        asum = asum + int(astr[j])
    for k in range(len(bstr)):
        bsum = bsum + int(bstr[k])
    absum.append(asum+bsum)
print(min(absum))

Measured memory_bytes: 9244
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.imageio.IIOException;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      String word = br.readLine();
      word.toLowerCase();

      Function<String,Long> findingWord =
        s -> Stream.of(s.split(" "))
          .filter(w -> word.equals(w))
          .count();

      Optional<Long> result =
        br.lines()
          .filter(w -> !"END_OF_TEXT".equals(w))
          .map(String::toLowerCase)
          .map(findingWord)
          .reduce(Long::sum);

      System.out.println(result.get());
    }
  }
}


Measured memory_bytes: 31436
#include<iostream>
#include<vector>
#include<string>

using ll = long long;

int main(){
    int n;
    std::cin >> n;
    ll ans = 0;
    for(ll i = 1; i <= n; i++){
        // iの倍数でn以下の数の総和
        ll N = n / i;
        // i, 2 * i, ..., N * i
        ans += i * ((N * (N + 1)) / 2);
    }
    std::cout << ans << std::endl;
    return 0;
}


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

int main() {
  int A, B, N, c;
  cin >> A >> B;
  N = A;
  c = 0;
  for (int i = 0; i < B - A + 1; i++) {
    if (N / 10000 != N % 10) {
      N++;
      continue;
    }
    else if (N /1000 % 10 != N / 10 % 10) {
      N++;
      continue;
    }
    else {
      c++;
      N++;
    }
  }
  cout << c << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define all(V) (V).begin(), (V).end() 
using namespace std;
typedef long long ll;
bool solve(ll n, ll a, ll b, ll c, ll d) {
	if(d == 0) return a == b;
	ll req = b - a;
	for(ll i = -n; i <= n; i++) {
		ll rem = req - (c * i);
		ll j = rem / d;
		if(rem % d && rem < 0) {
			j--;
		}
		ll residue = req - i * c - j * d;
		assert(residue >= 0);
		if(residue > 0 && abs(i) + abs(j) == n && i < 0) {
			continue;
		}
		if(residue <= d - c && abs(i + j + n) % 2 == 0 && abs(i) + abs(j) <= n) {
			// cout << i << ' ' << j << ' ' << residue << endl;
			return true;
		}
	}
	return false;
}

int main() {fio;
	ll n, a, b, C, D;
	cin >> n >> a >> b >> C >> D;
	n--;
	if(solve(n, a, b, C, D) || solve(n, b, a, C, D)) {
		cout << "YES\n";
	} else {
		cout << "NO\n";
	}
    return 0;
}

Measured memory_bytes: 3652
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
ll mod = 1000000007;
ll big(ll b, ll p){
	if (p == 1) return b;
	ll h = big(b, p / 2);
	ll res = (h * h) % mod;
	if (p % 2 == 1) res = (res * b) % mod;
	return res;
}
int main(){
	ll n, k, c1 = 1, c2 = 1, ans = 1;
	scanf("%lld %lld", &n, &k);
	for (int i = 1; i <= min(n - 1, k); i++){
		c1 = (c1 * (n + 1 - i)) % mod;
		c1 = (c1 * big(i, mod - 2)) % mod;
		c2 = (c2 * (n - i)) % mod;
		c2 = (c2 * big(i, mod - 2)) % mod;
		ans += (c1 * c2) % mod;
		ans %= mod;
	}
	printf("%lld\n", ans);
}

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

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

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline

a, b = [int(_) for _ in input().split()]

a -= 1
b -= 1


def f(b, av, bv):
    A = [list(av * 100) for _ in range(50)]
    for i in range(1, 49):
        if b == 0: break
        for j in range(1, 99):
            if b == 0: break

            if A[i - 1][j] != bv and \
                    A[i - 1][j - 1] != bv and \
                    A[i - 1][j + 1] != bv and \
                    A[i][j - 1] != bv :
                A[i][j] = bv
                b -= 1
    for a in A:
        print(*a,sep='')

print(100,100)
f(b, '.', '#')
f(a, '#', '.')


Measured memory_bytes: 4596
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-6;
const int MOD = 1000000007;

int main(){
	double D;
	while(cin>>D,D){
		double px,py,vx,vy;
		cin>>px>>py>>vx>>vy;
		// (-px,-py) (vx, vy)
		if(abs((-px) * vy - (-py) * vx) < 1e-6){
			double d;
			assert(abs((-px)*vx+(-py)*vy) > EPS);
			if(-px * vx + (-py) * vy > -EPS){
				d = sqrt(px*px + py*py);
			}else{
				d = 2.0 - sqrt(px*px + py*py);
			}
			if(d < D + 1e-6){
				printf("%0.6lf\n", d);
			}else{
				cout<<"impossible"<<endl;
			}
		}else{
			cout<<"impossible"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1272
#include<stdio.h>
#define WHITE 0
#define GRAY  1
#define BLACK 2

int n,M[100][100];
int color[100];
int time;
int d[100],f[100];

void visit(int u){
  int v;
  
  color[u] = GRAY;
  d[u] = ++time;
  for(v=0;v<n;v++){
    if(M[u][v] == 0) continue;
    if(color[v] == WHITE) visit(v);
  }
  color[u] = BLACK;
  f[u] = ++time;
}

void dfs(){
  int u;

  for(u=0;u<n;u++) color[u] = WHITE;
  time = 0;
  
  for(u=0;u<n;u++){
    if(color[u]==WHITE) visit(u);
  }
}

int main(){
  int u,v,k;
  int i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    for(j=0;j<n;j++)
      M[i][j]=0;
	
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      M[u-1][v-1] = 1;
    }
  }
  
  dfs();
  for(i=0;i<n;i++) printf("%d %d %d\n",i+1,d[i],f[i]);
  
  return 0;
}




Measured memory_bytes: 2112
import Control.Applicative
import Data.Fixed

main = do
    [a,b] <- map (read :: String -> Int) . words <$> getLine
    putStrLn $
        show (a `div` b) ++ " " ++
        show (a `mod` b) ++ " " ++
        show ((realToFrac a) / (realToFrac b) :: Fixed E9)


Measured memory_bytes: 4136
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, X, M = [int(x) for x in input().split()]

    x = {}

    ruiseki = [0] * (M + 1)

    cnt = 1
    ans = X
    c = X
    ruiseki[1] = ans
    while cnt < N:
        if c == 0:
            print(ans)
            return
        next = c ** 2 % M
        if next in x.keys():
            y = x[next]
            # print(ruiseki)
            # print(cnt, y)
            if N == cnt:
                print(ans + next)
                return
            loop = ruiseki[cnt] - ruiseki[y - 1]
            loopcnt = cnt - y + 1
            ans += ((N - cnt) // loopcnt) * loop
            # print(ans)
            amari = (N - cnt) % loopcnt
            # print(amari, loop, loopcnt)
            if amari != 0:
                ans += ruiseki[y - 1 + amari] - ruiseki[y - 1]
                # print(ans)
            break

        ans += next
        cnt += 1
        ruiseki[cnt] = next
        ruiseki[cnt] += ruiseki[cnt - 1]
        c = next
        x[next] = cnt

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18164
N, K, Q = list(map(int, input().split(' ')))
A = [int(input()) for i in range(Q)]

diff = K - Q
point_list = [diff for i in range(N)]

for answer in A:
    point_list[answer - 1] += 1

for point in point_list:
    if point <= 0:
        print('No')
    else:
        print('Yes')

#print(point_list)

Measured memory_bytes: 10500
from collections import Counter
input()
a = [x // 400 for x in map(int, input().split())]
c = []
ans = 0
for i in a:
    if i > 7:
        ans += 1
    else:
        c.append(i)
print(max(1,len(Counter(c))), ans + len(Counter(c)))


Measured memory_bytes: 3316
#include<iostream>
#include<algorithm>
#include<string>
const int MOD = 1000000007;
using namespace std;
long long int sumN(long long int i){return i*(i+1)/2;}
int main(){
	long long int N,K,sum=0,M,m;
	cin>>N>>K;
	for(int i=K;i<=N+1;i++){
		M=sumN(N)-sumN(N-i);
		m=sumN(i-1);
		sum+=M-m+1;
		sum%=MOD;
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3636
#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 pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define resz resize
#define ini ll_MAX
#define inl LLONG_MAX
#define MOD 1000000007
#define sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define F0R(i, a) for (ll i = 0; i < (a); i++)
#define FORR(i, a, b) for (ll i = a; i >= (b); i--)
#define F0RR(i, a) for (ll i = a; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define pbds tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
     
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
     
using pii = pair<ll, ll>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
     
using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using vpdd = vector<pdd>;
using vvpdd = vector<vpdd>;
     
ll mod(ll a,ll b)
{
    return (b+a%b)%b;
}
     
ll gcd(ll a,ll b)
{
    if(b==0)return a;
    else return gcd(b,a%b);
}
ll po(ll a,ll b)
{
    ll ans = 1;
    while(b--)
        ans*=a;
    return ans;
}
ll pom(ll a,ll b,ll mod)
{
    if(b==0)return 1;
    ll k = pom(a,b/2,mod);
    if(b%2==0)return (k*k)%mod;
    else return ((k*k)*mod*a)%mod;
}
     
ll sqdist(ll a,ll b,ll c,ll d)
{
    return (a-c)*(a-c)+(b-d)*(b-d);
}
ll fact(ll n)
{
    if(n==0)return 1;
    ll ans = 1;
    FOR(i,1,n+1)ans*=i;
    return ans;
}

ll n,k,p;
ll visited[100];
vll vec[100];
void dfs(ll k)
{
    visited[k]++;
    p++;
    FOR(i,0,vec[k].size())
    {
        if(!visited[vec[k][i]])
            dfs(vec[k][i]);
    }
}


     
void solve()
{
    int a,b,c;
    cin>>a>>b>>c;
    int p = max(a,b);
    if(c%p==0)cout<<c/p;
    else cout<<c/p+1;
}
     
     
main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    solve();
}

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

#define MAX_N 500 

ll A, B, C, D, E, F;

int main() {
    cin >> A >> B >> C >> D >> E >> F;

    ll ans_sum = 0, ans_suger = 0;
    double rate = 0;
    for (int i = 0; i * 100 <= F; i++) {
        for (int j = 0; j * 100 <= F; j++) {
            int tmp_water = (i * A * 100) + (j * B * 100);
            if (tmp_water > F) continue;
            if (tmp_water == 0) continue;

            for (int c = 0; c <= F; c++) {
                for (int d = 0; d <= F; d++) {
                    int tmp_suger = (c * C + d * D);

                    if ((tmp_suger + tmp_water) > F) continue;
                    // printf("i: %d j: %d c: %d d: %d %d %d\n", i, j, c, d, tmp_water, tmp_suger);

                    // 溶けるかどうか
                    double tmp_ans = (double)tmp_suger / (tmp_suger + tmp_water);
                    double tmp_max_rate = (double)E / (100 + E); 
                    // cout << tmp_ans << endl;
                    // cout << tmp_max_rate << endl;
                    if (tmp_ans <= tmp_max_rate && tmp_ans >= rate) {
                        // printf("i: %d j: %d c: %d d: %d %d %d %d\n", 
                        //     i, j, c, d, tmp_water, tmp_suger, tmp_ans);
                        rate = tmp_ans;
                        ans_sum = tmp_suger + tmp_water;
                        ans_suger = tmp_suger;
                    }
                }
            }
        }
    }

    printf("%lld %lld\n", ans_sum, ans_suger);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


ll X,Y,Z,K;
vector<ll> AB;
vector<ll> C;

bool solve(ll P){
    int count = 0;
    REP(i,X*Y){
        REP(j,Z){
            if(AB[i] + C[j] >= P){
                count ++;
                if(count >= K){
                    return true;
                }
            }else{
                break;
            }
        }
    }
    return false;
}

ll binary_search(ll M){
    ll ng = M;
    ll ok = 0;
    while(abs(ok-ng)>1){
        ll mid = (ok+ng)/2;
        //cout << ng << ", " << mid << ", " << ok << endl;
        if(solve(mid)){//ここに条件をかく
            ok = mid;
        }else{
            ng = mid;
        }
    }
    return ok;
}

int main() {
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X);
    vector<ll> B(Y);
    C.assign(Z,0);
    REP(i,X){
        cin >> A[i];
    }
    REP(i,Y){
        cin >> B[i];
    }
    REP(i,Z){
        cin >> C[i];
    }
    AB.assign(X*Y, 0);
    REP(i,X){
        REP(j,Y){
            AB[i*Y + j] = A[i]+B[j];
        }
    }
    sort(ALL(AB), greater<ll>());
    sort(ALL(C), greater<ll>());


    ll border = binary_search(AB[0]+C[0]);

    int count = 0;
    vector<ll> ans;

    REP(i,X*Y){
        REP(j,Z){
            if(AB[i] + C[j] > border){
                count ++;
                ans.push_back(AB[i] + C[j]);
                if(count >= K){
                    break;
                }
            }else{
                break;
            }
        }
    }
    while (ans.size() < K) ans.push_back(border);
    sort(ALL(ans), greater<ll>());
    
    REP(i,K){
        cout << ans[i] << endl;
    }

    return 0;
}

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

int main(){
    int n;
    long long max = -1000000;
    long long min = 1000000;
    long long a;
    long long sum = 0;
    cin >> n;
    for(int i = 0; i < n ; ++i){
       cin >> a;
       if(a > max) max = a;
       if(a < min) min = a;
       sum += a;
      }
    cout << min << " " << max << " " << sum << endl;
    return 0;
  }
     

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)

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

int main() {


    string s; cin >> s;
    char tmp = s[0];
    for(int i=1; i < s.size(); i++) {
        if(s[i] == tmp) {
            cout << "Bad" << endl;
            return 0;
        }
        tmp = s[i];
    }

    cout << "Good" << endl;

    return 0;
    
}


Measured memory_bytes: 256
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/4/ALDS1_4_C


"""
s in [list]:
-> linear search O(n)
-> TLE
"""


def solve():
    mydict = {}
    n = int(input())
    for _ in range(n):
        ope, s = map(str, input().split())
        if ope == 'insert':
            mydict[s] = True
        elif ope == 'find':
            if s in mydict:
                print('yes')
            else:
                print('no')


if __name__ == '__main__':
    solve()



Measured memory_bytes: 33116
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int H, W;
	cin >> H >> W;

	map<int, int> MP;
	rep(i, W) {
		MP[i] = 1;
	}

	int kazu[200201] = {};
	kazu[1] = W;
	kazu[200100] = 1;
	int ima = 1;

	rep(i, H) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;

		auto s = MP.lower_bound(a);
		auto t = MP.upper_bound(b);

		int saishou = 1e9;
		for (; s != t; s++) {
			chmin(saishou, (*s).second + b - (*s).first + 1);
			kazu[(*s).second]--;
		}
		MP.erase(MP.lower_bound(a), t);

		b++;
		if (saishou < 1e8) {
			if (MP.find(b) != MP.end()) {
				if (b != W) {
					int tmp = MP[b];
					kazu[tmp]--;
					MP[b] = min(tmp, saishou);
					kazu[min(tmp, saishou)]++;
				}
			}
			else {
				if (b != W) {
					MP[b] = saishou;
					kazu[saishou]++;
				}
			}
		}

		while (kazu[ima] == 0) ima++;
		int ans = i + ima;
		if (ima > 200050) co(-1);
		else co(ans);
	}





	Would you please return 0;
}

Measured memory_bytes: 13816
#include <iostream>
#include <vector>
#include <set>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  vector<int> d(k);
  vector<vector<int>> a(k);
  for(int i=0;i<k;i++){
    cin >> d[i];
    for(int j=0;j<d[i];j++){
      int t;
      cin >> t;
      a[i].push_back(t);
    }
  }

  set<int> st;
  for(int i=0;i<k;i++){
    for(int j=0;j<d[i];j++){
      auto itr = st.find(a[i][j]);
      if(itr == st.end()){
        st.insert(a[i][j]);
      }
    }
  }

  cout << n-st.size() << endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
 
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
 
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
 
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 122)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 122)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 122)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll quickpow (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = quickpow (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template
ll n,m;
int main(){
 
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  
  	cin>>n>>m;
  	ll ans;
  	if(n*2 <= m){
		ans = n;
		m-=2*n;
		ans += m/4;  
	}
	else{
		ans = m/2;
	}
	cout<<ans<<newl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>


using namespace std;
#define INF 0x3f3f3f3f3f
#define ll long long
#define pr(x) (cerr << #x << ' ' << x << ' ')
#define prln(x) (cerr << #x << ' ' << x << endl)

map<ll, int> mm;

int main()
{
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
    #endif // LOCAL

    int n, m;
    scanf("%d %d", &n, &m);
    int t;
    ll sum = 0;
    ll ans = 0;

    mm[0]++;

    for (int i = 1; i <= n; ++i) {
        scanf("%d", &t);
        sum = (sum + t) % m;
        ans += mm[sum]++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
long long mod=1000000007;
int main(){
	int n,m;
	cin>>n>>m;
	int a[m+1];
	int d[n+1];
	memset(d,-1,sizeof(d));
	d[0]=d[1]=1;
	for(int i=1;i<=m;i++){
		cin>>a[i];
		d[a[i]]=0;
	}
	for(int i=2;i<=n;i++){
		if(d[i]!=0){
			d[i]=(d[i-1]+d[i-2])%mod;
		}
	}
	cout<<d[n]<<endl;
	return 0;
} 

Measured memory_bytes: 1024
#include <bits//stdc++.h>
using namespace std;
#define int long long
#define rep(i,n,k) for(int i=n;i<k;i++)
#define P make_pair
#define F first
#define S second
#define M LLONG_MAX
signed main(void){
    int n,m,ans,p,q;
    ans=0;
    string s1,s2;
    vector<int> v;
    cin>>s1>>s2;
    rep(i,0,s1.size()){
        if(s1[i]!=s2[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    
    
}


Measured memory_bytes: 3624
#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>
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;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VVI x(n), y(n);
    REP(i,n){
        int a = in();
        REP(j,a){
            x[i].push_back(in() - 1);
            y[i].push_back(in());
        }
    }
    int ans = 0;
    REP(mask,1<<n){
        bool f = true;
        int cnt = 0;
        REP(i,n) if ((mask >> i) & 1) cnt++;

        REP(i,n){
            if (((mask >> i) & 1) == 0) continue;
            REP(j,x[i].size()){
                if (((mask >> x[i][j]) & 1) != y[i][j]) f = false;
            }
        }
        if (f) chmax(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define ll long long
#define inf 20021225
#define N 10100
using namespace std;
int read()
{
	int s=0,t=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')	t=-1; ch=getchar();}
	while(ch>='0' && ch<='9')	s=s*10+ch-'0',ch=getchar();
	return s*t;
}
char ch[N],ans[N]; int n,k;
int main()
{
	n=read(),k=read(); scanf("%s",ch+1); char mn=127;
	for(int i=1;i<=n;i++)	mn=min(mn,ch[i]);
	if(k>=16||(1<<k-1)>=n){for(int i=1;i<=n;i++)	printf("%c",mn); return 0;}
	for(int i=n+1;i<=2*n;i++)	ch[i]=ch[n-i+n+1],ans[i-n]=127;
	for(int i=1;i<=n+1;i++)
		for(int j=0;j<n;j++)	if(ans[j+1]!=ch[i+j])
		{
			if(ans[j+1]>ch[i+j])	for(int l=1;l<=n;l++)	ans[l]=ch[i+l-1];
			break;
		}
	int cnt=0;
	for(int i=1;i<=n;i++)	if(ans[i]==ans[1])	cnt++; else	break;
	int owo=min(n,cnt<<k-1);	for(int i=1;i<=owo;i++)	putchar(mn);
	for(int i=1;i<=n-owo;i++)	putchar(ans[i+cnt]); 
	return 0;
}

Measured memory_bytes: 128
N = int(input())
P = list(map(int,input().split()))
R = sorted(P)
import copy
answer = 'NO'
for i in range(0,N-1):
    for j in range(i+1,N):
        Q = copy.deepcopy(P)
        A = Q[i]
        B = Q[j]
        Q[i] = B
        Q[j] = A
        if Q == R:
            answer = 'YES'
            break
if P == R:
    answer = 'YES'
print(answer) 

Measured memory_bytes: 74856