akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    int N, Q; cin >> N >> Q;
    dsu d(N);
    rep(i, Q) {
        int t, u, v; cin >> t >> u >> v;
        if (t) {
            if (d.same(u, v)) cout << 1 << endl;
            else cout << 0 << endl;
        }
        else {
            d.merge(u, v);
        }
    }
}


Measured memory_bytes: 3892
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll MOD2=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

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 (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

ll dp[3010][6300][3];

int main() {
    int N,S; cin>>N>>S;
    vector<ll> a(N);
    for (int i = 0; i < N; ++i) {
        cin>>a[i];
    }
    memset(dp,0, sizeof(dp));
    dp[0][0][0]=1;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= S; ++j) {
            (dp[i+1][j][0]+=dp[i][j][0])%=MOD2;
            (dp[i+1][j+a[i]][1]+=dp[i][j][0]*(i+1))%=MOD2;
            (dp[i+1][j+a[i]][2]+=dp[i][j][0]*(i+1)*(N-i))%=MOD2;

            (dp[i+1][j][1]+=dp[i][j][1])%=MOD2;
            (dp[i+1][j+a[i]][1]+=dp[i][j][1])%=MOD2;
            (dp[i+1][j+a[i]][2]+=dp[i][j][1]*(N-i))%=MOD2;

            (dp[i+1][j][2]+=dp[i][j][2])%=MOD2;

        }
    }
    cout<<dp[N][S][2]<<endl;
    return 0;
}


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

int a[1000];

int main(void){

	int i, j, k, n;
	int tmp;
	int v;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	for (i = 1; i <= n; i++) {
		//ソートを一回終えるごとに出力//
		for (k = 0; k < n - 1 ; k++) {
			printf("%d ", a[k]);
		}
		printf("%d\n", a[n - 1]);

		//実際にソートを行う//
		j = i - 1;
		v = a[i];
		while (j >= 0 && a[j] > v) {
			a[j + 1] = a[j];
			j--;
			a[j + 1] = v;

		}
	}
	return 0;
}


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

void bfs(const vector<vector<int>> &G, vector<int> &res, int s) {
    queue<int> que; que.push(s);
    vector<int> parent(G.size(), -1);
    vector<int> depth(G.size());
    while(!que.empty()) {
        int cur = que.front(); que.pop();
        for(auto &to : G[cur]) {
            if(parent[to] != -1) continue;
            que.push(to);
            parent[to] = cur;
            depth[to] = depth[cur] + 1;
            if(to == s) {
                vector<int> tmp;
                int i = to;
                for(int j = 0; j < depth[to]; ++j) {
                    tmp.push_back(i);
                    i = parent[i];
                }
                if(res.size() > tmp.size()) {
                    res = tmp;
                    return;
                }
            }
        }
    }
}

vector<int> mincycle(const vector<vector<int>> &G) {
    vector<int> res(G.size() + 1);
    for(int s = 0; s < G.size(); ++s) bfs(G, res, s);
    if(res.size() == G.size() + 1) return vector<int>();
    return res;
}

void solve() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    rep(i, 0, M) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
    }
    auto cycle = mincycle(G);
    if(cycle.size()) {
        cout << cycle.size() << '\n';
        for(auto &v : cycle) cout << v + 1 << '\n';
    } else {
        cout << -1 << '\n';
    }
}

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


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, k;
	cin >> n >> k;
	if((n - 1) * (n - 2) / 2 < k) cout << -1 << endl;
	else{
		vector<pair<int,int> > e;
		for(int i = 2; i <= n; i++) e.push_back({1, i});
		int has = (n - 1) * (n - 2) / 2;
		for(int i = 2; i <= n; i++) for(int j = i + 1; j <= n && has > k; j++) e.push_back({i, j}), has--;
		cout << e.size() << endl;
		for(auto ed : e) cout << ed.first << " " << ed.second << endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(pair<int, int>a, pair<int, int>b) {
	if (a.second == b.second) {
		return a.first > b.first;
	}
	return a.second > b.second;
}

int main() {
	int a, b;
	cin >> a >> b;
	b += a * 3;
	cout << b / 2 << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

a,b,c,d=mii()
c,d=min(c,d),max(c,d)

num = b-a+1

ac = (a-1)//c
bc = b//c 

ad = (a-1)//d
bd = b//d

cd = b //((c*d)//gcd(c,d)) - (a-1) //((c*d)//gcd(c,d))

print(num - (bc+bd-ac-ad)+cd)


Measured memory_bytes: 63852
#include <iostream>
#include <algorithm>
using namespace std;
int x, n;
const int n_max = 100;
int p[n_max];
int main()
{
    cin >> x >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    for (int i = n; i < n_max; i++)
    {
        p[i] = 1000;
    }

    int dist = 0;
    int temp;
    while (1)
    {
        temp = x - dist;
        if (!any_of(begin(p), end(p), [=](int n) { return n == temp; }))
        {
            cout << temp << endl;
            return 0;
        }
        temp = x + dist;
        if (!any_of(begin(p), end(p), [=](int n) { return n == temp; }))
        {
            cout << temp << endl;
            return 0;
        }
        dist++;
    }
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}



int main(){FIN

    char a;cin>>a;
    if(isupper(a)) cout<<'A'<<endl;
    else cout<<'a'<<endl;
    return 0;
}

Measured memory_bytes: 3688
import java.util.*;

public class Main {

    public static void main(String[] args) {
        //Compute c1 = new Compute();//calc

        long count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        //StringBuilder answer=new StringBuilder();

        //input
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        for (int i=1;i<n+1;++i)
        {
            String s = String.valueOf(i);
            if (s.length()%2==1)
            {
                ++count;
            }
        }
        System.out.println(count);
        //output
        //System.out.println(String.format("%.0f",answer));
    }
}

Measured memory_bytes: 27220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int A, B, C, D;;
	cin >> A >> B >> C >> D;

	int N[10] = {};
	N[A]++;
	N[B]++;
	N[C]++;
	N[D]++;

	if (N[1] && N[4] && N[7] && N[9]) co("YES");
	else co("NO");

	Would you please return 0;
}

Measured memory_bytes: 256
//................ DON'T WISH IT WERE EASIER, WISH YOU WERE BETTER........................
//............ WHEN LIFE PUTS YOU IN TOUGH SITUATIONS, DONT SAY "WHY ME" SAY "TRY ME".......
 
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define pb emplace_back
#define endl "\n"
#define f first
#define mp make_pair
#define s second
#define int long long
#define delrep(v)  (v).erase(unique((v).begin(),(v).end()),(v).end());
#define all(a)  (a).begin(),(a).end()
#define allr(a) (a).rbegin(),(a).rend()
#define sz(x)   (int)x.size()
#define lll __int64
const int N=1e6+10; const int M=100000;
const int mod=998244353;
using namespace std;
typedef long long ll;
const long long MAX_SIZE = 3000003;
vector<pair<int,int>>v[N]; map<int,int>hashx;
vector<int>a(N); vector<int>b(N); int pref[N]; int suff[N]; int sum[N];
vector<ll>dp(N,-1);
ll n;
int mindis(ll x)        // top down dp
{
    if(x==0) return 0; 
    if(dp[x]!=-1) return dp[x]; int ans=INT_MAX;
     for(int i=1;i<=2;i++) 
         {
            if(x-i>=0) 
             { 
                int ans2=mindis(x-i)+abs(a[x]-a[x-i]); 
                ans=min(ans,ans2); dp[x]=ans;  
             }
           }
  return dp[x];
}

int32_t main()
{
   int n; cin>>n; for(int i=0;i<n;i++) cin>>a[i]; 
   mindis(n-1);
   cout<<dp[n-1]; return 0;
}
 
 

Measured memory_bytes: 54272
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()

using namespace std;

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/

int main() {
	string s;
	vector<int> S(100000000);
	int ans = 0;
	int top = 0;
	cin >> s;
	for (int i = 0;i < s.size();i++) {
		S[top] = s[i] - '0';
		if (top > 0) {
			if (S[top] != S[top - 1]) {
				ans++;
				top--;
				top--;
			}
		}
		top++;
	}
	cout << ans * 2 << endl;
}

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

using ll=long long;

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

const ll INF=1LL<<60;
const int MAX_V = 100100;
int N,W;
ll w[110];
ll v[110];
ll dp[110][MAX_V];

int main(){
  cin >> N >> W;
  for (int i=1;i<=N;i++)
    cin >> w[i] >> v[i];
  for (int i=0;i<=N;i++){
    for (int j=0;j<=MAX_V;j++)
      dp[i][j]=INF;
  }
  dp[0][0]=0;
  for (int j=0;j<=MAX_V;j++){
    for (int i=1;i<=N;i++){
      chmin(dp[i][j],dp[i-1][j]);
      if (j-v[i]>=0) chmin(dp[i][j],dp[i-1][j-v[i]]+w[i]);
    }
  }
      
  ll res=0;
  for (int j=0;j<MAX_V;j++){
    if (dp[N][j] <= W) res = j;
  }
  cout << res << endl;
}

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

int main() {
	string s;
	cin >> s;
	for(int i = 0; i < s.size() - 1; i++){
		if(s[i] == 'A' && s[i + 1] == 'C'){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" <<endl;
	return 0;
}

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

ll powmod(ll x, ll y) {
  ll res = 1;
  for (ll i = 0; i < y; i++) {
    res = res * x % mod;
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  ll ans = powmod(10, n) - powmod(9, n) - powmod(9, n) + powmod(8, n);
  ans %= mod;
  ans = (ans + mod) % mod;
  cout << ans << endl;
}


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

int main() {
  int N,M;
  cin >>N >>M ;
  vector<int> a(60);
  vector<int> b(60);
  for(int i=0;i<M;i++)cin>>a.at(i)>>b.at(i);
    for(int i=0;i<N;i++){
      	int cnt=0;
      for(int j=0;j<M;j++){
        if(a.at(j)==i+1)cnt++;
        if(b.at(j)==i+1)cnt++;
		
      }
      cout << cnt <<endl;
    }
  
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String args[]){

		//sc??¨dice??????????????????????????????
		Scanner sc = new Scanner(System.in);
		Dice dice = new Dice(sc);

		//????????????????????????
		String command = sc.next();

		//????????????char????????????
		for(int i = 0; i < command.length(); i++){
			char action = command.charAt(i);
			//
			dice.roll(action);
		}

		System.out.println(dice.gettopNum());
		sc.close();
	}
}

class Dice {
	//?????£?????????
	private int[] dice = new int[6];

	//?????????????????????
	Dice(Scanner scan){
		for(int i = 0; i < 6; i++){
			this.dice[i] = scan.nextInt();
			//????????????
			//System.out.println("this.dice[" + i + "]" + this.dice[i]);
		}
	}

	//???????????????????????\????????????
	void roll(char action){
		//??????????????´?????????????????????????????¢?????????
		int temp = dice[0];

		//????§??????¨??¢?????????????????????????????????????????????
		switch(action){
		case 'N':
			dice[0] = dice[1];
			dice[1] = dice[5];
			dice[5] = dice[4];
			dice[4] = temp;
			break;

		case 'S':
			dice[0] = dice[4];
			dice[4] = dice[5];
			dice[5] = dice[1];
			dice[1] = temp;
			break;

		case 'E':
			dice[0] = dice[3];
			dice[3] = dice[5];
			dice[5] = dice[2];
			dice[2] = temp;
			break;

		case 'W':
			dice[0] = dice[2];
			dice[2] = dice[5];
			dice[5] = dice[3];
			dice[3] = temp;
			break;

		default :
			break;
		}
	}

	int gettopNum(){
		return dice[0];
	}
}

Measured memory_bytes: 26212
#include<stdio.h>

int min(int a,int b){
	return a<b?a:b;
}

int main(void){
	int a,b,c,x,y,total;
	scanf("%d %d %d %d %d",&a,&b,&c,&x,&y);
	
	if(a+b<2*c){
		total=a*x+b*y;
	}
	else{
		total=2*c*(x<y?x:y);
		if(x>y){
			total=2*c*y+(a<2*c?a:2*c)*(x-y);
		}
		else{
			total=2*c*x+(b<2*c?b:2*c)*(y-x);
		}
	}
	printf("%d\n",total);
	return 0;
}


Measured memory_bytes: 128
S = input()
T = input()
N = len(S)
x = 0
if S == T:
    print('Yes')
    exit()
while S != T:
    if x > N:
        print('No')
        exit()
    else:
        S = S[N - 1] + S
        S = S[0:N]
        x += 1
        if S == T:
            print('Yes')
            exit()

Measured memory_bytes: 9116
#include <stdio.h>
#include <stdlib.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;

int main(void)
{
    ll n, k;

    scanf("%lld%lld", &n, &k);

    n = n % k;

    if (n == 0)
    {
        puts("0");
        return 0;
    }

    if ((n - k > 0 && n > n - k) || (n - k < 0 && n > -(n - k)))
        if (n - k >= 0)
            n = n - k;
        else
            n = -(n - k);

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

    return 0;
}

Measured memory_bytes: 1732
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>n;
    set<pair<ll,ll>> p;
    a=n;

    if(n%2)n--;
    n/=2;
    for(ll i=1;i<=n;i++){
        p.insert(make_pair(i,n*2+1-i));
        //cout<<i<<" "<<n*2+1-i<<endl;
    }
    for(ll i=1;i<=n*2;i++){
        for(ll j=i+1;j<=n*2;j++){
            pair<ll,ll> p1=make_pair(i,j);
        if(p.find(p1)==p.end()) sum++;
        }
    }
    if(a%2){
        for(ll i=1;i<a;i++) sum++;
    }

    cout<<sum<<endl;
    for(ll i=1;i<=n*2;i++){
        for(ll j=i+1;j<=n*2;j++){
            pair<ll,ll> p1=make_pair(i,j);
        if(p.find(p1)==p.end()) cout<<i<<" "<<j<<endl;
        }
    }
    if(a%2){
        for(ll i=1;i<a;i++) cout<<i<<" "<<a<<endl;
    }



    return 0;
}


Measured memory_bytes: 3560
#include <iostream>
using namespace std;
int main() {
  int R, G, B, N,ans = 0;
  cin >> R >> G >> B >> N;
  for(int i = 0; i <= N / R; i++) {
    for (int j = 0; j <= (N - R * i) / G; j++) {
      if ((N - R * i - G * j) % B == 0) {
        ans++;
        //cout << i << ", " << j << endl;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define INF 0x3f //plus infinite


int main(){
  int a,b;
  char op;
  cin >> a >> op >> b;
  if(op == '+')
    cout << a+b << endl;
  else
    cout << a-b << endl;
  return 0;
}

/*文字列の辞書順について
 *C++の順序では'0'～'9'→'A'～'Z'→'a'～'z'の順に
 *                       なっていることに注意しましょう。
 */

/*行単位での入力
 * getline(cin,文字列変数);
 */


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
using ll = long long;

int main() {
  string s;
  cin >> s;
  bool istrue = false;
  for(int i = 0; i < s.size(); i++) {
    if(s[i] == '7') {
      istrue = true;
    }
  }
  if(istrue) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll, ll, ll>>>;

// MOD確認

int main(){
   long double A,B;
   cin >> A >> B;
   ll C = A * B;
   cout << C << endl;
}

Measured memory_bytes: 3728
N = int(input())
X = list(map(int, input().split()))
 
 
def variance(x):
    avg = sum(X) // len(X)
    return (avg - x) ** 2
 
 
def main(X):
    tot = 0
    tot2 = 0
    for x in X:
        tot += variance(x)
        tot2 += variance(x - 1)
    return min(tot, tot2)
 
 
ans = main(X)
print(ans)

Measured memory_bytes: 3060
#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:https://atcoder.jp/contests/abc146/tasks/abc146_f>
 問題文============================================================
 F - Sugoroku
 =================================================================
 解説=============================================================
 
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int N,M; cin >> N >> M;
    string S; cin >> S;
    for(auto& c:S) c -= '0';

    reverse(S.begin(),S.end());
    
    vector<int> idx;
    for(int i = 0; i <= N;i++){
        if(S[i] == 0) idx.push_back(i);
    }
    idx.push_back(INF);
    
    int now = 0;
    while(idx[now] != N){
        if(idx[now+1]-idx[now] > M) return vector<ll>{-1};
        int next = now+1;
        while(idx[next+1]-idx[now] <= M){
            next++;
        }
        
        res.push_back(idx[next]-idx[now]);
        now = next;
        
    }
    reverse(res.begin(),res.end());
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<vector<ll>>() << endl;
    return 0;
}


Measured memory_bytes: 1864
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin >>N>>M;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    vec.at(i)=0;
  }
  for(int i=0;i<M;i++){
    int a,b;
    cin >>a>>b;
    a-=1;
    b-=1;
    vec.at(a)+=1;
    vec.at(b)+=1;
  }
  
  for(int i=0;i<N;i++){
    cout <<vec.at(i)<<endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    	
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int R = sc.nextInt();
		
		int ans = N % R;
		if(ans == 0){
	   		System.out.println("0");
		}else{
	   		System.out.println("1");
		}
		
   		sc.close();
        return ;

    }
    
}



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

#define llong long long
#define inf 999999999
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<PP, int> PPP;
typedef struct data{
	int now;
	int cost;
}data;
int nh[4] = {1, 0, -1, 0};
int nw[4] = {0, 1, 0, -1};





int main(){
	int a, b;
	cin >> a >> b;
	int c = a * b;
	if(c % 2 == 0) cout << "Even" << endl;
	else cout << "Odd" << endl;

	return 0;
}

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

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;
}

int main(){
    int x; cin >> x;
    int num_500, num_5;
    num_500 = x / 500; x = x - 500 * num_500;
    num_5 = x / 5;
    int ans = 1000 * num_500 + 5 * num_5;
    cout << ans << endl;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;
const ll inf = 1e18;


ll a,b,c,d;

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

    cin>>a>>b>>c>>d;

    vector<ll> v = {a,b};
    vector<ll> w = {c,d};

    ll res = -inf;
    for (ll x: v) {
	for (ll y: w) {
	    res = max(res, x*y);
	}
    }

    cout<<res<<endl;
    
    return 0;
}


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v)                                                            \
  do {                                                                         \
    x = max(x, v);                                                             \
  } while (0)
#define chmin(x, v)                                                            \
  do {                                                                         \
    x = min(x, v);                                                             \
  } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  // n<=10, x => R=x
  // n>10,  x => R=x - 100 * (10-N)
  ll N, R, x;
  cin >> N >> R;
  if (N >= 10) {
    x = R;
  } else {
    x = R + 100 * (10-N);
  }
  cout << x << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <string.h>
#define ll long long int



int main()
{
   int s;
   scanf("%d",&s);
   int array[1000];
   memset(array,0,sizeof(array[0])*1000);
   array[1]=s;
    for (int i = 2;i<1000;i++)
    {
       if (array[i-1]%2==0)
       {
           array[i]=array[i-1]/2;
       }
       else if (array[i-1]%2!=0)
       {
          array[i]=3*array[i-1]+1;

       }

    }

   for (int j=1;j<1000;j++)
    for (int i = j+1;i<1000;i++)
    {
       if (array[j]==array[i])
       {
          printf("%d",i);
          return 0;

       }
    }





   return 0;
}


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

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

    bool galf = true;
    for (int i=0; i<S.size(); i++){
        if(i%2==0 && S.at(i)=='L') {
            galf=false;
            break;
        }
        if(i%2==1 && S.at(i)=='R') {
            galf=false;
            break;
        }
    }
    if (!galf) cout<< "No" << endl;
    if (galf) cout<< "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define lf long double
typedef vector <ll> vi;
typedef pair <ll,ll> ii;
typedef vector <pair <int,int> >vii;
typedef vector <vector <ll> > vv;
typedef vector <string> vs;
ll mod=1000000007;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    vi a(n);
    for(ll i=0;i<n;i++)
        cin>>a[i];
    multiset<ll> ma;
    for(ll i=0;i<n;i++)
    {
        if(ma.empty() || a[i]<=(*ma.begin()))
        {
            ma.insert(a[i]);
        }
        else
        {
            auto i1=ma.lower_bound(a[i]);
            auto j1=prev(i1);
            ma.erase(j1);
            ma.insert(a[i]);
        }
    }
    cout<<ma.size()<<endl;
}


Measured memory_bytes: 5760
# -*- coding: utf-8 -*-

n, x = map(int, input().split())

a, p = [1], [1]
for i in range(1,n):
    a.append(3 + a[i-1]*2)
    p.append(1 + p[i-1]*2)

def sum(n, x):
    if n == 0:
        return 0 if x <= 0 else 1
    elif x <= a[n-1]+1:
        return sum(n-1, x-1)
    else:
        return sum(n-1, x-a[n-1]-2)+1+p[n-1]

print(sum(n, x))


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

using namespace std;

#define N 1200

int n,m,c[N],f[N][N];

int main(){
	scanf("%d",&n);
	if (n==1){puts("1\n1"); return 0;}
	m=(n+3)/4*4;
	if (n%4==0){
		for (int i=1;i<=m;++i) c[i]=i;
	}
	if (n%4==1){
		c[1]=c[2]=1;
		c[3]=c[4]=2;
		c[5]=c[6]=3;
		for (int i=7;i<=m;++i) c[i]=i-3;
	}
	if (n%4==2){
		c[1]=c[2]=1;
		c[3]=c[4]=2;
		for (int i=5;i<=m;++i) c[i]=i-2;
	}
	if (n%4==3){
		c[1]=c[2]=1;
		for (int i=3;i<=m;++i) c[i]=i-1;
	}
	m/=2;
	for (int i=1;i<=m;++i)
		for (int j=1;j<=m;++j) f[j][(i+j-2)%m+1]=c[i*2-j%2];
	printf("%d\n",m);
	for (int i=1;i<=m;++i)
		for (int j=1;j<=m;++j) printf(j==m?"%d\n":"%d ",f[i][j]);
	
	return 0;
}
			

Measured memory_bytes: 5248
S = input()
N = len(S)
Sum = 0
for i in range(2**(N-1)):
    exp = []
    for j in range(N):
        exp.append(S[j])
        if ((i >> j) & 1):
            exp.append('+')
    
    a = ''
    for j in range(len(exp)):
        if exp[j] == '+':
            Sum += int(a)
            a = ''
        else:
            a += exp[j]
        if j == (len(exp)-1):
            Sum += int(a)
    
print(Sum)

Measured memory_bytes: 9036
a,b,c,x,y = map(int,input().split())

if c >= a and c >= b:
    print(a*x + b*y)
    exit()

if 2*c - a - b > 0:
    print(a*x + b*y)
    exit()

ans = 0
ans += 2*c*min(x,y)#同じ枚数まではABを買う

#xのほうが大きいとき    
if x > y:
    if c*2 <= a:
        ans += (x-y)*c*2
    else:
        ans += (x-y)*a

#yのほうが大きいとき
if x < y:
    if c*2 <= b:
        ans += (y-x)*c*2
    else:
        ans += (y-x)*b

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>

int main(){
  int i,n,a[100],count=0,minj,temp,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<n;i++){
    minj=i;
    for(j=i;j<n;j++){
      if(a[j]<a[minj]){
        minj=j;
      }
    }
    temp = a[i];
    a[i]=a[minj];
    a[minj]=temp;
    if(i!=minj){
      count++;
    }
  }
    for(i=0;i<n;i++){
      if(i<n-1){
        printf("%d ",a[i]);
      }
      else{
        printf("%d\n",a[i]);
      }
    }
    printf("%d\n",count);
    return 0;
}



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

using namespace std;

#define vi vector<int>
#define pb push_back
#define lli long long int
#define INF 100000001
#define all(c) (c.begin(),c.end())
#define sz(x) c.size()


void solve() {
	int n;
	cin >> n;
	if (n % 1000)
		cout << 1000 - (n % 1000) << endl;
	else cout << 0 << endl;
}

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

#ifndef ONLINE_JUDGE

	freopen("input.txt", "r", stdin);

	freopen("output.txt", "w", stdout);
#endif
	// int t; cin >> t;
	// while (t--) {
	solve();

	// }



	return 0;

}

Measured memory_bytes: 3584
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int N;
	cin >> N;

	vector<int> a(3*N);
	for(int i=0; i<3*N; i++){
		cin >> a.at(i);
	}

	sort(a.begin(),a.end());
	long long sum=0;
	for(int i=0; i<N; i++){
		sum+=a.at(3*N-2-i*2);
	}

	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 1408
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Set<String> hashSet = new HashSet<String>();
		String[] blueCards = new String[n];
		for(int i = 0; i < n; i++) {
			String tmp = sc.next();
			blueCards[i] = tmp;
			hashSet.add(tmp);
		}
		int m = sc.nextInt();
		String[] redCards = new String[m];
		for(int i = 0; i < m; i++) {
			redCards[i] = sc.next();
		}
		int maxSum = 0;
		for(String str : hashSet) {
			int tmp = 0;
			for(String blue : blueCards) {
				if(blue.equals(str)) {
					tmp++;
				}
			}
			for(String red : redCards) {
				if(red.equals(str)) {
					tmp--;
				}
			}
			if(tmp > 0 && maxSum < tmp) {
				maxSum = tmp;
			}
		}
		System.out.println(maxSum);

	}

}


Measured memory_bytes: 22740
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>

typedef unsigned long long int uint64;
typedef long long int          int64;

#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))


void get_AB (int64 *a, int64 *b)
{
  int cnt;
  
  cnt = scanf("%lld %lld", a, b);

  return;
}

int main()
{
  int cnt;
  int i;
  int64 N,D;
  int64 range;
  int64 num;

  get_AB(&N, &D);

  range = D*2+1;

  num = N/range;
  if((num == 0) ||
     ((N%range) > 0)) {
    num++;
  }

  printf("%lld", num);

  return 0;
}



Measured memory_bytes: 128
# coding:utf-8


def main():
    N = int(input())
    V = list(map(int, input().split()))
    V.sort()

    for i in range(N-1):
        a = V.pop(0)
        b = V.pop(0)
        V.append((a+b)/2)
        V.sort()

    print(V[0])


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;
typedef long long ll;

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

  int p, h;
  cin >> p >> h;
  int ho[h + 1];
  int flag = 0;
  for(int i = 0; i < h; i++){
    cin >> ho[i];
  }

    int tmp = 0;
    int sum = 0;
    for(int i = h - 1; i >= 0; i--){
      tmp = ho[i] - ho[i - 1];
      if(tmp > sum){
        sum = tmp;
      }
    }
    int fir = p - sum;
    int sec = ho[h - 1] - ho[0];
    cout << min(fir, sec);

  return 0;
}


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

long long dfs(long long cur, long long s){
    if(cur == 0)
        return s;
    long long sum = 0, res = 0, p = 1;
    while(cur){
        sum += p * (cur % 10);
        cur /= 10, p *= 10;
        res += dfs(cur, s + sum);
    }
    return res;
}
int main()
{
    long long num;
    cin >> num;
    cout << dfs(num, 0) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(...)
#include <complex.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;

int n ;
string s;

int32_t main() {
    ios::sync_with_stdio (false);
    cin.tie (0);
    cin >>  n >> s;
    vi dp (n + 1);
    for (int i = 0; i < n; i++) {
        dp[i + 1] = dp[i] + (s[i] == 'W');
    }
    vi dp2 (n + 1);
    for (int i = n - 1; i >= 0; i--) {
        dp2[i] = dp2[i + 1] + (s[i] == 'E');
    }
    int ans = (int) 1e9;
    for (int i = 0; i < n; i++) {
        int nw = dp[i] + dp2[i + 1];
        ans = min (ans, nw);
    }
    cout << ans << '\n';




    return 0;
}













Measured memory_bytes: 2964
def solve(a, b):
    if a == b:
        return 1

    f = 1 << 60
    r = 0
    while f:
        if r == 0 and b & f and a & f == 0:
            r = f
        elif r > 0 and b & f:
            k = f << 1
            break
        f >>= 1
    else:
        k = 1

    a &= r - 1

    if k > a:
        return (r << 1) - a

    return 2 * (r - a) + k


a = int(input())
b = int(input())
print(solve(a, b))


Measured memory_bytes: 9132
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

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

ll MOD = 1000000007;

int main()
{
    ll a, b, h;
    cin >> a >> b >> h;
    cout << (a+b) * h / 2 << endl;
    return 0;
}


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

int main() {
  string s;
  int ans=0;
  cin>>s;
  // for(int i=0;i<s.size();i++) {
  //   if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T') cnt++;
  //   else {
  //     ans=max(ans,cnt);
  //     cnt=0;
  //   }
  // }
  // ans=max(ans,cnt);
  for(int i=0;i<s.size();i++) {
    for(int j=i;j<s.size();j++) {
      bool can=true;
      for(int k=i;k<=j;k++) {
        if(s[k]!='A'&&s[k]!='C'&&s[k]!='G'&&s[k]!='T') {
          can=false;
        }
      }
      if(can) ans=max(ans,j-i+1);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3608
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let m1: usize = scan(tokens);
    let _d1: usize = scan(tokens);
    let m2: usize = scan(tokens);
    let _d2: usize = scan(tokens);
    if m1 < m2 {
        println!("1");
    } else {
        println!("0");
    }
}


Measured memory_bytes: 4352
import java.util.*

fun main(args: Array<String>) {
    val (h, w) = readLine()!!.split(" ").map(String::toInt)
    val map = Array(h) { readLine()!!.toCharArray().map { c -> if (c == '.') -1 else 0 }.toIntArray() }
    val queue = ArrayDeque<Int>()
    for (th in 0 until h) for (tw in 0 until w) if (map[th][tw] == 0) queue.offer(10000 * th + tw)

    val dir = mutableListOf(Pair(1, 0), Pair(0, 1), Pair(-1, 0), Pair(0, -1))//上下左右
    var max = 0
    while (queue.size > 0) {
        val q = queue.poll()!!
        for (d in dir) {
            val qh = q / 10000
            val qw = q % 10000
            val th = qh + d.first
            val tw = qw + d.second
            if (th in 0 until h && tw in 0 until w && map[th][tw] == -1) {
                queue.offer(10000 * th + tw)
                val next = map[qh][qw] + 1
                map[th][tw] = next
                max = Math.max(max, next)
            }
        }
    }
    println(max)
}


Measured memory_bytes: 89548
N, M = map(int, input().split())
ans = ['*'] * N
for _ in range(M):
    s, c = map(int, input().split())
    if ans[s - 1] == '*' or ans[s - 1] == str(c):
        ans[s - 1] = str(c)
    else:
        print(-1)
        exit()

if ans[0] == '*':
    if N == 1:
        ans[0] = '0'
    else:
        ans[0] = '1'

if ans[0] == '0' and N > 1:
    print(-1)
else:
    ans = ''.join(ans)
    print(ans.replace('*', '0'))


Measured memory_bytes: 3064
n = int(input())
a = [int(input()) for _ in range(n)]
now = a[0]
c = 1

if now == 2:
    print(1)
    exit()

for i in range(n):
    now = a[now-1]
    c += 1
    if now == 2:
        print(c)
        exit()
print(-1)

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



int main(int argc, char const *argv[])
{

#if !ONLINE_JUDGE

	freopen("in1.txt", "r", stdin);
	freopen("out1.txt", "w" , stdout);

#endif

	long long w, a, b;
	cin >> w >> a >> b;


	if (b > a + w)
	{
		cout << b - a - w << endl;
	}
	else if (a > b + w)
	{
		cout << a - b - w << endl;
	}
	else {
		cout << 0 << endl;
	}

	return 0;
}

Measured memory_bytes: 3608
package main

import "fmt"

var A, B, C, X int

func main() {
	fmt.Scanf("%d", &A)
	fmt.Scanf("%d", &B)
	fmt.Scanf("%d", &C)
	fmt.Scanf("%d", &X)

	ans := 0
	for i := 0; i <= A; i++ {
		if 500*i > X {
			break
		}
		for j := 0; j <= B; j++ {
			if 500*i+100*j > X {
				break
			}
			for k := 0; k <= C; k++ {
				if 500*i+100*j+50*k == X {
					ans++
				}
			}
		}
	}

	fmt.Println(ans)
}

// Library

func MakeMatrix(w, h int) [][]int {
	m := make([][]int, w)
	for x := 0; x < w; x++ {
		m[x] = make([]int, h)
	}

	return m
}

func Max(x, y int) int {
	if x > y {
		return x
	}
	return y
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {//xの親を求める
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {//xとyが連結しているか判定
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {//xとyを連結
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {//xを含む木のサイズを求める
        return -par[root(x)];
    }
};

int main() {
    ll N,M;
    cin>>N>>M;
    vector<P> bridge(0);
    rep(i,M){
        int a,b;
        cin>>a>>b;
        --a;--b;
        bridge.pb({a,b});
    }
    vector<ll> ans(M);
    ans.at(M-1)=N*(N-1)/2;
    UnionFind uf(N);
    for(int i=M-1;i>=1;i--){
        int a=bridge.at(i).first,b=bridge.at(i).second;
        if(uf.issame(a,b)){
            ans.at(i-1)=ans.at(i);
        }
        else{
            ll sa=uf.size(a),sb=uf.size(b);
            ans.at(i-1)=ans.at(i)-sa*sb;
            uf.merge(a,b);
        }
    }
    rep(i,M){
        cout<<ans.at(i)<<endl;
    }
}

Measured memory_bytes: 5304
#include<stdio.h>
int main()
{
	int h,w,i,j,a1[101][101],b;
	char a[101][101];
	scanf("%d %d",&h,&w);

	for(i=0;i<h;i++){
		scanf("%s",a[i]);
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			a1[i][j]=-1;
		}
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(a[i][j]=='c'){
				b=0;
				while(j+b<w){
					a1[i][j+b]=b;
					b++;
				}
			}
		}
	}
	for(i=0;i<h;i++){
		printf("%d",a1[i][0]);
		for(j=1;j<w;j++){		
			printf(" %d",a1[i][j]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 656
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


using i64 = ::std::int_fast64_t;
using u64 = ::std::uint_fast64_t;
using i32 = ::std::int_fast32_t;
using u32 = ::std::uint_fast32_t;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 N, K;
  std::cin >> N >> K;
  std::vector<i64> A;
  tools::read(A, N);

  for (i64 i = 0; i + K < N; ++i) {
    std::cout << (A[i] < A[i + K] ? "Yes" : "No") << '\n';
  }
  return 0;
}

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

int main(void){
	int n,d,x;
	int a[101];
	int i;
	int ans;

	scanf("%d",&n);
	scanf("%d %d",&d,&x);

	ans = x;

	for(i = 1;i <= n; i++ ){
		scanf("%d",&a[i]);
		ans += (1 + ((d - 1) / a[i]) );
	}

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

	return 0;
}

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

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}


int main() {

int n;
cin >> n ;

int a[n];
rep(i,n)cin >> a[i];


int tem = 0;
int num = 0;
int ans = 0;
int count = 0;
rep(i,n)tem = max(tem,a[i]);
rep(i,n){
    if(a[i] == tem)count++;
    else ans =max(ans,a[i]);
}


rep(i,n){
    if(a[i] != tem) cout << tem << endl;
    else if(a[i] == tem){
        if(count == 1)cout << ans << endl;
        else cout << tem << endl;
        } 
}


  return 0;

}

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

int main(void) {
	int number[10] = { 0 };

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

	if (number[1] == 1 && number[9] == 1 && number[7] == 1 && number[4] == 1) {
		std::cout << "YES" << std::endl;
	}
	else {
		std::cout << "NO" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

long long int INF = 1e18;
using namespace std;

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

long long int DP[200][200] = {};

int n;

int main(){
	
	cin >> n;
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			DP[i][j] = INF;
		}
		DP[i][i] = 0;
	}
	for(int loop = 0; loop < n; loop++){
		
		int id, k;
		cin >> id >> k;
		id--;
		
		for(int i = 0; i < k; i++){
			int num;
			cin >> num;
			num--;
			DP[id][num] = 1;
		}
	}
	
	for(int k = 0; k < n; k++){
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				DP[i][j] = min(DP[i][j], DP[i][k] + DP[k][j]);
			}
		}
	}
	
	for(int i = 0; i < n; i++){
		cout << i + 1 << " ";
		if(DP[0][i] == INF){
			cout << -1 << endl;
		}else{
			cout << DP[0][i] << endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 3244
iN,iM = [int(x) for x in input().split()]
iD = 10**9 +7 #法

def fPrimeCounter(iM):
    i = 2
    iS = int(iM ** 0.5) + 1
    aRet = []
    while i < iS or iM != 1:
        iCounter = 0
        while iM % i == 0:
            iM = iM // i
            iCounter += 1
        if 0 < iCounter : aRet.append(iCounter)
        i += 1

    return aRet

#二分累乗法 iDを法として
def fBiPow(iX,iN,iD):
    iY = 1
    while iN > 0:
        if iN % 2 == 0:
            iX = iX * iX % iD
            iN = iN // 2
        else:
            iY = iX * iY % iD
            iN = iN - 1
    return iY

aP = fPrimeCounter(iM)
if aP == [] :
    print (1)
else:
    iMax = max(aP) + iN - 1
    aM = [1] * (iMax + 1)
    #階乗 iD を法とした
    for i in range(1,iMax + 1):
        aM[i] = aM[i-1] * i  % iD
    aInvM = [1]* (iMax + 1)
    aInvM[iMax] = fBiPow(aM[iMax],iD-2,iD)
    #階乗の逆元 iD を法とした
    for i in range(iMax,0,-1):
        aInvM[i-1] = aInvM[i]*i % iD

    iRet = 1
    for i in aP:
        # i + iN -1  C  iN -1
        iRet *= aM[i+iN-1] * aInvM[iN-1] * aInvM[i] % iD
    iRet %= iD
    print(iRet)


Measured memory_bytes: 40692