akhauriyash/Code-Regression huggingface dataset:
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

int a,b,c,d;
ll res;

int main(){
	scanf("%d%d%*d%d%d%*d%*d",&a,&b,&c,&d);
	For(i,0,2)
		if (a>=i&&c>=i&&d>=i){
			res=max(res,0ll+6ll*i+4ll*((c-i)/2)+4ll*((d-i)/2)+2ll*b+4ll*((a-i)/2));
		}
	cout<<res/2<<endl;
}

Measured memory_bytes: 256
A, B, C, D, E, F=map(int, input().split())
a=[[str(100*A),'0']]
for i in range(101):
    for j in range(101):
        for k in range(101):
            for l in range(101):
                x=100*A*i+100*B*j
                y=C*k+D*l
                if x+y>F or x==0:
                    break
                if 100*y/(x+y)<=(E*100)/(100+E):
                    a.append([str(x+y),str(y)])
print(' '.join(sorted(a, key=lambda x: (100*int(x[1]))/int(x[0]) if int(x[0])!=0 else 0)[-1]))


Measured memory_bytes: 63756
#include "bits/stdc++.h"
using namespace std;

using ll = long long int;
#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()

#define pi 3.14159265358979

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 cnt_rep = 0;
ll powmod(ll N, ll P, ll M){
  cnt_rep++;
  if(P == 0) return 1;
  if(P%2 == 0){
    ll t = powmod(N, P/2, M);
    return t*t % M;
  }
  return (N * powmod(N, P-1, M)) % M;
}


ll gcd(ll a, ll b){
  ll resi, g, l;
  if(a > b){
    g = a; l = b;
  }else if(b > a){
    g = b; l = a;
  }else{
    return a;
  }
  resi = g % l;
  if(resi != 0){
    return gcd(l, resi);
  }else{
    return l;
  } 
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

int ans = 0;
int N, M, Q;

template<typename T>
void showall(vector<T> v){
  rep(i, 0, v.size()){
    cout << v[i] << " ";
  }
  cout << endl;
}


 
int main() {
  int N, K;
  cin >> N >> K;

  vector<int> d(K), a(N);
  vector<vector<int>> A(K, a);

  map<int, int> m;

  rep(i, 0, K){
    cin >> d[i];
    rep(j, 0, d[i]){
      cin >> A[i][j];
      m[A[i][j]]++;
    }
  }
  int ans = 0;
  rep(i, 0, N){
    if(m[i+1] == 0) ans++;
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;

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

#ifdef LOCAL
	#define eprintf(...) printf(__VA_ARGS__)
#else
	#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) 		( ((a) + ((b) - 1) ) / b)
#define SET_ZERO(a)	 		( memset((a), 0, sizeof(a)))
#define SET_NUM_ARRAY(a,b)	( memset((a), b, sizeof(a)))
//#define int long long int //dont forget to change int to signed

int main() {
	int N; lli T;
	scanf("%d %lld", &N, &T);
	lli now = 0, stop = 0;
	lli ans = 0;
	scanf("%lld", &now);
	stop = now + T;
	for (int i = 1; i < N; i++) {
		lli t;
		scanf("%lld", &t);
		ans += t < stop ? t - now : T;
		now = t;
		stop = now + T;
	}

	printf("%lld\n", ans + T);
	return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<vector<int>> v(9,vector<int>(9,0));
  for(int i=0;i<n-1;i++){
    v[s[i]-'1'][s[i+1]-'1']++;
  }
  vector<int> p(9);
  vector<int> ans(9,-1);
  int val=IINF,tmp;
  for(int i=0;i<9;i++) p[i]=i;
  vector<int> x={0,0,0,1,1,1,2,2,2};
  vector<int> y={0,1,2,0,1,2,0,1,2};
  do {
    vector<int> pos(9);
    for(int i=0;i<9;i++) pos[p[i]]=i;
    tmp=0;
    for(int i=0;i<9;i++){
      for(int j=0;j<9;j++){
        tmp+=v[i][j]*(abs(x[pos[i]]-x[pos[j]])+abs(y[pos[i]]-y[pos[j]]));
      }
    }
    if(tmp<val){
      val=tmp;
      for(int i=0;i<9;i++){
        ans[i]=p[i];

      }
    }
  } while( next_permutation(p.begin(), p.end()) );     // 次の順列を生成
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cout << ans[3*i+j]+1;
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3284
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

vl getDic(string s){
    vl temp(26,0);
    rp(i,s.length())
        temp[s[i] - 'a']++;
    return temp;
}

vl mergeV(vl a, vl b){
    rp(i,a.size())
        a[i] = min(a[i],b[i]);
    return a;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n;
    cin >> n;
    vl v;
    string s[n];
    rp(i,n) cin >> s[i];
    v = getDic(s[0]);
    rep(i,1,n){
        v = mergeV(v,getDic(s[i]));
    }
    rp(i,v.size()){
        char c = (char)(i +(int)'a');
        rp(j,v[i])
            cout << c;
    }
    cout << endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }



int main() {
    ll n,t; cin >> n >> t;
    vector<ll> tv(n);
    rep(i, n) cin >> tv[i];


    ll ans = 0;
    ll start = 0;
    ll end = 0;
    rep(i, n) {
        if(tv[i] > end) {
            ans += end-start;
            start = tv[i];
            end = start + t;
        } else {
            end = tv[i] + t;
        }
    }

    ans += end-start;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
import java.io.PrintStream;
import java.util.Scanner;
import java.util.stream.LongStream;

public class Main {
    static final PrintStream so = System.out;
    static final Scanner sc = new Scanner(System.in);
    static final int INF = Integer.MAX_VALUE;

    static int[] mh = {0, 1, 0, -1};
    static int[] mw = {1, 0, -1, 0};
    
    public static void main(String[] args) {
        long N = nl();
        long[] p = new long[5];
        for (int i = 0; i < 5; i++) {
            p[i] = nl();
        }
        
        long min = LongStream.of(p).min().getAsLong();
        so.println(5L + (N-1)/min);
    } 

    static int ni() {
        return sc.nextInt();
    }
    
    static long nl() {
        return sc.nextLong();
    }

    static char[] nsToChars() {
        return sc.next().toCharArray();
    }
}


Measured memory_bytes: 28756
open Printf
open Scanf
open Base
open Stdio

(* Core.read_line is deprecated *)
let read_line () =
    (* Out_channel.(flush stdout); *)
    In_channel.(input_line_exn stdin)

let f = let rec loop l (money, kabu) = match l with
            | [] -> failwith ""
            | [x] -> money + kabu * x
            | (x::(y::_ as y_s)) -> let maisu = money / x in
                loop y_s (if x > y
                    then (money + kabu * x, 0)
                    else (money - maisu * x, kabu + maisu)
                )
    in
    Fn.flip loop (1000, 0)

let () =
    ignore (read_line ());
    read_line ()
    |> String.split_on_chars ~on:[' ']
    |> List.map ~f:int_of_string
    |> f
    |> printf "%d\n"


Measured memory_bytes: 5864
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  long long N,M,V,P;
  cin >> N >> M >> V >> P;

  vector<long long> A(N);
  for(int i = 0;i < N;i++) cin >> A.at(i);

  sort(A.begin(),A.end(),greater<long long>());
  long long base = A.at(P-1);

  int ans = P;
  long long sum = base;
  for(int i = P;i < N;i++) {
    long long p = A.at(i) + M;
    
    if(p < base) break;
    if(V-P <= N-i-1) {
      ans++;
      sum += A.at(i);
      continue;
    }

    long long rest = (V-P-N+i+1)*M;
    if(p*(i-P+1) - sum >= rest) ans++;
    

    sum += A.at(i);
  }

  cout << ans << endl;

  
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s[0]=='R'&&s[1]=='R'&&s[2]=='R')
        cout<<3;
    else if((s[0]=='R'&&s[1]=='R')||(s[1]=='R'&&s[2]=='R'))
        cout<<2;
    else if(s[0]=='R'||s[1]=='R'||s[2]=='R')
        cout<<1;
    else
        cout<<0;
    return 0;
}


Measured memory_bytes: 3544
package main

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for D - Flipping Signs
	var N int
	fmt.Scan(&N)

	sc.Split(bufio.ScanWords)
	A := make([]int, N)
	flag := make(map[int]int, 2)
	var sum int
	var min int = 10000000000
	var b int
	for i := 0; i < N; i++ {
		A[i] = nextInt()
		if A[i] < 0 {
			flag[1]++
			sum -= A[i]
		} else {
			flag[0]++
			sum += A[i]
		}

		b = int(math.Abs(float64(A[i])))
		if min > b {
			min = b
		}
	}

	if flag[1]%2 == 0 {
		fmt.Println(sum)
	} else {
		fmt.Println(sum - 2*min)
	}
}


Measured memory_bytes: 4276
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define maxn 2005
using namespace std;
int n,m;
int st[maxn];
char s[maxn][maxn];
int a[maxn][maxn];
int dp[maxn][maxn];
int l[maxn][maxn],r[maxn][maxn];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%s",s[i]+1);

	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(s[i][j]=='#')
				a[i][j]=1;
			else
				a[i][j]=0;
		}
	}

	for(int i=1;i<n;i++)
	{
		for(int j=1;j<m;j++)
		{
			if(a[i][j]^a[i+1][j+1]^a[i+1][j]^a[i][j+1])
				a[i][j]=0;
			else
				a[i][j]=1;
		}
	}

	n--; m--;

	for(int i=1;i<=n;i++)
	{
		for(int j=m;j>=1;j--)
		{
			if(a[i][j]==0)
				dp[i][j]=0;
			else
				dp[i][j]=dp[i][j+1]+1;
		}
	}

	for(int j=1;j<=m;j++)
	{
		int top=0;
		for(int i=1;i<=n;i++)
		{
			while(top && dp[st[top]][j]>dp[i][j])
			{
				r[st[top]][j]=i-1-st[top]+1;
				top--;
			}
			st[++top]=i;
		}
		while(top)
			r[st[top]][j]=n-st[top]+1,top--;
	}

	for(int j=1;j<=m;j++)
	{
		int top=0;
		for(int i=n;i>=1;i--)
		{
			while(top && dp[st[top]][j]>dp[i][j])
			{
				l[st[top]][j]=st[top]-(i+1)+1;
				top--;
			}
			st[++top]=i;
		}
		while(top)
			l[st[top]][j]=st[top]-1+1,top--;
	}

	int ans=max(n+1,m+1);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			ans=max(ans,(l[i][j]+r[i][j]-1+1)*(dp[i][j]+1));
		}
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 66944
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var cnt=0;
var mn=arr[cnt].split(" ").map(Number);
cnt++;
var m=mn[0];
var n=mn[1];
var si=[];
for(var i=0;i<m-1;i++){si[i]=arr[cnt]-0;cnt++;}
var ai=[];
for(var i=0;i<n;i++){ai[i]=arr[cnt]-0;cnt++;}
var sum=0;
var i=0;
ai.forEach(function(v){
   var k=(v>0)?1:-1;
   var v=Math.abs(v);
   while(v--){
      if(k==1)sum+=si[i];
      i=i+k;
      if(k==-1)sum+=si[i];
   }
   sum=sum%100000
});
console.log(sum);

Measured memory_bytes: 33004
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		out = new PrintWriter(new BufferedOutputStream(System.out));

		int m = sc.nextInt();
		int ans = 48-m;
		out.println(ans);

		out.close();
	}

	//-----------http://codeforces.com/blog/entry/7018---------------------------------
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	//--------------------------------------------------------

}



Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1e18;
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    string ans = "No";
    ll a, b, c;
    cin >> a>> b >> c;
    if(c > a + b and 4 * a * b < (c - a - b) * (c - a - b)) ans = "Yes";
    cout << ans << endl;
    return 0;
}

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

int main(){
  double min=10000000,max=0;
  double h;
  
  while(cin>>h){
    if(max<h)max=h;
    if(min>h)min=h;
  }
  cout<<max-min<<endl;



  return 0;
}

Measured memory_bytes: 3212
#include <iostream>

using namespace std;

int main(){
	int a,b;

	cin >> a >> b;

	for (int i = 1; i < 4; i++) {
		if ((a*b*i) % 2 != 0) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;


}


Measured memory_bytes: 256
#include <iostream>
int main() {
  double d, t, s;
  std::cin >> d >> t >> s;
  s = d / s;
  t -= s;
  if(t >= 0) {
    std::cout << "Yes" << std::endl;
  } else {
      std::cout << "No" << std::endl;
  }
}

Measured memory_bytes: 3676
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
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;}

int main(){
	ll n;
	cin >> n;
	vector<ll> x(n),xsort(n);
	REP(i,n) cin >> x[i];
	
	xsort = x;
	
	sort(xsort.begin(), xsort.end());
	
	ll median1 = xsort[n/2-1];
	ll median2 = xsort[n/2];
	
	REP(i,n){
		if(x[i]==median1  || x[i] < median1){
			cout << median2 <<endl;
		}else if(x[i]==median2|| x[i] > median2){
			cout << median1 <<endl;
		}
	}
	
	return 0;
}

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

static const int MAX = 2e+5 + 1;
int cnt[MAX];

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        cnt[a[i]]++;
    }
    ll ans = 0;
    for(int i = 0; i <= n; i++){
        ans += 1LL * cnt[i] * (cnt[i]-1) / 2;
    }
    for(int i = 0; i < n; i++){
        cout << ans - cnt[a[i]] + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 4752
import sys 
import math

#N = int(input())
a = list(map(int, input().split(" ")))
total = 0;

if abs(a[0]-a[2]) <= a[3]:
    print("Yes")
elif abs(a[0]-a[1]) <= a[3] and abs(a[1]-a[2]) <= a[3]:
    print("Yes")
else:
    print("No")


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

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

#define LL long long
#define Ldouble long double
#define PI 3.14159265358979323846264338327950288419

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

int n, s[200005], l[200005], r[200005];
LL ans;

int stk[200005], p;

int main(){
	scanf("%d", &n);
	FI(i, 1, n) scanf("%d", &s[i]);
	FI(i, 1, n){
		while(p > 0 && s[stk[p]] > s[i]) p--;
		if(p == 0) l[i] = i;
		else l[i] = i - stk[p];
		stk[++p] = i;
	}
	p = 0;
	FD(i, n, 1){
		while(p > 0 && s[stk[p]] > s[i]) p--;
		if(p == 0) r[i] = n - i + 1;
		else r[i] = stk[p] - i;
		stk[++p] = i;
	}
//	FI(i, 1, n) printf("%d: %d %d\n", i, l[i], r[i]);
	FI(i, 1, n) ans += 1LL * s[i] * l[i] * r[i];
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3328
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;
typedef long long ll;
const int maxx = 1e5 + 5;

int main(){
	int n, m;
	while(scanf("%d %d", &n, &m) == 2){
		cout << (3 * n + m) / 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
mod=10**9+7

class Dijkstra():
    """ ダイクストラ法
    重み付きグラフにおける単一始点最短路アルゴリズム

    * 使用条件
        - 負のコストがないこと
        - 有向グラフ、無向グラフともにOK

    * 計算量はO(E*log(V))

    * ベルマンフォード法より高速なので、負のコストがないならばこちらを使うとよい
    """
    class Edge():
        """ 重み付き有向辺 """
        def __init__(self, _to, _cost):
            self.to = _to
            self.cost = _cost

    def __init__(self, V):
        """ 重み付き有向辺
        無向辺を表現したいときは、_fromと_toを逆にした有向辺を加えればよい

        Args:
            V(int): 頂点の数
        """
        self.G = [[] for i in range(V)]  # 隣接リストG[u][i] := 頂点uのi個目の隣接辺
        self._E = 0  # 辺の数
        self._V = V  # 頂点の数

    @property
    def E(self):
        """ 辺数
        無向グラフのときは、辺数は有向グラフの倍になる
        """
        return self._E

    @property
    def V(self):
        """ 頂点数 """
        return self._V

    def add(self, _from, _to, _cost):
        """ 2頂点と、辺のコストを追加する """
        self.G[_from].append(self.Edge(_to, _cost))
        self._E += 1

    def edge(self,_from):
        return self.G[_from]

    def shortest_path(self, s):
        """ 始点sから頂点iまでの最短路を格納したリストを返す
        Args:
            s(int): 始点s
        Returns:
            d(list): d[i] := 始点sから頂点iまでの最短コストを格納したリスト。
                     到達不可の場合、値はfloat("inf")
        """
        import heapq
        que = []  # プライオリティキュー（ヒープ木）
        d = [10**15] * self.V
        d[s] = 0
        cnt=[0]*self.V
        cnt[s]=1
        heapq.heappush(que, (0, s))  # 始点の(最短距離, 頂点番号)をヒープに追加する

        while len(que) != 0:
            cost, v = heapq.heappop(que)
            # キューに格納されている最短経路の候補がdの距離よりも大きければ、他の経路で最短経路が存在するので、処理をスキップ
            if d[v] < cost: continue

            for i in range(len(self.G[v])):
                # 頂点vに隣接する各頂点に関して、頂点vを経由した場合の距離を計算し、今までの距離(d)よりも小さければ更新する
                e = self.G[v][i]  # vのi個目の隣接辺e
                if d[e.to] > d[v] + e.cost:
                    d[e.to] = d[v] + e.cost  # dの更新
                    heapq.heappush(que, (d[e.to], e.to))  # キューに新たな最短経路の候補(最短距離, 頂点番号)の情報をpush
                    cnt[e.to]=cnt[v]%mod
                elif d[e.to]==d[v]+e.cost:
                    cnt[e.to]+=cnt[v]
                    cnt[e.to]%=mod
        return d,cnt

import sys

input=sys.stdin.readline
sys.setrecursionlimit(1000000)

N,M=map(int,input().split())
S,T=map(int,input().split())
mati=Dijkstra(N)
for i in range(M):
    u,v,d=map(int,input().split())
    mati.add(u-1,v-1,d)
    mati.add(v-1,u-1,d)

spath,Sways=mati.shortest_path(S-1)
tpath,Tways=mati.shortest_path(T-1)

ans=Sways[T-1]*Tways[S-1]
ans%=mod
for u in range(N):
    for e in mati.edge(u):
        v=e.to
        d=e.cost
        ans-=(Tways[v]*Sways[u])**2*(spath[u]+d+tpath[v]==spath[T-1] and spath[u]+d!=tpath[v] and spath[u]!=tpath[v]+d and (tpath[v]+d>=spath[u]>=tpath[v] or tpath[v]+d>=spath[u]+d>=tpath[v]))
        ans%=mod

for i in range(N):
    ans-=(Tways[i]*Sways[i])**2*(spath[i]+tpath[i]==spath[T-1] and spath[i]==tpath[i])
    ans%=mod

print(ans%mod)


Measured memory_bytes: 140144
N = int(input())
xyh = [list(map(int, input().split())) for i in range(N)]
# print(N, xyh)

height = None
found = False
for cx in range(0, 101):
    for cy in range(0, 101):
        candidate = 0
        for x, y, h in xyh:
            if h == 0: continue
            dx = abs(x - cx)
            dy = abs(y - cy)
            candidate = dx + dy + h 
            break

        found = True
        for x, y, h in xyh:
            _h = candidate - abs(x - cx) - abs(y - cy)
            if h == 0 and _h <= 0: continue
            if not h == _h:
                found = False
                break
        
        if found is True: break
    if found is True: break
height = candidate if candidate is not None else 0

print(cx, cy, height)


Measured memory_bytes: 3064
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
arrA = list(map(int,input().split()))

cnt = Counter(arrA)
maxnum = max(arrA)
ans = 0
for i in range(maxnum+1):
    num = cnt[i-1] + cnt[i] + cnt[i+1]
    ans = max(ans,num)
    # print(i,num,ans)

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 14564
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<vector<pair<int, int>>> E(N);
  for (int i = 0; i < N - 1; i++){
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    E[u].push_back(make_pair(w, v));
    E[v].push_back(make_pair(w, u));
  }
  vector<int> c(N, -1);
  c[0] = 0;
  queue<int> Q;
  Q.push(0);
  while (!Q.empty()){
    int v = Q.front();
    Q.pop();
    for (auto P : E[v]){
      int d = P.first;
      int w = P.second;
      if (c[w] == -1){
        if (d % 2 == 0){
          c[w] = c[v];
        } else {
          c[w] = 1 - c[v];
        }
        Q.push(w);
      }
    }
  }
  for (int i = 0; i < N; i++){
    cout << c[i] << endl;
  }
}

Measured memory_bytes: 6784
import math
import itertools
import bisect
import sys
input = sys.stdin.readline


# 素数判定
def eratosthenes(n):
    is_prime = [1] * n
    is_prime[0] = 0
    prime=[]

    for i in range(2, n + 1):
        if is_prime[i - 1]:
            j = 2 * i
            while j <= n:
                is_prime[j - 1] = 0
                j += i
    for i in range(n):
        if is_prime[i]==1:
            prime.append(i+1)
    return prime


# mod の逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

q=int(input())
s= [list(map(int, input().split())) for i in range(q)]
v=eratosthenes(pow(10,5))
ans=[]
for i in range(len(v)):
    x=(v[i]+1)//2
    index = bisect.bisect_left(v, x)
    if v[index]==x:
        ans.append(v[i])

for i,j in s:
    r = bisect.bisect_left(ans, j+1)
    l = bisect.bisect_left(ans, i-1)
    print(r-l)


Measured memory_bytes: 72540
import fractions

a,b,c,d=map(int, input().split())

a-=1

buf_1=a-(a//c+a//d)+a//((c*d)//fractions.gcd(c,d))
buf_2=b-(b//c+b//d)+b//((c*d)//fractions.gcd(c,d))

print(buf_2-buf_1)

Measured memory_bytes: 5048
#include<stdio.h>

typedef struct{//all number is 0
  int color;//0 white /1 gray /2 black
  int start;
  int finish;
}Graf;


Graf A[100];
int G[100][100];
int total_time=0;


void DFS(int u,int n){
  int i;

  if( A[u].color!=0)return;
  total_time++;
  A[u].color=1;

  A[u].start=total_time;
  
  for(i=0;i<n;i++){
    if(G[u][i]==1 && A[i].color==0){
      DFS(i,n);
    }
  }
  
  total_time++;
  
  A[u].color=2;
  A[u].finish=total_time;
 
}


int main(){
  
  int id;
  int n;
  int num;
  int i,j;
  int hand;
 
  for(i=0;i<100;i++){ //all 0
    A[i].color=A[i].start=A[i].finish=0; // all 0
    
    for(j=0;j<100;j++){
      G[i][j]=0;
    }
  }

  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d%d",&id,&num);
    
    for(j=0;j<num;j++){
      scanf("%d",&hand);
      G[id-1][hand-1]=1;
    }
  }
  
  for(i=0;i<n;i++){
    DFS(i,n);
  }
  
  for(i=0;i<n;i++){//OUTPUT
    printf("%d %d %d\n",i+1,A[i].start,A[i].finish);
  }
  
  return 0;
}


   



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

int main(){
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  s1[0] = toupper(s1[0]);
  s2[0] = toupper(s2[0]);
  s3[0] = toupper(s3[0]);
  cout << s1[0] << s2[0] << s3[0] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#define mod 1000000007
using namespace std;
inline long long ksm(long long x,long long y)
{
	long long rtn=1;
	while(y)
	{
		if(y&1) rtn*=x,rtn%=mod;
		x*=x,x%=mod,y>>=1;
	}
	return rtn;
}
long long cnt[100005];
int main(int argc, char** argv) {
	long long n,k,ans=0;
	cin >> n >> k;
	for(long long i=k;i>=1;i--)
	{
		cnt[i]=ksm(k/i,n);
		for(long long j=i+i;j<=k;j+=i)
			cnt[i]-=cnt[j],cnt[i]%=mod;
		cnt[i]+=mod,cnt[i]%=mod;
		ans+=cnt[i]*i%mod,ans%=mod;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3944
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

//------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    vector<string> grid(h);
    vector<vector<bool>> seen(h, vector<bool>(w, false));
    vector<vector<int>> syougai_index_x(h);
    vector<vector<int>> syougai_index_y(w);
    for (int i = 0; i < h; i++)
    {
        cin >> grid[i];
        syougai_index_x[i].push_back(-1);
        for (int j = 0; j < w; j++)
        {
            if (grid[i][j] == '#')
            {
                syougai_index_x[i].push_back(j);
            }
        }
        syougai_index_x[i].push_back(w);
        sort(ALL(syougai_index_x[i]));
    }
    for (int i = 0; i < w; i++)
    {
        syougai_index_y[i].push_back(-1);
        syougai_index_y[i].push_back(h);
        for (int j = 0; j < h; j++)
        {
            if (grid[j][i] == '#')
            {
                syougai_index_y[i].push_back(j);
            }
        }
        sort(ALL(syougai_index_y[i]));
    }

    int ans = -INF;

    for (int y = 0; y < h; y++)
    {
        for (int x = 0; x < w; x++)
        {
            if (grid[y][x] == '#')
            {
                continue;
            }
            else
            {
                // 今見ている場所から一番近い右側の障害物のindex
                int right_x = upper_bound(ALL(syougai_index_x[y]), x) - syougai_index_x[y].begin();
                // 今見ている場所から一番近い下側の障害物のindex
                int down_y = upper_bound(ALL(syougai_index_y[x]), y) - syougai_index_y[x].begin();
                // cout << "dbg:" << syougai_index_x[y][right_x] << ' ' << syougai_index_y[x][down_y] << endl;
                int tmp = syougai_index_x[y][right_x] - syougai_index_x[y][right_x - 1] - 1;
                tmp += syougai_index_y[x][down_y] - syougai_index_y[x][down_y - 1] - 2;
                // cout << "dbg2:" << tmp << endl;
                chmax(ans, tmp);
            }
        }
    }
    cout << ans << endl;
}

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

using namespace std;
typedef pair<int,int> pii;
const int N = 2e5 + 10;

int n , res , maxn;
int A[N];

map<int,int> exi;
int check(int mid){
	exi.clear();	
	for (int i = 2;i <= n;i++){
		if (A[i] > A[i-1]){
		
		}else{
			if (!mid) return 0;
			int p = A[i];
			while (p && exi[p] == mid) {
				p--;
			}
			if (!p) return false;
			exi[p]++;
			
			auto it = exi.upper_bound(p);
			while(it != exi.end()) it = exi.erase(it);
		}
	}
	return true;
}

int main(){
	scanf("%d",&n);
	for (int i = 1;i <= n;i++){
		scanf("%d",A + i);
		maxn = max(maxn , A[i]);
	}
	
	int L = 0 , R = n , res = n;
	while (L <= R){
		int mid = L + R >> 1;
		if (check(mid)){
			res = mid + 1;
			R = mid - 1;
		}else{
			L = mid + 1;
		}
	}
	
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <numeric>
#include <algorithm>
#include <vector>
using namespace std;

struct ab {
    int a;
    int b;

    ab(int inputed_a, int inputed_b)
    {
        a = inputed_a;
        b = inputed_b;
    }
    bool operator<(const ab &another) const
    {
        return b < another.b;
    }
};

int main()
{
    int N; cin >> N;
    vector<ab> works;
    for(int i = 0; i < N; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        works.push_back(ab(a, b));
    }

    sort(works.begin(),works.end());

    long sum = 0;
    for(int i = 0; i < N; ++i) {
        sum = sum + works[i].a;
        if(sum > works[i].b) {
            cout << "No" << "\n";
            return 0;
        }
    }
    cout << "Yes" << "\n";

    return 0;
}


Measured memory_bytes: 2420
import math
import functools
N, D = list(map(int,input().split()))
X = [list(map(int,input().split())) for _ in range(N)]
ans = 0
for i in range(N):
    for j in range(N):
        if i >= j:
            continue
        L = [(X[i][d]-X[j][d])**2 for d in range(D)]
        distance = math.sqrt(functools.reduce(lambda x,y:x+y,L))
        if (distance % 1) == 0:
            ans += 1
print(ans)


Measured memory_bytes: 3944
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        if(!(cin >> n))
            return 0;

        printf("3C%02d\n", (n-1)%39+1);
    }
}

Measured memory_bytes: 0
#coding:utf-8

s = input()
while s != '':
    if s[len(s) - 5: ] == 'erase' or s[len(s) - 5: ] == 'dream':
        s = s[:len(s) - 5]
    elif s[len(s) - 6:] == 'eraser':
        s = s[:len(s) - 6]
    elif s[len(s) - 7:] == 'dreamer':
        s = s[: len(s) - 7]
    else:
        print('NO')
        break
else:
    print('YES')

Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long 

// fact(n)
int fact(int n){
	if(n == 1)	return 1;
	else return (n * fact(n - 1));
}

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

// gcd(a,b)
int gcd(int a,int b){
	int ret;
	ret = (b == 0) ? a : gcd(b, a % b);
	return ret;
}

// lcm(a.b)
int lcm(int a,int b){
	return (a * b) / gcd(a,b);
}

// qsort(array, size, sizeof(int),comp);
int comp(const int *a,const int *b){
	return (*a - *b);
}

// append(array,*size,addNum)
void append(int *array,int *size,int num){
	realloc(array, sizeof(int) * (*size + 1));
	array[(*size)] = num;
	++(*size);
}

// pop(array,*size) & nongetpop(array,*size)
int pop(int *array,int *size){
	int temp = array[(*size - 1)];
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
	return temp;
}

void nongetpop(int *array,int *size){
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
}

int main(int argc, char const *argv[])
{
	int cnt = 700;
	char ch;
	for (int i = 0; i < 3; ++i)
	{
		if((ch = getchar()) == 'o')	cnt += 100;
	}
	printf("%d\n", cnt);
	return 0;
}



Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str=br.readLine();
		System.out.println((str.equals("ABC"))? "ARC":"ABC");
	}
}

Measured memory_bytes: 32404
program main
  implicit none
  integer :: n, i, begin, even, odd, i_atr
  logical :: rtol
  character(100000) :: s
  integer, allocatable :: res(:)
  read (*, *) s
  n = len_trim(s)
  allocate (res(n))
  res(:) = 0

  begin = 1
  rtol = .false.
  do i = 2, n + 1
    if (i == n + 1 .or. (s(i:i) == "R" .and. rtol)) then
      ! 区間 [begin, i - 1] が1つのbasin. そのbasinに対する処理
      even = (i - 1) / 2 - (begin - 1) / 2
      odd = (i - begin) - even
      if (mod(i_atr, 2) == 0) then
        res(i_atr) = even
        res(i_atr + 1) = odd
      else
        res(i_atr) = odd
        res(i_atr + 1) = even
      end if

      ! 次のbasinのための処理
      begin = i
      rtol = .false.
    else if (s(i:i) == "L") then
      if (.not. rtol) then
        i_atr = i - 1
        rtol = .true.
      end if
    end if
  end do

  write (*, "(100000(i0, ' '))") res(:)
end program main


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


int main() {
  int n;
  cin >> n;
  int ans=0;
  rep2(i,1,n+1){
    rep2(j,1,n+1){
      rep2(k,1,n+1){
        int a=__gcd(i,j);
        a=__gcd(a,k);
        ans+=a;
      }
    }
  }

    cout<<ans<<endl;
  
  
}







Measured memory_bytes: 3604
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;

const int maxn = 1e5+1;
int longest = 0;

vector<vector<int>> adj;
vector<int> topo; 
bool visited[maxn + 1];
int dp[maxn + 1];

void dfs(int curr){
    visited[curr] = true;

    for(int x : adj[curr]){
        if(!visited[x])
            dfs(x);
    }
    topo.push_back(curr);
}

int main(){
    int n, m;
    cin >> n >> m;
    adj.resize(n + 1);

    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        adj[x].push_back(y);
    }

    for(int i = 1; i <= n; i++){
        if(!visited[i])
            dfs(i);
    }

    for(int i = n; i > 0; i--){
		int curr = topo[i - 1];
		for(int v : adj[curr]){
			dp[v] = max(dp[v], dp[curr] + 1);
		}
	}

    int longest = -1;
    for(int i = 0; i <= n; i++)
        longest = max(dp[i], longest);
    cout << longest;
}

Measured memory_bytes: 8824
#include<iostream>
#include<vector>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<cstring>
#include<map>
#include<iostream>
using namespace std;
typedef pair<int,int> Pt;
typedef pair<int,Pt> P;
#define fr first
#define sc second
Pt gl;
int h,w,d[]={0,1,0,-1};
bool used[1000][1000];
char mas[1000][1000];
vector<Pt> vc;
bool bfs(int n){
  mas[vc[n].fr][vc[n].sc] = '.';
  bool ok = false;
  if(n){
    for(int i = 0 ; i < 4 ; i++){
      int nx = vc[n].fr + d[i] , ny = vc[n].sc + d[3-i];
      if(nx >= 0 && nx < h && ny >= 0 && ny < w){
        if(used[nx][ny]) ok = true;
      }
    }
  }else ok = true;
  if(ok){
    queue<Pt> que;
    que.push(Pt(vc[n]));
    used[vc[n].fr][vc[n].sc] = true;
    while(!que.empty()){
      Pt p = que.front();
      que.pop();
      if(p == gl) return true;
      for(int i = 0 ; i < 4 ; i++){
        int nx = p.fr + d[i] , ny = p.sc + d[3-i];
        if(nx >= 0 && nx < h && ny >= 0 && ny < w && !used[nx][ny] && mas[nx][ny] != '#'){
          que.push(Pt(nx,ny));
          used[nx][ny] = true;
        }
      }
    }
  }
  return false;
}
int main(){
  cin >> w >> h ;
  for(int i = 0 ; i < h ; i++){
    for(int j = 0 ; j < w ; j++){
      cin >> mas[i][j];
      if(mas[i][j] == 't') gl = Pt(i,j);
    }
  }
  int n;
  cin >> n;
  vc.resize(n+1);
  vc[0] = Pt(0,0);
  for(int i = 1 ; i <= n ; i++ ){
    cin >> vc[i].sc >> vc[i].fr ;
  }

  int i = 0;
  for(i = 0 ; i <= n ; i++ ){
    if( bfs(i) ){
      cout << i << endl;
      break;
    }
  }
  if(i == n+1) cout << -1 << endl;
}

Measured memory_bytes: 3188
import numpy as np

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

N = tmp[0]
K = tmp[1]


# i = N % K


# if N > K:
#     N = N + K

# solve = [0] * (K+1)

# for i in range(0, K-1):
#     solve[i] = N % (K - i)

solve = N % K
if solve > abs(solve - K):
    solve = abs(solve - K)

print(solve)

# solve.reverse()

# for iter in range(0,K-1):
#     if solve[iter] == 0:
#         continue
#     else:
#         print(solve[iter])
#         break
# print(0)

    

Measured memory_bytes: 12484
#include<iostream>
#include<map>
#include<string>
using namespace std;

int main()
{
  int n, m;
  string s, s2;
  int k;
  map<string, int> cost;

  while(cin>>n, n){
    cost.clear();
    while(n-- > 0){
      cin>>s>>k;
      cost[s] = k;
    }
    cin>>n;
    while(n-- > 0){
      cin>>s>>m;
      k = 0;
      while(m-- > 0){
	cin>>s2;
	k += cost[s2];
      }
      if(cost[s] > k) cost[s] = k;
    }
    cin>>s;
    cout<<cost[s]<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
 
// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
 
 
/*
--------------------------------------------
 
	type
 
--------------------------------------------
*/
using LL = long long;
using ULL = unsigned long long;
//using pair<T1, T2> = p12;
 
/*
--------------------------------------------
 
	container
 
--------------------------------------------
*/
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
 
/*
--------------------------------------------
 
	repetition
 
--------------------------------------------
*/
#define MAX(a,b) (a>b)?a:b
#define MIN(a,b) (a>b)?b:a
#define REP(n) for(int i=0; i<(n); i++)
#define REPj(n) for(int j=0; j<n; j++)
#define REPS(i,n) for(int i=0; i<(n); i++)
#define REPinit(a,n) for(int i=a; i<(n); i++)
#define REPinitj(a,n) for(int j=a; j<n; j++)
 
//algorithm
//#define SORT(c) sort((c).begin(),(c).end())
 
/*
--------------------------------------------
 
	constant
 
--------------------------------------------
*/
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
/*
 
	Optimizer
 
*/
//#pragma GCC optimize("Ofast")


/*
 
	Utility Algorithm
 
*/
template <typename T>
void swapAlgorithm(T& a, T& b) {
    T tmp = a;
    a = b;
    b = tmp;
}

LL euclideanAlgorithm(LL a, LL b) {
    LL a_tmp = a;
    LL b_tmp = b;

    if (a_tmp > b_tmp) {
        swapAlgorithm<LL>(a_tmp, b_tmp);
    }

    LL r = a_tmp % b_tmp;
    while (r != 0) {
        a_tmp = b_tmp;
        b_tmp = r;
        r = a_tmp % b_tmp;
    }
    return b_tmp;    
}

LL getLCM(LL a, LL b) {
    return (a * b)/(euclideanAlgorithm(a, b));
}

/*
  Code
*/

double eauclidDistance(pair<double, double>& x1, pair<double, double>& x2) {
  return sqrt((x1.first - x2.first) * (x1.first - x2.first) + (x1.second - x2.second) * (x1.second - x2.second));
}

void swap(int& a, int& b) {
  int tmp;
  tmp = a;
  a = b;
  b = tmp;
}

int main(int argc, char const *argv[])
{
  ULL N;
  cin >> N;

  ULL sum = 0;
  int upper;
  for (int i = 1; i <= N; i++)
  {
    sum += i;
    if(sum >= N) {
      upper = i;
      break;
    }
  }

  for (int i = 1; i <= upper; i++) {
    if(sum - i == N) continue;
    cout << i << endl;
  }
  

  return 0;
}


Measured memory_bytes: 256
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  																						   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
																													   
const int INF = 1000000001;																						   
const float PI = 3.14;	
const int mod = 1e9+7;																							   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra																													   																				   list<int>::iterator it;																								   
																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS//////////////////////////////////////////////////////


///////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	int a, b;
	cin >> a >> b;
	cout << a - b + 1 << endl;
	
	
	
	
						
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count = 0;
    int[] ary = new int[n];
    for(int c = 0;c<n;c++){
      ary[c] = sc.nextInt();
    }
    Arrays.sort(ary);
    int a = n/2;
    int b = 0;
    if(ary[a]!=ary[a-1]){
      b = ary[a-1];
      count = ary[a] - b;
    } 
    System.out.println(count);
  } 
}

Measured memory_bytes: 50408
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  int H,W,D;
  cin >> H >> W >> D;
  int X = H*W;
  pair<int,int> pos[X+1];
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      int tmp;
      cin >> tmp;
      pos[tmp] = make_pair(i,j);
    }
  }

  //累積和
  int sum[X+1];
  for(int i=X;i>=1;i--){
    if(i+D > X){
      sum[i] = 0;
    }else{
      sum[i] = sum[i+D];
      sum[i] += abs(pos[i+D].first - pos[i].first);
      sum[i] += abs(pos[i+D].second - pos[i].second);
    }
  }

  int Q;
  cin >> Q;
  int L[Q],R[Q];
  for(int i=0;i<Q;i++) cin >> L[i] >> R[i];
  for(int i=0;i<Q;i++) cout << sum[L[i]] - sum[R[i]] << endl;
  return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n;
  R n;
  ll a[n];
  rep(i,n) R a[i];
  ll d[n+1];
  mem(d);
  map<ll,ll> m;
  m[0]=1;
  ll ans=0;
  rep(i,n) {
    d[i+1]=d[i]+a[i];
    ans+=m[d[i+1]];
    m[d[i+1]]++;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
const ll MOD=1000000007,INF=1e18;
int dx[]={0,0,1,-1};
int dy[]={-1,1,0,0};
int dyy[]={1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1};
int dxx[]={0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1};

int N,M,K,A,B,C;
string s,t;

signed main() {
    IOS();
    cin>>A>>B>>C;
    cout<<min(B/A,C)<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define rep(i,N) for(int i=0;i<N;i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1e9+7;

int main() {
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  
  string answer;
  if (A+B < C+D) answer = "Right";
  else if (A+B == C+D) answer = "Balanced";
  else answer = "Left";
  
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
a = [-1 for i in range(n)]
ans = True
for i in range(m):
  s,c = map(int,input().split())
  s -= 1
  if (n != 1 and s == 0 and c == 0) or (a[s] != -1 and a[s] != c):
    ans = False
    print(-1)
    break
  else:
    a[s] = c
if ans:
  for i in range(n):
    if a[i] == -1 and (n == 1 or (n != 1 and i != 0)):
      a[i] = 0
    elif a[i] == -1:
      a[i] = 1
    a[i] = str(a[i])
  print("".join(a))


Measured memory_bytes: 3064