akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(),(u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

const int inf = 1e9;
const int N = 2e5 + 10;  // limit for array size
int n;  // array size
PII t[2 * N][2];

void modify(int p, int value, bool sel) {  // set value at position p
	int pos = p;
	for (t[p += n][sel] = MP(value, pos); p > 1; p >>= 1) t[p >> 1][sel] = min(t[p][sel], t[p ^ 1][sel]);
}

PII query(int l, int r, bool sel) {  // min on interval [l, r)
	PII res = MP(inf, n);
	for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
		if (l & 1) res = min(res, t[l++][sel]);
		if (r & 1) res = min(res, t[--r][sel]);
	}
	return res;
}

vector <int> g[N];

int id;

PII M[N];

int go(int p, int k)
{
	if (p >= k)
		return -1;

	auto q = query(p, k, p & 1);

	vector < vector<int> > V;

	auto pom = query(q.second, k, 1 - (p & 1));

	int myid = id++;

	M[myid] = MP(q.first, pom.first);

	int v = go(p, q.second);
	if(v != -1)
		g[myid].push_back(v);

	v = go(q.second + 1, pom.second);
	if(v != -1)
		g[myid].push_back(v);

	v = go(pom.second + 1, k);
	if (v != -1)
		g[myid].push_back(v);

	return myid;
}

int inDeg[N];

int main()
{
	scanf("%d", &n);

	REP(i, 2 * n + 1)
		t[i][0] = t[i][1] = MP(inf, i);

	REP(i, n)
	{
		int p;
		scanf("%d", &p);
		if (i & 1)
		{
			modify(i, p, 1);
			modify(i, inf, 0);
		}
		else
		{
			modify(i, inf, 1);
			modify(i, p, 0);
		}
	}

	go(0, n);

	// wylicz indeg
	REP(i, n / 2)
		for (int nr : g[i])
			inDeg[nr]++;

	set < pair<PII, PII> > S;

	REP(i, n / 2)
		S.insert(MP(MP(inDeg[i], M[i].first), MP(M[i].second, i)));

	// sortuj topologicznie i wypisuj
	while (!S.empty())
	{
		auto p = *S.begin(); S.erase(p);

		printf("%d %d ", p.first.second, p.second.first);

		for (int nr : g[p.second.second])
		{
			S.erase(MP(MP(inDeg[nr], M[nr].first), MP(M[nr].second, nr)));
			inDeg[nr]--;
			S.insert(MP(MP(inDeg[nr], M[nr].first), MP(M[nr].second, nr)));
		}
	}

	printf("\n");

	return 0;
}

Measured memory_bytes: 31104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n;
  cin >> n;
  vec l(n);
  for(ll i=0;i<n;i++) {
    cin >> l[i];
  }
  sort(l.rbegin(),l.rend());
  ll sum=0;
  for(ll i=1;i<n;i++) {
    sum+=l[i];
  }
  if(sum>l[0]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;

int main()
{
    int count=0;
    string S,T;
    cin>>S>>T;
    for(int i=0;i< S.length();i++)
    {
        if(S[i]!=T[i])
        {
            count++;
        }
    }
    cout<<count;
    return 0;
}


Measured memory_bytes: 3908
#include "bits/stdc++.h"

#define ld long double

using namespace std;

const ld PI = 3.14159265358;

ld a, b, h, m;
int main(){
    cin >> a >> b >> h >> m;
    ld r1 = a;
    ld t1 = (h + m/60)/12 * 2 * PI;
    ld r2 = b;
    ld t2 = (m/60) * 2 * PI;
    ld x1 = r1 * cos(t1);
    ld y1 = r1 * sin(t1);
    ld x2 = r2 * cos(t2);
    ld y2 = r2 * sin(t2);
    cout << setprecision(10) << fixed;
    cout << sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
    return 0;
}

Measured memory_bytes: 4156
using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var atr = ReadDoubles();
            var a = atr[0];
            var t = atr[1];
            var r = atr[2];

            WriteLine(r / (a / t));
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}



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

public static class Solution
{
    static long GetMax(List<long> list, long K)
    {
        var N = list.Count;
        var acc = new long[N * 2 + 1];
        for (int i = 0; i < N; i++)
        {
            acc[i + 1] = acc[i] + list[i];
        }
        for (int i = 0; i < N; i++)
        {
            acc[i + N + 1] = acc[i + N] + list[i];
        }

        long score = 0;
        var cycleScore = acc[N];
        if (cycleScore > 0)
        {
            var m = K / N;
            if (K % N == 0)
            {
                m--;
            }
            score += cycleScore * m;
            K -= m * N;
        }
        if (K > 0)
        {
            long max = long.MinValue;
            for (int l = 0; l < N; l++)
            {
                for (int r = l + 1; r < N * 2 && r - l <= K; r++)
                {
                    var sum = acc[r] - acc[l];
                    max = Math.Max(max, sum);
                }
            }
            score += max;
        }
        return score;
    }

    static long Solve(int N, long K, int[] P, long[] C)
    {
        var seqs = new List<List<long>>();
        var visited = new bool[N];
        for (int i = 0; i < N; i++)
        {
            if (visited[i])
            {
                continue;
            }

            var list = new List<long>();
            var cur = i;
            while (!visited[cur])
            {
                visited[cur] = true;
                list.Add(C[cur]);
                cur = P[cur];
            }
            seqs.Add(list);
        }

        var max = seqs.Max(s => GetMax(s, K));
        return max;
    }

    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var N = (int)vals[0];
        var K = vals[1];
        var P = Console.ReadLine().Split(' ').Select(x => int.Parse(x) - 1).ToArray();
        var C = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

        var max = Solve(N, K, P, C);
        Console.WriteLine(max);
    }
}

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

int main()
{
    int S, h, m, s;
    cin >> S;

    h = S / 3600;
    S = S - (h * 3600);
    m = S / 60;
    S = S - (m * 60);
    s = S;

    std::cout << h << ":" << m << ":" << s << std::endl;
    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define rep(i,a,n) for (register int i=a;i<=n;i++)
#define per(i,a,n) for (register int i=n;i>=a;i--)
#define FOR(i,a,n,x) for (register int i=a;i<=n;i+=x)
#define ROF(i,a,n,x) for (register int i=n;i>=a;i-=x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define VI vector<int>
#define ll long long
#define ull unsigned long long
#define lowbit(x) ((x)&(-x))
#define mem(i, a) memset(i, a, sizeof(i))
#define sqr(x) ((x)*(x))
#define ls (p << 1)
#define rs (p << 1 | 1)
using namespace std;

template <typename T>

inline void read(T &X) {
  X = 0; char ch = 0; T op = 1;
  for(; ch > '9' || ch < '0'; ch = getchar())
    if(ch == '-') op = -1;
  for(; ch >= '0' && ch <= '9'; ch = getchar())
    X = (X << 3) + (X << 1) + ch - 48;
  X *= op;
}

const int INF = 0x3f3f3f3f;
const int MAXN =  + 5;

int a, b, c;

int main() {
#ifdef WiLe
  freopen ("input.txt", "rt", stdin);
#endif
  scanf("%d %d %d", &a, &b, &c);
  printf("%d %d %d\n", c, a, b);


#ifdef WiLe
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}
/*
# author : WiLe
# date : 2020/04/17
*/

Measured memory_bytes: 256
n, c = gets.to_s.split.map{|t| t.to_i }

d = [[0] * (c+1) ] + Array.new(c){ [0] + gets.to_s.split.map{|t| t.to_i } }
grid = Array.new(n){ gets.to_s.split.map{|t| t.to_i } }

counters = Array.new(3){ Array.new(c+1){ 0 } }

# O(N^2)
n.times do |i|
  n.times do |j|
    counters[(i+j)%3][grid[i][j]] += 1
  end
end

# O(cP3)
ans = n * n * 1000
(1..c).to_a.permutation(3) do |colors|
    
  cost = 0
  3.times do |i|
    color = colors[i]
    counter = counters[i]
    
    counter.each_with_index do |cnt, col|
      
      next if col == color
      cost += d[col][color] * cnt
    end
  end
  
  ans = cost if ans > cost
end

puts ans

Measured memory_bytes: 4476
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>
#include <set>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int x, n;
	std::cin >> x >> n;
	int l = x, r = x;
	std::set<int> st;
	while(n--) {
		int lol;
		std::cin >> lol;
		st.insert(lol);
	}
	while(1) {
		if(!st.count(l)) {
			std::cout << l << '\n';
			return 0;
		}
		l--;
		if(!st.count(r)) {
			std::cout << r << '\n';
			return 0;
		}
		r++;
	}
}

Measured memory_bytes: 3648
function Main(input) {
  input = input.split("\n");
  var H = parseInt(input[0].split(" ")[0]);
  var W = parseInt(input[0].split(" ")[1]);
  var mod = Math.pow(10,9)+7;
  input.shift();
  input.splice(H,input.length);
  var S = input.map(i => i.split(""));
  var edge = new Array();
  var id=0;
  for(var i=0;i<H;i++){
    for(var j=0;j<W;j++){
      if(S[i][j]=="."){
        if(i!=H-1){
          if(S[i+1][j]=="."){
            edge.push([id,id+W]);
          }
        }
        if(j!=W-1){
        if(S[i][j+1]=="."){
            edge.push([id,id+1]);
          }
        }
      }
      id++;
    }
  }
  var map = new Array(H*W);
  for(var i=0;i<H*W;i++){
    var mapsub = new Array(H*W).fill(mod);
    mapsub[i]=0;
    map[i]=mapsub;
  }
  for(var i=0;i<edge.length;i++){
    map[edge[i][0]][edge[i][1]]=1;
    map[edge[i][1]][edge[i][0]]=1;
  }
  var ans =0;
  for(var k=0;k<H*W;k++){
    for(var i=0;i<H*W;i++){
      for(var j=0;j<H*W;j++){
        map[i][j]=Math.min(map[i][k]+map[k][j],map[i][j]);
      }
    }
  }
  for(var i=0;i<H*W;i++){
    for(var j=0;j<H*W;j++){
      if(map[i][j]<mod){
        ans=Math.max(ans,map[i][j]);
      }
    }
  }

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 8984
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll N,ans=0,ans2=0,sum=0,sum2=0;

int main(){
    cin>>N;
    ll A[N];
    rep(i,N){
        cin>>A[i];
    }
    //奇数が正
    rep(i,N){
        sum+=A[i];
        sum2+=A[i];
        if(i%2==0){
            if(sum<=0){
                ans+=abs(sum)+1;
                sum=1;
            }
        }
        else{
            if(sum>=0){
                ans+=abs(sum)+1;
                sum=-1;
            }
        }
        if(i%2==1){
            if(sum2<=0){
                ans2+=abs(sum2)+1;
                sum2=1;
            }
        }
        else{
            if(sum2>=0){
                ans2+=abs(sum2)+1;
                sum2=-1;
            }
        }
        // printf("%lld : %lld\n",ans,ans2);
    }
    out(min(ans,ans2));
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  vector<int> P(200010);
 
  cin >> N;
  for(int i=0; i<N; i++) cin >> P[i];
  
  int m = 9999999; int ans = 0;
  for(int i=0; i<N; i++){
    if(P[i] <= m){
        ans++;
        m = P[i];
    }
  }
 
  cout << ans << endl;
}

Measured memory_bytes: 1152
/*
 * ID: adityaa
 * LANG: C++
 */
#include <bits/stdc++.h>
using namespace std;

#define fio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mem(x, y) memset(x, y, sizeof x);
#define fi first
#define se second
#define pb push_back
#define pii pair<int , int>
#define asdfg y1
#define int long long
#define double long double
#define endl '\n'
#define PI 3.14159265359

/*-----------------------------------------------------------------------*/

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

/*-----------------------------------------------------------------------*/

// check base cases n = 0 , n = 1
// max / min questions - check for binary search
const int maxn = (int) 1e6 + 6;
const double EPS = 1e-9;
const int INF = (int)1e18 + 18;
const int mod = (int) 998244353;
int n , k , height[maxn] , dp[maxn];

signed main() {
    
    fio;
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> height[i];
        dp[i] = INF;
    }
    
    dp[1] = 0;
    for(int i = 2; i <= n; i++){
        for(int j = 1; j <= min(i - 1 , k); j++){
            dp[i] = min(dp[i] , dp[i - j] + abs(height[i] - height[i - j]));
        }
    }
    
    cout << dp[n] << endl;
    
    
    
    
    return 0;
    
}


Measured memory_bytes: 5120
#最大増加部分列（Longest Increasing Subsequence）
def LIS(L):
  """数列L→最大増加部分列の長さ
  計算量はNlogN"""
  from bisect import bisect
  best=[]
  for i in L:
    pos=bisect(best,i)
    if len(best)<=pos:
      best.append(i)
    else:
      best[pos]=i
  return len(best)

import math 
x1,y1,x2,y2=map(int,input().split())
N=int(input())
W=abs(x2-x1)
H=abs(y2-y1)
xsgn=2*(x2>x1)-1
ysgn=2*(y2>y1)-1
XY=[]
for i in range(N):
  x,y=map(int,input().split())
  if (x-x1)*(x-x2)<=0 and (y-y1)*(y-y2)<=0:
    XY+=[[xsgn*(x-x1),ysgn*(y-y1)]]
N=len(XY)
short=20-5*math.pi
long=10*math.pi-20
straight=100*(W+H)

XY.sort()
Y = [y for x,y in XY]

fountain=LIS(Y)

if fountain<min(W,H)+1:
  print(straight-short*fountain)
else:
  print(straight-short*(fountain-1)+long)

Measured memory_bytes: 40184
// AtCoder178.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    //string s;
    //cin >> s;

    //int i = atoi(s.c_str());
    //if (i == 0) {
    //    cout << 1;
    //}
    //else {
    //    cout << 0;
    //}

    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(max(a * c, a * d), max(b * c, b * d));
    //cout << ans;


    return 0;
}



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

int N;
int X[505],Cnt[505],Num[505],Ans[505*505];

int main(){
	int i,j,k;
	scanf("%d",&N);
	for(i=1;i<=N;i++){
		scanf("%d",&X[i]);
		Ans[X[i]]=i;
	}
	for(i=1,j=0;i<=N*N;i++)
		if(Ans[i])
			Num[++j]=Ans[i];
	for(i=1;i<=N;i++)
		Cnt[i]=i-1;
	for(i=1;i<=N*N;i++)
		if(!Ans[i])
			for(j=1;j<=N;j++)
				if(Cnt[Num[j]]){
					Cnt[Ans[i]=Num[j]]--;
					break;
				}
	for(i=1;i<=N;i++)
		Cnt[i]=N-i;
	for(i=N*N;i;i--)
		if(!Ans[i])
			for(j=N;j;j--)
				if(Cnt[Num[j]]){
					Cnt[Ans[i]=Num[j]]--;
					break;
				}
	for(i=1;i<=N;i++)
		for(j=1,k=0;j<=N*N;j++){
			k+=(Ans[j]==i);
			if(k==i){
				if(j^X[i]){
					puts("No");
					return 0;
				}
				break;
			}
		}
	puts("Yes");
	for(i=1;i<=N*N;i++)
		printf("%d ",Ans[i]);
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <ctime>
#include <unordered_map>
#include <iomanip>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;

int N,to[200010][26],l[200010]; string s;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> s;
    N=s.length();

    int i,j;
    for (i=0; i<26; i++) to[N][i]=-1;
    for (i=N-1; i>=0; i--){
        for (j=0; j<26; j++)
            to[i][j]=to[i+1][j];

        to[i][s[i]-'a']=i;

        bool ok=1; int lmin=N;
        for (j=0; j<26; j++)
            if (to[i][j]==-1) ok=0;
            else lmin=min(lmin,l[to[i][j]+1]);

        if (ok) l[i]=1+lmin;
    }

    string ans;
    int len=l[0]+1,p=0;
    while (len){
        for (j=0; j<26; j++)
            if (to[p][j]==-1 || l[to[p][j]+1]<len-1){
                ans+=char('a'+j);
                len--;
                p=to[p][j]+1;
                break;
            }
    }

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


Measured memory_bytes: 21652
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define eps 1e-8

int A,B,C,D,E,F;
int dp[3005];

int main()
{
    scanf("%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F);
    int sum=0,sugar=0;
    for (int i=0;i<=30;i++)
    {
        for (int j=0;j<=30;j++)
        {
            if (i==0&&j==0) continue;
            int wat = 100*(i*A+j*B);
            if (wat>=F) break;

            int x = (i*A+j*B)*E;
            x=min(x,3000);
            memset(dp,0,sizeof(dp));
            dp[0]=1;
            for (int k=C;k<=x;k++)
                if (dp[k-C]) dp[k]=1;
            for (int k=D;k<=x;k++)
                if (dp[k-D]) dp[k]=1;

            for (int k=0;k<=F-wat;k++)
            {
                if (dp[k])
                {
                    if (k*sum>sugar*(wat+k)||sum==0)
                    {
                        sum=(k+wat);
                        sugar=k;
                    }
                }

            }
        }
    }
    printf("%d %d\n",sum,sugar);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vl A(N);
  REP(i, N) cin >> A[i];
  sort(ALL(A));
  ll now = 0;
  vl B(N + 1, 0);
  REP(i, N) { B[i + 1] = A[i] + B[i]; }
  ll ans = 0;
  for (ll i = N - 2; i >= 0; i--) {
    if (A[i + 1] <= B[i + 1] * 2)
      ans++;
    else
      break;
  }
  cout << ans + 1 << endl;
  return 0;
}


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

int main() {
    long long x, y;
    cin >> x >> y;
    if (y == x)
    {
        cout << -1 << endl;
        return 0;
    }
    if (x > y && x % y == 0)
    {
        cout << -1 << endl;
        return 0;
    }
    
    
    int Maxv = (int)1e9;
    for (int i = 1; i <= Maxv; i++)
    {
        long long a = x * i;
        if (a % y != 0)
        {
            cout << a << endl;
            return 0;
        }
        
    }
}

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

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
using P = pair<int,int>;
//Write From this Line

int main()
{
	int N, W;
	cin >> N >> W;
	vector<int> v(N), w(N);
	rep (i,N) cin >> v[i] >> w[i];

	vector<vector<ll>> dp(105, vector<ll> (100100,0));

	for(int i = 1; i <= N; i++){
		int weight = w[i-1];
		int value = v[i-1];
		rep(j,weight+1) dp[i][j] = dp[i-1][j];
		for(int j = 0; j+weight <= W; j++){
			dp[i][j+weight] = max(dp[i-1][j+weight], dp[i][j]+value);
		}
	}
	cout << dp[N][W] << endl;
}



Measured memory_bytes: 86060
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define FORE(x,arr) for(auto &x:arr)
#define REP(v,n) FOR(v,0,n)
#define ALL(c) begin(c),end(c)
const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0};
const int INF = 1e9;
template<class T,class U>ostream&operator<<(ostream &os,const pair<T,U> &p){
    os<<"("<<p.first<<","<<p.second<<")";return os;}
template<class T>ostream&operator<<(ostream &os,const vector<T> &v){
    ITR(i,v)os<<*i<<(i==end(v)-1?"":" ");return os;}
//-----------------------------------------------------------

struct node {
    int i;
    int from;           // ??\???????????°
    vector<node*> to;   // ??\?¶????????????????
};
vector<node*> topological_sort(vector<node> &g) {
    vector<node*> sorted;
    queue<node*> q;
    FORE(nd,g) if(nd.from==0) q.push(&nd);
    while(!q.empty()) {
        node* v=q.front(); q.pop();
        sorted.push_back(v);
        FORE(u,v->to) {
            (u->from)--;
            if((u->from)==0) {
                q.push(u);
            }
        }
    }
    return sorted;
}

int main(int argc, char const *argv[]) {
    int V,E;
    cin>>V>>E;
    vector<node> g(V);
    REP(i,V) g[i].i=i;

    REP(i,E) {
        int a,b;
        cin>>a>>b;
        g[a].to.push_back(&g[b]);
        g[b].from++;
    }

    vector<node*> ans = topological_sort(g);
    REP(i,V) {
        cout<<ans[i]->i<<endl;
    }
    return 0;
}

Measured memory_bytes: 4048
#include<bits/stdc++.h>
using namespace std;
 
const int N = 2e5 + 5;
//const int mod = 1e9 + 7;
typedef long long ll;
#define mp make_pair
 
char c;
string s;
ll n,i,ans;
map < pair < int , int > , int > M;
 
 
struct hashh{
    ll t,a,b,x,bol,X,mod;
    hashh() { t=b=x=X=mod=0; a=bol=1; }
    void f(){ 
        for(t=X,i=mod-2; i ; i>>=1){
            if(i & 1) bol = bol*t % mod;
            t = t*t % mod;
        }
        for(i=n-1; i>=0 ;i--){
            c = s[i];
            if(c == '-') x--;
            if(c == '+') x++;
            if(c == '>') x *= X;
            if(c == '<') x *= bol;
            x = (x % mod + mod) % mod;
        }
    }       
                
    void g(){               
        if(c == '+') b -= a;                
        if(c == '-') b += a;                            
        if(c == '>') a *= bol;                                  
        if(c == '<') a *= X;        
        a = (a % mod + mod) % mod;                  
        b = (b % mod + mod) % mod;                              
        t = (a*x + b) % mod;                                                
    }                                                                                   
};                                                                                                  
                                                                                                                
int main(){                                                                                                             
    cin >> n >> s;                      
                                                                                                                            
    hashh h1,h2;    
    h1.mod = 1e9+7;  h1.X=10000003; h1.f();
    h2.mod = 1e9+9;  h2.X=1000007; h2.f();
                                                
    M[mp(0,0)] = 1;                                     
    for(i=n-1; i>=0 ;i--){                                      
        c = s[i];                                                       
        h1.g(); h2.g();                                                         
                                                                                    
        ans += M[mp(h1.t,h2.t)];                                                    
        M[mp(h1.b,h2.b)]++;                                                             
    }
        
    cout << ans;
    return 0;
}    

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

int main(){
	int m,f,r;
	
	while (1){
		cin >> m >> f >> r ;
		if (m==-1 && f==-1 && r==-1) break;
		int s=m+f;
		if (m==-1 || f==-1) cout << "F" << endl;
		else if (s >=80) cout << "A" << endl;
		else if (65<=s && s<80) cout << "B" << endl;
		else if (50<=s && s<65) cout << "C" << endl;
		else if (30<=s && s<50 && r>=50) cout << "C" << endl; 
		else if (30<=s && s<50 && r<50) cout << "D" << endl;
		else if (s<30) cout << "F" << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout(val) cout << std::fixed << std::setprecision(20) << val;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };

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

  int n; cin >> n;
  vector<ll> a(n), b(n);
  rep(i, n) {
    cin >> a[i] >> b[i];
  }

  ll ans = 0;
  for(int i = n - 1; i >= 0; --i) {
    ans += ((ans + a[i]) % b[i]) ? b[i] - ((ans + a[i]) % b[i]) : 0;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
class Program
    {
    	static void Main(string[] args)
    	{
            string[] s1 = Console.ReadLine().Split(' ');
            int n = int.Parse(s1[0]), m = int.Parse(s1[1]);
            int[] s = new int[n];
            string[] s2 = Console.ReadLine().Split(' ');
            for (int i=0; i<n; i++) s[i] = int.Parse(s2[i]);
            int[] t = new int[m];
            string[] s3 = Console.ReadLine().Split(' ');
            for (int i=0; i<m; i++) t[i] = int.Parse(s3[i]);

            int mod = 1000000007;

            int[,] dp = new int[n+1, m+1];
            for (int i=0; i<=n; i++) dp[i, 0] = 1;
            for (int i=0; i<=m; i++) dp[0, i] = 1;
            for (int i=1; i<=n; i++)
            {
                for (int j=1; j<=m; j++)
                {
                    if (s[i-1] == t[j-1]) dp[i, j] = dp[i-1, j] + dp[i, j-1];
                    else dp[i, j] = dp[i-1, j] + dp[i, j-1] - dp[i-1, j-1];
                    if (dp[i, j] < 0) dp[i, j] += mod;
                    else dp[i, j] %= mod;
                }
            }
            Console.WriteLine(dp[n, m]);
        }
    }

Measured memory_bytes: 28384
#include<iostream>
#include<iomanip>
#include<cmath>
#include<tuple>
#include<queue>
#include<algorithm>
 // Initialize 
int const MAXN = 50;
double const INF = 1e9;
double const eps = 5e-7;
int x[MAXN], y[MAXN], N;
 
double min_possible(double cx, double cy, double r) {
  double res = 0.0;
  for(int i = 0; i < N; ++i) {
    double dx = x[i] - cx, dy = y[i] - cy;
    dx = std::max(std::fabs(dx) - r, 0.0);
    dy = std::max(std::fabs(dy) - r, 0.0);
    res = std::max(res, dx*dx + dy*dy);
  }
  return std::sqrt(res);
}
 
double calc(double cx, double cy) {
  double res = 0.0;
  for(int i = 0; i < N; ++i) {
    double dx = x[i] - cx, dy = y[i] - cy;
    res = std::max(res, dx*dx + dy*dy);
  }
  return std::sqrt(res);
}
 
int main() {
  std::cin >> N;
  for(int i = 0; i < N; ++i) std::cin >> x[i] >> y[i];
  
  std::queue<std::tuple<double, double, double>> q;
  double ans = INF;
  q.emplace(500.0, 500.0, 500.0);
  while(q.size()>0) {
    double xx, yy, rr; 
    std::tie(xx, yy, rr) = q.front(); q.pop();
    double d = min_possible(xx, yy, rr);
    if(d >= ans - eps*std::max(d, 1.0)) continue; // cut-off no improve
    ans = std::min(ans, calc(xx, yy));
    for(double rx: {-0.5, 0.5}) for(double ry: {-0.5, 0.5}) {
      q.emplace(xx+rx*rr, yy+ry*rr, rr*0.5);
    }
  }
  std::cout << std::setprecision(10) << std::fixed << ans << std::endl;
  return 0;
}

Measured memory_bytes: 384
# 19-String-Finding_a_Word.py

# ?????????????´¢
# ??????????????? W ??¨?????? T ????????????????????????T ??????????????? W ?????°???????????????????????°?????????????????????????????????
# ?????? T ????????????????????????????????????????????§????????????????????????????????? Ti ??¨????????????
# ???????????? Ti ?????????????????? W ??¨??????????????????????????°??????????????????
# ???????????§????????¨?°???????????????\???????????????

# Constraints
# W????????????????????????10????¶????????????????
# T??????????????????????????????????????????1000????¶????????????????

# Input
# ?????????????????? W ????????????????????????
# ?¶???????????????°????????????????????£??????????????????????????????
# END_OF_TEXT ??¨??????????????????????????????????????????????????????

# Output
# ?????? W ?????°???????????????????????????

# Sample Input
# computer
# Nurtures computer scientists and highly-skilled computer engineers
# who will create and exploit "knowledge" for the new era.
# Provides an outstanding computer environment.
# END_OF_TEXT

# Sample Output
# 3
# Note

import re

count=0

w = input().lower()

while 1:
	string = input()
	if string=="END_OF_TEXT":
		break;

	for i in string.lower().split():
		count += w==i

print(count)

Measured memory_bytes: 7564
#include <stdio.h>
#include <string.h>

int main(void)
{
  char str[21];
  char after[21];
  int i;
  /* reset */
  memset(str, '\0', sizeof(str));
  memset(after, '\0', sizeof(after));

  if(fgets(str, sizeof(str), stdin) != NULL) 
  {
  //str[strlen(str)-1] = '\0';
    for (i=0; i < strlen(str); i++)
    {
      after[strlen(str)-1-i] = str[i];
    }
  }
  //gets(str);


  printf("%s\n", after);

  return 0;
}

Measured memory_bytes: 520
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

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

	if (N % 2 == 1) {
		cout << 0 << endl;
		return 0;
	}

	Int ans = 0;
	Int x5 = 5;
	while (x5 <= N) {
		ans += (N / x5) / 2;
		x5 *= 5;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
def c_traveling_plan(N, A):
    total = 0  # すべての観光スポットを順に回ったときの費用
    a = [0] + A + [0]  # 0から出発して最後に0に帰るためこうする(forループも楽)
    for i in range(N + 1):
        total += abs(a[i] - a[i + 1])
    ans = ''
    for i in range(1, N + 1):
        # a_{i-1}->a_i->a_{i+1} をつなぐ2つの経路の長さ(delta1)を引き、
        # 新しい経路の長さ(delta2)を足す
        delta1 = abs(a[i - 1] - a[i]) + abs(a[i] - a[i + 1])
        delta2 = abs(a[i - 1] - a[i + 1])
        ans += '{0}\n'.format(total - delta1 + delta2)
    return ans[:-1]
  
N = int(input())
A = [int(i) for i in input().split()]
print(c_traveling_plan(N, A))

Measured memory_bytes: 14164
a, b, k = map(int, input().split())
if b - a < k * 2:
    for i in range(a,b+1):
        print(i)
else:
    ans = []
    for i in range(a,a+k):
        if i < a+k: ans.append(i)
    for i in range(b-k+1, b+1):
        if i > b-k and i not in ans: ans.append(i)
    for i in ans: print(i)

Measured memory_bytes: 3060
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int N=100010;
int n,R,C,tp,x[N][2],y[N][2],stk[N],vis[N];
struct data{
	int x,y,idx;
	data(){}
	data(int a,int b,int c=0):x(a),y(b),idx(c){}
};
vector<data>v;
bool check(int x,int y){
	return (!x||x==R)||(!y||y==C);
}
int in(data a){
	if(!a.x)
		return 1;
	if(a.y==C)
		return 2;
	if(a.x==R)
		return 3;
	return 4;
}
bool cmp(data a,data b){
	if(!a.x&&!a.y)
		return 1;
	if(!b.x&&!b.y)
		return 0;
	if(!a.x&&!b.x)
		return a.y<b.y;
	if(a.x==R&&b.x==R)
		return a.y>b.y;
	if(!a.y&&!b.y)
		return a.x>b.x;
	if(a.y==C&&b.y==C)
		return a.x<b.x;
	return in(a)<in(b);
}
int main(){
	scanf("%d%d%d",&R,&C,&n);
	for(int i=1;i<=n;i++){
		int x1,y1,x2,y2;
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		if(check(x1,y1)&&check(x2,y2)){
			v.push_back(data(x1,y1,i));
			v.push_back(data(x2,y2,i));
		}
	}
	sort(v.begin(),v.end(),cmp);
	for(auto &i:v){
		if(!vis[i.idx]){
			stk[++tp]=i.idx;
			vis[i.idx]=1;
		}
		else{
			if(stk[tp]==i.idx)
				tp--;
			else{
				puts("NO");
				return 0;
			}
		}
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 4980
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy
from operator import itemgetter

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


N, K = na()
for i in range(K):
    print((cmb(K-1, i, mod) * cmb(N-K+1, N-K-i, mod)) % mod)

Measured memory_bytes: 12128
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int ans;
int N, M;
pair<int, char> pr[7];

int main(void) {
    cin >> N >> M;
    rep(i, 0, M) {
        int s; char ch;
      scanf("%d %c", &s, &ch);
        pr[i] = mp(s, ch);
    }
    rep(i, 0, 1000) {
        string str;
        str = to_string(i);
        if (str.size() != N) continue;
        bool ok = true;
        rep(i, 0, M) {
            //cout << pr[i].second << endl;
            //cout << str[pr[i].first-1] << endl;
            if (pr[i].second != str[pr[i].first-1]) ok = false;
        }
        if (ok) {
            printf("%d\n", i);
            return 0;
        }
    }
    
   

  
    printf("-1\n");

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	int x,y,sx,sy,cost;
};
int a[101]={};

int main() {

	int n;
	cin>>n;
	rep(i,n)cin>>a[i+1];

	int f=1;
	int t=0;

	while(f){
		f=0;
		for(int i=n; i>0; i--){
			if(a[i]<a[i-1]){
				t++;
				int x=a[i];
				a[i]=a[i-1];
				a[i-1]=x;
				f=1;
			}
		}
	}
	for(int i=1; i<n; i++)cout<<a[i]<<" ";

	cout<<a[n]<<endl;
	cout<<t<<endl;

	return 0;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main(){
    ios::sync_with_stdio(false);
    int N, M, C;
    cin >> N >> M >> C;
    vi B(M);
    for(int &i : B){
        cin >> i;
    }
    int ans=0;
    for(int j=0;j<N;j++){
        int s=0;
        for(int &b : B){
            int A;
            cin >> A;
            s += A*b;
        }
        if(s+C>0) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	static long[] s;
	static long[,] dp;
	static bool[,] visited;
	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		var sa = Input();
		var a = new long[n];
		for(int i = 0; i < n; i++)
		{
			a[i] = sa[i].ToLong();
		}
		
		s = new long[n+1];
		
		for(int i = 1; i <= n; i++)
		{
			s[i] = s[i - 1] + a[i - 1];
		}
		
		dp = new long[n+1,n+1];
		visited = new bool[n+1,n+1];
		Console.WriteLine(Solve(0, n-1));
	}
	
	private static long Solve(int l, int r)
	{
		if(r == l) return 0;
		
		if(visited[l, r]) return dp[l, r];
		
		int mid = (l + r) / 2;
		long min = DpInf;
		for(int c = l; c < r; c++)
			min = Math.Min(min, Solve(l, c) + Solve(c+1, r));
		dp[l, r] = min + (s[r+1] - s[l]);
		visited[l, r] = true;
		return dp[l, r];
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}


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

int main() {
  int N;
  int total = 0;
  cin >> N;

  for(int i=N;i;i--){
    int A;
    cin >> A;
    
    for(int j=0;;j++){
      if(A%2){
        total = i==N||j<total?j:total;
        break;
      }else{
        A/=2;
      }
    }
  }
  cout << total << endl;
}


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

int main(){
    int n,m;
    cin>>n>>m;
    int x[100000],d[100000];
    for(int i=0;i<m;i++){
        cin>>x[i];
    }
    if(n>=m){
        cout<<0<<endl;
        return 0;
    }
    sort(x,x+m);
    for(int i=0;i<m-1;i++){
        d[i]=x[i+1]-x[i];
    }
    sort(d,d+m-1,greater<int>());
    int ans=x[m-1]-x[0];
    for(int i=0;i<n-1;i++){
        ans-=d[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i) 
typedef long long ll;
using namespace std;

int main(){
  ll t1,t2; cin >> t1 >> t2;
  ll a1,a2; cin >> a1 >> a2;
  ll b1,b2; cin >> b1 >> b2;

  ll c1=t1*a1; ll d1=t1*b1;
  ll c2=t2*a2; ll d2=t2*b2;
  
  ll B1=max(c1,d1); ll B2=max(c2,d2);
  ll S1=min(c1,d1); ll S2=min(c2,d2);
  ll s1=B1-S1; ll s2=B2-S2;
  ll ans=0; ll cs=s1;
  
  if( ( (c1>d1) && (c2>d2) ) || ( (c1<d1) && (c2<d2) ) ) cout << 0 << endl;
  else{
  if(s1<s2){
    cs=s2-s1;
    ans+=(s1/cs)*2;
    s1=s1-((ans/2)*cs);
    if(s1==0) cout << ans << endl;
    else cout << ans+1 << endl;
  }
  else if(s1==s2) cout << "infinity" << endl;
  else cout << 0 << endl;
  }
 return 0;
}


Measured memory_bytes: 256
nh  = int(input())
m  = [int(i) for i in input().split()]
h  = [int(i) for i in input().split()]

h1 = sum(h)

for i in range(len(m)):
    if h[i-1] != 0 and i != 0:
        val = abs(m[i] - h[i-1])
        if m[i] > h[i-1]:
            m[i]  = val
            h[i-1]  = 0
        else:
            m[i]  = 0
            h[i-1]  = val        

    if m[i] != 0 and i < nh:
        val = abs(m[i] - h[i])
        if m[i] > h[i]:
            m[i]  = val
            h[i]  = 0
        else:
            m[i]  = 0
            h[i]  = val


print(h1 - sum(h))
            
        


Measured memory_bytes: 18624
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here
    vector<int> s(13);
    int c,n=0,m=0;
    cin>>c;
    for(int i=0;i<c;i++){
        int a;
        cin>>a;
        s[a/=400]++;
    }
    for(int i=0;i<13;i++){
        if(s[i]!=0 && i<=7){
            n++;
        }
        else if(s[i]!=0)m+=s[i];
    }
    cout<<n+(n==0)<<" "<<n+m<<endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

N = input()

primes = [False, False] + [True] * 100000

prime_ls = []

for i in range(100000):
    if primes[i]:
        prime_ls.append(i)
        for j in range(i * 2, 100000, i):
            primes[j] = False

primes = prime_ls[:1006]

ans = [[1] * 502 for i in range(502)]

for i in range(502):
    for j in range(502):
        if (i + j) % 2 == 0:
            pos1 = (i + j) / 2
            pos2 = 753 + (i - j) / 2
            ans[i][j] *= primes[pos1]
            ans[i][j] *= primes[pos2]

for i in range(1, 501):
    for j in range(1, 501):
        if (i + j) % 2 == 1:
            ans[i][j] *= ans[i - 1][j]
            ans[i][j] *= ans[i + 1][j]
            ans[i][j] *= ans[i][j - 1]
            ans[i][j] *= ans[i][j + 1]
            ans[i][j] = int(math.sqrt(ans[i][j])) + 1

for i in range(1, N + 1):
    print " ".join(map(str, ans[i][1:N+1]))


Measured memory_bytes: 44556
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:

*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 200010;
const int MAXK = 110;
const int MAXQ = 200010;


const int LOG_A = 60;
int n;
ll a[MAXN], basis[LOG_A];

void insertVector(ll mask) {
    FORE(i,LOG_A-1,0) {
        if (!(mask & (1LL << i))) continue;
        if (!basis[i]) {
            basis[i] = mask;
            return;
        }
        mask ^= basis[i];
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) cin >> a[i];
    
    ll xorSum = 0;
    FOR(i,1,n) xorSum ^= a[i];

    FORE(i,LOG_A-1,0)
        if (xorSum & (1LL << i)) {
            FOR(j,1,n)
                if (a[j] & (1LL << i)) a[j] -= (1LL << i);
        }

    FOR(i,1,n) insertVector(a[i]);

    ll maxXor = 0;
    FORE(i,LOG_A-1,0) {
        if (!basis[i]) continue;
        if (maxXor & (1LL << i)) continue;
        maxXor ^= basis[i];
    }
    cout << maxXor + (xorSum ^ maxXor);
    return 0;
}


Measured memory_bytes: 1024
use std::io::Read;
use std::str::SplitWhitespace;
use std::str::FromStr;

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

pub trait Parse<T> {
    fn parse(&mut self) -> T;
}

impl<'a, T> Parse<T> for SplitWhitespace<'a>
where
    T: FromStr,
{
    fn parse(&mut self) -> T {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let n: usize = iter.parse();
    let mut v: Vec<i64> = (0..n).map(|_| iter.parse()).collect();
    v.sort();
    let mut ans = 0;
    loop {
        if let Some(&f) = v.first() {
            ans = f;
            v.remove(0);
            if v.iter().all(|x| x % ans == 0) {
                break;
            }
        } else {
            break;
        }
        v = v.iter().map(|x| x % ans).filter(|&x| x > 0).collect();
        v.push(ans);
        v.sort();
    }

    println!("{}", ans);
}

Measured memory_bytes: 6396