akhauriyash/Code-Regression huggingface dataset:
N, Y = map(int, input().split())

resx, resy, resz = (-1, -1, -1)
xmax = min(N, Y//10000)
for x in range(xmax+1):
    ymax = (Y - 10000*x)//5000
    for y in range(ymax+1):
        z = N - x - y
        total = 10000*x + 5000*y + 1000*z

        if total == Y:
            resx, resy, resz = (x, y, z)
            break
        else:
            continue

print(resx, resy, resz)

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
signed main() {
    ll n;
    cin >> n;
  if (n == 10 || n == 100 || n == 1000 || n == 10000 || n == 100000) {
    cout<<10<<endl;
  }
  else {
        ll a = n / 100000;
        ll b = n % 100000 / 10000;
        ll c = n % 10000 / 1000;
        ll d = n % 1000 / 100;
        ll e = n % 100 / 10;
        ll f = n % 10;
        cout << a + b + c + d + e + f << endl;
  }
}

Measured memory_bytes: 3628
# coding: utf-8
def depth(i, adj, Dep, Arr, times):
    if Dep[i-1]:
        return times
    Dep[i-1]=times
    times+=1
    # t=[depth(j, adj, Dep, f, times) j in adj[i-1]]
    for j in adj[i-1]:
        times=depth(j, adj, Dep, Arr, times)
    Arr[i - 1]=times
    times+=1
    return times


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

d,f=[0]*n,[0]*n

t=1

dlist=[i for i in range(n) if d[i]==0]

for i in dlist:
    t = depth(i + 1, adj, d, f, t)

for i, df in enumerate(zip(d, f)):
    print(i + 1, *df)

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

int main(){
  int H,W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++){
    cin >> S.at(i);
    cout << S.at(i) << endl << S.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int a, b, _; cin >> a >> b >> _;
	cout << a * b / 2 << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 256
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int a, b;

void init()
{
}

void solve()
{
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b;
    cout << (b % a == 0 ? a+b : b-a) << endl;
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

#define rep(i, j) for(int i=0; i < (int)(j); i++)
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) {
    for(T &a : v) is >> a; return is;
}

void set_min(string &s, const string &s1) {
    if(s == "") s = s1;
    if(s1.size() < s.size()) s = s1;
    else if(s1.size() == s.size()) s = min(s, s1);
}


string merge(const string &s1, const string &s2) {
    rep(i, s1.size()) {
        rep(j, s2.size()) {
            if(i + j < s1.size()) {
                if(s1[i + j] != s2[j]) goto FAIL;
            } else {
                return s1 + s2.substr(j);
            }
        }
        return s1;
  FAIL:;
    }
    return s1 + s2;
}

bool solve() {
    int N; cin >> N;
    if(N == 0) return false;
    vector<string> S(N); cin >> S;
    rep(i, S.size()) rep(j, i) {
        if(merge(S[j], S[i]) == S[j]) {
            S.erase(S.begin() + i);
            i--;
            break;
        }
    }
    N = S.size();
    vector<vector<string>> dp(1 << N, vector<string>(N));
    rep(i, N) dp[1 << i][i] = S[i];
    rep(stat, 1 << N) {
        rep(src, N) {
            if(not (stat & (1 << src))) continue;
            rep(dst, N) {
                if(stat & (1 << dst)) continue;
                set_min(dp[stat | (1 << dst)][dst], merge(dp[stat][src], S[dst]));                
            }
        }
    }
    string ans = "";
    rep(i, N) {
        set_min(ans, dp[(1 << N) - 1][i]);
    }
    cout << ans << endl;
    return true;
}

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

Measured memory_bytes: 3552
use proconio::input;
use std::collections::HashMap;

fn main() {
    input! {
        n: usize,
        mut a: [u64; n],
        q: usize,
        bc: [(u64, u64); q],
    }
    let mut r = 0;
    let mut h = HashMap::new();
    for aj in a {
        *h.entry(aj).or_insert(0) += 1;
        r += aj;
    }

    for i in 0..q {
        let mut hbv = 0;
        {
            let hb = (*(&mut h)).entry(bc[i].0).or_insert(0);
            hbv = *hb;
            *hb = 0;
        }

        let hc = (*(&mut h)).entry(bc[i].1).or_insert(0);
        *hc += hbv;

        r = r + hbv * bc[i].1 - hbv * bc[i].0;

        println!("{}", r);
    }
}


Measured memory_bytes: 9532
import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        String s = sc.next();
        String t = sc.next();
        boolean bre = false;
        int yaku = 1;
        if (s.charAt(0) != t.charAt(0)) {
            bre = true;
        } else {
            for (int i = 2; i <= Math.min(n, m); i++) {
                if (n % i == 0 && m % i == 0) {
                    yaku = i;
                }
            }
            if (yaku != 1) {
                int a = n / yaku;
                int b = m / yaku;
                for (int i = 1; a * i < n && b * i < m; i++) {
                    if (s.charAt(a * i) != t.charAt(b * i)) {
                        bre = true;
                        break;
                    }
                }
            }
        }

        long l = (long)n * m / yaku;
        if (bre) {
            System.out.println(-1);
        } else {
            System.out.println(l);
        }
    }
}

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

#define pb         push_back

const int INF = 1000000000;
const int MOD = 1000000007;

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

	while(1){
		int n;
		int m;
		cin >> n;
		if(n == 0) break;

		vector<set<int> > pset;
		for(int i=0; i<n; i++){
			int m;
			cin >> m;
			set<int> tmp;
			for(int j=0; j<m; j++){
				int x;
				cin >> x;
				tmp.insert(x);
			}
			/*
			puts("set:");
			for(auto it = tmp.begin(); it != tmp.end(); it++){
				cout << *it << " ";
			}
			puts("");
			*/
			pset.push_back(tmp);
		}

		int k;
		cin >> k;
		set<int> sch;
		for(int i=0; i<k; i++){
			int x;
			cin >> x;
			sch.insert(x);
		}

		int ans = -1;
		bool f = false;
		for(int i=0; i<n; i++){
			/*
			for(auto it = pset[i].begin(); it != pset[i].end(); it++){
				cout << *it << " ";
			}
			puts("");
			*/
			//if(includes(sch.begin(), sch.end(), pset[i].begin(), pset[i].end())){
			if(includes(pset[i].begin(), pset[i].end(), sch.begin(), sch.end())){
				if(f){
					ans = -1;
					break;
				}
				ans = i;
				f = true;
			}
		}
		if(ans == -1){
			puts("-1");
		}else{
			printf("%d\n", ans+1);
		}
	}
	

	return 0;
}

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

int main()
{
    string s;
    cin >> s;
    vector<ll> cnt(26, 0);
    for (auto c: s)
    {
        ++cnt[c-'a'];
    }

    ll ans = 1+(s.size()-1)*s.size()/2;
    rep(i, 0, 26)
    {
        ans -= cnt[i] * (cnt[i] - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 644
N, K, S = list(map(int, input().split()))
if(S == 10 ** 9):
  A = [S * (i < K) + (i >= K) for i in range(N)]
else:
  A = [S * (i < K) + 10 ** 9 * (i >= K) for i in range(N)]
print(*A)

Measured memory_bytes: 9880
def search(S, n, t):
    i=0
    S[n]=t
    while (S[i] != t):
        i+=1
    return i!=n

sum=0

n=int(input())
S=list(map(int, input().split()))

S.append([0]*10000)

q=int(input())
T=list(map(int, input().split()))

for i in range(0,q):
    if search(S,n,T[i]):
        sum+=1

print(sum)

Measured memory_bytes: 6548
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	int A, B; cin >> A >> B;
	cout << max(0, A - 2 * B) << endl;

	return 0;
}

Measured memory_bytes: 256
from itertools import accumulate
from math import*
from collections import deque
from collections import defaultdict
from itertools import permutations
from heapq import*
from collections import Counter
from itertools import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

input()
d = Counter(map(int,input().split()))
input()
t = Counter(map(int,input().split()))
d.subtract(t)
if -d:
    print("NO")
else:
    print("YES")

Measured memory_bytes: 68020
MOD = 10**9+7
MAX = 2*10**5
n, m, k = map(int, input().split())

fact = [1]*(MAX+1)
for i in range(1, MAX+1):
    fact[i] = (fact[i-1]*i)%MOD
finv = [1]*MAX + [pow(fact[-1], MOD-2, MOD)]
for i in range(MAX, 0, -1):
    finv[i-1] = (finv[i]*i)%MOD

def comb(n, r):
    return ((fact[n]*finv[n-r])%MOD*finv[r])%MOD

cumsum = [0]*(MAX+1)
for i in range(1, max(n, m)+1):
    cumsum[i] = cumsum[i-1]+i

ans = 0
for i in range(n):
    ans += (cumsum[i] + cumsum[n-i-1])*(m**2)
for i in range(m):
    ans += (cumsum[i] + cumsum[m-i-1])*(n**2)

ans //= 2
ans = (ans*comb(n*m-2, k-2))%MOD
print(ans)


Measured memory_bytes: 27864
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<int>a(10000);
    vector<char>op(10000);
    vector<int>b(10000);
    for (int i=0;i<10000;i++){
        cin >> a.at(i) >> op.at(i) >> b.at(i);
        if(op.at(i)=='+'){
            cout <<a.at(i)+b.at(i)<<endl;}
        if(op.at(i)=='-'){
            cout <<a.at(i)-b.at(i)<<endl;}
        if(op.at(i)=='*'){
            cout <<a.at(i)*b.at(i)<<endl;}
        if(op.at(i)=='/'){
            cout <<a.at(i)/b.at(i)<<endl;}
        if(op.at(i)=='?'){
            break;
        }
    }

}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    vector<int64_t> dp(k+1, 0);
    dp.at(0) = 1;
    vector<int64_t> cumsum_dp(k+2, 1);
    cumsum_dp.at(0) = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= k; j++) {
            dp.at(j) = (cumsum_dp.at(j+1) - cumsum_dp.at(max(0, j-a.at(i))) + MOD) % MOD;
        }
        for (int j = 2; j <= k+1; j++) {
            cumsum_dp.at(j) = (cumsum_dp.at(j-1) + dp.at(j-1)) % MOD;
        }
    }
    cout << dp.at(k) << endl;
}

Measured memory_bytes: 1792
n,d = map(int, input().split())

xl = [list(map(int, input().split())) for _ in range(n)]

def check(x,y):
    ss = sum([(x[i]-y[i])**2 for i in range(d)])
    i = 0
    while i*i<ss:
        i += 1
    return i*i==ss


res = 0
for i in range(n-1):
    for j in range(i+1,n):
        if check(xl[i],xl[j]):
            res += 1
print(res)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>

using namespace std;

// 幸福な人数をカウントする
int count_happy(int N, vector<char> line){
    int count = 0;
    for (int i = 0; i < N; i++){
        if (i == 0 && line[0] == 'L') continue;
        if (i == N-1 && line[N-1] == 'R') continue;
        if (line[i] == 'L' && line[i-1] == 'L') count++;
        else if (line[i] == 'R' && line[i+1] == 'R') count++;
    }
    return count;
}

// l番目からr番目までを回転 (0index)
// 参照渡し(無駄なコピーを行わないため)
vector<char> rot_line(int l, int r, vector<char>& line){
    for (int i = l; i <= r; i++){
        if (line[i] == 'L') line[i] = 'R';
        else if (line[i] == 'R') line[i] = 'L';
    }
    return line;
}

int main()
{
    int N, K, rot1, rot2;
    cin >> N >> K;
    vector<char> S(N);
    for (int i = 0; i < N; i++){
        cin >> S[i];
    }

    int count_k = 0;

    // RL LR を検出して、L-L間を入れ替え
    for (int i = 0; i < N-1; i++){
        if (S[i] == 'R' && S[i+1] == 'L'){
            for (int j = i+1; j < N-1; j++){
                if (S[j] == 'L' && S[j+1] == 'R'){
                    rot1 = i+1;
                    rot2 = j;
                    S = rot_line(rot1, rot2, S);

                    // cout << "l: " << rot1 << ", r: " << rot2 << ", line: ";
                    // for (int i = 0; i < N; i++){
                    //     cout << S[i];
                    // }
                    // cout << endl;

                    count_k++;
                    break;
                }
            }
        }
        if (count_k == K) break;
    }

    if (count_k < K){
        // LR RL を検出して、R-R間を入れ替え
        for (int i = 0; i < N-1; i++){
            if (S[i] == 'L' && S[i+1] == 'R'){
                for (int j = i+1; j < N-1; j++){
                    if (S[j] == 'R' && S[j+1] == 'L'){
                        rot1 = i+1;
                        rot2 = j;
                        S = rot_line(rot1, rot2, S);

                        // cout << "l: " << rot1 << ", r: " << rot2 << ", line: ";
                        // for (int i = 0; i < N; i++){
                        //     cout << S[i];
                        // }
                        // cout << endl;

                        count_k++;
                        break;
                    }
                }
            }
            if (count_k == K) break;
        }
    }

    // 回転がK回に達していない時、ここまでで、４パターンになっている
    // 全てL、全てR、前半L後半R、前半R後半L
    // 前後半が違うパターンは1度だけ回転が必要

    if (count_k < K){
        if (S[0] != S[N-1]){
            for (int i = 0; i < N-1; i++){
                if (S[i] != S[i+1]){
                    rot1 = 0;
                    rot2 = i;
                    S = rot_line(rot1, rot2, S);

                    // cout << "l: " << rot1 << ", r: " << rot2 << ", line: ";
                    // for (int i = 0; i < N; i++){
                    //     cout << S[i];
                    // }
                    // cout << endl;

                    count_k++;
                    break;
                }
            }
        }
    }

    cout << count_happy(N, S) << endl;

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,b) for(int i=1;i<=b;i++)
#define drep(i,b) for(int i=b;i>=1;i--)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pr pair<int,int>
#define ff first
#define ss second
#define int long long
#define endl '\n'
using namespace std;
const int N=2e5+5;
const int mod=1e9+7;
int n,m,k,t,x,y,z;
int a[N],b[N],c[N],d[N],A[N];

int get(int ans=0) {
    rep(i,k) {
        if(A[b[i]]-A[a[i]]==c[i]) ans+=d[i];
    } return ans;
}

void dfs(int i,int k,int &ans) {
    A[i]=k;
    if(i==n) {
        ans=max(ans,get());
        return ;
    }
    Rep(j,k,m) dfs(i+1,j,ans);
}

void solve(int ans=0) {
    cin>>n>>m>>k;
    rep(i,k) cin>>a[i]>>b[i]>>c[i]>>d[i];
    dfs(0,1,ans);
    cout<<ans<<endl;
}

#undef int
int main() {
    ios::sync_with_stdio(false);
    //int T;cin>>T;
    //while(T--)
        solve();
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
typedef long long in;
typedef pair<in,in> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (in)x.size()
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(in i=x;i<(y);++i)
#define per(i,x,y) for(in i=y;i>=(x);--i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

int main()
{
	IOS;
	in n;
	cin >> n;
	if(n%2 == 1)
	{
		cout << "0\n";
		return 0;
	}
	in ans = 0;
	for(in i = 5; n >= i; i*=5)
	{
		in agr = n/i;
		ans += n / (2*i);
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var w, h, x, y int
	fmt.Scan(&w, &h, &x, &y)

	b := 0
	if x+x == w && y+y == h {
		b = 1
	}
	fmt.Println(float64(w*h)/float64(2), b)
}


Measured memory_bytes: 512
N,K,*X = map(int, open(0).read().split())
S = bin(K)[2:]
L = len(S)
one = set()
ls = [(a,b) for a,b in zip(*[iter(X)]*2) if a<=K]
kls = [K]
ans = 0
for i in range(L):
  if S[i]=='1':
    m = int(S[:i]+'0'+'1'*(L-i-1),2)
    kls.append(m)
for k in kls:
  m = 0
  for a,b in ls:
    if k==k|a:
      m += b
  ans = max(ans,m)
print(ans)

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

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vstr;

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define asd cout << "ok" << endl;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define trav(it, m) for(auto it = m.begin(); it it!= m.end(); it++)

const char nl = '\n';
const int MOD = 1e9 +7;
const ll INF = 1e19;
const ld PI = acos((ld)-1);
const int MX = 2e5 + 5;

int main(){

  ios_base::sync_with_stdio(0); cin.tie(0);
  int n;
  ld t, tmp;
  cin >> n >> t >> tmp;
  ld a[n+2];
  for(int i = 1; i <= n; i++)
    cin >> a[i];
  int ans;
  ld k = 1223123.123;
  for(int i =1; i <= n; i++){
    if(abs((t - a[i]*0.006) - tmp) < k)
    {
      k = abs((t - a[i]*0.006) - tmp);
      ans = i;
    }
  }
  cout << ans << nl;







  return 0;
}



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

int main(void){
    long long N,T;
    cin>>N>>T;
    
    long long sum=0,END=0;
    for(int i=0;i<N;i++){
        long long t;
        cin>>t;
        if(t<END)sum+=(t+T)-END;
        else sum+=T;
        END=t+T;
    }
    
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll x;std::cin >> x;
  std::cout << (x<1200?"ABC":"ARC") << '\n';
  return 0;
}


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

using namespace std;

class UnionFind {
  unordered_map<int, int> graph_;
  unordered_map<int, int> sizes_;

 public:
  int Root(int key) {
    if (graph_.count(key) == 0 || graph_[key] == key) {
      return key;
    } else {
      return graph_[key] = Root(graph_[key]);
    }
  }

  bool Same(int key1, int key2) { return Root(key1) == Root(key2); }

  void Unite(int key1, int key2) {
    if (Same(key1, key2)) {
      return;
    }

    int root1 = Root(key1);
    int root2 = Root(key2);
    int size = Size(root1) + Size(root2);
    graph_[root1] = root2;
    sizes_[root2] = size;
  }

  int Size(int key) {
    int root = Root(key);
    return sizes_.count(root) > 0 ? sizes_[root] : 1;
  }
};

int main(int argc, const char *argv[]) {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> edges(m);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    edges[i] = make_pair(a, b);
  }

  auto c2 = [](long long n) -> long long { return n * (n - 1ll) / 2ll; };
  UnionFind uf;
  vector<long long> ans{c2(n)};

  for (int i = m - 1; i >= 1; --i) {
    auto edge = edges[i];
    if (uf.Same(edge.first, edge.second)) {
      ans.push_back(ans.back());
    } else {
      long long sz1 = uf.Size(edge.first), sz2 = uf.Size(edge.second);
      ans.push_back(ans.back() - sz1 * sz2);
    }

    uf.Unite(edge.first, edge.second);
  }

  reverse(ans.begin(), ans.end());
  for (auto a : ans) {
    cout << a << '\n';
  }

  return 0;
}

Measured memory_bytes: 10172
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    int ans = n;
    for(int i = 0; i <= n-m; i++)
    {
        int tmp = 0;
        int cur = 0;
        for(int j = i; j < i+m; j++)
        {
            if(s[j] != t[cur]) tmp++;
            cur++;
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    while (true){
        int a, d, n; cin >> a >> d >> n;
        if(a == 0 and d == 0 and n == 0) return 0;
        else{
            int count = 0, ans;
            for(int i = a; i <= 10e6; i += d){
                if(i == 1) continue; // 1は素数ではない
                bool flag = true;
                FOR(j, 2, sqrt(i) + 1){
                    if(i % j == 0){
                        flag = false;
                        break;
                    }
                }
                if(flag or i == 2) count++;
                if(count == n){
                    ans = i;
                    break;
                }
            }
            cout << ans << endl;
        }
    }
    
}


Measured memory_bytes: 3096
"""
k,s=map(int,input().split())
x=[0]*k
for i in range(0,k):
  x[i]=i
x.append(k)
a=int(s/3)-1
count=0
for i in range(0,len(x)):
  stemp=s-x[i]
  for j in range(0,min(k+1,stemp)):
    if stemp-x[j] in x:
      count=count+1
print(count)
"""
n=int(input())
temp=[]
i=1
j=0
while True:
  temp.append(i*4+j*7)
  i=i+1
  if (i-1)*4+j*7>100:
    i=0
    j=j+1
  if j>=15:
    break
for i in range(0,len(temp)):
  if temp[i]==n:
    print("Yes")
    break
else:
  print("No")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,N) for(ll i=0; i<N; i++)
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

int main(){
    ll n; cin >> n;
    ll odd = (n+1)/2;

    double ans = (double) odd / n;
    cout << ans << endl;
}


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

int main()
{
  	int a,b,c;
  	double s,l,h,rad;
  
 	cin >> a >> b >> c;
  	
  	rad = c * M_PI / 180.0;
      
    s = a*b / 2 * sin(rad);
    l = sqrt(a*a + b*b -2*a*b*cos(rad)) + a + b;
  	h = s * 2.0 / a;
      
  	cout  << fixed << setprecision(8) << s << endl;
  	cout  << l << endl;
  	cout  << h << endl;
  
}


Measured memory_bytes: 3480
//shan61916
#include <bits/stdc++.h>
    using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n" 
typedef long long ll;
typedef unsigned long long ull ;
typedef double dll ;

int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  string s;
  cin >> s;
  ll fir = (ll)(s[0] - '0')*10 + (ll)(s[1] - '0') ;
  ll sec = (ll)(s[2] - '0')*10 + (ll)(s[3] - '0') ;
  ll  mt = 0, st = 0;
  ll na = 0;
  if(fir  >= 1 and fir <= 12)mt++ ;
  if(sec  >= 1 and sec <= 12)st++;
  if((fir  < 1 or  fir > 12) and (sec  < 1 or  sec > 12)) na++;
  if(na) {
    cout << "NA" ;
    return 0;
  }
  if(mt and st) {
    cout << "AMBIGUOUS";
  }
  else if(st) {
    cout <<"YYMM" ;
    
  }
  else {
    cout << "MMYY" ;
  }
  return 0;
} //good night.

Measured memory_bytes: 256
N=int(input())
s=[input() for _ in range(N)]
#print(s)

b=[[0 for i in range(26)] for j in range(N)]
for i,ss in enumerate(s):
  for j in list(ss):
      b[i][ord(j)-97]+=1
#print(b)

c=[10**10]*26
for j in range(26):
  for i in range(N):
    c[j]=min(c[j],b[i][j])
#print(c)

ans=[]
for j in range(26):
  ans.append(c[j]*chr(j+97))
print("".join(ans))

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int d=max({a,b,c}),e=min({a,b,c});
	int f=a+b+c-d-e;
	if(d==e){
		cout<<1<<endl;
	}
	else if(f>e&&f<d){
		cout<<3<<endl;
	}
	else{
		cout<<2<<endl;
	}
	return 0;
}
		


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

int main(int argc, char **argv)
{
	char S[200], T[200];
	scanf("%s %s", S, T);
	printf("%s%s\n", T, S);
	return 0;
}


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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int>a(n);
  for(int i=0;i<n;i++)
    cin >> a.at(i);
  sort(a.begin(),a.end());
  int ans=0;
  for(int i=0;i<m;i++)
    ans+=a.at(i);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3616
using System;

namespace ITP1_8_B
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string x = Console.ReadLine();
                if (x == "0")
                    break;
                int sum = 0;
                foreach (var n in x)
                {
                    sum += int.Parse(n.ToString());
                }
                Console.WriteLine(sum);
            }
        }
    }
}

Measured memory_bytes: 9228
X, Y = input().split()
x = int(X)
y = int(Y)
a = (4*x - y) / 2
b = (-2*x + y) / 2
if(a >= 0 and a.is_integer() and b >= 0 and b.is_integer()):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9180
#include<stdio.h>
int main(){
  int a,b,c,d;
  int max1, max2;
  //scanf("%d %d %d %d", &a, &b, &c, &d);
  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &c);
  scanf("%d", &d);
    
  if(a < b)
    max1 = a;
  else
    max1 = b;

  if(c < d)
    max2 = c;
  else
    max2 = d;

  printf("%d\n", max1+max2);

  return 0;
}


Measured memory_bytes: 128
def solve(a):
    m, diff, ans = 10 ** 10, 0, 0
    for i in range(len(a)):
        if a[i] < m:
            m = a[i]
        elif a[i] - m > diff:
            diff = a[i] - m
            ans = 1
        elif a[i] - m == diff:
            ans += 1

    return ans


def main():
    n, t = map(int, input().split())
    a = list(map(int, input().split()))
    print(solve(a))

if __name__ == '__main__':
    main()


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

void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i,n) cin >> v[i];
  vector<int> copied = v;
  sort(copied.begin(), copied.end());
  rep(i,n) {
    if (v[i] != copied[n-1]) cout << copied[n-1] << endl;
    else cout << copied[n-2] << endl;
  }
}

int main() {
  solve();
  return 0;
}


Measured memory_bytes: 3200
from bisect import bisect_right
from collections import defaultdict

s = list(input())
t = list(input())

L = len(s)
M = len(t)

ss = s * 2

ind_dict = defaultdict(list)
for i in range(2 * L):
    ind_dict[ss[i]].append(i)


def query_str(c, ind):
    if len(ind_dict[c]) == 0:
        return -1
    else:
        r = bisect_right(ind_dict[c], ind)
        return ind_dict[c][r]


res_total = 0
res = -1
for i in range(M):
    res = query_str(t[i], res)
    if res == -1:
        res_total = 0
        break
    if res >= L:
        res -= L
        res_total += L

if res == -1:
    print(-1)
else:
    print(res_total + res + 1)



Measured memory_bytes: 63656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;


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

    ll x;
    cin>>x;
    ll ans = 0,n = 100;

    while(n < x){
        ans++;
        n *= 1.01;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <string>
#include <climits>
#include <algorithm>

using namespace std;

bool nprime[1000000]={0};
int main(){
	
	for(int i=2; i<1000000; ++i){
		
		if(!nprime[i]){
			for(int j=i+i; j<1000000; j+=i){
				nprime[j] = true;
			}
		}
		
	}
	
	int n;
	
	while(cin>>n, n){
		
		int up = 2*n;
		int sum = 0;
		
		for(int i=n+1; i<=up; ++i){
			
			if(!nprime[i])
				sum++;
		}
		
		cout << sum << endl;
	}
	
	return 0;
}

	

Measured memory_bytes: 2136
using System;
using System.IO;

namespace Tenka2019C
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Console.SetIn(new StreamReader(args[0]));
            }

            new Program().Solve();
        }

        void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine().ToCharArray();

            var leftBlack = new int[N + 1];
            leftBlack[0] = 0;

            var rightWhite = new int[N + 1];
            rightWhite[N] = 0;

            var temp = 0;

            for (int i = 0; i < S.Length; i++)
            {
                if (S[i] == '#')
                {
                    temp++;
                }
                leftBlack[i + 1] = temp;
                // Console.Error.WriteLine("l:" + i + ":" + temp);
            }

            temp = 0;

            for (int i = S.Length - 1; i >= 0; i--)
            {
                if (S[i] == '.')
                {
                    temp++;
                }
                rightWhite[i] = temp;
                // Console.Error.WriteLine("r:" + i + ":" + temp);
            }

            var min = int.MaxValue;

            for (int i = 0; i <= S.Length; i++)
            {
                temp = leftBlack[i] + rightWhite[i];
                // Console.Error.WriteLine(i + ":" + temp);
                min = Math.Min(min, temp);
            }

            Console.WriteLine(min);
        }
    }
}


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

int main() {
  int n;
  cin >> n;
  vector<vector<bool>> a(n, vector<bool>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int w;
      cin >> w;
      a.at(i).at(j) = w;
    }
  }
  vector<vector<int64_t>> dp(n + 1, vector<int64_t>(1 << n));
  dp.at(0).at(0) = 1;
  //for (int i = 0; i < n; i++) {
    for (int s = 0; s < 1 << n; s++) {
      for (int j = 0; j < n; j++) {
        if (s & (1 << j)) continue;
        int i = __builtin_popcount(s);
        if (!a.at(i).at(j)) continue;
        (dp.at(i + 1).at(s + (1 << j)) += dp.at(i).at(s)) %= 1000000007;
      }
    }
  //}
  cout << dp.at(n).at((1 << n) - 1) << endl;
}


Measured memory_bytes: 377344
# include <iostream>
# include <cstdio>
# include <cmath>
# include <cstring>
# include <string>
# include <cstdlib>
# include <algorithm>
# include <stack>
# include <queue>
# include <vector>
# define maxx (103)
# define Pi (3.14159265358979)
# define inf (2147483647)
using namespace std;
int read() {
	int x=0,f=1;
	char ch;
	while(ch<'0'||ch>'9')  {
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		x=x*10+ch-'0';
		ch=getchar();
	}
	return f*x;
}
int main() {

	char c;
	int a=0,i;
	
	for(i = 1;i <= 4;i++){
		c=getchar();
		if(c=='2'){
			a++;
		}
	}
	cout << a << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <math.h>
using namespace std;

int main()
{
	int A, B, C, K;

	cin >> A >> B >> C >> K;

	if(A >= K){
		cout << K;
	}else if(A+B >= K){
		cout << A;
	}else{
		cout << (A-(K-A-B));
	}

	return 0;
	
}

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

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

//0 1 2 3
//S H D C
int conv_s(char s){
    if(s=='S')return 0;
    if(s=='H')return 1;
    if(s=='D')return 2;
    return 3;
}

//0 ... 12
//2 3 ... 9 10 11 12 13 1
int conv_n(char n){
    if(isdigit(n))return n-'0'-2;
    if(n=='T')return 8;
    if(n=='J')return 9;
    if(n=='Q')return 10;
    if(n=='K')return 11;
    return 12;
}

int T;
int n[4][13],s[4][13];

signed main(){
    char hoge;
    while(cin>>hoge,hoge!='#'){
        T=conv_s(hoge);
        rep(i,4)rep(j,13){
            char x,y;
            cin>>x>>y;
            n[i][j]=conv_n(x);
            s[i][j]=conv_s(y);
        }

        int point[2]={0};
        int par=0;
        rep(t,13){
            int k[4]={0};
            k[s[par][t]]=1;
            k[T]=2;
            pint st[4];
            rep(i,4)st[i]=pint(k[s[i][t]]*13+n[i][t],i);
            sort(st,st+4);
            par=st[3].se;
            point[par&1]++;
        }
        if(point[0]>point[1])cout<<"NS "<<point[0]-6<<endl;
        else cout<<"EW "<<point[1]-6<<endl;
    }
    return 0;
}

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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

ll dp[200][10];
ll mod = 1000000007;
int h,w,k;
bool check(int pattern) {
  for(int i=0;i<=w;i++){
    if( ((1<<i)&pattern) && ((1<<(i+1))&pattern) ){
      return false;
    }
  }
  return true;
}

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  cin>>h>>w>>k;

  int pattern = pow(2, w-1);
  dp[0][0]=1;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      for(int k=0;k<pattern;k++){
        if(!check(k))continue;
        if(j>0 && ( (k>>(j-1)) &1) )  {
          // 左
          dp[i+1][j-1]+=dp[i][j];
          dp[i+1][j-1]%=mod;
        }
        else if(j<w-1 && ( (k>>(j)) &1)  ) {
          // 右
          dp[i+1][j+1]+=dp[i][j];
          dp[i+1][j+1]%=mod;
        }
        else {
          // 下
          dp[i+1][j]+=dp[i][j];
          dp[i+1][j]%=mod;
        }
      }
    }
  }

  // for(int i=0;i<=h;i++){
  //   for(int j=0;j<w;j++){
  //     printf("%14lld", dp[i][j]);
  //   }
  //   printf("\n");
  // }
  // printf("\n");

  cout<<dp[h][k-1]<<endl;

  return 0;
}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseArray(x::Array{SubString{String}, 1}) = map(parseInt, x)

function main()
  x, y = readline() |> split |> parseArray

  z = (4x-y)÷2
  w = (4x-y)%2
  if w==0 && z>=0 && z<=x
    println("Yes")
  else
    println("No")
  end
end

main()


Measured memory_bytes: 161120
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
#define mod 1000000007
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define setA0(a) for(ull i =0;i<n;i++){a[i] = 0;}
#define aout(a) for(auto x : a){cout<<x<<' ';} // array output macro 
#define ain(a) for(ull i =0;i<n;i++){cin>>a[i];} //array input macro
#define NofSetBits(x) __builtin_popcount(x);
#define InpGrph(g,e) while(e--){ll x;ll y;cin>>x>>y ;g[x].pub(y);g[y].pub(x);}
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main(){
  FastIO;
  ll lim = 1000050;
  ll n;
  cin>>n;
  ull ans =n-1;
  for(ull i=1;i<=lim;i++){
     if(n%i==0){
        ans = min(ans,i+(n/i) - 2);
     }
  }
  cout<<ans;
   
  return 0;
} 


Measured memory_bytes: 3620
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
    long long k; cin >> k;
    long long a[50] = {};
    for (int i = 0; i < 50; i++) a[i] += 49 + k/50;
    for (int i = 0; i < 50; i++) a[i] += i < k%50 ? 51 - k%50 : -(k%50);
    cout << "50\n";
    for (int i = 0; i < 50; i++) cout << a[i] << ' ';
    cout << endl;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        String Sa = sc.next();
        String Sb = sc.next();
        String Sc = sc.next();
        sc.close();

        int numA = Sa.length();
        int numB = Sb.length();
        int numC = Sc.length();
        int countA = 0;
        int countB = 0;
        int countC = 0;
        
        char turn = 'a';

        while(true){
            if(turn == 'a'){
                if(countA == numA){
                    System.out.println('A');
                    break;
                }
                turn = Sa.charAt(countA);
                countA++;
            }
            if(turn == 'b'){
                if(countB == numB){
                    System.out.println('B');
                    break;
                }
                turn = Sb.charAt(countB);
                countB++;
            }
            if(turn == 'c'){
                if(countC == numC){
                    System.out.println('C');
                    break;
                }
                turn = Sc.charAt(countC);
                countC++;
            }    
        }
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;

struct state{
	  int x,y;
	  int s;
	  int t;
	  int dir;
	  state(int xi, int yi, int score,int time){
			x = xi; y = yi; s = score; t = time;
			dir = abs((ll)xi*(ll)yi*(ll)time ) % 6 ;
	  }
	  bool operator > (const state& tgt) const {
			return s > tgt.s;
	  }
	  bool operator < (const state& tgt) const {
			return s < tgt.s;
	  }
	  bool operator == (const state& tgt) const {
			if(x == tgt.x and y == tgt.y)
				  return true;
			else
				  return false;
	  }
	  
};

const int dx[2][7] = {{ 0, 1, 1, 0,-1,-1, 0}, { 0, 1, 1, 0,-1,-1, 0}};
const int dy[2][7] = {{ 1, 0,-1,-1,-1, 0, 0}, { 1, 1, 0,-1, 0, 1, 0}};
int sx,sy,gx,gy;
int lx,ly;
int n;
int used[300][300][6];
vvi board;

void dijk(){

	  state ini = state(sx,sy,0,0);
	  priority_queue<state,vector<state>,greater<state> > q;
	  q.push(ini);

	  state corr = state(0,0,0,0);
	  while(q.size()){
			corr = q.top();		q.pop();

			if(corr == state(gx,gy,0,0)) break; // ??´??????
			if(used[corr.y+150][corr.x+150][corr.t%6] != -1)  continue; // ??¢?´¢??????
//			cout << "    POP (" << corr.x << "," << corr.y << ") "<< corr.s << "s ," << corr.t << "t" << endl;

			used[corr.y+150][corr.x+150][corr.t%6] = 1; // ??¢?´¢??????

			for(int i=0; i<7; i++){
				  int tmp = (corr.x + 300) % 2;
				  int nx  = corr.x + dx[tmp][i];
				  int ny  = corr.y + dy[tmp][i];
				  if(abs(nx) > lx || abs(ny) > ly)  continue; // ?£????
				  if(board[ny+150][nx+150] == 1)	continue; // ??¶???
				  
				  int score = corr.s;
				  if(corr.dir != i) score += 1; // ???????????????????????´???
//				  cout << "      PUSH (" << nx << "," << ny << ") "<< score <<"s ," << corr.t+1 << "t" << endl;
				  state next = state(nx, ny, score, corr.t+1); 
				  if(used[ny+150][nx+150][next.t%6] != 1)
						q.push(next);
			}
	  }
	  if(corr == state(gx,gy,0,0)) // ??´??????
			cout << corr.s << endl;
	  else
			cout << -1 << endl;
}


int main(){

//	  cout << (-11)%4x << endl;
	  cin >> sx >> sy >> gx >> gy;
	  cin >> n;
	  board = vvi(300,vi(300,0));
	  memset(used,-1,sizeof(used));
	  for(int i=0; i<n; i++){
			int xi,yi; cin >> xi >> yi;
			board[yi+150][xi+150] = 1;
	  }
	  cin >> lx >> ly;
	  dijk();
	  
}

Measured memory_bytes: 6008
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cassert>

using namespace std;


bool solve(){
	
	int n, m, p;
	cin>> n>> m>> p;
	if(n==0 && m==0 && p==0) return false;
	
	int a=0, b=0;
	for(int i=0;i<n;i++){
		int in;
		cin>> in;
		a += in;
		if(i == m-1) b = in;
	}
	if(b==0){	//気付かぬ…
		cout<< 0<< endl;
	}else{
		cout<< a*100 * (100-p)/100 / b<< endl;
	}
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	while(solve());

	return 0;
}

 

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n) for (int i = n; 0<i;i--)
#define print(out) cout<< out  << "\n";
#define mod 1000000007
const int INF = 1e9;

int main(){
  int N,K,k;cin>>N>>K;
  double rev=0.0,tmp;
  REP(i,1,N+1){
    tmp=1.0/N;
    int now=i;
    while(now<K){
      tmp/=2;
      now*=2;
    }
    rev+=tmp;
  }
  cout<<setprecision(12)<<rev<<"\n";

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define r0 return 0;
#define f(k,i,n,j) for(ll k=i;k<=n;k=k+j)
#define cin(a) cin>>a;
#define loop while(t--)
#define vi vector<int>
#define vii vector<long long int>
#define SORT(v) sort(v.begin(),v.end());
#define mod (1e9+7)
#define crap ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
bool palin(string s)
{
    int i=0,j=s.length()-1;
    while(i<j)
    {
        if(s[i++]!=s[j--])
            return false;
    }
    return true;
}
signed main()
{
    crap;
    string s;
    cin>>s;
    if(palin(s))
    {
        string t=s.substr(0,(s.size()-1)/2);
        string r=s.substr((s.size()+3)/2);
        if(palin(t) && palin(t))
        cout<<"Yes"<<endl;
        else
        cout<<"No"<<endl;
        
    }
    else
    {
        cout<<"No"<<endl;
    }
    
}

Measured memory_bytes: 256
#include<math.h>
#include<map>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include<array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
#include<bitset>
#include <list>
#include<numeric>
#include <fstream>
#include<set>
//AtCoderC++.cpp

using namespace std;

template<typename T>
inline T ceiling(T n, T d) {
	return n % d == 0 ? n / d : n / d + 1;
}


int main() {
	int N; cin >> N;
	auto as = vector<double>(N);
	double answer = 0;
	for (size_t i = 0; i < N; i++) {
		cin >> as[i]; as[i] = 1 / as[i];
		answer += as[i];
	}
	cout << 1 / answer << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int a = 0;
  int b = 0;
  for (int i = 0; i < N; i++) {
    if ((i % 2) == 0 ) {
      a = a + vec.at(i);
    }
    else {
      b = b + vec.at(i);
    }
  }
  cout << a - b << endl;
}


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

int main() {
	string moji;
	cin >> moji;
	
	string core ="CODEFESTIVAL2016";
	int count=0;
	
	for(int i=0; i<16; i++){
		if(moji[i]!=core[i]){count++;}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P; typedef unsigned long long int ull;
const ll mod = 1000000007;
const int inf = 1e9 + 7;
const ll linf = 1LL << 60;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define REP(i,m,n) for(int i=(m);i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define vec vector<int>
#define vecb vector<bool>
#define vecd vector<double>
using str = string;
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
std::string sreverse(string str, int firstItr, int secondItr) {
	if (firstItr < 0 || secondItr>int(str.size() - 1))return str;
	while (firstItr < secondItr) {
		swap(str[firstItr], str[secondItr]);
		firstItr++; secondItr--;
	}
	return str;
}
std::string RunLengthEncoding(std::string str) {
	int itr = 0; std::string res;
	while (itr < int(str.size())) {
		char tmp = str[itr++];
		int length = 1;
		while (itr <int(str.size()) && str[itr] == tmp) { ++itr; ++length; }
		res.push_back(tmp);
		res += to_string(length);
	}
	return res;
}
std::string split(std::string str, size_t first_itr, size_t second_itr) {
	std::string tmp;
	for (size_t i = first_itr; i < second_itr + 1; i++) {
		tmp.push_back(str.at(i));
	}
	return tmp;
}



int main() {
	str s; cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256