akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    //ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    int H,W,A,B;
    cin >> H >> W >> A >> B;
    rep(i,H){
        rep(j,W){
            if(i<B && j<A)cout << 1;
            else if(i>=B && j>=A)cout << 1;
            else cout << 0;
        }
        cout << endl;
    }

    


}

/*

にんじゃりばんばん

 */



Measured memory_bytes: 1280
#define Bobyama
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100;
int N;
int W[MAX_N];

int main() {
  std::ios::sync_with_stdio(false);std::cin.tie(0);
  
  cin >> N;
  rep(i, N) cin >> W[i];

  int ans = INFINT;
  for (int t = 0; t < N-1; ++t) {
    int w1 = 0, w2 = 0;
    for (int j = 0; j <= t; ++j) {
      w1 += W[j];
    }
    for (int j = t+1; j < N; ++j) {
      w2 += W[j];
    }
    ans = min(ans, abs(w1-w2));
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
    string s;
    cin>>s;
    int cou=0;
    while (s.size()>1) {
        if(s[0]=='x'&&s.back()!='x'){
            s.erase(s.begin());
            cou++;
        }
        else if (s[0]!='x'&&s.back()=='x'){
            s.pop_back();
            cou++;
        }
        else if (s[0]==s.back()){
            s.erase(s.begin());
            s.pop_back();
        }
        else{
            cout<<"-1"<<endl;
            return 0;
        }
    }
    cout<<cou<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
#include<algorithm>
#include<string>
#define REP(i,a) for(int  i=0;i<a;i++)
int A[101][101];
int B[101][101];
int main(){
	int a,b=0,c=0,d,n,m;	
	cin>>n>>m;
	while(n!=0||m!=0){
	REP(i,m){
		REP(j,m){
			A[i][j]=10002;
			B[i][j]=10002;
		}
		A[i][i]=0;
		B[i][i]=0;
	}
	REP(i,n){
	cin>>a>>b>>c>>d;
	A[a-1][b-1]=c;
	B[a-1][b-1]=d;	
	A[b-1][a-1]=c;
	B[b-1][a-1]=d;
	}
	REP(k,m){
		REP(i,m){
		if(i==k) continue;
	 		REP(j,m){
		if(i==j)continue;
		A[i][j]=min(A[i][j],A[i][k]+A[k][j]);
		B[i][j]=min(B[i][j],B[i][k]+B[k][j]);
			}
		}	
	}
	cin>>n;
	REP(i,n){
	cin>>a>>b>>c;
	if(c==0) cout<<A[a-1][b-1]<<endl;
	else cout<<B[a-1][b-1]<<endl;
	}
	cin>>n>>m;
	}
	return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n,k;
    cin>>n>>k;
    ll a[n];
    rep(0,i,n){
        cin>>a[i];
    }
    rep(0,i,n-k){
        if(a[i]<a[i+k])cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}


Measured memory_bytes: 5192
def main():
  n, k = map(int,input().split())
  s = input()

  from itertools import groupby

  tmp = []
  num = []
  for ke, v in groupby(s):
    num.append(ke)
    tmp.append(len(list(v)))
  
  num += [0]
  tmp += [0]

  nt = len(tmp)
  wa = [0] * (nt+1)
  for i in range(nt):
    wa[i+1] = wa[i] + tmp[i]

  ans = 0
  for i in range(len(wa)):
    x = k*2
    if num[i] == "1":
      x += 1
    try:
      ans = max(ans, wa[i+x] - wa[i])
    except:
      break
  if not ans:
    ans = len(s)
  print(ans)

main()

Measured memory_bytes: 8772
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <ratio>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;
template<class T> using v = vector<T>;
template<class T, class U> using p = pair<T, U>;

#define REP(i, n) for(int i = 0; i < n; ++i)
#define REP1(i, n) for(int i = 1; i <= n; ++i)

template<class T> T read() { T x{}; cin >> x; return x; }
template<class T> v<T> read(int N){ v<T> x(N); REP(i, N) cin >> x[i]; return x; }

template<class T>
void write(const T &x){ cout << x << endl; }
void write(double x){ printf("%.15f\n", x); }

const ull MOD = 1000'000'007;

ll N, D, A;
const ll NMAX = 2 * 1e5 + 10;
struct E {
    ll x;
    ll h;
};
E e[NMAX] = {};


int main(){
    cin >> N >> D >> A;
    REP(i, N){ cin >> e[i].x >> e[i].h; }
    
    sort(e, e + N, [](auto& l, auto& r){ return l.x < r.x; });
    
    ll ans = 0;
    ll a = 0;
    queue<p<ll, ll>> q;
    for(ll n = 0; n < N; ++n){
        const auto& en = e[n];
        auto x = en.x;
        auto h = en.h;
        while(!q.empty() && q.front().first + 2 * D < x){
            a -= q.front().second * A;
            q.pop();
        }
        if(h <= a){ continue; }
        ll num_bom = (h - a + A - 1) / A;
        ans += num_bom;
        q.push({x, num_bom});
        a += num_bom * A;
    }
    
    cout << ans << endl;
    
}



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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll A, B, K;
    cin >> A >> B >> K;
    int n = 0;
    vector<int> v;
    FOR(i, std::min(A, B) + 1, 1)
    {
        if (A % i == 0 && B % i == 0)
            v.push_back(i);
    }

    cout << v[v.size() - K] << endl;
    return 0;
}

Measured memory_bytes: 256
N,H,*abs=$<.read.split.map(&:to_i)
abs=abs.each_slice(2)

amax=abs.map{|a,b|a}.max
bs=abs.map{|a,b|b}.select{|b|amax < b}.sort_by{|b|-b}

h = H
ret = 0
bs.each do |b|
    h -= b
    ret += 1
    if h <= 0
        puts ret
        exit 0
    end
end

ret+=(h/amax.to_f).ceil
puts ret


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


int main(){
    int n,m,X,Y;
    cin >> n >> m >> X >> Y;
    vector<int> x(n+1);
    vector<int> y(m+1);
    for(int i=0;i<n;i++){
        cin >> x.at(i);
    }
    x.at(n)=X;
    for(int i=0;i<m;i++){
        cin >> y.at(i);
    }
    y.at(m)=Y;
    sort(x.rbegin(),x.rend());
    sort(y.begin(),y.end());
    if(x.at(0)<y.at(0)){
        cout << "No War" <<endl;
    }else{
        cout << "War" <<endl;
    }
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] n = new int[3];
		for(int i = 0; i < 3; i++) {
			n[i] = sc.nextInt();
		}
		Arrays.sort(n);
		n[2] -= n[1];
		n[1] -= n[0];
		System.out.println(n[1]+n[2]);
	}
}

Measured memory_bytes: 21716
use std::io::*;
use std::str::FromStr;

fn main(){
    let n: usize = read();
    let mut a: Vec<u64> = (0..n).map(|_| read::<u64>()).collect();
    let mut ans: u64 = 0;
    for i in 0..n {
        ans += a[i] / 2;
        a[i] %= 2;
        if i != n-1 && a[i] == 1 && a[i+1] > 0 {
            ans += 1;
            a[i+1] -= 1;
        }
    }
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

Measured memory_bytes: 4352
import sys
n, m = map(int, input().split())
for i in range(0, n + 1):
    val = m - 1000 * n - 4000 * i
    if val < 0:
        break
    elif val % 9000 == 0:
        z = val // 9000
        if n - i - z < 0:
            continue
        print(z, i, n - i - z)
        sys.exit()
print(-1, -1, -1)

Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG//実行時、何も出なかったらこれを使う
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<numeric>
#include<climits>
#include<limits>//
#include <stdio.h>//

using namespace std;

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

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

int dy[] = {1,0}; //次に行くところ
int dx[] = {0,1}; //上に同じ


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h,w,k,cnt2 = 0;
  cin >> h >> w >> k;
  vector<string> c(h);
  vector<vector<int>> a(h,vector<int>(w,1)),new_a;
  for (int i = 0; i < h; i++){
    cin >> c[i];
  }

  for (int bit = 0; bit < 1 << h; bit++){
    a.assign(h,vector<int>(w,1));
    for (int i = 0; i < h; i++){
      if (bit & 1 << i){
        for (int l = 0; l < w; l++){
          a[i][l] = 0;
        }
      }
    }
    new_a = a;
    for (int bit2 = 0; bit2 < 1 << w; bit2++){
      for (int j = 0; j < w; j++){
        if (bit2 & 1 << j){
          for (int l = 0; l < h; l++){
            new_a[l][j] = 0;        
          }
        }    
      }
      int cnt = 0;
      for (int l = 0; l < h; l++){
        for (int m = 0; m < w; m++){
          if (new_a[l][m] != 0 && c[l][m] == '#'){
           cnt++;
          }
        }
      }
      if (cnt == k){
        cnt2++;
      }
      new_a = a;
    }
  }
  cout << cnt2 << '\n';
  //bit全探索で、行を選んだ後、列を選ぶ。'_'
  return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iomanip>
using namespace std;

int N;
string S;
int mod = 1e9 + 7;

int main() {
    cin >> N;
    double ans = 0;
    for (int i = 0; i < N; i++) {
        double x;
        string s;
        cin >> x >> s;
        if (s == "BTC") {
            x *= 380000;
        }
        ans += x;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int main(){
	int a[10];
	char b[10];
	while(cin >> b){
		for(int i=0;i<10;i++){
			b[i]-='0';
			for(int j=0;j<10;j++){
				if(b[i]==j){
					a[i]=j;
				}
			}
		}
		
		a[0]=a[0]+a[1]*9+a[2]*6+a[3]*4+a[4]*6+a[5]*6+a[6]*4+a[7]*6+a[8]*9+a[9];
		a[1]=a[0]/10;
		a[0]=a[0]-a[1]*10;
		

		cout << a[0] <<"\n";
	}
		
return 0;
}

Measured memory_bytes: 1140
package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  w, h := getI(), getI()
  g := make([][]byte, h)
  for r := range g {
    g[r] = make([]byte, w)
  }
  for c := 0; c < w; c++ {
    s := strings.TrimSpace(getS())
    for r := range g {
      g[r][c] = s[r]
    }
  }
  /*
  for r := range g {
    fmt.Printf("%s\n", g[r])
  }
  fmt.Printf("\n")
  */
  friction := make([][]int, w + 1)
  cost := make([][]int, w + 1)
  for r := range friction {
    friction[r] = make([]int, w + 1)
    cost[r] = make([]int, w + 1)
  }

  result := 0
  for rb := 1; rb < h; rb++ {
    ra := rb - 1
    a, b := g[ra], g[rb]
    for d := 0; d < w; d++ {
      x, y := 0, 0
      for c := d; c < w; c++ {
        if a[c] == b[c - d] {
          x++
        }
        if a[c - d] == b[c] {
          y++
        }
        friction[1 + c][1 + c - d] = x
        friction[1 + c - d][1 + c] = y
      }
    }
    /*
    for ai := w; ai >= 0; ai-- {
      for bi := w; bi >= 0; bi-- {
        fmt.Printf("%d ", friction[ai][bi])
      }
      fmt.Printf("\n")
    }
    fmt.Printf("\n")
    */
    cost[w][w] = friction[w][w]
    for i := w - 1; i >= 0; i-- {
      cost[w][i] = cost[w][i + 1] + friction[w][i]
      cost[i][w] = cost[i + 1][w] + friction[i][w]
    }
    for ai := w - 1; ai >= 0; ai-- {
      for bi := w - 1; bi >= 0; bi-- {
        cost[ai][bi] = friction[ai][bi]
        x := cost[ai + 1][bi]
        y := cost[ai][bi + 1]
        if x <= y {
          cost[ai][bi] += x
        } else {
          cost[ai][bi] += y
        }
      }
    }
    /*
    for ai := w; ai >= 0; ai-- {
      for bi := w; bi >= 0; bi-- {
        fmt.Printf("%d ", cost[ai][bi])
      }
      fmt.Printf("\n")
    }
    fmt.Printf("\n")
    */
    result += cost[0][0]
  }

  writer.WriteString(fmt.Sprintf("%d\n", result))
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int x[1234567];

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    sort(ALL(a));
    rep(i,n){
        if(i-2>=0 && a[i] == a[i-2])continue;
        for(int j=a[i];j<=1e6;j+=a[i]){
            x[j]++;
        }
    }
    int ans = 0;
    rep(i,n){
        if(x[a[i]]==1)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 7948
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            long xx = sc.nextLong();
            long cur = 5;
            long sum = 0;
            while (cur <= xx) {
                sum += (xx / cur) / 2;
                cur *= 5;
            }
            pw.println(xx % 2 == 0 ? sum : 0);
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<int>a(n),b(n),x;
    ll sum=0;
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    int cnt=0;
    rep(i,n){
        if(a[i]-b[i]<0)sum+=b[i]-a[i],cnt++;
        else x.push_back(a[i]-b[i]);
    }
    sort(x.begin(),x.end());
    while(sum>0&&!x.empty()){
        sum-=x.back();
        x.pop_back();
        cnt++;
    }
    if(sum>0)cout<<-1<<endl;
    else cout<<cnt<<endl;
}

Measured memory_bytes: 1660
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    if (a > b) swap(a, b);
    if (a > c) swap(a, c);
    if (b > c) swap(b, c);

    printf("%d %d %d\n", a, b, c);

    return 0;
}


Measured memory_bytes: 3152
/**
 * 標準入力マクロ by https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
 */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        a: u32,
        b: u32,
    }
    println!("{}", if a * b % 2 == 0 { "Even" } else { "Odd" });
}

Measured memory_bytes: 4352
/***********************
*  Author: xuziyuan    * 
***********************/
 
#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))
 
using namespace std;
 
const LL MOD=1e9+7;
 
LL n,a[200010],b[200010],pw[40],num[40],ans=0,tmp,pos1,pos2;
vector <LL> v;
 
int main()
{
	pw[0]=1;
	repn(i,30) pw[i]=pw[i-1]*2;
	cin>>n;
	rep(i,n) scanf("%I64d",&a[i]);
	rep(i,n) scanf("%I64d",&b[i]);
	rep(i,29)
	{
		v.clear();
		rep(j,n) v.pb(b[j]%pw[i+1]);
		sort(v.begin(),v.end());
		rep(j,n)
		{
			//cout<<i<<' '<<j<<endl;
			tmp=a[j]%pw[i+1];
			pos1=lower_bound(v.begin(),v.end(),pw[i]-tmp)-v.begin();
			pos2=upper_bound(v.begin(),v.end(),pw[i+1]-tmp-1)-v.begin();
			num[i]+=pos2-pos1;
			pos1=lower_bound(v.begin(),v.end(),pw[i]*3-tmp)-v.begin();
			num[i]+=v.size()-pos1;
			//cout<<i<<' '<<j<<endl;
		}
	}
	rep(i,30) ans+=num[i]%2*pw[i];
	cout<<ans<<endl;
	rt0;
}

Measured memory_bytes: 5492
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  string S;
  cin >>S;
  const int N = 13;
  vector<ll> dp(N);
  dp[0] = 1;
  
  ll mod = pow(10,9)+7;
  int mul = 1;
  for(int i=S.size()-1;i>=0;i--){
    
    vector<ll> nextDP(N);
    
    char c = S[i];
    if(c == '?'){
      rep(k,10){
        rep(j,N){
          nextDP[(k*mul + j)%N] += dp[j];
          nextDP[(k*mul + j)%N] %= mod ;
        }
      }
    }else{
      int k = (int)(S[i] - '0');
        rep(j,N){
          nextDP[(k*mul + j)%N] += dp[j];
          nextDP[(k*mul + j)%N] %= mod ;
        }
    }
    
    mul *= 10;
    mul %= N;
    dp = nextDP;
  }
  cout << dp[5] << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <math.h>
#include <list>
#include <stack>
#include <set>
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <queue>
#include <functional>
#include <map>
#include <cstdlib>
#include <typeinfo>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int main() {
	string s;
	cin >> s;
	ll n = s.size(), ans = n;
	for (ll i = 0; i < n - 1; i++)if (s[i] != s[i + 1]) ans = min(ans, max(i + 1, n - i - 1));
	cout << ans << endl;
	return 0;
}


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

string rev( string s );
int calcMultiple( string a, string b );

int main()
{
    int n;
    string m;

    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> m;

        bool a[1000001] = {};
        int cnt = 0;
        while( m.size() > 1 )
        {
            int max = 0;
            for( int j = 1; j < m.size(); j++ )
            {
                int mul = calcMultiple( m.substr( 0, j ), m.substr( j, m.size() ) );
                if( mul > max )
                    max = mul;
            }

            if( a[max] )
            {
                cnt = -1;
                break;
            }
            a[max] = true;

            string res = "";
            while( max != 0 )
            {
                res += ( max % 10 + '0' );
                max /= 10;
            }

            m = rev( res );
            cnt++;

        }
        cout << cnt << endl;
    }

    return 0;
}

string rev( string s )
{
    string res = "";
    for( int i = s.size() - 1; i >= 0; i-- )
        res += s[i];
    return res;
}

int calcMultiple( string a, string b )
{
    int x = 0, y = 0, d = 1;
    for( int i = a.size() - 1; i >= 0; i-- )
    {
        x += ( a[i] - '0' ) * d;
        d *= 10;
    }

    d = 1;
    for( int i = b.size() - 1; i >= 0; i-- )
    {
        y += ( b[i] - '0' ) * d;
        d *= 10;
    }
    return x * y;
}



Measured memory_bytes: 4180
n,m = map(int,input().split())
g = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)
from collections import deque
d = deque([[0,0]]) # 左は今考えてる部屋、右は前の部屋
ans = [-1 for i in range(n)]
kak = [-100 for i in range(n)]
while d:
    u,v = d.popleft()
    if ans[u] == -1:
        ans[u] = v
    for j in g[u]:
        if ans[j] == -1 and kak[j] == -100:
            kak[j] = 0
            d.append([j,u])
        else:
            continue
print('Yes')
for i in range(1,n):
    print(ans[i]+1)

Measured memory_bytes: 104428
def inpl(): return [int(i) for i in input().split()]
mod = 10**9 +7
n = int(input())

fac = [1 for _ in range(n+1)]
for i in range(n):
    fac[i+1] = (i+1)*fac[i]%mod

inv = [1 for _ in range(n+1)]
for i in range(2,n):
    inv[i] = (-(mod//i) * inv[mod%i]) %mod    

facinv = [1 for _ in range(n+1)]
for i in range(n):
    facinv[i+1] = inv[i+1]*facinv[i]%mod

def comb(a, b):
    if a < b or b < 0:
        return 0
    return fac[a]*facinv[b]*facinv[a-b]
    
a = inpl()
x = sum(a) - n*(n+1)//2
Y = [i for i, v in enumerate(a) if v == x]
y = n-Y[1]+Y[0]

for k in range(1,n+2):
    ans = (comb(n-1, k) + 2*comb(n-1, k-1) + comb(n-1, k-2) - comb(y, k-1))%mod
    print(ans)

Measured memory_bytes: 25776
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll MOD = 1e9 + 7;
ll *fact, *fact_inv;

ll Mod(ll x) {
    if (x < 0)
        return (MOD - x % MOD);
    else
        return x % MOD;
}

ll power(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1) res = Mod(res * a);
        a = Mod(a * a);
        b >>= 1;
    }
    return res;
}

ll inverse(ll x) { return power(x, MOD - 2); }

ll Comb(int N, int k) {
    if (k < 0 || N < k) {
        return 0;
    }
    return Mod(fact[N] * Mod(fact_inv[N - k] * fact_inv[k]));
}

int main() {
    int N, K;
    cin >> N >> K;
    fact = (ll *)malloc(sizeof(ll) * (N + 10));
    fact_inv = (ll *)malloc(sizeof(ll) * (N + 10));
    fact[0] = 1;
    fact_inv[0] = 1;
    for (int i = 1; i < N + 10; i++) {
        fact[i] = Mod(i * fact[i - 1]);
        fact_inv[i] = inverse(fact[i]);
    }

    ll ans;
    for (int i = 1; i <= K; i++) {
        if (N - K < i - 1) {
            cout << 0 << endl;
        } else {
            ans = Mod(Comb(N - K + 1, i) * Comb(K - 1, K - i));
            // cout << "red " << Comb(N - K + 1, i) << endl;
            // cout << "blue " << Comb(K - 1, K - i) << endl;
            cout << ans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner number = new Scanner(System.in);
		int w = number.nextInt();
		int h = number.nextInt();
		int x = number.nextInt();
		int y = number.nextInt();
		int r = number.nextInt();
		boolean result = true;
		if(w < x + r || 0 > x - r) result = false;
		if(h < y + r || 0 > y - r) result = false;
		if(result == true) System.out.println("Yes");
		else System.out.println("No");
	}
}


Measured memory_bytes: 26356
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
 ll a,b,c;
 string s;
 cin>>s;
 for(int i=0;i<3;i++)cout<<s[i];
 cout<<endl;
    return 0;
}


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

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

  string a = "AKIHABARA";
  int p[] = {0, 4, 6, 8};

  for (int i = 0; i < (1 << 4); ++i) {
    string t = a;
    for (int j = 3; j >= 0; --j) {
      if (i & (1 << j))
        t.erase(p[j], 1);
    }
    if (s == t) {
      puts("YES");
      return 0;
    }
  }
  puts("NO");
}

Measured memory_bytes: 256
import math
def py():
    print("Yes")
def pn():
    print("No")
def iin():
    x = int(input())
    return x

neko = 0
nya = 0
nuko = 0
h,w = map(int,input().split())
neko = h%2
nya = w%2
nuko = h * w /2
if neko + nya == 2:
    nuko = nuko + 1
if (h == 1)or(w == 1):
    nuko = 1
print(int(nuko))

Measured memory_bytes: 3064
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

ans = 0
t = 100
p = 100
for i in range(n):
    t = a[i]
    ans += b[t-1]
    if t == p+1:
        ans += c[p-1]
    p = t
print(ans)

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

using pli = std::pair<long long, int>;

int main()
{
	int N, x;
	scanf("%d%d", &N, &x);
	std::vector<int> d(N), c(N);
	for (int i{}; i < N; i++)
		scanf("%d%d", &d[i], &c[i]);

	int max_place{x + 2 * *std::max_element(d.begin(), d.end())};
	std::vector<long long> dist(max_place + 1, 1LL << 60);
	std::priority_queue<pli, std::vector<pli>, std::greater<pli>> dij;
	dist[0] = 0;
	dij.push({0, 0});
	while (!dij.empty())
	{
		auto now{dij.top()};
		dij.pop();
		if (now.first > dist[now.second]) continue;
		if (now.second == x) break;
		for (int i{}; i < N; i++)
		{
			int next[2]{now.second - d[i], now.second + d[i]};
			for (int j{}; j < 2; j++)
			{
				if (next[j] < 0 || max_place < next[j]) continue;
				if (dist[next[j]] <= now.first + c[i]) continue;
				dist[next[j]] = now.first + c[i];
				dij.push({dist[next[j]], next[j]});
			}
		}
	}
	if (dist[x] == (1LL << 60))
		puts("-1");
	else
		printf("%lld\n", dist[x]);

	return 0;
}



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

int tmp, mod;

int eucrid(int a, int b){
  mod = a % b;
  if (mod != 0){
    a = b;
    b = mod;
    return eucrid(a, b);
  }else return b;
}

int main(){
  int a, b, gcd;
  scanf("%d %d", &a, &b);
  if (a < b){
    tmp = a;
    a = b;
    b = tmp;
  }
  gcd = eucrid(a, b);
  cout << gcd <<endl;
}



Measured memory_bytes: 3192
#include<bits/stdc++.h>
#include<boost/algorithm/string/replace.hpp>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::algorithm;
using namespace boost::multiprecision;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const int INF = 1e9;
const int MOD = 1e9+7;

//C++17
template<typename Type>
Type GCD(Type a,Type b){ return b ? GCD(b,a%b) : a ;}
template<typename Type>
Type LCM(Type a,Type b){ return a*b / GCD(a,b) ;}

template<typename Type>//文字列の置換/Boost:replace_all()
Type replace_str(Type str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main() {
    int n;cin >> n;
    vector<ll> xv(n+1);
    rep(i,n+1)cin >> xv[i];
    sort(ALL(xv));
    ll ans = xv[1] - xv[0];
    for(int i=1;i<n;i++){
        ll tmp = xv[i+1] - xv[i]; 
        ans = GCD(ans,tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>

#define INF 100000000

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << ((b / a >= c) ? c : (b / a)) << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);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;}
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
/*----------------------------------------------------------------------------------*/

const ll mod = 1e9+7;

ll get_mod (ll a) {
    if (a >= 0) a %= mod;
    else {
        while (a < 0) {
            a += mod;
        }
    }
    return a;
}

int main() {
    int n, m; cin >> n >> m;
    vector<ll> x(n), y(m);
    rep(i,n) cin >> x[i];
    rep(i,m) cin >> y[i];
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    ll sumx = 0, sumy = 0;
    rep(i,n) {
        sumx += x[i]*i%mod;
        sumx = get_mod(sumx);

        sumx -= x[i]*(n-i-1);
        sumx = get_mod(sumx);
    }

    rep(i,m) {
        sumy += y[i]*i%mod;
        sumy = get_mod(sumy);

        sumy -= y[i]*(m-i-1);
        sumy = get_mod(sumy);
    }

    cout << sumx*sumy%mod << endl;
    return 0;
}


Measured memory_bytes: 1792
from collections import deque
s = deque(input())

n = int(input())
l = []

base = 1

for i in range(n):
  l=list(input().split())
  if l[0] == '1':
    base = base *-1
  else:
    if l[1] =='1' and base == 1 :
      s.appendleft(l[2])
    elif l[1] =='2' and base == 1 :
      s.append(l[2])
    elif l[1] =='1' and base == -1 :
      s.append(l[2])
    elif l[1] =='2' and base == -1 :
      s.appendleft(l[2])

if base ==-1:
  s=''.join(list(reversed(s)))
      
print("".join(s))  

Measured memory_bytes: 8552
r = "abcdefghijklmnopqrstuvwxyz"
while 1:
	n = input()
	if n == 0: break
	s = list(raw_input())
	ab = [map(int,raw_input().split()) for i in range(n)]
	for a,b in ab[::-1]:
		d = abs(a - b)
		s[a-1],s[b-1] = r[(r.index(s[b-1]) + d)%26],r[(r.index(s[a-1]) + d)%26]
	print "".join(s)

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

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

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

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

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

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

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

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

fn main() {
    input! {
        n: i32,
        k: i32,
        x_list: [i32; n]
    }
    let ans: i32 =
        x_list
            .into_iter()
            .map(|x| {
                if x < (x - k).abs() {
                    x * 2
                } else {
                    let a = (x - k).abs();
                    a * 2
                }
            })
            .sum();
    println!("{}", ans);
}


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

int main(){
    ll N,M;
  ll sum=0;
  ll counter=0;
  cin >> N >> M;
  vector<ll> A(N);
  for(ll i=0;i<A.size();i++){
    cin >> A[i];
  	sum+=A[i];
  }
  
  for(ll i=0;i<A.size();i++){
    double tmp= (double)sum/(double)(4*M);
    if(A[i]>=tmp )counter++;
  }
  if(counter>=M){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3596
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<complex>
#include<iomanip>
#include<unordered_map>
#define deg(x) cerr<<#x<<"="<<x<<endl;
#define fd(x) for(int i=0;i<x;i++)
#define fdd(a,x) for(int i=a;i<x;i++)
#define fx(x,n) for(int i=n-1;i>=x;i--)
#define mst(x) memset(x,0,sizeof(x));
#define fi first
#define se second
#define TB ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define ok "ok"
#define HH puts("");
#define ls rt<<1
#define rs rt<<1|1
#define pb(a,b) a.push_back(b);
#define FIN  freopen("1.in","r",stdin);
#define FOUT freopen("1.out","w",stdout);
using namespace std;
typedef long long ll;typedef long long LL;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<string,int> pss;
typedef unsigned long long ull;
const ll mod=998244353;
const int inf=1e9+7;
const double eps=1e-6;
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return (r+m)%m;}
const double pi=acos(-1);

int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
vector<int> g[1000005];
int ff[1000005],d[1000005];
map<pii,int> mp;

char a[1005][1005];
bool vis[1005][1005];
int sx,sy,ex,ey;
int n,m;

int find(int x){
    return ff[x]==x?x:ff[x]=find(ff[x]); 
}
int id(int x,int y){
	return (x-1)*m+y;
}
pii pos(int x){
	return pii((x-1)/m,x%m);
}

void dfs(int x,int y){
	int f=find(id(x,y));
	for(int i=0;i<4;i++){
		int nx=x+dx[i],ny=y+dy[i];
		if(nx<1||nx>n||ny<1||ny>m)continue;
		if(vis[nx][ny]||a[nx][ny]=='#')continue;
		int fk=find(id(nx,ny));
		ff[fk]=f;
		vis[nx][ny]=true;
		dfs(nx,ny);
	}
}

int main(){
    TB
    cin>>n>>m;
	fdd(1,n*m+1){
        d[i]=-1;ff[i]=i;
    }
	cin>>sx>>sy>>ex>>ey;
	fdd(1,n+1)
        cin>>(a[i]+1);
	int ccc=0;
	fdd(1,n+1){
		for(int j=1;j<=m;j++){
			if(vis[i][j]||a[i][j]=='#')continue;
			dfs(i,j);
			ccc++;
		}
	}
	int s=find(id(sx,sy)),t=find(id(ex,ey));
	if(s==t){ cout<<0<<endl;return 0; }
	fdd(1,n+1){
		for(int j=1;j<=m;j++){
			if(a[i][j]=='#')continue;
			for(int nx=i-2;nx<=i+2;nx++){
				for(int ny=j-2;ny<=j+2;ny++){
					if(nx<1||nx>n||ny<1||ny>m)continue;
					if(nx==i&&ny==j)continue;
					if(a[nx][ny]=='#')continue;
					int f1=find(id(i,j)),f2=find(id(nx,ny));
					if(f1==f2)continue;
					if(mp[pii(f1,f2)])continue;
					g[f1].push_back(f2);g[f2].push_back(f1);
					mp[pii(f1,f2)]=mp[pii(f2,f1)]=1;
				}
			}
		}
	}
	queue<int> que;
	que.push(s);
	d[s]=0;
	int ans=-1;
	while(!que.empty()){
		int u=que.front();que.pop();
		if(u==t){ ans=d[u];break; }
		for(int v:g[u]){
			if(d[v]==-1){
				d[v]=d[u]+1;
				que.push(v);
			}
		}
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 65588
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define INF 999999999999999997;
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.
	LL N, Y;
	cin >> N >> Y;
	LL x = -1, y = -1, z = -1;

	if (N * 10000 < Y) {
		x = -1;
		y = -1;
		z = -1;
	}
	else {
		// max
		LL flg = 0;
		FOR(i, 0, N+1) {
			FOR(j, 0, N-i+1) {
				LL now = i * 1000 + j * 5000 + (N - i - j) * 10000;
				//cout << "now x = " << N - i - j << endl;
				if (now == Y) {
					x = N - i - j;
					y = j;
					z = i;
					flg = 1;
					break;
				}
			}
			if (flg)break;
		}


	}
	cout << x << " " << y << " " << z << endl;
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)
x = 1000
kabu = 0
(n-1).times do |i|
  if a[i] < a[i+1]
    kabu = x / a[i]
    x = x % a[i]
    x += a[i+1] * kabu
  end
end
puts x

Measured memory_bytes: 14304
#include <iostream>
#include<string.h>
#include<algorithm>
using namespace std;

int main() {
	int A,B,C,ans;
	
	cin >> A >> B>>C;
	ans = C - (A - B);
	if (ans <= 0) cout << "0" << endl;
	else cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

ll N,K;


ll man(ll N, ll val) {
  //  cout << val << endl;
  if(N==0) return val;
  return min(man(N-1, val*2),man(N-1, val + K));

}

int main() {
  cin >> N >> K;
  cout << man(N,1) << endl;
}



Measured memory_bytes: 3148
#include <stdio.h>

int main()
{
	int n,a[5000],max,sum,
		i,j;
	
	while(scanf("%d",&n),n){
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		max=a[0];

		for(i=0;i<n;i++){
			int sum = 0;
			for(j=i;j<n;j++){
				sum += a[j];
				max = max<sum ? sum : max;
			}
		}
		printf("%d\n",max);
	}
	
	return 0;
}

Measured memory_bytes: 0
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
h1,m1,h2,m2,k = readInts()
print(h2*60 + m2 - h1*60 - m1 - k)


Measured memory_bytes: 10852
// {{{
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#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(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()

//#if __cplusplus >= 201103
typedef long long ll;
//#endif
typedef pair<int, int> P;
typedef pair<int, P> IP;

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

const int INF = 100000000;
//#if __cplusplus >= 201103
const ll LINF = 10000000000000000ll;
//#endif
//const int MOD = 1e9 + 7;
const int MOD = 1000000007;
const double EPS = 1e-9;
// }}}

int N, Q, K;
vector<P> v[100000];
ll dp[100010];

void init()
{
}

void rec(int vtx, int prev)
{
    REP(i, v[vtx].size()){
        P &p = v[vtx][i];
        int next = p.fi;
        int d = p.se;
        if(next == prev) continue;
        dp[next] = dp[vtx] + d;
        rec(next, vtx);
    }
}

void solve()
{
    REP(i, N) dp[i] = -1;
    dp[K] = 0;
    rec(K, -1);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i, N-1){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        v[a].pb(mp(b, c));
        v[b].pb(mp(a, c));
    }
    cin >> Q >> K;
    K--;
    solve();
    REP(i, Q){
        int a, b;
        cin >> a >> b;
        a--; b--;
        cout << dp[a] + dp[b] << endl;
    }
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 14336
n,m,k = map(int,input().split())
mod = 10**9+7
def combination(n,r,p):
    if n < r or r < 0:
        return 0
    r = min(n-r,r)
    
    fact = [1,1]
    factinv = [1,1]
    inv = [0,1]
    for i in range(2,n+1):
        fact.append((fact[-1]*i)%p)
        inv.append((-inv[p%i]*(p//i))%p)
        factinv.append((factinv[-1]*inv[-1])%p)
    return fact[n]*factinv[r]*factinv[n-r]%p
temp = combination(n*m-2,k-2,mod)
ans = 0
for d in range(1,n):
    ans += d*((n-d)*(m**2))*temp
for d in range(1,m):
    ans += d*((m-d)*(n**2))*temp
print(ans%mod)

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

int main() {
	int n, k, l[50];
	cin >> n >> k >> l[0];
	for (int i = 1; i < n; i++) {
		cin >> l[i];
	}

	for (int i = 0; i < n - 1; i++) {
		for (int j = i + 1; j < n; j++) {
			if (l[i] < l[j]) {
				int tmp = l[j];
				l[j] = l[i];
				l[i] = tmp;
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < k; i++) ans += l[i];

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        double P [] = new double[N+1];
        double DP[][] = new double[N+1][N+1];
        for(int i=1;i<=N;i++){
            P[i]= sc.nextDouble();
            Arrays.fill(DP[i],0);
        }
        DP[0][0]=1;
        for(int i=1;i<=N;i++){
            for(int j=0;j<=i;j++){
                if(j>0)DP[i][j] = DP[i-1][j-1] * P[i]+DP[i-1][j]*(1-P[i]);
                else DP[i][j]=DP[i-1][j]*(1-P[i]);
            }
        }
        double opt = 0;
        for(int i=(N+1)/2;i<=N;i++) opt += DP[N][i];
        System.out.println(opt);
    }
}

Measured memory_bytes: 135488
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long MOD = 1e9 + 7;
using namespace std;
typedef long long ll;

map<ll, int> mp;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int k, t;
	cin >> k >> t;
	vector<int> a(t);
	for (int i = 0; i < t; i++) cin >> a[i];
	sort(a.rbegin(), a.rend());
	cout << max(a[0] - 1 - (k - a[0]), 0) << endl;
	return 0;
}

Measured memory_bytes: 256