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

int main(){
  int S,T;
  cin >>S>>T;
  int ans=0;
  
  for (int i=0;i<1000;++i){
    if ((S-1)*i+1>=T){
      ans=i;
      break;
    }
  }
    
  cout<<ans<<endl;
}
   

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

#define LL long long
#define vi vector<int>
#define srt(a) sort(a.begin(), a.end());
#define se second
#define fi first
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.precision(10);
    cout << fixed;
    LL n;
    cin >> n;
    vector<LL> v(n);
    forn(i, n) cin >> v[i];
    if (v[0] != 0 || v[n - 1] >= n)
    {
        cout << -1 << endl;
        return 0;
    }
    reverse(all(v));
    LL an = v[0], f = 1, b = v[0];
    for1(i, n - 1)
    {
        if (v[i] >= b)
        {

            an += v[i];
        }
        else if (v[i] == b - 1)
        {
            an += 0;
        }
        else if (v[i] < b - 1)
        {
            f = 0;
            break;
        }
        //cout << an << endl;
        b = v[i];
    }

    cout << (f ? an : -1) << endl;
    return 0;
}

Measured memory_bytes: 1920
// template {{{
#include <bits/stdc++.h>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define sz(c) (static_cast<int>(c.size()))
#define endl "\n"

using ld = long double;
using ll = long long;

inline ll addm(ll __a, ll __b, ll __m);
inline ll subm(ll __a, ll __b, ll __m);
inline ll mulm(ll __a, ll __b, ll __m);
ll powm(ll __a, ll __b, ll __m);
ll inv(ll __x, ll __m);
// }}}

const ll INFL = numeric_limits<ll>::max() / 2;
const ll INF = numeric_limits<int>::max() / 2;
const ll MOD = 1e9+7;

const int N = 105;
const int K = 100500;
int a[N];
bool dp[K];

void solve()
{
    int n, k; cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    dp[0] = false;
    for (int j = 1; j <= k; j++) {
        dp[j] = false;
        for (int i = 0; i < n; i++) {
            if (j-a[i] >= 0 && !dp[j-a[i]])
                dp[j] = true;
        }
    }
    cout << (dp[k] ? "First" : "Second") << endl;
}

// main {{{
int main()
{
    cin.sync_with_stdio(0); cin.tie(NULL);
    solve();
    return 0;
}

inline ll addm(ll __a, ll __b, ll __m = MOD) {
    return ((__a+__b)%__m);
}
inline ll subm(ll __a, ll __b, ll __m = MOD) {
    return (((__a-__b)%__m+__m)%__m);
}
inline ll mulm(ll __a, ll __b, ll __m = MOD) {
    return ((__a*__b)%__m);
}
ll powm(ll __a, ll __b, ll __m = MOD) {
    ll ret = (!__b) ? 1 : powm(__a, __b/2, __m);
    return (!__b) ? 1 : mulm(mulm(ret, ret, __m), (__b%2) ? __a : 1, __m);
}
ll inv(ll __x, ll __m = MOD) {
    return powm(__x, __m-2, __m);
}
// }}}


Measured memory_bytes: 384
#include <bits/stdc++.h>
//#pragma GCC optimize "-O3"
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned short us;
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ll infll=(1ull<<63)-1,mod=1e9+7;
const int inf=(1ull<<31)-1;
int a,b,c;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);cout.precision(18);
	cin>>a>>b>>c;
	cout<<max(c-a+b,0);
	return 0;
}


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

const int INF = 1 << 30;

struct Edge {
    int to; int cap; int rev;
    Edge(int t, int c, int r) : to(t), cap(c), rev(r) {}
};

struct Flow {
    vector <vector<Edge>> G;
    vector<bool> used;
    Flow(int n) : G(n), used(n, false) {}
    void add_edge(int from, int to, int cap) {
        G[from].push_back(Edge(to, cap, G[to].size()));
        G[to].push_back(Edge(from, 0, G[from].size() - 1));
    }
    int dfs(int v, int t, int f) {
        if (v == t) return f;
        used[v] = true;
        for (int i = 0; i < G[v].size(); i++) {
            Edge &e = G[v][i];
            if (!used[e.to] && e.cap > 0) {
                int d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    int max_flow(int s, int t) {
        int flow = 0;
        while (1) {
            fill(used.begin(), used.end(), false);
            int f = dfs(s, t, INF);
            if (f == 0) return flow;
            flow += f;
        }
    }
};

int main() {
    int x, y, e;
    cin >> x >> y >> e;

    Flow fl(x+y+2);
    for (int i = 0; i < x; i++) fl.add_edge(x+y, i, 1);
    for (int i = 0; i < y; i++) fl.add_edge(x+i, x+y+1, 1);
    for (int i = 0; i < e; i++) {
        int a, b;
        cin >> a >> b;
        fl.add_edge(a, b+x, 1);
    }

    cout << fl.max_flow(x+y, x+y+1) << "\n";
    return 0;
}


Measured memory_bytes: 3268
function main(input) {
  input = input.trim().split("\n");
  const n = Number(input[0]);
  const a = input[1].split(" ").map(n => Number(n));
  const arr = [0];
  for (let i = 1; i < n; i++) {
    const num = a[i-1]*2 - arr[arr.length -1];
    arr.push(num);
  }
  const dif = (a[a.length-1]*2 - (arr[0] + arr[arr.length -1]))/2;
  const result = [dif];
  for (let i = 1; i < n; i++) {
    result.push(a[i-1]*2 - result[result.length -1]);
  }
  console.log(result.join(" "));
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

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

    string S;
    cin >> S;
    vector<pair<char, int>> T;
    S += "X";
    char prev = S[0];
    int num = 1;
    for (int i=1; i<S.size(); ++i) {
        if (prev == S[i]) {
            num++;
        }
        else {
            T.emplace_back(prev, num);
            num = 1;
            prev = S[i];
        }
    }

    if (T.size()%2 == 0) T.emplace_back('X', 0);
    vector<pair<int, int>> p;
    for (int i=1; i<T.size()-1; i += 2) {
        int num = T[i-1].second + T[i].second + T[i+1].second;
        p.emplace_back(num, i);
    }

    // for (auto tmp : p) {
    //     cout << tmp.first << tmp.second << " ";
    // }
    // cout << endl;

    //sort(p.rbegin(), p.rend());
    char tmp = T[0].first;
    int sz = min((int)p.size(), K);
    rep(i, sz) {
        T[p[i].second].first = tmp;
    }

    string St = "";
    rep(i, T.size()) {
        St += string(T[i].second, T[i].first);
    }

    int ans = 0;
    rep(i, St.size()-1) {
        if (St[i] == St[i+1]) ans++;
    }

    //cout << St << endl;

    cout << ans << endl;

}


Measured memory_bytes: 2164
A,B,C,D = map(int,input().split())
 
alice = [i for i in range(A,B + 1)]
bob = [i for i in range(C,D + 1)]
 
common = [i for i in bob if i in alice]

if len(common) == 0:
  print(0)
else:
  print(len(common)-1)

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,k; cin>>n>>k;
	int ret=0,x;
	for (int i=0; i<n; i++)
		cin>>x, ret+=2*min(x,k-x);
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> a(n+1);
    for(int i=1;i<=n;i++)
    cin>>a[i];
    vector<int> dp(n+2,INT_MAX);
    dp[1]=0;
    for(int i=1;i<=n;i++)
    {
        if(i+1<=n)
        dp[i+1]=min(dp[i+1],dp[i]+abs(a[i]-a[i+1]));
        if(i+2<=n)
        dp[i+2]=min(dp[i+2],dp[i]+abs(a[i+2]-a[i]));
    }
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 4052
#include<stdio.h>
int main(void){
	int n,i = 0;
	int a[1000];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	printf("%d",a[n-1]);
	for(i=n-2;i>-1;i--){
		printf(" %d",a[i]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n, k; std::string s;
    std::cin >> n >> k >> s;
    std::deque<std::pair<int, int>> q;
    auto l = s.find_first_of('1');
    while (l != std::string::npos) {
        int r = s.find_first_of('0', l);
        q.emplace_back(l, r == -1 ? n : r);
        l = s.find_first_of('1', r);
    }
    if (s.front() == '0') q.emplace_front(0, 0);
    if (s.back() == '0') q.emplace_back(n, n);

    if (q.size() <= k + 1) {
        std::cout << n << std::endl;
        return 0;
    }

    int ret = 0;
    for (int i = 0; i + k < q.size(); i++) {
        ret = std::max(ret, q[i + k].second - q[i].first);
    }
    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 768
N = int(input())

result = [0]*(N+1)

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            f = x*x + y*y + z*z + x*y + y*z + z*x
            if f <= N:
                result[f] += 1
for i in range(N):
    print(result[i+1])

Measured memory_bytes: 9092
function count(y,x){
   var dy=[0,1,1,1];
   var dx=[1,-1,0,1];
   var max=1;
   for(var i=0;i<4;i++){
      var cnt=0;
      for(var j=0;j<=n;j++){
         var yy=y+(dy[i]*j);
         var xx=x+(dx[i]*j);
         if(yy<0 || xx<0 || yy>=n || xx>=n)break;
         if(yx[yy][xx]!=1)break;
         cnt++;
      }
      max=Math.max(max,cnt);
      cnt=0;
   }
   return max;
}
 
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var n=Arr.shift()-0;
   if(n==0)break;
   var yx=[];
   for(var i=0;i<n;i++){
      yx[i]=(Arr.shift()).split("").map(Number);
   }
   var max=0;
   for(var i=0;i<n;i++){
      for(var j=0;j<n;j++){
         if(yx[i][j]==1)max=Math.max(max,count(i,j));
      }
   }
   console.log(max);
}

Measured memory_bytes: 18428
#include<bits/stdc++.h>
using namespace std;
#define BeatMeScanf ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define sz 150010
const int mod=1000000007;

int main(){
    BeatMeScanf;
    int a,b,c;
    cin>>a>>b;

    if(a==1&&b==2) cout<<3<<endl;
    else if(a==2&&b==1) cout<<3<<endl;
    else if(a==1 && b==3) cout<<2<<endl;
    else if(a==3&&b==1) cout<<2<<endl;
    else cout<<1<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	input := scanString()
	c := input[0]
	fmt.Println(string(c + 1))
}

func scanString() (s string) {
	sc.Scan()
	return sc.Text()
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long
#define mid ((l+r)/2)
using namespace std;
int n,ans,a[222222],b[222222],t[888888];
void build(int l,int r,int p){
	if(l==r){t[p]=b[l];return;}
	build(l,mid,p*2),build(mid+1,r,p*2+1),t[p]=max(t[p*2],t[p*2+1]);
}
void update(int l,int r,int p,int c,int v){
	if(l==r){t[p]=v;return;}
	mid>=c?update(l,mid,p*2,c,v):update(mid+1,r,p*2+1,c,v);
	t[p]=max(t[p*2],t[p*2+1]);
}
int query(int l,int r,int p){
	if(l==r)return l;
	return t[p]==t[p*2]?query(l,mid,p*2):query(mid+1,r,p*2+1);
}
signed main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)scanf("%d",&b[i]);
	build(1,n,1),b[0]=b[n],b[n+1]=b[1];
	for(int tmp=n;tmp;){
		int p=query(1,n,1),d=b[p]-a[p],k=b[p+1]+b[p-1];
		if(!d){tmp--,update(1,n,1,p,0);continue;}
		if(d<k){printf("-1");return 0;}
		ans+=d/k,b[p]-=d/k*k,b[0]=b[n],b[n+1]=b[1];
		if(b[p]==a[p])tmp--,update(1,n,1,p,0);
		else update(1,n,1,p,b[p]);
	}
	printf("%lld",ans);
}

Measured memory_bytes: 10496
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define sz(x) int(x.size())
using ll = long long;
const ll LLINF = numeric_limits<long long>::max();
const int mod = 1000000007;
const int INF = 1001001001;

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

    if(s[2]==s[3]&&s[4]==s[5]){
        cout << "Yes";
    }
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

vector<bool> primeno(1000100, true);
void Eratosthenes(int n) {
    primeno[0] = primeno[1] = false;
    int limit = sqrt(n)+1;
    for(int i = 2; i < limit; ++i) {
        if(primeno[i]) {
            for(int j = 0; i*(j+2) < n; ++j) {
                primeno[i*(j+2)] = false;
            }
        }
    }
}

int n;

int main() {
    Eratosthenes(300000);
    while(1) {
        cin >> n;
        if(n == 0) break;
        int cnt = 0;
        for(int i = n+1; i <= 2*n; ++i) {
            if(primeno[i]) cnt++;
        }
        cout << cnt << endl;
    }
}


Measured memory_bytes: 3192
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

vector<int> calc_digits(int n) {
    vector<int> ans;

    if (n == 0) {
        ans.push_back(0);
        return ans;
    }

    while (n > 0) {
        ans.push_back(n % 10);
        n /= 10;
    }
    reverse(ans.begin(), ans.end());

    return ans;
}

int main(void) {
    int N, M;
    cin >> N >> M;

    // {s, c}
    vector<pair<int, int>> conds(M);
    for (int i = 0; i < M; i++) {
        cin >> conds[i].first;
        cin >> conds[i].second;
    }

    int ans = -1;
    for (int i = 0; i < 1000; i++) {
        vector<int> digits = calc_digits(i);
        // for (int d : digits) {
        //     cout << d << " ";
        // }
        // cout << endl;

        if ((int) digits.size() != N) {
            continue;
        }

        bool ok = true;
        for (auto cond : conds) {
            int s = cond.first;
            s--;
            int c = cond.second;
            if (s >= (int) digits.size()) {
                ok = false;
            }
            if (digits[s] != c) {
                ok = false;
            }
        }

        if (ok) {
            ans = i;
            break;
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static int dfs(int p, int q, int a, int n, int cur_pro, int prev_d){
		if(n < 0){
			return 0;
		}
		
		if(p == 0 && cur_pro <= a){
			return 1;
		}else if(n == 0){
			return 0;
		}
		
		int sum = 0;
		
		int divide = /* a */ a / cur_pro + 1;
		while(p * divide >= q){
			//System.out.println("[" + n +"]" + " 1 / " + divide);
			/*if(divide * cur_pro > a){
				divide--;
				continue;
			}else
			*/if(n * q < p * divide){
				divide--;
				continue;
			}else if(divide < prev_d){
				break;
			}
			
			final int upper = p * divide - q;
			final int downer = q * divide;
			
			sum += dfs(upper, downer, a, n - 1, cur_pro * divide, divide);
			
			divide--;
		}
		
		return sum;
	}
	
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			StringTokenizer tok = new StringTokenizer(br.readLine());
			final int p = Integer.parseInt(tok.nextToken());
			final int q = Integer.parseInt(tok.nextToken());
			final int a = Integer.parseInt(tok.nextToken());
			final int n = Integer.parseInt(tok.nextToken());
			
			if(p == 0 && q == 0 && a == 0 && n == 0){
				break;
			}
			
			int sum = dfs(p, q, a, n, 1, 0);
			
			System.out.println(sum);
		}
		
	}

}

Measured memory_bytes: 21628
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<vector>

using namespace std;

int main(void) {
	int N = 0, *X;

	scanf("%d", &N);
	vector<int> list(N);
	vector<int> list2(N);
	X = (int *)malloc(sizeof(int) * N);
	for (int i = 0; i < N; i++) {
		int j = 0;
		scanf("%d", &j);
		list[i] = j;
		list2[i] = j;
	}

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

	for (int i = 0; i < N; i++) {
		if (list2[i] < list[N / 2])
			printf("%d\n", list[N / 2]);
		else
			printf("%d\n", list[N / 2 - 1]);
	}

	return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define int long long
int dp[111][111][333];
signed main(){
  int n,w;
  cin>>n>>w;
  int a[n],b[n];
  for(int i=0;i<n;i++) cin>>a[i]>>b[i];
  int t=a[0];
  //cout<<n<<" "<<w<<" "<<t<<endl;
  for(int i=0;i<n;i++) a[i]-=t;
  memset(dp,-1,sizeof(dp));
  dp[0][0][0]=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<111;j++){
      for(int k=0;k<333;k++){
	if(dp[i][j][k]<0) continue;
	dp[i+1][j][k]=max(dp[i+1][j][k],dp[i][j][k]);
	if(k+a[i]<333)
	  dp[i+1][j+1][k+a[i]]=max(dp[i+1][j+1][k+a[i]],dp[i][j][k]+b[i]);
      }
    }
  }
  int ans=0;
  for(int j=0;j<111;j++){
    for(int k=0;k<333;k++){
    if(dp[n][j][k]<0) continue;
    if(j*t+k<=w) ans=max(ans,dp[n][j][k]);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 32256
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

test = False
if test:
    N = 2*10**5
    A = [i*2 for i in range(N)]
else:
    N = I()
    A = LI()

for idx in range(0, N):
    A[idx] -= idx + 1

import statistics
b = statistics.median(A)
#  print('b', b)
result = 0
for a in A:
    result += abs(a-b)
print(int(result))


Measured memory_bytes: 28528
n = gets.to_i
ss = gets.chomp.chars

r = ss.count("R")
g = ss.count("G")
b = ss.count("B")
ans = r * g * b

0.upto(n) do |i|
  j = 1

  while i + 2 * j < n
    k = i + 2 * j

    a = ss[i]
    b = ss[i + j]
    if a == b
      j += 1
      next
    end

    c = ss[k]
    ans -= 1 if b != c && c != a

    j += 1
  end
end

puts ans


Measured memory_bytes: 14392
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,k;
    cin>>a>>b>>c;
    cin>>k;
    
    for(int i=0;i<k;i++){
        int mx=max({a,b,c});
        if(mx==a) a=mx*2;  
        else if(mx==b) b=mx*2;
        else if(mx==c) c=mx*2;
    }
    
    cout<<a+b+c<<endl;
    
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
 
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int i,n,a=0,b=0;
        String s1,s2;
        n=sc.nextInt();
        
        for(i=0;i<n;i++) {
            s1=sc.next();
            s2=sc.next();
            
            if(s1.compareTo(s2)>0) {
                a+=3;
            }
            else if(s1.compareTo(s2)<0) {
                b+=3;
            }
            else if(s1.compareTo(s2)==0) {
                a+=1;
                b+=1;
            }
        }
        System.out.println(a+" "+b);
        
        sc.close();
    }
}



Measured memory_bytes: 29620
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)

ll nCi[50];//(n-1-i)Ci
int COUNT_SIZE = 10000005;


ll po(int n, ll k){//n^k%MOD
	ll ret;
	if(k == 1){
		return (ll)n;
	}else if(k%2 == 0){
		ll r = po(n,k/2);
		ret = r * r % MOD;
	}else{
		ret = n * po(n,k-1) % MOD;
	}
	return ret;
}




int main(void){
	ll n,m;
	cin>>n>>m;
	int p = 2;
	int count[COUNT_SIZE];
	rep(i,COUNT_SIZE){
		count[i] = 0;
	}
	while(p <= COUNT_SIZE - 5){
		if(m%p == 0){
			m = m/p;
			count[p]++;
		}else{
			p++;
		}
	}
	ll ans = 1;
	if(m > COUNT_SIZE - 5){
		ans = n;
	}

	nCi[0] = 1;
	nCi[1] = n;
	reps(i,39){
		nCi[i+1] = nCi[i] * (n+i) % MOD * po(i+1, MOD-2) % MOD;
	}
	reps(i,COUNT_SIZE - 5){
		ans = ans * nCi[count[i]] % MOD;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 39296
import itertools


pr = []
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    count = 0
    for c in itertools.combinations(range(1, n+1), 3):
        if sum(c) == x:
            count += 1
    pr.append(count)
for e in pr:
    print(e)


Measured memory_bytes: 5640
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N,X;
int32_t A[100000];


// 最大公約数（Greatest Common Divisor）
uint64_t gcd(uint64_t m, uint64_t n)
{
	// ユークリッドの互除法
	for (;;)
	{
		if (0 == m) { return n; }
		n %= m;
		if (0 == n) { return m; }
		m %= n;
	}
}
// 最小公倍数（Least Common Multiple）を返す。
uint64_t lcm(uint64_t m, uint64_t n)
{
	if (0 == m) { return n; }
	if (0 == n) { return m; }
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N >> X;
	for (size_t i = 0; i < N; i++)
	{
		in >> A[i];
		A[i] = std::abs(A[i]-X);
	}

	int32_t gcdtmp = A[0];
	for (size_t i = 1; i < N; i++)
	{
		gcdtmp = gcd(gcdtmp, A[i]);
	}
	out << gcdtmp << endl;


	return 0;
}
#endif

#if 0
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t H, W;

int map[500][500];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> H >> W;

	for (int32_t i = 0;i < H; i++)
	{
		for (int32_t j = 0; j < W; j++)
		{
			in >> map[i][j];
		}
	}

	int32_t x1=-1, y1=-1;
	for (int32_t i = 0; i < H; i++)
	{
		for (int32_t j = 0; j < W; j++)
		{
			if (map[i][j] % 2 == 1)
			{
				if (x1 == -1) {
					x1 = j; y1 = i;
				}
				else {
					int32_t x2 = j, y2 = i;
					while (x1 < x2) {
						out << y1+1 << ' ' << x1 + 1 << ' ' << y1 + 1 << ' ' << x1 + 1 + 1 << '\n';
						++x1;
					}
					while (x2 < x1) {
						out << y1 + 1 << ' ' << x1 + 1 << ' ' << y1 + 1 << ' ' << x1 + 1 - 1 << '\n';
						--x1;
					}
					while (y1 < y2) {
						out << y1 + 1 << ' ' << x1 + 1 << ' ' << y1 + 1 + 1 << ' ' << x1 + 1 << '\n';
						++y1;
					}
					while (y2 < y1) {
						out << y1 + 1 << ' ' << x1 + 1 << ' ' << y1 + 1 - 1 << ' ' << x1 + 1 << '\n';
						--y1;
					}

					x1 = -1, y1 = -1;
				}
			}
		}
	}
	out << std::flush;

	return 0;
}
#endif


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

int main(void){
    int n; cin >> n;
    vector<int>x(n),y;
    for(int i=0;i<n;i++) cin >> x[i];
    y = x; sort(y.begin(),y.end());
    int l=y[n/2-1],r=y[n/2];
    for(int i=0;i<n;i++){
        if(x[i]<=l) cout << r << endl;
        else cout << l << endl;
    }

    return 0;
}

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

int main(){
    // 制約見て！！！デカかったらlong longにすること！

    int x,y,z;
    cin >> x >> y >> z;
    x -= z;
    int ans = x/(y+z);
    cout<<ans<<endl;
}

Measured memory_bytes: 3556
(let* ((n (read))
       (s (make-array (list (1+ n)) :initial-element 0)))
  (loop :for i :from 1 :to n
        :for w := (read)
        :do (setf (aref s i) (+ (aref s (1- i)) w)))
  (let ((ans (aref s n)))
    (loop :for i :from 1 :to (1- n)
          :do (setf ans (min ans (abs (- (aref s n) (aref s i) (aref s i))))))
    (format t "~A~%" ans)))


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

int main() {
  int64_t a,b,c,k;
  cin >> a >> b >> c >> k;
  int64_t ans;
  
  if(a>k)
    ans = k;
  
  else{
    if(a+b > k)
      ans = a;
    else if (a+b+c <k)
      ans = a-c;
    else
      ans = a - (k-a-b);
  }
  cout << ans << endl;
}

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

using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define allpt(v) (v).begin(), (v).end()
#define allpt_r(v) (v).rbegin(), (v).rend()


const int mod = 1e9 + 7;
const string wsp = " ";
const string tb = "\t";
const string rt = "\n";

template <typename T>
void show1dvec(vector<T> v)
{
    if (v.size() == 0)
        return;
    int n = v.size() - 1;
    rep(i, n) cout << v[i] << wsp;
    cout << v[n] << rt;
    return;
}

template <typename T>
void show2dvec(vector<vector<T>> v)
{
    int n = v.size();
    rep(i, n) show1dvec(v[i]);
}

bool in_field(int h, int w, int y, int x)
{
    return 0 <= y && y < h && 0 <= x && x < w;
}

struct node
{
    int depth = -1;
    PII parent;
    vector<PII> children;
};

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    // int n, m, a, b, c;
    // cin >> n >> m;
    // vector<node> nodes(n);
    // vector<pair<int, int>> edges(n);
    // rep(i, m)
    // {
    //     cin >> a >> b >> c;
    //     a--, b--;
    //     edges[a] = make_pair(b, c);
    //     edges[b] = make_pair(a, c);
    // }

    int n;
    cin >> n;
    VL rain_into_dam(n), rain_on_mountain(n);
    rep(i, n) cin >> rain_into_dam[i];
    ll total_rain = accumulate(allpt(rain_into_dam), 0ll);
    rain_on_mountain[0] = total_rain;
    rep(i, n / 2) rain_on_mountain[0] -= 2 * rain_into_dam[2 * i + 1];
    rep(i, n - 1) rain_on_mountain[i + 1] = 2 * rain_into_dam[i] - rain_on_mountain[i];
    show1dvec(rain_on_mountain);

    return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    int sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    int ave = sum / n;
    int ans1 = 0;
    int ans2 = 0;
    rep(i, n) {
        ans1 += (a[i] - ave) * (a[i] - ave); 
        ans2 += (a[i] - ave-1) * (a[i] - ave-1); 
    }
    cout << min(ans1, ans2) << endl;
    return 0;
}


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

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    u32 K;
    string S;
    cin >> K >> S;
    if (S.size() <= K) {
        cout << S << endl;
    } else {
        cout << S.substr(0, K) << "..." << endl;
    }
}


Measured memory_bytes: 3572
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main(void) {
	int n, m, a; cin >> n >> m;
	int test[101] = { 0 };
	for (int h = 0; h < n; h++) {
		cin >> a;
		test[h] = a;
	}
	for (int h = 1; h <= m; h++) {
		for (int i = 0; i < n; i++) {
			if (i != n - 1 &&  test[i] % h > test[i + 1] % h) {
				int uio = test[i];
				test[i] = test[i + 1];
				test[i + 1] = uio;
			}
		}
	}
	for (int h = 0; h < n; h++) {
		cout << test[h] << endl;
	}
}


Measured memory_bytes: 3084
/* ex2_3
    kas056 */
 
#include <stdio.h>
 
int main(){
    int N, A;
    //入力読み込み
    scanf("%d", &N);
    scanf("%d", &A);
    //N^2－A を計算、出力
    printf("%d\n", N*N - A);
  
    return 0;
}

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

using namespace std;

long int fact(int n) {
    if (n == 1) {
        return 1;
    }
    return n * fact(n-1) % 1000000007;
}

int main() {
    int N;
    cin >> N;
    cout << fact(N) << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
  
int main(void){
  int i,n = 0;
  char w[11], t[1001];
  
  scanf("%s", w);
  
  do{
    scanf("%s",t);
    if(!strcmp(t,"END_OF_TEXT")) break;
      for(i=0;t[i]!='\0';i++)
        if(t[i]<91) t[i] += 32;
    if( !strcmp(w,t) ) n++;
  }while(1);
  
  printf("%d\n",n);
  
  return 0;
}


Measured memory_bytes: 2056
// AtCoder template
// 見た奴全員saba!
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

ll a, b, c, d, cd;

// 最大公約数を求める
// 計算量O(logn)
template<class T>
T gcd(T a, T b){
    if(b == 0) return a;
    return gcd(b, a%b);
}

// 最小公倍数を求める
// 計算量O(logn)
template<class T>
T lcm(T a, T b){
    return a/gcd(a,b)*b;
}

ll f(ll a){
    ll n_c = a/c;
    ll n_d = a/d;
    ll n_cd = a/cd;
    return a - (n_c + n_d - n_cd);
}

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

    cin >> a >> b >> c >> d;
    cd = lcm(c,d);
    cout << f(b) - f(a-1) << endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
int main(){
	int z;
	cin>>z;
	for(int i=1;i<=9;++i){
		string k(3,'0'+i);
		int p=stoi(k);
		if(p>=z){
			cout<<p;
			break;
		}
	}
}

Measured memory_bytes: 256
S=list(map(len,input().split("T")))
x,y=map(int,input().split())
x=abs(x-S[0])
y=abs(y)
L=S[2::2]
R=S[1::2]
sumL=sum(L)
sumR=sum(R)
flag=0
if sumL>=x and sumR>=y and (sumL-x)%2==0 and (sumR-y)%2==0 and flag==0:
    setL1={0}
    setR1={0}
    gL=(sumL-x)//2
    gR=(sumR-y)//2
    if gL==0:
        flag=1
    else:
        for i in L:
            setL=setL1
            setL1=set()
            s=setL1.add
            for j in setL:
                k=i+j
                s(k)
                s(j)
                if k==gL:
                    flag=1
                    break
            if flag==1:
                break
    if flag==1:
        if gR==0:
            flag=2
        else:
            for i in R:
                setR=setR1
                setR1=set()
                s=setR1.add
                for j in setR:
                    k=i+j
                    s(k)
                    s(j)
                    if k==gR:
                        flag=2
                        break
                if flag==2:
                    break
if flag==2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
#define sc scanf
#define pr printf
#define pb push_back
#define ll long long int
int main()
{
float x=0.0,n,a;
cin>>n;
while(n--)
{
    cin>>a;
    x+=(1/a);
}
cout<<fixed<<setprecision(10)<<1/x<<endl;
      return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>
#include <random>
#include <fstream>
#include <cfloat>
#include <complex>
using namespace std;
int main() {
	int n, k; 
	cin >> n >> k;
	vector<int> score(n); 
	for (auto& s : score) cin >> s;
	for (auto i = k; i < n; ++i) {
		if (score[i] > score[i - k]) {
			cout << "Yes\n";
		}
		else {
			cout << "No\n";
		}
	}
}

Measured memory_bytes: 4044
#ABC122B_Atcoder.rb
s = gets.chomp.chars
idx1 = 0
idx2 = 0
max = 0

while idx2 < s.size
  if s[idx1..idx2].grep(/[ACGT]/).size == s[idx1..idx2].size
    max = s[idx1..idx2].size if max < s[idx1..idx2].size
    idx2 += 1
    #puts "OK max=#{max} #{s[idx1..idx2].grep(/[ACGT]/)}"
  else
    idx2 += 1
    idx1 = idx2
    #puts "NG"
  end
end
puts max


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

#ifdef LOCAL
#include<debug.h>
#else
#define db(...) 21
#endif

#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 2e5 + 10;
ll fat[maxn], inv[maxn];

ll C(int n, int k)
{
  if(n < k) 
    return 0;
  if(n < 0 || k < 0) 
    return 0;
  return (((fat[n] * inv[k]) % mod) * inv[n - k]) % mod;
}

void initFactorials()
{
  fat[0] = 1;
  inv[0] = 1;
  for(int i = 1; i < maxn; i++)
  {
    fat[i] = (fat[i-1] * i) % mod;
    inv[i] = exp(fat[i], mod - 2);
  }
}

int main()
{
  ios::sync_with_stdio(false);
  int n,k;
  initFactorials();
  cin >> n >> k;
  ll ans = 0;
  for(int i = 0; i < min(n, k + 1); i++)
  {
    ans += (C(n, i) * C(n - 1, n - i - 1)) %  mod;
    ans %= mod;
  }

  cout << ans << endl;
  return 0;
}

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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  int H,W;
  cin >> H >> W;
  rep(i,H)rep(j,W){
    string s;
    cin >> s;
    if(s == "snuke"){
      cout << (char)('A'+j) << i+1 << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
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; }
const double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

    int N, C;
    cin >> N >> C;
    int X[N], V[N];
    rep(i,N){
        cin >> X[i] >> V[i];
    }
    int sum1[N]{}, sum2[N]{};
    int pot1[N]{}, pot2[N]{};
    int maxi1[N]{}, maxi2[N]{};
    sum1[0] = V[0] - X[0];
    pot1[0] = sum1[0] - X[0];
    sum2[N-1] = V[N-1] - (C - X[N-1]);
    pot2[N-1] = sum2[N-1] - (C - X[N-1]);
    maxi1[0] = max((int)0, sum1[0]);
    maxi2[N-1] = max((int)0, sum2[N-1]);
    int ans = max({(int)0, sum1[0], sum2[N-1]});
    for(int i=1;i<N;i++){
        sum1[i] = sum1[i-1] + V[i] - (X[i] - X[i-1]);
        chmax(ans, sum1[i]);
        pot1[i] = max(sum1[i] - X[i], pot1[i-1]);
        maxi1[i] = max(sum1[i], maxi1[i-1]);
    }
    for(int i=N-2;i>=0;i--){
        sum2[i] = sum2[i+1] + V[i] - (X[i+1] - X[i]);
        chmax(ans, sum2[i]);
        pot2[i] = max(sum2[i] - (C - X[i]), pot2[i+1]);
        maxi2[i] = max(sum2[i], maxi2[i+1]);
    }
    rep(i,N-1){
        chmax(ans, pot1[i]+maxi2[i+1]);
        chmax(ans, pot2[i+1]+maxi1[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6528
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	cnt := 1
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		if a == cnt {
			cnt++
		}
	}
	if cnt == 1 {
		fmt.Println(-1)
	} else {
		fmt.Println(n - cnt + 1)
	}
}


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

using ll = long long;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> L(M), R(M), D(M);
    vector<vector<pair<int, ll>>> edge(N);
    rep(i, M) {
        cin >> L[i] >> R[i] >> D[i];
        L[i]--;
        R[i]--;
        edge[L[i]].push_back(make_pair(R[i], D[i]));
        edge[R[i]].push_back(make_pair(L[i], -D[i]));
    }
    vector<bool> done(N, false);
    vector<ll> x(N, 0);
    rep(i, N) {
        if (done[i]) continue;
        ll minx = 0, maxx = 0;
        queue<pair<int, ll>> q;
        q.push(make_pair(i, 0));
        done[i] = true;
        while (!q.empty()) {
            auto p = q.front();
            q.pop();
            int j = p.first;
            ll y = p.second;
            x[j] = y;
            //cout << "x[" << j << "]:=" << x[j] << "\n";
            minx = min(minx, y);
            maxx = max(maxx, y);
            rep(k, edge[j].size()) {
                auto r = edge[j][k];
                if (done[r.first]) continue;
                q.push(make_pair(r.first, y + r.second));
                done[r.first] = true;
            }
        }
        if (maxx - minx > 1e9) {
            cout << "No\n";
            return 0;
        }
    }
    rep(i, M) {
        if (x[R[i]] - x[L[i]] != D[i]) {
            //rep(i, N) cout << "x[" << i << "]=" << x[i] << "\n";
            //cout << i << " ";
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
}

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

int main(){
  double a, b, c, d, e, f;
  
  while(cin >> a >> b >> c >> d >> e >> f){
    cout << fixed << setprecision(3);

    double x = (c*e-f*b)/(a*e-d*b) + 0;
    double y = (c-a*x)/b + 0;

    cout << x << " " << y << endl;
  }
}


Measured memory_bytes: 3288
# coding: utf-8

def closest_pair(P, n):
    if n <= 1:
        return float('inf')

    m = n // 2
    x = P[m][0]
    d = min(closest_pair(P[:m], m), closest_pair(P[m:], n-m))
    P.sort(key=lambda p: p[1])

    Q = []
    for p in P:
        if (p[0] - x)**2 >= d:
            continue

        for q in Q:
            dx = p[0] - q[0]
            dy = p[1] - q[1]

            if dy**2 >= d:
                break

            d = min(d, dx**2 + dy**2)

        Q.insert(0, p)

    return d


N = int(input())
P = [list(map(int, input().split())) for _ in range(N)]
P.sort()
print(closest_pair(P, N))





Measured memory_bytes: 101740
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n;
vector <int> a;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    a.resize(n);
    for(auto &i : a) cin >> i;
    vector <int> g(n), h(n);
    vector <int> s;
    for(int i = 0 ; i < n ; i++){
        while(s.size() && a[i] < a[s.back()]) s.pop_back();
        if(s.size()) g[i] = s.back();
        else g[i] = -1;
        s.push_back(i);
    }
    s.clear();
    for(int i = n - 1 ; i >= 0 ; i--){
        while(s.size() && a[i] < a[s.back()]) s.pop_back();
        if(s.size()) h[i] = s.back();
        else h[i] = n;
        s.push_back(i);
    }
    ll ans = 0;
    for(int i = 0 ; i < n ; i++){
        ans += 1LL * a[i] * (i - g[i]) * (h[i] - i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3832
#include<bits/stdc++.h>
using namespace std;
int main(){
  int w,h,x,y;
  cin >> w >> h >> x >> y;
  cout << fixed << setprecision(10) ;
  cout << (double)((double)w*(double)h)/2 << " " << ((x+x==w && y+y==h)?1:0) << endl;
}


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

int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    long long ans;
    if ((A + B) < (2 * C)) {
        ans = A * X + B * Y;
    } else {
        if (X < Y) {
            if (B < 2 * C) {
                ans = 2 * C * X + B * (Y - X);
            } else {
                ans = 2 * C * Y;
            }
        } else {
            if (A < 2 * C) {
                ans = 2 * C * Y + A * (X - Y);
            } else {
                ans = 2 * C * X;
            }
        }
    }
    cout << ans << endl;
}

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

typedef  long long ll;



int main(){

    int n;
    string s;
    cin>>n>>s;

    if(s.size()<=n){
        cout<<s<<endl;
    }
    else{
        string ans="";
        for(int i=0;i<n;i++) ans+=s[i];
        ans+="...";
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int N,M,X;
  cin>>N>>M>>X;
  vi A(M);
  rep(i,0,M) cin>>A[i];
  int ans=0;
  if(A[0]<X&&X<A[M-1]){
    int D=disup(A,X);
    ans=min(D,M-D);
    }
  cout<<ans;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 1e9+7;

int main(){
    ll N; cin >> N;
    vector<ll> A(N); for(int i = 0; i < N; i++) cin >> A[i];
    ll XOR = 0;
    for(int i = 0; i < N; i++) XOR = XOR ^ A[i];
    for(int i = 0; i < N; i++) cout << (XOR^A[i]) << " ";
    cout << endl;
}

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

#define fill(a,val) memset(a, (val), sizeof a)
#define pb push_back
#define lli long long int
#define scantype int
#define endl "\n"
#define unique(x) x.erase(unique(x.begin(),x.end()), x.end())
#define sort_f(x)  sort(x.begin(),x.end());
#define sort_r(x)  sort(x.rbegin(),x.rend());

lli MOD  = 1000000007;
lli inf = 1e15;

void scan(scantype &x);
lli powermod(lli _a,lli _b,lli _m){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
lli string_to_number(string s){lli x=0; stringstream convert(s); convert>>x; return x;}
lli add(lli a,lli b){lli x = (a+b)%MOD; return x; }
lli mul(lli a,lli b){lli x = (a*b)%MOD; return x; }
lli sub(lli a,lli b){lli x = (a-b+MOD)%MOD; return x; }
lli divi(lli a,lli b){lli x = a;lli y = powermod(b,MOD-2,MOD);lli res = (x*y)%MOD;return res;}

#define N 200003

long  divisors(long x) {
    long limit = x;
    long numberOfDivisors = 0;

    if (x == 1) return 1;

    for (long i = 1; i < limit; ++i) {
        if (x % i == 0) {
            limit = x / i;
            if (limit != i) {
                numberOfDivisors++;
            }
            numberOfDivisors++;
        }
        if(numberOfDivisors>=4)
        {
            break;
        }
    }

    return numberOfDivisors;
}
 bool isPrime(long n)
{
   
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
 
    for (long i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
 
    return true;
}
#define max_a 100001
bool visit[max_a]={false};
vector<long> a[max_a];
long sum=0;
long cost[max_a];
void dfs(long node)
{
    visit[node]=true;
    
    for(int i=0;i<(int)a[node].size();i++)
    {
        if(visit[a[node][i]]==false)
        {
            sum+=cost[a[node][i]];
            dfs(a[node][i]);
            
        }
    }
    
}
void SieveOfEratosthenes(int n)
{
   
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
 
    for (int p=2; p*p<=n; p++)
    {
        
        if (prime[p] == true)
        {
           
            for (int i=p*2; i<=n; i += p)
                prime[i] = false;
        }
    }
 
   
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string str="AC";
    string s;
    cin>>s;
    int flag=0;
    for(int i=0;i<(int)s.length()-1;i++)
    {
      if(s[i]==str[0] && s[i+1]==str[1])
      {
        flag=1;
      }
    }
    if(flag==1)
    {
      cout<<"Yes";
    }
    else
    {
      cout<<"No";
    }
    return 0;
}



Measured memory_bytes: 2560
#include<stdio.h>

int main(void)
{
	int t,n,i,a[4];
	for (i = 0;i < 4;i++)
	{
		scanf("%d %d",&t ,&n);
		if (t == 1) {a[i] = n * 6000;}
		else if (t == 2) {a[i] = n * 4000;}
		else if (t == 3) {a[i] = n * 3000;}
		else {a[i] = n * 2000;}
	}
	for (i = 0;i < 4;i++)
	{
		printf("%d\n", a[i]);
	}
	return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int n, w, i, v, card[][], a[][];
		String m;
		card = new int[4][13];
		a = new int[4][];
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();

		for(w = 0; w < 4; w++){
			for(v = 0; v < 13; v++){
				card[w][v] = 0;
			}
		}
		
		for(v = 0; n > v; v++){
			m = sc.next();
			i = sc.nextInt();
			switch(m){
			case "S" : card[0][i - 1] = 1;
						break;
			case "H" : card[1][i - 1] = 1;
						break;
			case "C" : card[2][i - 1] = 1;
						break;
			case "D" : card[3][i - 1] = 1;
						break;
			}
		}
		
		for(w = 0; w < 4; w++){
			for(v = 0; 13 > v; v++){
				if(card[w][v] == 0){
					switch(w){
					case 0 : System.out.println("S " + (v + 1));
								break;
					case 1 : System.out.println("H " + (v + 1));
								break;
					case 2 : System.out.println("C " + (v + 1));
								break;
					case 3 : System.out.println("D " + (v + 1));
								break;
					}
				}
			}
		}
	}
}

Measured memory_bytes: 26148