akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint B1 = 1532834020;
constexpr lint M1 = 2147482409;
constexpr lint B2 = 1388622299;
constexpr lint M2 = 2147478017;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string S, T;
  cin >> S >> T;
  int ans = S.size();
  REP(i, S.size()-T.size()+1) {
    int tmp = 0;
    REP(j, T.size()) {
      if(S[i+j] != T[j]) tmp++;
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
vector<pair<ll,ll>> x;
int main(){
    ll n,p,a=1;
    cin>>n>>p;
    if(n>1)rep(i,2,p+1){
      ll tmp=0;
      ll w=pow(i,n);
      while(p%w==0&&p>1){tmp++;p/=w;}
      if(tmp>0)x.pb(mp(tmp,i));
      if(p<pow(i+1,n))break;
      if(i==2*sqrt(p)&&x.size()==0)break;
    }
    else a=p;
    rep(i,0,x.size()){
        a*=pow(x[i]S,x[i]F);
    }
    cout<<a;
}


Measured memory_bytes: 384
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.06.16 21:03:21
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

int main() {
    double w, h, x, y;
    scanf("%lf%lf%lf%lf", &w, &h, &x, &y);

    double ret = w * h / 2.0;
    bool b;
    if (w / 2.0 == x && h / 2.0 == y) {
        b = true;
    } else {
        b = false;
    }

    if (b) {
        printf("%lf %d\n", ret, 1);
    } else {
        printf("%lf %d\n", ret, 0);
    }

    /* --------------------------------- */
    return 0;
}

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

int main(){
    int k,s,x,y,z,ans = 0;
    cin >> k >> s;
    for(x = 0;x <= k;x++){
        for(y = 0;y <= k;y++){
            z = s - x - y;
            if(0 <= z && z <= k)ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int n,i,j;
	int ans;
	char era[1000000];


	while(scanf("%d",&n) != EOF){
		for(i=0; i<=n;i++)
			era[i]=1;
		ans=0;
		for(i=2;i<=n;i++){
			if(era[i] == 1){
				ans++;
				for(j=i; j<=n;j+=i)
					era[j]=0;
			}
		}
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 1572
N = int(input())
A = [int(x) for x in input().split()]
A = [0] + A
B = []

i = N
if N%2==1:    
    for i in range(N, 0, -2):
        B.append(A[i])
    for i in range(2, N, 2):
        B.append(A[i])
else:
    for i in range(N, 1, -2):
        B.append(A[i])
    for i in range(1, N, 2):
        B.append(A[i])

print(*B)
    
    

Measured memory_bytes: 26180
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C;
  cin >> A >> B >> C;
  
  if( ( 3*max(A,max(B,C)) - (A+B+C) ) % 2 == 0 ){
    cout << ( 3*max(A,max(B,C)) - (A+B+C) ) / 2 << endl;
  }else{
    cout << ( 3*max(A,max(B,C)) - (A+B+C) ) / 2 + 2 << endl;
  }
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
inf = 10**17
mod = 10**9+7

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

ac = [0] * n
wa = [0] * n

acn = 0
wan = 0
for i in range(m):
    p, s = input().split()
    p = int(p)
    p -= 1
    if ac[p] > 0: continue
    if s == 'AC':
        ac[p] = 1
        acn += 1
        wan += wa[p]
    else:
        wa[p] += 1

print(acn, wan)


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

int main() {
	int a,b,k; cin>>a>>b>>k;
	bool t{1};
	while(k--){
		if(t){
			if(a%2) a--;
			a>>=1;
			b+=a;
		}
		else{
			if(b%2) b--;
			b>>=1;
			a+=b;
		}
		t^=1;
	}
	cout<<a<<' '<<b<<endl;
}


Measured memory_bytes: 256
#include <iostream>

#define N 20
#define K 10
#define S 155

using namespace std;

int count_sets(int n, int k, int s) {
    int count = 0;
    if (k == 0) {
        if (s == 0) {
            return 1;
        }
        return 0;
    }
    for (int i=1; i<=n; i++) {
        count += count_sets(i-1, k-1, s-i);
    }
    return count;
}

int main() {
    while (true) {
        int n, k, s;
        cin >> n >> k >> s;
        if (n == 0) {
            return 0;
        }
        cout << count_sets(n, k, s) << endl;
    }
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, M; 
  cin >> N >> M;

  int ans = 0;
  for(int i = 1; i*i <= M; i++){
    if(M%i == 0){
      if(M/i >= N) chmax(ans, i);
      if(i >= N) chmax(ans, M/i);
    }
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 256
//************************
//*  Date: 2018.9.22     *
//*  Problem:            *
//*  Author: xuziyuan    * 
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int a[3];

int main()
{
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	cout<<a[2]*10+a[0]+a[1]<<endl;
	rt0;
}

Measured memory_bytes: 256
A,B,C,D = list(map(int, input().split()))

C, D = min(C,D), max(C,D)

dividable_C = B//C - (A-1)//C
dividable_D = B//D - (A-1)//D

x = C*D
r = D%C
while r!=0:
    D = C
    C = r
    r = D%C
saisho_ko_baisu = x//C

dividable_CD = (B//saisho_ko_baisu) - ((A-1)//saisho_ko_baisu)

print(B - A + 1 - (dividable_C + dividable_D - dividable_CD))


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


void make_comb(
    const int N, const int M, const int Q,
    vector<int> A,
    int &best_sum_d,
    const vector<int> &a,
    const vector<int> &b,
    const vector<int> &c,
    const vector<int> &d
) {
    if (A.size() == (N+1)) {
        int sum_d = 0;
        for (int j = 0; j < Q; j++) {
            if (A.at(b.at(j)) - A.at(a.at(j)) == c.at(j)) {
                sum_d += d.at(j);
            }
        }
        if (sum_d > best_sum_d) {
            best_sum_d = sum_d;
        }        
        return;
    }else{
        int i = A.back();
        for (; i < (M+1); i++) {
            vector<int> A_tmp = A;
            A_tmp.push_back(i);
            make_comb(N, M, Q, A_tmp, best_sum_d, a, b, c, d);
        }
    }
}


int main() {
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<int> a(Q);
    vector<int> b(Q);
    vector<int> c(Q);
    vector<int> d(Q);
    int best_sum_d = 0;
    for (int i = 0; i < Q; i++) {
        cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
    }

    vector<int> A(1,1);
    make_comb(N, M, Q, A, best_sum_d, a, b, c, d);
    cout << best_sum_d << endl;
}

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

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

int main() {
  ll n,k;
  cin >> n >> k;
  int p[n];
  ll c[n];
  rep(i,n) {
    cin >> p[i];
    p[i]--;
  }
  rep(i,n) cin >> c[i];
  ll ans = -1000000000000;
  rep(i,n) {
    int now = i;
    ll cycle_score = 0;
    int cycle_len = 0;
    while (1) {
      now = p[now];
      cycle_score += c[now];
      cycle_len++;
      if (now == i) break;
    }
    //printf("%d %lld\n", cycle_len, cycle_score);
    now = i;
    ll cnt = 0;
    int len = 0;
    while (1) {
      len++;
      now = p[now];
      cnt += c[now];
      int num = (k-len) / cycle_len;
      ll score = cnt + max(0ll,cycle_score)*num;
      ans = max(ans,score);
      if (now == i || len == k) break;
    }
  }
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;
  vector<int> p(M);
  vector<string> S(M);
  for(int i = 0; i < M; i++){
    cin >> p[i] >> S[i];
  }
  vector<bool> anscheck(N,false);
  vector<int> wacheck(N,0);
  int penalty = 0;
  for(int i = 0; i < M; i++){
    if(S[i]=="WA"){
      wacheck[p[i]-1]++;
    }
    if(S[i]=="AC"){
      if(anscheck[p[i]-1]==false){
        penalty += wacheck[p[i]-1];
        anscheck[p[i]-1] = true;
      }
    }
  }
  int ac = 0;
  for(int i = 0; i < N; i++){
    if(anscheck[i]){
      ac ++;
    }
  }
  cout << ac << " " << penalty; 
}

Measured memory_bytes: 6528
import math
n = int(input())

def check(s):
	if s == 1:
		return False
	for i in range(2, int(math.sqrt(s)) + 1):
		if s%i == 0:
			return False
	return True

for i in range(n,10**6):
	if check(i):
		print (i)
		exit()


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

int main()
{
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if(e-a > k){
    cout << ":(" <<endl;
  }
  else{
    cout << "Yay!" <<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
#define MOD 1000000007
typedef pair<int,int>pii;
int n,a[30][30],dp[1<<22],n1;
int main(){
	cin>>n,n1=(1<<n);
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			cin>>a[i][j];
	dp[0]=1;
	for(int i=0;i<n1;i++){
		int c=0;
		for(int j=0;j<n;j++)if(i&(1<<j))c++;
		for(int j=0;j<n;j++)if(~i&(1<<j))if(a[c][j]){
			dp[i+(1<<j)]=(dp[i+(1<<j)]+dp[i])%MOD;
		}
	}
	cout<<dp[(1<<n)-1]<<endl;
	return 0;
}
/*
3
0 1 1
1 0 1
1 1 1
*/

Measured memory_bytes: 10496
//
/*
ID: kfoozmi1
LANG: C++
TASK:
*/
#include <bits/stdc++.h>
using namespace std;

#ifdef kfoozminus
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu() {
	cerr << endl;
}

template <typename T>
void faltu(T a[], int n) {
	for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
	cerr << endl;
}

template <typename First, typename ... hello>
void faltu(First arg, const hello&... rest) {
	cerr << arg << ' ';
	faltu(rest...);
}
#else
#define dbg(args...)
#endif

#define PB push_back
#define F first
#define S second
#define MP make_pair
#define SQR(a) ((a) * (a))
#define vsort(v) sort(v.begin(), v.end())
#define PQ priority_queue
#define PI acos(-1)
#define EPS 1e-9

#define B1 43
#define B2 43

#define MOD1 1000000007
#define MOD2 1000000009
#define MOD  1000000007

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

//int dx[] = {0, 0, +1, -1};
//int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool checkBit(ll n, int i) { return n & (1LL << i); }
inline ll setBit(ll n, int i) { return n | (1LL << i); }
inline ll resetBit(ll n, int i) { return n & (~ (1LL << i)); }
inline bool EQ(double a, double b) { return fabs(a-b) < EPS; }
inline double dist(double ix, double iy, double jx, double jy) { return sqrt(SQR(ix - jx) + SQR(iy - jy)); }

#define PMX 1000000

int marked[PMX/64+2];

#define mark(x) marked[x>>6] |= (1<<((x&63)>>1))
#define check(x) (marked[x>>6] & (1<<((x&63)>>1)))

bool isPrime(int x)
{
    return (x>1) && ((x==2) || ((x&1) && (!(check(x)))));
}

void seive(int n)
{
    int i, j;
    for(i=3; i*i<=n; i+=2)
    {
        if(!check(i))
        {
            for(j=i*i; j<=n; j+=i<<1)
            {
                mark(j);
            }
        }
    }
}

ll bigMod(ll a, ll b)
{
	ll r = 1;
	while(b) {
		if(b & 1) (r *= a) %= MOD;
		b >>= 1;
		(a *= a) %= MOD;
	}
	return r;
}

#define INF 100000000
#define MX 100007

pii cnt[MX];
int n, m, i, ans, x, y;

int main()
{
#ifdef kfoozminus
	//freopen("in", "r", stdin);
#endif
	scanf("%d %d", &n, &m);
	cnt[1] = {1, 1};
	for(i = 2; i <= n; i ++) cnt[i] = {1, 0};
	while(m --) {
		scanf("%d %d", &x, &y);
		cnt[x].F --;
		cnt[y].F ++;
		cnt[y].S |= cnt[x].S;
		if(cnt[x].F == 0) cnt[x].S = 0;
		dbg(x, y, cnt[x].F, cnt[x].S, cnt[y].F, cnt[y].S);
	}
	for(i = 1; i <= n; i ++) ans += cnt[i].S;
	printf("%d\n", ans);
        return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
#define CEIL(A,B) ((A)+(B)-1)/(B)
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

ll N, K;

int main() {
    fastio();
    cin >> N >> K;
    vector<ll> A(K + 1);
    ll ans = 0;
    for(int x = K; x >= 1; x--) {
        A[x] = modpow(K / x, N);
        ll i = 2;
        while(i * x <= K) {
            A[x] = (A[x] + MOD - A[i * x]) % MOD;
            i++;
        }
        ans = (ans + A[x] * x % MOD) % MOD;
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std; // スペル注意
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define pb push_back 
// make_pair など各自で
int N, K;
int gcd(int a, int b){
	return b ? gcd(b, a % b) : a;
}
int main(){
	cin >> N >> K;
	int g;
	int ma = 0;
	rep(i, N){
		int a;
		cin >> a;
		ma = max(a, ma);
		if(i == 0)g = a;
		else{
			g = gcd(g, a);
		}
			//printf("%d\n", g);
	}

	cout << ((K % g == 0) && (K <= ma) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.*;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt();
    int M = in.nextInt();
    if (N == 1) {
      System.out.println(1);
      return;
    }
    int[] A = new int[N];
    Arrays.fill(A, 1);
    for (int i = 0; i < M; i++) {
      A[in.nextInt() - 1] = 0;
    }
    long[] B = new long[N];
    B[0] = A[0];
    B[1] = (A[0] + A[1]) * A[1];
    for (int i = 2; i < N; i++) {
      B[i] = ((B[i - 1] + B[i - 2]) % 1_000_000_007L) * (long) A[i];
    }
    System.out.println(B[N - 1]);
  }
}

Measured memory_bytes: 48360
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<assert.h>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> P1;
typedef long long int ll;

//define
#define INF 1e9
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))


int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int cnt = 0, maxv = 0;

	rep(i, n) {
		if (s[i] == 'I') cnt++;
		else if (s[i] == 'D') cnt--;

		chmax(maxv, cnt);
	}
	cout << maxv << endl;
}





Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef pair<int, int> P;

map<int, int> m;

int encode(const vector<int>& a) {
	int ret = 0;
	for(int i = 0; i < 8; i++) {
		ret <<= 3;
		ret |= a[i];
	}
	return ret;
}

void decode(int c, vector<int>& a) {
	for(int i = 0; i < 8; i++) {
		a[7 - i] = c & 7;
		c >>= 3;
	}
}

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

	vector<int> a(8);
	for(int i = 0; i < 8; i++) {
		a[i] = i;
	}
	queue<P> q;
	q.push(P(encode(a), 0));
	m[encode(a)] = 0;
	while(!q.empty()) {
		P p = q.front();
		q.pop();
		if(m[p.first] != p.second) continue;
		decode(p.first, a);
		int d[] = { 1, -1, 4, -4 };
		for(int i = 0; i < 8; i++) {
			if(a[i] != 0) continue;
			for(int j = 0; j < 4; j++) {
				if(d[j] == 1 && (i == 3 || i == 7)) continue;
				if(d[j] == -1 && (i == 0 || i == 4)) continue;
				if(d[j] == 4 && 4 <= i) continue;
				if(d[j] == -4 && i <= 3) continue;
				swap(a[i], a[i + d[j]]);
				int code = encode(a);
				if(m.find(code) == m.end() || p.second + 1 < m[code]) {
					m[code] = p.second + 1;
					q.push(P(code, p.second + 1));
				}
				swap(a[i], a[i + d[j]]);
			}
		}
	}

	string s;
	while(getline(cin, s)) {
		for(int i = 0; i < 8; i++) {
			a[i] = s[2 * i] - '0';
		}
		int code = encode(a);
		cout << m[code] << endl;
	}
}

Measured memory_bytes: 2160
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

/* #include <bits/stdc++.h> */

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#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 FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    int n,m;
    while (cin >> n >> m) {
        map<int,int> cntA, cntB;
        FOR(i,1,n+1) {
            int a; cin >> a;
            cntA[a]++;
        }
        FOR(_,0,m) {
            int b,c; cin >> b >> c;
            cntB[c] += b;
        }
        auto i = cntA.rbegin();
        auto j = cntB.rbegin();
        int total = 0; LL ans = 0;
        while (total < n) {
            if (j == cntB.rend() || i->first >= j->first) {
                const int x = min(i->second, n-total);
                ans += 1LL* i->first * x;
                total += x; i->second -= x;
                if (i->second == 0)
                    ++i;
            }
            else {
                const int x = min(j->second, n-total);
                ans += 1LL * j->first * x;
                total += x; j->second -= x;
                if (j->second == 0)
                    ++j;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 9600
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

const long long mod = 998244353;
char S[303]; int K; long long D[303][606], P[303][606];

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

int main()
{
	scanf ("%s", S);
	scanf ("%d", &K);

	int cnt = 0;
	vector<int> v;
	for (int i = 0; S[i]; i++){
		if (S[i] == '1') cnt++;
		else{
			v.push_back(cnt);
			cnt = 0;
		}
	}
	v.push_back(cnt);

	D[0][0] = 1;
	int s = 0;
	while (!v.empty()){
		int a = v.back(); v.pop_back(); s += a;
		for (int b = 0; b <= s; b++){
			int m = abs(a - b);
			for (int j = 0; j <= s; j++) if (j + a - b >= 0){
				for (int k = 0; k <= s * 2; k++){
					add(P[j + a - b][k + m], D[j][k]);
				}
			}
		}
		for (int j = 0; j <= s; j++) for (int k = 0; k <= s * 2; k++){
			D[j][k] = P[j][k];
			P[j][k] = 0;
		}
	}

	long long ans = 0;
	for (int k = 0; k <= s * 2; k += 2) if (k / 2 <= K){
		add(ans, D[0][k]);
	}
	printf ("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 6048
line = gets.split(' ').map(&:to_i)

A = line[0] - 1
B = line[1]
C = line[2]
D = line[3]

one_to_a = A - (A/C) - (A/D) + (A/(C.lcm(D)))
one_to_b = B - (B/C) - (B/D) + (B/(C.lcm(D)))

print one_to_b - one_to_a

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
vpint G[111111];

int dist[111111];
void dfs(int v,int p,int d){
    dist[v]=d;
    for(auto &e:G[v]){
        if(e.fi!=p)dfs(e.fi,v,d+e.se);
    }
}

signed main(){
    cin>>N;
    rep(i,N-1){
        int a,b,c;cin>>a>>b>>c;
        a--;b--;
        G[a].pb({b,c});G[b].pb({a,c});
    }

    int Q,K;cin>>Q>>K;
    K--;
    dfs(K,-1,0);
    while(Q--){
        int a,b;
        cin>>a>>b;
        a--;b--;
        cout<<dist[a]+dist[b]<<endl;
    }
    return 0;
}


Measured memory_bytes: 14592
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {
	
	int a;
	scanf("%d", &a);
	printf("%d\n", 24 + (24 - a));
	
	Please AC;
}


Measured memory_bytes: 888
from fractions import gcd
n = int(input())
*A, = map(int, input().split())
L = [0]*n
R = [0]*n
for i in range(n-1):
    L[i] = gcd(L[i-1], A[i])
    R[n-1-i] = gcd(R[(n-i)%n], A[n-1-i])
B = [gcd(L[i-1], R[(i+1)%n]) for i in range(n)]
print(max(B))

Measured memory_bytes: 16108
using System;
class aizu{
    public static int Main(){
        int i;
        int[] n = new int[100];
        string[] str = new string[100];
        for( ; ; ){
            str = Console.ReadLine().Split(' ');
            for(i=0;i<3;i++){
                if(i==1) continue;
                n[i] = int.Parse(str[i]);
            }
            switch(str[1]){
                case "+": n[3]=n[0]+n[2]; break;
                case "-": n[3]=n[0]-n[2]; break;
                case "*": n[3]=n[0]*n[2]; break;
                case "/": n[3]=n[0]/n[2]; break;
                case "?": return 0;
            }
            Console.WriteLine("{0}",n[3]);
        }
    }
}

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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

int xcomp(pii& a, pii& b) {
	return a.first < b.first;
}

#define XSORT(c) sort((c).begin(),(c).end(),xcomp)

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  while(true){
  LL N;
  cin >> N;
  if(N==0){
    break;
  }
  vector<pair<LL, LL>> rw;
  LL r_sum = 0;
  LL w_sum = 0;
  REP(i, N)
  {
    LL r,w;
    cin >> r >> w;
    rw.push_back({r, w});
    r_sum += r;
    w_sum += w;
  }
  XSORT(rw);
  if(r_sum-rw[rw.size()-1].first<rw[rw.size()-1].first){
    LL r_space = rw[rw.size() - 1].first - (r_sum - rw[rw.size() - 1].first);
    auto rw_rmax = rw[rw.size() - 1];
    rw.pop_back();

    vector<bool> hoge(2001, false);
    hoge[0] = true;
    REP(i, rw.size())
    {
      for (int j = 1000; j >= 0;--j){
        hoge[j + rw[i].second]= hoge[j + rw[i].second] || hoge[j];
      }
    }

    LL max = 0;
    
    REP(i,r_space+1){
      if(hoge[i]){
        max = i;
      }
    }

    cout << rw_rmax.first * 2 + w_sum - max << endl;
  }
  else
  {
    cout << r_sum + w_sum << endl;
  }
  }
}



Measured memory_bytes: 3212
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;

// restoring-road-network.rs --- Restoring Road Network
// author: Seong Yong-ju <sei40kr@gmail.com>

// tanakah's input macro
// cf https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        n: usize,
        edges: [[i64; n]; n],
    };

    let mut dp = edges;
    let mut needed = vec![vec![true; n]; n];
    let mut exists = true;

    for k in 0..n {
        for i in (0..n).filter(|&i| i != k) {
            for j in (i..n).filter(|&j| j != k) {
                let t = dp[i][k] + dp[k][j];

                match dp[i][j].cmp(&t) {
                    Ordering::Equal => {
                        needed[i][j] = false;
                    }
                    Ordering::Greater => {
                        dp[i][j] = t;
                        needed[i][j] = false;
                        exists = false;
                    }
                    _ => {}
                }
                if t <= dp[i][j] {
                    dp[i][j] = t;
                    needed[i][j] = false;
                }
            }
        }
    }

    let ans = if exists {
        (0..n)
            .map(|i| {
                (i..n)
                    .filter(|&j| needed[i][j])
                    .map(|j| dp[i][j])
                    .sum::<i64>()
            })
            .sum::<i64>()
    } else {
        -1
    };
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long int ll;
const int N = 13;
int cost[N];
int arr[N][N];
int brr[N][N];
int dp[N ][N];
vector<int> total(N);

int n, m, x;
ll ans = 1e10;
string fun(int n)
{
	int binaryNum[32];
	int i = 0;
	while (n > 0) {
		binaryNum[i] = n % 2;
		n = n / 2;
		i++;
	}

	string s;
	for (int j = i - 1; j >= 0; j--)
		s += binaryNum[j] + '0';
	return s;
}


void solve(vector<int> v) {
	int sz = v.size();
	ll  temp = 0;
	//int brr[sz + 1][sz + 1];
	for (int i = 0; i < sz; ++i) {
		temp += cost[ v[i] ];
		for (int j = 0; j < m; ++j) {
			if (i == 0)
				brr[i][j] = arr[ v[i] ][j];
			else
				brr[i][j] = arr[ v[i] ][j] + brr[i - 1][j];
		}
		bool flag = true;
		//cout << "brr: ";
		for (int k = 0; k < m; ++k) {
			//cout << brr[i][k] << " ";
			if (brr[i][k] < x) {
				flag = false;
				break;
			}
		}
		//cout << "\n";
		if (flag) {
			//cout << "found it: \n";
			ans = min(ans, temp);
			//cout << "ans isssssssssssssss: " << ans << "\n";
			return;
		}
	}
	//cout << "\n";
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m >> x;
	memset(dp, 0, sizeof(dp));

	for (int i = 0; i < n; ++i) {
		cin >> cost[i];
		for (int j = 0; j < m; ++j) {
			cin >> arr[i][j];
			if (i == 0)
				dp[i][j] += arr[i][j];
			else
				dp[i][j] += arr[i][j] + dp[i - 1][j];
		}
	}
	for (int i = 0; i < m; ++i) {
		if (dp[n - 1][i] < x) {
			cout << "-1";
			return 0;
		}
	}

	ll all = pow(2, n);
	string s;
	for (int i = 0; i < all; ++i) {
		s = fun(i);
		//cout << "i is: " << i << "s is: " << s << "\n";
		vector<int> v;
		for (int j = 0; j < s.size(); ++j) {
			if (s[j] == '1') {
				//cout << "j is: " << j << "\n";
				v.pb(s.size() - j - 1);
			}
		}
		if (v.size())
			solve(v);
	}
	if (ans == 1e12) cout << "-1";
	else cout << ans << "\n";
  
  return 0;
}



Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 1000000000



int main(){
	int N,K;
	cin>>N>>K;
	vector<vector<int>> E(N,vector<int>(0));
	for(int i=0;i<N-1;i++){
		int x,y;
		cin>>x>>y;
		x--;y--;
		E[x].push_back(y);
		E[y].push_back(x);
	}
	if(N==1){
		cout<<K<<endl;
		return 0;
	}
	stack<int> que;
	int start;
	
	for(int i=0;i<N;i++){
		if(E[i].size()==1){
			start = i;
		}
	}
	que.push(start);
	vector<int> siz(N,0);
	vector<int> dp(N,-1);
	dp[start] = K;
	while(que.size()!=0){
		int a = que.top();
		que.pop();

		for(int i=0;i<E[a].size();i++){
			if(dp[E[a][i]]!=-1)continue;
			siz[a]++;
			siz[E[a][i]]++;
			dp[E[a][i]] = max(0,K-siz[a]);
			que.push(E[a][i]);
		}
	}
	
	int ans = 1;
	
	for(int i=0;i<N;i++){
		ans = mod(ans*dp[i]);
		///cout<<dp[i]<<endl;
	}
	
	cout<<ans<<endl;
	
	
	return 0;
}


Measured memory_bytes: 7288
#include <bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define INF 2147483647
#define INFLL LLONG_MAX
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<int>
#define vvi vector<vector<int>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    map<string, int> m;
    int n;
    cin >> n;
    int mcnt = 0;
    rep(i, n){
        string s;
        cin >> s;
        m[s]++;
        mcnt = max(mcnt, m[s]);
    }

    for(auto s: m){
        if(s.second == mcnt) cout << s.first << endl;
    }
    return 0;
}

Measured memory_bytes: 23808
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <complex>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack> 
#include <bitset>
#include <queue>
#include <assert.h>
#include <unordered_map>
using namespace std;

void output(long long n, int len) {
	if (len == 0) return;
	int x = n % 26;
	output(n / 26, len - 1);
	printf("%c", 'a' + x);
}

int main()
{
	long long n;
	cin >> n;
	for (long long len = 1, tot = 26; ; tot *= 26, len++) {
		if (n <= tot) {
			n--;
			output(n, len);
			cout << endl;
			return 0;
		} else {
			n -= tot;
		}
	}
	return 0;
}


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

int main(){
  int n , x, t;
  cin >> n >> x >> t;
  int ans = 0 , cnt = 0;
  while(n > cnt){
    cnt += x;
    ans += t;
  }
  cout << ans << endl;
  return 0;
}

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

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

  while (true) {
    C -= B;
    if (C <= 0) return cout << "Yes" << "\n", 0;
    A -= D;
    if (A <= 0) return cout << "No" << "\n", 0;
  }
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <numeric>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
    int n;
    cin >> n;
    n = n%10;
    if (n==2 || n==4 || n==5 || n==7 || n==9) cout << "hon" << endl;
    else if (n==3) cout << "bon" << endl;
    else cout << "pon" << endl;
}

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

const int INF = 1001001001;

vector<int> to[2505];
vector<int> rto[2505];
bool reachableFrom1[2505];
bool reachableToN[2505];
bool ok[2505];

void dfs(int v) {
  if (reachableFrom1[v]) return;
  reachableFrom1[v] = true;
  for (int u : to[v]) {
    dfs(u);
  }
}
void rdfs(int v) {
  if (reachableToN[v]) return;
  reachableToN[v] = true;
  for (int u : rto[v]) {
    rdfs(u);
  }
}

int main() {
  int n, m, p;
  cin >> n >> m >> p;
  vector<tuple<int,int,int>> edges;
  rep(i,m) {
    int a, b, c;
    cin >> a >> b >> c;
    --a; --b;
    c -= p;
    c = -c;
    edges.emplace_back(a,b,c);
    to[a].push_back(b);
    rto[b].push_back(a);
  }
  dfs(0);
  rdfs(n-1);
  rep(i,n) ok[i] = reachableFrom1[i]&reachableToN[i];
  { // bellman-ford
    vector<int> d(n,INF);
    d[0] = 0;
    bool upd = true;
    int step = 0;
    while (upd) {
      upd = false;
      rep(i,m) {
        int a, b, c;
        tie(a,b,c) = edges[i];
        if (!ok[a]) continue;
        if (!ok[b]) continue;
        int newD = d[a]+c;
        if (newD < d[b]) {
          upd = true;
          d[b] = newD;
        }
      }
      step++;
      if (step > n) {
        puts("-1");
        return 0;
      }
    }
    int ans = -d[n-1];
    ans = max(ans, 0);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 640
n,d = map(int, input().split())
x = [[0] * d for i in range(n)]

for i in range(n):
    x[i] = list(map(int,input().split()))

count = 0
for i in range(n):
    for j in range(i+1,n):
        s = 0
        for k in range(d):
            s += (x[i][k] - x[j][k]) ** 2

        if (s**(0.5)).is_integer():
            count += 1
print(count)


Measured memory_bytes: 3064
#include <stdio.h>
int prime[1000000]={0};
int main(void)
{
    int i,j;
    prime[0]=prime[1]=1;
    for(i=2;i<1000000;i++)
    {
        if(prime[i]==1) continue;
        for(j=2;i*j<1000000;j++)
            prime[i*j]=1;
    }
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int box=0;
        for(i=2;i<=n;i++)
            if(prime[i]==0)
                box++;
        printf("%d\n",box);
    }
    return 0;
}

Measured memory_bytes: 4500
#include<cstdio>
int main(){
	int a,b,c,d;
	while(~scanf("%d%d%d%d",&a,&b,&c,&d)){
		if((a + b) > (c + d))
			printf("Left\n");
		else if((a + b) == (c + d))
			printf("Balanced\n");
		else
			printf("Right\n");
	}
	return 0;
}

Measured memory_bytes: 128
def gcd(a, b)
  r = a % b
  r.zero? ? b : gcd(b, r)
end

a, b, d, e = gets.split.map(&:to_i)
g = d * e / gcd(d, e)
m = b - a + 1
cnt1 = b / d - (a - 1) / d
cnt2 = b / e - (a - 1) / e
cnt3 = b / g - (a - 1) / g
puts m - (cnt1 + cnt2 - cnt3)

Measured memory_bytes: 1788
class unionfind:
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
    def find(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def count(self, x):
        return -self.root[self.find(x)]
import sys
input=sys.stdin.readline
n=int(input())
l=[tuple(map(int,input().split())) for i in range(n)]
l.sort()
import collections
d=collections.defaultdict(int)
j=1
for i in l:
    if d[i]==0:
        d[i]=j
        j+=1
pq=[]
for i in range(n-1):
    pq.append((l[i+1][0]-l[i][0],d[l[i]],d[l[i+1]]))
l.sort(key=lambda x:x[1])
for i in range(n-1):
    pq.append((l[i+1][1]-l[i][1],d[l[i]],d[l[i+1]]))
ans=0
pq.sort()
uf=unionfind(n)
for c,x,y in pq:
    if not uf.same(x,y):
        ans+=c
        uf.unite(x,y)
print(ans)

Measured memory_bytes: 50448
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
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;
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<long long, long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N;
    ll H;
    cin >> N >> H;
    vecl A(N),B(N);
    ll ans = 0;
    REP(i,N) cin >> A[i] >> B[i];
    sort(B.begin(),B.end(),greater<ll>());
    sort(A.begin(),A.end(),greater<ll>());
    REP(i,N) {
        if(A[0] <= B[i]) {H -= B[i];
        ans++;}
        if(H <= 0) {
            cout << ans << endl;
            return 0;
        }
    }
    ans += H/A[0] + (H%A[0] == 0 ? 0 : 1);
    cout << ans << endl;
}


Measured memory_bytes: 1792
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

a = [INT() for _ in range(N)]
tmp = [0]*N
tmp2 = a[0]-1
cnt = 0
while 1:
  if tmp[tmp2] == 1:
    print("-1")
    break
  elif tmp2 == 1:
    print(cnt+1)
    break
  tmp[tmp2] = 1
  tmp2 = a[tmp2]-1
  cnt += 1

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

using namespace std;

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define debug(a) cout << #a << ": " << a << endl;

int main() {
  int A, B;
  cin >> A >> B;
  if (abs(A + B) % 2 == 0)
    cout << abs(A + B) / 2 << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main() {
	ll t1, t2, a1, a2, b1, b2;
	cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

	ll suma = a1 * t1 + a2 * t2;
	ll sumb = b1 * t1 + b2 * t2;

	// 無限回会う場合を除外
	if (suma == sumb) {
		cout << "infinity" << endl;
		return 0;
	}

	// Aがどんどん離れていく状態にする
	if (suma < sumb) {
		swap(a1, b1);
		swap(a2, b2);
		swap(suma, sumb);
	}

	// t1完了時点でどこまで追い抜いているか
	ll half = t1 * (b1 - a1);

	// 追い抜いていない場合を除外
	if (half < 0) {
		cout << 0 << endl;
		return 0;
	}

	// t2完了時点でどこまで追い抜かれているか
	ll comp = suma - sumb;

	ll ans = 1 + 2 * (half / comp);
	if (half%comp == 0) --ans;
	cout << ans << endl;
	return 0;
}

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

const ll mod = 1e9 + 7;

int n;
struct mat {
  ll a[55][55];
} m;
mat mul(mat &x, mat &y) {
  mat res;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      res.a[i][j] = 0;
      for (int k = 0; k < n; k++) {
        res.a[i][j] = (res.a[i][j] + x.a[i][k] * y.a[k][j]) % mod;
      }
    }
  }
  return res;
}
mat matpow(mat &x, ll y) {
  mat cur = x;
  mat ans;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      ans.a[i][j] = (i == j);
    }
  }
  while (y > 0) {
    if (y % 2 == 1) ans = mul(ans, cur);
    cur = mul(cur, cur);
    y /= 2;
  }
  return ans;
}

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

  ll k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> m.a[i][j];
    }
  }
  mat res = matpow(m, k);
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      ans = (ans + res.a[i][j]) % mod;
    }
  }
  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<string> A(N), B(M);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    for (int i = 0; i < M; i++)
    {
        cin >> B[i];
    }

    for (int i = 0; i + M <= N; i++)
    {
        for (int j = 0; j + M <= N; j++)
        {
            bool flag = true;
            for (int k = 0; k < M; k++)
            {
                for (int l = 0; l < M; l++)
                {
                    if (A[i + k][j + l] != B[k][l])
                        flag = false;
                }
            }
            if (flag == true)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256