akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define pq          priority_queue
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define inf         INT_MAX-100
#define vl          vector<ll>
#define vvl         vector<vector<ll>>
#define F           first
#define S           second
#define db          double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
const int N=1e5+5;
vl g[N];
ll in[N];
ll lp[N];

void solve()
{
   ll n,m,ans=0;
   cin>>n>>m;
   rep(i,0,m)
   {
       ll u,v; cin>>u>>v;
       g[u].pb(v);
       in[v]++;
   }
   queue<ll>q;
   rep(i,1,n+1) if(in[i]==0) q.push(i);
   while(!q.empty())
   {
       ll s=q.front();
       q.pop();
       for(ll d:g[s])
       {
           in[d]--;
           if(in[d]==0) { q.push(d); lp[d]=1+lp[s]; }
       }
   }
   rep(i,1,n+1) ans=max(ans,lp[i]);
   cout<<ans;
}
int main()
{
    ll T=1;
    //cin>>T;
    while(T--)
        solve();
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
long long int a[100000][2];
long long int dp[105][100005];
long long int n;
long long int mini(long long int a,long long int b)
{
    if(a<b)
        return a;
    return b;
}

long long int find(int i,int j)
{
    if(j==0)
        return 0;
    if(i==n)
        return 1e15;
    if(j<0)
        return 1e15;

    if(dp[i][j]!=-1)
        return dp[i][j];

    return dp[i][j] = mini(find(i+1,j),a[i][0]+find(i+1,j-a[i][1]));

    
}


int main()
{
  
    long long int w;
    cin>>n>>w;
    memset(dp,-1,sizeof(dp));
    for(int i = 0;i<n;i++)
        for(int j=0;j<2;j++)
            cin>>a[i][j];
        long long int ans =0;
    for(int i = 1;i<=1e5;i++)
    {
        long long int wt = find(0,i);
        //cout<<wt<<" "<<i<<"\n";
        if(wt<=w)
            ans = i;
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 82304
#include <bits/stdc++.h>
using namespace std;
long long n,k;
int main(){
  cin>>n>>k;
  vector<long long> c(100000);
  for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    c.at(a-1)+=b;
  }
  for(int i=0;i<100000;i++){
    if(c.at(i)==0) continue;
    else if(k>c.at(i)){
      k-=c.at(i);
    }
    else if(k<=c.at(i)){
      cout<<i+1<<endl;
      break;
    }
  }
}


Measured memory_bytes: 1024
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
MOD = 10**9 + 7

# print('c', c)
if N % 2 == 0:
    for key, value in c.items():
        if key % 2 != 1:
            print(0)
            exit()
        if value != 2:
            print(0)
            exit()
else:
    if c.get(0) is None:
        print(0)
        exit()
    for key, value in c.items():
        if key == 0:
            continue
        if key % 2 != 0:
            print(0)
            exit()
        if value != 2:
            print(0)
            exit()
ans = pow(2, N // 2, MOD)
print(ans)


Measured memory_bytes: 14820
#include <stdio.h>
#include <iostream>
using namespace std;

int main(void) {
	float n=0;
	float min=9999999,max=0;
	while (scanf("%f",&n) != EOF)
	{
		if (max < n){max = n;}
		if (min > n){min = n;}
	}
	cout << max-min << endl;
	return 0;
}

Measured memory_bytes: 0
import math

k = int(input())

box = [0]*(k+1)
ans = 0

for a in range(1,k+1):
    for b in range(1,k+1):
        box[math.gcd(a,b)] += 1

for i in range(1,k+1):
    for c in range(1,k+1):
        ans += math.gcd(i,c)*box[i]

print(ans)

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

using namespace std;

int n, k;
int a[100000];
int dp[100000];

int main()
{
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	dp[0] = 0;
	for (int i = 1; i < n; i++)
	{
		dp[i] = INT_MAX;
		for (int j = 1; j <= k; j++)
		{
			if (i - j >= 0)
				dp[i] = min(dp[i], abs(a[i] - a[i - j]) + dp[i - j]);
		}
	}
	cout << dp[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 1024
package main

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

var sc = bufio.NewScanner(os.Stdin)

func stringLineScan() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000009)
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(stringLineScan())
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(stringLineScan())
	}
	l := make([]int, n)
	r := make([]int, n)
	l[0], r[n-1] = a[0], a[n-1]
	for i := 1; i < n; i++ {
		l[i] = gcd(l[i-1], a[i])
	}
	for i := n - 2; i >= 0; i-- {
		r[i] = gcd(r[i+1], a[i])
	}
	ans := larger(l[n-2], r[1])
	for i := 1; i < n-1; i++ {
		ans = larger(gcd(l[i-1], r[i+1]), ans)
	}
	fmt.Println(ans)
}
func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}
func larger(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}


Measured memory_bytes: 4736
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N, x;
    cin >> N >> x;
    vector<ll> a(N);
    rep(0, i, N)
    {
        cin >> a.at(i);
    }
    sort(all(a));
    ll ans = 0;
    rep(0, i, N)
    {
        x -= a.at(i);
        if (x < 0)
        {
            break;
        }
        ans++;
    }
    if (x > 0)
    {
        ans--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int a,b,c;

int main(int argc, char const* argv[])
{
    cin >> a >> b >> c;
    if(a == b)  cout << c << endl;
    else if(b==c) cout << a << endl;
    else cout << b << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
p = 2019
s = list(map(int, input()))
n = len(s)
ans = 0
if p == 2:
    for i, c in enumerate(s):
        if c % 2 == 0:
            ans += i + 1
elif p == 5:
    for i, c in enumerate(s):
        if c % 5 == 0:
            ans += i + 1
else:
    l = [0] * (n + 1)
    for i, c in enumerate(s):
        l[i + 1] = l[i] + pow(10, n - i - 1, p) * c
        l[i + 1] %= p
    for v in Counter(l).values():
        ans += v * (v - 1) // 2
print(ans)


Measured memory_bytes: 17996
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

const int MAX_N = 1333;
int dp[MAX_N][MAX_N];

int LD(string &s, string &t) {
    int n=s.length(); int m=t.length();
    if (!n||!m) return 0;

    rep(i,MAX_N) rep(j,MAX_N) dp[i][j]=INF;
    rep(i,MAX_N) dp[i][0]=i;
    rep(i,MAX_N) dp[0][i]=i;

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            int change_cost=0;
            if (s[i-1]!=t[j-1]) change_cost=1;
            dp[i][j]=min({dp[i-1][j]+1,dp[i][j-1]+1,dp[i-1][j-1]+change_cost});
        }
    }

    return dp[n][m];
}

int main(int argc, char const *argv[]) {
    string s,t;
    cin>>s>>t;
    cout << LD(s,t) << endl;
    return 0;
}


Measured memory_bytes: 10156
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;

bool solve( vector <ll> v, int index) {
    ll tmp = v[index];
    v[index] = 0;

    for(int i = 0; i < v.size(); i++){
        if(2 * tmp >= v[i]){
            tmp += v[i];
        }
        else{
            return false;
        }
    }
    return true;
}

int main(){

    ll N;
    cin >> N;
    vector <ll> v(N);
    for(int i = 0; i < N; i++) cin >> v[i];

    sort(all(v));
    if(solve(v, 0)){
        cout << N << endl;
        return 0;
    }
    
    ll left = 0;
    ll right = N - 1;
    while(right - left != 1){
        ll mid = (left + right) / 2;
        
        if( solve(v, mid) ){
            right = mid;
        }
        else{
            left = mid;
        }
    }

    cout << N - right << endl;


}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>

using namespace std;

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

  if(s[0] == s[1] && s[1] == s[2]) cout << "Yes" << endl;
  else if(s[1] == s[2] && s[2] == s[3]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3604
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

int A[500000];
int cnt;

void merge(int A[], int left, int mid, int right) {
    int L[250001], R[250001];
    int n1 = mid - left;
    int n2 = right - mid;
    
    for (int i = 0; i < n1 + 1; i++) L[i] = A[left + i];
    for (int i = 0; i < n2; i++) R[i] = A[mid + 1 + i];

    L[n1 + 1] = INFINITY;
    R[n2] = INFINITY;

    int li = 0, rj = 0;
    for (int ak = left; ak < right + 1; ak++ ) {
        cnt++;
        if (L[li] <= R[rj]) {
            A[ak] = L[li];
            li++;
        } else {
            A[ak] = R[rj];
            rj++;
        }
    }
}

void mergeSort(int A[], int left, int right) {
    if (left == right) return;

    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid + 1, right);
    merge(A, left, mid, right);
}


int main(void) {
    int n;
    cnt = 0;

    cin >> n;
    for (int i = 0; i < n; i++ ) cin >> A[i];

    mergeSort(A, 0, n - 1);

    for (int i = 0; i < n; i++ ) {
        if ( i ) cout << " ";
        cout << A[i];
    }
    cout << endl;

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 6948
#include<bits/stdc++.h>
using namespace std;
#define lc "\n"
#define fast_io ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define int long long
#define c(a,n) for(int i = 0; i < n; i++) cin >> a[i];
#define ffor(n) for(int i = 0; i < n; i++)
 
typedef vector<int> vi;
typedef vector<float> vf;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef map<string,int> msi;
typedef map<int,int> mii;
typedef unordered_map<string,int> umsi;
 
 
int32_t main()
{
    fast_io;
    int n,w;
    cin>>n>>w;
    vector<pair<int,int>>a(n);
    for(int i=0;i<n;i++)cin>>a[i].first>>a[i].second;
    vii dp(n,vi(w+1,LLONG_MIN));
    for(int i=0;i<n;i++)
    dp[i][0]=0;
    int ans=LLONG_MIN;
    for(int i=0;i<n;i++)
    {
        dp[i][a[i].first]=a[i].second;
        for(int wj=a[i].first;wj<=w;wj++)
        {
            int add=LLONG_MIN;
            for(int j=0;j<i;j++)
            add=max(add,dp[j][wj-a[i].first]);
            if(add!=LLONG_MIN)
            dp[i][wj]=a[i].second+add;
            ans=max(ans,dp[i][wj]);
        }
    }
    cout<<ans<<lc;

    
    
    return 0;
}

Measured memory_bytes: 82396
import math

n = int(input())

z = math.factorial(n-2)*(n-1)*2
total = 0
p = []

for _ in range(n):
	x, y = map(int, input().split())
	
	for a, b in p:
		d = ((x-a)**2 + (y-b)**2)**0.5
		total += z*d
		
	p.append((x,y))
	
print(total/math.factorial(n))
	


Measured memory_bytes: 38256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null) {

			int n = Integer.parseInt(line.substring(0, line.indexOf(' ')));
			int m = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
			if (n == 0 && m == 0)
				break;

			//
			m++;
			int[] wish = new int[m];
			for (int i = 0; i < n; i++) {
				line = br.readLine();
				for (int j = 0; j < line.length(); j += 2) {
					wish[j / 2 + 1] += (line.charAt(j) - '0');
				}
			}
			//
			int[] rank = Arrays.copyOf(wish, m);
			Arrays.sort(rank);

			//
			StringBuilder sb = new StringBuilder();
			int i1 = -1, i2 = -1;
			for (int i = m - 1; i >= 0; i--) {
				i1 = rank[i];
				if (i1 == i2)
					continue;
				for (int j = 1; j < m; j++) {
					if (wish[j] == i1)
						sb.append(j + " ");
				}
				i2 = i1;
			}
			System.out.println(sb.toString().substring(0, sb.length() - 1));
		}
	}
}

Measured memory_bytes: 23988
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  int n,x,q,k;
    vector<int>v;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        v.push_back(x);
    }
    cin>>q;
    for(int i=0;i<q;i++)
    {
        cin>>k;
        vector<int>::iterator s;
        s=lower_bound(v.begin(),v.end(),k);
        cout<<s-v.begin()<<endl;
    }
    return 0;
}



Measured memory_bytes: 3528
// AtCoder Beginner Contest 151
// F - Enclose All
// https://atcoder.jp/contests/abc151/tasks/abc151_f
// 最小包含円
#include <bits/stdc++.h>
using namespace std;
struct _I { _I() {cin.tie(0);ios::sync_with_stdio(false);}} __I;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class F, class S> istream& operator >> (istream& s, pair<F, S>& p)
{ cin >> p.first >> p.second; return s;}
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007

ll N, A;
vector<int> x;

ll dp[50][50+1][2500+1];

ll solve(ll p=0, ll chosen=0, ll sum = 0)
{
    if (p == N) {
        return (chosen >0 && sum==chosen*A) ? 1 : 0;
    }

    ll& res = dp[p][chosen][sum];
    if (~res) return dp[p][chosen][sum];
    res = 0;

    res += solve(p+1, chosen+1, sum+x[p]);
    res += solve(p+1, chosen, sum);

    return dp[p][chosen][sum] = res;
}

int main()
{
    cin >> N >> A;
    x.resize(N); cin >> x;

    memset(dp, -1, sizeof dp);

    cout << solve() << endl;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> counter(N);
  int checker;
    for(int j = 0;j < N;j++){
      int checker = 0;
      int A;
      cin >> A;
      for(int k = 0;1;k++){
        if(A % 2 == 0){
          A = A / 2;
          checker++;
        }
        else{
          break;
        }
      }
      counter.at(j) = checker;
    }
  sort(counter.begin(),counter.end());
 cout << counter.at(0) << endl;
}

      
        

    
  

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

int main(){

  //initialization
  int N;
   
  //input
  cin >> N;
  int A[N];
  for(int i=0; i<N; i++) cin >> A[i];

  //solver
  sort(A, A+N);
  cout << A[N-1] -  A[0]<< "\n"; 
}


Measured memory_bytes: 3680
N = gets.to_i
s = gets.chomp

num_white = s.count('.')
num_black = 0
ans = num_black + num_white
N.times do |i|
  if s[i] == '#'
    num_black += 1
  else
    num_white -= 1
  end
  ans = [ans, num_black + num_white].min
end
puts ans

Measured memory_bytes: 14744
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

if __name__ == "__main__":
    n,x,y = map(int,input().split())
    x-=1
    y-=1
    ans = [0]*(n)
    for i in range(n):
        for j in range(i+1,n):
            d = min(abs(i-j),abs(x-i) + abs(y-j) + 1)
            ans[d] += 1
    for i in range(1,n):
        print(ans[i])

Measured memory_bytes: 3956
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    using P = array<int, 3>;
    P v{};
    while(scanf("%d %d %d", &v[0], &v[1], &v[2]) != EOF){
        if(v <= P{1868, 9, 7}) {
            puts("pre-meiji");
            continue;
        }
        if(v <= P{1912, 7, 29}) printf("meiji"), v[0] -= 1867;
        else if(v <= P{1926, 12, 24}) printf("taisho"), v[0] -= 1911;
        else if(v <= P{1989, 1, 7}) printf("showa"), v[0] -= 1925;
        else printf("heisei"), v[0] -= 1988;
        printf(" %d %d %d\n", v[0], v[1], v[2]);
    }
    return 0;
}


Measured memory_bytes: 3200
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		int[] A = new int[Q];
		int[] B = new int[Q];
		long[] C = new long[Q];
		long[] min_cost = new long[N];
		Arrays.fill(min_cost, Long.MAX_VALUE/ 10);
		PriorityQueue<Edge> pq = new PriorityQueue<>();
		for (int i = 0; i < Q; ++i) {
			A[i] = sc.nextInt();
			B[i] = sc.nextInt();
			C[i] = sc.nextInt();
			pq.add(new Edge(A[i], B[i], C[i]));
			min_cost[A[i]] = Math.min(min_cost[A[i]], C[i] + 1);
			min_cost[B[i]] = Math.min(min_cost[B[i]], C[i] + 2);
		}
		for (int i = 0; i < 2 * N; ++i) {
			min_cost[(i + 1) % N] = Math.min(min_cost[(i + 1) % N], min_cost[i % N] + 2);
		}
		for (int i = 0; i < N; ++i) {
			pq.add(new Edge(i, (i + 1) % N, min_cost[i]));
		}
		DJSet ds = new DJSet(N);
		long ret = 0;
		while (!pq.isEmpty()) {
			Edge edge = pq.poll();
			if (ds.equiv(edge.a, edge.b))
				continue;
			ret += edge.cost;
			ds.setUnion(edge.a, edge.b);
			pq.add(new Edge(edge.b, (edge.a + 1) % N, edge.cost + 1));
		}
		System.out.println(ret);

	}

	static class DJSet {
		int n = 1;
		int[] upper;

		public DJSet(int n) {
			this.n = n;
			upper = new int[n];
			Arrays.fill(upper, -1);
		}

		int root(int x) {
			return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
		}

		boolean equiv(int x, int y) {
			return root(x) == root(y);
		}

		void setUnion(int x, int y) {
			x = root(x);
			y = root(y);
			if (x != y) {
				if (upper[x] < upper[y]) {
					int d = x;
					x = y;
					y = d;
				}
				upper[y] += upper[x];
				upper[x] = y;
			}
		}
	}

	static class Edge implements Comparable<Edge> {
		int a;
		int b;
		long cost;

		public Edge(int a, int b, long cost) {
			this.a = a;
			this.b = b;
			this.cost = cost;
		}

		@Override
		public int compareTo(Edge o) {
			return Long.compare(this.cost, o.cost);
		}
	}
}


Measured memory_bytes: 152028
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define ins insert
#define sb substr
#define con continue
#define ub upper_bound
#define lb lower_bound
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define pll pair<ll,ll>
#define pld pair<ld,ld>
using namespace std;

ll power(ll x, ll y);
ll mpower(ll x, ll y, ll p);
ll modInv(ll a, ll m);
ll gcdExtended(ll a, ll b, ll *x, ll *y);
bool isPrime(ll n);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t,i,j,k,l,h,p,q,r,x,y,z,a,b,c,d,f,n,m,M=1000000007;
    char ch,ch2,ch3;
    string s,s1,s2,s3;
    vector<ll> v,w;
    unordered_map<ll,ll> N;
    set<ll> S;
    set<ll> :: iterator itr;
    cin>>x>>y;
    y=y*2;
    cout<<max((ll)0,x-y);
    return 0;
}

ll modInv(ll a, ll m){
    ll x, y;
    ll g = gcdExtended(a, m, &x, &y);
    ll res = (x%m + m) % m;
    return res;
}

ll gcdExtended(ll a, ll b, ll *x, ll *y){
    if (a == 0){
        *x = 0, *y = 1;
        return b;
    }
    ll x1, y1;
    ll gcd = gcdExtended(b%a, a, &x1, &y1);
    *x = y1 - (b/a) * x1;
    *y = x1;
    return gcd;
}

ll mpower(ll x, ll y, ll p){
    ll res = 1;
    x = x % p;
    while(y > 0){
        if(y & 1) res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

ll power(ll x, ll y){
    ll res = 1;
    while (y > 0){
        if (y & 1) res = res*x;
        y = y>>1;
        x = x*x;
    }
    return res;
}

bool isPrime(ll n){
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    ll p=sqrt(n);
    for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
            return false;
    return true;
}


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

typedef long long ll;

ll dp[MAX][100005];
const ll inf = 1e14;

int main()
{
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    int n, s = 0, W, w[MAX], v[MAX];

    cin>>n>>W;
    for(int i = 0; i < n; i++){
        cin>>w[i]>>v[i];
        s += v[i];
    }

    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= s; j++)
            dp[i][j] = inf;
    }
    dp[0][0] = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= s; j++){
            if(j < v[i-1])
                dp[i][j] = dp[i-1][j];
            else{
                dp[i][j] = min(dp[i-1][j] , w[i-1] + dp[i-1][j-v[i-1]]);
            }
        }
    }
    for(int i = s; i > 0; i--){
        if(dp[n][i] <= W){
            cout<<i<<endl;
            return 0;
        }
    }

    cout<<0<<endl;

    return 0;
}

Measured memory_bytes: 80128
import sys
sys.setrecursionlimit(10 ** 8)

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    X, Y = ZZ()
    for n in range(101):
        for m in range(101):
            if n+m == X and 2*n+4*m == Y:
                print('Yes')
                break
        else: continue
        break
    else: print('No')

    return

if __name__ == '__main__':
    main()


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

int main() {

  int N, R;
  cin >> N >> R;

  if (N < 10) {
    int K = (10 - N) * 100; 
    cout << R + K << endl;
  } else {
    cout << R << endl;
  }
  return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
const int N=200005;
const int MOD=1000000007;
int n;
char s[N];
int a[N];
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	if(s[1]=='W')
	{
		printf("0");
		return 0;
	}
	a[0]=1;
	for(int i=1;i<=n*2;i++)
		if(s[i]==s[i-1]) a[i]=a[i-1]^1;
		else a[i]=a[i-1];
	int num=0;
	long long ans=1;
	for(int i=1;i<=n*2;i++)
	{
		if(a[i]==1) num++;
		else ans=ans*num%MOD,num--;
		if(num<0)
		{
			printf("0");
			return 0;
		}
	}
	if(num!=0)
	{
		printf("0");
		return 0;
	}
	for(int i=1;i<=n;i++)
		ans=ans*i%MOD;
	printf("%lld",ans);
	return 0;
}

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

#define M 1000000
#define L 12

char H[M][L];

int getChar(char ch){
  if(ch=='A') return 1;
  else if(ch=='C') return 2;
  else if(ch=='G') return 3;
  else if(ch=='T') return 4;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for(i=0;i<strlen(str);i++){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key)
{
  return key%M;
}

int h2(int key)
{
  return 1+key%(M-1);
}

int find(char str[])
{
  long long sum;
  int i,j;

  sum = getKey(str);

  for(i=0;;i++){
    j = (h1(sum)+i*h2(sum))%M;
    if(strcmp(H[j],str)==0) return 1;
    else if(strlen(H[j])==0) return 0;
  }
}  

int insert(char str[]){
  long long sum;
  int i,h;

  sum = getKey(str);
  
  for(i=0;;i++){
    h = (h1(sum)+i*h2(sum))%M;
    if(strcmp(H[h],str)==0) return 1;
    else if(strlen(H[h])==0){
      strcpy(H[h],str);
      return 0;
    }
  }
}

int main(){
  int i,n;
  char str[L],com[9];
  
  for(i=0;i<M;i++) H[i][0] = '\0';
    
  scanf("%d",&n);
    
  for(i=0;i<n;i++){
    scanf("%s%s",com,str);
    if(com[0]=='i') insert(str);
    else{
      if(find(str)==1) printf("yes\n");
      else printf("no\n");
    }
  }

  return 0;
}  




Measured memory_bytes: 13460
# 2,000,001 個の石が並べられている
# K個の連続した石が黒、他は白
# 座標Xが黒の時、黒の存在範囲を全て小さい順に表示する

k, x = map(int, input().split())

first = max(-1000000, x-k+1)
end = min(1000000, x+k-1)

for i in range(first, end+1):
    print(i)

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

int linearSearch(int key,int a[],int n){
    int i=0;
    a[n]=key;
    while (a[i]!=key)
        i++;
    return i!=n;
}

int main() {
    int n,q,i;
    int s[10001],t;
    int sum=0;
    cin>>n;
    for (i= 0; i < n; ++i) {
        cin>>s[i];
    }
    cin>>q;
    for (i = 0; i < q; ++i) {
        cin>>t;
        if (linearSearch(t,s,n))
            sum++;
    }

    cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 3116
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int ans = 0;
		int[] b = new int[N - 1];

		for (int i = 0; i < N - 1; i++) {
			b[i] = scan.nextInt();
		}

		for (int i = 0; i < N; i++) {
			if (i == 0) {
				ans += b[i];
			} else if (i == N - 1) {
				ans += b[i - 1];
			}else {
				ans += Math.min(b[i - 1], b[i]);
			}
		}

		System.out.println(ans);

	}
}

Measured memory_bytes: 22612
// #pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
#define MM " "
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}


int s[4][4]={
    {6,3,1,4},
    {2,0,2,0},
    {1,3,6,4},
    {5,0,5,0}
};
int check(int x,int y){
    return s[x%4][y%4];
}

main(){
    int n=in();
    if(n==1){
        cout<<1<<endl<<0<<endl;
        return 0;
    }
    else if(n==2) {
        cout<<2<<endl<<"00"<<endl<<1<<endl;
        return 0;
    }
    cout<<n-1<<endl;
    rep2(i,2,n){
        cout<<1;
        rep(j,i-2)cout<<0;
        cout<<1<<endl;
    }
    
}


Measured memory_bytes: 3112
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/input.txt"
exit $?
'''
import sys


def _i(): return int(sys.stdin.readline().strip())


def _gcd(a, b):
    a, b = max(a, b), min(a, b)
    if a % b == 0:
        return b
    return _gcd(b, a % b)


def main():
    gcd = [[1]*201 for _ in range(201)]
    for i in range(1, 201):
        for j in range(i, 201):
            g = _gcd(i, j)
            gcd[i][j] = gcd[j][i] = g

    k = _i() + 1
    ans = 0
    for l in range(1, k):
        for m in range(1, k):
            glm = gcd[l][m]
            for n in range(1, k):
                ans += gcd[glm][n]
    return ans


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 69300
N, K = map(int, input().split())
x = list(map(int, input().split()))
ans = 1e9

for i in range(N-K+1):
    l = x[i]
    r = x[i+K-1]
    ans = min(ans, abs(l) + abs(r-l), abs(r)+abs(l-r))
    
print(ans)

Measured memory_bytes: 14384
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define pq priority_queue
#define st first
#define nd second

using namespace std;
typedef long long ll;
ll const inf = 1e9;
ll const mod = 998244353;



int main()
{
    string s;
    cin >> s;
    int num = 753;
    int temp = 0;
    int ans = 1e9;
    fr(i, 0, s.size() - 2){
        temp = (int)(s[i] - '0') * 100 + (int)(s[i + 1] - '0') * 10 + (int)(s[i + 2] - '0');
        ans=  min(ans, abs(temp - num));
    }
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n,q=parseMap(split(readline()))
    s=chomp(readline())
    cnt=[0 for i in 1:n]
    for i in 2:n
        cnt[i]=cnt[i-1]
        if s[i-1:i]=="AC"
            cnt[i]+=1
        end
    end
    for i in 1:q
        l,r=parseMap(split(readline()))
        println(cnt[r]-cnt[l])
    end
end
main()

Measured memory_bytes: 167448
n,m=map(int,input().split())

one=-1
two=-1
thr=-1

for i in range(m):
    s,c=map(int,input().split())
    
    if n==1:
        if s==1:
            if one==-1 or one==c:
                one=c
            else:
                print("-1")
                exit()
    
    elif n==2:
        if s==1:
            if one==-1 or one==c:
                one=c
            else:
                print("-1")
                exit()
        elif s==2:
            if two==-1 or two==c:
                two=c
            else:
                print("-1")
                exit()
    
    else:
        if s==1:
            if one==-1 or one==c:
                one=c
            else:
                print("-1")
                exit()
        elif s==2:
            if two==-1 or two==c:
                two=c
            else:
                print("-1")
                exit()
        else:
            if thr==-1 or thr==c:
                thr=c
            else:
                print("-1")
                exit()


if one==-1:
    if n==1:
        one=0
    else:
        one=1
if two==-1:
    two=0
if thr==-1:
    thr=0

if n==1:
    for i in range(10):
        if i==one:
            print(i)
            exit()
elif n==2:
    for i in range(10,100):
        if str(i)[0]==str(one) and str(i)[1]==str(two):
            print(i)
            exit()
else:
    for i in range(100,1000):
        if str(i)[0]==str(one) and str(i)[1]==str(two) and str(i)[2]==str(thr):
            print(i)
            exit()

print("-1")

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n;
	cin >> n;
	vector<pii> red(n);
	vector<pii> blue(n);
	FOR(i,0,n){
		int a,b;
		cin >> a >> b;
		red[i] = mp(a,b);
	}
	FOR(i,0,n){
		int c,d;
		cin >> c >> d;
		blue[i] = mp(c,d);
	}
	sort(ALL(blue));
	int ans = 0;
	FOR(bi,0,n){
		int riMax = -1;
		int redYMax = -1;
		FOR(ri,0,(int)red.size()){
			//cout << red[ri].first << " " << blue[bi].first << " " << red[ri].second << " " << blue[bi].second << "\n";
			if(red[ri].first < blue[bi].first && red[ri].second < blue[bi].second){
				if(redYMax < red[ri].second){
					riMax = ri;
					redYMax = red[ri].second;
				}
			}
		}
		if(riMax != -1){
			ans++;
			red.erase(red.begin()+riMax);
		}
	}
	ANS(ans);
	return 0;
}


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

const int inf = -1000;
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;
}
void bubble(vector<int> &v){
int n = v.size();
  for(int k=1;k<=n-1;++k){
    for(int i=1;i<n;++i){
        if(v[i]<v[i-1])
            swap(v[i],v[i-1]);
    }
  }
}
int main() {

   int a,k;
   string s;
   cin>>a>>k>>s;

   s[k-1] = s[k-1]+32;
   cout<<s;

    return 0;

      }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define mod 1000000007
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=(a*a)%mod;
		b>>=1;
	}
	return ans;
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		int a,b,c;
      cin>>a>>b>>c;
      cout<<c<<" "<<a<<" "<<b;
	}
	return 0;
}

Measured memory_bytes: 896
n = int(input())

t,a = map(int,input().split())

h = list(map(int,input().split()))

t_2 = (t-a)/0.006
res = 1000000

for m in range(n):
  num_ = abs(t_2 - h[m])
  if res > num_:
    res = num_
    res_2 = m + 1
print(res_2)

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

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

  string s; cin >> s;
  long long int ans = 0;
  
  if(s.size() < 3) {cout << ans << endl; return 0;}
  
  int a = 0;
  for(int i = 0; i < s.size() - 1; i++){
    if(s.at(i) == 'A') {
      a ++;
    }else if(s.at(i) == 'B' && s.at(i + 1) == 'C'){
      ans += a;
      i++;
    } else a = 0;
  }
  
  //cout << s << endl;
  cout << ans << endl;
}

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

#define MX 100000

int n, m, ans;
vector<int> graph[MX+5];
queue<int> kol;
int st[MX+5];
int dp[MX+5];

void solve( )
{
	while( !kol.empty() )
	{
		int v=kol.front();
		kol.pop();

		for( auto &u : graph[v] )
		{
			dp[u]=max( dp[u], dp[v]+1 );
			st[u]--;
			if( st[u]==0 ) kol.push(u);
		}
	}

}

int main( )
{
	cin>>n>>m;
	for( int i=0; i<m; i++ )
	{
		int a, b; cin>>a>>b;
		graph[a].push_back(b);
		st[b]++;
	}

	for( int i=1; i<=n; i++ )
		if( st[i]==0 ) kol.push(i);

	solve();

	for( int i=1; i<=n; i++ )
		ans=max( ans, dp[i] );

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


Measured memory_bytes: 6528
#include <stdio.h>

int main(void){
	int h[3], m[3], s[3], h2[3], m2[3], s2[3];
	int i;
	for(i = 0; i < 3; i++){
		scanf("%d %d %d %d %d %d",&h[i], &m[i], &s[i], &h2[i], &m2[i], &s2[i]);
		if(s2[i] < s[i]){
			m2[i] -= 1;
			s2[i] += 60;
		}
		if(m2[i] < m[i]){
			h2[i] -= 1;
			m2[i] += 60;
		}
		h[i] = h2[i] - h[i];
		m[i] = m2[i] - m[i];
		s[i] = s2[i] - s[i];
	}
	
	for(i = 0; i < 3; i++){
		printf("%d %d %d\n", h[i], m[i], s[i]);
	}
	return 0;
}

Measured memory_bytes: 600
A, B, C, X, Y = map(int, input().split())
if X>= Y:
  ans = min(A*X+B*Y, X*C*2, Y*C*2 + (X-Y)*A)
else:
  ans = min(A*X+B*Y, Y*C*2, X*C*2 + (Y-X)*B)
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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 mul(ll a, ll b) { if (a == 0) return 0; if (infl / a < b) return infl; return min(infl, a * b); }
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N;
ll MA = 1;
//---------------------------------------------------------------------------------------------------
void _main() {
	rep(i, 0, 18) MA *= 10;

	cin >> N;
	ll tot = 1;
	rep(i, 0, N) {
		ll a; cin >> a;
		tot = mul(tot, a);
	}
	if (MA < tot) cout << "-1" << endl;
	else cout << tot << endl;
}







Measured memory_bytes: 3644
#include<stdio.h>

int main(void){
  long int N;
  long int a[5];
  int i,k;
  long int m;
  long int ans=0;

  scanf("%ld",&N);

  for(i=0;i<5;i++){
    scanf("%ld",&a[i]);
  }

  m=a[0];

  for(i=1;i<5;i++){
    if(a[i]<m) m = a[i];
    k=i;
  }

  if(N<=m) ans=5;

  else{
    for(i=0;i<k;i++){
      ans++;
    }
    
    ans = ans + ((N+m-1)/m);
    
    for(i=k+1;i<5;i++){
      ans++;
    }
  }

  printf("%ld\n",ans);

  return 0;
}



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

#define LL long long
#define LD long double
#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ree(a,n) memset(a,n,sizeof(a));

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))

multiset<int> mt;
vector<int> v[100005];


int main()
{
    NO_TLE
    int n,m,t;
    cin>>n>>m;
    LL ans=0;
    rep(i,n)
    {
        int a,b;
        cin>>a>>b;
        //mt.insert(t);
        v[a].push_back(b);
    }
    //rep(i,100005)mt.insert(0);
    rer(i,1,m)
    {
        rep(j,v[i].size())
        {
            mt.insert(v[i][j]);
        }
        if(!mt.empty())
        {
            auto it=mt.end();
            --it;
            int x=*it;
            ans+=x;
            mt.erase(it);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 7808
#include<iostream>
#include<string>

using namespace std;

int main() {
	int i, k, t, a[100], max = 0, sum = 0, ans = 0;

	cin >> k >> t;

	for (i = 0; i < t; i++) {
		cin >> a[i];
		sum += a[i];
		if (a[i] > max) {
			max = a[i];
		}
	}

	sum -= max;

	if (max > sum + 1) {
		ans = max - sum - 1;
	}
	else {
		ans = 0;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
input = raw_input

x, k, d = map(int, input().split(" "))
is_plus = x >= 0
x = abs(x)

r = x // d
if r > k:
    y = x - k*d
else:
    y1 = x - r*d
    y2 = x - (r+1)*d
    k2 = k-r
    if k2 % 2 == 0:
        y = y1
    else:
        y = y2

y = abs(y)
print(y)

Measured memory_bytes: 64348
def main():
    N = input()
    hon = ['2', '4', '5', '7', '9']
    pon = ['0', '1', '6', '8']
    if N[-1] in hon:
        print('hon')
    elif N[-1] in pon:
        print('pon')
    else:
        print('bon')


if __name__ == '__main__':
    main()


Measured memory_bytes: 61660
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int k;
    cin, k;
    int s = 0;
    vector<int> used(k, false);
    REP(i, 0, k) {
        s = (s * 10 + 7) % k;
        if (used[s]) break;
        used[s] = true;
        if (s == 0) {
            print(i + 1);
            return 0;
        }
    }
    print(-1);

    return 0;
}


Measured memory_bytes: 7152
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, m, q = map(int, input().split())
abcd = [0] * q
for i in range(q):
    abcd[i] = list(map(int, input().split()))

def dfs(seq):
    if len(seq) == n:
        yield seq
    else:
        if seq:
            last = seq[-1]
        else:
            last = 1
        for i in range(last, m+1):
            new_seq = seq.copy()
            new_seq.append(i)
            yield from dfs(new_seq)

seq = dfs([])
ans = 0
for s in seq:
    tmp_ans = 0
    for a, b, c, d in abcd:
        if s[b-1] - s[a-1] == c:
            tmp_ans += d
    ans = max(ans, tmp_ans)
print(ans)


Measured memory_bytes: 9192
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#define rp(i,a,b) for(int (i)=(int)(a);i<(int)(b);++i)

typedef long long ll;


using namespace std;


int main(){
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if(x+r>W or x-r<0 or y+r>H or y-r<0)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
        
    return 0;
};

Measured memory_bytes: 3084
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <assert.h>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define Re register
#define LL long long
#define U unsigned
#define FOR(i,a,b) for(Re int i = a;i <= b;++i)
#define RFOR(i,a,b) for(Re int i = a;i >= b;--i)
#define SFOR(i,a,b,c) for(Re int i = a;i <= b;i+=c)
#define CLR(i,a) memset(i,a,sizeof(i))
#define BR printf("--------------------\n")
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

const int MAXN = 2000000+5;

void calc(int *a){
	assert(a != NULL);
	printf("%d\n",*a);
}

int main(){
	int x;scanf("%d",&x);
	if(x == 7 || x == 5 || x == 3) puts("YES") ;
	else puts("NO");
	return 0;
} 

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        s: String, t: String
    }
    let ans = &s[..] == &t[..t.len()-1];
    if ans {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2132
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


int main() {
  ll n, m; cin >> n >> m;
  ll ans = n*(n-1)/2 + m*(m-1)/2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,a[200001],i,cnt,s,flg[200001],flg1;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	cnt=0; s=1; flg1=0;
	while(1){
		s=a[s];
		cnt++;
		if(s==2){
			flg1=1;
			break;
		}
		if(flg[s]==1) break;
		else flg[s]=1;
		
	}
	if(flg1==1) printf("%d\n",cnt);
	else printf("-1\n");
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
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 MOD = 1000000007;
ll INF =1<<30;

int main(){
   ll n;
   cin >>n;
   vector<ll> a(n);
   rep(i,n)cin >> a[i];
   ll sum = 0;
   rep(i,n){
      sum+=a[i];
   }
   map<ll,ll>mp;
   rep(i,n){
      mp[a[i]]++;
   }
   int q;
   cin >> q;
   rep(i,q){
      int b,c;
      cin >> b>>c;
      sum-=mp[b]*b;
      sum+=mp[b]*c;
      mp[c]+=mp[b];
      mp[b]=0;
      cout << sum <<endl;
   }
}

Measured memory_bytes: 9976
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
#define MOD (int)1e9 + 7
int main(){
  int n, m;
  cin >> n >> m;
  if(abs(n - m) > 1){
    cout << 0 << endl;
    return 0;
  }
  ll ans = 1;
  for(int i = 0; i < n; i++){
    ans *= (i + 1);
    ans %= MOD;
  }
  for(int i = 0; i < m; i++){
    ans *= (i + 1);
    ans %= MOD;
  }
  if(m == n){
    ans *= 2;
  }
  ans %= MOD;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256