akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    int n;
	cin >> n;
    int a[n];
    int m=0;
    int x,y;
    fr(i,n){
     cin >> a[i];
     m+=abs(a[i]); 
    }
    sort(a,a+n);
    if(a[0]<0&&0<a[n-1]){
     cout <<m<< endl;
     int plus;
     fr(i,n){
       if(a[i]>0){
         plus = i;
         break;
       }
     }
     x = a[plus-1];
     y = a[plus];
     fr(i,n-1-plus){
       cout <<x<<" "<<y<< endl;
       x = x-y;
       y = a[plus+i+1];
     }
     x += y;
     y = x-y;
     x -= y;
     
     fr(i,plus){
       cout <<x<<" "<<y<< endl;
       x = x-y;
       y = a[i];
     }
    }else if(a[0]>=0){
      cout <<m-2*a[0]<< endl;
      x=a[0];
      y = a[1];
      fr(i,n-2){
       cout <<x<<" "<<y<< endl;
       x = x-y;
       y = a[i+2];
     }
     cout <<y<<" "<<x<< endl;
    }else{
      cout <<m+2*a[n-1]<< endl;
      x=a[n-1];
      y=a[0];
      fr(i,n-1){
       cout <<x<<" "<<y<< endl;
       x = x-y;
       y = a[i+1];
      }
   }
}


Measured memory_bytes: 2304
def main():
    mochi = int(input())
    list = []
    dic = {}
    for i in range(mochi):
        list.append(input())
    list.sort()
    list.reverse()
    for j in range(len(list)):
        if list[j] not in dic:
            dic[list[j]] = 'mochi' + list[j] + 'cm'
    print(len(dic))
main()

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	const int mod=1e9+7;
	int64_t n,k; cin>>n>>k;
	int64_t mn=(k-1)*k/2, mx=(n+(n-k+1))*k/2;
	int64_t ans=0;
	while(mx>=mn){
		mx=(n+(n-k+1))*k/2;
		ans+=mx-mn+1;
		ans=ans%mod;
		mn=(k+1)*k/2;
		++k;
	}
	cout<<ans<<"\n"s;
}

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

ll gcd(ll a, ll b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

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



int main(){
  int N;
  cin >> N;
  vector<ll> A(N);
  for(int i = 0; i<N; i++){
    cin >> A.at(i);
  }
  ll ans = 0;
  for(int i = 0; i< N; i++){
    ans += A.at(i) -1;
  }


  //
  // ll ha = 1;
  // for(int i = 0;i<N; i++){
  //   ha = lcm(ha, A.at(i));
  // }
  // ll ans = 0;
  // ll waru = ha-1;
  // for(int i= 0; i<N; i++){
  //   ans += waru % A.at(i);
  // }
  cout << ans << endl;


}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int x;
    cin >> x;
    for (int i = 1; i <= x; ++i) {
        if(x-i*100 <= i*5 && x-i*100 >= 0){
            puts("1");
            return 0;
        }
    }
    puts("0");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
    double r;
    const double PI = atan(1.0) * 4.0;
    cin >> r;

    cout << fixed << setprecision(15) << r * r * PI << ' ' << 2 * r * PI << endl;
} 



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



int main()
{
	int x, y;
	while (cin >> x >> y){
		if (x == 0 && y == 0){
			break;
		}
		cout << min(x, y) <<" "<< max(x, y)<< endl;
	}

	return 0;
}

Measured memory_bytes: 1160
/**
 * Created by hiramekun at 16:20 on 2019-09-17.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n;
    string s;
    cin >> n >> s;

    vvl dp(n + 1, vl(n + 1)); // dp[i][j]: sのi番目とj番目から始める文字列が一致する最大の長さ
    ll ans = 0;
    dp[0][0] = 1;
    rep(i, n) {
        rep(j, n) {
            if (s[i] == s[j]) {
                dp[i + 1][j + 1] = min(j - i, dp[i][j] + 1);
            }
            ans = max(ans, dp[i + 1][j + 1]);
        }
    }
    cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 195840
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 20 21:10:32 2019

@author: yama
"""

n = int(input())
l = [-1] + list(map(int, input().split()))

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

for i in range(n, 0, -1):
    c = n//i
    s = 0
    for j in range(1, c+1):
        s += ll[i*j]
    if l[i] == 0:
        if s % 2 == 0:
            ll[i] = 0
        else:
            ll[i] = 1
    else:
        if s % 2 == 0:
            ll[i] = 1
        else:
            ll[i] = 0
              
m = ll.count(1)
print(m)
lll = []
for i in range(1, len(ll)):
    if ll[i] == 1:
        lll.append(i)
        
print(' '.join(map(str, lll)))

Measured memory_bytes: 20528
#include <bits/stdc++.h>
using namespace std;
int N,kazu,naga,onp;
char moto[50],saga[150];
int main(){
    cin>>N;
    scanf("%s",&moto);
    onp=strlen(moto);
    for(int i=0;i<N;i++){
        scanf("%s",saga);
        naga=strlen(saga);
        for(int j=0;j<naga;j++){
            int aho=0;
            if(saga[j] == moto[0]){
                for(int k=1;k<naga;k++){
                    for(int l=1;l<naga;l++){
                        if(j+(k*l)>=naga||saga[j+(k*l)]!=moto[l])break;
                        if(l==onp-1){
                            kazu++;
                            aho=1;
                        }if(aho==1)break;
                    }if(aho==1)break;
                }if(aho==1)break;
            }if(aho==1)break;
        }
    }
    cout<<kazu<<endl;
}

Measured memory_bytes: 3240
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    static const int MAXN=310;
    int N;
    ll A[MAXN][MAXN];
    int mark[MAXN][MAXN];
    void solve(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin>>N;
        for(int u=1;u<=N;u++){
            for(int v=1;v<=N;v++){
                cin>>A[u][v];
            }
        }
        for(int k=1;k<=N;k++){
            for(int u=1;u<=N;u++){
                for(int v=1;v<=N;v++){
                    if(u==v||k==u||k==v)continue;
                    if(A[u][v]==A[u][k]+A[k][v])mark[u][v]=true;
                    else if(A[u][v]>A[u][k]+A[k][v]){
                        cout<<-1;
                        return;
                    }
                }
            }
        }
        ll ans=0;
        for(int u=1;u<=N;u++){
            for(int v=1;v<=N;v++){
                if(!mark[u][v])ans+=(ll)A[u][v];
            }
        }
        cout<<ans/2;
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

Measured memory_bytes: 1920
n, l = map(int,input().split())
s = []
cnt = 0
min_apple = 9999
sub_apple = 0
for i in range(n):
    s.append(l + i)
    if min_apple > abs(l + i):
        min_apple = abs(l + i)
        sub_apple = s[i]
print(sum(s) - sub_apple)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <functional>
#include <utility>
#include <algorithm>
#include <iomanip>

using Pair = std::pair<int, int>;
constexpr int infl = 1e+9;

int n;
int cost[11][11];

bool func() {
    std::fill(cost[0], cost[0] + sizeof(cost) / sizeof(int), infl);
    
    std::cin >> n;
    
    if(n == 0)
        return false;
    
    int from, to, c;
    int tMax = 0;
    for(int i = 0; i < n; ++i) {
        std::cin >> from >> to >> c;
        
        cost[from][to] = c;
        cost[to][from] = c;
        cost[to][to] = 0;
        cost[from][from] = 0;
        
        tMax = std::max({tMax, to, from});
    }
    ++tMax;
    
    for(int i = 0; i < tMax; ++i)
        for(int j = 0; j < tMax; ++j)
            for(int k = 0; k < tMax; ++k) {
                cost[j][k] = std::min(cost[j][k], cost[j][i] + cost[i][k]);
            }
    
    int costMin = infl, idx = 0;
    for(int i = 0; i < tMax; ++i) {
        int sum = 0;
        
        for(int j = 0; j < tMax; ++j) {
            sum += cost[i][j];
        }
        
        if(costMin > sum) {
            idx = i;
            costMin = sum;
        }
    }
    
    std::cout << idx << " " << costMin << std::endl;
    
    return true;
}

int main() {
    while(func());
}

Measured memory_bytes: 3076
import numpy as np

#N,M,Cの入力
N, M, C = map(int, input().split())

#Bの入力
B = [int(x) for x in input().split()]
B = np.array(B)

#Aの入力
A = []
for n in range(N):
  A.append([int(x) for x in input().split()])
A = np.array(A)

#行列計算
D = np.dot(A,B)+C

#判定
n = 0
for d in D:
  if d>0:
    n += 1
print(n)

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

const int N=100;
int n;
int a[N*2+100];

int main()
{
	//freopen("input.txt","r",stdin);
	
	scanf("%d",&n);
	for (int i=1;i<=2*n;i++)
	    scanf("%d",&a[i]);
	
	sort(a+1,a+2*n+1);
	
	int sol=0;
	for (int i=1;i<=n;i++)
	    sol+=a[2*i-1];
	
	printf("%d\n",sol);
	
	return 0;
}

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

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: 3600
#include<bits/stdc++.h>

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;


int main(){
    long long H,N;
    cin>>H>>N;
    long long sum=0;

    rep(i,N){
        long long a;
        cin>>a;
        sum+=a;
    }

    if(sum>=H){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    
    return 0;

}
/*


*/


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

char banmen[5000];

const int line_block_num[32]={
	0,
	1,
	1,2,
	1,2,2,3,
	1,2,2,3,2,3,3,4,
	1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5
};

int main(void) {
	int block_num;
	int i,j;
	int btype,blength,bpos;
	char block;
	int nowpos;
	int result;
	while(1) {
		scanf("%d",&block_num);
		if(block_num==0)break;
		memset(banmen,0,sizeof(banmen));
		for(i=0;i<block_num;i++) {
			scanf("%d%d%d",&btype,&blength,&bpos);
			if(btype==1) {
				block=31>>(5-blength);
				block<<=(4-(bpos-1))-(blength-1);
			} else {
				block=1<<(4-(bpos-1));
			}
			for(nowpos=1;nowpos<5000;nowpos++) {
				if(banmen[nowpos] & block)break;
			}
			if(btype==1) {
				banmen[nowpos-1]|=block;
			} else {
				for(j=0;j<blength;j++) {
					banmen[nowpos-1-j]|=block;
				}
			}
			for(nowpos=5000-1;nowpos>=0;nowpos--) {
				if((banmen[nowpos] & 31)==31) {
					banmen[nowpos]=0;
					for(j=nowpos;j>0;j--) {
						banmen[j]=banmen[j-1];
					}
					nowpos++;
				}
			}
		}
		result=0;
		for(i=0;i<5000;i++)result+=line_block_num[banmen[i]];
		printf("%d\n",result);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
//#include "atcoder/all"
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
const ll mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  // a * b + c = n

  ll ans = 0;

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (n - i * j > 0)
        ans++;
      else
        break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3680
// #include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
// #include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), greater<type>())
#define SORTF(a, comp) sort(ALL(a), comp)
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a, type) ((type)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) (lower_bound(ALL(a), (x)) - a.begin())
#define bisect_right(a, x) (upper_bound(ALL(a), (x)) - a.begin())
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUT2(a) REPx(&x, a) INPUT(x);
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define ENDL cout << endl;

// const int INF = 2e9;
const LL INF = 9e18;
const LL MOD = 1e9+7;

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, greater<T> >;
template<class T> inline bool chmin(T &a, T b){if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){if (a < b) {a = b; return true;} return false;}
template<class T> inline void debug1(V<T> A){REP(int, i, SIZE(A, int)){if (A[i] == INF) cout << "I ";else cout << A[i] << " ";}ENDL}
template<class T> inline void debug2(VV<T> A){REP(int, i, SIZE(A, int)){REP(int, j, SIZE(A[i], int)){if (A[i][j] == INF) cout << "I "; else cout << A[i][j] << " ";}ENDL}}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  LL a, b, c;
  cin >> a >> b >> c;
  if (c-a-b <= 0) cout << "No" << endl;
  else if (4*a*b < (c-a-b)*(c-a-b)) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

int main()
{
  int N, X;
  cin >> N >> X;

  int minm = 1000;
  for(int i = 0; i < N; ++i) {
    int m;
    cin >> m;

    X -= m;
    minm = min(minm, m);
  }

  cout << N + (X / minm) << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define X first
#define Y second

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int w, h;
vs m;
int dx[] = {-1, 0, 1, 0};
int dy[] = { 0,-1, 0, 1};

void dfs(char tar, pii p);

int main(void){
    for(; cin >> w >> h, w;){
        m = vs(h);
        rep(y, h) cin >> m[y];

        rep(y, h) rep(x, w) if(m[y][x] == 'B'){
            rep(i, 4){
                dfs('B', mp(x + dx[i], y + dy[i]));
            }
        }
        rep(y, h) rep(x, w) if(m[y][x] == 'W'){
            rep(i, 4){
                dfs('W', mp(x + dx[i], y + dy[i]));
            }
        }

        pii sum = mp(0, 0);
        rep(y, h) sum.first += count(all(m[y]), 'b');
        rep(y, h) sum.second += count(all(m[y]), 'w');

        cout << sum.first << " " << sum.second << endl;
    }

	return 0;
}

void dfs(char tar, pii p){
    if(p.X < 0 || w <= p.X ||
       p.Y < 0 || h <= p.Y) return;

    char ene = tar == 'B' ? 'W':'B';
    char extar = tar == 'B' ? 'b':'w';
    char exene = tar == 'B' ? 'w':'b';

    if(m[p.Y][p.X] == ene || m[p.Y][p.X] == extar || m[p.Y][p.X] == '-' ||
       m[p.Y][p.X] == tar)
        return;

    if(m[p.Y][p.X] == '.') m[p.Y][p.X] = extar;
    if(m[p.Y][p.X] == exene) m[p.Y][p.X] = '-';

    rep(i, 4){
        dfs(tar, mp(p.X + dx[i], p.Y + dy[i]));
    }
}

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

typedef long long ll;

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

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n;
	ll k;
	cin >> n >> k;
	ll count[100001];
	FOR(i,0,100001)count[i] = 0;
	FOR(i,0,n){
		int a,b;
		cin >> a >> b;
		count[a] += b;
	}
	FOR(i,1,100001){
		if(count[i] >= k){
			ANS(i);
			return 0;
		}
		k -= count[i];
	}
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

ll digit_sum(ll b,ll n){
  if(n<b)return n;
  return digit_sum(b,n/b) + n%b;
}

ll solve(ll n, ll s){
  ll b = 2;
  ll pre = -1;
  while(pre!=n/b){
    if(digit_sum(b,n) == s) return b;
    pre = n/b;
    b++;
  }
  perr(m, 1, pre+1){
    ll l = n/m, r = n/(m+1);
    //cout << m SP l SP r << endl;
    while(l-r>1){
      b = (l+r)/2;
      ll d = digit_sum(b,n);
      //cout << b SP d << endl;
      if(d == s) return b;
      else if(d>s) r = b;
      else l = b;
    }
    if(digit_sum(l,n) == s) return l;
  }
  if(n==s) return n+1;
  return -1;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  ll n,s;cin >> n >> s;
  cout << solve(n,s) << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
using namespace std;
 
class UnionFind {
public:
  vector<long long> par;
  vector<long long> size;
  
  UnionFind(long long N) : par(N), size(N,1) {
    for(long long i=1; i<N; i++) {
      par[i] = i;
    }
  }
 
  long long root(long long x) {
    while(par[x] != x) {
      x = par[x];
    }
    return x;
  }
 
  void unite(long long x, long long y) {
    long long rx = root(x);
    long long ry = root(y);
    if(size[ry]<=size[rx]) {
      size[rx] += size[ry];
      par[ry] = rx;
    } else {
      size[ry] += size[rx];
      par[rx] = ry;
    }
  }
  
  bool same(long long x, long long y) {
    long long rx = root(x);
    long long ry = root(y);
    return rx == ry;
  }
  
  long long siz(long long x) {
    return size[root(x)];
  }
};
 
int main() {
  long long N, M;
  cin >> N >> M;
  
  vector<vector<long long>> stock(M, vector<long long>(2, 0));
  vector<long long> ans(M, 0);
  
  for(long long i=0; i<M; i++) {
    long long a, b;
    cin >> a >> b;
    stock[i][0] = a-1;
    stock[i][1] = b-1;
  }
  
  UnionFind uf(N);
  ans[M-1] = N*(N-1)/2;
  
  for(long long i=M-1; i>0; i--) {
    long long a = stock[i][0];
    long long b = stock[i][1];
    if(uf.same(a,b)) {
      ans[i-1] = ans[i];
    } else {
      ans[i-1] = ans[i] - uf.siz(a) * uf.siz(b);
      uf.unite(a,b);
    }
  }
  
  for(auto a:ans) {
    cout << a << endl;
  }
  
  return 0;
}

Measured memory_bytes: 9088
// minpro2019_C
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    ll K, A, B;
    cin >> K >> A >> B;
    
    // calculation
    if (K == 1) {
        // ビスケットを叩いて＋１で２枚
        cout << 2 << "\n";
    } else if (K == 2) {
        // たたくのみ or 1回交換する
        // B = 1 でも良い．どうせ増やせないから
        cout << std::max(ll(1+2), B) << "\n";
    } else if (K >= 3){
        ll bis = 1;
        if (K < A - bis + 2) {
            // 1回も交換できないとき
            cout << 1 + K << "\n";
        } else if (K == A - bis + 2) {
            // ぴったり1回だけ交換できるとき
            cout << max(1+K, B) << "\n";
        } else {
            // 1回以上交換できるとき
            // 1回目
            bis = max(1 + (A-1) + 2, B);
            K -= (A - 1) + 2;
            // 2回目以降
            if (A + 2 >= B) {
                // 交換が得じゃないとき
                cout << bis + K << "\n";
            } else {
                // 交換が得なとき: (A + 2) < B
                ll yen = 0;
                while (K >= 2) {
                    if (K >= 2 && bis >= A) {
                        // 2回分使って交換
                        bis += B - A;
                        K -= 2;
                    } else if (K >= 2 && bis < A) {
                        // ビスケットがA枚未満
                        bis++;
                        K--;
                    } else if (K < 2){
                        bis++;
                        K--;
                    }
                }
                cout << bis + K << "\n";
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace Sample101
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var line = Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToArray();
                if (line[0] == 0 && line[1] == 0)
                {
                    return;
                }
                if (line[0] > line[1])
                {
                    var temp = line[0];
                    line[0] = line[1];
                    line[1] = temp;
                }
                Console.WriteLine(line[0] + " " + line[1]);
            }
        }
    }
}


Measured memory_bytes: 16388
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
const ll MAX = 2*(ll)pow(10, 5);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll a, b, k; cin >> a >> b >> k;
  ll tmp = 0;
  for (ll i = min(a, b); i >= 1; i--) {
    if (a%i==0 && b%i==0) tmp++;
    if (tmp == k) {
      cout << i << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
//const n = +input[0];
//const a = [];
//for(let i=0;i<n;i++){
//	a.push(input[i+1].split(" ").map((x:string):number=>+x));
//}

//const [n, m] = input[0].split(" ").map((x: string): number => +x);
//const a = input[1].split(" ").map((x: string): number => +x);

function compareFunc(a, b){
    return a-b;
}

const [a, b]: number[] = input[0].split(' ').map((x: string): number => +x);

if((a+b) % 2 === 0){
    console.log((a+b)/2);
}else{
    console.log('IMPOSSIBLE');
}

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
vector<int> quq;
int main(){
	long long n,a,i,pos,ans=0,sz;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a;
		quq.push_back(a);
	}
	sort(quq.begin(),quq.end());
	for(i=0;i<quq.size();)
	{
		pos=upper_bound(quq.begin(),quq.end(),quq[i])-quq.begin();
		sz=pos-i;
		if(sz<quq[i])
		{
			ans+=sz;
		}
		else
		{
			ans+=sz-quq[i];
		}
		i=pos;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int num;  int n,s;
void dfs(int i,int sum,int dp){
  if(sum>s)
    return;
  if(dp==n){
    if(sum==s){
      num++;
      return;
    }else
      return;
  }
  for(int j=i+1;j<=9;j++)
    dfs(j,sum+j,dp+1);
}
int main(){
  while(cin>>n>>s,n+s!=0){
    num=0;
    for(int i=0;i<=9;i++)
      dfs(i,i,1);
    cout<<num<<endl;
  }
  return 0;
}

Measured memory_bytes: 3072
// In god we trust
 
#include <bits/stdc++.h>
#include <chrono>
#include <algorithm>
#include <signal.h>
#include <thread>
 
#define pb push_back
#define fi first
#define se second
#define Vi vector<int>
#define Vb vector<bool>
#define Pi pair<int, int>
#define MP make_pair
#define MT make_tuple
#define Q queue
#define Qi Q<int>
#define INF 1000000000 
#define LINF 1000000000000000000
#define int long long
using namespace std;
using namespace std::chrono;



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

  string s;
  string t;
  cin >> s >> t;
  bool could = true;
  if (s.size() == t.size() - 1){
    for (int i = 0; i < s.size(); i++)
      if(s[i] != t[i]){
	could = false;
	break;
      }
    if(could)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  else
    cout << "No" << endl;
}


Measured memory_bytes: 3636
package main

import "fmt"

func main() {
	var N, M int
	fmt.Scan(&N, &M)

	light := make(map[int]map[int]struct{})

	for i := 1; i <= M; i++ {
		var K int
		fmt.Scan(&K)
		light[i] = make(map[int]struct{})
		var tmp int
		for j := 0; j < K; j++ {
			fmt.Scan(&tmp)
			light[i][tmp] = struct{}{}
		}
	}

	p := make(map[int]int)
	for i := 1; i <= M; i++ {
		var tmp int
		fmt.Scan(&tmp)
		p[i] = tmp
	}

	ans := 0
	for i := 0; i < (1 << uint(N)); i++ {
		good := true
		for m := 1; m <= M; m++ {
			count := 0
			for j := 0; j < N; j++ {
				if i&(1<<uint(j)) > 0 {
					if _, ok := light[m][j+1]; ok {
						count++
					}
				}
			}
			if (count % 2) != p[m] {
				good = false
				break
			}
		}
		if good {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define debug(x) cerr<<#x<<" = "<<x
#define sp <<"  "
#define el <<endl
#define fgx cerr<<"-----------------------------------"<<endl
#define LL long long
#define M
using namespace std;
namespace IO{
	const int BS=(1<<23)+5; int Top=0;
	char Buffer[BS],OT[BS],*OS=OT,*HD,*TL,SS[20]; const char *fin=OT+BS-1;
	char Getchar(){if(HD==TL){TL=(HD=Buffer)+fread(Buffer,1,BS,stdin);} return (HD==TL)?EOF:*HD++;}
	void flush(){fwrite(OT,1,OS-OT,stdout),OS=OT;}
	void Putchar(char c){*OS++ =c;if(OS==fin)flush();}
	void write(int x){
		if(!x){Putchar('0');return;} if(x<0) x=-x,Putchar('-');
		while(x) SS[++Top]=x%10,x/=10;
		while(Top) Putchar(SS[Top]+'0'),--Top;
	}
	int read(){
		int nm=0,fh=1; char cw=getchar();
		for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
		for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
		return nm*fh;
	}
}using namespace IO;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n=read(),a=read(),b=read(),t1=0,t2=0,t3=0;
	while(n--){
		int x=read();
		if(x<=a) t1++;
		else if(x<=b) t2++;
		else t3++;
	}
	printf("%d\n",min(min(t1,t2),t3));
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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; }

using namespace std;

int main(){
    int A[34] = {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};
    int K;
    cin >> K ;
    cout << A[K-1] << endl;

}


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

int main(void){
	int N;
	cin >> N;
	long long ans=0;
	string S[N];
	long long a = 0;
	long long b = 0;
	long long c = 0;
	for(int i=0;i<N;i++)cin >> S[i];
	for(int i=0;i<N;i++){
		if(S[i][S[i].size()-1]=='A'&&S[i][0]=='B')c++;
		else if(S[i][S[i].size()-1]=='A')a++;
		else if(S[i][0]=='B')b++;
		for(int j=0;j<S[i].size()-1;j++){
			if(S[i][j]=='A'&&S[i][j+1]=='B'){
				ans++;
			}
		}
	}
	/*
	cout << "c = " << c << endl;
	cout << "a = " << a << endl;
	cout << "b = " << b << endl;
	*/
	//a c c c c b という並びが最大になる
	//ab ab ab c c c c c よりも
	//ab ab ac c c c cb;の方が多い
	if(a>0&&c>0&&b>0){
		a--;
		ans += c+1;
		c = 0;
		b--;
	}else if(a>0&&c>0){
		ans += c;
	}else if(b>0&&c>0){
		ans += c;
	}else if(c>0){
		ans += c-1;
	}
	ans += min(a,b);
	cout << ans << endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int a,b,x;
    cin>>a>>b>>x;
    cout<<fixed<<setprecision(20)<<atan(2*x<a*a*b?a*b*b/(2.*x):2.*(a*a*b-x)/(a*a*a))*180/M_PI<<endl;
}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long X, K, D;
  cin >> X >> K >> D;
  if (X < 0) X = -X;
  long long steps = X / D, rem = X % D;
  if (steps >= K) {
    cout << X - K * D << '\n';
  } else {
    long long rem_steps = K - steps;
    cout << (rem_steps % 2 == 0 ? rem : abs(rem - D)) << '\n';
  }
  return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int mn=4*100000;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        int temp;
        cin >> temp;
        if(temp<mn)
        ++ans;
        mn=min(mn,temp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
<?php

fscanf(STDIN, '%d %d', $N, $D);

$count = 0;

for ($i=0; $i < $N; $i++) {
    fscanf(STDIN, '%d %d', $x, $y);
    $dist = sqrt(pow($x, 2) + pow($y, 2));

    if ($dist <= $D) {
        $count++;
    }
}

echo $count;

echo PHP_EOL;


Measured memory_bytes: 16192
n=int(input())
l =1
r=1
for _ in range(n):
    t,a=map(int,input().split())
    l = (l+t-1)//t*t
    r = (r+a-1)//a*a
    l = max(l,r//a*t)
    r = max(r,l//t*a)
print(r+l)

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

int main(void){
    int N;
    cin >> N;
    switch(N % 10){
        case 0:
        case 1:
        case 6:
        case 8:
            cout << "pon" << endl;
            break;
        case 3:
            cout << "bon" << endl;
            break;
        default:
            cout << "hon" << endl;
            break;
    }
    return 0;
}

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

struct UnionFind{
    vector<int> par;
    vector<int> dep;

    UnionFind(int siz){
        par.assign(siz,0);
        dep.assign(siz,0);
        for(int i = 0; i < siz; i++){
            par[i] = i;
        }
    };

    int find(int x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(dep[x] < dep[y]) par[x] = y;
        else{
            par[y] = x;
            if(dep[x] = dep[y]) dep[x]++;
        }
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> side(m, vector<int>(2));
    
    for(int i = 0; i < m; i++){
        cin >> side[i][0] >> side[i][1];
        side[i][0]--, side[i][1]--;
    }

    int ans = 0;
    for(int i = 0; i < m; i++){
        UnionFind uf(n);
        for(int j = 0; j < m; j++){
            if(i != j) uf.unite(side[j][0], side[j][1]);
        }
        if(!uf.same(side[i][0], side[i][1])) ans++;
    }

    cout << ans << endl;
}

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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}


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

  lint ans=0;
  vector<lint> b(n+1,0);
  for(lint i=0;i<n;i++) {
    if(a[i] <= n) { b[a[i]]++; }
    else { ans++; }
  }

  for(lint i=1;i<=n;i++) {
    if(b[i] == i) { continue; }
    else if(b[i] > i) { ans += b[i]-i; }
    else if(b[i] < i) { ans += b[i]; }
  }

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

Measured memory_bytes: 1792
#include<iostream>
#include<string>
using namespace std;
const int BUF = 55;


int szA, szB;
string A[BUF], B[BUF];

void read() {
    cin >> szA >> szB;
    for (int i = 0; i < szA; ++i) {
        cin >> A[i];
    }
    for (int i = 0; i < szB; ++i) {
        cin >> B[i];
    }
}


void work() {
    for (int ar = 0; ar + szB <= szA; ++ar)
        for (int ac = 0; ac + szB <= szA; ++ac) {
            for (int br = 0; br < szB; ++br) {
                for (int bc = 0; bc < szB; ++bc) {
                    if (A[ar + br][ac + bc] != B[br][bc]) {
                        goto _fail;
                    }
                }
            }
            cout << "Yes" << endl;
            return;
            _fail:;
        }
    cout << "No" << endl;
}


int main() {
    read();
    work();
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 44

int n[N];

int Fibonacci(int j){
  if(n[j] == NULL){
    if(j == 0 || j == 1) n[j] = 1;
    else n[j] = Fibonacci(j-1) + Fibonacci(j-2);
  }
  return n[j];
}
int main(){
  int i;
  scanf("%d", &i);
  printf("%d\n", Fibonacci(i));
  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int p[10000],k;
void init()
{
    k=0;
    for(int i=2;i<=55555;i++)
    {
        int flag=1;
        for(int j=2;j*j<=i;j++)
        {
            if(i%j==0)
            {
                flag=0;
                break;
            }
        }
        if(flag&&i%10==3&&i!=3)
        {
            p[k++]=i;
        }
    }
}
int main()
{
    init();
    int n;
    scanf("%d",&n);
    printf("3");
    for(int i=0;i<n-1;i++)
    {
        printf(" %d",p[i]);
    }
    printf("\n");
}


Measured memory_bytes: 256
//Resting_Prince
#include<bits/stdc++.h>
#define mod 1000000007
#define inf 1e18
#define PI 3.141592653589
#define fi first
#define se second 
#define sv(v) sort(all(v));reverse(all(v))
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mk make_pair
#define en '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double ld;

int main()
{
    ll n,k,a[200005],c[2003]={0};
    cin>>n>>k;
    rep(i,0,n-1)cin>>a[i];
    ll j,l=0,o=0;
    rep(i,0,n-1)
    {
        rep(j,0,n-1)
        {
            if(i==j)continue;
            if(a[i]>a[j])
            {
                if(i>j)
                    l=(l+((k*(k-1))/2))%mod;
                else
                    l=(l+((k*(k+1))/2))%mod;
            }
        }
    }
    cout<<(l+mod)%mod;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define maxn 1000000

int S[maxn];

int main( void ) {
	int n, l;
	scanf("%i %i", &n, &l);
	
	for( int i = 1; i <= n; i++ ) {
		scanf("%i", &S[i]);
	}
	
	int lidx = -1, ridx = -1;
	for( int i = 1; i < n; i++ ) {
		if( (long long)S[i] + S[i+1] >= l ) {
			lidx = i;
			ridx = i+1;
			break;
		}
	}
	
	if( lidx != -1 ) {
		puts("Possible");
		for( int i = 1; i < lidx; i++ ) {
			printf("%i\n", i);
		}
		for( int i = n-1; i >= ridx; i-- ) {
			printf("%i\n", i);
		}
		
		printf("%i\n", lidx);
	} else {
		puts("Impossible");
	}
	
	return 0;
}

Measured memory_bytes: 1152
# B
n = int(input())
a = [0]
for i in range(n):
    a.append(int(input()))
    
i = 1
ans = 0
while True:
    ans += 1
    if a[i] == 2:
        print(ans)
        break
    if ans > len(a):
        print(-1)
        break
    i = a[i]

Measured memory_bytes: 7080
#include <iostream>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

typedef complex<double> Vector;

struct Circle {
    Vector center;
    double r;

    pair<Vector,Vector> intersection(const Circle &c) const {
        const double d = abs(c.center - center);
        const double cos_ = (d*d + r*r - c.r*c.r) / (2*d);
        const double sin_ = sqrt(r*r - cos_*cos_);
        const Vector e = (c.center - center) / d;
        return make_pair(center + e*Vector(cos_, sin_), center + e*Vector(cos_, -sin_));
    }

    inline bool intersects(const Circle &c) const {
        return norm(center-c.center) <= pow(r+c.r, 2);
    }

    inline bool contains(const Circle &c) const {
        return abs(center-c.center)+c.r <= r;
    }

    inline bool contains(const Vector &v) const {
        return abs(center-v) <= r;
    }
};

int main() {
    while(true) {
        int N;
        cin >> N;
        if(!N) break;

        vector<Circle> circles(N);
        for(int i = 0; i < N; ++i) {
            double x, y;
            scanf("%lf,%lf", &x, &y);
            circles[i].center = Vector(x, y);
            circles[i].r = 1;
        }
        int ans = 1;
        for(int i = 0; i < N; ++i) {
            const Circle c1 = circles[i];
            for(int j = 0; j < i; ++j) {
                const Circle c2 = circles[j];
                if(!c1.intersects(c2)) continue;
                pair<Vector,Vector> vs = c1.intersection(c2);
                int cnt1 = 0, cnt2 = 0;
                for(int k = 0; k < N; ++k) {
                    if(i == k || j == k) continue;
                    if(circles[k].contains(vs.first)) ++cnt1;
                    if(circles[k].contains(vs.second)) ++cnt2;
                }
                ans = max(ans, max(cnt1, cnt2)+2);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1296
#include <cstdio>
#include <cstring>

int main()
{
  static char s[200010];
  scanf("%s",s);
  int c=0,n=strlen(s);
  int S=0;
  for(int i=0;i<n;i++){
    if(s[i]=='S'){
      S++;
    }
    else{
      if(S>0){
	S--;
	c++;
      }
    }
  }
  printf("%d\n",n-2*c);
  return 0;
}


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

int main()
{
    int a[300009], n, i;
    cin >> n;

    for(i = 0; i < 3*n; i++)
        cin >> a[i];

    sort(a, a+3*n);

    long long ans = 0;
    for(i = 3*n-2; i >= n; i -=2)
        ans = ans + a[i];

    cout << ans;
}


Measured memory_bytes: 4772
s = input()
l = [0, 4, 6, 8]
for i in range(16):
    st = list('AKIHABARA')
    for j in range(4):
        if (i >> j) & 1:
            st[l[j]] = ''
    if s == ''.join(st):
        print('YES')
        exit(0)
print('NO')

Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		int[] h = new int[n];

		int index = 0;
		for (int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			h[i] = sc.nextInt();
			if (h[i] != 0) {
				index = i;
			}
		}

		int ch = 0;

		for (int cx = 0; cx <= 100; cx++) {
			loop: for (int cy = 0; cy <= 100; cy++) {

				for (int i = 0; i < n; i++) {
					if (h[i] != 0) {
						index = i;
					}
				}
				ch = h[index] + Math.abs(cx - x[index]) + Math.abs(cy - y[index]);
				for (int i = 0; i < n; i++) {

					if (h[i] != Math.max(ch - Math.abs(cx - x[i]) - Math.abs(cy - y[i]), 0)) {
						continue loop;
					}
				}
				System.out.println(cx + " " + cy + " " + ch);
				System.exit(0);
			}
		}

		sc.close();
	}

}

Measured memory_bytes: 23764
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
alist=[list(map(int,input().split())) for i in range(n)]
ans=0
for j in range(n):
      s=0
      for k in range(m):
            s+=alist[j][k]*b[k]
      if s+c>0:
            ans+=1
print(ans)


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

int main() {
  long long N;
  cin >>N;
  long long S = 0;
  for (int i = 1; i < N+1; i++) {
    if(i%3 != 0&&i%5 != 0){
      S += i;
    }
  }
  cout << S<<endl;

}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,i,j,d,e,f;
    cin>>a;
    if(a%500==0)
        cout<<a*2<<endl;
    else
    {
        b=a/500;
        c=b*1000;
        d=a%500;
        e=d/5;
        f=e*5;
        cout<<c+f<<endl;
    }
    return 0;
}


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

using namespace std;


int main() {
    int n,y;
    cin>>n>>y;
    y/=1000;
    for (int i = 0; i <=n; ++i) {
        for (int j = 0; j <=n-i; ++j) {
            if((i+j*5+(n-i-j)*10)==y){
                cout<<n-i-j<<" "<<j<<" "<<i<<endl;
                return 0;
            }
        }
    }
    cout<<"-1 -1 -1"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, first, last) for (int i = (first); i < (last); ++i)
#define REP(i, n) FOR(i, 0, n)
#define CLR(a) memset((a), 0, sizeof(a))
#define DUMP(x) std::cerr << #x << " = " << (x) << std::endl;
#define DUMPR(v) REP(_i,v.size()){std::cerr<< #v << "[" << _i << "] = " << (v[_i]) << std::endl;}
#define CIN_VEC(v,N) {v.clear(); v.reserve(N); REP(i,N){typename decltype(v)::value_type x; cin>>x; v.emplace_back(x);}};

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_string(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef unsigned long long ull;
typedef unsigned long ul;

static const int NMAX = 100000;
int h[NMAX];
int N;
int dp[NMAX];
const static int INF = 1e9;

int main() {
  int K;
  cin>>N>>K;
  REP(i,N) cin >> h[i];
  REP(i,N) dp[i] = INF;
  dp[0] = 0;

  REP(i,N) {
    for(int k=i+1; k <= i+K && k<N;k++) {
      dp[k] = min(dp[k], dp[i] + abs(h[i]-h[k]));
    }
    // DUMP(i);
    // REP(i,N) DUMP(dp[i]);
  }
  cout<<dp[N-1]<<endl;

  return 0;
}


Measured memory_bytes: 1024
N, M, X, Y = map(int, input().split())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))

for i in range(X+1, Y+1):
    flag1 = all([True if x < i else False for x in xs])
    flag2 = all(True if y >= i else False for y in ys)
    if flag1 and flag2:
        print("No War")
        exit()
print("War")

Measured memory_bytes: 40048
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

ll powermod(ll a,ll b,ll m){
	if(b==0){
		return 1LL;
	}
	if(b%2){
		return (a*powermod(a,b-1LL,m))%m;
	}
	return powermod((a*a)%m,b/2LL,m);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N=in();
	map<int,int> M;
	REP(i,N){
		M[in()]++;
	}

	if(!(N%2)){
		int index=0;
		for(auto& x:M){
			if(x.first!=2*index+1 || x.second!=2){
				out(0);
				return 0;
			}
			index++;
		}
		out(powermod(2,M.size(),atcoder_mod));
	}
	else{
		int index=0;
		for(auto& x:M){
			if(x.first!=2*index){
				out(0);
				return 0;
			}
			if((x.first==0 && x.second!=1) || (x.first>0 && x.second!=2)){
				out(0);
				return 0;
			}
			index++;
		}
		out(powermod(2,M.size()-1,atcoder_mod));
	}

	return 0;
}


Measured memory_bytes: 3200