akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

vector<int> ans;
vector<vector<pair<int, long long>>> graph;

void dfs(int p, long long cost) {
  for(int i=0;i<graph[p].size();i++) { // !!
    if(ans[graph[p][i].first] != -1) {
      continue;
    }
    long long c_cost = graph[p][i].second + cost;
    // cout << "cost: " << graph[p][i].first << " -> " << c_cost << endl;
    ans[graph[p][i].first] = c_cost % 2 == 0 ? 0 : 1;
    dfs(graph[p][i].first, c_cost);
  }
}

vector<int> even_relation(int n, int u[], int v[], long long w[]) {
  for(int i=0;i<n;i++) {
    vector<pair<int, long long>> nodes; 
    graph.push_back(nodes);
    ans.push_back(-1);
  }
  for(int i=0;i<n-1;i++) {
    graph[v[i]-1].push_back(make_pair(u[i]-1, w[i]));
    graph[u[i]-1].push_back(make_pair(v[i]-1, w[i]));
  }
  ans[0] = 0;
  dfs(0, 0);
  /*
  for(int i=0;i<graph.size();i++) {
      cout << i << " -> ";
    for(int j=0;j<graph[i].size();j++) {
      cout << graph[i][j].first << " ";
    }
    cout << endl;
  }
  */
  return ans;
}

int main(){
  int n;
  cin >> n; 
  int u[n-1];
  int v[n-1];
  long long w[n-1];
  for(int i=0;i<n-1;i++) {
    cin >> u[i];
    cin >> v[i];
    cin >> w[i];
  }
  vector<int> ans = even_relation(n, u, v, w);
  for(int i=0;i<ans.size();i++) {
    if(i != 0)
      cout << endl; 
    cout << ans[i];
  }
}

Measured memory_bytes: 10768
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);

		while(true){
			int n=sc.nextInt();
			if(n==0) break;
			int sum=0,maxi=0,mini=1000;
			for(int i=0;i<n;i++){
				int a=sc.nextInt();
				sum+=a;
				maxi=Math.max(maxi,a);
				mini=Math.min(mini,a);
			}
			System.out.println((sum-maxi-mini)/(n-2));
		}

		return;
	}
}

Measured memory_bytes: 20944
import sys, heapq, math

input = sys.stdin.readline

N, M = map(int, input().split())
path = [set() for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    path[a-1].add(b-1)
    path[b-1].add(a-1)

h = [(0, 0, 0)] # 距離, id, 直前のid
heapq.heapify(h)
cost = [[math.inf, -1]]*N

while len(h) != 0:
    d, idx, pre_idx = heapq.heappop(h)
    if cost[idx][0] <= d:
        continue
    cost[idx] = [d, pre_idx]
    for next_idx in path[idx]:
        if cost[next_idx] == math.inf:
            continue
        heapq.heappush(h, (d+1, next_idx, idx))

if max(cost)[0] == math.inf:
    print('No')
    sys.exit()

print('Yes')
for d, pre_idx in cost[1:]:
    print(pre_idx+1)



Measured memory_bytes: 180612
//Created Time:2019年12月02日 星期一 20时04分36秒
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define N 102
#define mod 1000000007

using namespace std;

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

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n * 2 - 1; ++i)
		scanf("%d", a + i);
	sort(a + 1, a + n * 2);
	f[n][1][0] = 1;
	for(int i = n - 1; i; --i)
		for(int j = 0; j <= n * 2 - 1; ++j)
			for(int k = 0; k + j <= n * 2 - 1; ++k){
				int w = f[i + 1][j][k]; if(!w) continue;
				bool flag1 = (a[i + 1] != a[i]), flag2 = (a[n * 2 - i] != a[n * 2 - i - 1]);
				for(int l = 1; l <= j + flag1; ++l)
					(f[i][j + flag1 - l + 1][k + flag2 + (l != 1)] += w) %= mod;
				for(int l = 1; l <= k + flag2; ++l)
					(f[i][j + flag1 + 1][k + flag2 - l] += w) %= mod;
			}
	int ans = 0;
	for(int i = 0; i <= n * 2 - 1; ++i)
		for(int j = 0; j <= n * 2 - 1; ++j)
			(ans += f[1][i][j]) %= mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
#!/usr/bin/env python3
import sys
import collections as cl


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


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


def main():
    N = input()
    print('Yes' if N[2] == N[3] and N[4] == N[5] else 'No')


main()


Measured memory_bytes: 65004
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int INF = 1e12;
const int MAX_V = 100010;

int p[MAX_V];
bool marked[MAX_V];

int dfs(int v){
    return (marked[v] ? v : dfs(p[v]));
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q, v;
    char c;
    while(cin >> n >> q && n){
        memset(marked, false, sizeof(marked));
        rep(i, 1, n){
            cin >> v; v--;
            p[i] = v;
        }
        marked[0] = true;
        int ans = 0;
        rep(i, 0, q){
            cin >> c >> v; v--;
            if(c == 'M'){
                marked[v] = true;
            }else{
                ans += dfs(v) + 1;
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 4004
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;

const int N=4005;
const int mod=924844033;

int n,k,x,y,len,m,tag,ans;
int a[N],dp[N][N][2],f[N],c[N][N],fac[N];
bool vis[N][2];

void init(int n){
	int i,j;
	c[0][0]=1; fac[0]=1;
	for (i=1;i<=n;i++){
		c[i][0]=1;
		for (j=1;j<=i;j++) c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
	}
	for (i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mod;
}

int main(){
	int i,j;
	scanf("%d%d",&n,&k);
	init(4000);
	for (i=1;i<=n;i++)
		for (j=0;j<2;j++) if (!vis[i][j]){
			for (x=i,y=j;x<=n;x+=k,y^=1){
				vis[x][y]=1;
				m++;
			}
			a[m]=1;
		}
	dp[1][0][0]=1;
	for (i=1;i<m;i++)
		for (j=0;j<=i;j++){
			(dp[i+1][j][0]+=(dp[i][j][0]+dp[i][j][1])%mod)%=mod;
			if (!a[i]) (dp[i+1][j+1][1]+=dp[i][j][0])%=mod;
		}
	for (i=0;i<=m;i++) (f[i]+=dp[m][i][0]+dp[m][i][1])%=mod;
	ans=fac[n]; tag=-1; m=min(n,m);
	for (i=1;i<=m;i++){
		(ans+=1ll*tag*f[i]*fac[n-i]%mod)%=mod;
		tag*=-1;
	}
	ans=(ans+mod)%mod;
	printf("%d\n",ans);
	return 0;
}

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


long long int result = 0;
int N;
long long int X;
long long int eatLog[51][2] = {};
//もう食べられない：1
//基本：0


int eat(int level) {
	if (eatLog[level][0] != 0 && X> eatLog[level][1]) {
		result += eatLog[level][0];
		X -= eatLog[level][1];
		return 0;
	}
	long long int start_result = result;
	long long int  start_eat = X;
	if (level == 0) {
		++result;
		if (--X == 0)return 1;
	}
	else {//パン
		if (--X == 0)return 1;		
		//レベル level-1 バーガー
		if (eat(level - 1))return 1;
		//パティ
		++result;
		if (--X == 0)return 1;
		//レベル level-1 バーガー
		if (eat(level - 1))return 1;
		//パン
		if (--X == 0)return 1;
	}
	eatLog[level][0] = result-start_result ;
	eatLog[level][1] = start_eat - X;
	return 0;
}


int main() {
	scanf("%d %lld", &N, &X);
	eat(N);
	printf("%lld", result);
	
}


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

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int N, T, A;
	cin >> N >> T >> A;
	vector<int> H(N);
	for (int i = 0; i < N; i++) {
		cin >> H.at(i);
	}
	int ans = 0;
	double tmp = abs(T - H.at(0)*0.006 - A);
	for (int i = 1; i < N; i++) {
		double tmpp;
		tmpp = abs(T - H.at(i)*0.006 - A);
		if ( tmpp < tmp ) {
			tmp = tmpp;
			ans = i;
		}
	}
	cout << ans+1 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long &x, long long &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a%b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n;
	cin >> n;
	vector<vector<int>>a(n, vector<int>(3));
	rep(i, n) {
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	}
	int nowx = 0, nowy = 0, nowt = 0;;
	int len;
	bool ans = true;
	rep(i, n) {
		len = abs(a[i][1] - nowx) + abs(a[i][2] - nowy);
		if (len <= a[i][0] - nowt && (len - a[i][0] + nowt) % 2 == 0) {
			nowt = a[i][0];
			nowx = a[i][1];
			nowy = a[i][2];
			continue;
		}
		else {
			ans = false;
			break;
		}
	}
	Yes(ans);
	return 0;
}

Measured memory_bytes: 5760
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		int h = t / 3600;
		int m = (t - h * 3600) / 60;
		int s = t - (h * 3600) - (m * 60);
		System.out.println(h +":"+ m + ":" + s);
	}

}

Measured memory_bytes: 17352
function main(input) {
  const args = input.split(' ');
  const a = parseInt(args[0]);
  const b = parseInt(args[1]);
  
  if (a * b % 2 === 0) {
    console.log('Even');
  } else {
    console.log('Odd');
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define ALL(i) (i).begin(),(i).end()
#define RALL(i) (i).begin(),(i).end(),greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
#define TENFIVE2 200005
// #define int long long
const int INF = 999999999;
const int MOD = 1e9 + 7;
const double EPS = 1e9 + 7;
const double PI = acos(-1);
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

inline int in(){int x;std::cin>>x;return x;}

using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
using vii = vector<vector<int> >;
using vl = vector<long long>;
using vp = vector<pint>;

template <typename T> void print(T x) { std::cout << x << '\n'; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T*)array, (T*)(array + N), val);
}
signed main(){
  int N,x;
  vi a;
  cin>>N>>x;
  rep(i,N){int tmp;cin>>tmp;a.pb(tmp);}
  ll ans=0;
  if(a[0] > x){int dec = a[0]-x;a[0]-= dec; ans+=dec;}

  rep1(i,N){
    if(a[i]+a[i-1]>x){ int dec = (a[i] +a[i-1])-x;a[i]-=dec; ans+=dec; }
  }

  // if(a[N-1]>x)
  print(ans);
  return 0;
}


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

const int MaxN = 100000;
unsigned long long S[ MaxN + 10 ];

int main()
{
unsigned long long i;
unsigned long long N;
unsigned long long M;
unsigned long long A;
unsigned long long x;
unsigned long long iCnt;
unsigned long long iSum;

	scanf( "%llu%llu", &N, &M );

	iSum = 0;
	iCnt = 0;
	for( i = 1; i <= N; i++ )
	{
		scanf( "%llu", &A );

		iSum += A;
		iSum %= M;
		S[ i ] = iSum;
	}

	sort( S, S + ( N + 1 ) );

	x = 0;
	for( i = 1; i <= N; i++ )
	{
		if( S[ i - 1 ] == S[ i ] )
			x++;
		else
		{
			iCnt += ( x + 1 ) * x / 2;
			x = 0;
		}
	}

	if( x > 0 ) iCnt += ( x + 1 ) * x / 2;

	printf( "%llu\n", iCnt );

	return 0;
}






Measured memory_bytes: 1024
N = int(input())
a = [chr(i) for i in range(97, 97+26)]
ans = ''
while N != 0:
    y = N%26
    if y == 0:
        ans = a[-1] + ans
        N = N//26 - 1
    else:
        ans = a[y-1] + ans
        N = N//26 
print(ans)

Measured memory_bytes: 9168
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <vector>
#include <utility>

using namespace std;

int main()
{
    int a, b;
    cin>>a>>b;
    cout<<a*b-b-a+1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
    string O, E; cin >> O >> E;
    int loopC = max(O.size(), E.size());
    for (int i = 0; i < loopC; i++)
    {
        if (O.size() > i)
        {
            cout << O[i];
        }
        if (E.size() > i)
        {
            cout << E[i];
        }
    }
    cout << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
        for (int i = 0; i < n; i++) {
            pq.add(Integer.parseInt(sc.next()));
        }

        while (m > 0) {
            pq.add(pq.poll() / 2);
            m--;
        }

        long result = 0;
        for (int a : pq) {
            result += a;
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 48212
while 1:
	n=input()
	if n==0:break
	hmax=10000
	block=[map(int,raw_input().split()) for i in range(n)]
	field=[[0]*5 for i in range(hmax)]
	h=0
	for d,p,q in block:
		if d==1:
			for li in range(h+2,-2,-1):
				if field[li][q-1:q+p-1]!=[0]*p or li==-1:
					field[li+1][q-1:q+p-1]=[1]*p
					h=max(h,li+1+1)
					break
		else:
			for li in range(h+2,-2,-1):
				if field[li][q-1]!=0 or li==-1:
					for i in range(p):
						field[li+i+1][q-1]=1
					h=max(h,li+1+p)
					break
		i=0
		while 1:
			if field[i]==[1]*5:
				del field[i]
				h-=1
			elif field[i]==[0]*5:
				break
			else:
				i+=1
	print sum([sum(field[li]) for li in range(len(field))])

Measured memory_bytes: 7156
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) {
        cin >> a[i];
        --a[i];
    }
    vector<ll> s(n+1,0);

    rep(i,n) {
        s[i+1] = (s[i] + a[i]) % k;
    }

    ll ans = 0;
    map<ll, int> mp;
    queue<ll> q; 
    rep(i,n+1) {
        q.push(s[i]);
        while (q.size()>k) {
            --mp[q.front()];
            q.pop();
        }
        ans += mp[s[i]];
        ++mp[s[i]];
    }
    cout << ans << endl;
    return 0;
}


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

// ll calc(ll A, ll B, ll N){
//     if (A < N - B - 1){
//         return A + (B - A) / 2 + 1;
//     } else{
//         return N - B - 1 + (B - A) / 2 + 1;
//     }
// }

int main(){
    ll N, A, B;
    cin >> N >> A >> B;
    A--;
    B--;
    ll dist = abs(A - B);
    ll ans = 0;
    if (dist % 2 == 0){
        ans = dist / 2; 
    } else{
        if (A < B){
            ll dist1 = min(A, N - B - 1);
            ans = dist1 + (dist + 1) / 2;
            // ll way1 = min(N - A - 1, B);
            // ll way2 = calc(A, B, N); 
            // ans = min(way1, way2);
        } else{
            ll dist1 = min(B, N - A - 1);
            ans = dist1 + (dist + 1) / 2;
            // ll way1 = min(N - B - 1, A);
            // ll way2 = calc(B, A, N);
            // ans = min(way1, way2);
        }
    }   
    cout << ans << endl;

    return 0;
}


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

int N;

void dfs(int n, int m, const std::string& s) {
    if (n == N) {
        std::cout << s << std::endl;
        return;
    }

    for (int i = 0; i <= m; ++i) {
        if (i == m) {
            dfs(n + 1, m + 1, s + (char)('a' + i));
        } else {
            dfs(n + 1, m, s + (char)('a' + i));
        }
    }
}


int main() {
    std::cin >> N;
    dfs(1, 1, "a");         

    return 0;
}


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

using namespace std;

#define WMAX (1e5+10)

int main() {
    int n, ww;

    cin >> n >> ww;

    vector<int> w(n), v(n);

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

    vector<vector<int_fast64_t>> dp(n + 1, vector<int_fast64_t>(WMAX));

    for(int wt = 0; wt < WMAX; ++wt) {
        dp.at(0).at(wt) = 0;
    }
    
    for(int i = 1; i <= n; ++i) {
        for(int wt = 0; wt < WMAX; ++wt) {
            if(wt < w.at(i - 1)) {
                dp.at(i).at(wt) = dp.at(i - 1).at(wt);
            } else {
                dp.at(i).at(wt) = max(dp.at(i - 1).at(wt), dp.at(i - 1).at(wt - w.at(i - 1)) + v.at(i - 1));
            }
        }
    }

    printf("%ld\n", dp.at(n).at(ww));

    return 0;
}

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

moziretu={}
a=1
for i in range(n):
    s=input()

    if s in moziretu:
        moziretu[s]=moziretu[s]+1
        a=max(a,moziretu[s])
    else:
        moziretu[s]=1

ans=[k for k, v in moziretu.items() if v == a]
ans.sort()
for i in ans:
    print(i)

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

using namespace std;
vector <int> v , rez;

int main(){
	int N , a;
	cin>>N;
	rez.resize(N);
	for (int i=0;i<N;i++)
	{
		cin>>a;
		v.push_back(a);
	}
	rez[0]=0;
	for (int i=1;i<N;i++)
	{
		rez[i]=abs(v[i-1]-v[i]);
	}
	
	for (int i=2;i<N;i++)
	{
		rez[i]=min(rez[i]+rez[i-1],abs(v[i-2]-v[i])+rez[i-2]);
	}
	
	//for (int i=0;i<N;i++)
	//	cout<<rez[i]<<' ';
	
	cout<<rez[N-1];
	
	return 0;
}


Measured memory_bytes: 1276
N = int(input())
S = [list(input()) for _ in range(N)]
T = [list(_) for _ in zip(*S)]
cnt = 0
for i in range(N):
    f = 1
    for j in range(N):
        if S[i + j - N] != T[j][i:] + T[j][:i]:
            f = 0
            break
    cnt += f
print(cnt * N)


Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
bool isquare(int x){
  int m=floor(sqrt(x));  
  if (m*m==x) return true;
  else return false;
}

int main() {
    int x,y;
    cin>>x>>y;
    int c[20][20];
  int ans=0;
    for (int i=0; i<x; i++){
       for (int j=0; j<y; j++){
         cin>>c[i][j];
       }
    }
    for (int i=0; i<x; i++){
       for (int j=0; j<x; j++){
          int s=0;
          for (int k=0; k<y; k++) 
             s+=(c[i][k]-c[j][k])*(c[i][k]-c[j][k]);
          if (isquare(s)) ans++;
       }
    }
    cout<<(ans-x)/2;
}

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

ans_list = []
p = []
n = []

# 最大にプラス、最小にマイナスを割り当てる
p.append(A[-1])
n.append(A[0])

# 正ならプラスを負ならマイナスを割り当てる
for a in A[1:-1]:
    if a >= 0:
        p.append(a)
    elif a < 0:
        n.append(a)

# プラスが１つになるまで消す
res = n[0]
for ep in p[1:]:
    ans_list.append((res, ep))
    res -= ep
n[0] = res
p = [p[0]]

# マイナスがなくなるまで消す
res = p[0]
for en in n:
    ans_list.append((res, en))
    res -= en

# 残ったものが最大値
M = res
print(M)
for x, y in ans_list:
    print(x, y)

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

int main() {
  int n, p;
  scanf("%d%d", &n, &p);
  int ones = 0;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    if (x % 2 == 1) ones++;
  }
  int zeros = n - ones;
  long long ans = 1;
  for (int i = 0; i < zeros; i++) {
    ans *= 2;
  }
  if (ones > 0) {
    for (int i = 0; i < ones - 1; i++) {
      ans *= 2;
    }
  }
  if (p == 1) {
    ans = (1LL << n) - ans;
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 256
/*
  "Piece of shit. Stupid piece of shit. I'm a real stupid piece
   of shit. But I know I'm a piece of shit. That at least makes
   me better than all the pieces of shit that don't know they're
   pieces of shit. Or is it worse?"
     - BoJack F. Horseman
*/
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstring>
#include<climits>
#include<numeric>
#include<random>
#include<fstream>
#include<chrono>

#include<deque>
#include<queue>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<unordered_map>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define int          long long
#define ld           long double
#define pii          pair<int,int>
#define vi           vector<int>
#define maxpq        priority_queue<int>
#define minpq        priority_queue<int,vi,greater<int>>
#define pb           push_back
#define mp           make_pair
#define ff           first
#define ss           second
#define endl         '\n'
#define rep(i,s,e)   for(int i=s;i<=e;i++)
#define brep(i,s,e)  for(int i=s;i>=e;i--)
#define all(x)       (x).begin(),(x).end()
#define ball(x)      (x).rbegin(),(x).rend()
#define sz(x)        (int)x.size()
#define mem(x,y)     memset(x,y,sizeof(x))
#define milf(x)      x.reserve(1LL<<14LL); x.max_load_factor(0.25);
#define pbds         tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define VR46         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
mt19937              rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1e9+7;
ld EPS = 1e-12;
const int INF32 = 0x3F3F3F3F;
const int INF = 0x3F3F3F3F3F3F3F3F;
const int crng = rng();

signed main()
{
    VR46 ifstream fin("input.txt"); ofstream fout("output.txt");
    // auto start = chrono::high_resolution_clock::now();

    // GANDU TEST CASE BNAKE TEST KRLE; CHECK BOUNDS;
    // int t; cin>>t; rep(test,1,t)
    {
        int n, k;
        cin>>n>>k;
        vi a(n);
        for(auto &i:a) cin>>i;
        sort( all(a) ) ;
        int use = 0;
        rep(i,0,max(n-1-k,-1LL)) use += a[i];
        cout<<use<<endl;
    }

    // auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); 
    // cout<<"Time taken by function: "<<duration.count()<<" milliseconds"<<endl;

    // *( hsh.find_by_order(k) ) kth smallest, from 0
    // hsh.order_of_key(k) num of ele str less than k
    // change less to less_equal for multiset pbds
    // Create struct HASH; Use milf(x) for every hashmap; Use CRNG xor;
}

Measured memory_bytes: 1792
#ライブラリインポート
from collections import defaultdict
con = 998244353
INF = float("inf")

def getlist():
	return list(map(int, input().split()))

N, A, B, K = getlist()

fac = [0] * (N + 1)
inv = [0] * (N + 1)
finv = [0] * (N + 1)
fac[0], fac[1] = 1, 1
inv[1] = 1
finv[0], finv[1] = 1, 1

# 前計算
for i in range(2, N + 1):
	fac[i] = fac[i - 1] * i % con
	inv[i] = inv[con % i] * (con - (con // i)) % con
	finv[i] = finv[i - 1] * inv[i] % con

#処理内容
def main():
	ans = 0
	for i in range(N + 1):
		if (K - i * A) % B == 0:
			j = int((K - i * A) // B)
			if 0 <= j and j <= N:
				ans += (fac[N] * finv[i] * finv[N - i] * fac[N] * finv[j] * finv[N - j]) % con
				ans %= con

	#出力
	print(ans)

if __name__ == '__main__':
	main()

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

using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    string s;
    cin >> s;
    int allE = 0, allW = 0;
    for(int i = 0; i < N; ++i) {
        if (s.at(i) == 'E') ++allE;
        else ++allW;
    }
    size_t res = s.length();
    int curE = 0, curW = 0;
    for(size_t i = 0; i < s.length(); ++i) {
        size_t migiE = allE - curE;
        if (s.at(i) == 'E') --migiE;
        res = min(res, curW + migiE);

        if (s.at(i) == 'E') ++curE;
        else ++curW;
    } 
    cout << res << endl;
}


Measured memory_bytes: 900
#include<stdio.h>

int main(void){

  int n;
  int h[100];
  int i;
  int m;
  int k = 1;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&h[i]);
  }
  int s;
  s = h[0];

  for(i=1;i<n;i++){
    for(m=0;m<=i-1;m++){
      if(h[m]>s){
        s=h[m];
      }
    }
    if(h[i]>=s){
      k++;
    }
  }
  
  printf("%d",k);
  return 0;
}

Measured memory_bytes: 128
/*
doge
░░░▄░░░░░░░░░░░░░░▄
░░░░░░░░▌▒█░░░░░░░░░░░▄▀▒▌
░░░░░░░░▌▒▒█░░░░░░░░▄▀▒▒▒▐
░░░░░░░▐▄▀▒▒▀▀▀▀▄▄▄▀▒▒▒▒▒▐
░░░░░▄▄▀▒░▒▒▒▒▒▒▒▒▒█▒▒▄█▒▐
░░░▄▀▒▒▒░░░▒▒▒░░░▒▒▒▀██▀▒▌
░░▐▒▒▒▄▄▒▒▒▒░░░▒▒▒▒▒▒▒▀▄▒▒▌
░░▌░░▌█▀▒▒▒▒▒▄▀█▄▒▒▒▒▒▒▒█▒▐
░▐░░░▒▒▒▒▒▒▒▒▌██▀▒▒░░░▒▒▒▀▄▌
░▌░▒▄██▄▒▒▒▒▒▒▒▒▒░░░░░░▒▒▒▒▌
▀▒▀▐▄█▄█▌▄░▀▒▒░░░░░░░░░░▒▒▒

Mr Mr has arrived

*/
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <cassert>
#include <iomanip>
#include <random>

using namespace std;

#define ll long long
#define ld long double
#define null NULL

const int N = 333;

queue<int> q[N];

int a[N][N];

bool mark[N];

int n, m;

inline bool check(int x) {
	memset(mark, 0, sizeof(mark));
	for (int i = 1; i <= n; ++i) {
		while (!q[i].empty()) {
			q[i].pop();
		}
		for (int j = 1; j <= m; ++j) {
			q[i].push(a[i][j]);
		}
	}
	bool incorrect = true;
	while (incorrect) {

		vector<int> cnt(m + 1);

		for (int i = 1; i <= n; ++i) {
			if (!q[i].empty()) {
				++cnt[q[i].front()];
			}
		}

		incorrect = false;

		for (int sport = 1; sport <= m; ++sport) {
			if (cnt[sport] > x) {
				mark[sport] = true;
				incorrect = true;
			}
		}

		for (int i = 1; i <= n; ++i) {
			while (!q[i].empty() && mark[q[i].front()]) {
				q[i].pop();
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		if (!q[i].empty()) {
			return true;
		}
	}
	return false;
}


int main() {
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			scanf("%d", &a[i][j]);
		}
	}
	int l = 0, r = n;
	while (r - l > 1) {
		int mid = (l + r) >> 1;
		if (check(mid)) {
			r = mid;
		} else {
			l = mid;
		}
	}
	printf("%d\n", r);
	return 0;
}













Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
//Int mod = 1e6+3;

int main() {
    Int x, a;
    cin >> x >> a;
    dump(x < a ? 0 : 10);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++) {
        cout << "x";
    }
    cout << endl;
}

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

using namespace std;

int main()
{
	string buf;
	
	while (cin >> buf) {
		int amount = 0;
		while ( !(buf.empty()) ) {
			switch ( buf.at(0) ) {
			case 'M':
				buf.erase( buf.begin() ); amount += 1000; break;
			case 'D':
				buf.erase( buf.begin() ); amount += 500; break;
			case 'C':
				if ( buf.size() >= 2 ) {
					if ( buf.at(1) == 'M' ) { buf.erase(0,2); amount += 900; break; }
					else if ( buf.at(1) == 'D' ) { buf.erase(0,2); amount += 400; break; }
				}
				buf.erase( buf.begin() ); amount += 100; break;
			case 'L':
				buf.erase( buf.begin() ); amount += 50; break;
			case 'X':
				if ( buf.size() >= 2 ) {
					if ( buf.at(1) == 'C' ) { buf.erase(0,2); amount += 90; break; }
					else if ( buf.at(1) == 'L' ) { buf.erase(0,2); amount += 40; break; }
				}
				buf.erase( buf.begin() ); amount += 10; break;
			case 'V':
				buf.erase( buf.begin() ); amount += 5; break;
			case 'I':
				if ( buf.size() > 1 ) {
					if ( buf.at(1) == 'X' ) { buf.erase(0,2); amount += 9; break; }
					else if ( buf.at(1) == 'V' ) { buf.erase(0,2); amount += 4; break; }
				}
				buf.erase( buf.begin() ); amount += 1; break;
			}
			// cout << buf << endl;
		}
		cout << amount << endl;
	}	
	
	return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<string> st;
    
    for(int i = 0 ; i < n; i++) {
        string s;
        cin >> s;
        st.push_back(s);
    }
    
    sort(st.begin(), st.end());
    
    for(int i = 0; i < n; i++) {
        cout << st[i];
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int,int>;
using psi = pair<string,int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i,a,n) for(in6 i = a; i < (in6)(n); i++)
#define repdown(i,n) for(in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647
#define dset(n) cout << fixed << setprecision(n)

void yes() {
  cout << "Yes";
}

void no() {
  cout << "No";
}

int main() {
  int k,a,b;
  cin >> k>> a >> b;
  bool ans = 0;
  repa(i,a,b+1) {
    if(i % k == 0) ans = 1;
  }
  if(ans) cout << "OK";
  else cout << "NG";
  hinata;
}


Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
typedef long long int ll;
using namespace std;

int main(){
	vector<int> a(10);
	for(int i=0;i<10;i++){
		cin >>a[i];
	}
	sort(a.begin(),a.end());
	cout << a[9] << endl;
	cout << a[8] << endl;
	cout << a[7] << endl;
}


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

class Program
{
    static void Main()
    {
        Solve();
    }

    static void Solve()
    {
        int n = int.Parse(Console.ReadLine());
        var d = Console.ReadLine().Split().Select(int.Parse).OrderByDescending(x => x).ToArray();
        int sum = 0;

        for(int a = 1; a < n - 1; a++)
        {
            for(int b = 0; b < a; b++)
            {
                int ok = a;
                int ng = n;
                while(ng - ok > 1)
                {
                    int c = (ok + ng) / 2;
                    if (d[c] > d[b] - d[a])
                        ok = c;
                    else
                        ng = c;
                }
                sum += ok - a;
            }
        }

        Console.WriteLine(sum);

    }
}


Measured memory_bytes: 13408
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  if(S[1] == 'B')
    cout << "ARC" << endl;
  else
    cout << "ABC" << endl;
  
  return 0;
}


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

int main(void) {
	int h, w;
	cin >> h >> w;
	vector<vector<int> > c(11, vector<int>(11)), a(h, vector<int>(w));
	for(int i=0;i<10;i++) {
		for(int j=0;j<10;j++) {
			cin >> c[i][j];
		}
	}

	for(int i=0;i<h;i++) {
		for(int j=0;j<w;j++) {
			cin >> a[i][j];
		}
	}

	// ワーシャルフロイト
	for(int i=0;i<10;i++) {
		for(int j=0;j<10;j++) {
			for(int k=0;k<10;k++) {
				c[j][k] = min(c[j][k], c[j][i]+c[i][k]);
			}
		}
	}
	ll cost = 0;
	for(int i=0;i<h;i++) {
		for(int j=0;j<w;j++) {
			if(a[i][j] == -1) continue;
			int node = a[i][j];
			cost += c[node][1];
		}
	}
	cout << cost << endl;
}

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

int N,M; bool ab[10][10],seen[10];

int dfs(int v, int N, bool seen[10]) {
  bool allVisited = true;
  rep(i,N) {
    if (seen[i] == false) allVisited = false;
  }
  if (allVisited) return 1;
  int ret =0;
  rep(i,N) {
    if (ab[v][i] == false) continue;
    if (seen[i]) continue;
    seen[i] = true;
    ret += dfs(i,N,seen);
    seen[i] = false;
  }
  return ret;
}

int main(){
  cin >> N >> M;
  rep(i,M) {
    int a,b; cin >> a >> b; 
    ab[a-1][b-1] = ab[b-1][a-1] = true;
  }
  
  rep(i,N) seen[i] = false;
  seen[0] = true;
  cout << dfs(0,N,seen) << endl;
}

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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);
  
  int r;
  cin >> r;

  cout << 2.0 * r * acos(-1) << '\n';
}

Measured memory_bytes: 3796
//                             In The Name Of Allah
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std; 
 
const int N = 1e6 + 100, OO = 1e9 + 7, T = 410, M = 998244353, P = 6151, SQ = 800, lg = 32;
typedef pair <int, int> pii;

int32_t main() {
	use_fast;
	int n, m;
	cin >> n >> m;
	int t = n * (n - 1) / 2 + (m * (m - 1)) / 2;
	cout << t << endl;
	return 0; 
} 
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- ... 
*/

Measured memory_bytes: 256
#include <stdio.h>
int H;
   
int left(int x){
  return 2*x;
 }
 
int right(int x){
  return 2*x+1;
 }
 
void maxHeapify(int A[], int i){
  int l,r,tmp;
  int largest;
  l = left(i);
  r = right(i);
  if(l <= H && A[l] > A[i]){
    largest = l;
  } else {
    largest = i;
  }
  if(r <= H && A[r] > A[largest]){
    largest = r;
  }
  if(largest !=i){
    tmp = A[i];
    A[i]=A[largest];
    A[largest]= tmp;
    maxHeapify(A,largest);
  }
   
}void buildMaxHeap(int A[]){
  int i;
  for(i = H/2;i > 0;i--){
    maxHeapify(A,i);
  }
}
   
int main(){
  int i;
  int *A;
  scanf("%d",&H);
A = (int *)malloc(sizeof(int)*H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }
  buildMaxHeap(A);
  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
   
  return 0;
}

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

int main (void) {
    int K;
    int A, B;

    cin >> K >> A >> B;

    for ( int i=A; i<=B; i++ ) {
        if ( i % K == 0 ) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}


Measured memory_bytes: 3636
let a, b, k = Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let l, r = min b @@ k + a - 1, max a @@ b - k + 1
let _ = for i = a to l do Printf.printf "%d\n" i done; for i = if r <= l then l + 1 else r to b do Printf.printf "%d\n" i done

Measured memory_bytes: 384
import java.util.Scanner;

/**
 * @author yadavd5
 *
 */
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(n==0)
			System.out.println("1");
		else
			System.out.println("0");
	}
}

Measured memory_bytes: 35564
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
a=0
z=10**5
for i in range(m):
    a=max(a,l[i][0])
    z=min(z,l[i][1])
if a<=z:
    print(z-a+1)
else:
    print(0)

Measured memory_bytes: 27328
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif
#define LDcout(x,n) fixed<<setprecision(n)<<x

#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

void mainmain(){
	int n;
	int K;
	cin>>n>>K;
	// vector<set<int>> vv(K);
	vector<int> vv(n);
	rep(i,K){
		int t;
		cin>>t;
		rep(j,t){
			int tt;
			cin>>tt;
			// vv[i].insert(tt);
			vv[tt-1]=i;
		}
	}
	vint v(n,0);
	int t;
	cin>>t;
	rep(i,t){
		int a,b;
		cin>>a>>b;
		if(vv[a-1]==vv[b-1]){
			v[a-1]=v[b-1]=1;
		}
	}
	int ans=0;
	rep(i,n){
		ans+=v[i];
	}
	cout<<ans<<endl;
}


signed main() {
	ios_base::sync_with_stdio(false);
  	cout<<fixed<<setprecision(0);
    mainmain();
}

Measured memory_bytes: 1200
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main(){
    let mut list:Vec<i32>;
    let mut i = 1;
    loop {
        let input:i32 = read();
        if input == 0 {
            break;
        }
        println!("Case {}: {}", i, input);
        i+=1;
    }
}


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

int main(){
    int A, B; cin >> A >> B;
    if(A>=10 || B>=10){
        cout << -1 << endl;
    }

    else{
        cout << A*B << endl;
    }
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	s := reads()

	yesOrNo(s[2] == s[3] && s[4] == s[5])
}

// IO---------------------------------------------------

func readi() (n int) {
	fmt.Scan(&n)
	return
}

func readf() (n float64) {
	fmt.Scan(&n)
	return
}

func reads() (n string) {
	fmt.Scan(&n)
	return
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func readSlice() []string {
	return strings.Split(readLine(), " ")
}

func atoi(a []string) (b []int) {
	b = make([]int, len(a))
	for i := range a {
		b[i], _ = strconv.Atoi(a[i])
	}
	return
}

func atof(a []string) (b []float64) {
	b = make([]float64, len(a))
	for i := range a {
		b[i], _ = strconv.ParseFloat(a[i], 64)
	}
	return
}

func readSlice2(n int) (a []int, b []int) {
	a = make([]int, n)
	b = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func readFloatSlice2(n int) (a []float64, b []float64) {
	a = make([]float64, n)
	b = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func yesOrNo(b bool) {
	if b {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

func yesorNO(b bool) {
	if b {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")
}

func yesorno(b bool) {
	if b {
		fmt.Println("yes")
		return
	}
	fmt.Println("no")
}

// calc---------------------------------------------------

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func ave(a []int) (ave int) {
	for i := 0; i < len(a); i++ {
		ave += a[i]
	}
	ave /= len(a)
	return
}

func eq(a []string, b []string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

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

func max(a ...int) int {
	max := a[0]
	for i := 1; i < len(a); i++ {
		if max < a[i] {
			max = a[i]
		}
	}
	return max
}

func min(a ...int) int {
	min := a[0]
	for i := 1; i < len(a); i++ {
		if min > a[i] {
			min = a[i]
		}
	}
	return min
}

func mid(a []int) int {
	sort.Ints(a)
	return a[len(a)/2]
}

func sum(a []int) (ans int) {
	for i := range a {
		ans += a[i]
	}
	return
}

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

int main() {
  long long a, b, k;
  cin >> a >> b >> k;
  long long k2 = a+k;
  k2 = min(b+1, k2);
  for(long long i=a; i<k2; i++) {
    cout << a << endl;
    a++;
  }
  long long b2 = b-k+1;
  b2 = max(a, b2);
  for(long long i=b2; i<=b; i++) {
    cout << b2 << endl;
    b2++;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<pair<int,int>> jobs;
bool comp(pair<int,int> const &a,pair<int,int> const &b){
    return a.second < b.second;
}
int32_t main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        jobs.push_back({a,b});
    }
    sort(jobs.begin(),jobs.end(),comp);
    int s = 0;
    for(pair<int,int> p : jobs){
        s+=p.first;
        if(s>p.second){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 6384
#include<iostream>
    #include<vector>
    #include<algorithm>
    #define lli long long
    #define all(i) i.begin(),i.end()
    #define rall(i) i.rbegin(),i.rend()
    #define rep0(i,j) for(int i=0;i<j;i++)
    #define rep1(i,j) for(int i=1;i<=j;i++)
    #define rep0d(i,j) for(int i=j-1;i>=0;i--)
    #define MAX 1000000007
     
    using namespace std;
     
     
     
    int main() {
        lli n, mi = 1e16;
        lli min;
        cin >> n;
        vector<lli> vec(5,0);
        rep0(i,5){
            cin >> vec[i];
        
            if(vec[i]<mi){
                min = i;
                mi = vec[i];
            }
        }
        
        // cout << ((n%vec[min]==0)?0:1);
        // cout << '\n';
        cout << n/vec[min] + 4 + ((n%vec[min]==0)?0:1);
        cout << '\n';
    }

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*/
  int x; cin>>x; 
  if(x>=30){ cout<<"Yes\n"; }
  else cout<<"No\n"; return 0; 
}

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

void solve()
{
    char a, b;
    cin >> a >> b;
    if( a == 'H' ){
        cout << b << "\n";
    }
    else {
        b == 'H'? cout << "D\n" : cout << "H\n";
    }
}
int main() {

    solve();

    return 0;
}


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

using namespace std;

const int MX = 5002;

int a[MX], l[MX][MX], r[MX][MX];
long long dp[MX];

int main() {
	int n, A, B;
	ignore = scanf("%d %d %d", &n, &A, &B);
	for (int i = 1; i <= n; i++) ignore = scanf("%d", a + i);
	
	n += 2;
	a[n - 1] = n - 1;
	
	for (int i = 0; i < n; i++) {
		l[i][i] = 0;
		for (int j = i + 1; j < n; j++) {
			l[i][j] = l[i][j - 1] + (a[j] < a[i] ? 1 : 0);
		}
		
		r[i][i] = 0;
		for (int j = i - 1; j >= 0; j--) {
			r[j][i] = r[j + 1][i] + (a[j] > a[i] ? 1 : 0);
		}
	}
	
	dp[0] = 0;
	for (int i = 1; i < n; i++) {
		dp[i] = 1e16;
		for (int j = 0; j < i; j++)
			if (a[j] < a[i] && l[j][i] + r[j][i] == i - j - 1)
				dp[i] = min(dp[i], dp[j] + l[j][i] * 1LL * B + r[j][i] * 1LL * A);
	}
	
	printf("%lld\n", dp[n - 1]);
	
	return 0;
}


Measured memory_bytes: 195072
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			String[] str=sc.next().split(",");
			double[] l=new double[10];
			double length=0;
			for(int i=0;i<10;i++){
				l[i]=Integer.parseInt(str[i]);
				length=length+l[i];
			}
			double v1=Integer.parseInt(str[10]);
			double v2=Integer.parseInt(str[11]);
			double cross=v1*(length/(v1+v2));
			int part=0;
			length=0;
			for(int i=0;i<10;i++){
				length=length+l[i];
				part++;
				if(length>=cross){
					break;
				}
			}
			System.out.println(part);
		}
	}
}

Measured memory_bytes: 17140
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(a) (a).begin(), (a).end()
#define sz(a) (int) (a).size()
#define x first
#define y second

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &el : a) cin >> el;
    map<int, int> mp;
    int ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        ans += mp[a[i] + i];
        mp[i - a[i]]++;
    }
    cout << ans << "\n";

    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<vector<ll>> A(N,vector<ll>(3,0));
  for(int i=0;i<N;i++){
    for(int j=0;j<3;j++){
      cin >> A[i][j];
    }
  }
  vector<vector<ll>> M(N,vector<ll>(3,0));
  M[0][0]=A[0][0];
  M[0][1]=A[0][1];
  M[0][2]=A[0][2];
  for(int i=1;i<N;i++){
    M[i][0]=A[i][0]+max(M[i-1][1],M[i-1][2]);
    M[i][1]=A[i][1]+max(M[i-1][0],M[i-1][2]);
    M[i][2]=A[i][2]+max(M[i-1][0],M[i-1][1]);
  }
  cout << max(max(M[N-1][0],M[N-1][1]),M[N-1][2]) << endl;
}

Measured memory_bytes: 11136
#include<iostream>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<cctype>

using namespace std;

int main(){

	int k;
	cin>>k;
	
	if(k%2==1){
		cout<<(k/2)*(k/2+1)<<endl;
	}else cout<<(k/2)*(k/2)<<endl;
	return 0;
}


Measured memory_bytes: 256