akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2730>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    string S; cin >> S;
    ll L = S.find('>');
    ll R = S.rfind('<');
    if(L!=string::npos) res = max(res,N-L);
    if(R!=string::npos) res = max(res,R+1);
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}



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

#define int long long
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)x.size())
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

/*
 */

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int, int>;

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

  rep(i, 0, sz(s)) cout << "x";
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>

using namespace std;

int main(void){
    // Your code here!
    int a,b;double f=0;
    
    scanf("%d %d",&a,&b);

    printf("%d %d %.5f\n",a/b,a%b,(double)a/b);//printf("%d %d %.5f",a/b,a%b,f);

    return 0;
}



Measured memory_bytes: 3232
#include <stdio.h>
#include <string.h>

int
main()
{
	char x[1000];
	int i;
	int len;
	int sum;	
	for (;;)
	{
		scanf("%s", x);

		if (strcmp(x, "0") == 0)
			break;

		sum = 0;
		len = strlen(x);
		for (i = 0; i < len; i++)
		{
			sum += x[i] - '0';
		}
		printf("%d\n", sum);
	}

	return 0;
}

Measured memory_bytes: 536
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define rsort(x) sort(all(x));reverse(all(x))
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool debug=false;
/*---------------------------------------------------*/

int main(){
  ll n,k;
  ll ans=0;
  cin>>n>>k;
  ans=k;
  rep(i,n-1){
    ans*=(k-1);
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

struct UnionFind
{
    vector<int> data;

    UnionFind(int size) : data(size, -1) { }

    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }

    bool findSet(int x, int y) {
        return root(x) == root(y);
    }

    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }

    int size(int x) {
        return -data[root(x)];
    }
};

int main()
{
    int N, K, R;

    cin >> N >> K;
    UnionFind uf(N);

    for (int i = 0; i < K; ++i) {
        int m, r1, r2;
        cin >> m >> r1;

        for (int j = 1; j < m; ++j) {
            cin >> r2;
            uf.unionSet(r1 - 1, r2 - 1);
        }
    }

    cin >> R;
    int p, q, ans = 0;
    vector<bool> used(N, false);
    for (int i = 0; i < R; ++i) {
        cin >> p >> q;
        if (uf.findSet(p - 1, q -1)) {
            if (!used[p - 1])
                ++ans;
            if (!used[q - 1])
                ++ans;
            used[p - 1] = used[q - 1] = true;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1192
import itertools

n=int(input())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])

narabi = [0+i for i in range(n)]

ans = 0
count = 0
for v in itertools.permutations(narabi, n):
    count += 1
    tmp_len = 0
    for i in range(1,n):
        x, y = abs(ab[v[i-1]][0]-ab[v[i]][0])**2, abs(ab[v[i-1]][1]-ab[v[i]][1])**2
        tmp_len += (x + y)**0.5
    ans += tmp_len

print(ans/count)

Measured memory_bytes: 75128
import sys
q = int(input())
v = []
for _ in range(q):
    s = sys.stdin.readline()
    if s[0] == '2':
        v.pop()
    else:
        c, x = map(int, s.split())
        if c == 0:
            v.append(x)
        else:
            sys.stdout.write("{}\n".format(v[x]))


Measured memory_bytes: 13368
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
abc = []
for i in range(X):
  for j in range(Y):
    if (i + 1) * (j + 1) > K:
      break
    for k in range(Z):
      if (i + 1) * (j + 1) * (k + 1) > K:
        break
      abc.append(A[i] + B[j] + C[k])
    
abc.sort(reverse = True)
for i in range(K):
  print(abc[i])


Measured memory_bytes: 8708
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<deque>
#include<map>
#include<iomanip>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define ll long long
#define pb(a) push_back(a)
using namespace std;
const vector<VE> DIR{ {-1,0},{1,0},{0,-1},{0,1} };
const ll MOD = 1000000007;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
int main() {
	ll n, k;
	cin >> n >> k;
	ll a = n / k;
	ll ans = min(abs(n - a * k), abs(n - (a + 1) * k));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(ReadLine());
        var A = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        var B = new int[N];

        for (int i = 0; i < N - 1; i++)
        {
            B[A[i] - 1]++;
        }

        for (int i = 0; i < N; i++)
        {
            WriteLine(B[i]);
        }
    }
}


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

int main() {
    int64_t N;
    cin >> N;
    int64_t ans = 0;
    for (int64_t i = 1; i <= N; i++) {
        if (i % 3 == 0 || i % 5 == 0) {
            continue;
        }
        ans += i;
    }

    cout << ans << endl;
}

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

#include<bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <queue>
#include <set>
#include <string>
#include <stdbool.h>
#include<ctime>

#include <cstring>

#define pub push_back


#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ll long long
#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) < (b) ? (a) : (b))

#define getI(a) scanf("%d",&a)
#define getII(a, b) scanf("%d%d",&a,&b)
#define getIII(a, b, c) scanf("%d%d%d",&a,&b,&c)
#define getL(a) scanf("%lld",&a)
#define getLL(a, b) scanf("%lld%lld",&a,&b)
#define getLLL(a, b, c) scanf("%lld%lld%lld",&a,&b,&c)
#define BEND(c) (c).begin(),(c).end()
#define BEND2(c) (c).rbegin(),(c).rend()
#define fi first
#define se second
#define pi 3.1415926535897932384626
#define getS(a) scanf("%s",a)
#define pfb(a) printf("%.10lf\n",a);
#define pfi(a) printf("%d",a);
#define pfii(a, b) printf("%d%d",a,b);
#define pfl(a) printf("%lld",a);
#define pfll(a, b) printf("%lld%lld",a,b);
#define pfd(a) printf("%.12lf ",a);
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define endl "\n"

#define MOD  ( int)(1e9 + 7)
#define MAXN (ll) ((1e5+5))
#define K 25
#define  ALPHABET_SIZE  26
//#define N (int)(1e5+10)
#define sag (sol|1)
#define sol (root<<1)
#define ort (bas+son)/2
#define INF (ll )1e18
#define int ll
using namespace std;



vector <set<int>> vec(MAXN);




typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<pair<int, int>>> vvpi;
typedef vector<long long> vl;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<vi> graph;

vector<ll> fact;
vector<ll> fact2;
void finit(int n);
ll exp(ll taban, ll us, ll md);
ll ebob(ll a, ll b);
ll ekok(ll a, ll b);
ll comb(ll a, ll b);


void finit(int n){
	fact.resize(n + 5);
	fact2.resize(n + 5);
	fact[0] = fact2[0] = 1;
	for (int i = 1; i <= n; i++){
		fact[i] = (fact[i - 1] * i) % MOD;
		fact2[i] = exp(fact[i], MOD - 2, MOD);
	}
}
ll exp(ll taban, ll us, ll md) {
	ll carpan = taban % md;
	if (carpan == 0) return 0;
	ll temp = us;
	ll ans = 1;
	while (temp){
		if (temp % 2) ans = (ans*carpan) % md;
		temp /= 2;
		carpan = (carpan*carpan) % md;
	}
	return ans;
}

ll ebob(ll a, ll b){
	if (!a)return b;
	return ebob(b%a, a);
}

ll ekok(ll x, ll y){
	return (x*y) / ebob(x, y);
}

ll comb(ll x, ll y){
	if (x < y) return 0;
	return fact[x] * ((fact2[x - y] * fact2[y]) % MOD) % MOD;
}














ll n, k;
ll res;
ll d ,m;
ll t = 1, x, y, p, q;
signed main(){

	IOS;
	//cin >> t;
	
	while (t--){
	
		cin >> n;
		vi vec(n+1); 
		ll mx = 0; 
		for (int a, i = 1; i <= n; i++){
			cin >> a;
			vec[i]=a;
			if (a > mx){
				mx = a;
			}
			else{
				res += (mx - a);

			}
		}
		cout << res << endl; 

		
	}
	


	getchar(); getchar();

	return 0;

}

/*
5
90 108
45 105
75 40
165 175
33 30


*/

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

int main(){
	int N;
	cin >> N;
	int pay = N * 800;
	int income = (N / 15) * 200;
	cout << pay - income << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n, t;
    cin>>n>>t;
    vector<LP> ab(n);
    cin>>ab;

    sort(rng(ab));

    vvl dp(n + 1, vl(t + 4000));
    rep(i, n) rep(j, t + 100) {
        chmax(dp[i + 1][j], dp[i][j]);
        chmax(dp[i + 1][j + ab[i].fi], dp[i][j] + ab[i].se);
    }

    vl rem;
    ll m = 0;
    ll ans = 0;
    for (int i = n - 1; i >= 0; --i) {
        chmax(ans, dp[i + 1][t - 1] + m);
        chmax(m, ab[i].se);
    }
    cout<<ans<<endl;
}

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

int main() {
    int A, B;
    cin >> A >> B;

    int minX, maxX, ans=-1;
    minX = min(A * 25 / 2, B * 10);
    maxX = max((A+1) * 25 / 2, (B+1) * 10);

    for (int x=minX; x<=maxX; x++) {
        if ((x * 8 /100 == A) && (x * 10 / 100 == B)) {
            ans = x;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
N, K = map(int, input().split())
mod = 998244353

LR = [tuple(map(int, input().split())) for _ in range(K)]
LR.sort()

dpsum = [0] * (N + 1)
dpsum[1] = 1
dp = [0] * (N + 1)
dp[1] = 1

for i in range(2, N + 1):
    for L, R in LR:
        l = i - R
        r = i - L
        
        if r < 0:
            continue
        l = max(l, 0)
        
        dp[i] += dpsum[r] - dpsum[l - 1]
        dp[i] %= mod
    dpsum[i] = dpsum[i - 1] + dp[i]

print(dp[N])


Measured memory_bytes: 27960
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    long long ans=0;
    for(int i=1;i<=n;i++)
    {
        if(i%3!=0 &&i%5!=0)
            ans+=i;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<(x)<<endl
#define ps(x) cout<<(x);
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define fi first
#define se second
ll a[101],b[101],c,d,n,m,x,y,z,h,w,sum,mi,ma,ans,s,t,l,r,res,tmp,itr,p,q;
bool flag;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int dx8[8]={1,1,0,-1,-1,-1,0,1},dy8[8]={0,1,1,1,0,-1,-1,-1};
char cha;
string st;
typedef map<ll, ll> imap;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<pair<ll,ll> > VP;


int main(void){
    cin>>n;
    imap odd,even;
    ll mae=0,mao=0,mase=0,maso=0;
    rep(i,n){
        cin>>tmp;
        if(i%2==0){
            even[tmp]++;
            if(even[tmp]>mae){mae=even[tmp];c=tmp;}
            if(c!=tmp)mase=max(mase,even[tmp]);
        }
        else{
            odd[tmp]++;
            if(odd[tmp]>mao){mao=odd[tmp];d=tmp;}
            if(d!=tmp)maso=max(maso,odd[tmp]);
        }
    }
    d(n)d(c)d(d)d(mae)d(mao)d(mase)d(maso)
    if(c!=d)p(n-mae-mao);
    else p(n-max(mae+maso,mase+mao));
    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define in insert
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    string s;
    cin >> s;
    for(int i = 0; i < s.size() -1 ; i++){
        if(s[i] == s[i+1]){
            cout << "Bad";
            return 0;
        }
    }
    cout << "Good";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int h,w;
    cin>>h>>w;

    vector<string> grid(h);
    REP(i,h){
        cin >> grid[i];
    }
    char tmpc;
    REP(i,h){
        REP(j,w){

            if(grid[i][j]=='.'){
                tmpc = '0';

                FOR(k,-1,2){
                    FOR(l,-1,2){
                        if(0<=i+k&&i+k<h&&0<=l+j&&l+j<w){
                            tmpc += (grid[i + k][l + j] == '#') ? 1 : 0;
                        }

                    }
                }
                grid[i][j] = tmpc;
            }
        }
    }
    REP(i,h){
        cout << grid[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define INF 1e9 + 7
#define cae cout << ans << endl;
#define cye cout << "Yes" << endl;
#define cne cout << "No" << endl;
#define r0 return 0;
#define ll long long
using namespace std;
typedef pair<int,int>P;
signed main() {
    string s;
    cin >> s;
    rep(i, s.size()) {
        if (i % 2 == 0) {
            cout << s[i];
        }
    }
    cout << endl;
    r0
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

	int n;
	cin >> n;
	vi a(n);
	rep(i, n)cin >> a[i];
	int ans = a[0];
	if (ans == 2) {
		cout << 1 << endl;
		return 0;
	}
	int cnt = 1;
	bool f = false;
	rep(i, a.size()) {
		ans = a[ans-1];
		cnt++;
		if (ans == 2) {
			f = true;
			break;
		}
	}
	if (f) {
		cout << cnt << endl;
	}
	else {
		cout << "-1" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
const ll INFLL=LLONG_MAX;
const int INF=INT_MAX;
#define eb emplace_back
#define emp emplace
#define mp(a,b) make_pair(a,b)
template<class T> using min_heap=priority_queue<T,vector<T>,greater<T> >;
template<class T>
void sort(vector<T>& v){
	sort(v.begin(),v.end());
}
template <class T, class U>
void sort(vector<T>& v,U func){
	sort(v.begin(),v.end(),func);
}
template <class T>
int lb_index(vector<T>& v,T k){
	return lower_bound(v.begin(),v.end(),k)-v.begin();
}
template <class T>
int ub_index(vector<T>& v,T k){
	return upper_bound(v.begin(),v.end(),k)-v.begin();
}
template<class T>
struct segtree{
	int n;
	function<T(T,T)> op;
	vector<T>arr;
	vector<T>st;
	void build(int lo,int hi,int u){
		if(lo==hi){
			st[u]=arr[lo];
		}
		else{
			int mi=(hi+lo)>>1;
			build(lo,mi,u<<1);
			build(mi+1,hi,u<<1|1);
			st[u]=op(st[u<<1],st[u<<1|1]);
		}
	}
	segtree(vector<T> v,function<T(T,T)> op):n(v.size()),st(v.size()*4),op(op){
		arr=v;
		build(0,n-1,1);
	}
	segtree(T n,function<T(T,T)> op):n(n),st(n*4),op(op){}
	T query(int lo,int hi,int u,int l,int r){
		if(l>r)return T();
		if(l==lo&&r==hi){
			return st[u];
		}
		int mi=(hi+lo)>>1;
		if(mi>r){
			return query(lo,mi,u<<1,l,r);
		}
		else if(mi<l){
			return query(mi+1,hi,u<<1|1,l,r);
		}
		else{
			return op(query(lo,mi,u<<1,l,mi),query(mi+1,hi,u<<1|1,mi+1,r));
		}
	}
	T query(int l,int r){
		return query(0,n-1,1,l,r);
	}
	T addupd(int lo,int hi,int u,int p,int x){
		if(lo==hi&&lo==p){
			return st[u]+=x;
		}
		int mi=(hi+lo)>>1;
		if(mi>=p){
			return st[u]=op(addupd(lo,mi,u<<1,p,x),st[u<<1|1]);
		}
		else if(mi<p){
			return st[u]=op(addupd(mi+1,hi,u<<1|1,p,x),st[u<<1]);
		}
	}
	T setupd(int lo,int hi,int u,int p,int x){
		if(lo==hi&&lo==p){
			return st[u]=x;
		}
		int mi=(hi+lo)>>1;
		if(mi>=p){
			return st[u]=op(addupd(lo,mi,u<<1,p,x),st[u<<1|1]);
		}
		else if(mi<p){
			return st[u]=op(addupd(mi+1,hi,u<<1|1,p,x),st[u<<1]);
		}
	}
	void add(int p,T x){
		addupd(0,n-1,1,p,x);
	}
	void set(int p,T x){
		setupd(0,n-1,1,p,x);
	}
//	void radd(int l,int r,T x){
//		
//	}
//	void rset(int l,int r,T x){
//		
//	}
	void add(int l,int r,T x){
		if(l==r)add(l,x);
//		else radd(l,r,x);
	}
	void set(int l,int r,T x){
		if(l==r)set(l,x);
//		else rset(l,r,x);
	}
};
int main(){
	int n,q;
	cin>>n>>q;
	segtree<int>t(n+1,[](int a,int b){
		return a+b;
	});
	while(q--){
		int c;
		cin>>c;
		if(c){
			int k;
			cin>>k;
			cout<<t.query(0,k-1)<<"\n";
		}
		else{
			int a,b,x;
			cin>>a>>b>>x;
			t.add(a-1,x);
			t.add(b,-x);
		}
	}
}



Measured memory_bytes: 4428
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<vector<vector<double>>> dp(n+1,vector<vector<double>>(n+1,vector<double>(n+1,0)));
  for(int i=0;i<=n;i++){
    for(int j=0;i+j<=n;j++){
      for(int k=0;i+j+k<=n;k++){
        if(i>0)
          dp[i][j][k]+=dp[i-1][j+1][k]*i/(i+j+k);
        if(j>0)
          dp[i][j][k]+=dp[i][j-1][k+1]*j/(i+j+k);
        if(k>0)
          dp[i][j][k]+=dp[i][j][k-1]*k/(i+j+k);
        if(i+j+k>0)
          dp[i][j][k]+=(double)n/(i+j+k);
      }
    }
  }
  int i=0;
  int j=0;
  int k=0;
  for(int x=0;x<n;x++){
    int a;
    cin>>a;
    if(a==3)
      i++;
    if(a==2)
      j++;
    if(a==1)
      k++;
  }
  cout<<fixed<<setprecision(16)<<dp[i][j][k]<<endl;
}

Measured memory_bytes: 216832
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
using namespace std;

const int INF = 1e9;
typedef long long ll;
#define MAX_N 1000001

int n;
bool isPrime[MAX_N];

void init(){
  for(int i = 0; i <= MAX_N; i++) isPrime[i] = true;
  isPrime[0] = isPrime[1] = false;
  for(int i = 2; i * i <= MAX_N; i++){
    if(isPrime[i]) for(int j = i * i; j <= MAX_N; j += i){
      isPrime[j] = false;
    }
  }
}

int main(void){
  init();
  while(cin >> n && n){
    int cnt = 0;
    for(int i = 2; i < n; i++){
      if(i <= n / 2 && isPrime[i] && isPrime[n-i]) cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 2136
length = input()
rtn = 0
li = list(map(int, input().split()))
for i, n1 in enumerate(li):
    if len(li) == i + 1:
        print(rtn)
        break
    for j, n2 in enumerate(li):
        if i >= j: continue
        rtn += n1 * li[j]

Measured memory_bytes: 2940
n = int(input())
nlist = list(map(int,input().split()))

for i in range(0,n):
    if nlist[i]%2 == 1:
        nlist[i] = 3

ansn = 0

for i in range(0,n):
    if nlist[i]%3 == 0 or nlist[i]%5 == 0:
        ansn += 1

if ansn == n:
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 3064
/*input
10 10
158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202
*/

// Nihesh Anderson - knandy

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

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#define endl '\n'
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{ll res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(ll* a, ll* b){shuffle(a,b,grndm);}

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	ll n, k; cin >> n >> k;
	vector<ll> a(n);
	for(ll i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll lo = 1, hi = 1000000000;
	while(lo <= hi) {
		ll mid = (lo + hi) >> 1;
		ll cnt = 0;
		for(ll i = 0; i < n; i++) {
			cnt += (a[i] - 1) / mid;
		}
		if(cnt > k) {
			lo = mid + 1;
		}
		else {
			hi = mid - 1;
		}
	}
	cout << lo << endl;
	return 0;
}




















Measured memory_bytes: 4760
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define N 310
using namespace std;
ll C[N][N],f[N][N],s[N][N];
int read()
{
	int x=0,f=1;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x*f;
}
int n,K,mod;
int main()
{
	n=read();K=read();mod=read();	
	C[0][0]=1;
	for(int i=1;i<=n;C[i][0]=1,i++)
		for(int j=1;j<=i;j++)
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	for(int j=0;j<=K;j++)
		f[1][j]=1,s[1][j]=K-j+1;
	for(int i=2;i<=n+1;i++)
	{
		for(int j=0;j<=K;j++)
			for(int k=1;k<i;k++)
				f[i][j]=(f[i][j]+f[i-k][j]*s[k][j+1]%mod*C[i-2][k-1])%mod;	
		for(int j=K;j>=0;j--)
			s[i][j]=(f[i][j]+s[i][j+1])%mod;
	}
	printf("%lld",f[n+1][0]);			
	return 0;
}

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



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
const double PI=3.14159265358979323846;

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







int main() {


  cout<<fixed<<setprecision(10);

  ll n; cin>>n;
  vint h(n); rep(i,n) cin>>h[i];

  ll max = (ll)1e10;
  vint dp(n, max);

  dp[0] = 0;
  rep(i,n){
    chmin(dp[min(n-1, i+1)], dp[i] + abs(h[min(n-1, i+1)] - h[i]));
    chmin(dp[min(n-1, i+2)], dp[i] + abs(h[min(n-1, i+2)] - h[i]));
  }

  cout<<dp[n-1]<<endl;

}

//


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Text;
using System.Diagnostics;
using static System.Math;
using static System.Array;

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{

    class Solve
    {
        const int mod = 1000000007;
        const int INF = 2147483647;
        const long SINF = 9223372036854775807;

        static int N;
        static List<Tuple<int, int>> X;
        
        
        

        public static void Input()
        {
            var cin = new Scanner();
            N = int.Parse(Console.ReadLine());
            X = new List<Tuple<int, int>>(N);
            var input = cin.SplitReader();
            for(var i = 0; i < N; i++)
            {
                X.Add(new Tuple<int, int>(input[i], i));
            }
        }

        static void Main(string[] args)
        {
            Input();

            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            X.Sort();
            int[] ans = new int[N];
            for(var i = 0; i < N; i++)
            {
                if (i <= (N / 2) - 1)
                {
                    ans[X[i].Item2] = X[N / 2].Item1;
                }
                else
                {
                    ans[X[i].Item2] = X[(N / 2) - 1].Item1;
                }
            }

            for(var i = 0; i < N; i++)
            {
                Console.WriteLine(ans[i]);
            }

            Console.Out.Flush();

        }





    }

    public class Scanner
    {
        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }

    }

    public class Graph
    {
        
    }
}

    



Measured memory_bytes: 41700
#include <bits/stdc++.h>
using namespace std;
 
pair<long long, long long> solve( int h, int w ) {
    if( h % 2 == 0 || w % 2 == 0 )
        return make_pair( 1LL * h * w / 2, 1LL * h * w / 2 );
    
    if( w < h )
        swap( w, h );
    
    return make_pair( 1LL * h * (w / 2), 1LL * h * (w / 2 + 1) );
}
 
int main( void ) {
    
    int h, w;
    cin >> h >> w;
    
    long long ans = 1e18;
    for( int i = 1; i < h; i ++ ) {
        pair<long long, long long> arr = solve( h - i, w );
        
        arr.first  = min( arr.first , 1LL * i * w );
        arr.second = max( arr.second, 1LL * i * w );
        
        ans = min( ans, arr.second - arr.first );
    }
    
    swap( h, w );
    
    for( int i = 1; i < h; i ++ ) {
        pair<long long, long long> arr = solve( h - i, w );
        
        arr.first  = min( arr.first , 1LL * i * w );
        arr.second = max( arr.second, 1LL * i * w );
        
        ans = min( ans, arr.second - arr.first );
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define LONGMAX 1e18
#define ll long long
#define dd double
#define MOD 1000000007
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define endl "\n"
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first	
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define INF 1e9
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
ll powe(ll x,ll y){ll res=1;while(y>0){if(y&1)res=res*x;y=y>>1;x=x*x;}return res;}
ll mpowe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
void ceilsearch(ll ar[],ll low,ll high,ll x,ll &y){ll mid=(low+high)/2;if(low>high)return;if(ar[mid]>=x){y=mid;ceilsearch(ar,low,mid-1,x,y);}else{ceilsearch(ar,mid+1,high,x,y);}}
int main()
{
	fastio();
	//#ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //freopen("outpu.txt","w",stdout);
    //#endif
	string s;
	cin>>s;
	ll N=s.size();
	for(ll i=0;i<N;i++)
	{
	    cout<<'x';
	}
}

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

using namespace std;
bool isPrime(long long n);


int main()
{
    ///////高速化///////
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    ///////////////////
    long long n;
    cin >> n;
    long long ans;

    for(int i=0;i<n;i++)
    {
        long long kari=0;
        cin >> kari;
        if(isPrime(kari)==true)
        {
            ans++;
        }
    }
    cout << ans << endl;
}

bool isPrime(long long n)
{
    if(n==2)
    {
        return true;
    }
    
    if(n<=1||n%2==0)
    {
        return false;
    }

    for(long long i=3;i*i<=n;i+=2)
    {
        if(n%i==0)
        {
            return false;
        }   
    }
    return true;
}


Measured memory_bytes: 3120
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class ABC151A
    {
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var t = NS.ToArray();
            t[0] = (char)(t[0] + 1);
            Console.WriteLine(new string(t));
        }
        static class Console_
        {
            static Queue<string> param = new Queue<string>();
            public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); }
        static long NN => long.Parse(Console_.NextString());
        static double ND => double.Parse(Console_.NextString());
        static string NS => Console_.NextString();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
    }
}
namespace Library {
}


Measured memory_bytes: 12768
import java.io.PrintWriter
import java.util.*

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = nextInt()
    val G = Graph(N)
    repeat(N - 1) { i ->
        val (a, b) = nextIntList()
        G.addEdgeTwoWay(a, b, i)
    }
    G.edgeColors()
}

class Graph(private val V: Int) {
    private val vec = Array(V + 1) { mutableListOf<Edge>() }

    fun addEdgeTwoWay(a: Int, b: Int, index: Int) {
        vec[a].add(Edge(b, index))
        vec[b].add(Edge(a, index))
    }

    fun edgeColors() {
        val colors = IntArray(V - 1) { 0 }
        val que = ArrayDeque<Triple<Int, Int, Int>>()
        que.addLast(Triple(1, 0, Int.MAX_VALUE))
        while (que.size > 0) {
            val (v, pv, pc) = que.removeFirst()
            var cc = 1
            for ((to, index) in vec[v]) {
                if (to == pv) continue
                if (cc == pc) cc++
                colors[index] = cc
                que.addLast(Triple(to, v, cc))
                cc++
            }
        }
        println(colors.max()!!)
        println(colors.joinToString("\n"))
    }

    data class Edge(val to: Int, val index: Int)
}

Measured memory_bytes: 76128
#include<iostream>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long double ld;
#define mp make_pair
#define pb push_back

#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)

#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)

const ll mod = 1e9 + 7;
// const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

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

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


int main() {
	char S[3];
	char T[3];
	rep(i, 3) {
		cin >> S[i];
	}
	ll ans = 0;
	rep(i, 3) {
		cin >> T[i];
		if (S[i] == T[i]) {
			ans++;
		}
	}

	cout << ans << endl;
	return 0;
}

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

int main() {
    int n;
    long long ans=0;
    cin >> n;
    string s,t;
    vector<char> a(10);
    map<string, int> p;


    for(int i=0; i<n; i++) {
        cin >> s;
        t="";
        for(int j=0; j<10; j++) {
            a[j]=s.at(j);
        }
        sort(a.begin(), a.end());
        for(int j=0; j<10; j++) {
            t=t+a[j];
        }
        if(p.count(t)) {
            p.at(t)++;
            ans+=p.at(t);
        }
        else {
            p[t]=0;
        }
    }
    cout << ans;
}

Measured memory_bytes: 11136
MOD = 10 ** 9 + 7
N = int(input())
memo = [{} for _ in range(N + 1)]


def isOK(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i], t[i - 1] = t[i - 1], t[i]
        if ''.join(t).count('AGC'):
            return False
    return True


def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == N:
        return 1
    ret = 0
    for c in 'ACGT':
        if isOK(last3 + c):
            ret = (ret + dfs(cur + 1, last3[1:] + c)) % MOD
    memo[cur][last3] = ret
    return ret


print(dfs(0, 'TTT'))


Measured memory_bytes: 3888
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, K = LI()
    ops = []
    for _ in range(N):
        a, b = LI()
        ops.append((a, b))
    ops = sorted(ops, key=lambda x: x[0])
    for op in ops:
        a, b = op
        if K - b <= 0:
            ans = a
            break
        K -= b
    print(ans)
main()



Measured memory_bytes: 21464
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		char s[] = scan.next().toCharArray();
		char zero_start[] = new char[s.length];
		char one_start[] = new char[s.length];

		int zero_count = 0;
		int one_count = 0;

		for (int i = 0; i < s.length; i++) {
			if (i % 2 == 0) {
				zero_start[i] = '0';
				one_start[i] = '1';
			}else {
				zero_start[i] = '1';
				one_start[i] = '0';
			}
		}

		for(int i = 0; i < s.length; i++) {
			if(s[i] != zero_start[i]) {
				zero_count++;
			}
			if(s[i] != one_start[i]) {
				one_count++;
			}
		}

		System.out.println(Math.min(zero_count, one_count));
	}
}

Measured memory_bytes: 26548
if __name__=="__main__":
    # Problem B
    N = int(input())
    A = [None]*N
    A = list(map(int, input().split(' ')))
    result = 1
    flag = False
    is_zero = False
    if 0 in A:
        print("0")
    else:
        for x in A:
            result = result * x
            if result > 1e18:
                flag = True
                break
        if flag:
            print("-1")
        else:
            print(result)
           
         

Measured memory_bytes: 22492
#include <stdio.h>
 
#define SIZE 50
 
int main(int argc, char *argv[]) {
  int h, w;
  scanf("%d %d\n", &h, &w);
  char map[SIZE][SIZE];
  for (int i = 0; i < h; ++i) {
    scanf("%s\n", map[i]);
  }
 
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (map[i][j] == '.') {
        int c = 0;
        if (0 < i) {
          if (map[i - 1][j] == '#') ++c;
          if (j < w - 1 && map[i - 1][j + 1] == '#') ++c;
          if (0 < j && map[i - 1][j - 1]== '#') ++c;
        }
        if (j < w - 1 && map[i][j + 1] == '#') ++c;
        if (0 < j && map[i][j - 1]== '#') ++c;
        if (i < h - 1) {
          if (map[i + 1][j] == '#') ++c;
          if (j < w - 1 && map[i + 1][j + 1] == '#') ++c;
          if (0 < j && map[i + 1][j - 1]== '#') ++c;
        }
        map[i][j] = c + '0';
      }
    }
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      printf("%c", map[i][j]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 128
N,M,Q=map(int,input().split())


Query=[]
answer=[[0]*N for i in range(N)]
for i in range(M):
  L,R=map(int,input().split())
  answer[N-L][R-1]+=1

for i in range(1,N):
  answer[0][i]+=answer[0][i-1]
  answer[i][0]+=answer[i-1][0]
  
for i in range(1,N):
  for j in range(1,N):
    answer[i][j]+=answer[i-1][j]
    answer[i][j]+=answer[i][j-1]
    answer[i][j]-=answer[i-1][j-1]
for i in range(Q):
  p,q=map(int,input().split())
  print(answer[N-p][q-1])
'''
for i in range(Q):
  answer=0
  Query=list(map(int,input().split()))
  for j in range(M):
    if train[j][0]>=Query[0] and train[j][1]<=Query[1]:
      answer+=1
  print(answer)
'''
  

Measured memory_bytes: 9348
#include<iostream>
using namespace std;
long n,k,i,t,a=0x7fffffffffffffff;
int main(){
    cin>>n>>k;
    long x[n];
    for(auto &d:x)cin>>d;
    for(;i<n-k+1;i++)t=labs(x[i]-x[i+k-1]),a=min(a,min(labs(x[i]),labs(x[i+k-1]))+t);
    cout<<a;
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main(void){

	int a,b,c;
	cin >> a >> b >>c;
	if(c>=a&&c<=b){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
# Selection Sort
N = int(input())
A = list(map(int, input().split()))
swapCnt = 0
for i in range(N):
    minNum = i
    for j in range(i, N):
        if A[j] < A[minNum]:
            minNum = j
    if minNum != i:
        A[minNum], A[i] = A[i], A[minNum]
        swapCnt += 1
print(' '.join(map(str, A)))
print(swapCnt)



Measured memory_bytes: 5600
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.*;

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

        long sum = 0;
        for (int i=1; i<=num; i++) {
            if (i % 5 == 0 || i % 3 == 0) continue;
            else sum+=i;
        }

        System.out.println(sum);
    }
}


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

int main(){
    int N, H[100], ans = 0;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> H[i];
    }
    for(int i = 0; i < N; i++){
        bool  isView = true;
        for(int j = 0; j < i; j++){
            if(H[j] > H[i]){
                isView = false;
                break;
            }
        }
        if(isView){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256