akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(const T a, const T b){return a>=0 ? a/b : (a+1)/b-1;}
template<class T> T div_ceil(const T a, const T b){return a>=0 ? (a-1)/b+1 : a/b;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

char s[8][8];

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

char other(char c){
    return c == 'o' ? 'x' : 'o';
}

int count(int x, int y, int dx, int dy, char c){
    int ret = 0;
    x += dx; y += dy;
    while(in(x, y) && s[x][y] == other(c)){
        ++ret;
        x += dx; y += dy;
    }
    return in(x, y) && s[x][y] == c ? ret : 0;
}

int count_sum(int x, int y, char c){
    int ret = 0;
    for(int dx=-1; dx<=1; ++dx)for(int dy=-1; dy<=1; ++dy)if(dx != 0 || dy != 0){
        ret += count(x, y, dx, dy, c);
    }
    return ret;
}

void put(int x, int y, char c){
    s[x][y] = c;
    int tx, ty;
    for(int dx=-1; dx<=1; ++dx)for(int dy=-1; dy<=1; ++dy)if(dx != 0 || dy != 0){
        if(count(x, y, dx, dy, c) > 0){
            tx = x + dx; ty = y + dy;
            while(s[tx][ty] == other(c)){
                s[tx][ty] = c;
                tx += dx; ty += dy;
            }
        }
    }
}

int main(){
    rep(i, 8)rep(j, 8) scanf(" %c", &s[i][j]);
    rep(i, 64){
        int cnt = 0, tx = -1, ty = -1;
        if(i % 2 == 0){
            rep(x, 8)rep(y, 8)if(s[x][y] == '.'){
                if(chmax(cnt, count_sum(x, y, 'o'))){
                    tx = x; ty = y;
                }
            }
            if(cnt > 0) put(tx, ty, 'o');
        }
        else{
            rrep(x, 8)rrep(y, 8)if(s[x][y] == '.'){
                if(chmax(cnt, count_sum(x, y, 'x'))){
                    tx = x; ty = y;
                }
            }
            if(cnt > 0) put(tx, ty, 'x');
        }
    }
    rep(i, 8){
        rep(j, 8) printf("%c", s[i][j]);
        printf("\n");
    }
}


Measured memory_bytes: 3164
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)

	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())

	sc.Scan()
	s := sc.Text()

	if a >= 3200 {
		fmt.Println(s)
	} else {
		fmt.Println("red")
	}
}


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

int main() {
  int k;
  cin >> k;
  vector<int> a={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << a.at(k-1) << endl;
  return 0;
}


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

int main(){

    long H,C = 0,T = 1;
    cin >> H;

    while (H > 0){
        C += 1 * T;
        T = T * 2;
        H = H / 2;
    }
    cout << C << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            out.println((n / 2) * ((n + 1) / 2));
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long nextLong() {
            long n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

        public int nextInt() {
            long n = nextLong();

            if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE)
                throw new NumberFormatException();

            return (int) n;
        }

    }
}



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

using i64 = long long;

vector<i64> v;
i64 ant, sum;
int n;

int main() {
#ifdef HOME
	freopen("arc59a.in", "r", stdin);
	freopen("arc59a.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n;
	v.resize(n);
	for (auto &i: v)
		cin >> i;

	ant = 2e9;
	for (int i = -100; i <= 100; ++i) {
		sum = 0;
		for (int j = 0; j < n; ++j)
			sum+= i64(v[j] - i) * (v[j] - i);
		ant = min(ant, sum); }

	cout << ant << endl;

	return 0; }


Measured memory_bytes: 256
#include<cstdio>
int main(){
int A,B,K;
scanf("%d %d %d",&A,&B,&K);
for(int i=1;i<=K;i++)
{   if(i%2==1){
	if(A%2==1)
	{   A=A-1;
	    B=B+A/2;
	    A=A/2;
	}
	else {
		B=B+A/2;
		A=A/2;	
	}
	}
     else {
     if(B%2==1){
     B=B-1;
     A=A+B/2;
     B=B/2;}
     else {
     A=A+B/2;
     B=B/2;}
     	 } 
     	 	 }
    printf("%d %d",A,B);
     	 }

	

Measured memory_bytes: 128
n,k = map(int,input().split())
numbers = input().split()

d = {}
for i  in numbers:
  if i in d.keys():
      d[i] += 1
  else:           
      d[i] = 1

sorted_d = sorted(d.values(),reverse=True)
sums = sum(sorted_d[k:])
print(sums)


Measured memory_bytes: 35616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int dp[100100];

void solve(istream& cin, ostream& cout) {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  REP(i, n) cin >> h[i];
  REP(i, 100100) dp[i] = INF;
  dp[0] = 0;
  REP(i, n) {
    FOR(j, 1, k) {
      dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
    }
  }
  cout << dp[n - 1] << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


Measured memory_bytes: 1024
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    
    int num = A + B;
    int mai = A - B;
    int seki = A * B;
    
    int bigger = 0;
    if(num > mai) {
      bigger = num;
    }else{
      bigger = mai;
    }
    
    if(bigger > seki) {
      System.out.println(bigger);
    }else{
      System.out.println(seki);
    }
  }
}

Measured memory_bytes: 22996
#include <stdio.h>

int main(){
  long i,i_min,pas_min;
  long n,time=0;
  long trans[5];
  
  scanf("%ld",&n);
  for(i=0;i<5;i++){
    scanf("%ld",&trans[i]);
    if(i==0){
      pas_min=trans[0];
      i_min=0;
    } else if(trans[i]<=pas_min){
      pas_min=trans[i];
      i_min=i;
    }
  }
  
  if(n%trans[i_min]==0){
	time=n/trans[i_min]+4;
  } else {
    time=n/trans[i_min]+5;
  }
  
  printf("%ld",time);
}

Measured memory_bytes: 128
N=int(input())
l=input().split()
l=[int(i) for i in l]
a=0
for i in l:
    if i%2==0:
        if i%3==0 or i%5==0:
            a+=1
    else:
        a+=1
if a==N:
    print('APPROVED')
else:
    print('DENIED')

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

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

    int ans = 0;
    for (int i = 0; i < S.size(); i++) {
        if (i + 1 >= S.size()) break;

        if (S.at(i) != S.at(i+1)) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template <class T> inline void dump(T &v){irep(i, v){cout<<(*i)<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 998244353;//1000000007;
constexpr ld EPS = 1e-11;



int main() {
    
    int t=7;
    int k;
    cin>>k;
    for(int i=1;i<1e6+10;i++){
        if(t%k==0){
            fin(i);
            return 0;
        }
        t*=10;
        t+=7;
        t%=k;
        // fin(t);
    }
    fin(-1);
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define double long double
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    string s;cin>>s;
    ll K;cin>>K;
    vector<vector<vector<ll> > >dp(s.size()+1,vector<vector<ll> >(2,vector<ll>(4)));
    dp[0][0][0]=1;
    rep(i,s.size()){
        ll t=s[i]-'0';
        rep(k,4){
            rep(l,t){
                if(l==0)dp[i+1][1][k]+=dp[i][0][k];
                else if(k==3)continue;
                else dp[i+1][1][k+1]+=dp[i][0][k];
            }
            if(t>0){
                if(k<3)dp[i+1][0][k+1]+=dp[i][0][k];
            }else{
                dp[i+1][0][k]+=dp[i][0][k];
            }
            rep(l,10){
                if(l==0)dp[i+1][1][k]+=dp[i][1][k];
                else if(k==3)continue;
                else dp[i+1][1][k+1]+=dp[i][1][k];
            }
        }
    }
    rep(i,4){
        rep(j,2){
            //cout<<i<<' '<<j<<' '<<dp[s.size()][j][i]<<endl;
        }
    }
    cout<<dp[s.size()][0][K]+dp[s.size()][1][K]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using str = string;
using ll = long long;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define RREP(i,n) for(int i=int(n)-1; i>=0; i--)
#define FOR(i,f,t) for(int i=int(f); i<=int(t); i++)
#define RFOR(i,f,t) for(int i=int(f); i>=int(t); i--)
#define ALL(vec) (vec).begin(),(vec).end()
#define ASORT(vec) sort(ALL(vec))
#define DSORT(vec) sort(ALL(vec), greater<int>());
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define YES(ans) if(ans) cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define Yes(ans) if(ans) cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define yes(ans) if(ans) cout<<"yes"<<endl; else cout<<"no"<<endl;

int main() {
    int n, s;
    cin >> n;
    REP(i, n) {
        s = 0;
        for(int j=0; j<58; j++) {
            for(int k=j; k<82; k++) {
                for(int l=k; l<100; l++) {
                    if( (j+k+2)*(j+k+2) + (k+l+2)*(k+l+2) + (l+j+2)*(l+j+2) == 2*(i+1) ) {
                        if( (j!=k)&&(k!=l) ) {
                            s = s+6;
                        } else if( (j!=k)||(k!=l) ) {
                            s = s+3;
                        } else {
                            s = s+1;
                        }
                    }
                }
            }
        }
        cout << s << endl;
    }
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int n,d;
  cin >> n >> d;
  d = d * 2 + 1;
  cout << (n + d - 1) / d << '\n';
  return 0;
}

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

int N,K,X,Y,sum;//KはくまでX円でNはくする

int main(){

	cin>>N>>K>>X>>Y;
	if(N>K){
		sum=K*X+(N-K)*Y;
	}
	else{sum=X*N;}
	

	cout<< sum<<endl;
	return 0;

	}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main() {
	string s;
	cin >> s;
	if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) cout << "Bad" << endl;
	else cout << "Good" <<endl;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

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

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll a,b,c;
    cin >> a >> b >> c;
    if(b-a == c-b) cout << "YES";
    else cout << "NO";
    cout << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
typedef long long ll;
const int N=2002000,P=1000000007;
int i,i1,i2,j,j1,j2,fg,ans;
int X[6],Y[6],Jc[N],Jc_[N];
int ksm(int x,int y) {
	int z=1;
	for (;y;y>>=1,x=(ll) x*x%P) if (y&1) z=(ll) z*x%P;
	return z;
}
void pre(int n) {
	int i;
	Jc[0]=Jc_[0]=1;
	for (i=1;i<=n;i++) Jc[i]=(ll) Jc[i-1]*i%P;
	Jc_[n]=ksm(Jc[n],P-2);
	for (i=n-1;i;i--) Jc_[i]=(ll) Jc_[i+1]*(i+1)%P;
}
int C(int n,int m) {
	if (n<m) return 0;
	return (ll) Jc[n]*Jc_[m]%P*Jc_[n-m]%P;
}
int Js(int x1,int y1,int x2,int y2) {
	return C(x2-x1+y2-y1,x2-x1);
}
int work(int x1,int y1,int x2,int y2) {
	int i,j,ans=0;
	for (i=X[2];i<=X[3];i++) {
		ans=(ans+P-(ll) Js(x1,y1,i,Y[2]-1)*Js(i,Y[2],x2,y2)%P*(i+Y[2]-1)%P)%P;
		ans=(ans+(ll) Js(x1,y1,i,Y[3])*Js(i,Y[3]+1,x2,y2)%P*(i+Y[3]))%P;
	}
	for (i=Y[2];i<=Y[3];i++) {
		ans=(ans+P-(ll) Js(x1,y1,X[2]-1,i)*Js(X[2],i,x2,y2)%P*(X[2]+i-1)%P)%P;
		ans=(ans+(ll) Js(x1,y1,X[3],i)*Js(X[3]+1,i,x2,y2)%P*(X[3]+i))%P;
	}
	return ans;
}
int main() {
	pre(2000000);
	for (i=0;i<6;i++) scanf("%d",&X[i]);
	for (i=0;i<6;i++) scanf("%d",&Y[i]);
	for (i=0;i<16;i++) {
		int fg=1;
		if (i&1) i1=X[1],fg*=-1;
		else i1=X[0]-1;
		if (i&2) i2=X[4],fg*=-1;
		else i2=X[5]+1;
		if (i&4) j1=Y[1],fg*=-1;
		else j1=Y[0]-1;
		if (i&8) j2=Y[4],fg*=-1;
		else j2=Y[5]+1;
		ans=(ans+fg*work(i1,j1,i2,j2))%P;
		ans=(ans+P)%P;
	}
	printf("%d\n",ans);
}

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

typedef long long ll;

#define min(a, b) (((a) < (b))? (a):(b))
#define max(a, b) (((a) > (b))? (a):(b))
#define REP(i, a, n) for(int i=(a); i<(n); i++)
#define rep(i, n) REP(i, 0, (n))
#define square(a) (a)*(a)
#define pb push_back

int x,y,z;
int main(){
    cin >> x >> y >> z;
    int ans;
    ans = (x-z)/(y+z);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    int64_t K;
    cin >> N >> K;
    vector<int> a(N), b(N);
    vector<pair<int, int>> p(N);
    for (int i = 0; i < N; i++){
        cin >> a.at(i) >> b.at(i);
        p.at(i) = make_pair(a.at(i), b.at(i));
    }
    sort(p.begin(), p.end());
    int64_t count = 0;
    for (int i = 0; i < N; i++){
        count += p.at(i).second;
        if (count >= K){
            cout << p.at(i).first << endl;
            break;
        }
    }
}

Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

#include <bits/stdc++.h>
using namespace std;



int main() {
    int N;
    int K,d;
    int num;
    set<int> S;
    
    cin >> N >> K;
    rep(i,K){
        cin >> d;
        rep(i,d){
            cin >> num;
            S.insert(num);
        }
    }

    cout << N - S.size() << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
using namespace std;
int main()
{
  long long n,a,b;
  cin >> n >> a >> b;
 
  long long x[n + 1];
 
  for (int i = 1; i <= n; i++)
    cin >> x[i];
  
  long long sum = 0;
 
  for (int i = 1; i < n; i++) {
    int dis = x[i + 1] - x[i];
    if (dis * a < b){
      sum += dis * a;
    }else{
      sum += b;
    }
  }
 
  cout << sum << endl;
 
  return 0;
}

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

void solve (int n)
{
	readln;
	auto a = readln.splitter.map !(to !(long)).array;
	long res = long.min;
	int best;
	foreach (b; 0..2)
	{
		auto list = a.drop (b).stride (2);
		auto filtered = list.filter !(q{a >= 0});
		auto cur = filtered.empty ? list.reduce !(max) : filtered.sum;
		if (res < cur)
		{
			res = cur;
			best = b;
		}
	}
	writeln (res);

	int [] history;
	auto list = a.drop (best).stride (2);
	auto filtered = list.filter !(q{a >= 0});
	if (filtered.empty)
	{
		auto m = list.reduce !(max);
		auto pos = a.countUntil (m).to !(int);
		foreach_reverse (i; pos + 1..n)
		{
			history ~= i;
		}
		foreach (i; 0..pos)
		{
			history ~= 0;
		}
	}
	else
	{
		if (best)
		{
			history ~= 0;
			a.popFront ();
		}
		while (a.front < 0)
		{
			history ~= 0;
			a.popFront ();
			history ~= 0;
			a.popFront ();
		}
		int pos = 0;
		while (true)
		{
			int cur = pos + 2;
			while (cur < a.length && a[cur] < 0)
			{
				cur += 2;
			}
			if (cur >= a.length)
			{
				while (a.length > pos + 1)
				{
					history ~= a.length.to !(int) - 1;
					a.popBack ();
				}
				break;
			}
			int mid = (pos + cur) / 2;
			while (mid != pos)
			{
				debug {writeln (pos, " ", mid, " ", cur);}
				debug {writeln (a);}
				history ~= mid;
				a = a[0..mid - 1] ~ (a[mid - 1] + a[mid + 1]) ~
				    a[mid + 2..$];
				mid -= 1;
			}
			pos = mid;
		}
	}
	debug {writeln (a);}
	writefln ("%s\n%(%s\n%)", history.length, history.map !(q{a + 1}));
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		solve (n);
	}
}


Measured memory_bytes: 4476
w = int(input())
n = int(input())
kuji = [i+1 for i in range(w)]
for _ in range(n):
    a, b = map(int, input().split(','))
    kuji[a-1], kuji[b-1] = kuji[b-1], kuji[a-1]
print(*kuji, sep="\n")



Measured memory_bytes: 5600
#include<stdio.h>
long long a[110000],b[110000];
int main(void)
{
	long long i,j,k=0,n,m,sum=0;
	scanf("%lld",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		sum=sum+a[i];
	}
	if(sum%(n*(n+1)/2)!=0)
	{
		printf("NO\n");
		return 0;
	}
	sum=sum/(n*(n+1)/2);
	b[1]=a[1]-a[n];
	for(i=2;i<=n;i++)
	b[i]=a[i]-a[i-1];
	for(i=1;i<=n;i++)
	{
		if(sum-b[i]<0||(sum-b[i])%n)
		{
			printf("NO\n");
			return 0;
		}
		else
		k=k+(sum-b[i])/n;
	}
	if(k==sum)
	printf("YES\n");
	else
	printf("NO\n");
	return 0;
}

Measured memory_bytes: 1792
N, q = gets.chomp.split.map(&:to_i)
tasks = Array.new
queue = Array.new
elaps = 0
N.times { tasks.push(gets.chomp.split) }
class Task
  attr_accessor :name, :time

  def initialize(name, time)
    @name = name
    @time = time.to_i
  end
end

tasks.each do |a, b|
  queue.push(Task.new(a, b))
end

until queue.empty?
  u = queue.shift
  c = [q, u.time].min
  u.time -= c
  elaps += c
  if u.time > 0
    queue.push(u)
  else
    print "#{u.name} #{elaps}\n"
  end
end



Measured memory_bytes: 20188
#include<algorithm>
#include<cstring>
#include<cstdio>
#define mxn 1000010
using namespace std;
int n,m,sl,fh,ans,a[mxn],b[mxn],s[mxn],A[mxn],B[mxn],fa[mxn];
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
int getfa(int x)
{
	if(fa[x]!=x) fa[x]=getfa(fa[x]);
	return fa[x];
}
int main()
{
	n=rd();
	for(int i=1;i<=n;++i) a[n+1]^=(a[i]=rd());
	for(int i=1;i<=n;++i) b[n+1]^=(b[i]=rd());
	++n;memcpy(A+1,a+1,n<<2);memcpy(B+1,b+1,n<<2);
	sort(A+1,A+n+1);sort(B+1,B+n+1);
	for(int i=1;i<=n;++i) if(A[i]!=B[i]) return puts("-1"),0;
	for(int i=1;i<n;++i)
		if(a[i]!=b[i])
			++ans,s[++m]=a[i],s[++m]=b[i];
	if(!ans) return puts("0"),0;
	--ans;s[++m]=a[n];s[++m]=b[n];
	sort(s+1,s+m+1);m=unique(s+1,s+m+1)-s-1;
	for(int i=1;i<=m;++i) fa[i]=i;
	int x,y,fx,fy;
	for(int i=1;i<=n;++i)
		if(a[i]!=b[i])
		{
			x=lower_bound(s+1,s+m+1,a[i])-s;
			y=lower_bound(s+1,s+m+1,b[i])-s;
			fx=getfa(x);fy=getfa(y);
			if(fx!=fy) fa[fy]=fx;
		}
	for(int i=1;i<=m;++i)
		if(getfa(i)==i)
			ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 16896
from collections import deque
x=deque([])
for i in range(int(input())):
	a=input().split()
	if a[0]=='insert':
		x.insert(0,a[1])
	elif a[0]=='delete':
		if a[1] in x:
			x.remove(a[1])		
	elif a[0]=='deleteFirst':
		x.popleft()
	elif a[0]=='deleteLast':
		x.pop()
print(' '.join(x)) 


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

int ex2 (int x) {
    int res = 1;
    for (int i = 0; i < x; i++) {
        res = (res * 2) % 1000000007;
    }
    return res;
}

int main() {
    int n, a, occ[100005];
    bool pos = true;
    cin >> n;
    memset(occ, 0, sizeof(occ));
    for (int i = 0; i < n; i++) {
        cin >> a;
        occ[a]++;
    }
	//for (int i = 0; i < n; i++) cout << occ[i];
	//cout << '\n';
    if (n%2) {
        for (int i = 0; i < n; i++) {
            if (i == 0 && occ[i] != 1) pos = false;
            else if (i%2==1 && occ[i] != 0) pos = false;
            else if (i%2==0 && i && occ[i] != 2) pos = false;
        }
    } else {
        for (int i = 0; i < n; i++) {
            if (i == 0 && occ[i] != 0) pos = false;
            else if (i%2==1 && occ[i] != 2) pos = false;
            else if (i%2==0 && i && occ[i] != 0) pos = false;
        }
    }
    if (pos) cout << ex2(n/2);
    else cout << 0;
}

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

int main(){
    int X;
    cin >> X;
    int a=0,b=0;
    a = X/500;
    X = X-a*500;
    b = X/5;
    X = X-b*5;
    cout << a*1000 + b*5  <<endl;
}

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

using namespace std;

void vec_print(vector<int> a){
  for(int i=0; i<a.size(); i++) std::cout << a[i];
  std::cout  << '\n';
}

int main(){
  int input[5];
  vector<int> permutation(5);
  for(int i=0; i<5; i++){
    std::cin >> input[i];
    permutation[i] = i;
  }

  int min_val = INT_MAX;
  do{
    int time = 0;
    for(int i=0; i<5; i++){
      if( i != 4 ){
        time += (input[permutation[i]]+9) / 10 * 10;
      }else{
        time += input[permutation[i]];
      }
    }
    min_val = min(min_val, time);
  }while( next_permutation( permutation.begin(), permutation.end() ));

  std::cout << min_val << '\n';
  return 0;
}


Measured memory_bytes: 888
#include <iostream>
using namespace std;
int main(void){
  int n,m;
  cin >> n >> m;
  int ac[n],wa[n],acflg[n];
  for(int i=0;i<n;i++){
      ac[i]=0;
      wa[i]=0;
      acflg[i]=0;
  }
  
  for(int i=0;i<m;i++){
      int p;
      string s;
      cin >> p >> s;
      if(acflg[p-1]==0){
          if(s=="WA"){
              wa[p-1]++;
          }else if (s=="AC"){
              ac[p-1]++;
              acflg[p-1]=1;
          }
      }
  }

  int sa=0,sw=0;
  for(int i=0;i<n;i++){
      if(acflg[i]==1){
      sa+=ac[i];
      sw+=wa[i];
      }
  }
  
  cout << sa << ' ' << sw << endl;
  return 0;
}

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



int main(){
	int N;
	cin>>N;
	vector<int> A(N);
	long long a = 1;
	long long x = 1;
	for(int i=0;i<N;i++){
		cin>>A[i];
		if(A[i]%2==0)a*=2;
		x*=3;
	}
	cout<<x-a<<endl;
	
	
	
	return 0;
}


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

vector<vector<int> > edges;


vector<int> wut1;
vector<int> cnt2;

vector<int> pmax;
vector<int> par;

vector<vector<int> > event1;
vector<vector<int> > event2;

void dfs1(int v, int p, int cmax){
	par[v] = p;
	pmax[v] = cmax;
	if(cmax >= 0) event2[cmax].push_back(v);
	if(v > cmax && cmax >= 0){
		for(int a : edges[v]){
			if(a == p) continue;
			event1[cmax].push_back(a);
		}
	}
	for(int a : edges[v]){
		if(a == p) continue;
		dfs1(a, v, max(cmax, v));
	}
}

vector<int> ans;

void dfs2(int v, int p, int curans){
	curans += wut1[v];
	ans[v] = curans + cnt2[v];
	for(int a : edges[v]){
		if(a == p) continue;
		int newans = curans;
		dfs2(a, v, curans);
	}
}

struct UF{
    int n;
    vector<int> par;
    vector<int> sz;
    UF(int n) : n(n) {
        for(int i = 0; i < n; i++){
        	par.push_back(i);
        	sz.push_back(1);
        }
    }
    int find(int a){
        if(a != par[a]) par[a] = find(par[a]);
        return par[a];
    }
    void join(int a, int b){
    	if(find(a) == find(b)) return;
    	int u = find(a);
    	int v = find(b);
    	sz[v] += sz[u];
    	par[u] = v;
    }
};

int main(){
	cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	edges.resize(n);
	pmax.resize(n);
	ans.resize(n);
	cnt2.resize(n);
	wut1.resize(n, 0);
	par.resize(n);
	event1.resize(n);
	event2.resize(n);
	for(int i = 0; i < n-1; i++){
		int a, b;
		cin >> a >> b;
		a--; b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	dfs1(0, -1, -1);

	UF uf(n);
	for(int i = 0; i < n; i++){
		for(int x : event1[i]){
			if(x < i){
				wut1[x] -= uf.sz[uf.find(x)];
			}
		}
		for(int x : event2[i]){
			if(x > i){
				cnt2[x] = 1;
				for(auto r : edges[x]){
					if(r >= i) continue;
					cnt2[x] += uf.sz[uf.find(r)];
				}
			} else {
				cnt2[x] = uf.sz[uf.find(x)];
			}
		}
		for(int a : edges[i]){
			if(a < i){
				uf.join(a, i);
			}
		}
	}
	for(int i = 0; i < n; i++){
		for(int x : event1[i]){
			wut1[x] += cnt2[par[x]];
		}
	}
	dfs2(0, -1, 0);
	for(int i = 1; i < n; i++){
		cout << ans[i] << ' ';
	}
	cout << '\n';
}

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

void dfs(int, int);
vector<vector<int>> nodeEdges;
vector<int> nodeCounter;
int main()
{
    int N, Q;
    cin >> N >> Q;
    nodeEdges = vector<vector<int>>(N + 1, vector<int>(0));
    nodeCounter = vector<int>(N + 1, 0);
    for (int i = 0; i < N - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        nodeEdges.at(a).push_back(b);
        nodeEdges.at(b).push_back(a);
    }
    for (int i = 0; i < Q; i++)
    {
        int p, x;
        cin >> p >> x;
        nodeCounter.at(p) += x;
    }
    dfs(1, -1);
    for (int i = 1; i <= N; i++)
    {
        if(i != 1){
            cout << " ";
        }
        cout << nodeCounter.at(i);
    }
    return 0;
}

void dfs(int currentNode, int parentNode)
{
    if(parentNode != -1){
        nodeCounter.at(currentNode) += nodeCounter.at(parentNode);
    }
    for(int node : nodeEdges.at(currentNode)){
        if(node == parentNode){
            continue;
        }
        dfs(node, currentNode);
    }
}

Measured memory_bytes: 23424
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int s,w;
  cin >> s >> w;
  if(s <= w){
    cout << "unsafe" << endl;
  }else{
    cout << "safe" << endl;
  }
}

Measured memory_bytes: 3632
import sys
N,M = map(int, input().split())
s = []
c = []
for i in range(M):
    si, ci = map(int, input().split())
    s.append(si-1)
    c.append(ci)
if N==1:
    for x in range(10**(N-1)-1, 10**N):
        ans = 0
        st = str(x)
        for i in range(M):
            if int(st[s[i]]) == c[i]:
                ans += 1
        if ans==M:
            print(x)
            sys.exit()
    print(-1)
else:
    for x in range(10**(N-1), 10**N):
        ans = 0
        st = str(x)
        for i in range(M):
            if int(st[s[i]]) == c[i]:
                ans += 1
        if ans==M:
            print(x)
            sys.exit()
    print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
    using namespace std;
int gcd(int a, int b) {
  while(1) {
    if(a < b) swap(a, b);
    if(b<=0) break;
    a %= b;
  }
  return a;
}
    int main(){
      int N;
      cin >>N;
   int ans=0;;
      
      
      for(int i=1;i<N+1;i++){
        for(int j=1;j<N+1;j++){
          int pair=gcd(i,j);
          for(int l=1;l<N+1;l++){
         ans+=gcd(pair,l);
        }
      }
      }
      
     
      
  cout <<ans<<endl;
        
    }

Measured memory_bytes: 3676
#include <bits/stdc++.h>
#include <cstring>
#include <limits>
using namespace std;
#define ll long long int
#define lli long long int
#define fw(i, s, e) for (ll i = s; i < e; ++i)
#define fe(i, s, e) for (ll i = s; i <= e; ++i)
#define fb(i, e, s) for (ll i = e; i >= s; --i)
#define L(T)  \
    ll T;     \
    cin >> T; \
    while (T--)
#define FASTIO                   \
    ios::sync_with_stdio(false); \
    cin.tie(nullptr);            \
    cout.tie(nullptr);
#define mem(a, i) memset(a, i, sizeof(a))
#define ld long double
#define endl "\n"
#define in(P) \
    ll P;     \
    cin >> P;
int main()
{
    FASTIO
    // L(T)
    // {
    // }
    in(n);
    ll a[n + 90];
    fw(i, 1, n + 1) cin >> a[i];
    ll cnt = 0;
    fw(i, 1, n + 1)
    {
        if (a[i] % 2 == 1 && i % 2 == 1)
        {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>
using namespace std;


int main(){
	while(1){
		int h, w;
		scanf(" %d %d", &h, &w);
		if(h==0 && w==0) break;
		
		for(int i=0; i<h; ++i){
			for(int j=0; j<w; ++j){
				if( (i+j)%2==0 ) printf("#");
				else printf(".");
			}
			printf("\n");
		}
		printf("\n");

	}
	return 0;
}






Measured memory_bytes: 2612
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<ll, int> P;
const ll Mod = 1000000007;
const ll INF = Mod * 100LL;
int main() {
  int N,K,Q;
  cin >> N >> K >> Q;
  ll ans = INF;
  vector<ll> A(N);
  vector<P> As(N);
  set<int> Set;
  Set.insert(-1);
  Set.insert(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    As[i].F = A[i];
    As[i].S = i;
  }
  sort(As.begin(),As.end());
  for (int i = 0; i < N; i++) {
    multiset<ll> Sum;
    int p = 0;
    for (auto itr = next(Set.begin(),1); p <= i; itr++) {
      p++;
      auto pitr = prev(itr,1);
      multiset<ll> S;
      for (int j = *pitr+1; j < *itr; j++) {
        S.insert(A[j]);
      }
      
      int len = 0;
      int sz = (int)S.size();
      if (*pitr == -1 && *itr == N) {
        len = max(len,sz);
      } else if (*pitr == -1 || *itr == N) {
        len = max(len,sz - K + 1);
      } else {
        len = max(len,sz - K + 1);
      }
      int cnt = 0;
      for (auto itr = S.begin(); cnt < len; itr++) {
        Sum.insert(*itr);
        cnt++;
      }
    }
    if ((int)Sum.size() >= Q) {
      ans = min(ans,*(next(Sum.begin(),Q-1)) - *(Sum.begin()));
      Set.insert(As[i].S);
    } else {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int N;
double L;
int s[100010],t[100010],u[100010];

int main(){
  while(true){
    cin >> N >> L;
    if(N==0) return 0;
    for(int i=1;i<=N;i++){
      cin >> s[i] >> t[i] >> u[i];
    }
    double l = 0,r = 2e9;
    for(int ti=0;ti<100;ti++){
      double m = (l+r)/2;
      double now = L;
      bool ok = true;
      for(int i=1;i<=N;i++){
	now = min(L,now+m*(s[i]-t[i-1]));
	now = min(now-(u[i]-m)*(t[i]-s[i]),L);
	if(now<0) ok = false;
      }
      now = min(L,now+m*(86400-t[N]));
      double pre = now;
      for(int i=1;i<=N;i++){
	now = min(L,now+m*(s[i]-t[i-1]));
	now = min(now-(u[i]-m)*(t[i]-s[i]),L);
	if(now<0) ok = false;
      }
      now = min(L,now+m*(86400-t[N]));
      if(ok && pre<=now) r = m;
      else l = m;
    }
    cout << fixed;
    cout << setprecision(10) << r << endl;
  }
}



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

namespace TYC
{
	void work()
	{
		int n, p;
		scanf("%d", &n);
		for (p = 0; (1 << p) <= n; p++)
			if ((1 << p) == n)
				return void(puts("No"));
		puts("Yes");
		p--;
		printf("%d %d\n", 1, 2);
		printf("%d %d\n", 2, 3);
		printf("%d %d\n", 3, n + 1);
		printf("%d %d\n", n + 1, n + 2);
		printf("%d %d\n", n + 2, n + 3);
		for (int i = 4; i < n; i += 2)
		{
			printf("%d %d\n", n + 1, i);
			printf("%d %d\n", i, i + 1);
			printf("%d %d\n", n + 1, n + i + 1);
			printf("%d %d\n", n + i + 1, n + i);
		}
		if (n % 2 == 0)
		{
			printf("%d %d\n", 1 << p, n); 
			if (n - (1 << p) + 1 == 3)
				printf("%d %d\n", 3, n << 1);
			else
				printf("%d %d\n", (n << 1) - (1 << p) + 1, n << 1); 
		}
	}
}

int main()
{
	TYC::work();
	return 0;
}

Measured memory_bytes: 2816
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N, cnt;
	char S;
	bool PWGY[4] = { false, false, false, false };

	cin >> N;
	rep(i, N) {
		cin >> S;
		if (S == 'P') PWGY[0] = true;
		else if (S == 'W') PWGY[1] = true;
		else if (S == 'G') PWGY[2] = true;
		else if (S == 'Y') PWGY[3] = true;
	}

	cnt = (PWGY[0] ? 1 : 0)
		+ (PWGY[1] ? 1 : 0)
		+ (PWGY[2] ? 1 : 0)
		+ (PWGY[3] ? 1 : 0);

	cout << (cnt == 3 ? "Three" : "Four") << endl;

	return 0;
}


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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int gcd(int x,int y){
    if(x<y){
        swap(x,y);
    }
    if(x%y==0) return y;
    else return(gcd(y,x%y));
}


int main(){
    int n,X;
    cin >> n >> X;
    int a[n];
    REP(i,n){
        int x;
        cin >> x;
        a[i] = abs(X-x);
    }
    sort(a,a+n);
    int ans = a[0];
    for(int i=1;i<n;i++){
        ans = gcd(ans,a[i]);
    }
    cout << ans << endl;
    return 0;
}  

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

int main() {
    int N,cnt;
    cin >> N;
    cnt = 0;
    vector<int> vec(N);
    for(int i = 1; i <= N; i++) {
        cin >> vec[i];
        if(i % 2 == 1) {
            if(vec[i] % 2 == 1) {
                cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3572
from collections import defaultdict
N = int(input())
a = [int(input()) for _ in range(N)]

d = defaultdict(int)
for i, e in enumerate(a, 1):
    d[i] = e

count = 1
tmp = d[1]
if tmp == 2:
    print(1)
    exit()

while count <= N:
    v = d[tmp]
    count += 1
    if v == 2:
        print(count)
        exit()
    tmp = v
print(-1)


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

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

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

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

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

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll t1 = min({a*4, b*2, c});
	ll t2 = min(t1*2, d);
	ll n;
	cin>>n;
	ll ans = n/2*t2;
	if(n&1) ans += t1;
	cout<<ans<<endl;
}


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

Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <stdio.h>

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

typedef long long ll;

using namespace std;

const int INF = 1e9;
const double PI=3.14159265358979323846;

class Dice{
private:
  int N[6];
  
public:
  void setN(int index, int value);
  void printN(int index);
  void roll(char c);
};

void Dice::setN(int index, int value){
  N[index] = value;
}

void Dice::printN(int index){
  cout << N[index] << endl;
}

void Dice::roll(char c){
  switch(c){
    int memo;
  case 'E':
    memo = N[0]; N[0] = N[3]; N[3] = N[5];
    N[5] = N[2]; N[2] = memo;
    break;
  case 'N':
    memo = N[0]; N[0] = N[1]; N[1] = N[5];
    N[5] = N[4]; N[4] = memo;
    break;
  case 'W':
    memo = N[0]; N[0] = N[2]; N[2] = N[5];
    N[5] = N[3]; N[3] = memo;    
    break;
  case 'S':
    memo = N[0]; N[0] = N[4]; N[4] = N[5];
    N[5] = N[1]; N[1] = memo;    
    break;
  }
}

int main(){
  Dice dice;
  
  int n; string s;
  rep(i,6){
    cin >> n;
    dice.setN(i, n);
  }
  cin >> s;

  rep(i,s.size()){
    dice.roll(s[i]);
  }
  dice.printN(0);
}



Measured memory_bytes: 3196
N,M = [int(i) for i in input().split(" ")]
pS = [0]*N
ac,wa = 0,0
for _ in range(M):
    p,S = input().split(" ")
    p = int(p)-1
    if pS[p] != -1 and S == "WA":
        pS[p]+=1
    if pS[p] != -1 and S=="AC":
        ac+=1
        wa+=pS[p]
        pS[p]=-1
print(ac,wa)

Measured memory_bytes: 3828
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define __DEBUG__ 1

typedef   signed long long int slli;
typedef unsigned long long int ulli;
const slli MAX_SLLI = 0x7FFFFFFFFFFFFFFF;
const slli MIN_SLLI = 0x8000000000000000;
const ulli MAX_ULLI = 0xFFFFFFFFFFFFFFFF;
const ulli MIN_ULLI = 0x0000000000000000;

#define N_TIMES(i, n)     for (ulli i = 0;     i <  n; ++i)
#define N_TIMES_REV(i, n) for (slli i = n - 1; i >= 0; --i)

#ifdef __DEBUG__
template<typename T>
std::ostream& operator<<(std::ostream &os, const std::list<T> &list)
{
  const std::string delim = ", ";
  typename std::list<T>::const_iterator itr = list.begin();
  while (itr != list.end()) {
    os << *itr;
    ++itr;
    if(itr != list.end()) os << delim;
  }
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v)
{
  const std::string delim = ", ";
  for (unsigned n = 0; n < v.size(); ++n) {
    os << v[n];
    if((n + 1) < v.size()) os << delim;
  }
  return os;
}
#endif

typedef std::vector< std::vector<bool> > EdgeTable;

typedef std::bitset<8> VisitedFlags;
const VisitedFlags NullFlags(0);

inline bool complete(unsigned N, const VisitedFlags &visited)
{
  N_TIMES(n, N) { 
    if(!visited[n]) return false;
  }
  return true;
}

unsigned search(const EdgeTable &edge, unsigned node, const VisitedFlags &visited)
{
  unsigned N = edge.size();
  unsigned count = 0;

  if(complete(N, visited)) return 1;

  for (unsigned next = 0; next < N; ++next) {
    if (visited[next]) continue;
    if (!edge[node][next]) continue;
    
    VisitedFlags flags = visited;
    flags.set(next);
    count += search(edge, next, flags);
  }

  return count;
}

unsigned search(const EdgeTable &edge)
{
  unsigned start = 0;

  VisitedFlags visited = NullFlags;
  visited.set(start);

  return search(edge, start, visited);
}

int main()
{
  unsigned N, M;
  std::cin >> N >> M;

  EdgeTable edge(N);
  N_TIMES(n, N) {
    edge[n] = std::vector<bool>(N, false);
  }

  N_TIMES(m, M) {
    unsigned a, b;
    std::cin >> a >> b;
    
    edge[a - 1][b - 1] = edge[b - 1][a - 1] = true;
  }

  std::cout << search(edge) << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n, h;
    cin >> n >> h;
    int maxe = 0;
    vector<int> b(n);
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a >> b[i];
        chmax(maxe, a);
    }
    sort(b.begin(), b.end(), greater<int>());
    int ans = 0;
    for(int i = 0; i < n; ++i){
        if(b[i] <= maxe)    continue;
        h -= b[i];
        ++ans;
        if(h <= 0){
            cout << ans << endl;
            return 0;
        }
    }
    ans += ceil((double)h / maxe);
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
#define FOR(i,l,r) for (int i = (l); i < (r); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((int)(c).size())
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<int,int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
static const double EPS = 1e-10;
static const double PI  = acos(-1.0);
// static const ll MOD = 1000000007;
static const ll MOD = 998244353;
static const int INF = 1 << 30;
// static const ll INF = 1LL << 62;
// --------------------------------------------------------


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);

    int N, K; cin >> N >> K;

    VLL dp(N + 1, 0);
    dp[1] = 1;

    VI L(K), R(K);
    REP(i, K) cin >> L[i] >> R[i];

    VLL S(N + 1, 0);
    S[1] = 1;
    FOR(i, 2, N + 1) {
        REP(j, K) {
            int l = L[j], r = R[j];
            if (i - l < 1) continue;
            dp[i] += MOD + S[i - l] - S[max(0, i - r - 1)];
        }
        dp[i] %= MOD;
        S[i] = (S[i - 1] + dp[i]) % MOD;
    }
    ll ans = dp[N];
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 6356