akhauriyash/Code-Regression huggingface dataset:
import sys
buf = sys.stdin.buffer

class UnionFind:
  def __init__(self, num_of_node):
    self.roots = [-1] * num_of_node
    self.ranks = [1] * num_of_node
    self.groups = num_of_node
 
  def get_root(self, node):
    root = self.roots[node]
    if root == -1:
      return node
    else:
      root = self.get_root(root)
      self.roots[node] = root
      return root

  def is_same_group(self, node1, node2):
    return self.get_root(node1) == self.get_root(node2)

  def unite(self, node1, node2):
    self.groups -= 1
    root1, root2 = self.get_root(node1), self.get_root(node2)
    rank1, rank2 = self.ranks[root1], self.ranks[root2]
    if rank1 < rank2:
      root1, root2 = root2, root1
    self.roots[root2] = root1
    self.ranks[root2] += self.ranks[root1]

def main():
  n = int(buf.readline())
  XY = map(int, buf.read().split())
  Xs = []
  Ys = []
  for i, (x, y) in enumerate(zip(XY, XY)):
    Xs.append((x-1, i))
    Ys.append((y-1, i))
    
  Xs.sort()
  Ys.sort()
  
  edges = []
  for i, ((x, node), (nx, new_node)) in enumerate(zip(Xs[:-1], Xs[1:])):
    edges.append((nx-x, node, new_node))
 
  for i, ((y, node), (ny, new_node)) in enumerate(zip(Ys[:-1], Ys[1:])):
    edges.append((ny-y, node, new_node))
 
  edges.sort(reverse=True)
 
  ans = 0
  uf = UnionFind(n)
  while uf.groups != 1:
    d, node1, node2 = edges.pop()
    if uf.is_same_group(node1, node2):
      continue
    uf.unite(node1, node2)
    ans += d
  print(ans)

if __name__ == "__main__":
    main()

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

int h, w;
vector<vector<char>> graph;
vector<vector<int>> length;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

void bfs() {
  queue<pair<int, int>> q;
  q.push(make_pair(0, 0));
  while (!q.empty()) {
    pair<int, int> u;
    u = q.front(); q.pop();
    int x = u.first;
    int y = u.second;
    for (int i = 0; i < 4; i ++) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (nx >= 0 && nx < h && ny >= 0 && ny < w && graph[nx][ny] == '.' && length[nx][ny] == 0) {
        length[nx][ny] = length[x][y] + 1;
        q.push(make_pair(nx, ny));
      }
    }
  }
}

int main() {
  cin >> h >> w;
  int cnt_black = 0;
  graph = vector<vector<char>>(h, vector<char>(w));
  for (int i = 0; i < h; i ++) {
    for (int j = 0; j < w; j ++) {
      cin >> graph[i][j];
      if (graph[i][j] == '#') cnt_black ++;
    }
  }

  length = vector<vector<int>>(h, vector<int>(w, 0));
  length[0][0] = 1;
  bfs();

  int ans;
  if (length[h - 1][w - 1] == 0) ans = -1;
  else ans = h * w - length[h - 1][w - 1] - cnt_black;

  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		int add = a + b;
		int diff = a - b;
		int multi = a * b;
		int max = 0;
		
		if (add >= diff) {
			max = add;
		} else {
			max = diff;
		}
		
		if (multi > max) {
			max = multi;
		}
		
		System.out.println(max);
  }
  
}

Measured memory_bytes: 21076
#include <iostream>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない


int main(){
	int a, b;
	cin >> a >> b;
	if (b%a == 0)cout << a + b << endl;
	else cout << b-a << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    int ans=-1;
    cin >> n;
    vector<int> a;
    rep(i,n){
        int q;
        cin >> q;
        a.push_back(q-1);
        a.push_back(q);
        a.push_back(q+1);
    }
    map<int,int> cnt;
    rep(i,a.size()){
        cnt[a[i]] ++;
        ans = max(ans,cnt[a[i]]);
    }
    cout << ans <<endl;

}

Measured memory_bytes: 5872
using System;
using static System.Console;

namespace abc157
{
    class Program
    {
        static void Main()
        {
            var a = new int[3][];
            a[0] = ReadNumList();
            a[1] = ReadNumList();
            a[2] = ReadNumList();
            var n = int.Parse(ReadLine());
            var checkList = new int[][,] {
                new int[,] {{0, 0}, {0, 1}, {0, 2}},
                new int[,] {{1, 0}, {1, 1}, {1, 2}},
                new int[,] {{2, 0}, {2, 1}, {2, 2}},
                new int[,] {{0, 0}, {1, 0}, {2, 0}},
                new int[,] {{0, 1}, {1, 1}, {2, 1}},
                new int[,] {{0, 2}, {1, 2}, {2, 2}},
                new int[,] {{0, 0}, {1, 1}, {2, 2}},
                new int[,] {{0, 2}, {1, 1}, {2, 0}}
            };
            var bingo = new bool[3][];
            bingo[0] = new bool[3];
            bingo[1] = new bool[3];
            bingo[2] = new bool[3];
            for (var i = 0; i < n; ++i)
            {
                var b = int.Parse(ReadLine());
                for (var ix = 0; ix < 3; ++ix)
                {
                    for (var iy = 0; iy < 3; ++iy)
                    {
                        if (a[ix][iy] == b)
                        {
                            bingo[ix][iy] = true;
                        }
                    }
                }
            }
            foreach (var check in checkList)
            {
                if (bingo[check[0,0]][check[0,1]] && bingo[check[1,0]][check[1,1]] && bingo[check[2,0]][check[2,1]])
                {
                    WriteLine("Yes");
                    return;
                }
            }
            WriteLine("No");
        }
        static int[] ReadNumList()
        {
            var line = Console.ReadLine().Split(' ');
            if (line.Length == 1 && string.IsNullOrEmpty(line[0]))
            {
                return new int[0];
            }
            var numList = new int[line.Length];
            for (var i = 0; i < line.Length; ++i)
            {
                numList[i] = int.Parse(line[i]);
            }
            return numList;
        }
    }
}


Measured memory_bytes: 27544
#include<iostream>
#include<cmath>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#define P pair<long long, long long>


using namespace std;
const long long int MOD=1e9+7;

int main(){
  long long base=1, h, ans=0;
  cin >> h;
  while(h>0){
    ans+=base;
    base*=2;
    h/=2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <numeric>
#include <math.h>

#define user spaesk
#define pi acos(-1)
#define lli long long int
#define ld long double
#define ff first
#define ss second
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

typedef vector<vector<lli> > matrix ;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;
const int NN = 5e3 + 6;

lli dp[107][N], acc[107][N];

void solve()
{

    lli n, k;
    cin>>n>>k;
    lli a[n + 1];
    for(int i = 1; i <= n; i ++) {
        cin>>a[i];
    }

    dp[0][0] = 1;
    for(int i = 0; i <= k; i ++) {
        acc[0][i] = 1;
    }

    for(int i = 1; i <= n; i ++) {
        for(int j = 0; j <= k; j ++) {
            dp[i][j] = (acc[i - 1][j]);
            if(j - a[i] - 1 >= 0) {
                dp[i][j] -= acc[i - 1][j - a[i] - 1];
            }
            dp[i][j] = (dp[i][j] + mod) % mod;

            acc[i][j] = (dp[i][j]);
            if(j > 0) {
                acc[i][j] += (acc[i][j - 1]);
            }
            acc[i][j] %= mod;

        }
    }

//    for(int i = 0; i <= n; i ++) {
//        for(int j = 0; j <= k; j ++) {
//            cout<<dp[i][j]<<' ';
//        }
//        cout<<endl;
//    }

    cout<<dp[n][k];

    cout<<"\n";
    return ;
}

/*
*/

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

    int t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 474112
_ = gets
v_ary = gets.chomp.split.map(&:to_i)
c_ary = gets.chomp.split.map(&:to_i)
sum = 0

v_ary.length.times do |i|
  if v_ary[i] > c_ary[i]
    sum += v_ary[i] - c_ary[i]
  end
end
puts sum

Measured memory_bytes: 1788
import java.util.*;
import static java.lang.System.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int a  = sc.nextInt();
		long GCD = a;
		for(int i = 1; i < n; i++) {
			int b = sc.nextInt();
			GCD = gcd(GCD, b);
		}
		out.println(GCD);

	out.close();
}
	  //最大公約数を求めるメソッド
	  private static long gcd(long m, long n) {
		    if(m < n) return gcd(n, m);
		    if(n == 0) return m;
		    return gcd(n, m % n);
		}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}


Measured memory_bytes: 22872
#include<iostream>
using namespace std;
#define INF (1 << 30)
#define MAX 2000000

int h = 0, A[MAX+1];
int parent(int i){return i/2;}
int left(int i){return i * 2;}
int right(int i){return i * 2 + 1;}

int maxHeapify(int T[], int i){
  int l = left(i);
  int r = right(i);
  int largest = i;
  if ( l <= h && T[i] < T[l]){
    largest = l;
  }
  if ( r <=  h && T[largest] < T[r]){
    largest = r;
  }

  if ( largest != i){
    swap(T[i], T[largest]);
    maxHeapify(T, largest);
  }

  return 0;
}

void heapIncreaseKey(int key){
  if ( A[h] > key){return ;}
  A[h] = key;
  int i = h;
  while (i > 1 && A[i] > A[parent(i)] ){
    swap(A[i], A[parent(i)]);
    i = parent(i);
  }
}

void insert(int key){
  A[++h] = -INF;
  heapIncreaseKey(key);
}

int extract(){
  int maxV;
  if ( h < 1){return -INF;}
  maxV = A[1];
  A[1] = A[h--];
  maxHeapify(A, 1);

  return maxV;
}

int main(){
  string com;
  int key;
  while (1){
    cin >> com;
    if ( com == "insert"){
      cin >> key;
      insert(key);
    } else if ( com == "extract"){
      cout << extract() << endl;
    } else if ( com == "end"){
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 7016
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef long double ld;
    typedef pair<int,int> P;
    typedef pair<ll,ll> l_l;
    const int INF=1001001000;
    const int mINF=-1001001000;
    const ll LINF=1010010010010010000;
    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;
    }
    double lim[40100];
    void update(int now,double t,double v){
        now*=2;
        t*=2;
        for(int i=now;i<=now+t;i++){
            chmin(lim[i],v);
        }
    }
    int main(){
        int n;cin >> n;
        vector<double> t(n),v(n);
        for(int i=0;i<n;i++) cin >> t[i];
        for(int i=0;i<n;i++) cin >> v[i];
        int tot=0;
        for(int i=0;i<n;i++) tot+=t[i];
        fill(lim,lim+40100,INF);
        int now=0;
        for(int i=0;i<n;i++){
            update(now,t[i],v[i]);
            now+=t[i];
        }
        lim[0]=0;
        lim[2*tot]=0;
        for(int i=0;i<=2*tot;i++) chmin(lim[i+1],lim[i]+0.5);
        for(int i=2*tot;i>=0;i--) chmin(lim[i-1],lim[i]+0.5);
        double ans=0.0;
        for(int i=0;i<2*tot;i++){
            ans+=(lim[i]+lim[i+1])/2*0.5;
        }
        cout << setprecision(10) << ans << endl;
        return 0;
    }

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

using namespace std;

int main()
{
//    freopen("in.txt","r",stdin);

    string w;
    cin>>w;
    string t;
    int con=0;
    while(cin>>t)
    {
        if(t=="END_OF_TEXT")
            break;
        for(int i=0;i<t.length();i++)
        {
            if(isupper(t[i]))
                t[i]=tolower(t[i]);
        }
        if(t==w)
            con++;

    }
    cout<<con<<endl;
}



Measured memory_bytes: 3212
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

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

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    size_t H, W, K; cin >> H >> W >> K;

    vector<string> mat(H);
    for (auto &mi: mat) cin >> mi;

    auto res = make_v(0, H, W);
    size_t base = 1;
    for (size_t i = 0; i < H; ++i) {
        if (all_of(mat[i].begin(), mat[i].end(), [&](char c) { return c == '.'; })) {
            continue;
        } else {
            bool exist = false;
            for (size_t j = 0; j < W; ++j) {
                if (exist && mat[i][j] == '#') {
                    base++;
                } else if (mat[i][j] == '#') {
                    exist = true;
                }
                res[i][j] = base;
            }
        }
        base++;
    }

    for (int i = 0; i < H; ++i) {
        if (all_of(res[i].begin(), res[i].end(), [&](int x) { return !x; })) {
            for (int j = 0; j < W; ++j) {
                if (i + 1 < H && res[i + 1][j]) res[i][j] = res[i + 1][j];
                if (i - 1 >= 0 && res[i - 1][j]) res[i][j] = res[i - 1][j];
            }
        }
    }

    for (int i = H - 1; i >= 0; --i) {
        if (all_of(res[i].begin(), res[i].end(), [&](int x) { return !x; })) {
            for (int j = 0; j < W; ++j) {
                if (i + 1 < H && res[i + 1][j]) res[i][j] = res[i + 1][j];
                if (i - 1 >= 0 && res[i - 1][j]) res[i][j] = res[i - 1][j];
            }
        }
    }

    for (size_t i = 0; i < H; ++i) {
        for (size_t j = 0; j < W; ++j) {
            cout << res[i][j] << (j == W - 1)[" \n"];
        }
    }

    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int main(){
  string s;
  cin >> s;
  int n = s.size();
  REP(i,n)
    cout << 'x';
  cout << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int cnt=0;
		for(int i=a;i<b+1;i++)
		{
			if(c%i==0)
				cnt++;
		}
		
		System.out.println(cnt);
	}
}



Measured memory_bytes: 26408
from collections import Counter


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

ans1 = 0
counter = Counter(a)
items = list(counter.items())
counter_dict = dict(items)

for i in range(len(items)):
    c_i = items[i][1]
    ans1 += c_i * (c_i - 1) // 2

for k in range(n):
    ans2 = counter_dict.get(a[k]) - 1
    print(ans1 - ans2)

Measured memory_bytes: 40084
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define int long long
using namespace std;
const int INF=1<<29;
const int N_MAX=100000;
int N;
vector<int> h;
int dp[N_MAX];
//dp[i]:足場i(0-base)にたどり着くまでの最小コスト
signed main(){
    cin>>N;
    h.resize(N);
    REP(i,N) cin>>h[i];
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<N;++i){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),
                  dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[N-1]<<endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
using namespace std;
vector<int>p;
int main(){
    unsigned long long int a;
    cin>>a;

    while(a!=0){
        a-=1;
        p.push_back(a%26);
        a/=26;
    }
    for(int i=p.size()-1;i>=0;i--){
        char c=p[i]+97;
        cout<<c;
    }
}

Measured memory_bytes: 3684
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    N = int(input())
    
    def rec(n, maxchr, ans):
        if n==N-1:
            print(ans)
        else:
            for i in range(maxchr+1):
                # print(i)
                rec(n+1, maxchr, ans+chr(i+97))
            rec(n+1, maxchr+1, ans+chr(maxchr+98))

    rec(0, 0, 'a')

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 4412
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define mod 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  double n,m,a,b,c,d;
  double l;
  cin >>l;
  a=l/3;
  a=a*a*a;
  cout <<fixed<<SYOU(7)<<a<<'\n';
  return (0);
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
S = sum(a[:2])
X = 0
for i in range(2, n):
    X ^= a[i]
if S - X < 0 or (S - X) % 2 != 0:
    print(-1)
    exit(0)
D = (S - X) // 2
if D > a[0] or D & X:
    print(-1)
    exit(0)
res = D
for i in range(60, -1, -1):
    if X & (1 << i):
        Q = res | (1 << i)
        if Q <= a[0]:
            res = Q
print(-1 if res == 0 else a[0] - res)


Measured memory_bytes: 61984
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
ll n, m, s, t;
struct Edge{
    ll to;
    ll cost1;
    ll cost2;
};

vector<vector<Edge>> g;

vector<ll> dijkstra(int start, int type){
    vector<ll> dist(n, INF);
    priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> q;
    q.push(make_pair(0, start));
    dist[start] = 0;
    while(!q.empty()){
        ll now = q.top().second;
        ll nowdist = q.top().first;
        q.pop();
        if(dist[now] < nowdist) continue;
        for(int i = 0; i < g[now].size(); i++){
            ll next = g[now][i].to;
            ll nextcost = (type?g[now][i].cost1:g[now][i].cost2);
            if(dist[next] <= nowdist + nextcost) continue;
            dist[next] = nowdist + nextcost;
            q.push(make_pair(dist[next], next));
        }
    }

    return dist;
   
}
int main(void){
	cin >> n >> m >> s >> t;
    s--;
    t--;
    g.resize(n);

    for(int i = 0; i < m; i++){
        ll from, to;
        cin >> from >> to;
        from--;
        to--;
        Edge tmp;
        cin >> tmp.cost1 >> tmp.cost2;
        tmp.to = to;
        g[from].push_back(tmp);
        tmp.to = from;
        g[to].push_back(tmp);
    }

    ll best = INF;
    vector<ll> ans(n);
    vector<ll> exdist = dijkstra(s, 1);
    vector<ll> gdist = dijkstra(t, 0);
    for(int i = n - 1; i >= 0; i--){
        //cout << best << " " << exdist[i] + gdist[t] << endl;
        best = min(best, exdist[i] + gdist[i]);
        ans[i] = best;
    }

    for(int i = 0; i < n; i++){
        cout << (ll)1e15 - ans[i] << endl;
    }


}

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

using ll = long long int;
#define int ll

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

struct Read {
	int operator()(void) {
		int d;
		std::cin >> d;
		return d;
	}
}read;
struct ReadReal {
	double operator()(void) {
		double d;
		std::cin >> d;
		return d;
	}
}readReal;
struct ReadString {
	std::string operator()(void) {
		std::string s;
		std::cin >> s;
		return s;
	}
}readString;
struct ReadEof {
	bool operator()(void) {
		return std::cin.eof();
	}
}readEof;

struct Print {
	void operator()(double d, int digit) {
		std::cout << std::fixed << std::setprecision(digit) << d;
	}
	template <typename T>
	void operator()(T t) {
		std::cout << t;
	}
	template <typename T>
	void operator()(const std::vector<T> &v, const std::string &sep = " ") {
		if (v.empty()) return;
		Print()(v[0]);
		for(int i = 1;  i < v.size(); ++i) {
			Print()(sep);
			Print()(v[i]);
		}
		return;
	}
	template <typename T>
	void operator()(T begin, T end, const std::string &sep = " ") {
		if (begin == end) return;
		Print()(*begin);
		for(auto it = ++begin;  it != end; ++it) {
			Print()(sep);
			Print()(*it);
		}
		return;
	}
}print;
struct Println {
	void operator()(void) {
		std::cout << std::endl;
	}
	void operator()(double d, int digit) {
		print(d, digit);
		Println()();
	}
	template <typename T>
	void operator()(T t) {
		print(t);
		Println()();
	}
	template <typename T>
	void operator()(const std::vector<T> &v, const std::string &sep = " ") {
		print(v, sep);
		Println()();
	}
	template <typename T>
	void operator()(T begin, T end, const std::string &sep = " ") {
		print(begin, end, sep);
		Println()();
		return;
	}
}println;

constexpr int kQueueMax = 100'000;
struct Process{
	string name;
	int time;
};
class Queue {
public:
	Queue():m_Head(0), m_Tail(0), m_Queue() {
	}
	void Enqueue(const Process &p) {
		if (isFull()) return;
		m_Queue[m_Tail] = p;
		m_Tail = (m_Tail + 1 == kQueueMax ? 0 : m_Tail + 1);
	}
	Process Dequeue(void) {
		if (isEmpty()) return Process();
		Process& p = m_Queue[m_Head];
		m_Head = (m_Head + 1 == kQueueMax ? 0 : m_Head + 1);
		return p;
	}
	bool isEmpty() const {
		return  m_Head == m_Tail;
	}
	bool isFull() const {
		// Head と Tail の間は1つ空ける
		return (m_Tail + 1) % kQueueMax == m_Head;
	}
private:
	int m_Head;
	int m_Tail;
	Process m_Queue[kQueueMax];
};

void ProcessScheduler(int size, int quantum) {
	unique_ptr<Queue> queue = make_unique<Queue>();
	for(auto s = readString(); !readEof(); s = readString()) {
		auto time = read();
		queue->Enqueue({s, time});
	}

	int total_time = 0;
	while(!queue->isEmpty()) {
		Process p(queue->Dequeue());
		if (p.time <= quantum) { // 終了処理
			total_time += p.time;
			print(p.name);
			print(" ");
			println(total_time);
		} else { // ラウンドロビン
			p.time -= quantum;
			total_time += quantum;
			queue->Enqueue(p);
		}
	}
	return;
}

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

	int size = read();
	int quantum = read();
	ProcessScheduler(size, quantum);

	return 0;
}



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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	int a, b; cin >> a >> b;

	int a_card[6000];
	int b_card[6000];

	int ans = 0;

	for (int i = 0;i < a;i++){
		cin >> a_card[i];
	}

	for (int i = 0;i < b;i++){
		cin >> b_card[i];
	}

	for (int i = 0;i < b;i++){
		int a_idx = 0;
		int b_idx = i;
		while(b_idx < b){
			int now = b_card[b_idx];
			while(a_idx < a &&  a_card[a_idx] != now) a_idx++;
			if(a_idx == a) break;
			b_idx++;
			a_idx++;
		}
		ans = max(ans,b_idx-i);
	}

	cout << ans << endl;

	return 0;

}



Measured memory_bytes: 3236
#include<bits/stdc++.h>
#define ll  long long int
#define db long double 
#define ull unsigned long long int
// #define mp make_pair
#define F first
#define S second
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
#define Nmax 1000005
// #define INF 10000000000000
#define MOD 1000000007
#define MAXN 200005
 
using namespace std;


int main()
{
        ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int tests=1;
    // cin>>tests;    
    while(tests--)
    {
    	ll a,b,c,d;
    	cin>>a>>b>>c>>d;
    	if(b<=0 && d<=0)
    	{
    		cout<<a*c;
    	}
    	else if(a>=0 && c>=0)
    	{
    		cout<<b*d;
    	}
    	// else if(a>=0 && d<=0)
    	// {
    	// 	if()
    	// }
    	else 
    	{
    		ll ans=LLONG_MIN;
    		if(a>=0 && d<=0)
    		{
    			if(a==0 || d==0) ans=0;
    		}
    		else if(b<=0 && c>=0)
    		{
    			if(c==0 || b==0) ans=0;
    		}
    		cout<<max(a*c,max(b*d,max(b*c,max(ans,d*a))));
    	}
    }

    return 0;
}
    

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
unordered_map<int,long long>unmap;
int num[200005];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n;
    long long ans=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>num[i];
        unmap[num[i]]++;
    }
    for(auto i=unmap.begin();i!=unmap.end();i++){
        ans += 1LL * (*i).second * ((*i).second-1)/2;
    }
    for(int i=1;i<=n;i++){
        cout<<ans-unmap[num[i]]+1<<endl;
    }
    return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll h,w;
  cin >> h >> w;

  ll c[10][10];
  REP(i, 10){
    REP(j, 10)
    cin >> c[i][j];
  }

  ll a[h][w];
  REP(i, h){
    REP(j, w)
    cin >> a[i][j];
  }


  REP(k, 10){
    REP(i, 10){
      REP(j, 10)
        c[i][j] = min(c[i][k]+c[k][j], c[i][j]);
    }
  }

  ll ans = 0;
  REP(i, h){
    REP(j, w){
      if(a[i][j] == -1)
        continue;
      ans += c[a[i][j]][1];
    }
  }

  cout << ans << endl;
    
  
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
    static int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        String[][] table = new String[x + 2][y + 2];
        for (String[] t : table) {
            Arrays.fill(t, "#");
        }
        for (int i = 1; i <= x; i++) {
            String str = sc.next();
            for (int j = 1; j <= y; j++) {
                table[i][j] = String.valueOf(str.charAt(j - 1));
            }
        }
        
        int[][] dp = new int[x + 2][y + 2];
        dp[1][1] = 1;
      
        for (int i = 1; i <= x; i++) {
            for (int j = 1; j <= y; j++) {
                if (i == 1 && j == 1) continue;
                if (table[i][j].equals("#")) continue;
                
                boolean upToDown = table[i - 1][j].equals(".");
                boolean leftToRight = table[i][j - 1].equals(".");
                
                if (upToDown && leftToRight) {
                    dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
                } else if (upToDown) {
                    dp[i][j] = dp[i - 1][j];
                } else if (leftToRight) {
                    dp[i][j] = dp[i][j - 1];
                } else {
                    table[i][j] = "#";
                    if (i == x && j == y) {
                        dp[i][j] = 0;
                    }
                }
            }
        }
        
        System.out.println(dp[x][y]);
    }
}

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    LL N, M;
    cin >> N >> M;
    if(N == 1 || M == 1) {
        if(N*M == 1) {
            cout << 1 << endl;
        }else{
            cout << N*M - 2 << endl;
        }
    }else{
        cout << (N - 2)*(M - 2) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N,W,H;
	scanf("%d%d%d" ,&W,&H,&N);
	if(H<W){
		printf("%d",(N+W-1)/W);
		
		
	}else{
		printf("%d",(N+H-1)/H);
		
	}
	

}




Measured memory_bytes: 3816
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 	3.14159265358979323846

unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans2=999999;
    REP(i,n){
      int a;
      cin >> a;
      int ans=0;
      while(!(a%2)){
        a/=2;
        ans++;
      }
      ans2=min(ans,ans2);
    }
    cout << ans2 << endl;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  int a[1000000], b[1000000];

  for (int i = 0; i < n + 1; ++i) {
    cin >> a[i];
  }

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

  long c = 0;
  for (int i = 0; i < n; ++i) {
    int left = min(a[i], b[i]);
    c += left;
    a[i] -= left;
    b[i] -= left;

    int right = min(a[i + 1], b[i]);
    c += right;
    a[i + 1] -= right;
    b[i] -= right;
  }

  cout << c << endl;
}

Measured memory_bytes: 6400
#if 0

#endif

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

priority_queue<int> PQ;
int main() {
  string s;
  while (cin >> s && s != "end") {
    if (s == "insert") {
      int n; cin >> n;
      PQ.push(n);
    } else {
      cout << PQ.top() << endl;
      PQ.pop();
    }
  }
}



Measured memory_bytes: 6996
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0;i < n;++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define print(a) cout << a << endl;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
inline int newline() { putchar('\n'); return 0; }

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

    vector<ll> list(n, 0);
    rep(n - 1) {
        ll a;
        cin >> a;

        a--;

        list[a]++;
    }

    rep2(i, n) print(list[i]);
    return 0;
}

Measured memory_bytes: 4848
#include<stdio.h>
int main(){
  int a,b,c,count;
  while(1){
    if(scanf("%d%d",&a,&b)==EOF)break;
    count=0;
    c=a+b;
    while(c!=0){
      c=c/10;
  
	count++;
    } 
    printf("%d\n",count);
  }  
  return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define pi pair<ll,ll>
#define endl "\n"
#define MAXN 200005
using namespace std;

ll n,k,cnt,mod=1e9+7;
ll fr[MAXN], bk[MAXN];

void solve()
{
    cin>>n>>k;
    for(ll i=1;i<=n;i++) fr[i]=fr[i-1]+i;
    for(ll i=n;i>=0;i--) bk[i]=bk[i+1]+i;
 //    for(ll i=0;i<=n;i++) cout<<fr[i]<<" ";
 //    cout<<endl;
	// for(ll i=0;i<=n;i++) cout<<bk[i]<<" ";
 //    cout<<endl;
    for(ll i=k;i<=n+1;i++)
    {
    	ll minn=fr[i-1];
    	ll maxx=bk[n-i+1];
    	// cout<<minn<<" "<<maxx<<endl;
    	cnt=(cnt+(maxx-minn+1+mod)%mod)%mod;
    }
    cout<<cnt%mod<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    solve();
}


Measured memory_bytes: 6772
fun main(args:Array<String>?): Unit {
    val stations = (('A' .. 'Z') + ('a' .. 'z')).toCharArray()
    while(true){
        val n = readLine()!!.trim().toInt()
        if (n == 0) return
        val key = readLine()!!.trim().split(' ').map(String::toInt).toIntArray()
        val word = readLine()!!.trim().toCharArray()
        for (i in word.indices){
            word[i] = stations[(lowerBound(stations, word[i]) - key[i % key.size] + stations.size) % stations.size]
        }
        println(word.joinToString(""))
    }
}
fun lowerBound(array: CharArray, target: Char): Int {
    var left = 0
    var right = array.size
    while(left < right){
        val mid = (left + right) / 2
        if (array[mid] < target){
            left = mid + 1
        }else{
            right = mid
        }
    }
    return right
}


Measured memory_bytes: 33160
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }



signed main(){

    string S; cin >> S;
    string T = S;
    REVERSE(T);
    REP(i, T.size()){
        if(T[i] == 'b') T[i] = 'd';
        else if(T[i] == 'd') T[i] = 'b';
        else if(T[i] == 'p') T[i] = 'q';
        else if(T[i] == 'q') T[i] = 'p';
    }
    if(S == T) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 512
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 10000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

struct edge{ll from, to, cost;};
struct graph{
  ll V;
  vector<ll> d;
  vector<edge> es;
  graph(ll n){
    init(n);
  }
  void init(ll n){
    V = n;
    d.resize(V);
    REP(i,V){
      d[i] = INF;
    }
  }
  void add_edge(ll from, ll to, ll cost){
    edge e;
    e.from = from, e.to = to, e.cost = cost;
    es.push_back(e);
  }
  void bellman_ford(ll s){
    REP(i,V) d[i] = INF;
    d[s] = 0;
    REP(i,V-1){
      bool update = false;
      for(auto e:es){
        if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){
          d[e.to] = d[e.from] + e.cost;
          update = true;
        }
      }
      if(!update) break;
    }
  }
  bool negative_loop(ll gl){
    REP(i,V) d[i] = 0;
    REP(i,V){
      for(auto e:es){
        if(d[e.to]>d[e.from]+e.cost){
          d[e.to] = d[e.from]+e.cost;
          if(i==V-1&&e.to==gl) return true;
        }
      }
    }
    return false;
  }
};

int main(){
  ll n,m;
  cin >> n >> m;
  graph g(n);
  REP(i,m){
    ll a, b,c;
    cin >> a >> b >> c;
    g.add_edge(a-1,b-1,-c);
  }
  if(g.negative_loop(n-1)){
    cout << "inf" << endl;
  }else{
    g.bellman_ford(0);
    cout << -g.d[n-1] << endl;
  }
  return 0;
}


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

const int maxl=3e5+10;

int n,m,cas,k,cnt,tot,ans;
int a[maxl],b[maxl];
char s[maxl];
bool in[maxl]; 

inline void prework()
{
	int x;
	scanf("%d",&x);
	if(x<=599)
		puts("8");
	else if(x<=799)
		puts("7");
	else if(x<=999)
		puts("6");
	else if(x<=1199)
		puts("5");
	else if(x<=1399)
		puts("4");
	else if(x<=1599)
		puts("3");
	else if(x<=1799)
		puts("2");
	else
		puts("1");
} 

inline void mainwork()
{
	
}

inline void print()
{
	
}

int main()
{
	int t=1;
	//scanf("%d",&t);
	for(cas=1;cas<=t;cas++)
	{
		prework();
		mainwork();
		print();
	}
	return 0;
}

Measured memory_bytes: 3768
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var xkd = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var x = xkd[0];
        var k = xkd[1];
        var d = xkd[2];
        x *= Sign(x);
        var need = x / d;
        if (k < need)
        {
            Console.WriteLine(x - k * d);
            return;
        }
        x -= need * d;
        k -= need;

        Console.WriteLine(k % 2 == 0 ? x : d - x);
    }
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  sort(d.begin(), d.end());
  int ans = 0;
  for (int k = 0; k < 100001; k++) {
    int l = lower_bound(d.begin(), d.end(), k) - d.begin();
    if (l == n / 2) ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
    static Scanner sc = new Scanner(System.in);
	static final int MOD = 1000000007;
	static long[] f = null;
	static long[] fInverse = null;

    public static void main(String[] args) {
        int n = Integer.parseInt(sc.next());
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        f = new long[b + 1];
        fInverse = new long[b + 1];
        for(int i = 1; i <= b; ++i) {
            f[i] = (i == 1) ? 1 : f[i - 1] * i % MOD;
            fInverse[i] = calcModInv(f[i]);
        }

        long ans = pow(2, n) - 1L - comb(n, a) - comb(n, b);
        while(ans < 0L) {
            ans += MOD;
        }
        System.out.println(ans);
    }

    static long comb(int n, int r) {
        long perm = 1L;
        for(int i = n; i > n - r; --i) {
            perm = perm * i % MOD;
        }
        return perm * fInverse[r] % MOD;
    }
	
	static long calcModInv(long n) {
		long[] s = new long[2];
		solveEquation(n, MOD, s);
		return (s[0] >= 0) ? s[0] : s[0] + MOD;
	}
	
	static void solveEquation(long a, long b, long[] res) {
		if(a < b) solveEquation(b, a, res);		
		if(b == 0) {
			res[0] = 1;
			res[1] = 0;
			return;
		}		
		solveEquation(b, a % b, res);
		long tmp = res[0] % MOD;
		res[0] = res[1] % MOD;
		res[1] = tmp - a / b % MOD * res[1] % MOD;
    }
    
    static long pow(long a, long x) {
        if(x == 0L) {
            return 1L;
        }

        long t = pow(a, x / 2L);
        if(x % 2L == 0) {
            return t * t % MOD;
        } else {
            return t * t % MOD * a % MOD;
        }
    }

    static boolean isPrime(long n) {
        for(long t = 2L; t * t <= n; t += (t == 2L) ? 1L : 2L) {
            if(n % t == 0L) {
                return false;
            }
        }
        return true;
    }
}

Measured memory_bytes: 32456
#include <iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<limits.h>

#define MOD 1000000007


using namespace std;

long long int modpow(long long int a, int n) {

	if (n == 0)return 1;
	if (n == 1) return a;

	long long int wk = modpow(a, n / 2);

	long long int ret = 0;
	if (n % 2 == 0) {
		ret = 1;
	}
	else {
		ret = a;
	}

	return (((ret * wk) % MOD) * wk) % MOD;

}

long long int gcd(long long int a, long long int b) {
	long long int tmp;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	long long int r = a % b;

	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

long long int lcm(long long int a, long long int b) {

	long long int wk_int;

	wk_int = (a * b) % MOD;
	
	long long int ret;

	ret = (wk_int * modpow(gcd(a, b), MOD - 2)) % MOD;

	return ret;

}

bool isPrime(int n) {
	if (n == 1)return false;
	if (n == 2)return true;

	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}

	return true;
}








int main()
{
	
	int n, k;

	cin >> n >> k;

	double winrate;
	double ans = 0;
	int wk = 0;
	for (int i = 1; i <= n; i++) {
		wk = i;
		winrate = 1.0;

		while (wk < k) {
			wk *= 2;
			winrate /= 2.0;
		}

		ans += winrate / (double)n;
	}

	printf("%.10lf\n", ans);


	return 0;

}



Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int a[10000], b[10000], n, m, l, i, j, k;
long long c;
	scanf("%d %d %d", &n, &m, &l);
	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++)
			scanf("%d", a + i * m + j);
	for (i = 0; i < m; i++)
		for (j = 0; j < l; j++)
			scanf("%d", b + i * l + j);

	for (i = 0; i < n; i++)
		for (j = 0; j < l; j++)
		{
			c = 0;
			for (k = 0; k < m; k++)
				c += a[i * m + k] * b[k * l + j];
			printf("%ld", c);
			if (j != l - 1)
				printf(" ");
			else
				printf("\n");
		}

	return 0;
				
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i,j,n) for(int i=j;i<=n;i++)
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b;
    cin>>a>>b;
    if(a%500<=b)
      cout<<"Yes";
    else
     cout<<"No";
    
}   
    
    
     

     
   





Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a[200005] = {}, b = mod, z = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if (a[i] < b) b = a[i], z++;
    }
    cout << z;
}


Measured memory_bytes: 4400
from math import ceil
from itertools import product

D,G=map(int,input().split())
pc=[list(map(int,input().split())) for _ in range(D)]

def calc(P):
  count = 0
  g = G
  for i in range(D):
    p,c = pc[-1-i]
    if P[-1-i]==1:
      count += p
      g -= (D-i)*100*p+c
    if g<=0:
      return count
  for i in range(D):
    p,c = pc[-1-i]
    if P[-1-i]==0:
      tmp = min(p-1,ceil(g/((D-i)*100)))
      count += tmp
      g -= (D-i)*100*tmp
    if g<=0:
      return count
  return -1

MIN=10**9
for P in product(range(2),repeat=D):
  tmp = calc(P)
  if tmp != -1 and tmp < MIN: MIN=tmp
    
print(MIN)

Measured memory_bytes: 9252