akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main() {
	int i, j, a, b, k;
	int x[100], xsoe = 0;

	scanf("%d %d %d", &a, &b, &k);

	for (i = 1; i <= a; i++) {
		if (a % i == 0 && b % i == 0) {
			x[xsoe] = i;
			xsoe++;
		}
	}

	printf("%d\n", x[xsoe - k]);

	return 0;
}

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

int main(){
    ll D,T,S;
    cin >> D >> T >> S;

    if(S * T >= D){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3592
from random import choice
from time import time
start_time = time()
d = int(input())
*C, = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]
X = []
L = [-1 for j in range(26)]
for i in range(d):
    max_diff = -10**10
    best_j = 0
    for j in range(26):
        memo = L[j]
        L[j] = i
        diff = S[i][j] - sum([C[jj] * (i - L[jj]) for jj in range(26)])
        if diff > max_diff:
            max_diff = diff
            best_j = j
        L[j] = memo
    L[best_j] = i
    X.append(best_j)


def f(X):
    score = 0
    L = [-1 for j in range(26)]
    A = [0 for j in range(26)]
    for i in range(d):
        score += S[i][X[i]]
        A[X[i]] += (i - L[X[i]]) * (i - L[X[i]] - 1) // 2
        L[X[i]] = i
    for j in range(26):
        A[j] += (d - L[j]) * (d - L[j] - 1) // 2
        score -= C[j] * A[j]
    return score


max_score = f(X)
while time() - start_time < 1.8:
    i = choice(range(d))
    j = choice(range(26))
    memo = X[i]
    X[i] = j
    score = f(X)
    if score > max_score:
        max_score = score
    else:
        X[i] = memo
    a = choice(range(7))
    i0 = choice(range(d - a))
    i1 = i0 + a
    memo = X[i0], X[i1]
    X[i0], X[i1] = X[i1], X[i0]
    score = f(X)
    if score > max_score:
        max_score = score
    else:
        X[i0], X[i1] = memo
for x in X:
    print(x + 1)


Measured memory_bytes: 93920
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    def dfs(i=-1,s=0,cnt=1):
        if cnt==rn:return s
        if i==-1:
            return min(dfs(j) for j in range(rn))
        vis[i]=True
        ri=rr[i]
        res=inf
        for j in range(rn):
            if vis[j]:continue
            rj=rr[j]
            res=min(res,dfs(j,s+dist[ri][rj],cnt+1))
        vis[i]=False
        return res


    inf=10**9
    n, m, rn = MI()
    rr = LI()
    to = defaultdict(list)
    dist=[[inf]*n for _ in range(n)]
    for _ in range(m):
        a, b, c = MI()
        a, b = a - 1, b - 1
        to[a].append((b, c))
        to[b].append((a, c))
        dist[a][b]=dist[b][a]=c
    for w in range(n):
        distw=dist[w]
        for u in range(n):
            for v in range(n):
                duv=distw[u]+distw[v]
                if duv<dist[u][v]:dist[u][v]=dist[v][u]=duv
    vis=[False]*rn
    print(dfs())

main()


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

int main(){
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  vector<int> arr(N, 0);
  int idx = 0;
  char pre = '1';
  if (S.at(0) == '0') { // 0スタートだった
    idx++;
    arr.at(0) = 0; // 1が0個あることにする
    pre = '0';
  }
  for (int i = 0; i < N; i++) {
    if (pre == S.at(i)) {
      arr.at(idx)++;
    } else {
      idx++;
      arr.at(idx)++;
    }
    pre = S.at(i);    
  }
  
  int max_lensum = 0;
  for (int i = 0; i < idx+1; i = i+2) {
    int lensum = accumulate(arr.begin()+i, arr.begin() + min(i+2*K+1, idx+1), 0);
    if (lensum > max_lensum) max_lensum = lensum;
    if (i+2*K+1 > idx) break;
  }
  cout << max_lensum << endl;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

vector<int> divisor(int x){
    vector<int> ret;
    for(int i=1; i*i<=x; ++i){
        if(x%i==0){
            ret.pb(i);
            if(x/i != i) ret.pb(x/i);
        }
    }
    sort(all(ret),greater<int>());
    return ret;
}

const ll mod = 1e9+7;

ll mod_pow(ll x, ll n){
    ll ret = 1;
    while(n){
        if(n&1) (ret *= x) %= mod;
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

ll mod_inv(ll x){
    return mod_pow(x,mod-2);
}

const int F = 100010;
ll f[F];

ll C(int n, int r){
    ll ret = f[n];
    (ret *= mod_inv(f[r])) %= mod;
    (ret *= mod_inv(f[n-r])) %= mod;
    return ret;
}

int n,m;
vector<int> d;
int D;

const int MD = 1000;
const int N = 50;
map<ll,ll> dp[MD][N];
ll dfs(int dep, int cr_n, int re_m){
    // printf(" CALL(%d %d %d) \n", dep,cr_n,re_m);
    if(dep == D-1) return re_m==1;
    if(dp[dep][cr_n].count(re_m)) return dp[dep][cr_n][re_m];

    ll ret = 0;
    int tmp = re_m;
    int i = 0;
    while(1){
        if(cr_n + i > n) break;
        // printf(" d[dep] %d , i %d\n",d[dep],i);
        ret += (dfs(dep+1, cr_n+i, tmp)*C(n-cr_n,i))%mod;
        ret %= mod;

        if(tmp%d[dep]!=0) break;
        tmp /= d[dep];
        ++i;
    }

    // printf(" (%d %d %d) %lld\n", dep,cr_n,re_m,ret);
    dp[dep][cr_n][re_m] = ret;
    return ret;
}

int main(){
    f[0] = 1;
    for(int i=1; i<F; ++i) f[i] = (f[i-1]*i)%mod;

    cin >>n >>m;

    d = divisor(m);
    D = d.size();

    cout << dfs(0,0,m) << endl;
    return 0;
}


Measured memory_bytes: 40704
from heapq import heappop, heappush

n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [tuple(int(x) for x in input().split()) for _ in range(m)]

bc.sort(reverse=True)

h = []

for x in a:
    heappush(h, x)

for b, c in bc:
    for _ in range(b):
        temp = heappop(h)
        if temp >= c:
            heappush(h, temp)
            break
        else:
            heappush(h, c)

print(sum(h))



Measured memory_bytes: 21752
readlines.each do |line|
  m, f, r = line.split.map(&:to_i)
  break if m == -1 && f == -1 && r == -1

  next puts :F if m == -1 || f == -1
  a = m + f
  next puts :A if 80 <= a
  next puts :B if 65 <= a && a < 80
  next puts :C if 50 <= a && a < 65 || r >= 50
  next puts :D if 30 <= a && a < 50
  next puts :F
end

Measured memory_bytes: 6104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
using C = complex<ld>;


void dfs(C s, C g, ll r){
    if(r==0){
        cout << s.real() << " " << s.imag() << '\n';
        if(g.real()==100.0L and g.imag()==0.0L)
            cout << g.real() << " " << s.imag() << '\n';
        return;
    }

    C t1 = (s * C(2) + g) * C(1.0L / 3), t2 = (s + g * C(2)) * C(1.0L / 3);

    C u = (t2 - t1) * polar(1.0L, PI / 3) + t1;

    dfs(s, t1, r - 1);
    dfs(t1, u, r - 1);
    dfs(u, t2, r - 1);
    dfs(t2, g, r - 1);
}

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

    dfs(C(0, 0), C(100, 0), N);
}


Measured memory_bytes: 3284
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let n: u32 = read();
    println!("0");
    let s: String;
    s = read();
    if s == "Vacant" {
        return;
    }
    let mut idl = 0;
    let mut idr = n;
    let mut idm;
    let mut l = s.clone();
    let mut r = s;
    for _ in 1..20 {
        idm = (idl + idr) / 2;
        println!("{}", idm);
        let m: String = read();
        if m == "Vacant" {
            return;
        }
        if (idm - idl + 1) % 2 == 1 && l != m || (idm - idl + 1) % 2 == 0 && l == m {
            idr = idm;
            r = m;
        } else {
            idl = idm;
            l = m;
        }
    }
    return;
}


Measured memory_bytes: 4948
#include<iostream>
#include<sstream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

int main(){

  long long N;
  cin>> N;

  vector< pair<long long,long long> > vpair;
  pair<long long,long long> pairbuf;
  for(long long i=0; i<N; i++){
    cin >> pairbuf.first;
    pairbuf.second=i;
    vpair.push_back(pairbuf);
  }
  sort(vpair.begin(),vpair.end());
  for(int i=0; i<vpair.size(); i++){
    cout<<vpair[i].second+1<<endl;
  }
  return 0;
}


Measured memory_bytes: 2544
use std::io::stdin;

fn main() {
    let mut s = String::new();

    stdin().read_line(&mut s).ok();
    let tmp: Vec<i32> = s
        .trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    let k = tmp[0];
    let n = tmp[1];
    s.clear();

    stdin().read_line(&mut s).ok();
    let mut a_vec: Vec<i32> = s
        .trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();

    a_vec.sort();
    let first_diff = a_vec[0];
    a_vec = a_vec.into_iter().map(|x| x - first_diff).collect();

    let mut a_diff_vec: Vec<i32> = Vec::new();
    let mut tmp_dist = 0;
    for &i_a_vec in a_vec.iter() {
        a_diff_vec.push(i_a_vec - tmp_dist);
        tmp_dist = i_a_vec;
    }
    a_diff_vec.push(k -  a_vec[(n-1) as usize]);
    let max_diff = a_diff_vec.iter().max().unwrap();

    let res = k - max_diff;
    println!("{}", res);
}


Measured memory_bytes: 10492
h,w=gets.split.map &:to_i
a=[[-1]*(w+1)]
h.times{a<<[-1]+gets.chomp.chars.map{|c|c=='#'?-1:0}}
a[1][1]=1
(1..h).each{|i|(1..w).each{|j|a[i][j]=[a[i][j-1],0].max+[a[i-1][j],0].max if (i>1||j>1)&&a[i][j]>=0}}
p a[h][w]%(10**9+7)


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

int main()
{
    int n, c, k;
    cin >> n >> c >> k;
    vector<int> times(n);
    rep(i, 0, n) cin >> times[i];

    sort(times.begin(), times.end());
    int cnt = 0;
    int ans = 0;
    int limit_time = times[0] + k;
    for (auto time: times)
    {
        if (time > limit_time or cnt == c)
        {
            ++ans;
            cnt = 0;
            limit_time = time + k;
        }
        cnt++;
    }
    if (cnt > 0) ++ans;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
import java.io.PrintWriter

val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val n = nextInt()
    val aa = listOfInt()
    val pairs = mutableListOf<Pair<Int, Int>>()

    for (i in 1..n) {
        pairs.add(Pair(i, aa[i-1]))
    }

    pairs.sortBy { it.second }
    println(pairs.joinToString(separator = " "){ it.first.toString()})
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 79184
#include <bits/stdc++.h>
        using namespace std;
        #define ll long long int
        #define pb push_back
        #define mk make_pair
        #define ft first
        #define sc second
        #define ppb pop_back
        #define sz size
        #define forn(i,a,n) for(i=a;i<n;i++)
        #define M 998244353 
        #define inf 2e18

        bool check(ll n,ll k){
            while(n%k==0){
                n=n/k;
            }
            return n%k==1;
        }
        
        int main() {

        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        
        ll n;
        cin>>n;
        ll x=n-1;
        set<ll> s;
        for(ll i=2;i*i<=x;i++){
            if(x%i==0){
                s.insert(i); 
                s.insert(x/i);
            }
        }
        s.insert(x);
        for(ll i=2;i*i<=n;i++){
            if(n%i==0)
            {if(check(n,i)){
                            s.insert(i);
                        }
                        if(check(n,n/i)){
                            s.insert(n/i);
                        }}
        }
        s.insert(n);
        s.erase(1);
        // for(auto i:s)cout<<i<<" ";
        cout<<s.size(); 


        return 0;
    }

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int f_dir[2][4] = {{-1, 0, 1, 0}, {0, 1, 0, -1}}; //↑→↓←
int e_dir[2][8] = {{-1, -1, -1, 0, 0, 1, 1, 1}, {-1, 0, 1, -1, 1, -1, 0, 1}};
bool is_in_field(int y, int x, int h, int w){
  return (y >= 0 && y < h && x >= 0 && x < w);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  ll n, d; cin >> n >> d;
  ll cnt = 0;
  for(int i = 0; i < n ; i++){
    ll x, y; cin >> x >> y;
    if(x*x + y*y <= d*d) cnt++;
  }
  cout << cnt << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


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

int main() {
    int A,B,C;
    int temp = 0;
    cin >> A >> B >> C;
    temp = A;
    A = B;
    B = temp;

    temp = A;
    A = C;
    C = temp;

    cout << A <<" "<< B <<" "<< C;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = list(map(int,input().split()))

ctr = Counter(A)
lng = short = 0
for k,v in sorted(ctr.items(), reverse=True):
    if v == 1: continue
    if lng == 0 and v >= 4:
        print(k*k)
        exit()
    if lng == 0:
        lng = k
    else:
        short = k
        break
print(lng * short)

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

int x, mart[6]={100,101,102,103,104,105};
bool dp[100001], ans=0;

int main(){
	memset(dp,0,sizeof dp);
	dp[0]=1;
	for (int i=100;i<100001;i++){
		for (int j=0;j<6;j++){
			if (i-mart[j]<0) continue;
			if (dp[i-mart[j]]) dp[i]=1;
		}
	}
	cin >> x;
	cout << dp[x] << "\n";
}

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

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LL MOD = 1000000007;
const int INF = 1e9;
const int MAXN = 100007;
const LD EPS = 1e-7;

int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("In.txt", "r", stdin);
	int n, c1 = 0;
	cin >> n;
	REP(i, n)
	{
		int a;
		cin >> a;
		if (a & 1) ++c1;
	}
	if (c1 & 1) cout << "NO";
	else cout << "YES";
	//cout << endl; system("pause");
	return 0;
}

Measured memory_bytes: 256
import itertools
n,m,q = map(int,input().split())
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
for i in range(q):
    a[i],b[i],c[i],d[i] = map(int,input().split())
ans = 0
for A in itertools.combinations_with_replacement(range(1,m+1),n):
    tmp = 0
    for i in range(q):
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            tmp += d[i]
    ans = max(ans,tmp)
print(ans)


Measured memory_bytes: 9148
n, m, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for z in range(X+1, Y+1):
    check = True
    for p in x:
        if p >= z:
            check = False
            break
    if check:
        for q in y:
            if q < z:
                check = False
                break
        if check:
            print("No War")
            exit()
print("War")


Measured memory_bytes: 3060
#![allow(non_snake_case, unused_imports)]

// Input
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)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $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, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: i64,
    }
    println!("ABC{}",N);
}

Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
int main() {
  ll n, a, b;
  cin >> a >> b >> n;
  cout << a * min(n, b - 1LL) / b - a * (min(n, b - 1LL) / b) << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long tint;
  
#define forsn(i, s, n) for(int i=s;i<int(n);i++)
#define forn(i, n) forsn(i, 0, n)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend() 
#define NACHO ios::sync_with_stdio(0); cin.tie(NULL);
 
const int INF = 1111122222;
const int MOD = 1e9+7;
 
int main(){
	NACHO;
	tint n, d, a; cin >> n >> d >> a;
	vector<pair<tint,tint>> m (n);
	forn(i, n){
		cin >> m[i].first >> m[i].second;
	}
	sort(all(m));
	vector<tint> c (n+1, 0);
	tint ret = 0;
	forn(i, n){
		int low = i, high = n+1;
		while(high-low > 1){
			int mid = low+(high-low)/2;
			if(m[mid].first <= m[i].first+2*d) low = mid;
			else high = mid;
		}
		tint upd = (m[i].second-c[i])/a+(m[i].second-c[i] >= 0 && (m[i].second-c[i]) % a != 0 ? 1 : 0);
		if(upd < 0) upd = 0;
		ret+=upd;
		c[i]+=tint(a*upd);
		c[low+1]-=tint(a*upd);
		c[i+1]+=c[i];
	}
	cout << ret << "\n";
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define init(a,i) for(int k=0;k<(i);k++)(a)[k]=0
#define in(a,i) for(int k=0;k<(i);k++)cin>>(a)[k]
#define all(a)  (a).begin(),(a).end()
#define el(a) (a).end()-(a).begin()
#define mod 1000000007
#define inf 2147483647
#define range(x,a,b) (a)<=x&&x<=(b)
int main(){
	int n;
	cin>>n;
	int v[n];
	in(v,n);
	int odd_num[100001],even_num[100001];
	init(odd_num,100001);
	init(even_num,100001);
	rep(i,n){
		odd_num[v[i]]++;
		i++;
		even_num[v[i]]++;
	}
	int odd_max=0,even_max=0,odd_sec_max=0,even_sec_max,odd_first=0,odd_second=0,even_first=0,even_second=0;
	rep(i,100001){
		if(odd_max<=odd_num[i]){
			odd_sec_max=odd_max;
			odd_max=odd_num[i];
			odd_second=odd_first;
			odd_first=i;
		}else if(odd_sec_max<=odd_num[i]){
			odd_sec_max=odd_num[i];
			odd_second=i;
		}
		if(even_max<=even_num[i]){
			even_sec_max=even_max;
			even_max=even_num[i];
			even_second=even_first;
			even_first=i;
		}else if(even_sec_max<=even_num[i]){
			even_sec_max=even_num[i];
			even_second=i;
		}
	}
	if(even_first!=odd_first){
		cout<<n-even_num[even_first]-odd_num[odd_first]<<endl;
	}
	else{
		cout<<n-max(even_num[even_first]+odd_num[odd_second],even_num[even_second]+odd_num[odd_first])<<endl;
	}
	return 0;
}

Measured memory_bytes: 4792
#include<iostream>
#include<math.h>
 using namespace std ;
 int main()
{
short int a,b,c,d;

cin>>a;
cin>>b;
cin>>c;
cin>>d;
if((abs(c-a))<=d) cout<< "Yes";
else
 if((abs(c-b)<=d)&& ( abs(b-a)<=d) ) cout<< "Yes";
else
cout<< "No";




}

Measured memory_bytes: 3588
#include <iostream>
#include <cmath>
#include <vector>

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

    int ball_num;
    int robot_b_start_position;
    std::vector<int> ball_positions;

    /** input datas **/
    std::cin >> ball_num >> robot_b_start_position;
    for (size_t i = 0; i < ball_num; i++) {
        int ball_position;
        std::cin >> ball_position;
        ball_positions.push_back(ball_position);
    }

    /** calculate distance between robot and ball **/
    int sumDistance = 0;
    for(auto ball_position : ball_positions){

        int distance_to_ball_forB = abs(ball_position - robot_b_start_position);
        int distance_to_ball_forA = abs(ball_position - 0);

        int nearDistance = std::min(distance_to_ball_forA,distance_to_ball_forB);
        int totalDistance = nearDistance * 2;

        sumDistance += totalDistance;
    }

    std::cout << sumDistance << '\n';

    return 0;
}


Measured memory_bytes: 888
#include<stdio.h>

int main()
{
	double w, h, r;
	int num;

	while (scanf("%d,%lf,%lf", &num,&w, &h)!=EOF)
	{
		r = w / (h*h);
		if (r >= 25.0)
		{
			printf("%d\n", num);
		}
	}

	return 0;
}


Measured memory_bytes: 628
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef vector<int> VI;
typedef vector<VI> VVI;
template<class T> T gcd( T a, T b ) {
	return !b ? a : gcd( b, a % b );
}
template<class T> T lcm( T a, T b ) {
	return a / gcd( a, b ) * b;
}
template<class T> string print_v( vector<T> v ) {
	OSS oss;
	for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end();
			++it_i ) {
		oss << *it_i << ", ";
	}
	return oss.str();
}

const int NONE = -1;
const string IMP = "Impossible";
int n, m;
VI A, B;

int get_most_big( int cur ) {
    int res = -1;
    for ( int i = 0; i < m; ++ i ) {
        if ( A[i] > cur + 1 ) continue;
        if ( res == -1 ) res = i;
        if ( B[res] < B[i] ) res = i;
    }
    return res;
}

int solve() {
    int res = 0;
    int cur = 0;
    while ( true ) {
        int id = get_most_big( cur );
        if ( id == -1 ) {
            return -1;
        }
        if ( cur >= B[id] ) {
            return -1;
        }
        res ++;
        cur = B[id];
        if ( cur >= n ) break;
    }
    return res;
}

int main() {
    while ( cin >> n >> m ) {
        A = VI(m), B = VI(m);
        for ( int i = 0; i < m; ++ i ) {
            cin >> A[i] >> B[i];
        }
        int ret = solve();
        if ( ret == -1 ) {
            cout << IMP << endl;
        } else {
            cout << ret << endl;
        }
    }
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

//#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

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>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    int r; cin >> r;
    put_double(2 * r * 3.14159265);

    return 0;
}



Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
const int mx = 100010;
int n;
char st[mx];
bool ans[4][mx];
bool check(int v) {
    bool a=ans[v][0];
    bool b=ans[v][n-1];
    bool c=ans[v][1];
    if (st[0]=='o') return a ? b!=c : b==c;
    else return a ? b==c : b!=c;
}
void output(int v) {
    for (int i=0;i<n;++i) printf("%c",ans[v][i]?'W':'S');
    printf("\n");
}
int main() {
    scanf("%d",&n);    scanf("%s",st);
    ans[0][0]=0;    ans[0][1]=0;    ans[1][0]=0;    ans[1][1]=1;    ans[2][0]=1;    ans[2][1]=0;    ans[3][0]=1;    ans[3][1]=1;
    for (int i=1; i<n; ++i)
        if (st[i]=='o') {
            ans[0][i+1]=(ans[0][i]==0) ? ans[0][i-1] : (!ans[0][i-1]);
            ans[1][i+1]=(ans[1][i]==0) ? ans[1][i-1] : (!ans[1][i-1]);
            ans[2][i+1]=(ans[2][i]==0) ? ans[2][i-1] : (!ans[2][i-1]);
            ans[3][i+1]=(ans[3][i]==0) ? ans[3][i-1] : (!ans[3][i-1]);
        } else {
            ans[0][i+1]=(ans[0][i]==1) ? ans[0][i-1] : (!ans[0][i-1]);
            ans[1][i+1]=(ans[1][i]==1) ? ans[1][i-1] : (!ans[1][i-1]);
            ans[2][i+1]=(ans[2][i]==1) ? ans[2][i-1] : (!ans[2][i-1]);
            ans[3][i+1]=(ans[3][i]==1) ? ans[3][i-1] : (!ans[3][i-1]);
        }
    if (ans[0][n]==ans[0][0]&&check(0)) output(0);
    else if (ans[1][n]==ans[1][0]&&check(1)) output(1);
    else if (ans[2][n]==ans[2][0]&&check(2)) output(2);
    else if (ans[3][n]==ans[3][0]&&check(3)) output(3);
    else printf("-1\n");
    return 0;
}



Measured memory_bytes: 768
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int INF = 1 << 20;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main()
{
    for(int i = 1; i < 10; i++){
        for(int j = 1; j < 10; j++){
            cout << i << 'x' << j << '=' << i*j << endl;
        }
    }
}


Measured memory_bytes: 3052
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;

ll arr[3];

int main(){
	int i, flag = 0;
	scanf("%lld %lld %lld", &arr[0], &arr[1], &arr[2]);
	sort(arr, arr + 3);
	for(i = 0; i < 3; i++) if(arr[i] % 2 == 0) flag =  1;
	if(flag == 1) printf("0");
	else printf("%lld", arr[0] * arr[1]);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main(){
  string s; cin >> s;
  int sum = 0;
  rep(i, s.size()){
    sum += s[i] - '0';
  }
  if(sum % 9 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3716
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,x,y,i,j,ans,f[500001],a[500001],cnt[500001];
int main(){
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++){
	 scanf("%d",&a[i]);
	 cnt[a[i]]++;
  }
  for(i=1;i<=n;i++){
  	for(j=i;j>=max(1,i-cnt[i]+1);j--)f[j]++;
  }
  for(i=1;i<=n;i++){
    ans+=(f[i]==0);
    //printf("%d ",f[i]);
}
//puts("");
    while(m--){
    	scanf("%d%d",&x,&y);
    	if(a[x]-cnt[a[x]]+1>=1){
    		f[a[x]-cnt[a[x]]+1]--;
    		if(!f[a[x]-cnt[a[x]]+1])ans++;
		}
		cnt[a[x]]--;
		a[x]=y;
		cnt[a[x]]++;
		if(a[x]-cnt[a[x]]+1>=1){
			f[a[x]-cnt[a[x]]+1]++;
    		if(f[a[x]-cnt[a[x]]+1]==1)ans--;
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 4992
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
typedef long long ll;
int n,a,b;ll res;
int main(){
	scanf("%d%d%d",&n,&a,&b);
	if(a>b||n==1&&a!=b)return puts("0"),0;
	res=(a+b+1ll*(n-2)*b)-(a+b+1ll*(n-2)*a)+1;
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ll long long
#define loop(a) loopi(i,a)
#define loopi(i,a) for(int i=0; i<a; i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
 
using namespace std;
 
const int Mod=1e9+7;

ll Pow(ll a, ll b, ll mod){
	ll y=1;
	ll z=a%mod;
	while(b>0){
		if(b%2==1){
			y=(y*z)%mod;
			b--;
		}
		b=b/2;
		z=(z*z)%mod;
	}
	return y;
}
 
int main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	int n;
	cin >> n;
	ll a[n];
	loop(n) cin >> a[i];
	ll b[60];
	loop(60) b[i]=0;
	loop(60){
		loopi(j,n){
			if((a[j]&1)==1) b[i]++;
			a[j]=a[j]>>1;
		}
	}
	ll ans=0;
	ll x;
	loop(60){
		x=(b[i]*(n-b[i]))%Mod;
		x=(x*Pow(2,i,Mod))%Mod;
		ans=(ans+x)%Mod;
	}
	cout << ans << "\n";
	return 0;
}


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(const T x,const T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}

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

const ll MOD=1e9+7;
const int MAX=1e5+100;

int main() {
  int N,M;cin>>N>>M;
  string S;cin>>S;
  reverse(ALL(S));
  int tmp=0;
  vector<int> res;
  while (tmp<N) {
    bool checker = false;
    for (int i=min(M,N-tmp);i>=1;i--) {
      if (S[tmp+i]=='0') {
        checker = true;
        res.push_back(i);
        tmp += i;
        break;
      }
    }
    if (!checker) {
      OUT(-1);
      return 0;
    }
  }
  reverse(ALL(res));
  DUMP(res);

  return 0;
}

Measured memory_bytes: 1144
/*************************************************************************
	> File Name: 1.cpp
	> Author: Knowledge_llz
	> Mail: 925538513@qq.com 
	> Blog: https://blog.csdn.net/Pig_cfbsl 
	> Created Time: 2020/6/14 20:07:52
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define LL long long
using namespace std;
int read(){
	char x=getchar(); int u=0,fg=0;
	while(!isdigit(x)){ if(x=='-') fg=1; x=getchar(); }
	while(isdigit(x)){ u=(u<<3)+(u<<1)+(x^48); x=getchar(); }
	return fg?-u:u;
}
int p[1000];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
	int x=read(), n=read(), a;
	int ans=12321563,y;
	For(i,1,n) a=read(), p[a]=1;
	For(i,0,101){
		if(p[i]) continue;
		a=abs(x-i);
		if(ans>a){ y=i; ans=a; }
	}
	cout<<y;
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <functional>
#include <iomanip>

using namespace std;

#ifdef LOCAL
    #define debug(v) cerr<<v<<"\n"
#else
    #define debug(...) 42
#endif
#define out(v) cout<<v<<"\n"
#define _overload3(_1,_2,_3,name,...) name
#define _all1(a) (a).begin(),(a).end()
#define _all2(a,n) (a),(a)+n
#define all(...) _overload3(__VA_ARGS__,42,_all2,_all1,)(__VA_ARGS__)
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
const int MOD = 1e9+7;
const int INF = 1e9;
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>ostream& operator<<(ostream& os, vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}
#include<type_traits>
template<typename T,size_t SIZE,enable_if_t<!is_same<remove_cv_t<T>,char>::value,nullptr_t> = nullptr>ostream& operator<<(ostream& os,T(&arr)[SIZE]){os<<"{";for(size_t i=0;i<SIZE;++i)os<<(i?", ":"")<<arr[i];os<<"}";return os;}

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int H, W, K; cin >> H >> W >> K;

  string s[H];
  rep(i, H) {
    cin >> s[i];
  }
  int count = 1;
  vvi _res, res;
  rep(i, H) {
    bool is_empty = true;
    int tmp_count = 0;
    rep(j, W) {
      if (s[i][j] == '#')
        ++tmp_count;
    }
    if (tmp_count != 0) {
      vi res2;
      int count2 = 0;
      rep(j, W) {
        if (s[i][j] == '#') {
          if (tmp_count == count2+1) {
            while (j < W) {
              res2.push_back(count+count2);
              ++j;
            }
            break;
          } else
            res2.push_back(count+count2);
          ++count2;
        } else
          res2.push_back(count+count2);
      }
      _res.push_back(res2);
      count += tmp_count;
    }
  }

  int empty_count = 0;
  rep(i, H) {
    bool is_empty = true;
    rep(j, W) {
      if (s[i][j] == '#')
        is_empty = false;
    }
    if (empty_count == _res.size())
      res.push_back(_res.back());
    else
      res.push_back(_res[empty_count]);
    if (!is_empty) {
      ++empty_count;
    }
  }
  rep(i, H) {
    rep(j, W) {
      cout << res[i][j] << " ";
    }
    cout << "\n";
  }

  return 0;
}


Measured memory_bytes: 1664
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * 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);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int H = in.nextInt();
            int W = in.nextInt();
            int h = in.nextInt();
            int w = in.nextInt();
            out.println(H * W - (H * w) - (W * h) + (h * w));
        }

    }
}



Measured memory_bytes: 21844
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Supplier<String> sc) {
		int N = Integer.parseInt(sc.get());
		int[] L = new int[N];
		Arrays.setAll(L, $ -> Integer.parseInt(sc.get()));
		Arrays.sort(L);

		int sum = 0;
		for (int i = 0; i < L.length; i++) {
			for (int j = i + 1; j < L.length; j++) {
				int a = L[i];
				int b = L[j];
				int upper = maximum(k -> k < a + b, L);
				int lower = Math.max(j + 1, Math.max(minimum(k -> a - b < k, L), minimum(k -> b - a < k, L)));
				int result = upper - lower + 1;
				if (lower <= i && i <= upper) result -= 1;
				if (lower <= j && j <= upper) result -= 1;
				sum += Math.max(0, result);
			}
		}
		System.out.println(sum);
	}

	int minimum(IntPredicate predicate, int[] array) {
		int l = -1;
		int r = array.length;
		while (Math.abs(r - l) > 1) {
			int mid = (l + r) / 2;
			if (predicate.test(array[mid])) r = mid;
			else l = mid;
		}
		return r;
	}

	int maximum(IntPredicate predicate, int[] array) {
		int l = array.length;
		int r = -1;
		while (Math.abs(r - l) > 1) {
			int mid = (l + r) / 2;
			if (predicate.test(array[mid])) r = mid;
			else l = mid;
		}
		return r;
	}
}

class Main {
	public static void main(String... args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		Solver.INSTANCE.solve(new Supplier<String>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
	}
}

Measured memory_bytes: 38740
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
 
class Program{
    static void Main(){
        string[] inputs = Console.ReadLine().Split(' ');
        int n = int.Parse(inputs[0]);
        int q = int.Parse(inputs[1]);
        Dictionary<string, int> processes = new Dictionary<string, int>();
        Queue<string> queue = new Queue<string>();
        for (int i = 0; i < n; i++)
        {
            inputs = Console.ReadLine().Split(' ');
            processes.Add(inputs[0], int.Parse(inputs[1]));
            queue.Enqueue(inputs[0]);
        }
        int pastTime = 0;
        while (true)
        {
            string currentProcess;
            try{
                currentProcess = queue.Dequeue();
            }
            catch(InvalidOperationException){
                break;
            }
            if(processes[currentProcess] > q){
                pastTime += q;
                processes[currentProcess] -= q;
                queue.Enqueue(currentProcess);
            }
            else{
                pastTime += processes[currentProcess];
                processes[currentProcess] = 0;
                Console.WriteLine("{0} {1}", currentProcess, pastTime);
            }
        }
    }
}

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

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

fn main() {
    use std::collections::VecDeque;
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let k: usize = scan(tokens);
    let mut queue: VecDeque<usize> = VecDeque::with_capacity(k);
    let mut sum: usize = 0;
    for _ in 0..k {
        let p: usize = scan(tokens);
        queue.push_back(p);
        sum += p;
    }
    let mut max: usize = sum;
    for _ in k..n {
        let p: usize = queue.pop_front().unwrap();
        sum -= p;
        let p: usize = scan(tokens);
        queue.push_back(p);
        sum += p;
        max = std::cmp::max(max, sum);
    }
    println!("{}", (k + max) as f64 / 2.0);
}


Measured memory_bytes: 6396
#include <stdio.h>

int main(void){
        int c[6]={}, val[]={1, 5, 10, 50, 100, 500};
        int sum=0, i;

        for( i=0 ; i<6 ; i++ ){
                scanf("%d", &c[i]);
                sum += c[i] * val[i] ;
        }

        if( sum>=1000 )
                puts("1");
        else
                puts("0");

        return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define repR(i, n) for(ll i = n; i >= 0; ++i)
#define FDS(i, n) for(ll i = 0; i < n; ++i)
#define FDSR(i, n) for(ll i = n; i >= 0; ++i)
#define FOR(i, m, n) for(ll i = m; i < n; ++i)
#define FORR(i, m, n) for(ll i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
#define INF 999999999
#define itn ll
#define ednl endl
using namespace std;
typedef long long ll;template<typename Typell>Typell G_C_D(Typell a, Typell b){if (a < 0) a = -a;if (b < 0) b = -b;while (b != 0) {a %= b;if (a == 0) return b;b %= a;}return a;}template<typename Typell>
Typell G_C_D(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = G_C_D(a, list[i]);}return a;}template<typename Typell>Typell L_C_M(Typell a, Typell b) {if( a == 0 && b == 0)return 0;return a / G_C_D(a, b) * b;}
template<typename Typell>Typell L_C_M(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = L_C_M(a, list[i]);}return a;}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int N,M;
	cin>>N>>M;
	vector<int> a(M);
	vector<int> b(M);
	FDS(i,M){
		cin>>a[i]>>b[i];
	}
	
	if(M==1){
		cout<<"IMPOSSIBLE"<<endl;
		return 0;
	}
	
	vector<int> iti(M);
	int t=0;
	FDS(i,M){
		if(a[i]==1){
			iti[t]=b[i];
			t++;
		}
	}
	VSORT(iti);
	VREV(iti);
	
	vector<int> saigo(M);
	int s=0;
	FDS(i,M){
		if(b[i]==N){
			saigo[s]=a[i];
			s++;
		}
	}
	VSORT(saigo);
	VREV(saigo);	
	
	int B=0;
	FDS(A,M){
		if(iti[A]==saigo[B]){
			cout<<"POSSIBLE"<<endl;
			return 0;
		}
		if(iti[A]==0||saigo[B]==0){
			cout<<"IMPOSSIBLE"<<endl;
			return 0;
		}
		if(iti[A]<saigo[B]){
			B++;
			A--;
		}
	}
}

Measured memory_bytes: 3456
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n,m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
uf = UnionFind(n)
for i in range(m):
    uf.union(a[i][0]-1,a[i][1]-1)
ans = 0
x = uf.parents
for i in range(n):
    if x[i]<0:
        #print(i)
        ans = max(ans,uf.size(i))
print(ans)


Measured memory_bytes: 106784
#include<iostream>
#include<list>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<queue>
using namespace std;

#define LL long long int
#define uLL unsigned long long int

#define S(a) scanf("%d",&a)
#define S2(a,b) scanf("%d%d",&a,&b)
#define S3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define SLL(a) scanf("%lld",&a)
#define SLL2(a,b) scanf("%lld%lld",&a,&b)
#define SLL3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define SC(a) scanf("%c",&a)
#define P(a) printf("%d",a)
#define PS(a) printf("%s",a)
#define PLL(a) printf("%lld",a)
#define PCASE(kk) printf("Case %d: ",kk++)
#define PCASENL(kk) printf("Case %d:\n",kk++)
#define NL puts("")

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pi (2.0*acos(0.0))
#define pii pair<int,int>

template<typename T>inline T POW(T B,T P)
{
    if(P==0) return 1;
    if(P&1) return B*POW(B,P-1);
    else return SQR(POW(B,P/2));
}
template <class T> inline T BMOD(T p,T e,T m)
{
    T ret=1;
    while(e)
    {
        if(e&1) ret=(ret*p)%m;
        p=(p*p)%m;
        e>>=1;
    }
    return (T)ret;
}
template <typename T>inline T ModInv (T b,T m)
{
    return BMOD(b,m-2,m);
}
template<typename T>inline T ABS(T a)
{
    if(a<0)return -a;
    else return a;
}
template<typename T>inline T gcd(T a,T b)
{
    if(a<0)return gcd(-a,b);
    if(b<0)return gcd(a,-b);
    return (b==0)?a:gcd(b,a%b);
}
template<typename T>inline T lcm(T a,T b)
{
    if(a<0)return lcm(-a,b);
    if(b<0)return lcm(a,-b);
    return a*(b/gcd(a,b));
}

/////////////////////////////////////////////////

int n,arr[503];
double x[503],y[503];
double calc(int a,int b)
{
    if(a==0)return y[b];
    double oti = y[a]+y[b];
    double lomb = fabs(y[b]-y[a]);

    double ret=sqrt(oti*oti - lomb*lomb);
    return x[a]+ret;
}

int main()
{
    while(S(n)!=EOF)
    {
        for(int i=1;i<=n;i++)
        {
            S(arr[i]);
        }
        double nw=0.0;
        x[0]=y[0]=0;
        for(int i=1;i<=n;i++)
        {
            double r=arr[i]*1.0;
            x[i]=0.0;
            y[i]=r;
            for(int j=0;j<i;j++)
            {
                x[i]=max(calc(j,i),x[i]);
            }

            nw=max(nw,y[i]+x[i]);
        }
        cout<<setprecision(8)<<fixed<<nw<<endl;
//        printf("%0.8lf\n",nw);

    }
    return 0;
}

Measured memory_bytes: 3284