akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cmath>

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define VEC vector

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				Vint;
typedef vector<Vint>			VV;

template<typename T>string join(const v(T)&v)
{stringstream s;REP(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		400010

const ll LINF = (ll)9e18+7;		//
const int INF = 100100100;			//2,147,483,647 (Max int)
const ll MOD = 1e9+7;
// テンプレ終了
//====================================================================//

// int DP[MAX];

//
int main(){
	ll N;cin >> N;

	ll ans = 0;

	REPS(i,1,N+1){
		if(i%3!=0 && i%5!=0)ans += i;
	}

	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 3636
// AtCoder Regular Contest 073
// C - Sentou

#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long int ll;


int N;
ll T;
ll ans;

int main() {

  ll t, stops_at;

  scanf("%d%lld", &N, &T);
  stops_at = 0;
  ans = 0;
  for (int i = 0; i < N; i++) {
    scanf("%lld", &t);
    ans += T - max(stops_at - t, 0LL);
    stops_at = t + T;
  }

  printf("%lld\n", ans);

  return 0;

}




Measured memory_bytes: 128
import bisect

n,k = map(int,input().split())
lst = list(map(int,input().split()))
mod = 10**9+7

order = sorted(lst)

ans = 0
for i in range(n):
    cnt = 0
    x = lst[i]
    for j in range(i+1,n):
        y = lst[j]
        if x>y:
            cnt += 1
    ans += cnt*k + (k*(k-1)//2)*bisect.bisect_left(order, x)
    ans %= mod
print(ans%mod)

Measured memory_bytes: 3188
import collections
n = int(input())

a = list(input())
su = 0
co = 1
coo = 0
c = 0
cc = 0
k = a[0]
c1 = n
c2 = 0
c3 = 0
aa = []
p = a.count("#")
pp = a.count(".")

for i in range(n-1):
	if k == a[i+1]:
		co += 1
	else:
		aa.append([k,co])
		k = a[i+1]
		co = 1

aa.append([k,co])
co = 0
if aa[-1][0] == ".":
	aa.append(["#",0])
for i in range(len(aa)):
	if aa[-(i+1)][0] == "#":
		c += aa[-(i+1)][1]
		c3 += aa[-(i+1)][1]
		c1 = min(c1,cc + p - c)
	else:
		cc += aa[-(i+1)][1]
		c2 += aa[-(i+1)][1]
		c1 = min(c1,cc + p - c)

print(min(c1,c2,c3))



Measured memory_bytes: 25376
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		long W = sc.nextLong();
		
		long s = H * W;
		long s1h = H * W;
		long s1w = H * W;
		long sh3 = H * W;
		long sw3 = H * W;
		
		if(H * W % 3 == 0) {
			System.out.println(0);
		} else {
			sh3 = (H / 3 + 1) * W - H / 3 * W;
			sw3 = (W / 3 + 1) * H - W / 3 * H;
			
			for(long i = 1; i < H; i++) {
				long s1 = i * W;
				long s2 = (H - i) * (W / 2);
				long s3 = 0;
				
				if(W % 2 == 0) {
					s3 = s2;
				} else {
					s3 = (H - i) * (W / 2 + 1);
				}
				
				long stemp = Math.max(Math.max(s1, s2), s3) - Math.min(Math.min(s1,  s2), s3);
				s1h = Math.min(s1h, stemp);
			}
			
			for(long i = 1; i < W; i++) {
				long s1 = i * H;
				long s2 = (W - i) * (H / 2);
				long s3 = 0;
				
				if(H % 2 == 0) {
					s3 = s2;
				} else {
					s3 = (W - i) * (H / 2 + 1);
				}
				
				long stemp = Math.max(Math.max(s1, s2), s3) - Math.min(Math.min(s1,  s2), s3);
				s1w = Math.min(s1w, stemp);
			}
			
			s = Math.min(Math.min(Math.min(sh3, sw3), s1h), s1w);
			System.out.println(s);
		}
	}
}


Measured memory_bytes: 23636
import math

n,m = map(int,input().split())
a = input()
b = input()
g = math.gcd(n,m)
l = (n*m)//g
d = {}
for i in range(n):
    d[i*(l//n)] = a[i]
for i in range(m):
    if i*(l//m) in d:
        if d[i*(l//m)] != b[i]:
            print(-1)
            exit()
print(l)

Measured memory_bytes: 19660
import sys
from string import digits

def main():
    n, s = sys.stdin.read().split()
    n = int(n)

    place = dict((i, set()) for i in digits)
    for i in range(n):
        place[s[i]].add(i)

    l = [None] * n
    l[0] = set()
    for i in range(1, n):
        l[i] = l[i-1] | set([s[i-1]])
    
    r = [None] * n
    r[n-1] = set()
    for i in range(n-2, -1, -1):
        r[i] = r[i+1] | set([s[i+1]])

    res = set()
    for j in digits:
        for c in place[j]:
            for i in digits:
                if i in l[c]:
                    for k in digits:
                        if k in r[c]:
                            res.add((i, j, k))
    
    print(len(res))


if __name__ == '__main__':
    main()

Measured memory_bytes: 50680
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n): return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
h=n1()
ans=0
c=0
for i in range(n-1):
    if h[i]>=h[i+1]:
        c+=1
    else:
        ans=max(ans,c)
        c=0
ans=max(ans,c)
print(ans)

Measured memory_bytes: 14480
#include <iostream>
#include <vector>
#include <map>
#include <math.h>
#include <algorithm>
#include <sstream>
#include <list>

using namespace std;

int main()
{
	long a, b, c, d, e;
	long k;
	cin >> a >> b >> c >> d >> e;
	cin >> k;

	if (e - a > k)
	{
		printf(":(");
	}
	else
	{
		printf("Yay!");
	}
	
	return 0;
}


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

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    if(a.at(a.length() - 1) == b.at(0) && b.at(b.length() - 1) == c.at(0)) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
s1 = raw_input()
s2 = raw_input()

a = [[0 for i in range(len(s2) + 1)]for i in range(len(s1) + 1)]
for i in range(len(s2) + 1):
    a[0][i] = i
for i in range(len(s1) + 1):
    a[i][0] = i
for i in range(len(s1)):
    for j in range(len(s2)):
        if s1[i] == s2[j]:
            a[i+1][j+1] = a[i][j]
        else:
            a[i+1][j+1] = min([a[i][j+1], a[i+1][j], a[i][j]]) + 1
print a[len(s1)][len(s2)]

Measured memory_bytes: 36624
#include <stdio.h>

int bubbleSort(int A[], int N)
{
  int flag = 1, t,j, i=0, sw=0;
  while (flag) {		  
      flag =0;
      for (j= N-1; j>=i+1; j--){
	    if ( A[j] < A[j-1] ){
	      t = A[j]; A[j] = A[j-1]; A[j-1] = t;
	      sw++;
	      flag=1;
	    }
      }
      i++;
  }
  return sw;
}


void print(int A[], int N, int sw){
  int i;
  for ( i = 0; i < N; i++ ){
    if (i) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
  printf("%d\n", sw);
}

int main( void )
{
  int A[100], n, i, sw=0;
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);

  sw=bubbleSort(A,n);

  print(A,n,sw);
  
  return 0;
}

  



Measured memory_bytes: 2680
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ull  unsigned long long
#define pb push_back

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 300000;

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt",  "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s;
    cin >> s;
    if (s.length() >= 4 && s.substr(0, 4) == "YAKI") cout << "Yes"; else cout << "No";
}


Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;

void main()
{
  string input;
  int div;

  while ((input = readln().chomp()).length != 0) {
    div = input.to!int();
    int[] position = iota(600).filter!(a => a % div == 0).array();
    int sum;
    foreach (pos; position) {
      sum += pos * pos * div;
    }
    writeln(sum);
  }
}

Measured memory_bytes: 1084
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x*2<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll a,b;cin>>a>>b;a=__gcd(a,b);
    ll cnt=1;
    for(ll i=2;i*i<=a;i++){
        bool state=0;
        while(a%i==0){state=1;a/=i;}
        if(state)cnt++;
    }
    if(a>1)cnt++;
    cout<<cnt<<"\n";
}


Measured memory_bytes: 3624
x,n = [int(x) for x in input().split()]
if n == 0:
    print(x)
    exit()
p = [int(x) for x in input().split()]
a = []
for i in range(102):
    if i in p:
        continue
    a.append(i)
b = [0]*len(a)
for i in range(len(a)):
    b[i] = a[i]
for i in range(len(a)):
    a[i] = abs(a[i]-x)
m = min(a)
if x - m in b:
    print(x-m)
else:
    print(x+m)

Measured memory_bytes: 9216
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main(){

	string X;

	cin>>X;

	bool f1=false,f2=false,f3=false,f4=false;
	if(X.size()>=6)f4=true;
	for(int i=0;i<X.size();i++)
	{
		if(X[i]>='a'&&X[i]<='z')f1=true;
		if(X[i]>='A'&&X[i]<='Z')f2=true;
		if(X[i]>='0'&&X[i]<='9')f3=true;
	}

	if(f1==false||f2==false||f3==false||f4==false)
		cout<<"INVALID"<<endl;
	else cout<<"VALID"<<endl;
	return 0;
}

Measured memory_bytes: 1180
def gcd(m, n)
    if m < n
        gcd(n, m)
    elsif n == 0
        m
    else
        gcd(n, m % n)
    end
end

def lcm(m, n)
    m * n / gcd(m, n)
end

n, m = gets.split.map(&:to_i)
num = gets.split.map(&:to_i)
prob = gets.split.map(&:to_i).map {|x| x / 100.0}

exp = 0

qs = [1]
lcms = [1]

(1..2**n-1).each do |x|
    a = (0..n-1).select {|i| x[i] == 1}
    i = a[0]
    y = x & (x - 1)
    qs[x] = qs[y] * prob[i]
    lcms[x] = lcm(lcms[y], num[i])
    k = m / lcms[x]
    exp += (a.size.odd? ? 1 : -1) * k * qs[x]
end
printf("%.9f\n", exp)

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

using namespace std;

int main() {
    int d, n;
    cin >> d >> n;
    if (n == 100) n++;

    int ans = n;
    for (int i = 0; i < d; ++i) {
        ans *= 100;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
const int fa=21;
int n,m;
struct wgh
{
    double l,a,b;
}a[fa];
double ans;
bool b[fa];
void dfs(int u,int o,double g)
{
    if(o>m)return;
    if(u==n)
    {
        if(o==m)
        {
            if(ans<g)
            ans=g;
        }
        return;
    }
    int i;
    double k=0;
    b[u+1]=true;
    for(i=1;i<=u;i++)
    {
        if(b[i])
        {
            k+=(a[u+1].l-a[i].l)*(a[u+1].l-a[i].l)+(a[u+1].a-a[i].a)*(a[u+1].a-a[i].a)+(a[u+1].b-a[i].b)*(a[u+1].b-a[i].b);
        }
    }
    dfs(u+1,o+1,g+k);
    b[u+1]=false;
    dfs(u+1,o,g);
    return;
}
int main()
{
    int i,j,k;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)
    {
        scanf("%lf%lf%lf",&a[i].l,&a[i].a,&a[i].b);
    }
           dfs(0,0,0);
        printf("%lf",ans);
    return 0;
}

Measured memory_bytes: 884
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin>>N;
vector<string>S(N);
vector<int>answer(4);
for(int i=0; i<N; i++){
    cin>>S.at(i);
    if(S.at(i)=="AC"){
        answer.at(0)++;
    }
    if(S.at(i)=="WA"){
        answer.at(1)++;
    }
    if(S.at(i)=="TLE"){
        answer.at(2)++;
    }
    if(S.at(i)=="RE"){
        answer.at(3)++;
    }
}
for(int i=0; i<4; i++){
    if(i==0){
        cout<<"AC x ";
    }
    if(i==1){
        cout<<"WA x ";
    }
    if(i==2){
        cout<<"TLE x ";
    }
    if(i==3){
        cout<<"RE x ";
    }
cout<<answer.at(i)<<endl;
}
}



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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
int main() {
	long long a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max({a * c * 1ll, a * d * 1ll, b * c * 1ll, b * d * 1ll}) << "\n";
}


Measured memory_bytes: 3672
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		if (a.length() > b.length()) {
			System.out.println("GREATER");
			return;
		}
		if (a.length() < b.length()) {
			System.out.println("LESS");
			return;
		}
		char[] ac = new char[a.length()];
		char[] bc = new char[b.length()];
		for (int i = 0; i < a.length(); i++) {
			ac[i] = a.charAt(i);
		}
		for (int i = 0; i < b.length(); i++) {
			bc[i] = b.charAt(i);
		}
		for (int i = 0; i < a.length(); i++) {
			if (ac[i]>bc[i]) {
				System.out.println("GREATER");
				return;
			}
			if (ac[i]<bc[i]) {
				System.out.println("LESS");
				return;
			}
		}
		System.out.println("EQUAL");
	}
}


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

int n;
int mat[500][500];

void rec(int l, int r, int c) {
  if (r - l == 1) return;
  int m = (l + r) / 2;
  for (int i = l; i < m; ++i) {
    for (int j = m; j < r; ++j) {
      mat[i][j] = c;
      mat[j][i] = c;
    }
  }
  rec(l, m, c + 1);
  rec(m, r, c + 1);
}

int main() {
  cin >> n;
  rec(0, n, 1);
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      cout << mat[i][j] << ' ';
    }
    cout << endl;
  }
}

Measured memory_bytes: 1408
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
class Problem
{
    static void Main()
    {
        //--------------------------------input--------------------------------//

        int n = Convert.ToInt32( Console.ReadLine() );
        var v = Array.ConvertAll( Console.ReadLine().Split(), Convert.ToInt32 );
        var c = Array.ConvertAll( Console.ReadLine().Split(), Convert.ToInt32 );
        

        //--------------------------------solve--------------------------------/

        var a = new int[n];
        for(int i = 0 ; i < n ; i++)
            a[i] = v[i] - c[i];

        var f = new int[n];
        f[0]=Math.Max(0,a[0]);
        for(int i = 1 ; i < n ; i++)
            f[i] = Math.Max( f[i - 1], f[i - 1] + a[i] );
        Console.WriteLine( f[f.Length - 1] );
    }
   

}

Measured memory_bytes: 11220
#include<stdio.h>

int main(void)
{
	int n,i,j;
	char s[101];
	int l[26]={0};
	int r[26]={0};
	int b[26]={0};
	int sum=0,max=0;
	scanf("%d%s",&n,s);
	
	for(i=1;i<n;i++){
		for(j=0;j<i;j++)
			l[s[j]-'a']=1;
		for(j=i;j<n;j++)
			r[s[j]-'a']=1;
		for(j=0;j<26;j++){
			b[j]=l[j]*r[j];
			sum+=b[j];
		}
		if(sum>max)
			max=sum;
		sum=0;
		for(j=0;j<26;j++){
			l[j]=0;
			r[j]=0;
		}
	}
	printf("%d",max);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

int main() {
    ll N, M, K;
    cin >> N >> M >> K;
    ll *A = new ll[N], *B = new ll[M];
    for (int i = 0; i < N; i++)
        cin >> A[i];
    for (int i = 0; i < M; i++)
        cin >> B[i];
    ll *a = new ll[N], *b = new ll[M];
    a[0] = A[0], b[0] = B[0];

    for (int i = 1; i < N; i++)
        a[i] = a[i-1]+A[i];
    for (int i = 1; i < M; i++)
        b[i] = b[i-1]+B[i];

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        if (K-a[i] >= 0) {
            ll *c = upper_bound(b, b+M, K-a[i]);
            ll ind =(ll)(c-b);
            ans = max(ans, i+1+ind);
        }
    }
    ll *c = upper_bound(b, b+M, K);
    ans = max(ans, (ll)(c-b));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9824
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
data = list(map(int,read().split()))

ans = []
it = iter(data)
for a,b in zip(it,it):
    if(a > b):
        a,b = b,a
    ab = a*b
    ok = 0
    ng = b*2
    while(ng-ok > 1):
        mid = (ok+ng)//2
        x = (mid//2) * ((mid+1)//2)
        if( ab > x):
            ok = mid
        else:
            ng = mid
    ans.append(max(0,ok-2*a) + 2*a-2)

print('\n'.join(map(str,ans)))

Measured memory_bytes: 64600
#a, b, c, d = (int(i) for i in input().split())  

#a = [int(i) for i in input().split()] 

A, B = (int(i) for i in input().split())  

if A <= 5:
    print(0)
elif 5 < A and A <= 12:
    print(int(B/2))
else:
    print(B)

Measured memory_bytes: 2940
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

int V, E;
vector<vector<int>> G;
vector<i64> dist;

void dfs(int u) {
    for (const int nxt : G[u]) {
        if (dist[nxt] != LINF) continue;
        chmin(dist[nxt], dist[u] + 1);
        dfs(nxt);
    }

    return;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    read(V, E);
    G.resize(V);

    rep(i, 0, E) {
        var(int, a, b);
        --a, --b;
        G[a].emplace_back(b);
    }

    i64 minlen = LINF;
    dist.resize(V);
    rep(a, 0, V) {
        for (const int b : G[a]) {
            fill(all(dist), LINF);
            dist[b] = 0;
            dfs(b);
            chmin(minlen, dist[a]);
        }
    }

    if (minlen == LINF) {
        print(-1);
        return 0;
    } else {
        print(0);
    }

    return 0;
}



Measured memory_bytes: 384
# 2019-11-14 20:54:46(JST)
import sys
# import collections
import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 


def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

def main():
    a, b, c, d = [int(x) for x in sys.stdin.readline().split()]
    res1 = b - (b // c + b // d - b // lcm(c, d))
    res2 = (a - 1) - ((a - 1) // c + (a - 1) // d - (a - 1) // lcm(c, d))
    ans = res1 - res2
    print(ans) 

if __name__ == "__main__":
    main()


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

ull lcm(ull, ull);
ull gcd(ull, ull);

int main()
{
    ull A, B, C, D;
    cin >> A >> B >> C >> D;

    ull ans = (B - (A - 1)) - ((B / C - (A - 1) / C) + (B / D - (A - 1) / D) - (B / lcm(C, D) - (A - 1) / lcm(C, D)));
    cout << ans << endl;
}

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

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

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

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

    string day[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    // int remain[7] = {7, 6, }

    string str; cin >> str;
    int i;
    for(int i = 0; i < 7; i++){
        if(str[0] == day[i][0] && str[1] == day[i][1]){
            cout << 7 - i << endl;
            break;
        }
    }



    return 0;
}

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

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
 
#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)
 
inline ll ii(){ ll x; cin >> x; return x; }
inline string is(){ string x; cin >> x; return x; }
inline ld id(){ ld x; cin >> x; return x; }
inline void oi(ll x){ cout << x; }
inline void od(ld x){ cout << fixed << setprecision(10) << x; }
inline void os(string x){ cout << x; }
inline void oe(){ cout << endl; }
inline void oie(ll x){ oi(x); oe(); }
inline void ode(ld x){ od(x); oe(); }
void ose(string x){ os(x); oe(); }

int main(){
    string s = is();
    if(s.find("RRR")!=string::npos){
        oie(3);
    }else if(s.find("RR")!=string::npos){
        oie(2);
    }else if(s.find("R")!=string::npos){
        oie(1);
    }else{
        oie(0);
    }

    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];
const int INF = 1e9;
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

void solve(long long N)
{
    if (N <= 999)
    {
        cout << "ABC" << endl;
    }
    else
    {
        cout << "ABD" << endl;
    }
}

int main()
{
    long long N;
    scanf("%lld", &N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
fn main(){
    let (x, y) = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let mut ws = s.trim_end().to_owned().split_whitespace();
        let mut ws = s.split_whitespace();
        let x: i32 = ws.next().unwrap().parse().unwrap();
        let y: i32 = ws.next().unwrap().parse().unwrap();
        (x, y)
    };

    for i in 0..x {
        {
            let mut cranes = 0;
            let mut turtles = 0;
            cranes = i + 1;
            turtles = x - cranes;

            if cranes * 2 + turtles * 4 == y {
                println!("Yes");
                return;
            }
        }
        {
            let mut cranes = 0;
            let mut turtles = 0;
            turtles = i + 1;
            cranes = x - turtles;

            if cranes * 2 + turtles * 4 == y {
                println!("Yes");
                return;
            }
        }
    }
    println!("No");
}


Measured memory_bytes: 2172
#ceilevenoddformula
import math
import bisect
import copy
import time
from collections import Counter
#map(int,input().split())
#int(x) for x in input().split()
n=int(input())
l=[int(x) for x in input().split()]
k=[]
def stockBuySell(price, n):  
    if (n == 1): 
        return

    i = 0
    while (i < (n - 1)): 
        while ((i < (n - 1)) and 
                (price[i + 1] <= price[i])): 
            i += 1
          
        if (i == n - 1): 
            break

        buy = i 
        i += 1
           
        while ((i < n) and (price[i] >= price[i - 1])): 
            i += 1
 
        sell = i - 1
        k.append(buy)
        k.append(sell)

stockBuySell(l,n)
cur=1000

for i in range(len(k)):
	if i%2==0:
		x=cur//l[k[i]]
		cur-=int(x)*l[k[i]]
	else:
		cur+=int(x)*l[k[i]]

print(cur)




 
          





























Measured memory_bytes: 68060
#include <bits/stdc++.h>
#define inf 1000000000 //1E+9
using namespace std;

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

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

	cout<<min(zero,one)*2<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,double> P;
int main(){
  int n,m,p,a,b;
  while(cin>>n>>m>>p>>a>>b,n){
    a--,b--;

    double t[8],tp;
    vector<P> e[31];

    for(int i=0;i<n;i++)cin>>t[i];
    for(int j=0,x,y;j<p;j++){
      cin>>x>>y>>tp;
      x--,y--;
      e[x].push_back(P(y,tp)),e[y].push_back(P(x,tp));
    }

    double dp[1<<8][30];
    for(int i=0;i<1<<n;i++)
	for(int j=0;j<m;j++)dp[i][j]=1e4;
    dp[0][a]=0;

    for(int i=0;i<1<<n;i++)
      for(int j=0;j<m;j++)
	for(int k=0;k<n;k++)
	  if(!(i&1<<k))
	    for(int l=0;l<e[j].size();l++)
	      dp[i+(1<<k)][e[j][l].first]
	 =min(dp[i+(1<<k)][e[j][l].first],dp[i][j]+e[j][l].second/t[k]);

    double ans=1e4;
    for(int i=0;i<1<<n;i++)ans=min(ans,dp[i][b]);
    if(ans==1e4)cout<<"Impossible"<<endl;
    else cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
const int MOD = 1e9 + 7;

ll N, M, K, Q, A;

ll dp[51][2505];

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

    N = 2 * N - 1;

    if (A == 1 || A == N) {
        cout << "No" << endl;
    } else if (N == 3) {
        cout << "Yes" << endl;
        cout << "1 2 3" << endl;
    } else {
        cout << "Yes" << endl;

        vector<int> ans;
        int l2 = (A == N - 1) ? A - 3 : A + 2;
        int r2 = (A == 2) ? A + 3 : A - 2;
        int i = N;
        for (; i >= 1 && (int)ans.size() < N / 2 - 2; i--) {
            if (i != A && i != A + 1 && i != A - 1 && i != l2 && i != r2) ans.push_back(i);
        }
        ans.push_back(l2);
        ans.push_back(A + 1);
        ans.push_back(A);
        ans.push_back(A - 1);
        ans.push_back(r2);
        for (; i >= 1; i--) {
            if (i != A && i != A + 1 && i != A - 1 && i != l2 && i != r2) ans.push_back(i);
        }
        for (int j = 0; j < N; j++) {
            cout << ans[j];
            if (j != N - 1) cout << " ";
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a; i < n; i++)
#define per(i,n,a) for (int i = n - 1; i >= a; i--)
using namespace std;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int r = 0;
    rep(i, 1, n + 1) {
        int c = 0, t = i;
        rep(j, 0, 5) {
            c += t % 10;
            t /= 10;
        }
        if (a <= c && c <= b) {
            r += i;
        }
    }
    cout << r << endl;
}


Measured memory_bytes: 256
def main():
    import math
    H = int(input())
    if H == 1:
        print(1)
    else:
        count = int(math.log(H,2))
        ans = 0
        for i in range(count):
            ans += 2**(i)
            if i == count-1:
                ans += 2**(i+1)
        print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<stdio.h>

int main(){
  int ans,x,N,M,sum=0;
  scanf("%d",&N);
  scanf("%d",&M);
  for(int a=1;a<=M;a++){
    scanf("%d",&x);
    sum+=x;
  };
  ans=N-sum;
  if(ans<0)ans=-1;
  printf("%d",ans);
};


Measured memory_bytes: 1724
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a;
    while(~scanf("%d",&a))
    {
        if(a%3==0)
        {
            printf("%d\n",a/3);
        }
        if(a%3!=0)
        {
    printf("%d\n",a/3);
        }
    }
   }


Measured memory_bytes: 128
object Main extends App {
    val in = io.Source.stdin.getLines
    for (n <- in if n != "0") {
        val dic = in.take(n.toInt).map{r => val Array(k, v) = r.split(" "); (k, v)}.toMap
        println(in.take(in.next.toInt).map(k => dic.get(k) match {
            case Some(v) => v
            case _ => k
        }).mkString)
    }
}

Measured memory_bytes: 57232
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
void Main()
{
    ll n;
    cin >> n;
    vector<ll> A(n);
    rep(i, n) cin >> A[i];

    sort(all(A));

    ll maxA = *max_element(all(A));
    vector<int> S(maxA + 1);

    rep(i, n) {
        if (S[A[i]]) {
            continue;
        }
        for (ll x = 2 * A[i]; x < S.size(); x += A[i]) {
            S[x] = 1;
        }
    }

    ll res = 0;
    rep(i, n) {
        if (i + 1 < n && A[i] == A[i + 1]) {
            continue;
        }
        if (i - 1 >= 0 && A[i-1] == A[i]) {
            continue;
        }
        if (S[A[i]] == 0) {
            res += 1;
        }
    }

    put(res);
}
signed main(){ Main();return 0;}

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

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

const int M = 3030;
int64_t dp[M][M][5];

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<int64_t>> A(H, vector<int64_t>(W));
    rep(i, K) {
        int r, c, v;
        cin >> r >> c >> v;
        r--, c--;
        A[r][c] = v;
    }
    if(A[0][0]) dp[0][0][1] = A[0][0];
    rep(i, H) rep(j, W) rep(k, 4) {
        if(i) {
            chmax(dp[i][j][0], dp[i - 1][j][k]);
            chmax(dp[i][j][1], dp[i - 1][j][k] + A[i][j]);
        }
        if(j) {
            chmax(dp[i][j][k], dp[i][j - 1][k]);
            chmax(dp[i][j][k + 1], dp[i][j - 1][k] + A[i][j]);
        }
    }
    int64_t ans = 0;
    rep(k, 4) chmax(ans, dp[H - 1][W - 1][k]);
    cout << ans << '\n';
    return 0;
}


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

int main() {
	int score = 0;
	int N; cin >> N;
	int arr[N];
	int sum = 0;
	for(int i = 0; i < N; i++) {
		cin >> arr[i];
		sum += arr[i];
	}
	if(sum % 10 != 0) {
		cout << sum << endl;
	} else {
		for(int i = 0; i < N; i++) {
			if((sum - arr[i])%10 != 0) {
				if(score < sum - arr[i]) {
					score = sum - arr[i];
				}
			}
		}
		cout << score << endl;
	}

}

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

#define select(_1, _2, x, ...) x

#define repn(i, n) for (int i = 0; i < (n); i++)
#define repr(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, ...) select(__VA_ARGS__, repr, repn)(i, __VA_ARGS__)

#define rrepn(i, n) for (int i = (n - 1); i >= 0; i--)
#define rrepr(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define rrep(i, ...) select(__VA_ARGS__, rrepr, rrepn)(i, __VA_ARGS__)

#define umax(m, x) (m = max(m, x));
#define umin(m, x) (m = min(m, x));

#define rng(v) v.begin(), v.end()
#define rrng(v) v.rbegin(), v.rend()

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;

const int INF = 1e9;
const ll LINF = 1e18;


int main() {
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    vector<ll> p(a), q(b), r(c);
    rep(i, a) cin >> p[i];
    rep(i, b) cin >> q[i];
    rep(i, c) cin >> r[i];

    sort(rrng(p));
    sort(rrng(q));
    sort(rrng(r));

    ll P = x - 1;
    ll Q = y - 1;
    ll R = 0;

    rep(i, c) {
        if (P >= 0 && Q >= 0) {
            if (p[P] < q[Q]) {
                if (p[P] < r[R]) {
                    p[P] = r[R];
                    P--;
                    R++;
                } else {
                    break;
                }
            } else {
                if (q[Q] < r[R]) {
                    q[Q] = r[R];
                    Q--;
                    R++;
                } else {
                    break;
                }
            }
        } else {
            if (P >= 0) {
                if (p[P] < r[R]) {
                    p[P] = r[R];
                    P--;
                    R++;
                } else {
                    break;
                }
            } else if (Q >= 0) {
                if (q[Q] < r[R]) {
                    q[Q] = r[R];
                    Q--;
                    R++;
                } else {
                    break;
                }
            }
        }
    }

    ll sum = 0;

    rep(i, x)
        sum += p[i];

    rep(i, y)
        sum += q[i];

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 2560
using System.Collections.Generic;
using System.Linq;
using static System.Console;
    class Program {
        static void Main(string[] args) {
            var N = int.Parse(ReadLine());
            HashSet<int> list = new HashSet<int>();
            for (int i = 0; i < N; i++) {
                var p = int.Parse(ReadLine());
                if (!list.Add(p)) {
                    list.Remove(p);
                }
            }
            WriteLine(list.Count());
            // ReadKey();
        }
    }

Measured memory_bytes: 19424
import java.util.*;
public class Main { 
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long o=0;
        long h=sc.nextLong();
        long c=1;
        while(h>=1){
            o+=c;
            c*=2;
            h/=2;
        }
       //PriorityQueue<Long> pq = new PriorityQueue<>(Collections.reverseOrder());
      
      
      System.out.println(o);
    }
}

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


#define li          long long int
#define uli         unsigned long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n;
PI a[22][22];
li aa[22];

inline bool check(const bitset<22>& bs) {
    rin{
        if (!bs[i])continue;
        rep(j, aa[i]) {
            if (a[i][j].S == 1) {
                if (!bs[a[i][j].F]) {
                    return false;
                }
            } else {
                if (bs[a[i][j].F]) {
                    return false;
                }
            }
        }
    }
    return true;
}

int main() {
    cin >> n;
    rin{
        cin >> aa[i];
        rep(j, aa[i]) {
            cin >> a[i][j].F >> a[i][j].S;
            a[i][j].F--;
        }
    }

    li res = 0;
    rep(i, bit(n)) {
        bitset<22> bs(i);
        if (check(bs)) {
            res = max(res, (li)bs.count());
        }
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3644
A = [list(map(int,input().split())) for _ in range(3)]
A.sort()

for i in range(1,5):
    count = 0
    for j in range(3):
        if i in A[j]:
            count += 1
    if count == 3:
        print('NO')
        break
else:
    print('YES')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
#define ll long long
#define int long long
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define mod 1000000007
typedef pair<ll,ll> pll;
#define F first
#define S second
#define printer(v) for(auto f: v) cout<<f<<" "
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define ipair pair<int,int>
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    // cout << setprecision(12) << fixed;

    int n,k; cin>>n>>k;
    vector<int> v(n, 0);
    while(k--){
    	int d; cin>>d;
    	while(d--){
    		int a; cin>>a; a--;
    		v[a]++;
    	}
    }
    int ans=0;
    for(auto f: v) if(f==0)ans++;
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int main(){
    int n;
    int y,m,d;
    int yy,mm,dd;
    cin >> n;

    for(int i=0;i<n;i++){
        cin >> y >> m >> d;
        yy = 1000;
        mm = 1;
        dd = 1;
        while(yy-1 != y){
            if((yy-1)%3 == 0){
                dd += 200;
            }else{
                dd += 195;
            }
            yy--;
        }
        mm = 10;
        if((yy-1)%3 == 0){
            dd += 20;
        }else{
            dd += 19;
        }
        yy--;
        while(mm != m){
            if((yy % 3) == 0){
                dd += 20;
            }else{
                if((mm-1)%2 == 0){
                    dd += 19;
                }else{
                    dd += 20;
                }
            }
            mm--;
        }
        cout << dd - d << endl;
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>
#include <set>
#include <bitset>
#include <limits>

using namespace std;

#define ll long long

int main(void){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for(ll i = 0;i < n;++i)     cin >> a[i];

    int flag = 1;
    for(ll i = k;i < n;++i){
        if(a[i] <= a[i-k]){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 4820
use std::io::Read;
use std::cmp::max;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let d = iter.next().unwrap().parse().unwrap();
    let g:i32 = iter.next().unwrap().parse().unwrap();
    let mut p = Vec::<i32>::new();
    let mut c = Vec::<i32>::new();
    for _ in 0..d{
        p.push(iter.next().unwrap().parse().unwrap());
        c.push(iter.next().unwrap().parse().unwrap());
    }

    let mut ans = p.iter().sum();
    for i in 0..1<<d{
        let mut all_solve:i32 = 0;
        let mut score:i32 = 0;
        for j in (0..d).filter(|j| i>>j&1==1){
            all_solve += p[j];
            score += c[j] + 100*p[j]*(1+j as i32);
        }
        if score >= g {
            ans = min(ans,all_solve);
        } else {
            for k in (0..d).filter(|k| i>>k&1==0){
                let res_solve = max((g - score -100) /100 /(1+k as i32) +1,0);
                if res_solve < p[k] {
                    ans = min(ans,res_solve+all_solve);
                }
            }
        }
    }
    println!("{}",ans);
}


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

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

public class Solver
{
	private int N;
	private int A;
	private int B;
	private int C;
	private string[] s;
	private List<char> ans = new List<char>();

	public void Solve()
	{
		N = GetInt();
		A = GetInt();
		B = GetInt();
		C = GetInt();
		s = GetStrings(N);

		if(dfs(0, A, B, C))
		{
			WriteLine("Yes");
			ans.Reverse();
			WriteLine(string.Join("\n", ans));
		}
		else
		{
			WriteLine("No");			
		}
	}

	private bool dfs(int p, int a, int b, int c)
	{
		if(p == N)
			return true;

		var code = s[p].Select(x => (int)(x - 'A')).ToArray();
		for(int i = 0; i < 2; i++)
		{
			var cnt = new int[3] { a, b, c };
			cnt[code[i]]++;
			cnt[code[i ^ 1]]--;
			if(cnt.Any(x => (x < 0)))
				continue;

			if(dfs(p + 1, cnt[0], cnt[1], cnt[2]))
			{
				ans.Add((char)(code[i] + 'A'));
				return true;
			}
		}
		return false;
	}
}

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

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

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

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

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

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

Measured memory_bytes: 61652
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>

int cnt = 0;
int m   = 0;
std::vector<int> g;

void insertionSort(int a[], int n, int g)
{
    for (int i = g; i < n; ++i) {
        int v = a[i];
        int j = i - g;
        while (j >= 0 && a[j] > v) {
            a[j + g] = a[j];
            j = j - g;
            cnt++;
        }
        a[j+g] = v;
    }
}

void shellSort(int a[], int n)
{

    int v = 1;
    while (true) {
        g.push_back(v);
        v *= 4;
        if (n <= v) {
            break;
        }
    }

    m = g.size();

    for (int i = 0; i < m; ++i) {
        insertionSort(a, n, g[m - 1 - i]);
    }

}

int main()
{
    int n;
    std::cin >> n;
    int a[n];
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i];
    }

    shellSort(a, n);

    std::cout << m << std::endl;

    for (int i = 0; i < m; ++i) {
        std::cout << g[m-1-i];
        if (i == (m-1)) {
            std::cout << std::endl;
        } else {
            std::cout << " ";
        }
    }

    std::cout << cnt << std::endl;

    for (int i = 0; i < n; ++i) {
        std::cout << a[i] << std::endl;
    }

    return 0;
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

map<ll, int> factorize(ll n)
{
    map<ll, int> mp;
    for (ll i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            mp[i]++; n /= i;
        }
    }
    if (n != 1) mp[n] = 1;
    return mp;
}

vector<ll> div(ll n)
{
    vector<ll> ret;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.emplace_back(i);
            if (i * i != n) ret.emplace_back(n/i);
        }
    }
    sort(ret.begin(), ret.end());
    // for (auto &e: ret) cout << e << endl;
    return ret;
}

inline ll mpow(ll n, ll k) {
    ll res = 1;
    while (k--) res *= n;
    return res;
}

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

    ll n; cin >> n;
    ll res1 = 1;
    auto f1 = factorize(n - 1);
    for (auto e: f1) res1 *= (e.second + 1);
    res1--;
    auto f2 = div(n);
    ll res2 = 0;
    for (auto &e: f2) {
        if (e == 1) continue;
        ll tmp = n;
        while (tmp % e == 0) tmp /= e;
        if (tmp % e == 1) res2++;
    }
    cout << res1 + res2 << endl;
    return 0;
}


Measured memory_bytes: 384