akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <ctype.h>
#include <deque>
#include <cstring>
#include <set>
#include <bitset>
#include <map>
#include <chrono>
#include <random>
#include <unordered_map>
#include <stdio.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef std::vector<int> vi;
typedef std::vector<bool> vb;
typedef std::vector<string> vs;
typedef std::vector<double> vd;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<int> > vvi;
typedef vector<vll> vvll;
typedef std::vector<std::pair<int, int> > vpi;
typedef vector<vpi> vvpi;
typedef std::pair<int, int> pi;
typedef std::pair<ll, ll> pll;
typedef std::vector<pll> vpll;

const long long mod = 1000000007;
const unsigned gen_seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937_64 gen(gen_seed);

#define all(c) (c).begin(),(c).end()
#define forn(i, a, b) for(int i = a; i < b; i++)
#define read(x) scanf("%d", &x)
#define readv(x, n) vi x(n); forn(i,0,n) scanf("%d", &x[i])

#define pb push_back
#define mp make_pair


int main()
{

    int n;
    scanf("%d", &n);
    readv(a,n);
    if(a[n-1] != 2) {
        cout<<-1;
        return 0;
    }
    ll l = 1;
    ll r = 1;
    for(int i = n-2; i>=0; i--) {
        if(l>r) continue;
        ll x = a[i];
        ll al = l*a[i+1];
        ll ar = (r+1)*a[i+1];
        l = (al + x-1)/x;
        r = (ar + x-1)/x - 1;
    }
    if(l>r) {
        cout<<-1;
        return 0;
    }
    cout<< l*a[0]<< ' '<<r*a[0] + a[0]-1;
    
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  string str;
  cin >> str;
  int q,i;
  cin >> q;
  string s1,s2;
  int a,b;
  for(i=0;i<q;i++){
    //cout << str << endl;
    cin >> s1 >> a >> b;
    if(s1=="print"){
      cout << str.substr(a,b-a+1) << endl;
    }else if(s1=="reverse"){
      string s3=str.substr(a,b-a+1);
      reverse(s3.begin(),s3.end());
      str=str.substr(0,a)+s3+str.substr(b+1,str.size()-a-1);
    }else{
      cin >> s2;
      str=str.substr(0,a)+s2+str.substr(b+1,str.size()-a-1);
    }
  }
  return 0;
}


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

int main(){
    int n;
    while(cin >> n, n){
        int x[n], y[n];
        x[0] = y[0] = 0;
        
        int a, b;
        for(int i = 1; i < n; i++){
            cin >> a >> b;
            x[i] = x[a], y[i] = y[a];
            if(b == 0)  x[i]--;
            if(b == 1)  y[i]--;
            if(b == 2)  x[i]++;
            if(b == 3)  y[i]++;
        }

        int lx = 0, rx = 0, uy = 0, dy = 0;
        for(int i = 0; i < n; i++){
            lx = min(lx, x[i]);
            rx = max(rx, x[i]);
            uy = max(uy, y[i]);
            dy = min(dy, y[i]);
        }

        cout << rx-lx+1 << " " << uy-dy+1 << endl;
    }
    return 0;
}


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

bool comp(pair<int,int> a, pair<int,int> b){return a.second < b.second;}

int main(void){
    
    int N,M;
    
    cin >> N >> M;
    
    vector<pair<int,int>> v;
    v.resize(M);
    for(int i = 0; i < M;i++)cin >> v[i].first >> v[i].second;
    
    sort(v.begin(),v.end(),comp);
    int mx = 0;
    int cont = 0;

    for(auto u:v){
        
        if(mx <= u.first){
            cont++;
            mx = u.second;
        }
    }
    
    cout << cont << endl;
    return 0;
    
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define mod 1000000007
#define MOD 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 1e18

const int maxn = 1000000 + 10;

void add(int &a, int b){
    a += b;
    if (a >= mod)
        a -= mod;
}

int fak[maxn];
int ifak[maxn];

int modpow(int a, int b){
    int c = 1;

    while (b){
        if (b & 1)
            c = 1LL * c * a % mod;
        a = 1LL * a * a % mod;
        b >>= 1;
    }

    return c;
}

int comb(int n, int k){
    return 1LL * fak[n] * ifak[k] % mod * ifak[n - k] % mod;
}


bool isreachable(pair<int,int>p1,pair<int,int>p2)
{
    if(p1.first>=p2.first and p1.second>=p2.second)
        return true;
    return false;
}

int main()
{
    fastio;
    fak[0] = 1;
    for (int i = 1; i < maxn; ++i)
        fak[i] = 1LL * fak[i-1] * i % mod;
        
    ifak[maxn-1] = modpow(fak[maxn-1], mod-2);
    
    for (int i = maxn-2; i >= 0; --i)
        ifak[i] = 1LL * ifak[i + 1] * (i+1) % mod;
    int h,w,n;
    cin >> h >> w >> n;
    vector<pair<int,int> >v(n);
    for(int i=0;i<n;i++)
    {
        cin >> v[i].first >> v[i].second;
        v[i].first-=1;
        v[i].second-=1;
    }
    vector<pair<pair<int,int>,int> >sv(n);
    for(int i=0;i<n;i++)
    {
        sv[i].first.first=min(v[i].first,v[i].second);
        sv[i].first.second=max(v[i].first,v[i].second);
        sv[i].second=i;
    }
    sort(sv.begin(),sv.end());
    vector<int>dp(n);
    for(int i=0;i<n;i++)
    {
        int ind=sv[i].second;
        int r=v[ind].first,c=v[ind].second;
        int nw=comb(r+c,r);
        for(int j=0;j<i;j++)
        {
            int ind2=sv[j].second;
            if(isreachable(v[ind],v[ind2]))
            {
                int rd=v[ind].first-v[ind2].first,cd=v[ind].second-v[ind2].second;
                int ways=comb(rd+cd,rd);
                int t=dp[j]*1LL*ways%mod;
                nw=(nw-t)%mod;
                nw=(nw+mod)%mod;  
            }
        }
        dp[i]=nw;
    }
    // for(int i=0;i<n;i++)
    //     cout << dp[i] << ' ';
    // cout << endl;
    int nw=comb(h+w-2,h-1);
    //cout << nw << endl;
    pair<int,int>p=make_pair(h-1,w-1);
    for(int i=0;i<n;i++)
    {
        int ind=sv[i].second;
        //cout << v[ind].first << " " << v[ind].second << endl;
        int rd=p.first-v[ind].first,cd=p.second-v[ind].second;
        //cout << rd << " " << cd << endl;
        int ways=comb(rd+cd,rd);
        int t=dp[i]*1LL*ways%mod;
        nw=(nw-t)%mod;
        nw=(nw+mod)%mod; 
    }
    cout << nw << endl;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FORD(i,b,a) for (int i = (int)(b) - 1; i >= a; --i)
#define REP(i,N) FOR(i,0,N)
#define st first
#define nd second
#define pb push_back

typedef pair<int, int> PII;
typedef long long LL;

LL A[222222];
LL needed[222222];

LL result[222222];
int main() {
  int N;
  scanf("%d", &N);
  REP(i,N) scanf("%lld", &A[i]);
  vector<PII> v;
  REP(i,N) v.push_back(PII(A[i], i));
  sort(v.rbegin(), v.rend());

  LL cnt = 0;
  LL sum = 0;
  REP(i,N) {
    needed[v[i].nd] = sum - cnt * v[i].st;
    ++cnt;
    sum += v[i].st;
  }

  int maxi = 0;
  REP(i,N) {
    if (A[i] <= maxi) continue;
    result[i] = sum - needed[i];
    sum -= result[i];
    maxi = A[i];
  }
  REP(i,N) printf("%lld\n", result[i]);
}


Measured memory_bytes: 5236
# 解説を参考に作成


def solve(N, As, Bs):
    As.sort()
    Bs.sort()
    ans = 0
    # N が奇数の場合
    if N % 2 == 1:
        x = (N + 1) // 2 - 1
        ans = Bs[x] - As[x] + 1
    # N が偶数の場合
    else:
        lowx = N // 2 - 1
        highx = N // 2
        ans = (Bs[lowx] + Bs[highx]) - (As[lowx] + As[highx]) + 1
    print(ans)
    pass


if __name__ == '__main__':
    N = int(input())
    A = []
    B = []
    for _ in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    solve(N, A, B)


Measured memory_bytes: 25416
#include<bits/stdc++.h>
using namespace std;
long long a,b;
int main(){
	cin>>a>>b;
	while(a--){
		char c[101];
		for(int i=0;i<b;i++)
			cin>>c[i];
		for(int i=0;i<b;i++)
			cout<<c[i];
		cout<<endl;
		for(int i=0;i<b;i++)
			cout<<c[i];
		cout<<endl;
	}
	return 0;
}

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

int top,N[1000];

void push(int x){
  N[++top]=x;
}

int pop(){
  top--;
  return N[top+1];
}

int main(){
  
  int x,y,z;
  char s[100];

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      y=pop();
      z=pop();
      push(y+z);
    } else if ( s[0] == '-' ){
      z=pop();
      y=pop();
      push(y-z);
    } else if ( s[0] == '*' ){
      y=pop();
      z=pop();
      push(y*z);    
} else {
      push(atoi(s));

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



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

int bubbleSort(int A[],int N) {
    int sw=0;
    bool f=true;
    for (int i=0; f; i++) {
        f=false;
        for (int j=N-1; j>=i; j--) {
            if (A[j]<A[j-1]) {
                swap(A[j],A[j-1]);
                f=true;
                sw++;
            }
        }
    }
    return sw;
}
int main() {
    int N;
    cin >> N;
    int A[N];
    for (int i=0; i<N; i++) {
        cin >> A[i];
    }
    int sw=bubbleSort(A,N);
    for (int i=0; i<N; i++) {
        printf("%s%d",((i==0)?"":" "),A[i]);
    }
    printf("\n");
    printf("%d\n",sw);
    return 0;
}

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

using namespace std;

const int maxn = 5e5 + 1;
int dp[maxn][3];
const int INF = 2e9;

int main()
{
    #ifdef DEBUG
    freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<pair<int, int> > segs;
    int ls = -1;
    for (int i = 0; i < n; i++){
        if (ls == -1 && s[i] == '1'){
            ls = i;
        }
        if (ls != -1 && s[i] == '0'){
            segs.push_back({ls, i - 1});
            ls = -1;
        }
    }
    if (ls != -1){
        segs.push_back({ls, n - 1});
    }
    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    int m = segs.size();
    for (int i = 1; i <= m; i++){
        dp[i][0] = max(dp[i - 1][0], max(dp[i - 1][1], dp[i - 1][2]));
        dp[i][1] = -INF;
        dp[i][2] = -INF;
        int l = segs[i - 1].first;
        int r = segs[i - 1].second;
        if (l - 2 >= 0 && s[l - 2] == '1'){
            dp[i][1] = max(dp[i][1], dp[i - 1][1] + r - l);
            dp[i][1] = max(dp[i][1], max(dp[i - 2][0], dp[i - 2][1]) + r - l + 1);
            if (i >= 3 && segs[i - 3].second + 2 < l - 2){
                dp[i][1] = max(dp[i][1], dp[i - 2][2] + r - l + 1);
            }
        }
        if (r + 2 < n && s[r + 2] == '1'){
            dp[i][2] = max(dp[i][2], max(dp[i - 1][0], dp[i - 1][1]) + (r - l + 1));
            dp[i][2] = max(dp[i][2], dp[i - 1][2] + r - l);
        }
    }
    cout << max(dp[m][0], max(dp[m][1], dp[m][2]));
    return 0;
}



Measured memory_bytes: 3736
d, g = map(int, input().split())
p = [0 for _ in range(d)]
c = [0 for _ in range(d)]
for i in range(d):
    p[i], c[i] = map(int, input().split())
ans = -1
for pat in range(2**d):
    score = 0
    now = 0
    l = []
    for i in range(d):
        if pat & (2 ** i):
            l.append(i)
            score += 100*(i+1)*p[i]+c[i]
            now += p[i]
    if score < g:
        maxidx = None
        for i in range(d-1, -1, -1):
            if not i in l:
                maxidx = i
                break
        if maxidx == None:
            continue
        if score+100*(maxidx+1)*(p[maxidx]-1) < g:
            continue
        for i in range(p[maxidx]-1):
            score += 100*(maxidx+1)
            now += 1
            if score >= g:
                break
    if ans == -1 or ans > now:
        ans = now
print(ans)

Measured memory_bytes: 3064
S = input()
T = input()
if S[0] == T[0] and S[1] == T[1] and S[2] == T[2]:
    print(3)
elif S[0] == T[0] and S[1] == T[1]:
    print (2)
elif S[0] == T[0] and S[2] == T[2]:
    print (2)
elif S[1] == T[1] and S[2] == T[2]:
    print (2)
elif S[0] == T[0] or S[1] == T[1] or S[2]==T[2]:
    print (1)
else:
    print (0)

Measured memory_bytes: 3064
from itertools import groupby


N = int(input())
A = list(map(int, input().split()))
groups = groupby(A)
A_uniq = [g[0] for g in groups]
# print(A_uniq)
N_uniq = len(A_uniq)

ptr = 1
ans = 1
flg = None
while ptr < N_uniq:
    if A_uniq[ptr] > A_uniq[ptr - 1]:
        if flg is None:
            flg = True
        else:
            if flg:
                ptr += 1
                continue
            else:
                ans += 1
                flg = None
    else:
        if flg is None:
            flg = False
        else:
            if flg:
                ans += 1
                flg = None
            else:
                ptr += 1
                continue
    ptr += 1
print(ans)


Measured memory_bytes: 14100
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int k = sc.nextInt();
    int ans = 0;
    int p = 1;
    for(int i = Math.min(a, b); i >= 1; i--) {
      if(((a % i) == 0) && ((b % i) == 0)) {
        if(p == k) {
          ans = i;
        } else {
          
        }
        p++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23764
#include<iostream>
#include<algorithm>
using namespace std;
static const int INFTY = (1 << 21);
int main(){
	int t[105][105];int c[105][105];
	int n,m,a,b,cost,time,kk,p,q,r;
	while(cin >> n >> m,n,m){
		for(int i=1;i<105;i++){
			for(int j=1;j<105;j++){
				t[i][j] = c[i][j] = INFTY;
			}
		} 
		for(int i = 0;i < n;i++){
			cin >> a >> b >> cost >> time;
			t[a][b] = time;
			t[b][a] = time;
			c[a][b] = cost;
			c[b][a] = cost;
		}
		for(int k=1;k<=m;k++){
			for(int i=1;i<=m;i++){
				if(t[i][k] == INFTY) continue;
				for(int j=1;j<=m;j++){
					if(t[i][k] == INFTY) continue;
					t[i][j] = min(t[i][j],t[i][k]+t[k][j]);
					c[i][j] = min(c[i][j],c[i][k]+c[k][j]);
				}
			}
		}
		cin >>  kk;
		for(int i=0;i<kk;i++){
			cin >> p >> q >> r;
			if(r == 0) cout << c[p][q] << endl;
			else cout << t[p][q] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1244
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

int D;
int c[32];
int s[512][32];
int ans[512];

void inp(){
    cin>>D;
    for(int i=1;i<=26;i++){
        cin>>c[i];
    }
    for(int i=1;i<=D;i++){
        for(int j=1;j<=26;j++){
            cin>>s[i][j];
        }
    }
}

void ans_inp(){
    for(int i=1;i<=D;i++){
        cin>>ans[i];
    }
}

void ans_ran(){
    for(int i=1;i<=D;i++){
        ans[i]=rand()%26+1;
    }
}

void man_disp(){
    int l[32]={0};
    int man=0;
    for(int i=1;i<=D;i++){
        int n=ans[i];
        l[n]=i;
        man+=s[i][n];
        for(int j=1;j<=26;j++){
            man-=c[j]*(i-l[j]);
        }
        cout<<man<<endl;
    }
}

void ans_disp(){
    for(int i=1;i<=D;i++){
        cout<<ans[i]<<endl;
    }
}

signed main(){
    inp();
    ans_ran();
    ans_disp();
    return 0;
}



Measured memory_bytes: 3288
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	multiset<int> arr={a,b,c};
	if(arr.count(5) == 2 && arr.count(7) == 1)cout<<"YES";
	else cout<<"NO";	
	return 0;
	}


Measured memory_bytes: 3496
fun main(args: Array<String>) {
    codefestival2017quala_b()
}

fun codefestival2017quala_b() {
    val (H, W, k) = readLine()!!.split(" ").map { it.toInt() }

    for (h in 0..H) {
        for (w in 0..W) {
            val blackCell = H * w + W * h - (w * h) * 2
            if (blackCell == k) return println("Yes")
        }
    }

    println("No")
}


Measured memory_bytes: 37928
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define YES cout << "YES" << endl
#define NO  cout << "NO"  << endl
#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX powl(2, 63)-1
using namespace std;
typedef long long ll;



int main(){
  int ab, bc, ca; cin >> ab >> bc >> ca;
  cout << (ab*bc*ca/2/(max(ab, max(bc, ca)))) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define bs binary_search
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ipr pair<ll,ll>
#define ps push_back
#define fs first
#define sc second
#define mkp make_pair
#define mod 1000000007
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,r,n,a,b,m;
	cin>>n>>a>>b;
	ll h[n],s=0;
	for(i=0;i<n;i++){
		cin>>h[i];
		if(h[i]>s){
			s=h[i];
		}
	}
	l=1; r=s/b+1;

	ll an=-1;
	while(r>=l){
		//cout<<l<<" "<<r<<endl;
		m=(r+l)/2;
		ll c=0;
		for(i=0;i<n;i++){
			k=max((ll)0,(h[i]-m*b));
			if(k%(a-b)==0) c+=(k/(a-b));
			else c+=(k/(a-b)+1);
		}
		if(c<=m){
			an=m;
			r=m-1;
		}
		else l=m+1;
	}
	cout<<an;
	return 0;
}


Measured memory_bytes: 1024
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2019

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

struct Route {
	int d;
	int p;
	bool operator<( const Route& right ) const {
			return p > right.p;
	}
};

int main()
{
	int N,M;

	while(cin >> N >> M)
	{
		if(N == 0 && M == 0){ break; }
		vector<Route> routes(N);
		int D,P;
		rep(i,N){
			cin >> D >> P;
			routes[i] = {D,P};
		}
		
		sort(ALL(routes));

		rep(i,N)
		{
			if(routes[i].d == 0){
				//Do Nothing...
			}
			else
			{
				if(routes[i].d <= M)
				{
					M -= routes[i].d;
					routes[i].d = 0;
				}
				else
				{
					routes[i].d -= M;
					M = 0;
					break;
				}
			}
		}

		int total=0;
		rep(i,N){
			total += routes[i].d * routes[i].p;
		}

		cout << total << endl;
	}
	return 0;
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
#define PI 3.14159265358979323846
using namespace std;
using ll = long long;
const int INF = -100100100;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i,n)cin >> l[i];
    ll ans = 0;
    sort(l.begin(),l.end());
    for(int i=n-1; i>=2;--i){
        int a = l[i];
        for(int j=i-1; j>=1;--j){
            int b = l[j];
            for(int k=j-1;k>=0;--k){
                int c = l[k];
                bool chk=true;
                if(a>=b+c)chk=false;
                if(b>=a+c)chk=false;
                if(c>=b+a)chk=false;
                if(chk)++ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

const int MOD=1e9+7;

ll mod(ll x){
    return (x%MOD + MOD)%MOD;
}

ll mul(ll a , ll b){
    return mod(mod(a)*mod(b));
}

    void solve(){
        int n,k;
        cin>>n>>k;
        vector<ll>pos;
        vector<ll>neg;
        for(int i=0;i<n;i++){
            int x;
            cin>>x;
            if(x>0)
                pos.push_back(x);
            else
                neg.push_back(x);
        }
        ll ans=1;
        if((int)pos.size()){
            if(k%2){
                sort(pos.begin(),pos.end());
                ans=mul(ans,pos.back());
                pos.pop_back();
                --k;
            }
            vector<ll>ok;
            sort(pos.begin(),pos.end(),greater<>());
            sort(neg.begin(),neg.end());
            for(int i=0;i+1<(int)pos.size();i+=2)
                ok.push_back(pos[i]*pos[i+1]);
            for(int i=0;i+1<(int)neg.size();i+=2)
                ok.push_back(neg[i]*neg[i+1]);
            if((int)pos.size()%2 && (int)neg.size()%2)
                ok.push_back(pos.back()*neg.back());
            sort(ok.begin(),ok.end(),greater<>());
            for(int i=0;i<(k/2);i++)
                ans=mul(ans,ok[i]);
            cout<<ans;
        }
        else{
            sort(neg.begin(),neg.end());
            if(k%2)
                reverse(neg.begin(),neg.end());
            for(int i=0;i<k;i++)
                ans=mul(ans,neg[i]);
            cout<<ans;
        }
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
        int t=1;
        for(int i=1;i<=t;i++){
            solve();
        }
        return 0;
    }


Measured memory_bytes: 6604
f=lambda:map(int,input().split())
n,k=f()
g=[[] for _ in range(n)]
for _ in range(n-1):
  a,b=f()
  g[a-1]+=[b-1]
  g[b-1]+=[a-1]
l=[0]*n
for _ in range(k):
  p,x=f()
  l[p-1]+=x
u=[0]*n
q=[0]
while q:
  v=q.pop()
  u[v]=1
  for c in g[v]:
    if u[c]: continue
    l[c]+=l[v]
    q+=[c]
print(*l)

Measured memory_bytes: 56284
#include "bits/stdc++.h"
using namespace std;

#define int long long

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


signed main(void) {
  int num; // num
  num = 0; // count, result
  // num = numeric_limits<int>::min(); // max
  // num = numeric_limits<int>::max(); // min
  int N;
  // int M;
  // array<int, 100000> A;;
  string S;
  // string T;

  cin >> S;

  for (auto it = S.begin(); it < S.end(); ++it) {
    if (*it == '1') *it = '9';
    else if (*it == '9') *it = '1';
  }

  cout << S << endl;
  
  
  return 0;
}


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

string toString(ll a){
  stringstream ss;
  ss << a;
  return ss.str();
}

string fizzbuzz(ll a){
  if(a%15==0)return "FizzBuzz";
  if(a%3==0)return "Fizz";
  if(a%5==0)return "Buzz";
  return toString(a);
}

ll multi(ll x, ll k){
  return (x-1)/k;
}

ll multi(ll l, ll r, ll k){
  return multi(r,k) - multi(l,k);
}

ll total_len(ll l, ll r, ll k){
  ll m3 = multi(l,r,3);
  ll m5 = multi(l,r,5);
  ll m15 = multi(l,r,15);
  return (m3-m15)*4 + (m5-m15)*4 + m15*8 + (r-l-m3-m5+m15)*k;
}

ll pos(ll a){
  ll d = 1, k = 1, res = 0;
  while(d*10<a){
    res += total_len(d,d*10,k);
    d *= 10; k++;
  }
  res += total_len(d,a,k);
  return res;
}

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

  ll l = 1, r = 1e18;
  while(r-l>1){
    ll m = (l+r)/2;
    if(pos(m) < s)l = m;
    else r = m;
  }

  string res;
  for(ll i=l;res.size()<50;i++){
    res += fizzbuzz(i);
  }
  ll start = s-pos(l)-1;
  cout << res.substr(start,20) << endl;
}

Measured memory_bytes: 1224
/* � Ashiq Uddin Pranto
   Department of Computer Science and Engineering
   BATCH 27
   University Of Rajshahi,Bangladesh
*/
#include<bits/stdc++.h>

#define ll long long
#define ld long double
#define FOR(x,y) for(ll i=x;i<=y;i++)
#define pb(x) push_back(x)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define matrix(x) vector<vector<x>>
#define vss vector<string>
#define PI (2*acos(0.0))
#define sqr(x) ((x)*(x))
#define sf(a)   scanf("%d",&a)
#define sfl(a)  scanf("%lld",&a)
#define sff(a,b)    scanf("%d %d",&a,&b)
#define sffl(a,b)   scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)    scanf("%lld %lld %lld",&a,&b,&c)
#define ms(a,b) memset(a, b, sizeof(a))
#define ff  first
#define ss  second
#define lcm(a, b)   ((a)*((b)/__gcd(a,b)))
#define all(a)  a.begin(),a.end()
#define readfile freopen("input.txt","r",stdin);
#define writefile freopen("output.txt","w",stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define gap " "
#define mx 104
#define inf (ll)1e9
#define WHITE 1
#define GRAY 2
#define BLACK 3
#define EMPTY_VALUE -1
#define mod 1000000007
#define MOD(a,b) (a%b + b)%b

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


int main()
{
    //fastio
    double d,s,t;
    cin>>d>>t>>s;
    if((d/(s+0.0))<=t) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 3740
#include<cstdio>
#include<string>
#include<iostream>
using namespace std;

int main()
{
	string s;
	int t;
	while(getline(cin,s))
	{
		for(int i=0;i<s.size();i=i+2)
		cout<<s[i];
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 512
import math
from collections import deque
from collections import defaultdict
import itertools as it

#自作関数群
def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()
def factorization(n):
  res = []
  if n%2==0:
    res.append(2)
  for i in range(3,math.floor(n//2)+1,2):
    if n%i==0:
      c = 0
      for j in res:
        if i%j==0:
          c=1
      if c==0:
        res.append(i)
  if len(res)==0:
    res = [n]
  return res
def fact2(n):
  p = factorization(n)
  res = []
  for i in p:
    c=0
    z=n
    while 1:
      if z%i==0:
        c+=1
        z/=i
      else:
        break
    res.append([i,c])
  return res
def fact(n):#階乗
  ans = 1
  m=n
  for _i in range(n-1):
    ans*=m
    m-=1
  return ans
def comb(n,r):#コンビネーション
  if n<r:
    return 0
  l = min(r,n-r)
  m=n
  u=1
  for _i in range(l):
    u*=m
    m-=1
  return u//fact(l)
def combmod(n,r,mod):
  return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
  r=copyQueue(q)
  ans=[0]*r.qsize()
  for i in range(r.qsize()-1,-1,-1):
    ans[i] = r.get()
  print(ans)
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1]*n

  def find(self, x): # root
    if self.parents[x]<0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]

  def union(self,x,y):
    x = self.find(x)
    y = self.find(y)

    if x==y:
      return

    if self.parents[x]>self.parents[y]:
      x,y = y,x

    self.parents[x]+=self.parents[y]
    self.parents[y]=x

  def size(self,x):
    return -1*self.parents[self.find(x)]

  def same(self,x,y):
    return self.find(x)==self.find(y)

  def members(self,x): # much time
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i)==root]

  def roots(self):
    return [i for i,x in enumerate(self.parents) if x<0]

  def group_count(self):
    return len(self.roots())

  def all_group_members(self):
    return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
  x = 1
  zero = "0"*n
  ans = []
  ans.append([0]*n)
  for i in range(2**n-1):
    ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
    x+=1
  return ans;
def arrsSum(a1,a2):
  for i in range(len(a1)):
    a1[i]+=a2[i]
  return a1
def maxValue(a,b,v):
  v2 = v
  for i in range(v2,-1,-1):
    for j in range(v2//a+1): #j:aの個数
      k = i-a*j
      if k%b==0:
        return i
  return -1
def copyQueue(q):
  nq = queue.Queue()
  n = q.qsize()
  for i in range(n):
    x = q.get()
    q.put(x)
    nq.put(x)
  return nq
def get_sieve_of_eratosthenes(n):
  data = [2]
  #data = [0,0,0]
  for i in range(3,n+1,2):
    data.append(i)
    data.append(0)
  for i in range(len(data)):
    interval = data[i]
    if interval!=0:
      for j in range(i+interval,n-1,interval):
        data[j] = 0
  ans = [x for x in data if x!=0]
  #ans = data[:]
  return ans


a,b = readInts()

#print(a+b)
print(a*b)

Measured memory_bytes: 9576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)

bool isACGT(char arg) {
    if(arg == 'A' || arg == 'C' || arg == 'G' || arg == 'T') {
        return true;
    } else {
        return false;
    }
}

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

    ll ans = 0;
    ll cnt = 0;
    REP(i, S.length()) {
        if(isACGT(S[i])) {
            ++cnt;
        } else {
            cnt = 0;
        }
        if(cnt > ans) {
            ans = cnt;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3624
A,B,C = map(int,input().split())
K = int(input())
state = "No"
for i in range(K+1):
    for j in range(K+1-i):
        for k in range(K+1-i-j):
            a = A*(2**i)
            b = B*(2**j)
            c = C*(2**k)
            if a < b and b < c:
                state = "Yes"
                break
print(state)

Measured memory_bytes: 61776
import java.util.*;
import java.io.*;

class Main {

	void solve () {

		int x = in.nextInt(), a = in.nextInt();
		out.println(x<a ? 0 : 10);
		
	}

	public static PrintWriter out = new PrintWriter(System.out);
	public static Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

}

Measured memory_bytes: 23252
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	add := a + b
	sub := a - b
	multiple := a * b

	ans := add
	if ans < sub {
		ans = sub
	}
	if ans < multiple {
		ans = multiple
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
import sys

n = int(input())
a = list(map(int,input().split()))

if 0 in a :
  print(0)
  sys.exit()

ans = 1
for i in range(n) :
  ans *= a[i]
  if ans > 10**18 :
    ans = -1
    break
    
print(ans)


Measured memory_bytes: 21644
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        long b = sc.nextLong();
        long n = sc.nextLong();
        long ans = 0L;
        if(n < b){
            ans = a * n /b;
        }else{
            ans = a*(b-1)/b;
        }
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 35724
n=int(input())  #数値入力 「N」だけの入力のとき
#n= 5  #数値入力 「N」だけの入力のとき
c=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
#c=[5, 2, 3, 4, 1]
d=[i for i in range(1,n+1)]
f=0
for i in range(n):
    if c[i]-d[i]:
        f+=1
#print(f)
if f == 0 or f == 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;

// graph template
template<typename T>
class edge{
    public:
        int src, to; T cost;

        edge(int to, T cost): src(-1), to(to), cost(cost){}
        edge(int src, int to, T cost): src(src), to(to), cost(cost){}
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using AdjacencyList = vector<Edges<T>>;
template<typename T>
using Matrix = vector<vector<T>>;

#ifndef GCD
#define GCD
// solve ax+by=gcd(a, b)
// return gcd(a, b)
template<typename T>
T gcd(const T a, const T b, T* const px = nullptr, T* const py = nullptr){
	if(py == nullptr){
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	T d = a;
	if(b != 0){
		d = gcd(b, a % b, py, px);
		*py -= (a / b) * *px;
	}else{
		*px = 1; *py = 0;
	}
	return d;
}
#endif


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

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

    ll res = 1;
    for(int i = 0; i < N; i++){
        res /= gcd(T[i], res);
        res *= T[i];
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int main()
{
	int x,y;
	while(scanf("%X%X",&x,&y)!=EOF)
	{
		if(x>y) printf(">\n");
		else if(x<y) printf("<\n");
		else printf("=\n");
		//printf("%d\n",x+y);
	}
	return 0;
}

Measured memory_bytes: 128
n,m = map(int,input().split())
ans = [99]*n
for i in range(m):
    s,c = map(int,input().split())
    if ans[s-1] == 99 or ans[s-1] == c:
        ans[s-1] = c
    else:
        print(-1)
        exit()
if ans[0] == 0 and n != 1:
    print(-1)
    exit()
if ans[0] == 99 and n != 1:
    ans[0] = 1
for i in range(n):
    if ans[i] == 99:
        ans[i] = 0


print("".join([str(i) for i in ans]))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,i=1;
    cin>>a>>b>>c>>d;
    while (a>0&&c>0)
    {
        if(i%2!=0)
            c-=b;
        else
            a-=d;
        i++;
    }
    //cout<<a<<" " <<c;
    if(a<=0)
        cout<<"No";
    else
        cout<<"Yes";
    return 0;
}


Measured memory_bytes: 3620
program kadai
implicit none
integer  ::  k,x
integer  ::  i,j,l,n
integer,allocatable  ::  ans(:)

read(*,*) k,x

i=x-k+1
j=x+k-1

allocate(ans(2*k-1))
n=1
do l=i,j
    ans(n)=l
    n=n+1
end do

write(*,*) ans
stop

end program kadai


Measured memory_bytes: 640
# ABC152c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    n = int(input())
    p = list(map(int, input().split()))

    cou = 0
    m = 10**9
    for i in range(n):
        if m < p[i]:
            cou += 1
        m = min(m, p[i])
    print(n-cou)


if __name__ == '__main__':
    main()


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

int main() {
	int N;
 	long long K;
	int A[3000];

	cin >> N;
	cin >> K;

	long long times = ((K-1) * K )/ 2 % (1000000007);

	for (int i = 0; i<N; i++){
		cin >> A[i];
	}

	//first, count the number of reverse in the one string
  long long c1 = 0;
	for (int i = 0; i<N-1; i++){
		for(int j = i+1; j<N; j++){
			if (A[i] > A[j]){
				c1++;
			}
		}
	}

	//second, count the numbers that caused by the repeating
	//after sort
	long long c2 = 0;
	for (int i=0; i<N; i++) {
    for (int j=i+1; j<N; j++) {
      if (A[i] < A[j]) {
				int tmp;
        tmp =  A[i];
        A[i] = A[j];
        A[j] = tmp;
      }
    }
  }

	for (int i = 0; i<N-1; i++){
    for(int j = i+1; j<N; j++){
      if (A[i] > A[j]){
        c2++;
      }
    }
  }

	long long ans = (c1*K + c2 * (times)) % (1000000007);

	cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(lambda x: int(x) -1, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

cnt = 0
prev_food = -10
for a in A:
    cnt += B[a]
    if prev_food == a-1:
        cnt += C[a-1]
    prev_food = a
print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(9), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-9, PI = acos(-1);
const int N = 1e5 + 9, M = 3e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 9;
const ll inf = 1e18;

int vis[N];
vector<int> adj[N];

int dfs(int node) {
  if(vis[node])
    return vis[node];
  int mx = 0;
  for(auto it: adj[node])
    mx = max(mx, dfs(it) + 1);
  vis[node] = mx;
  return mx;
}

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  int n, m, u, v;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> u >> v;
    adj[u].push_back(v);
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    if(!vis[i])
      ans = max(ans, dfs(i));
  cout << ans;
  return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <chrono>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define f first
#define fin cin
#define fout cout
#define int long long
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
#define all(x) x.begin(), x.end()
#define left vadia
#define lb lower_bound
#define right puta
using namespace std;
using namespace __gnu_pbds;
void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0); 
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}
typedef pair<ll, ll> pii;
typedef vector<vector<char>> mat;
typedef pair<int, string> pis;
const ll mod = 1e9+7;
const int MAXN = 2e5 + 5;
const int MAXV = 1e6+5;
typedef vector<int> vi;
typedef pair<int, pair<int, int>> piii;

int32_t main() {
	int  n;
	cin >> n;

	int cont = 0;
	while(n--) {
		int x, y;
		cin >> x >> y;
		if(x == y) cont++;
		else cont = 0;
		if(cont >= 3) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 3620
def calc(a,b,x)
    return (a*x/b).to_i - a * (x/b).floor
end

A,B,N = gets.split.map(&:to_i)

ans = calc(A,B,1)

z = calc(A,B,N)
ans = z if z > ans
z = calc(A,B,N-1)
ans = z if z > ans

if B < N
z = calc(A,B,B-1)
ans = z if z > ans
z = calc(A,B,B)
ans = z if z > ans
end

puts ans


Measured memory_bytes: 14348
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define        u64             uint64_t
#define        ll              long long
#define        endl            "\n"
#define        PI              acos(-1)
#define        fi              first
#define        si              second
#define        mkp             make_pair
#define        pb              push_back
#define        set0(arr)       memset(arr, 0, sizeof(arr))
#define        setinf(arr)     memset(arr, 126, sizeof(arr))
#define        all(x)          (x).begin(),(x).end()
#define        sz(v)           ((int)(v).size())
#define        IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using          pll        =      pair<ll, ll> ;
using          vl         =      vector<ll> ;
using          vpll       =      vector<pll> ;
using          mll        =      map<ll, ll> ;
using          mcl        =      map<char, ll> ;
using          msl        =      map<string,ll> ;
using          sl         =      set<ll> ;
using          sc         =      set<char> ;
using          dl         =      deque<ll> ;
const int N = 1e6+5 ;

ll      mod = 1e9+7 ;
vl      adj[N] ;
vpll    adjc[N] ;
ll      vis[N] ;
ll      arr[N] ;



int main()
{
    IOS;
    ll a, b, c, d, n, m, p, x, y, z, i, j, k, f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18, cs;
    string   str ;
    char     ch ;
    double   db ;
    ll       l, r ;
    //code

    cin>>n;
    for(i=1;i<n;i++)
    {
           for(j=i;j<n;j+=i)
              cnt++;
    }
    cout<<cnt<<endl;


    //code
    return 0;
}


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

template<class value_type>
class my_list{
public:
  class node{
  public:
    value_type value;
    node* front;
    node* back;
    node(value_type value_):value(value_),front(nullptr),back(nullptr){}
  };
  int n;
  node* front_;
  node* back_;
  my_list():n(0){
    front_ =
      back_ = new node(-1);
  }

  class iterator{
  public:
    node* current;
    iterator(node* current_):current(current_){}
    iterator():current(nullptr){}
    iterator& operator++(){
      current = current->back;
      return *this;
    }
    iterator& operator--(){
      current = current->front;
      return *this;
    }
    bool operator!=(iterator const& other){
      return current != other.current;
    }
    value_type& operator*(){
      return current->value;
    }
  };

  iterator insert(iterator itr,value_type value){
    ++n;
    node* add = new node(value);
    node* front = itr.current->front;
    node* back = itr.current;
    if(front!=nullptr){
      add->front = front;
      front->back = add;
    }else{
      front_ = add;
    }
    if(back!=nullptr){
      add->back = back;
      back->front = add;
    }
    return iterator(add);
  }

  iterator erase(iterator itr){
    --n;
    node* front = itr.current->front;
    node* back = itr.current->back;
    if(front!=nullptr){
      front->back = back;
    }else{
      front_ = back;
    }
    if(back!=nullptr){
      back->front = front;
    }
    delete itr.current;
    return iterator(back);
  }

  iterator begin(){
    return iterator(front_);
  }
  iterator end(){
    return iterator(back_);
  }
};


int main(){
  int q;
  my_list<int> li;
  my_list<int>::iterator itr = li.end();
  cin >> q;
  for(int i=0;i<q;++i){
    int kind;
    cin >> kind;
    if(kind==0){
      int x;
      cin >> x;
      itr = li.insert(itr,x);
    }else if(kind==1){
      int d;
      cin >> d;
      while(d){
        if(d>0){
          ++itr;
          --d;
        }else{
          --itr;
          ++d;
        }
      }
    }else{
      itr = li.erase(itr);
    }
  }
  for(auto&i:li){
    cout << i << endl;
  }
}



Measured memory_bytes: 18572
/*Author - Shubham Gupta (@shubham107)*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF	ll(1e18)
#ifdef SHUBHAM107
#include "../code-pieces/trace.h"
#else
#define trace(args...)
#endif

ll modpow(ll a, ll b, ll m = MOD) {
	a %= m; ll res = 1; while (b) {if (b & 1)res = res * a % m; a = a * a % m; b >>= 1;}
	return res;
}
ll bpow(ll a, ll b) {ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a) {return modpow(a, MOD - 2, MOD);}
void graph(vvi &adj, int m) {int x, y; forn(i, m) {cin >> x >> y; adj[x - 1].pb(y - 1); adj[y - 1].pb(x - 1);}}

const int mxN = 2e5 + 5;
void solve() {
	int n, k, d;
	cin >> n >> k;
	vi snake(n);
	forn(i, k){
		cin >> d;
		forn(j, d){
			int a; cin >> a;
			snake[a-1]++;
		}
	}
	int ans = 0;
	forn(i, n) ans += (snake[i] == 0);
	cout << ans;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef SHUBHAM107
	freopen("inp.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	freopen("err.txt", "w", stderr);
#endif
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define M 1000000007
//#define M 998244353
using namespace std;
const int inf=4e18;
const double pi=3.14159265358979;
string LCS(string s1,string s2)
{
	int n=s1.length(),m=s2.length(),i,j;
	int dp[n+1][m+1];
	for(i=0;i<=n;i++)
		dp[i][0]=0;
	for(i=0;i<=m;i++)
		dp[0][i]=0;
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
		{
			if(s1[i-1]==s2[j-1])
				dp[i][j]=dp[i-1][j-1]+1;
			else
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	string o;
	i=n;j=m;
	while(j>0&&i>0)
	{
		if(s1[i-1]==s2[j-1])
		{
			o+=s1[i-1];
			j--;i--;
		}
		else
		{
			if(dp[i-1][j]>dp[i][j-1])
				i--;
			else
				j--;
		}
	}
	reverse(o.begin(),o.end());
	return o;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	string s,t;cin>>s>>t;
	string o=LCS(s,t);
	cout<<o<<endl;
}

Measured memory_bytes: 70656
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=200000;

int main() {
	ll x,y;
    cin>>x>>y;
    ll a=INF;

	if(x<=y){
		//++
		a=y-x;
	}
	if(-x<=y){
		//-+
		a=min(a,1+y+x);
	}
	if(x<=-y){
		//+-
		a=min(a,1-y-x);
	}
	if(-x<=-y){
		//--
		a=min(a,2-y+x);
	}

    cout<<a;
}

Measured memory_bytes: 256
package main

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

func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanInt64() int64 {
	sc.Scan()
	i, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return i
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func scanInts64(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		res[i] = scanInt64()
	}
	return res
}

func scanText() string {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Scan()
	return sc.Text()
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	n := scanInt()
	a := scanInts(n)

	sort.Ints(a)
	cnt := map[int]int{}
	for _, i := range a {
		cnt[i]++
	}

	ones := map[int]int{}
	for i, ele := range cnt {
		if ele == 1 {
			ones[i]++
		}
	}

	max := int(1e6 + 1)
	d := make([]int, max)
	for num := range cnt {
		for j := 2; j*num < max; j++ {
			d[num*j]++
		}
	}

	ans := 0
	for num := range ones {
		if d[num] == 0 {
			ans++
		}

	}
	fmt.Println(ans)

}


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

typedef long long ll;
typedef pair<int,int> P;

const int INF=1e9;
const int MOD=1e9+7;

int main(){
    int N; cin >> N;
    int a[N];
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    int cnt=1;
    char sign;
    char cur='=';
    for(int i=1;i<N;i++){
        if(a[i]>a[i-1]) sign='+';
        else if(a[i]<a[i-1]) sign='-';
        else continue;

        if(sign!=cur&&cur!='='){
            cnt++;
            cur='=';
            continue;
        }
        cur=sign;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3908
while True:
    try:
        n = int(input())
    except:
        break
    s = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                for l in range(10):
                    if n == i+j+k+l:
                        s += 1
    print(s)

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

int main()
{
    string str;
    cin >> str;
    
    int q;
    cin >> q;
    
    for (int i = 0; i < q; i++) {
        string s;
        int a, b = 0;
        string re;
        
        cin >> s >> a >> b;
        if (s == "replace") {
            cin >> re;
        }
        
        if (s == "print") {
            cout << str.substr(a, b - a + 1) << endl;
        } else if (s == "replace") {
            str = str.replace(a, b - a + 1, re);
        } else if (s == "reverse") {
            string temp = str.substr(a, b - a + 1);
            reverse(temp.begin(), temp.end());
            str = str.replace(a, b - a + 1, temp);
        }
    }
}


Measured memory_bytes: 3200
using System;

namespace ABC
{
    class ABC075A
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int c = int.Parse(str[2]);

            int ans = 0;
            if(a == b) { ans = c; }
            else if (a == c) { ans = b; }
            else if (b == c) { ans = a; }

            Console.WriteLine("{0}", ans);
        }
    }
}


Measured memory_bytes: 11220