akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

using   lli     =   long long;
using   lld     =   long double;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<lld>;
const double PI = acos(-1);

#ifndef tejasp
#define trace(...) {}
#define cotra(...) {}
#define end_routine() {}
#define localsys 0
#define endl '\n'
#endif

inline lli mpow(lli a, lli b, lli m=mod) {
    a = a%mod;          b = b%(mod-1);
    if(a<0) a+=mod;     if(b<0) b+=mod-1;
    if(a==0) return 0;
    lli ans = 1;
    while (b) {
        if (b&1) ans=(ans*a)%m;
        a=(a*a)%m; b/=2;
    }
    return ans;
}

#define MAXN  1010
lli fact[MAXN], invf[MAXN], po[MAXN][MAXN];

void __prec()
{
    fact[0]=1;
    fol(i,1,MAXN) fact[i]=(fact[i-1]*i)%mod;
    fol(i,0,MAXN) invf[i]=mpow(fact[i],mod-2);
    fol(i,0,MAXN) fol(j,0,MAXN) po[i][j]=mpow(invf[i],j);
}

lli get(int n, int a, int k, int p)
{
    return (((((fact[n]*invf[a])%mod)*po[k][p])%mod)*invf[p])%mod;
}

std::vector<vl> dp(MAXN,vl(MAXN,0));

int tejas_919(int kkkk)
{
    lli n, m, k, q, u, v, temp=0, ans=0;
    lli a, b, c, d;
    cin>>n>>a>>b>>c>>d;
    trace(n,MAXN)
    dp[a-1][0]=1;
    fol(i,a,b+1) //size of each block
    {
        fol(j,0,MAXN) dp[i][j]=dp[i-1][j];
        fol(k,0,n)
        {
            if(dp[i-1][k]==0) continue;
            fol(j,c,d+1) //number of blocks
            {
                temp=k+(i*j);
                if(temp>n) break;
                dp[i][temp]+=(dp[i-1][k]*get(n-k,n-temp,i,j))%mod;
                dp[i][temp]%=mod;
            }
        }
    }
    cotra(dp)
    cout<<dp[b][n]<<endl;
    return 0;
}

signed main()
{
    #ifdef tejasp
            freopen("input.txt", "rt", stdin);
            freopen("output.txt", "wt", stdout);
    #endif
    if(!localsys) { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); }
    cout << fixed << setprecision(10);
    __prec();
    int t=1;
    //cin>>t;
    fol(i,0,t) { tejas_919(i+1); }
    end_routine();
    if(localsys) system("pause");
}


Measured memory_bytes: 16256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    ll n;
    cin >> n;
    vector<long long> vec(n);
    ll sum;
    vector<ll> sum_before(n);
    vector<ll> sum_after(n);
    rep(i, n){
        cin >> vec.at(i);
        if(i == 0){
            sum_before.at(i) = vec.at(i);
        }else{
            sum_before.at(i) = sum_before.at(i-1) + vec.at(i);
        }
    }
    rep(i,n){
        sum_after.at(i) = sum_before.at(n-1) - sum_before.at(i);
    }

    ll tmp = abs(sum_before.at(0) - sum_after.at(0));
    for(ll i = 1; i < n; i++){
        tmp = min(tmp, abs(sum_before.at(i) - sum_after.at(i)));
    }
    cout << tmp << endl;

}

Measured memory_bytes: 4992
using System;

class Program
{
	static void Main(string[] args)
	{
		int n = int.Parse(Console.ReadLine());

		long[] r = new long[n];
		for (int i = 0; i < n; i++)
		{
			r[i] = long.Parse(Console.ReadLine());
		}

		long max = -999999999;
		long min = r[0];
		for (int i = 1; i < n; i++)
		{
			max = Math.Max(max, r[i]-min);
			min = Math.Min(min, r[i]);
		}

		Console.WriteLine(max);
	}
}


Measured memory_bytes: 21076
import os
import sys
import numpy as np

def solve(N, M, A):
    # n 以上上がる方法だけを試した時に、M 回以上の握手を行うことができるか
    ok = 0
    ng = 202020
    while ok + 1 < ng:
        c = ok+ng >> 1
        cnt = 0
        idx_A = N-1
        for a1 in A:
            while idx_A >= 0 and A[idx_A]+a1 < c:
                idx_A -= 1
            cnt += idx_A + 1
        if cnt >= M:
            ok = c
        else:
            ng = c
    idx_A = N-1
    cum_A = np.zeros(len(A)+1, dtype=np.int64)
    cum_A[1:] = np.cumsum(A)
    ans = 0
    cnt = 0
    for a1 in A:
        while idx_A >= 0 and A[idx_A]+a1 < ok:
            idx_A -= 1
        cnt += idx_A + 1
        ans += cum_A[idx_A+1] + (idx_A+1)*a1
    ans -= (cnt-M) * ok
    return ans


# >>> numba compile >>>
numba_config = [
    [solve, "i8(i8,i8,i8[:])"],
]
if sys.argv[-1] == "ONLINE_JUDGE":
    from numba import njit
    from numba.pycc import CC
    cc = CC("my_module")
    for func, signature in numba_config:
        vars()[func.__name__] = njit(signature)(func)
        cc.export(func.__name__, signature)(func)
    cc.compile()
    exit()
elif os.name == "posix":
    exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
else:
    from numba import njit
    for func, signature in numba_config:
        vars()[func.__name__] = njit(signature, cache=True)(func)
    print("compiled!", file=sys.stderr)
# <<< numba compile <<<


def main():
    N, M = map(int, input().split())
    A = np.array(sorted(map(int, input().split()), reverse=True), dtype=np.int64)
    ans = solve(N, M, A)
    print(ans)

main()


Measured memory_bytes: 39144
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi frist
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> void read(T &x){
	int f=0; x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f|=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	if(f) x=-x;
}

const int N=200005;
int a[N],c[N],n,K;

int main(){
	read(n),read(K);
	rep(i,1,n){
		read(a[i]);
	}
	rep(k,1,K){
		memset(c,0,sizeof c);
		rep(i,1,n){
			int l=max(1,i-a[i]);
			int r=min(n,i+a[i]);
			c[l]++,c[r+1]--;
		}
		int flag=0;
		rep(i,1,n){
			c[i]+=c[i-1];
			a[i]=c[i];
			if(a[i]<n){
				flag=1;
			}
		}
		if(!flag){
			break;
		}
	}
	rep(i,1,n){
		printf("%d%c",a[i]," \n"[i==n]);
	}
	return 0;
}


Measured memory_bytes: 5276
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define print(A,n) for(ll i=0;i<n;++i)cout<<A[i]<<' ';cout<<endl;
#define take(A,n) for(ll i=0;i<n;++i)cin>>A[i];
ll mulmod(ll a,ll b,ll c) 
{ 
    if (b==0) 
        return 0; 
    ll s = mulmod(a, b/2, c); 
    if (b%2==1) 
        return (a%c+2*(s%c)) % c; 
 
    else
        return (2*(s%c)) % c; 
} 
 
  
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
int main()
{ll int tc;
//t=1;
tc=1;
 
while(tc--)
{ll int n,k,i;
cin>>n>>k;
double a[n];
double ans;
for(i=0;i<n;i++)
{cin>>a[i];
    if(i>0)
    a[i]+=a[i-1];
}
ans= (a[k-1]+k)/2;
for(i=0;i<n-k;i++)
{double temp = (a[i+k]-a[i]+k)/2;
    if(temp>ans)
    ans=temp;
}
   cout<<setprecision(12)<<ans;
}
 
    return 0;
}

Measured memory_bytes: 1792
function Main(input){ 
  var input = input.trim();
  switch(input){
    case "A":
      console.log("T");
    break;
    case "C":
      console.log("G");
    break;
    case "G":
      console.log("C");
    break;
    case "T":
      console.log("A");
    break;
  }
}
  Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7496
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

A,B = S()
if ord(A) > ord(B):
    print('>')
if ord(A) == ord(B):
    print('=')
if ord(A) < ord(B):
    print('<')

Measured memory_bytes: 77460
/* 
 * Author: aps
 * Time: 2020-01-26 21:43:11
**/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
 
using namespace __gnu_pbds;
using namespace std;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
 
const ll inf = 1e18;
const ll mod = 1e9+7;
 
inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x;}
inline ll sub(ll x, ll y) { x -= y; if (x < 0) x += mod; return x;}
inline ll mul(ll x, ll y) { return ((x % mod) * (y % mod)) % mod;}
inline ll gcd(ll x, ll y) { return x == 0 ? y : gcd(y % x, x); }
inline ll power(ll a, ll b) {
    ll x = 1;
    while (b) {
        if (b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}
inline ll inv(ll a) { return power(a, mod - 2);}

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

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    int h, n, sum = 0; cin >> h >> n; 
    vi a(n,0);
    for(int i=0; i<n; i++) {
        cin >> a[i];
    }
    sum = accumulate(all(a),sum);
    if(sum >= h) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}










Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

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

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

int main()
{
  int N;
  cin >> N;
  int ans = INT32_MAX;
  rep(i, N - 1)
  {
    int A = i + 1;
    int B = N - A;
    int score = 0;
    while (A != 0)
    {
      score += A % 10;
      A /= 10;
    }

    while (B != 0)
    {
      score += B % 10;
      B /= 10;
    }
    ans = min(ans, score);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main()
{
	char str1[10];
	char str2[10];
	scanf("%s %s",str1,str2);
	int a,b;
	scanf("%d%d",&a,&b);
	char str[10];
	scanf("%s",str);
	if(strcmp(str,str1)==0) printf("%d %d",a-1,b);
	else printf("%d %d",a,b-1);
	return 0;
}

Measured memory_bytes: 128
import math
a,b=input().split()
tmp = float(b)*1000
#print(int(int(a)*float(b)))
ans = int(a) * int(math.floor(tmp))
#print(ans)

ans = str(ans)
l = len(ans)

if l < 3:
    print(int(0))
else:
    print(int(ans[:l-3]))

Measured memory_bytes: 9188
import sys
n, k = map(int, sys.stdin.readline().split())
h = list(map(int, sys.stdin.readline().split()))

dp = [0 for _ in range(n)]
dp[0] = 0
for i in range(1, n):
    cost = []
    for j in range(i-k, i):
        if j < 0: continue
        cost.append(abs(h[i]-h[j]) + dp[j])
    dp[i] = min(cost)
print(dp[-1])


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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int X, Y;
    cin >> X >> Y;
    
    cout << X + Y / 2 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
  int N; cin >> N;
  vector<int> P(N), Q(N), v(N);
  int p, q;
  rep(i, N) cin >> P[i];
  rep(i, N) cin >> Q[i];
  rep(i, N) v[i] = i+1;

  int cnt = 0;
  do {
    cnt++;
    bool match_p = true, match_q = true;
    rep(i, N) if(v[i] != P[i]) match_p = false;
    rep(i, N) if(v[i] != Q[i]) match_q = false;
    if(match_p) p = cnt;
    if(match_q) q = cnt;
  } while(next_permutation(v.begin(), v.end()));
  cout << abs(q-p) << endl;

  return 0;
}


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

int main(){
  int N;
  cin >> N;
  
  for(int i=0;i<N;i++){
    int l,r,sum,ans;
    cin >> l >> r;
    
    sum = r-l+1;
    
    ans += sum;
    
    if( i == N-1 ){
    cout << ans << endl;}
  }
}

Measured memory_bytes: 256
from pprint import pprint

# import math
# import collections

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

c = []
for i in range(3):
    c.append(list(map(int, input().split(' '))))

diff_v = [[0] * 3 for i in range(3)]
diff_h = [[0] * 3 for i in range(3)]

for i in range(0, 3):
    for j in range(0, 3):
        if i > 0:
            diff_v[i][j] = c[i][j] - c[i - 1][j]

for j in range(0, 3):
    for i in range(0, 3):
        if j > 0:
            diff_h[j][i] = c[i][j] - c[i][j - 1]


def map_all(es):
    return all([e == es[0] for e in es[1:]]) if es else False


eq_v = all([map_all(d) for d in diff_v])
eq_h = all([map_all(d) for d in diff_h])

if eq_v and eq_h:
    print('Yes')
else:
    print('No')


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

void BubbleSort(vector<string> &B, int N) {
  for (int i = 0; i <= N-1; i++) {
    for (int j = N-1; j >= i+1; j--) {
      if (B[j][1] < B[j-1][1]) {
         swap(B[j], B[j-1]);
      }
    }
  }
}
void SelectionSort(vector<string> &S, int N) {
  for (int i = 0; i <= N-1; i++) {
    int minj = i;
    for (int j = i; j <= N-1; j++) {
      if (S[j][1] < S[minj][1]) {
        minj = j;
      }
    }
    if (minj != i) {
      swap(S[i], S[minj]);
    }
  }
}
bool isStable(vector<string> in, vector<string> out, int N) {
  for (int i = 0; i <= N - 1; i++) {
    for (int j = i + 1;  j <= N - 1; j++) {
      for (int a = 0; a <= N - 1; a++) {
        for(int b = a + 1; b <= N - 1; b++) {
          if (in[i][1] == in[j][1] && in[i] == out[b] && in[j] == out[a]) {
            return false;
          }
        }
      } 
    }
  }
  return true;
}

int main() {
  int N;
  cin >> N;
  vector<string> in(N);
  vector<string> B(N);
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    string tmp;
    cin >> tmp;
    in[i] = tmp;
    B[i] = tmp;
    S[i] = tmp;
  }
  /* バブルソート */
  BubbleSort(B, N);
  for (int i = 0; i < N; i++) {
    cout << B[i];
    if (i == N - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
  string stableB = isStable(in, B, N) ? "Stable" : "Not stable";
  cout << stableB << endl;

  /* 挿入ソート */
  SelectionSort(S, N);
  for (int i = 0; i < N; i++) {
    cout << S[i];
    if (i == N - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
  string stableS = isStable(in, S, N) ? "Stable" : "Not stable";
  cout << stableS << endl;
}


Measured memory_bytes: 3180
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int A, B, C;
    ll K;
    cin >> A >> B >> C >> K;
    cout << (K % 2 == 0 ? A - B : B - A) << endl;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define int ll

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

  string s;
  cin>>s;
  reverse(rng(s));
  int N=s.size();
  vector<vector<ull>>dp(N+1,vector<ull>(13,0));
  dp[0][0]=1;
  vector<int>d={1,10,9,12,3,4};
  for(int i=1;i<=N;i++){
    if(s[i-1]!='?'){
      int n=(int)(s[i-1]-'0');
      for(int j=0;j<13;j++){
        ll a;
        if(i==1) a=(j-n)%13;
        else a=(j-(n*d[(i-1)%6])%13)%13;
        if(a<0)a+=13,a%=13;
        dp[i][j]=(dp[i-1][a]%MOD+dp[i][j]%MOD)%MOD;
      }
    }
    else{
      for(int j=0;j<13;j++){
        for(int k=0;k<=9;k++){
          ll a;
          if(i==1)a=(j-k)%13;
          else a=(j-((k*d[(i-1)%6])%13))%13;
          if(a<0)a+=13,a%=13;
          dp[i][j]=(dp[i-1][a]%MOD+dp[i][j]%MOD)%MOD;
        }
      }
    }
  }
  cout<<dp[N][5]%MOD<<endl;
  return 0;
}


Measured memory_bytes: 13648
#include <iostream>

using namespace std;

int main() {
    int x, a, b;
    cin >> x >> a >> b;

    if (b - a <= 0) {
        cout << "delicious" << endl;
    } else if (b - a <= x) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10**7)

stdin = sys.stdin

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

a, b, c, k = na()
ans = 0
if a >= k:
    print(k)
else:
    res = k - a
    ans += a
    if b >= res:
        print(ans)
    else:
        print(ans - (res - b))

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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return abs(x-y)/gcd(x,y); }


int main() {
  int w,h,n; cin >> w >> h >> n;
  vector<int> x(n),y(n),a(n); for(int i=0;i<n;i++) { cin >> x[i] >> y[i] >> a[i]; }

  int xmin=0, xmax=w, ymin=0, ymax=h;
  for(int i=0;i<n;i++) {
    if(a[i] == 1) { xmin = max(xmin,x[i]); }
    else if(a[i] == 2) { xmax = min(xmax,x[i]); }
    else if(a[i] == 3) { ymin = max(ymin,y[i]); }
    else if(a[i] == 4) { ymax = min(ymax,y[i]); }
  }

  if(xmin >= xmax || ymin >= ymax) { cout << 0 << endl; }
  else { cout << (xmax-xmin)*(ymax-ymin) << endl; }
  return 0;
}

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

int main() {
  long long n, k;
  cin >> n >> k;
  long long cntsum = 0;
	for (int i=k;i<=n+1;i++){
		long long sum=(i*(n-i+1)+1)%1000000007;
		cntsum=(cntsum+sum)%1000000007;
	}
  cout << cntsum << endl;
}


Measured memory_bytes: 3636
#include <stdio.h>

#define MAX 100001
#define max(a,b) ((a) < (b) ? (b) : (a))

int par[MAX],sib[MAX],deg[MAX];
int height[MAX],dep[MAX];

void init(int);
int depth(int,int);

int main(){
  int n,i,id,l,r;

  scanf("%d" ,&n); 
  init(n);  

  for(i = 0 ; i < n ; i++){
    scanf("%d%d%d" ,&id ,&l ,&r);

    if(l != -1){
      par[l] = id;
      deg[id]++;
    }
    if(r != -1){
      par[r] = id;
      deg[id]++;
    }
    if(l != -1 && r != -1){
      sib[l] = r;
      sib[r] = l;
    }
  }

  for(i = 0 ; i < n ; i++){
    dep[i] = depth(i,0);
  }

  for(i = 0 ; i < n ; i++){
    printf("node %d: parent = %d, sibling = %d, " 
	   ,i, par[i], sib[i]);

    printf("degree = %d, depth = %d, height = %d, " 
	   , deg[i], dep[i], height[i]);
    
    if(par[i] == -1){
      printf("root\n");
    }else if(deg[i] != 0){
      printf("internal node\n");
    }else{
      printf("leaf\n");
    }
  }

  return 0;
}

void init(int n){
  int i;

  for(i = 0 ; i < n ; i++){
    par[i] = sib[i] = -1;
    deg[i] = height[i] = 0;
  }
}

int depth(int x,int dep){
  height[x] = max(height[x],dep);
  if(par[x] == -1){
    return dep;
  }else{
    return depth(par[x],dep+1);
  }
}


Measured memory_bytes: 2148
float x[100],y[100],t,u,a,b;n,i,j,k,c,s;main(m){for(;m=scanf("%d",&n),c=i=n;printf("%d\n",m))for(;!c?j=--i:scanf("%f,%f",x+c,y+--c);)for(;s=!c&&j--;)for(u=acos(hypot(a=x[j]-x[i],b=y[j]-y[i])/2),t=atan2(b,a);c=0,u<9&&s+3;s-=2)for(a=x[i]+cos(b=t+s*u),b=y[i]+sin(b),k=n;k--;)hypot(a-x[k],b-y[k])<1.1&&++c>m?m=c:0;}

Measured memory_bytes: 0
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' '); 
            int n = Int32.Parse(input[0]);
            int m = Int32.Parse(input[1]);

            var data = new string[n][];
            for(int i = 0; i < n; i++)
            {
                data[i] = Console.ReadLine().Split(' ');
            }

            var matchNum = data[0];
            matchNum[0] = "XX";
            for(int i = 1; i < n; i++)
            {
                var line = data[i].Skip(1);
                for(int j = 1; j < matchNum.Length; j++)
                {
                    if(!line.Contains(matchNum[j]))
                    {
                        matchNum[j] = "XX";                        
                    }
                }
            }

            int result = 0;
            foreach(string s in matchNum)
            {
                if(s != "XX")
                    result++;
            }

            Console.WriteLine(result);
        }      
    }
}


Measured memory_bytes: 13280
import itertools

N, M, Q = map(int, input().split())
a = [0] * Q
b = [0] * Q
c = [0] * Q
d = [0] * Q

for i in range(Q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

maxx = 0
for p in itertools.combinations_with_replacement(range(M), N):
    sum = 0
    for j in range(Q):
        if p[b[j] - 1] - p[a[j] - 1] == c[j]:
            sum += d[j]
    maxx = max(sum, maxx)
print(maxx)

Measured memory_bytes: 9220
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;
 
}
ll NcR(int n, int r) 
{ 
    ll p = 1, k = 1; 
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
            ll m=__gcd(p, k); 
            p /= m; 
            k /= m; 
            n--; 
            r--; 
        } 
    } 
    else
        p = 1; 
    return p;
}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x)
{
    return (ll)(log(x)/log(base));
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll i,j,l,m,n,k,x;
    	cin>>k>>x;
    	if(k*500>=x)
    	cout<<"Yes";
    	else
    	cout<<"No";
    	
    	
    	
    }
	return 0;
}

Measured memory_bytes: 256
#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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    string T;
    for(int i = 0; i < S.size(); i++) {
        if(i & 1) continue;
        T.push_back(S[i]);
    }
    cout << T << endl;
    return 0;
}


Measured memory_bytes: 592
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define eps 1e-6
#define ll  long long
#define endl '\n'
bool isPrime(ll a)
{
  ll count=0,i;
  rep(i,2,a/2+1)
    if(a%i==0) count++;
    if(count) return false;
    else return true;
}
void solve()
{
  ll n, a,m=0,b=1, k=0, i, j,l=2e9+7;
  string s, r, y;
  cin>>n;
 while(n)
 {
   if(isPrime(n)) {cout<<n;break;}
   n++;}
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
  // cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int a;
    cin>>a;
    cout << a+a*a+a*a*a << endl;

    



}


Measured memory_bytes: 3648
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

vector<vector<int> > edge(100005);
int ans[100005];

int solve(int v) {
  vector<int> tmpans;
  for(int i=0;i<edge[v].size();++i) {
    tmpans.push_back(solve(edge[v][i]));
  }
  sort(tmpans.begin(), tmpans.end());
  int ans1=0;
  for(int i=0;i<tmpans.size();++i) {
    ans1 = max(ans1, tmpans[i])+1;
  }
  return ans1;
}

int main() {
  int N;
  cin>>N;
  int tmp;
  for(int i=0;i<N-1;++i) {
    cin>>tmp;
    tmp--;
    edge[tmp].push_back(i+1);
  }
  cout<<solve(0)<<endl;
}



Measured memory_bytes: 17948
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
W = [input() for _ in range(N)]

if len(set(W)) != len(W):
	print("No")
	exit()

for i in range(1, N):
	if W[i-1][-1] != W[i][0]:
		print("No")
		exit()

print("Yes")

Measured memory_bytes: 5576
N = int(input())
S = list(input())

R = 0
G = 0
B = 0

for i in range(N):
	if S[i] == 'R':
		R += 1
	elif S[i] == 'G':
		G += 1
	else:
		B += 1
ans = R * G * B
for i in range(N - 2):
	for j in range(i + 1, N - 1):
		k = j + (j - i)
		if k >= N:
			break
		if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
			ans -= 1
print(ans)


Measured memory_bytes: 9208
#define _CRT_SECURE_NO_WARNINGS
#include <cassert>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
ll MOD = 1000000007LL;
#include <set>
#include <deque>

int N;
char ss[13] = "A";

void go(int i, char nc) {
	if (i == N) {
		puts(ss);
		return;
	}

	for (char c='a'; c<nc; c++) {
		ss[i] = c;
		go(i+1, nc);
	}
	ss[i] = nc;
	go(i+1, nc+1);
}

int main() {
	cin >> N;
	go(0, 'a');


	return 0;
}

Measured memory_bytes: 1536
#include<stdio.h>

int main(){
	int a, b, c, x;
	scanf("%d%d%d", &a, &b, &c);
	
	if(a > b){
		x = a;
		a = b;
		b = x;
	}
	if(a > c){
		x = a;
		a = c;
		c = x;
	}
	if(b > c){
		x = b;
		b = c;
		c = x;
	}
	
	printf("%d %d %d\n", a, b, c);
	
	return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define turbo cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define inf 999999999999999

using namespace std;

const int gr = 305;
int n;

long double dp[gr][gr][gr];
bool w[gr][gr][gr];

long double calc(int a, int b, int c){
  if(a<0 or b<0 or c<0)
    return 0;
  if(a==0 and b==0 and c==0)
    return 0;
  if(w[a][b][c]) return dp[a][b][c];
  w[a][b][c] = true;
  long double sum = (long double)(a+b+c);
  dp[a][b][c] = (long double)(n/sum) + (long double)(calc(a-1,b,c)*double(a/sum)) + (long double)(calc(a+1,b-1,c)*double(b/sum)) + (long double)(calc(a,b+1,c-1)*(long double)(c/sum));
  //cout << "a b c dp " << a << " " << b << " " << c << "\n";
  return dp[a][b][c];
}

int main(){
    turbo
    int x,a=0,b=0,c=0;
    cin >> n;
    for(int i=0;i<n;i++){
      cin >> x;
      if(x==1)
        a++;
      if(x==2)
        b++;
      if(x==3)
        c++;
    }
    printf("%.10Lf",calc(a,b,c));

    return 0;
}


Measured memory_bytes: 465152
#include<iostream>
using namespace std;
int main() {
	long long x1, y1, x2, y2, x3, y3, s;
	cin >> s;
	x1 = y1 = 0;
	x2 = 1e9, y2 = 1;
	x3 = (x2 - s % x2) % x2;
	y3 = (s + x3) / x2;
	cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
	return 0;
}

Measured memory_bytes: 3608
//#include "/Users/doomzday/Programming/stdc++.h"

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ldb = long double;

#define forn(i, x, n) for (int i = x; i < n; ++i)
#define forb(i, x, n) for (int i = x; i >= n; --i)
#define mmax(a, b, c) max(a, max(b, c))
#define mmin(a, b, c) min(a, min(b, c))
#define pb push_back
#define mp make_pair

const int N = 100500 * 1;

ll a[N];

int main() {
    int n;
    cin >> n;
    forn(i, 0, n) {
        cin >> a[i];
    }

    if (a[n - 1] != 2) {
        cout << "-1\n";
        return 0;
    }

    ll mn = 2, mx = 3;
    int cur = n - 2;
    while (cur >= 0) {
        if (a[cur] > mx) {
            cout << "-1\n";
            return 0;
        }

        ll d1 = (mn / a[cur] + (mn % a[cur] ? 1 : 0)),
            d2 = (mx / a[cur]);

        mn = a[cur] * d1;
        mx = a[cur] * (d2 + 1) - 1;

        if (mn > mx) {
            cout << "-1\n";
            return 0;
        }

        --cur;
    }

    cout << mn << " " << mx << '\n';
}

Measured memory_bytes: 1024
a = set(["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"])
s = input()
if len(s)<26:
    b = list(a-set(s))
    b.sort()
    print(s+b[0])
else:
    for i in range(2,27):
        if s[-i] < s[-i+1]:
            break
        if i == 26:
            print(-1)
            exit()
    for j in sorted(s[-i+1:]):
        if j > s[-i]:break
    print(s[:-i]+j)

Measured memory_bytes: 38256
n = int(input())
cnt = 0
for i in range(1, n + 1):
    cnt2 = 0
    for j in range(1, i + 1):
        if i % j == 0 and i % 2 != 0:
            cnt2 += 1
    if cnt2 == 8:
        cnt += 1
print(cnt)


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int main()
{
	for(int i=1;i>0;i++)
	{
		int x;
		cin>>x;
		if(x==0)
		{
			break;
		}
		cout<<"Case"<<" "<<i<<":"<<" "<<x<<endl;
	}
		return 0;
}

Measured memory_bytes: 1160
/*
  Vivek Rathi
  CSE 2nd Year
  MNNIT
*/
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long int
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define present(c,x) ((c).find(x) != (c).end())
#define null NULL
#define mp make_pair
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf 1e17
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//-------------------------------Template--Above------------------------------------------------
ll n,k;
ll a[51][51];
ll I[51][51];
void multiply(ll a1[][51],ll a2[][51])
{
	ll a3[51][51]={0};
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<n;j++)
		{
			for(ll k=0;k<n;k++)
			{
				a3[i][j]=(a3[i][j]+(a1[i][k]*a2[k][j])%M)%M;
			}
		}
	}
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<n;j++)
		{
			a1[i][j]=a3[i][j];
		}
	}
}
void MatPow(ll mat[][51],ll pow)
{
	if(pow==0)
	{
		for(ll i=0;i<n;i++)
		{
			for(ll j=0;j<n;j++)
			{
				mat[i][j]=I[i][j];
			}
		}
		return;
	}
	MatPow(mat,pow/2);
	if(pow%2==0)
		multiply(mat,mat);
	else
	{
		multiply(mat,mat);
		multiply(mat,a);
	}
	return;
}
int main()
{
	boost
	cin>>n>>k;
	ll ca[51][51];
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<n;j++)
		{
			cin>>a[i][j];
			if(i!=j)
				I[i][j]=0;
			else
				I[i][j]=1;
			ca[i][j]=a[i][j];
		}
	}
	MatPow(ca,k);
	ll co=0;
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<n;j++)
		{
			co=(co+ca[i][j])%M;
		}
	}
	cout<<co<<endl;
	return 0;
}


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

using namespace std;

int main(){
	char s[4];
	char t[4];
	scanf("%s %s", s, t);
	int ans = 0;
	for (int i = 0; i < 3; i++){
		if (s[i] == t[i])
			ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
s = []
t = []
for _ in range(n):
    a, b = input().split()
    s.append(a)
    t.append(int(b))
x = input()

ct = 0
for i in range(n):
    if (x == s[n-1 - i]):
        break
    else:
        ct += t[n-1 - i]

print(str(ct))


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

int jump_cost_acc[1000000];

// 6
// 30 10 60 10 60 50
int jump_cost(int * arr, int n)
{
    if(jump_cost_acc[n]!=-1) return jump_cost_acc[n];
    
    if(n<=1) return 0;
    else if (n==2) return abs(arr[1] - arr[0]);

    jump_cost_acc[n] =  min(abs(arr[1] - arr[0]) + jump_cost(arr+1, n-1), abs(arr[2] - arr[0]) + jump_cost(arr+2, n-2) );
    return jump_cost_acc[n];
    
}

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

    for(int i =0;i<1000000;i++)jump_cost_acc[i] = -1;
	jump_cost_acc[0] = 0;
	jump_cost_acc[1] = 0;
//	jump_cost_acc[2] = 1;
    cout<<jump_cost(arr,n);
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

vector<int> c(26);
vector<vector<int>> s(365 ,vector<int>(26));
vector<vector<int>> last(365 ,vector<int>(26));

int calc(int d){
    int k=18;
    int ret=1;
    ll maxv=-INF;
    rep(j,26){
        ll v=s[d][j]+c[j]*(d+1-last[d][j]);
        rep(i,k) v-=c[j]*k;
        if(v>maxv){
            maxv=v;
            ret=j+1;
        }
    }
    return ret;
}

int main(){
    int D;
    cin>>D;
    rep(i,26){ 
        cin>>c[i];
    }
    rep(d,D) rep(j,26) cin>>s[d][j];
    int t;
    int v=0;
    vector<int> kaisai_bi(26);
    int ans=18398+s[1][16];
    rep(j,26){
        if(j==16)continue;
        else if(j==0)ans-=c[j]*(2-1);
        else ans-=c[j]*(2-0);
    }
    rep(d,D) {
//        cin>>t;
        t=calc(d);
        cout<<t<<endl;
        t--;
        v+=s[d][t];
        kaisai_bi[t]=d+1;
        rep(j,26) last[d][j]=kaisai_bi[j];
        rep(j,26){ 
            v-=c[j]*(d+1-last[d][j]);
            }
    }
//    cout<<v<<endl;

    int m;
//    cin>>m;
m=0;
    rep(i,m){
        int dd,q;
        cin>>dd>>q;
        q--;
        int j=0;
        while(last[dd-1][j]!=dd || j>=26) j++;
        if(j==26){ 
            cout<<"error"<<endl;
            return 0;
        }
        v-=s[dd-1][j];
        for(int d=dd-1;d<D;d++){ 
            if(last[d][j]==dd){
                v+=c[j]*(d+1-last[d][j]);
                last[d][j]=(d==0? 0 : last[d-1][j]);
                v-=c[j]*(d+1-last[d][j]);
            }
            else{ 
                break;
            }
        }
        
        v+=s[dd-1][q];
        int before=last[dd-1][q];
        for(int d=dd-1;d<D;d++){ 
            if(last[d][q]==before){ 
                v+=c[q]*(d+1-last[d][q]);
                last[d][q]=dd;
                v-=c[q]*(d+1-last[d][q]);
            }
            else{ 
                break;
            }
        }
        cout<<v<<endl;
    }
    return 0;
}


Measured memory_bytes: 3692
package main

import (
	"fmt"
	"sort"
)

// 2019-03-31T23:37:06+0800
// 2019-03-31T23:44:53+0800
// 2019-03-31T23:56:49+0800
func main() {
	var N int
	fmt.Scanf("%d", &N)
	a := make([]int, N)
	n := 0
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &a[i])
		n += a[i]
	}
	out := solve(a)
	fmt.Println(out)
}

func solve(a []int) int {
	N := len(a)
	sort.Ints(a)
	if a[N-1] < N {
		return 0
	}
	total := 0
	for i := N - 1; i >= 0; i-- {
		if a[i] < N {
			break
		}
		times := a[i] / N
		left := a[i] % N
		total += times

		for ii := 0; ii < N; ii++ {
			a[ii] += times
		}
		a[i] = left
	}
	return total + solve(a)
}

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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;

bool cmp(pair<pair<string,ll>,ll> a,pair<pair<string,ll>,ll> b) {
	return ((a.fi.fi<b.fi.fi) || (a.fi.fi==b.fi.fi && a.fi.se>b.fi.se));
}

void solve(){
	ll n;
	cin>>n;
	vector<pair<pair<string,ll>,ll>> A(n);
	for(int i=0;i<n;i++){
		cin>>A[i].fi.fi>>A[i].fi.se;
		A[i].se=i+1;
	}
	sort(all(A),cmp);
	for(int i=0;i<n;i++)
		cout<<A[i].se<<"\n";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;

	//ll t;cin>>t;while(t--)
	solve();

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define pull pair<ull, ull>
#define F first
#define S second
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl
#define printArr(a, start, end)for(int i=start ; i<end ; ++i)cout << a[i] << " ";
#define readArr(a, start, end)for(int i=start ; i<end ; ++i)cin >> a[i];
#define read2D(mat, n, m)for(int i=0 ; i<n ; ++i)for(int j=0 ; j<m ; ++j)cin >> mat[i][j];

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

void solve(){
	int n;
	cin >> n;
	
	vll a(n);
	for(ll& x : a){
		cin >> x;
	}
	
	sort(all(a), greater<ll>());
	
	ll ans=a[0];
	int cnt=2;
	for(int i=1 ; i<n ; ++i){
		if(cnt == n)break;
		ans += 2*a[i];
		cnt += 2;
		if(cnt > n){
			ans -= a[i];
			break;
		}
	}
	
	cout << ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int tt=1;
	//cin >> tt;
	
	while(tt--){
		solve();
	}
}


Measured memory_bytes: 4748
import math

A,B,H,M = map(int, raw_input().split())

hour_rad = (H*60+M)*2.0/(12*60)
min_rad = M*2/60.0

diff_rad = max(hour_rad,min_rad) - min(hour_rad,min_rad)
if diff_rad > 1:
	diff_rad = 2 - diff_rad
dist_sq = A**2 + B**2 - 2*A*B*math.cos(diff_rad*math.pi)

print math.sqrt(dist_sq)

Measured memory_bytes: 64708
n = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
kaisu = 0
itta = Hash.new
itta.default = 0
loops = Array.new
now=0
n[1].times{|t|
    loops.push(now)
    itta[now]+=1
    if itta[a[now]-1] != 0 then
        #loopsから探す 長さ取る
        hidari = loops.find_index(a[now]-1)
        migi = loops.length - hidari

        puts loops[((n[1]-hidari)%migi)+hidari]+1
        exit
    end
    now=(a[now]-1)
}
puts now+1

Measured memory_bytes: 39100
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

long calc(string[] g) {
    int rows = cast(int) g.length;
    int cols = cast(int) g[0].length;

    int toIndex(int row, int col) { return row * cols + col; }

    auto uf = new UnionFind(rows * cols);
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            if (i + 1 < rows) {
                if (g[i][j] != g[i + 1][j]) uf.unite(toIndex(i, j), toIndex(i+1, j));
            }
            if (j + 1 < cols) {
                if (g[i][j] != g[i][j + 1]) uf.unite(toIndex(i, j), toIndex(i, j+1));
            }
        }
    }

    long ans = 0;
    bool[int] used;
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            int root = uf.root(toIndex(i, j));
            if (root in used) continue;
            used[root] = true;

            long a = 0; // 黒の個数
            long b = 0; // 白の個数
            // root に属する全てのノード
            uf.doEach(root, (node) {
                int row = node / cols;
                int col = node % cols;
                if (g[row][col] == '#') a++; else b++;
            });
            ans += a * b;
        }
    }
    return ans;
}

void main() {
    auto hw = readints;
    int h = hw[0], w = hw[1];
    string[] g;
    for (int i = 0; i < h; i++) {
        g ~= read!string;
    }
    writeln(calc(g));
}

class UnionFind {
    private int[] _data;
    private int[] _nexts; // 次の要素。なければ -1
    private int[] _tails; // 末尾の要素

    this(int n) {
        _data  = new int[](n + 1);
        _nexts = new int[](n + 1);
        _tails = new int[](n + 1);

        _data[] = -1;
        _nexts[] = -1;
        for (int i = 0; i < _tails.length; i++)
            _tails[i] = i;
    }

    int root(int a) {
        if (_data[a] < 0) return a;
        return _data[a] = root(_data[a]);
    }

    bool unite(int a, int b) {
        int ra = root(a);
        int rb = root(b);
        if (ra != rb) {
            if (_data[rb] < _data[ra]) swap(ra, rb);
            _data[ra] += _data[rb]; // ra に rb を繋げる
            _data[rb] = ra;
            // ra の末尾の後ろに rb を繋げる
            _nexts[_tails[ra]] = rb;
            // ra の末尾が rb の末尾になる
            _tails[ra] = _tails[rb];
        }
        return ra != rb;
    }

    bool isSame(int a, int b) {
        return root(a) == root(b);
    }

    /// a が属する集合のサイズ
    int groupSize(int a) {
        return -_data[root(a)];
    }

    /// a が属する集合の要素全て
    void doEach(int a, void delegate(int) fn) {
        auto node = root(a);
        while (node != -1) {
            fn(node);
            node = _nexts[node];
        }
    }
}


Measured memory_bytes: 17404
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n;
  cin >> n;
  int odd = (n + 1) / 2;
  printf("%.10f\n", double(odd) / double(n));
}

Measured memory_bytes: 256
// Beginner160.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <bits/stdc++.h>
#include <iostream>

using  namespace std;

int main()
{
	string s;
	cin >> s;
	cout << (s[2] == s[3] && s[4] == s[5] ? "Yes" : "No") << '\n';
}



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


void solve(long long N, std::vector<long long> H){
    int now_max = 0;
    int count = 0;
    for (int i = 0; i < N; i++) {
        if (H[i] >= now_max) {
            count++;
            now_max = H[i];
        }
    }
    cout << count << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> H(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&H[i]);
    }
    solve(N, std::move(H));
    return 0;
}


Measured memory_bytes: 256
N = int(input())
F = []
P = []
for _ in range(N):
    F.append(list(map(int, input().split())))
for _ in range(N):
    P.append(list(map(int, input().split())))

ans = -1000000000


for i in range(1, 1024):
    tmp = 0
    c = [0] * N
    ii = list(str(format(i, 'b')).zfill(10))
    for j in range(N):
        for k in range(10):
            if str(F[j][k]) == ii[k] and ii[k] == '1':
                c[j] += 1
    for j in range(N):
        tmp += P[j][c[j]]
    if tmp > ans :
        ans = tmp

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
int N;
cin >> N;
vector<int> vec(N);
for (int i = 0;i < N;i++) {
  cin >> vec.at(i);
}
int A = 0,B = 0;
sort(vec.begin(),vec.end());
reverse(vec.begin(),vec.end());
for (int i = 0;i < N;i += 2) A += vec.at(i);
for (int i = 1;i < N;i += 2) B += vec.at(i);

cout << A - B << endl;

return 0;
}


Measured memory_bytes: 256