akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**9)


class SegmentTree1():
    """
    1-indexed Segment Tree
    """
    def __init__(self, n_, ele_id, operation_func):
        self.n = 1 << (n_ - 1).bit_length()  # size
        self.data = [ele_id] * (2 * self.n)  # binary tree
        self.ele_id = ele_id  # identity element
        self.operation_func = operation_func  # binary operation of monoid

    def __getitem__(self, idx):
        return self.data[idx + self.n]

    def build(self, data_init):
        for i in range(len(data_init)):
            self.data[i + self.n] = data_init[i]
        for i in range(self.n - 1, 0, -1):
            self.data[i] = self.operation_func(self.data[2 * i],
                                               self.data[2 * i + 1])

    def update(self, idx, x):
        # change idx-th element to x (idx : 0-indexed)
        idx += self.n
        self.data[idx] = x
        while idx > 1:
            idx = idx >> 1
            self.data[idx] = self.operation_func(self.data[2 * idx],
                                                 self.data[2 * idx + 1])

    def query(self, l, r):
        # query for interval [l, r) (l, r : 0-indexed)
        l += self.n
        r += self.n
        ret = self.ele_id
        while l < r:
            if l & 1:  # right child
                ret = self.operation_func(ret, self.data[l])
                l += 1
            if r & 1:  # right child
                r -= 1
                ret = self.operation_func(ret, self.data[r])
            # go to parent-nodes
            l = l >> 1
            r = r >> 1
        return ret


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

dp = [-1] * (n + 1)
dp[n] = 1
roulette = [0] * (n + 1)

INF = 10**10
INF_PAIR = (INF, -1)
operation_func = lambda a, b: a if a[0] < b[0] else (b if a[0] > b[0] else
                                                     (a if a[1] < b[1] else b))
rmq = SegmentTree1(n + 1, INF_PAIR, operation_func)
rmq.update(n, (0, n))
for i in range(n - 1, -1, -1):
    if s[i] == '1':
        continue
    val, idx = rmq.query(i + 1, min(n, i + m) + 1)
    if val != INF:
        roulette[i] = idx - i
        dp[i] = val + 1
        rmq.update(i, (val + 1, i))

if dp[0] == -1:
    print(-1)
else:
    ans = []
    idx = 0
    while idx < n:
        ans.append(roulette[idx])
        idx += roulette[idx]
    print(*ans)


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

#define ll long long
#define ar array

const int mxN = 2e5;
int n, m;
ll k, a[mxN + 1], b[mxN + 1];

int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> m >> k;
	for (int i = 0; i < n; ++i) {
		cin >> a[i + 1];
		a[i + 1] += a[i];
	}
	for (int i = 0; i < m; ++i) {
		cin >> b[i + 1];
		b[i + 1] += b[i];
	}
	int ans = 0;
	for (int i = 0, j = m; i <= n; ++i) {
		if (a[i] > k)
			break;
		while (a[i] + b[j] > k)
			--j;
		ans = max(i + j, ans);
	}
	cout << ans;
}


Measured memory_bytes: 6748
#include <iostream>
#include <map>
#include <cstring>
using namespace std;

int x[100],y[100],sx[100],sy[100],n;

int lim , N , M , X;

int dp[2][1001][101];
int main(){
	while(cin >> lim >> N >> M >> X && lim){
		for(int i = 0 ; i < 2 ; i++)
			for(int j = 0 ; j <= lim ; j++)
				for(int k = 0 ; k <= M ; k++)
					dp[i][j][k] = -99999999;
		for(int i = 0 ; i < N ; i++){
			string t; cin >> t;
			cin >> sx[i] >> sy[i];
		}
		for(int i = 0 ; i < M ; i++){
			string t; cin >> t;
			cin >> x[i] >> y[i];
		}
		dp[0][0][0] = 0;
		
		for(int i = 0 ; i < M ; i++){
			for(int j = 0 ; j <= lim ; j++){
				for(int k = 0 ; k <= M ; k++){
					dp[i&1^1][j][k] = dp[i&1][j][k];
				}
			}
			for(int j = 0 ; j+x[i]  <= lim ; j++){
				for(int k = 0 ; k < M ; k++){
					dp[i&1^1][j+x[i]][k+1] = max( dp[i&1^1][j+x[i]][k+1] , dp[i&1][j][k] + y[i]);
				}
			}
		}
		int memory[1001]={0};
		for(int w = 0 ; w <= lim ; w++){
			for(int z = X ; z <= M ; z++){
				memory[w] = max(w?memory[w-1]:0,max(memory[w],dp[M&1][w][z]));
			}
		}
		int ans = 0;
		for(int i = 0 ; i < N ; i++)
			for(int j = i+1 ; j < N ; j++){
				int rem = lim - sx[i] - sx[j];
				if(rem>=0) ans = max(ans,sy[i]+sy[j]+memory[rem]);
			}
		for(int i = 0 ; i < N ; i++){
			int rem = lim - sx[i];
			if(rem>=0) ans = max(ans,sy[i]+memory[rem]);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1716
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

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

  ll x;
  cin>>x;
  ll res=0;
  if(x>=500){
      int mod=x%500;
      res+=(x/500)*1000;    
      res+=(mod/5)*5;
  }
  else{
     res+=(x/5)*5;
  }
  cout<<res<<endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int N, H;
	cin >> N >> H;

	vpii katana(N, pair<int, int>(0, 0));
	for (int i = 0; i < N; i++)
		cin >> katana[i].second >> katana[i].first;

	sort(rall(katana));
	int K = 0;
	for (int i = 1; i < N; i++)
	{
		int a = katana[i].second;
		int b = katana[i].first;
		if (a == katana[K].second)
		{
			if (b < katana[K].first)
				K = i;
		}
		else if (a > katana[K].second)
			K = i;
	}

	int mx_a = katana[K].second;
	int ans = 0;
	for (int c = 0; c < N && H > 0; c++)
	{
		int b = katana[c].first;
		if (b > mx_a)
		{
			H -= b;
			ans++;
		}
	}
	if (H <= 0)
		cout << ans << endl;
	else if (H % mx_a == 0)
		cout << ans + H / mx_a << endl;
	else
		cout << ans + H / mx_a + 1 << endl;
}














Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
int main(){
      int n;
      while(scanf("%d",&n)&&n){
            vector<int> a(n),b(n);
            REP(i,n)scanf("%d",&a[i]);
            REP(i,n)scanf("%d",&b[i]);
            sort(ALL(a),greater<int>());
            sort(ALL(b),greater<int>());
            int k=0,now=0,ans=-1;
            REP(i,n){
                  if(b[now]>=a[i])now++;
                  else k++;
                  if(k>(i+1)/2){
                        ans=i+1;
                        break;
                  }
            }
            if(ans==-1||ans==n)printf("NA\n");
            else printf("%d\n",ans);
      }
}

Measured memory_bytes: 1444
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    N = I()
    A = LI()
    ans = 0
    tl = 0
    for a in A:
        tl += a
    for i in range(N):
        tl -= A[i]
        ans += (A[i] * tl) % mod
    ans %= mod
    print(ans)



if __name__ == '__main__':
    main()

Measured memory_bytes: 102004
N = int(input())

s = [0] * N

for i in range(N):
    s[i] = input()

M = int(input()) 

t = [0] * M

for i in range(M):
    t[i] = input()
    
p = "" 
counter = 0
ans = 0

for i in range(N):
    p = s[i]
    for ii in range(N):
        if p == s[ii]:
            counter += 1
    for iii in range(M):
        if p == t[iii]:
            counter -= 1
    if ans < counter:
        ans = counter
    counter = 0    

print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#define max(a, b) a > b ? a : b
#define min(a, b) a < b ? a : b

int main()
{
	int n, i;
	
	scanf ("%d", &n);
	
	int R[200000];
	
	for(i = 0; i < n; i++) {
		scanf ("%d", &R[i]);
	}
	
	int maxv = -2000000000;
	int minv = R[0];
	
	for (i = 1; i < n; i++) {
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}
	
	printf ("%d\n", maxv);
	
	return 0;
}


Measured memory_bytes: 2648
import sys
A, B, C, K = map(int, input().split())
N = 0
if K - A < 0:
    print(K)
    sys.exit()
else:
    N = A
    K = K - A
if K - B < 0:
    print(N)
    sys.exit()
else:
    K = K - B
print(N - K)

Measured memory_bytes: 61656
#include <iostream>
#include<string>
using namespace std;
int main(){

    string S, T;
    cin >> S >> T;
    
    string str = S + S;
    
    if(str.find(T)!=string::npos){
        cout << "Yes";
    }else{
        cout << "No";
    }
    

return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
 
int twodiv(int x){
    int ret=0;
    while(x%2==0){
        x/=2;
        ret++;
    }
    return ret;
}


signed main(){
    int N;
    cin >>N;
    int ans=100000000000;
    REP(i,N){
        int a;
        cin>>a;
        ans =min(ans,twodiv(a));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<vector>
#include<list>
#include<set>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int m,n,t;
  int mx;
  multiset<int> a;
  multiset<int>::iterator it,jt;
  while(cin>>m>>n&&m+n){
    a.clear();
    a.insert(0);
    for(i=0;i<m+n;i++){
      cin>>t;
      a.insert(t);
    }
    mx=-1;
    it=jt=a.begin();
    jt++;
    for(i=0;i<m+n;i++){
      if(mx<*jt-*it)
	mx=*jt-*it;
      it++;
      jt++;
    }
    cout<<mx<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
N = int(input())

i_guess = int(N**0.5)
j_found = 0
i_found = 0
while i_found == 0:
    if N%i_guess == 0:
        i_found = i_guess
        j_found = int(N/i_found)
    else:
        i_guess -= 1

print(i_found+j_found-2)

Measured memory_bytes: 3060
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,n) for(int i = 0;i<(n);i++);
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 100100100100100;


int main() {
  ll X;
  cin >> X;
  if(X == 3||X == 5||X ==7) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {

	S := nextString()

	if S == "ABC" {
		fmt.Println("ARC")
	} else {
		fmt.Println("ABC")
	}
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    VV<char> a(n, V<char>(n));
    VV<char> b(m, V<char>(m));
    rep(i, n) rep(j, n) cin >> a[i][j];
    rep(i, m) rep(j, m) cin >> b[i][j];
    rep(i, n-m+1) rep(j, n-m+1) {
        bool flag = true;
        rep(k, m) rep(l, m) {
            if(a[i+k][j+l] != b[k][l]) flag = false;
        }
        if(flag) {
            Yes();
            return 0;
        }
    }
    No();
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
 
using namespace std;
 
 
	
int main()
{ 
	int r;
	cin>>r;
	double pi=3.1415926;
	double ans=2*r*pi;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9) + 7;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

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

ll factorial(ll n){
    ll t = 1;
    rep1(i, n){
        t *= i;
        t %= mod;
    }
    return t;
}

ll power(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = power(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = 1;
    for(ll i = 0; i < b; i++) {
        ans *= (a - i);
        ans /= (i + 1);
        ans %= mod;
    }
    return ans;
}

int main(){
    string s;
    cin >> s;
    if(s == "ABC")pf("ARC");
    else pf("ABC");
    return 0;
}



Measured memory_bytes: 3600
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int MOD = 1000000007;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int m = parseInt(sc.next());
		sc.close();
		out.println((n*(n-1))/2+(m*(m-1))/2);
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long int64;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int k;
	cin >> k;
	int64 sum = 0;
	for (int64 a = 1; a <= k; ++ a) {
		for (int64 b = 1; b <= k; ++ b) {
			int64 cur = __gcd(a, b);
			for (int64 c = 1; c <= k; ++ c) {
				sum += __gcd(cur, c);
			}
		}
	}
	cout << sum;
	
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i, n) for (ll i = 0; i < (n); i++)
#define fori(i, b, e) for (ll i = (b); i < (e); i++)
#define forr(i, b, e) for (ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    a--, b--, c--, d--;
    string s;
    cin >> s;

    bool flag = false;
    fori(i, a, b + 1)
    {
        static char ch = '?';
        static int cnt = 0;
        if (s[i] == ch || ch == '?')
            ch = s[i], cnt++;
        else
        {
            if (ch == '#' && cnt >= 2)
                return cout << "No", 0;
            ch = s[i], cnt = 1;
        }
    }
    fori(i, c, d + 1)
    {
        static char ch = '?';
        static int cnt = 0;
        if (s[i] == ch || ch == '?')
            ch = s[i], cnt++;
        else
        {
            if (ch == '#' && cnt >= 2)
                return cout << "No", 0;
            ch = s[i], cnt = 1;
        }
    }
    if (c > d)
    {
        if (b != n - 1 && s[b + 1] == '.')
        {
            while (b > 0 && s[b] == '.')
                b--;
            if (s[b] == '#')
                b++;
            b = max(a, b);
        }
        char ch = '?';
        int cnt = 0;
        fori(i, b, d + 1)
        {
            if (s[i] == ch || ch == '?')
                ch = s[i], cnt++;
            else
            {
                if (ch == '.' && cnt >= 3)
                    flag = true;
                ch = s[i], cnt = 1;
            }
        }
        if (ch == '.' && cnt >= 2)
            flag = true;
    }

    if (c < d)
        return cout << "Yes", 0;
    if (flag)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

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

using namespace std;

#define MAX_N 125
#define INF 1e9
const double EPS = 1e-8;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<double> vec;
typedef vector<vec> mat;

vec gauss_jordan(const mat &A,const vec &b){
  int n = A.size();
  mat B(n,vec(n+1));
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < n ; j++){
      B[i][j] = A[i][j];
    }
  }
  for(int i = 0 ; i < n ; i++){
    B[i][n] = b[i];
  }
  for(int i = 0 ; i < n ; i++){
    int pivot = i;
    for(int j = i ; j < n ; j++){
      if(abs(B[j][i]) > abs(B[pivot][i])){
        pivot = j;
      }
    }
    swap(B[i],B[pivot]);
    if(abs(B[i][i]) < EPS) return vec();
    for(int j = i+1 ; j <= n ; j++){
      B[i][j] /= B[i][i];
    }
    for(int j = 0 ; j < n ; j++){
      if(i != j){
        for(int k = i+1 ; k <= n ; k++){
          B[j][k] -= B[j][i]*B[i][k];
        }
      }
    }
  }
  vec x(n);
  for(int i = 0 ; i < n ; i++){
    x[i] = B[i][n];
  }
  return x;
}

struct Edge{
  int to,dist;
  Edge(int to,int dist) :
    to(to),dist(dist) {}
};

void solve(vi &sign,vii &road,vii &d,int S,int T,int N){
  mat A(N,vec(N,0));
  vec b(N,0);
  for(int i = 0 ; i < N ; i++){
    if(i == T){
      A[i][i] = 1; b[i] = 0;
      continue;
    }
    double sum = 0;
    int cnt = 0;
    if(sign[i] == 0){
      for(int j = 0 ; j < N ; j++){
        if(road[i][j] != INF){
          A[i][j] = -1;
          sum += road[i][j];
          cnt++;
        }
      }
    }else{
      int mini = INF;
      for(int j = 0 ; j < N ; j++){
        if(road[i][j] != INF){
          mini = min(mini,road[i][j]+d[j][T]);
        }
      }
      for(int j = 0 ; j < N ; j++){
        if(mini == road[i][j]+d[j][T] && road[i][j] != INF){
          cnt++;
          A[i][j] = -1;
          sum += road[i][j];
        }
      }
    }
    A[i][i] = cnt;
    b[i] = sum;
  }
  vec res = gauss_jordan(A,b);
  printf("%.10f\n",res[S]);
}

int main(){
  int N,S,T;
  while(cin >> N >> S >> T, N){
    S--; T--;
    vi sign(N);
    vii d(N,vi(N)),road(N,vi(N));
    for(int i = 0 ; i < N ; i++){
      cin >> sign[i];
    }
    for(int i = 0 ; i < N ; i++){
      for(int j = 0 ; j < N ; j++){
        cin >> d[i][j];
        if(d[i][j] == 0){
          d[i][j] = INF;
        }
      }
      d[i][i] = 0;
    }
    road = d;
    for(int k = 0 ; k < N ; k++){
      road[k][k] = INF;
      for(int i = 0 ; i < N ; i++){
        for(int j = 0 ; j < N ; j++){
          d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
        }
      }
    }
    if(d[S][T] == INF){
      cout << "impossible" << endl;
    }else{
      solve(sign,road,d,S,T,N);
    }
  }
  return 0;
}

Measured memory_bytes: 1456
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
//#include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

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

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}


int main(void) {
    int A, B; cin >> A >> B;
    int ans = 0;
    int sum = 1;
    for (ans = 0; sum < B; ans++) {
        sum--;
        sum += A;
    }
    cout << ans << endl;
}


Measured memory_bytes: 888
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <stack>
using namespace std;
char c;
int n=3,ans;
int main(){
	while (n--){
		cin>>c;
		if (c=='1')ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x) cout<<#x<<" = "<<(x)<<endl;
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int h,w; cin >> h >> w;
  string s[h]; REP(i,h) { cin >> s[i]; }

  int dp[h+1][w+1];
  REP(i,h) REP(j,w) dp[i][j] = INF;

  dp[0][0] = (s[0][0] == '.') ? 0 : 1;
  REP(i,h) {
    REP(j,w) {
      dp[i+1][j] = min(dp[i+1][j], (s[i][j] == '.' &&  s[i+1][j] == '#') ? dp[i][j]+1 : dp[i][j]);
      dp[i][j+1] = min(dp[i][j+1], (s[i][j] == '.' &&  s[i][j+1] == '#') ? dp[i][j]+1 : dp[i][j]);
    }
  }
  COUT(dp[h-1][w-1]);
  return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);  
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	while(k--){
		if(b<c && b>a){
			c=c*2;
		}
		else if(b>=c){
			c=c*2;
		}
		else if(b<=a){
			b=b*2;
		}
	}
	if(a<b && b<c){
		cout<<"Yes"<<"\n";
	}
	else{
		cout<<"No"<<"\n";
	}
	return 0;
}

Measured memory_bytes: 3648
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long LL;
#define M(a,b) memset(a,b,sizeof(a))
#define pb push_back
const int maxn = 200000+5;
const LL mod = 1000000007;
LL f[maxn];
LL p[maxn];
LL qp(LL a,LL p)
{
    LL res=1;
    while(p)
    {
        if (p&1)
            res=res*a%mod;
        a=a*a%mod;
        p>>=1;
    }
    return res;
}
LL solve(int n,int m)
{
    return p[n-m]*p[m]%mod*f[n]%mod;
}
int main()
{
    f[0]=1;
    p[0]=1;
    for (int i=1;i<=200000;++i)
    {
        f[i]=f[i-1]*i%mod;
        p[i]=qp(f[i],mod-2);
    }
    int n,m,a,b;
    scanf("%d%d%d%d",&n,&m,&a,&b);
    LL ans=0;
    ans=solve(n+m-2,n-1);
    for (int i=0;i<b;++i)
    {
        ans=(ans-solve(n-a-1+i,n-a-1)*solve(m-1-i+a-1,a-1))%mod;
        ans=(ans+mod)%mod;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)

#define INF INT_MAX / 2 - 1
#define PI 2*acos(0.0)
#define ll long long

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

int main() {
	int n, w;
	cin >> n >> w;
	struct { int v, w; } item[100];
	FOR(i, 1, n+1)
		cin >> item[i].v >> item[i].w;
	int dp[101][10001] = {};
	FOR(i, 1, n+1)
	FOR(j, 1, w+1)
		if (j < item[i].w)
			dp[i][j] = dp[i-1][j];
		else
			dp[i][j] = max(dp[i-1][j], dp[i-1][j-item[i].w] + item[i].v);
	cout << dp[n][w] << endl;
	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class C>
struct MaxFlow {
    C flow;
    V<char> dual;
};

template <class C, class E>
struct MFExec {
    static constexpr C INF = numeric_limits<C>::max();
    C eps;
    VV<E>& g;
    int s, t;
    V<int> level, iter;

    C dfs(int v, C f) {
        if (v == t) return f;
        C res = 0;
        for (int& i = iter[v]; i < int(g[v].size()); i++) {
            E& e = g[v][i];
            if (e.cap <= eps || level[v] >= level[e.to]) continue;
            C d = dfs(e.to, min(f, e.cap));
            e.cap -= d;
            g[e.to][e.rev].cap += d;
            res += d;
            f -= d;
            if (f == 0) break;
        }
        return res;
    }

    MaxFlow<C> info;
    MFExec(VV<E>& _g, int _s, int _t, C _eps)
            : eps(_eps), g(_g), s(_s), t(_t) {
        int N = int(g.size());

        C& flow = (info.flow = 0);
        while (true) {
            queue<int> que;
            level = V<int>(N, -1);
            level[s] = 0;
            que.push(s);
            while (!que.empty()) {
                int v = que.front(); que.pop();
                for (E e: g[v]) {
                    if (e.cap <= eps || level[e.to] >= 0) continue;
                    level[e.to] = level[v] + 1;
                    que.push(e.to);
                }
            }
            if (level[t] == -1) break;
            iter = V<int>(N, 0);
            while (true) {
                C f = dfs(s, INF);
                if (!f) break;
                flow += f;
            }
        }
        for (int i = 0; i < N; i++) info.dual.push_back(level[i] == -1);
    }
};

template <class C, class E> MaxFlow<C> get_mf(VV<E>& g, int s, int t, C eps) {
    return MFExec<C, E>(g, s, t, eps).info;
}

struct E {
    int to, rev; ll cap;
};

int main() {
    int n, m;
    cin >> n >> m;
    string st;
    cin >> st;
    VV<E> g(2 + n);
    int sv = n, tv = sv + 1;
    auto add_edge = [&](int from, int to, ll cap) {
        g[from].push_back(E{to, int(g[to].size()), cap});
        g[to].push_back(E{from, int(g[from].size()) - 1, 0});
    };

    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        if (st[i] == 'L') {
            add_edge(sv, i, a);
        } else {
            add_edge(i, tv, a);
        }
    }

    for (int i = 0; i < m; i++) {
        int s, t; ll b;
        cin >> s >> t >> b; s--; t--;
        if (s > t) swap(s, t);
        add_edge(t, s, b);
    }

    auto mf = get_mf(g, sv, tv, 0LL);
    cout << mf.flow << endl;
    return 0;
}


Measured memory_bytes: 3288
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9;
const ll mod=998244353;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H,W,h,w;cin>>H>>W>>h>>w;
    vector<vector<ll> >g(H,vector<ll>(W));
    if(H%h==0){
        if(W%w==0){
            cout<<"No"<<endl;
        }else{
            cout<<"Yes"<<endl;
            rep(i,H){
                rep(j,W){
                    ll c;
                    if(j%w==0)c=inf-w;
                    else if(j%w==w-1)c=-inf;
                    else c=1;
                    cout<<c<<' ';
                }
                cout<<endl;
            }
        }
    }else{
        cout<<"Yes"<<endl;
        rep(i,H){
            rep(j,W){
                ll c;
                if(i%h==0)c=inf-h;
                else if(i%h==h-1)c=-inf;
                else c=1;
                cout<<c<<' ';
            }
            cout<<endl;
        }
    }
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n;
    cin >> n;
    vector<int> pos(n);
    rep(i, n) cin >> pos[i], pos[i]--;
    vector<int> a(n), b(n);
    rep(i, n) a[i] = i+1, b[i] = n-i;
    vector<int> adda(n, 0), addb(n, 0);
    rep(i, n) {
        adda[pos[i]] += i;
        addb[pos[i]] += i;
    }
    rep(i, n-1) {
        adda[i+1] = adda[i] + adda[i+1];
    }
    drep(i, n-1) {
        addb[i] = addb[i+1] + addb[i];
    }
    rep(i, n) cout << a[i]+adda[i] << " ";
    cout << endl;
    rep(i, n) cout << b[i]+addb[i] << " ";
    cout << endl;
}

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

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


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

int data[100];
int count=0;
void SelectionSort(int[],int);

int main(){

	int i,n;
	
	cin>>n;
	for(i=0; i<n; i++){
	cin>>data[i];
	}
	
	SelectionSort(data,n);

	for(i=0; i<n; i++){
		cout<<data[i];
		if(i==n-1)cout<<endl;
		else cout<<" ";
	}
	
	cout<<count<<endl;

return 0;
	
}

void SelectionSort(int data[],int n){

	int i,j,mini,suspend;
	
	for(i=0; i<n; i++){

		mini=i;

		for(j=i; j<n; j++){
			if(data[j]<data[mini]){
				mini=j;
			}
		}

		if(data[i]>data[mini]){
		suspend=data[i];
		data[i]=data[mini];
		data[mini]=suspend;
		count++;
		}
		}
	
	}

Measured memory_bytes: 1160
/**
 * AOJ #0106: Discount of Buckwheat (PCK 2005)
 */

#include <stdio.h>

/**
 * Return the best price for w grams of buckwheat.
 */
int price(int w)
{
  double p, min;
  int a, b, c, ad, bd, cd;
  /* a price without discount, which must be the upper bound. */
  min = (w / 200) * 380 + (w % 200 == 0 ? 0 : 550 - 380);

  for (a = 0; a * 200 <= w; a++) { /* the number of bags from A */
    for (b = 0; a * 200 + b * 300 <= w; b++) {
      c = w - a * 200 - b * 300;
      if (c % 500 != 0) continue;
      c /= 500;
      ad = a - (a % 5); /* the number of bags subject of discount */
      bd = b - (b % 4);
      cd = c - (c % 3);
      p = (380 * ad) * 0.8  + 380 * (a - ad)
        + (550 * bd) * 0.85 + 550 * (b - bd)
        + (850 * cd) * 0.88 + 850 * (c - cd);
      if (min > p) min = p;
    }
  }
  return (int)min;
}

int main()
{
  int w;
  for (;;) {
    scanf("%d", &w);
    if (w == 0) break;
    printf("%d\n", price(w));
  }
  return 0;
}

Measured memory_bytes: 600
def make_routes(ns,used, cur):
    if all(used[cur]):
        yield []
    else:
        for i in (d for d,s in zip(range(ns+1), used[cur]) if not s):
            used[cur][i] = used[i][cur] = True
            for ret in make_routes(ns,used,i):
                yield [[cur, i]] + ret
            used[cur][i] = used[i][cur] = False

while True:
    ns,nl = map(int, raw_input().split())
    if ns == 0 and nl == 0:
        break
    costs = [[0]*(ns+1) for _ in xrange(ns+1)]
    used = [[True]*(ns+1) for _ in xrange(ns+1)]
    for _ in xrange(nl):
        a, b, c = map(int, raw_input().split())
        costs[a][b] = costs[b][a] = c
        used[a][b] = used[b][a] = False
    ans = [0,[]]
    for i in xrange(1,ns): #not ns+1
        for route in make_routes(ns, used, i):
            cost = sum(costs[a][b] for a,b in route)
            if ans[0] < cost:
                ans[0] = cost
                ans[1] = route
    print ans[0]
    print "{} {}".format(str(ans[1][0][0])," ".join(str(a[1])for a in ans[1]))

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

#define fastio std::ios::sync_with_stdio(false);
#define ll long long
#define scann(n) scanf("%d",&n)
#define scand(n) scanf("%lf",&n)
#define scans(s) scanf("%s",&s)
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define full v.begin(),v.end()
#define debug cout<<"Bug! Vag! Bagh!"<<endl;
#define pi acos(-1)
#define mx 10010
#define inf 10e10

int main()
{
    ll n;
    cin>>n;
    set<ll>s;
    for(ll i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        s.insert(x);
    }
    if(s.size()==n)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    return 0;
}
///arBishal_2017331022


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

bool is_prime(int N){
    if(N<=1) return false;
    for (int i = 2; i*i <= N; i++)
    {
        if(N%i==0) return false;
    }
    return true;
}

int main(){
    using namespace std;
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    int Q; cin >> Q;
    vector<pair<int, int>> q(Q);
    int minl = 100001, maxr = 0;
    for (int i = 0; i < Q; i++){
        cin >> q[i].first >> q[i].second; 
        minl = min(minl, q[i].first);
        maxr = max(maxr, q[i].second);
    } 

    vector<long> sum;
    long cnt = 0;
    for (int i = minl; i <= maxr; i+=2)
    {
        if(is_prime(i) && is_prime((i+1)/2)) cnt++;
        sum.push_back(cnt);
    }
    //for(int i : sum) cout << i << " ";
    //cout << endl;
    for (int i = 0; i < Q; i++)
    {
        if(q[i].first-minl-1>=0)
            cout << sum[(q[i].second-minl)/2] - sum[(q[i].first-minl)/2-1] << "\n";
        else 
            cout << sum[(q[i].second-minl)/2] << "\n";

    }
}

Measured memory_bytes: 1912
import java.util.*;

// ARC 80-D
// http://arc080.contest.atcoder.jp/tasks/arc080_b

public class Main {
	
	public static void main (String[] args) throws InterruptedException {
		Scanner in = new Scanner(System.in);
		
		int H = in.nextInt();
		int W = in.nextInt();
		int N = in.nextInt();
		
		int[] color = new int[N];
		for (int i = 0; i < N; i++) {
			color[i] = in.nextInt();
		}
		
		int row = 0;
		int col = 0;
		int colorIndex = 0;
		boolean toRight = true;
		
		while (row < H) {
			String s = "";
			if (toRight) {
				while (col < W) {
					if (color[colorIndex] == 0) {
						colorIndex++;
					}
					s += (colorIndex + 1) + " ";
					color[colorIndex]--;
					col++;
				}
				col--;
				toRight = false;
			} else {
				while (0 <= col) {
					if (color[colorIndex] == 0) {
						colorIndex++;
					}
					s = (colorIndex + 1) + " " + s;
					color[colorIndex]--;
					col--;
				}
				col++;
				toRight = true;
			}
			row++;
			System.out.println(s);
		}
	}
}


Measured memory_bytes: 41476
#!/usr/bin/env python3


INVALID = (-1, -1, -1)


def solve(n, y):
    y //= 1000
    for num_10 in range((y - n) // 9 + 1):
        z = y - n - 9 * num_10
        if z < 0 or z % 4 != 0:
            continue
        num_5 = z // 4
        num_1 = n - num_5 - num_10
        if num_1 >= 0 and num_5 >= 0 and num_10 >= 0:
            return (num_10, num_5, num_1)
    return INVALID


def main():
    n, y = (int(x) for x in input().split())
    print(*solve(n, y))


if __name__ == '__main__':
    main()


Measured memory_bytes: 39664
N = int(input())
A = [int(_) for _ in input().split()]

class BIT:
    # index 1~
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

def sub_problem(x):
    S = [0] * (N + 1)
    for i in range(N):
        S[i + 1] = S[i] + 1 if A[i] >= x else S[i] - 1

    geta = abs(min(S)) + 1
    for i in range(N + 1):
        S[i] += geta

    forward = 0
    bit = BIT(max(S))
    for s in S:
        forward += bit.sum(s)
        bit.add(s, 1)

    return forward >= M // 2 # TEST　これだと通らないはず

M = N * (N + 1) // 2  # (N+1)C2
sorted_A = sorted(A)

inf = 0
sup = N
while sup - inf > 1:
    mid = (sup + inf) // 2
    x = sorted_A[mid]

    if sub_problem(x):
        inf = mid
    else:
        sup = mid

print(sorted_A[inf])


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

int main(){
  string S,T;
  cin >> S >> T;
  int count=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)!=T.at(i)){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3892
import sys
def 解():
    input = sys.stdin.readline
    iN = int(input())
    #aF = [0]*iN
    #aP = [0]*iN
    #for i in range(iN):
    #   aF[i] = int(input().rstrip().replace(' ',''),2)
    aF = list(map(lambda x:int(input().rstrip().replace(' ',''),2),range(iN)))
    #for i in range(iN):
    #   aP[i] = [int(_) for  _ in input().split()]
    aP = list(map(lambda x:[int(_) for _ in input().split()],range(iN)))
    iD = 2**10
    #iMax = -1*(10**10)
    #for i in range(1,iD):
        #iM = 0
    #   iM = sum(map(lambda x:aP[x][bin(aF[x] & i).count("1")],range(iN)))
        #for j in range(iN):
        #   iM += aP[j][bin(aF[j] & i).count("1")]
    #   if iMax < iM:
    #       iMax = iM
    #こんなふうにも書けるのか。うーむ呪文っぽいわりにそんなに速くならなそう。
    print(max(sum( map(lambda x:aP[x][bin(aF[x] & i).count("1")],range(iN)))for i in range(1,iD)))
    #print(iMax)
解()


Measured memory_bytes: 3064
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::string;

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

    string result = "No";
    for (int i = 1; i < 10; i++)
    {
        for (int j = 1; j < 10; j++)
        {
            if (i * j == N)
            {
                result = "Yes";
            }
        }
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define SZ(X) ((int64_t)((X).size()))
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define intmax (std::numeric_limits<int64_t>::max() / 4)
#define doublemax (std::numeric_limits<double>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);





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

	int N, M;
	cin >> N >> M;
	vector<int>t(N);
	rep(i, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		t[a]++;
		t[b]++;
	}

	rep(i, N)if (t[i] % 2) {
		cout << "NO" << endl;
		return 0;
	}
	cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll k,t;
  cin>>k>>t;
  ll maxi=-1;
  vl a(t);
  rep(i,t){
    cin>>a[i];
    chmax(maxi,a[i]);
  }
  ll b=k-maxi;
  cout<<(b+1>=maxi?0:maxi-b-1)<<endl;
}


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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define MOD pow(10,9)+7
#define LLINF pow(2,61)-1
#define INF pow(2,29)-1


int main() {
  int A, B; cin >> A >> B;
  if (A>=10||B>=10) cout << "-1" << endl;
  else cout << A*B << endl;
  return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int N;
  cin>>N;
  vector<ll>A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  int r=0;
  ll X=0,S=0;
  ll ans=0;
  for(int l=0;l<N;l++){
    while((X^A[r])==S+A[r]&&r<N){
      X=X^A[r];
      S=S+A[r];
      r++;
    }
    ans+=r-l;
    if(l==r)r++;
    else{
      X=X^A[l];
      S=S-A[l];
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int x,a,b;
int main()
{
	scanf("%d",&x);
	if(x==1)
	{
		printf("Hello World");
		return 0;
	}
	else
	{
		scanf("%d %d",&a,&b);
		printf("%d",a+b);
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define x first
#define y second
#define mp make_pair
#define pb push_back
template <typename TYPE> inline void chkmax(TYPE &x,TYPE y){x<y?x=y:0;}
template <typename TYPE> inline void chkmin(TYPE &x,TYPE y){y<x?x=y:0;}
template <typename TYPE> void readint(TYPE &x)
{
    x=0;int f=1;char c;
    for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
    for(;isdigit(c);c=getchar())x=x*10+c-'0';
    x*=f;
}
const ll LIM=1000000000000000000ll;

ll a,b,c;
ll k;

int main()
{
	#ifndef ONLINE_JUDGE
//	freopen("code.in","r",stdin);
//	freopen("code.out","w",stdout);
	#endif
	readint(a),readint(b),readint(c),readint(k);
	if(k&1)printf("%lld\n",b-a);
	else printf("%lld\n",a-b);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <complex>
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define EACH(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
using namespace std;

struct Era {
  string name;
  int base,len;
};

int main()
{

  int n,q;

  while(cin>>n>>q, n|q) {
    string s;
    int base,wes;
    vector<Era> v;
    REP(i,n) {
      cin>>s>>base>>wes;
      Era e;
      e.name = s;
      e.base = base;
      e.len = wes;
      v.push_back(e);
    }

    int query;
    REP(i,q) {
      cin>>query;
      for(int j=0; j<v.size(); ++j) {
        if(v[j].len-v[j].base+1 <= query && v[j].len >= query) {
          cout<<v[j].name<<" "<<query-(v[j].len-v[j].base)<<endl;
          goto NEXT;
        }
      }
      cout<<"Unknown"<<endl;
    NEXT:;
    }
  }

}

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

typedef long long LL;
const int N = 2e5+7;

pair<int, int> pr[N];
LL x[N], h[N];
int rr[N];

LL add[N];

int main() {
    int n, d, a;
    cin>>n>>d>>a;

    for (int i=1; i<=n; i++) {
        cin>>pr[i].first>>pr[i].second;
    }

    sort(pr+1, pr+n+1);
    for (int i=1; i<=n; i++) {
        x[i] = pr[i].first;
        h[i] = pr[i].second;
    }

    int r = 0;
    for (int l=1; l<=n; l++) {
        while (r+1 <= n && x[r+1]-x[l] <= 2*d)   r++;
        rr[l] = r;
    }

    LL sub = 0, ans = 0;
    for (int i=1; i<=n; i++) {
        h[i] -= sub;
        if (h[i] > 0) {
            LL need = (h[i] + a-1)/a;
            ans += need;
            LL total = need * a;
            h[i] -= total;
            sub += total;
            add[rr[i]] += total;
        }

        assert(h[i] <= 0);
        sub -= add[i];
    }
    cout<<ans<<endl;
}


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

using namespace std;

int main() {
  int n, i, x;
  cin >> n;
  vector<int> h, c;
  h.push_back(0);
  c.push_back(0);
  for (i = 1; i<=n; i++) {
    cin >> x;
    h.push_back(x);
    c.push_back(0);
  }
  if (n<=3) {
    cout << abs(h[1]-h[n]) << endl;
    return 0;
  }
  c[1] = 0;
  c[2] = abs(h[1]-h[2]);
  c[3] = abs(h[1]-h[3]);
  for (i = 4; i<=n; i++) {
    c[i] = min(abs(h[i]-h[i-1])+c[i-1],abs(h[i]-h[i-2])+c[i-2]);
  }
  cout << c[n] << endl;
  return 0;
}


Measured memory_bytes: 1276
#include<stdio.h>
int main()
{
  int i,j,k,l,m,n,num,p;
  j=0;k=num=p=0;
  scanf("%d",&j);
  scanf("%d",&k);
  scanf("%d",&l);
  m=j%k;
  n=j*2;
  while (n%k!=m)
  {
    n=n+j;
    num++;
  }
  for (i=0;i<num+1;i++)
    if (i*j%k==l)p=1;
  if (p==1)printf("YES");else printf("NO");
  return 0;
}


Measured memory_bytes: 128