akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
#include<set>
using namespace std;

int main() {
  int Q; cin >> Q;
  multiset<int> S;
  long sum_l = 0, sum_r = 0, sum_b = 0;
  int q, a, b; cin >> q >> a >> b;
  S.insert(a); sum_b += b;
  auto it = S.begin();
  for (int i = 1; i < Q; i++) {
    cin >> q;
    if (q == 1) {
      cin >> a >> b;
      S.insert(a);
      if (*it > a) {
        sum_l += a;
        int old_val = *it;
        it--;
        sum_r += old_val; sum_l -= *it;
      } else {
        sum_r += a;
      }
      if (S.size() % 2 == 1) {
        int old_val = *it;
        it++;
        sum_l += old_val; sum_r -= *it;
      }
      sum_b += b;
    } else {
      cout << *it << " " << sum_r - sum_l - (S.size() % 2 == 0) * (*it) + sum_b << endl;
    }
  }
}

Measured memory_bytes: 9600
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    Set<Integer> m = new TreeSet<>();

    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      m.add(a);
    }

    System.out.println(m.size());
  }
}


Measured memory_bytes: 21844
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define rep1(i,n)  for(ll i=1; i<=n; i++)
#define rrep1(i,n) for(ll i=n; 1<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int a,b;  cin >> a >> b;
  if(8 < max(a,b)){
    cout << ":(";
  }else{
    cout << "Yay!";
  }
}


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

#define ll long long
#define pb push_back
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define inf 0x3f3f3f3f

int main(){
    fcin;
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    int last = -1;
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(a[i] >= last){
            ans++;  last = a[i];
        }
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n, u, v;
    cin >> n >> u >> v;
    u--; v--;
    mat g(n);
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vec dist_t(n, INF);
    vec dist_a(n, INF);

    auto bfs = [&](int st, vec& d) {
        d[st] = 0;

        queue<int> que;
        que.push(st);

        while (!que.empty()) {
            int v = que.front();
            que.pop();

            for (auto&& c : g[v]) {
                if (d[c] == INF) {
                    d[c] = d[v] + 1;
                    que.push(c);
                }
            }
        }
    };

    bfs(u, dist_t);
    bfs(v, dist_a);

    int res = -1;

    rep(i, n) {
        if (dist_t[i] < dist_a[i]) {
            res = max(res, dist_a[i]);
        }
    }

    cout << res-1 << endl;
    return 0;
}

Measured memory_bytes: 6656
#include<iostream>
#include<cmath>
#include<iomanip>
#include<vector>
#include<cfloat>
using namespace std;

const double EPS = 0.000001;
const double PI = acos(0.0)*2.0;

int main(){
    int n;
    cin >> n;
    double x[n], y[n];
    double ret = DBL_MAX;
    for(int i = 0; i < n; i++)  cin >> x[i] >> y[i];
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            double mx = (x[i]+x[j])/2.0, my = (y[i]+y[j])/2.0;
            double r = sqrt(pow(x[i]-mx, 2.0)+pow(y[i]-my, 2.0));
            bool valid = true;
            vector<bool> in(n, 0);
            for(int k = 0; k < n; k++){
                in[k] = sqrt(pow(x[k]-mx,2.0)+pow(y[k]-my,2.0)) <= r+EPS;
                valid &= in[k];
            }
            if(valid)   ret = min(ret, r);
            for(int k = 0; k < n; k++){
                if(in[k])   continue;
                // x[i], x[j], x[k]
                double a = x[j]-x[i];
                double b = x[k]-x[j];
                double c = y[j]-y[i];
                double d = y[k]-y[j];
                double X = -(x[i]*x[i]-x[j]*x[j]+y[i]*y[i]-y[j]*y[j]);
                double Y = -(x[j]*x[j]-x[k]*x[k]+y[j]*y[j]-y[k]*y[k]);
                double cy = X/2*b - Y/2*a;
                cy /= (b*c-a*d);
                double cx = (X/2-c*cy)/a;
                double radius = sqrt(pow(x[k]-cx,2.0)+pow(y[k]-cy,2.0));
                if(radius > r){
                    r = radius;
                    mx = cx;
                    my = cy;
                }
            }
            valid = true;
            for(int k = 0; k < n; k++){
                valid &= sqrt(pow(x[k]-mx,2.0)+pow(y[k]-my,2.0)) <= r+EPS;
            }
            if(valid)   ret = min(ret, r);
        }
    }
    cout << fixed << setprecision(12) << ret << endl;
    return 0;
}

Measured memory_bytes: 256
C=[list(map(int,input().split())) for _ in range(3)]

#a1=0としてよい
a=[0]*3
b=[0]*3
for j in range(3):
    b[j] = C[0][j] - a[0]
for i in range(3):
    a[i] = C[i][0] - b[0]
ans=True
for i in range(1,3):
    for j in range(1,3):
        if C[i][j] != a[i]+b[j]:
            ans=False
print('Yes' if ans else 'No')

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys

input = sys.stdin.readline


def Y():
    print("Yes")


def N():
    print("No")


def S():
    return input().rstrip()


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


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


n = S()

ans = 0
for s in list(n):
    ans += int(s)

if ans % 9 == 0:
    Y()
else:
    N()


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

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

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string S; cin >> S;
	int sum = 0;
	for (char c : S) {
		sum += (c - '0');
		sum %= 9;
	}
	print((sum == 0) ? "Yes" : "No");
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
 
int main() {
  int a, b, x;
  cin >> a >> b >> x;
  if(a > x) cout << "NO" << endl;
  else if(a + b < x) cout << "NO" << endl;
  else cout << "YES" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] $) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[][] a=new int[2][n];
		int max=0;
		for(int i=0;i<2;i++) {
			for(int j=0;j<n;j++)a[i][j]=sc.nextInt();
		}
		for(int i=0;i<n;i++) {
			int buff=0;
			for(int j=0;j<=i;j++) {
				buff+=a[0][j];
			}
			for(int j=i;j<n;j++) {
				buff+=a[1][j];
			}
			max=Math.max(max, buff);
		}
		System.out.println(max);
	}
}



Measured memory_bytes: 22100
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
const double PI = acos(-1);
const long double EPS = 1e-9;
using namespace std;


void solve(){
    int n;
    cin >> n;
    cout << pow(2, (int)log2(n));
}
int main(){
    int q = 1;
    //cin >> q;}
    while(q--) solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  long long int a,c=0;cin>>a;
  string d;
  map<string,long long int>b;
  rep(i,a){
    cin>>d;
    sort(d.begin(),d.end());
    if(b.count(d))b[d]++;
    else b[d]=1;
  }
  for(auto i=b.begin();i!=b.end();i++){
    c+=i->second*(i->second-1)/2;
  }
  cout<<c;
}


Measured memory_bytes: 11136
# -*- coding: utf-8 -*-
def solve():
    D =  list(map((2).__pow__, range(31)[::-1]))
    wdict = {(True, True):('R',-1,-1), (True, False):('U',-1,1), (False, False):('L',1,1), (False, True):('D',1,-1)}
    mode = None
    for _ in [None]*int(input()):
        x, y = map(int, input().split())
        u = x+y
        if mode is None:
            mode = 1-u%2
            res = str(31+mode) + '\n' + ' '.join(map(str, [1]*mode+D))
            W0 = '\n'+'R'*mode
        elif mode != 1-u%2:
            return('-1')
        res += W0
        u -= mode
        v = x-y-mode
        for d in D:
            w, a, b = wdict[u>0, v>0]
            res += w
            u += a*d
            v += b*d
    return str(res)

if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF 1000000000

int main(){
	char a, b;
	cin >> a >> b;
	if((a == 'H' &&  b == 'H')||(a == 'D' && b == 'D')) cout << "H\n";
	else cout << "D\n"; 
}

Measured memory_bytes: 256
import numpy as np

def count(n):
    return bin(n).count("1")

def merge(x, y):
    return x | y

def update(Seg, k, x):
    k += len(Seg)//2
    Seg[k] = x
    while k > 0:
        k = (k - 1) // 2
        Seg[k] = Seg[k*2+1]|Seg[k*2+2]

d = {c:(1 << (ord(c)-97)) for c in 'abcdefghijklmnopqrstuvwxyz'}

class SegmentTree:
    def __init__(self, A):
        N = len(A)
        n = (N-1).bit_length()
        self.N = 1 << n
        self.Seg = [0 for i in range(2*self.N)]
        #for i in range(N): self.update(i, A[i])
        if True:
            for i in range(N):
                self.Seg[self.N+i-1] = d[A[i]]
            for i in range(0,self.N-2)[::-1]:
                self.Seg[i] = self.Seg[i*2+1] | self.Seg[i*2+2]

    def update(self, k, x):
        i = self.N+k-1
        self.Seg[i] = d[x]
        while i > 0:
            i = (i-1)//2
            self.Seg[i] = self.Seg[i*2+1]|self.Seg[i*2+2]
    def merge(self, x, y):
        return x | y

    def query(self, a, b):
        return self.query_(a, b, 0, 0, self.N)

    def query_(self, a, b, k, l, r):
        if r <= a or b <= l:
            return 0
        if a <= l and r <= b:
            return self.Seg[k]
        vl = self.query_(a, b, 2*k+1, l, (l+r)//2)
        vr = self.query_(a, b, 2*k+2, (l+r)//2, r)
        return merge(vl, vr)

def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    S = input()[:-1]
    Q = int(input())
    Seg = SegmentTree(S)

    for _ in range(Q):
        q, i, c = input().split()
        if q == '1':
            i = int(i)-1
            Seg.update(i, c)
        else:
            l, r = int(i), int(c)
            print(count(Seg.query(l-1, r)))
main()


Measured memory_bytes: 38496
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
struct edge {
	int to;
	ll cost;
	int idx;
	edge(int idx, int to, ll cost = 1) :idx(idx), to(to), cost(cost) {}
};

void dijkstra(vector<vector<edge>> &G, int N, int s, vector<ll> &dist) {
	fill(dist.begin(), dist.end(), 1LL << 60);
	dist[s] = 0;
	priority_queue<P, vector<P>, greater<P>> Q;
	Q.emplace(0, s);
	while (!Q.empty()) {
		auto p = Q.top(); Q.pop();
		int v = p.second;
		ll d = p.first;
		if (d > dist[v]) continue;
		for (auto e : G[v]) {
			if (dist[e.to] > d + e.cost) {
				dist[e.to] = d + e.cost;
				Q.emplace(dist[e.to], e.to);
			}
		}
	}
}
int main() {
	int N, M;
	while (cin >> N >> M, N) {
		vector<vector<edge>> G(N, vector<edge>());
		vector<int> u(M);
		vector<int> v(M);
		vector<int> d(M);
		vector<int> c(M);
		vector<ll> dist(N);
		vector<vector<ll>> in(N, vector<ll>());
		for (int i = 0; i < M; i++) {
			cin >> u[i] >> v[i] >> d[i] >> c[i];
			u[i]--; v[i]--;
			G[u[i]].emplace_back(i, v[i], d[i]);
			G[v[i]].emplace_back(i, u[i], d[i]);
		}
		dijkstra(G, N, 0, dist);
		for (int i = 0; i < M; i++) {
			if (dist[u[i]] + d[i] == dist[v[i]]) {
				in[v[i]].push_back(c[i]);
			}
			else if (dist[v[i]] + d[i] == dist[u[i]]) {
				in[u[i]].push_back(c[i]);
			}
		}
		ll ans = 0;
		for (int i = 0; i < N; i++) {
			if (in[i].size() == 0) continue;
			sort(in[i].begin(), in[i].end());
			ans += in[i][0];
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 5288
using System;
using System.Collections.Generic;
using System.Linq;

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();

        long A = cin.nextLong();
        long B = cin.nextLong();

        if ((A + B) % 2 != 0)
        {
            Console.WriteLine("IMPOSSIBLE");
            return;
        }

        Console.WriteLine((A + B) / 2);
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}


Measured memory_bytes: 11092
/*author - Aryan Mittal*/
#include<bits/stdc++.h>
using namespace std;

#pragma GCC push_options
#pragma GCC optimize ("unroll-loops")

#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"

#define pow2(x) ((x)*(x))
#define ll long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front

#define mod 1000000007
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)

#define mp make_pair
#define ff first
#define ss second
#define null NULL

#define all(c) (c).begin(),(c).end()
#define nl "\n"

typedef vector<ll> vl;
typedef vector< vl > vvl;
typedef pair< ll,ll> pll;
typedef map< ll,ll> mll;

const double pi = 3.1415926535897;

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

    ll r;
    cin>>r;

    double ans = 2*pi*r;

    cout<<ans<<"\n";
    
    
    return 0;
}

Measured memory_bytes: 3792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int n;
int cnt[300010];
int cum[300010];

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		cnt[a]++;
	}
	sort(cnt + 1, cnt + n + 1);
	reverse(cnt + 1, cnt + n + 1);
	cum[1] = cnt[1];
	for (int i = 2; i <= n; i++)cum[i] = cum[i - 1] + cnt[i];
	int k = 1;
	for (int i = 1; i <= n; i++) {
		while (n - cum[k] < cnt[k] * (i - k) && k + 1 < i)k++;
		if (n - cum[k] < cnt[k] * (i - k))cout << (n - cum[k]) / (i - k) << endl;
		else cout << (n - cum[k - 1]) / (i - k + 1) << endl;
	}
}


Measured memory_bytes: 5840
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
#N, K = 5, 3
#A = [96, 98, 95, 100, 20]
#N, K = 3, 2
#A = [1001, 869120, 1001]
#N, K = 15, 7
#A = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9]

def getA(i):
    if i < 0:
        return 1
    elif i >= N:
        return 1
    else:
        return A[i]
# 
for i in range(K,N):
    #print(i,getA(i-K), getA(i))
    if getA(i-K) < getA(i):
        print("Yes")
    else:
        print("No")

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

struct Card{
  char a;
  int b;
};

bool compare_as_ints(Card i, Card j){
  return (i.b<j.b);
}

int partition(Card A[], int p, int r){
  Card x = A[r];
  int i = p-1;

  for(int j=p; j<=r-1; j++){
    if(A[j].b<=x.b){
      i++;
      swap(A[i], A[j]);
    }
  }
  swap(A[i+1], A[r]);
  return i+1;
}

void quickSort(Card A[], int p, int r){
  if(p<r){
    int q = partition(A, p, r);
    quickSort(A, p, q-1);
    quickSort(A, q+1, r);
  }
}

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

  Card A[100000], B[100000];
  for(int i=0; i<n; i++){
    cin >> A[i].a >> A[i].b;
    B[i] = A[i];
  }
  quickSort(A, 0, n-1);
  stable_sort(B, B+n, compare_as_ints);

  for(int j=0; j<n;j++){
   if(A[j].a==B[j].a){
    if(j==n-1){
     cout << "Stable" << endl;
    }
   }else{
     cout << "Not stable" << endl;
     break;
   }
  }
  for(int i=0; i<n; i++){
    cout << A[i].a << ' ' << A[i].b << endl;
  }
  return 0;
}



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

int N, K;

int main(){
    scanf("%d", &N);
    scanf("%d", &K);
    int i;
    int res = 1;
    for(i=0; i<N; i++){
        if(res >= K) break;
        res *= 2;
    }
    for(int j=i; j<N; j++){
        res += K;
    }
    printf("%d", res);
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>

constexpr size_t combination(size_t n, size_t r){
    if (r == 0 || r == n){
        return 1;
    }else if(r == 1){
        return n;
    }else{
        return (combination(n - 1, r - 1) + combination(n - 1, r));
    }
}

int main(){

    size_t n;
    std::cin >> n;

    std::vector<size_t> a(n);
    for(auto&& e : a){
        std::cin >> e;
    }

    std::map<size_t, size_t> m;
    for(const auto& e : a){
        if(!m.emplace(e, 1).second){
            m[e]++;
        }
    }

    size_t cnt = 0;
    for(const auto& e : m){
        if(e.second < 2){
            cnt += 0;
        }else{
            cnt += combination(e.second, 2);
        }
    }

    for(const auto& e : a){
        std::cout << cnt - m[e] + 1 << std::endl;
    }

    return 0;
}


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

int main(){
    int N, K;
    cin >> N >> K;
    ll V[N];
    ll V_r[N];
    for(ll i = 0; i < N; i++){
        cin >> V[i];
        V_r[N-i-1] = V[i];
    }
    
    /**
    for(ll i = 0; i < N; i++) cout << V[i];
    cout << "\n";
    for(ll i = 0; i < N; i++) cout << V_r[i];
    cout << "\n";
    **/
    
    vector<ll> v;
    ll ans = 0;
    ll limit_l = min(N,K);
    ll limit_r;
    
    for(ll left = 0; left <= limit_l; left++){
        limit_r = limit_l - left;
        for(ll right = 0; right <= limit_r; right++){
            for(ll i = 0; i < left; i++){
                v.push_back(V[i]);
            }
            for(ll i = 0; i < right; i++){
                v.push_back(V_r[i]);
            }
            sort(v.begin(),v.end());
            ll size = v.size();
            ll remain = min(size, K - left - right);
            for(ll i = 0; i < remain; i++){
                if(v[0] > 0)
                    break;
                v.erase(v.begin());
            }
            ll tmp = accumulate(v.begin(), v.end(), 0);
            ans = max(ans, tmp);
            /*
            for(ll i = 0; i < v.size(); i++)
                cout << v[i];
            cout << "\n";
            */
            v.clear();
            //cout << left << "  " << right << "  " << tmp << "\n";
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    string t;
    cin>>s>>t;
    int dp[s.size()+1][t.size()+1];
    
    for(int i=0;i<=s.size();i++){
        for(int j=0;j<=t.size();j++){
            dp[i][j]=0;
        }
    }
    
    for(int i=1;i<=s.size();i++){
        for(int j=1;j<=t.size();j++){
            if(s[i-1]==t[j-1]){
                dp[i][j]=max(dp[i-1][j-1],0)+1;
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
            
        }
    }
/*
    for(int i=0;i<=s.size();i++){
        for(int j=0;j<=t.size();j++){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }*/
    int i=s.size();
    int j=t.size();
    string str="";
    while(i>0 && j>0){
        if(dp[i][j]>dp[i-1][j] && dp[i][j]>dp[i][j-1]){
                str+=s[i-1];
                i--;
                j--;
        }
        else if(dp[i][j]==dp[i-1][j])
            i--;
        else
            j--;
    }
    reverse(str.begin(),str.end());
    cout<<str<<endl;
}

Measured memory_bytes: 35456
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <sstream>
#include <iomanip>
#include <time.h>
#include <fstream>

using namespace std;


int main(){
	int N, C, K;
	vector<int> t;

	
	cin>>N>>C>>K;
	for(int i=0;i < N;i++){
		int time;
		cin>>time;
		t.push_back(time);
	}
	sort(t.begin(),t.end());
	int ans = 0;
	int curr = 0;
	for (int i = 0; i < N; i++){
		if (t[i]-t[curr]>K){
			curr = i;
			ans++;
		}
		if (i - curr + 1 > C){
			ans++;
			curr = i;
		}
	}
	ans ++;
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 892
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<double,ll,ll> tdll;
const ll mod=1e9+7;
const ll inf=1ll<<60;

ll dp[200010][31];

int main(){
  ll n,t; cin >> n >> t;
  vector<tdll> v(n);
  vector<ll> w(0);
  rep(i,n){
    ll a,b; cin >> a >> b;
    if(a>0) v[i]=(tdll((double)a/(b+1),a,b));
    else w.push_back(b);
  }
  sort(all(v));
  reverse(all(v));
  sort(all(w));
  v.resize(n-w.size());
  rep(i,v.size()+1)rep(j,31) dp[i][j]=inf;
  dp[0][0]=0;
  rep(i,v.size())rep(j,31){
    if(j>i) break;
    ll x,a,b;
    tie(x,a,b)=v[i];
    chmin(dp[i+1][j],dp[i][j]);
    if(j+1<31&&dp[i][j]<=t) chmin(dp[i+1][j+1],(a+1)*(dp[i][j]+1)+b);
  }
  int ans=0;
  rep(j,31){
    if(dp[v.size()][j]<=t) ans=j;
  }
  if(w.size()>0){
    rep(j,31){
      int i=0;
      while(i<w.size()&&dp[v.size()][j]+1+w[i]<=t){
        dp[v.size()][j]+=1+w[i];
        i++;
        chmax(ans,j+i);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 53376
/*
 *  author: chw0501
 *  reference: 
 *  created: 24.04.2020 12:04:07(UTC)
*/
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define MOD 1000000007
#define INF 987654321 

string x;
int d,len;

//dp[i][j]: i개의 자릿수에 각각 0~9까지 들어갈 수 있고 그 전까지의 합이 j일 때의 가짓수 
ll dp[10010][100];

ll solve1(int i,int j){
	ll & ret=dp[i][j];
	if(ret!=-1ll) return ret;
	if(i==0){
		if(j==0) return ret=1;
		return ret=0;
	}
	ret=0;
	for(int k=0;k<10;k++){
		ret=(ret+solve1(i-1,(j+k)%d))%MOD;
	}
	return ret;
}

//앞에서 i번째 자릿수까지 x와 일치했을 때(지금까지의 합이 j) 앞으로 얻을 수 있는 가짓수
ll solve2(int i,int j){
	if(i==len-1){
		if(j==0) return 1;
		return 0;
	}
	ll ret=0;
	for(int k=0;k<(x[i+1]-'0');k++){
		ret=(ret+solve1(len-i-2,(j+k)%d))%MOD;
	}
	ret=(ret+solve2(i+1,(j+(x[i+1]-'0'))%d))%MOD;
	return ret;
}

int main(){
	cin>>x;
	cin>>d;
	len=x.size();
	memset(dp,-1ll,sizeof(dp));
	int y=x[0]-'0';
	ll ans=0;
	for(int i=0;i<y;i++) ans=(ans+solve1(len-1,i%d))%MOD;
	ans=(ans+solve2(0,y%d))%MOD;
	cout<<(ans+MOD-1)%MOD;
	return 0;
}

Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define task "b"
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))

const int N=200010;

int n,k;

int a[N],cur[N],nxt[N],pos[N],fre[N];

main(){
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    n=in,k=in;
    forinc(i,1,n) a[i]=in;
    fordec(i,n,1){
        nxt[i]=cur[a[i]];
        cur[a[i]]=i;
    }
    forinc(i,1,n){
        if(!nxt[i])
            nxt[i]=cur[a[i]];
    }
    int i=1,cnt=1;
    for(;;){
        pos[cnt]=i;
        cnt+=nxt[i]<=i;
        i=nxt[i]+1;
        if(i>n) break;
    }
    k%=cnt;
    vector<int> v;
    if(!pos[k]) return 0;
    forinc(i,pos[k],n){
        if(fre[a[i]]){
            while(fre[a[i]]){
                fre[v.back()]=0;
                v.pop_back();
            }
        } else{
            v.pb(a[i]);
            fre[a[i]]=1;
        }
    }
    forv(i,v) cout<<i<<" ";
}


Measured memory_bytes: 10992
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>
#include <set>
#include <numeric>

using namespace std;


template <typename T>
using TABLE = vector<vector<T>>;

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;


void divisor(long long N, vector<long long>& result)
{
    result.clear();
    long long max_n = sqrt(N);

    for(int i = 1; i <= max_n; ++i){
        if(N % i == 0){
            result.push_back(i);
            if(i != N / i){
                result.push_back(N / i);
            }
        }
    }
}



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

    vector<long long> divs;
    divisor(N - 1, divs);

    long long nums = divs.size() - 1;

    divisor(N, divs);

    for(long long d : divs){
        long long r = N;

        while(r % d == 0 && d != 1){
            r = r / d;
        }

        if(r % d == 1){
            ++nums;
        }
    }

    cout << nums;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
string s;
bool j(int a,int b)
{
    a--,b--;
    while(a<b)
    {
        if(s[a]==s[b]) a++,b--;
        else return false;
    }
    return true;
}
int main()
{
    cin>>s;
    int n=s.size();
    if(j(1,n)&&j(1,(n-1)/2)&&j((n+3)/2,n)) cout<<"Yes\n";
    else cout<<"No\n";
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long n,m;
    scanf("%ld%ld", &n,&m);



    printf("%ld\n", ((n-m)*100+(m*1900))<<m);
 
    return 0;
}


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

typedef long long ll;
using namespace std;

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

	int w,h; cin >> w >> h;
	int c[1005][1005];

	for (int i = 0;i < h;i++){
		for (int j = 0;j < w;j++){
			cin >> c[i][j];
		}
	}

	int a[2][1005];
	int c0 = 0, c1 = 0;

	for (int i = 0;i < w;i++){
		int tmp = c[0][i];
		a[0][i] = tmp;
		a[1][i] = (tmp == 0 ? 1 : 0);
		if(tmp == 0) c0++;
		else c1++;
	}

	if(abs(c0-c1) > 1){
		cout << "no" << endl;
		return 0;
	}

	int t1 = 0, t2 = 0;

	for (int i = 0;i < h;i++){
		int cnt = 0;
		for (int j = 0;j < 2;j++){
			for (int k = 0;k < w;k++){
				if(c[i][k] != a[j][k]){
					cnt++;
					break;
				}
				if(k == w-1){
					if(j == 0) t1++;
					else t2++;
				}
			}
			if(cnt == 2){
				cout << "no" << endl;
				return 0;
			}
		}
	}

	if(abs(t1-t2) > 1){
		cout << "no" << endl;
		return 0;
	}

	cout << "yes" << endl;

	return 0;

}



Measured memory_bytes: 7020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    int n, m; cin >> n >> m;
    vector<pair<int, int>> v(m);
    rep(i, m) cin >> v[i].first >> v[i].second;
    sort(all(v), [](pair<int, int> x, pair<int, int> y){ // secondでソート。pairを(b, a)にすれば普通のソートでok
        return x.second < y.second;
    });
    int ans = 0;
    int now = 0;
    rep(i, m) {
        if(now <= v[i].first) {
            ans++;
            now = v[i].second;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4036
#include <cstdio>
#define MAXN (100 + 5)
using namespace std;
int n, a[MAXN], ans, ansi = 101;
int mabs(int x) { return (x > 0) ? x : (-x); }
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]), a[0] += a[i];
	for (int i = 1; i <= n; i++)
		if (mabs(a[i] * n - a[0]) < mabs(a[ansi] * n - a[0]))
			ansi = i;
	printf("%d", ansi - 1);
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
	int n1,n2,n3;
	scanf("%d", &n1);
	scanf("%d", &n2);
	scanf("%d", &n3);
	if (n1 == n2 && n2 == n3) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
long long ways=1;
char a[3][56];
int n;
cin>>n;
for(int i=1;i<=2;i++){
	for(int j=1;j<=n;j++){
		cin>>a[i][j];
	}
}
if(n==1){
	cout<<3;return 0;
}
if(n==2){
	cout<<6;return 0;
}
else {
	int i=1;ways=3;
	if(a[1][1]!=a[2][1]){
		i=2;ways=6;
	} 
	else {
		i=1;ways=3;
	}
	while(i<n){
    if(a[1][i]==a[2][i]){
    	ways*=2;
    	if(a[1][i+1]!=a[2][i+1])
    	i++;
    	i++;
	}
	else {
    	if(a[1][i+1]!=a[2][i+1]){
    	i++;
    	ways*=3;
    }
    	i++;
	}
	ways%=1000000007;
}
}
cout<<ways;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<string> vec;
void dfs(string s){
  int n = s.size();
//  cout << n << ", " << s << endl;
  for(int i = 0; i < n; i++){
    string tmp = s;
    if(s[i] == 'A'){
      tmp = tmp.erase(i, 1);
//      cout << tmp << endl;
      vec.push_back(tmp);
      dfs(tmp);
    }
  }
  return ;
}

int main(void){
  string S;
  cin >> S;
  
  vec.push_back("AKIHABARA");
  dfs("AKIHABARA");
//  string s = "AKIHABARA";
//  cout << s << endl;
//  cout << s.erase(4, 1) << endl;
  bool tf = false;
  for(int i = 0; i < vec.size(); i++){
    if(S == vec[i]){
      tf = true;
      break;
    }
  }
  if(tf) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;  
}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{
  gearup;
  int d,g; cin >> d >> g;
  vl p(d),c(d);
  rep(i,d)cin>>p[i]>>c[i];
  ll res = L_INF;
  //全完をbit全探索
  rep(i,(1<<d)-1){
    ll sum = 0;
    ll num = 0;
    rep(j,d){
      if(i & (1<<j)){
        sum+=c[j] + 100 * (j+1) * p[j];
        num+=p[j];
      }
    }
    for(int j = d-1;j>=0;j--){
      if(i & (1 <<j))continue;
      rep(k,p[j]){
        if(sum >= g)continue;
        sum+=100*(j+1);
        num++;
      }
    }
    res = min(num,res);
  }
  out(res);
}

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

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define F first
#define S second

using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  string s;

  cin >> n;
  cin >> s;

  vector<int> r(n), g(n), b(n);
  rep(i, n) {
    if (i == 0) {
      r[i] = g[i] = b[i] = 0;
      if (s[i] == 'R') r[i] = 1;
      if (s[i] == 'G') g[i] = 1;
      if (s[i] == 'B') b[i] = 1;
    }
    else {
      r[i] = r[i-1];
      g[i] = g[i-1];
      b[i] = b[i-1];
      if (s[i] == 'R') r[i] = r[i-1] + 1;
      if (s[i] == 'G') g[i] = g[i-1] + 1;
      if (s[i] == 'B') b[i] = b[i-1] + 1;
    }
  }
  reverse(s.begin(), s.end());
  reverse(r.begin(), r.end());
  reverse(g.begin(), g.end());
  reverse(b.begin(), b.end());

  ll res = 0;
  rep(i, n - 2) {
    for(int j = i+1; j < n - 1; j++) {
      if (s[j] == s[i]) continue;
      char sk;
      if (s[i] == 'R' && s[j] == 'G') sk = 'B';
      else if (s[i] == 'R' && s[j] == 'B') sk = 'G';
      else if (s[i] == 'G' && s[j] == 'R') sk = 'B';
      else if (s[i] == 'G' && s[j] == 'B') sk = 'R';
      else if (s[i] == 'B' && s[j] == 'R') sk = 'G';
      else if (s[i] == 'B' && s[j] == 'G') sk = 'R';

      int ij = j - i;
      int cnt = 0;
      if (sk == 'R') cnt = r[j+1];
      if (sk == 'G') cnt = g[j+1];
      if (sk == 'B') cnt = b[j+1];
      int k = j + ij;
      if (k <= n - 1 && s[j + ij] == sk && cnt > 0) cnt -= 1;
      res += cnt;
    }
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 3688
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int isprime(int n){
    int count =0;
    for(int i=2;i<=sqrt(n);i++)
    if(n%i==0)count++;
    if(count)return 0;
    return 1;
}
int main()
{
   string s;
   cin>>s;
   for(int i=0;i<3;i++)
   cout<<s[i];
     return 0;
}
 
 


Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> bingo(9);
  for (int i = 0; i < 9; i++) {
    cin >> bingo.at(i);
  }
  
  int N;
  cin >> N;
  
  int num;
  for (int i = 0; i < N; i++) {
    cin >> num;
    for (int j = 0; j < 9; j++) {
      if(num == bingo.at(j)){
        bingo.at(j) = 0;
        break;
      }
    }
  }
  for (int i = 0; i < 9; i++) {
  }
  
  bool a = false;
  if(bingo.at(0)==0&&bingo.at(1)==0&&bingo.at(2)==0){
    a = true;
  }
  if(bingo.at(3)==0&&bingo.at(4)==0&&bingo.at(5)==0){
    a = true;
  }
  if(bingo.at(6)==0&&bingo.at(7)==0&&bingo.at(8)==0){
    a = true;
  }
  if(bingo.at(0)==0&&bingo.at(3)==0&&bingo.at(6)==0){
    a = true;
  }
  if(bingo.at(1)==0&&bingo.at(4)==0&&bingo.at(7)==0){
    a = true;
  }
  if(bingo.at(2)==0&&bingo.at(5)==0&&bingo.at(8)==0){
    a = true;
  }
  if(bingo.at(0)==0&&bingo.at(4)==0&&bingo.at(8)==0){
    a = true;
  }
  if(bingo.at(2)==0&&bingo.at(4)==0&&bingo.at(6)==0){
    a = true;
  }
  if(a){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
use List::Util qw/sum/;

chomp (my $n = <STDIN>);
chomp (my @a = split / /, <STDIN>);
my $sum = sum(@a);
my $x = 0;
my $min = 1e15;
for my $i (0..$n-2) {
  $x += $a[$i];
  $min = abs($sum - 2 * $x) if $min > abs($sum - 2 * $x);
}
print "$min\n";

Measured memory_bytes: 34924
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import sys


def get_ints():
    return map(int, sys.stdin.readline().strip().split())


def std_in():
    return sys.stdin.readline().strip()


def main():
    a, b, c = get_ints()
    k = int(std_in())

    for i in range(k):
        if a >= b:
            b *= 2
        elif b >= c:
            c *= 2

    if a < b < c:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 9180
#include <iostream>
#include <cmath>

#define c(i,j) c[(j) * (N) + (i)]

using namespace std;

int check(int* c, int n, int N){
    int d[3];
    for(int i=0; i<N; ++i){
        d[i] = c(n+1,i) - c(n, i);
    }
    if(d[0] == d[1] && d[1] == d[2]){
        return 0;
    }else{
        return -1;
    }
}

int main(){
    int N = 3;
    auto c = new int[N*N];
    for(int i=0; i<N; ++i){
        for(int j=0; j<N; ++j){
            std::cin >> c(i,j);
        }
    }
    
    if(check(c, 0, N) == 0 && check(c, 0, N) == check(c, 1, N)){
        cout << "Yes" << endl;     
    } else {
        cout << "No" << endl;
    }
    
    delete[] c;
}

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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define pb push_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;



void solve(){

    double r;
    cin >> r;

    cout << setprecision(12) << 2*acos(-1)*r << "\n";
    return;
}

/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/
int main(){

    fast_io;
    int t=1;
    // cin >> t;

    while(t--){
        solve();
    }

    cpuTime();
return 0;
}


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

#define int long long
#define double long double

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e16;
const int MOD = 1e9+7;

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; }

vi node;

int root(int x)
{
    if(node[x] == x) return x;
    return node[x] = root(node[x]);
}

void unite(int x, int y)
{
    int rx = root(x);
    int ry = root(y);
    node[rx] = ry;
}

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    const int MAX = 50000;
    vb makable(MAX, false);
    int n; cin >> n;
    vi A(n); REP(i, n) cin >> A[i];
    REP(i, 1 << n)
    {
        int sum = 0;
        REP(j, n) if(i & (1 << j)) sum += A[j];
        makable[sum] = true;
    }
    int q; cin >> q;
    vs ans;
    REP(i, q)
    {
        int m; cin >> m;
        if(makable[m]) ans.pb("yes");
        else ans.pb("no");
    }
    REP(i, ans.size()) cout << ans[i] << endl;
}


Measured memory_bytes: 3264
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <climits>
#include <math.h>
#include <utility>
#include <ctime>
#include <cstdlib>
using namespace std;

typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) a.begin(),a.end()

double time(double n, double k) {
	double result = 0;
	while (n < k) {
		n *= 2;
		result += 1;
	}
	return result;
}

int main() {
	double n, k;
	cin >> n >> k;
	double ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += (double)pow((double)0.5, (double)time(i, k)) * (double)(1 / n);
	}
	cout << setprecision(12) << ans << endl;
	return 0;
}

Measured memory_bytes: 512
using System;
class Program {
  static int countDigit(long n) {
    int sum = 0;
    while (n > 0) {
      ++sum;
      n /= 10;
    }
    return sum;
  }

  static void Main(string[] args) {
    long N = long.Parse(Console.ReadLine());
    int ans = 100;
    for (int i = 1; i <= Math.Sqrt(N); ++i) {
      if (N % i == 0) {
        ans = Math.Min(ans, Math.Max(countDigit(i), countDigit(N / i)));
      }
    }
    Console.WriteLine(ans);
  }
}


Measured memory_bytes: 13140
-- https://github.com/minoki/my-atcoder-solutions
import Data.Char (isSpace)
import Data.List (sort, unfoldr)
import qualified Data.ByteString.Char8 as BS

main = do
  [x,n] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  ps <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let (_, answer):_ = sort [ (abs (x - i), i) | i <- [0..101], i `notElem` ps ]
  print answer


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int N;
    char A[121],B[112],C[123];

    Scd(N);
    Scs(A);
    Scs(B);
    Scs(C);

    int ans = 0;
    int tt = 0;
    Rep(i,N){
        if( A[i] == B[i] && A[i] == C[i] ){
        }else if( A[i] == B[i] || B[i] == C[i] || C[i] == A[i] ){
            ans += 1;
        }else{
            ans += 2;
        }
    }
    printf ("%d\n", ans);

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
  	unsigned int N,X;
	unsigned int SUM = 0;
 
	cin>>N;
  	cin>>X;
  
  	unsigned int L[N];
	for(int i = 1;i <= N; i++){
    	cin >> L[i];
    }
	for(int k = 1;k <= N; k++){
      	SUM += L[k];
          if(SUM > X){
          	cout << k;
            break;
          }
          if(k == N)	cout << (N+1);
    }
  	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <bitset>
#include <functional>
using namespace std;
const constexpr int INF = 1e9;
//typedef std::pair<std::string,double> P;

typedef long long ll;
typedef vector<int> VI;

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

//グラフの隣接リスト
VI g[200010];
//頂点の入次数を管理
int h[100010];
ll N;
string arr[]={"AKIHABARA", "KIHABARA", "AKIHBARA", "AKIHABRA", "AKIHABAR",
              "KIHBARA", "KIHABRA", "KIHABAR", "AKIHBRA", "AKIHBAR", "AKIHABR",
              "KIHBRA", "KIHBAR", "KIHABR", "AKIHBR", "KIHBR"};
string s;
int main(void) {
    cin >> s;
    bool ok = false;
    for(int i=0; i<16; ++i) if(s==arr[i]) ok = true;
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    
	return 0;
}


Measured memory_bytes: 4992