akhauriyash/Code-Regression huggingface dataset:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
import itertools
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    h,w,k = map(int,ipt().split())
    s = [list(map(int,list(input()))) for _ in [0]*h]
    '''
    sms = [[0]*w for _ in [0]*h]
    for i in range(w):
        for j in range(h):
            sms[j][i] = sms[j-1][i]+s[j][i]
        print(i)
    '''
    cmi = 10**18
    for i in range(2**(h-1)):
        pos = [0]*h
        for j in range(h-1):
            if (i >> j) & 1:
                pos[j+1] = pos[j]+1
            else:
                pos[j+1] = pos[j]
        cmii = pos[-1]
        si = [0]*h
        for jj in range(h):
            si[pos[jj]] += s[jj][0]
        if max(si) > k:
            continue
        f = True
        for j in range(1,w):
            if f:
                for ii in range(h):
                    if si[pos[ii]]+s[ii][j] > k:
                        cmii += 1
                        si = [0]*h
                        for jj in range(h):
                            si[pos[jj]] += s[jj][j]
                        if max(si) > k:
                            f = False
                        break
                    else:
                        si[pos[ii]]+=s[ii][j]
        if f and cmii < cmi:
            cmi = cmii
    print(cmi)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 44376
import sys

N=int(input())
XYH=[list(map(int,input().split())) for i in range(N)]

for i in range(101):
    for j in range(101):
        LIST=[]
        for xyh in XYH:
            if xyh[2]==0:
                continue
            else:
                LIST.append(abs(i-xyh[0])+abs(j-xyh[1])+xyh[2])

        if min(LIST)==max(LIST):
            i0,j0,h0=i,j,LIST[0]
        else:
            continue


        CHECK=1


        for xyh in XYH:
            if xyh[2]==0:
                if abs(i0-xyh[0])+abs(j0-xyh[1])<h0:
                    CHECK=0

        if CHECK==1:
            print(i0,j0,h0)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  map<string, Int> ans;
  ans["SUN"] = 7;
  ans["MON"] = 6;
  ans["TUE"] = 5;
  ans["WED"] = 4;
  ans["THU"] = 3;
  ans["FRI"] = 2;
  ans["SAT"] = 1;

  string s;
  cin>>s;
  cout<<ans[s]<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll a, b;
  cin >> a >> b;

  rep(i, 1000000) {
    if ((i * 8)/100 == a and (i * 10)/100 == b) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <cmath>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <set>
using ll = long long;
using namespace std;
#define INF 999999999

int main()
{
    int N, A, B;
    cin >> N >> A >> B;
    vector<int> p(N);
    for (int i = 0; i < N; i++)
        cin >> p[i];
    int tmp1 = 0, tmp2 = 0, tmp3 = 0;
    for (auto v : p)
    {
        if (v <= A)
            tmp1++;
        else if (A < v && v <= B)
            tmp2++;
        else
            tmp3++;
    }
    cout << min(min(tmp1, tmp2), tmp3) << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    K = int(input())
    X = [int(i) for i in input().split()]
    ans = 0
    for x in X:
        ans += 2*x if abs(x - 0) < abs(K - x) else abs(K - x) * 2
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

//! dp[i番目まで使った時][合計の重さ]=価値の最大値
ll dp[105][10005];

pii vw[105];

int main()
{
	int N, W;
	cin >> N >> W;
	REP(i, N)
	{
		cin >> vw[i + 1].first >> vw[i + 1].second;
	}

	memset(dp, 0, sizeof(dp));
	FOR(i, N + 1, 1)
	{
		REP(w, W + 1)
		{
			dp[i][w] = dp[i - 1][w];
			if (w - vw[i].second < 0)
			{
				continue;
			}
			dp[i][w] = std::max(dp[i - 1][w - vw[i].second] + vw[i].first, dp[i - 1][w]);
		}
	}
	ll max = 0;
	REP(w, W + 1)
	{
		max = std::max(dp[N][w], max);
	}
	cout << max << endl;
	return 0;
}


Measured memory_bytes: 11340
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
 int n,k;
 cin >> n >> k;
 VI l(n);
 rep(i,n)cin >> l[i];
 sort(l.begin(),l.end());
 reverse(l.begin(),l.end());
 int ans=0;
 rep(i,k){
    ans+=l.at(i);
 }
  cout << ans << endl;
}



Measured memory_bytes: 3616
long A,B,C=1,D=6,E=19,F,M=998244353,m;b,c,N,s[4];
main(f){
	for(;read(0,&c,1),c-10;s[c-97]++,f&=b!=c,b=c)
		m=N?N%3?m:m*2%M:M-3,
		F=N++?(5*E-6*D+2*C-10*B+12*A)%M:65,A=B,B=C,C=D,D=E,E=F;
	printf("%d\n",!*s+!s[1]+!s[2]>1?:(A+(N%3|*s%3-s[2]%3?f:N>3?m+f:m)+M)%M);
}

Measured memory_bytes: 128
#include <stdio.h>
int main(){
  int a,b,c,d,p,x,y;
  scanf("%d %d %d %d %d",&a,&b,&c,&d,&p);
  x = a * p;
  if(c <= p){
    y = b + (d * (p - c));
  }else{
    y = b;
  }
  if(x < y){
    printf("%d\n",x);
  }else{
    printf("%d\n",y);
  }
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef long long int64;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
template<class T,class U>bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}
template<class T,class U>bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}
template<class T,class U>void vcin(T &v, U n){rep(i, n){typename T::value_type a;cin >> a;v.pb(a);}}
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cill(n);
    double pi = 3.141592;
    double ans = n * 2 * pi;


    co(ans);

    return 0;
}

Measured memory_bytes: 3792
#include "bits/stdc++.h"
#include<vector>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<iomanip>
#include<assert.h>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<stack>
#include<complex>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;
	
#define WHATS(var)cout<<__LINE__<<' '<<#var<<"="<<var<<endl;
	
template<class S, class T> ostream& operator <<(ostream &os, const pair<S, T> v){
	os << "( " << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<T> &v){
	for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<vector<T>> &v){
	for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<set<T>> &v){
	for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const set<T> &v){
	int i=0;
	for(auto it:v){
		if(i > 0){os << ' ';}
		os << it;
		i++;
	} 
	return os;
}
using ll=long long ;

int main() {
	ios::sync_with_stdio(false);
	// int a,b,c,d;cin>>a>>b>>c>>d;
	// cout<<(int(b>d))<<endl;

	// int N;cin>>N;
	// int answer=-1;
	// for(int i=1;i<50000;++i){
	// 	int j=i*108;
	// 	j/=100;
	// 	if(j==N){
	// 		answer=i;
	// 		break;
	// 	}
	// }
	// if(answer==-1)cout<<":("<<endl;
	// else cout<<answer<<endl;

	int N;cin>>N;
	string st;cin>>st;
	//vector<vector<int>>dp(4,vector<int>(30001));
	int answer=0;
	for(int i=0;i<1000;++i){
		vector<int>v;
		int k=i;
		for(int j=0;j<3;++j){
			v.push_back(k%10);
			k/=10;
		}
		
		int now=0;
		for(auto c:st){
			if(now<3&&v[now]==c-'0'){
				now++;
			}
		}
		if(now==3)answer++;
	}

	cout<<answer<<endl;
	return 0;
}

Measured memory_bytes: 384
a,b,c,d,t;main(n){for(;~scanf("%d",&n);printf("%d\n",t))for(t=a=0;a<=9;a++)for(b=0;b<=9;b++)for(c=0;c<=9;c++)for(d=0;d<=9;d++)a+b+c+d-n||t++;exit(0);}

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


int philiaPalindrome(string kalimat, int hitung){
    int len;
    string sub;
    len = kalimat.length();
    if (len==0 || len==1) {
        return hitung;
    }
    else
    {
        if (kalimat[0]!=kalimat[len-1]) {
            hitung +=1;
        }
    }
    sub = kalimat.substr(1, len-2);
    return (philiaPalindrome(sub,hitung));
}

int main() {
    string sebuahkalimat;
    int berapa=0;
    cin>>sebuahkalimat;
    berapa = philiaPalindrome(sebuahkalimat,berapa);
    cout<<berapa<<endl;
    
    return 0;
}

Measured memory_bytes: 256
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt, gcd
from copy import deepcopy


def main():
    n = int(input())
    a_list = tuple(map(int, input().split()))
    num = 1e18
    ans = 1
    if (0 in a_list):
        print(0)
        sys.exit()
    for i in range(n):
        ans *= a_list[i]
        if ans > num:
            print(-1)
            sys.exit()

    
    if ans <= num:
        print(ans)
    else:
        print(-1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 86516
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define LINY "YES\n"
#define Liny "Yes\n"
#define LINN "NO\n"
#define Linn "No\n"
#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"

int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a*b /gcd(a,b);}

int main(){
  ll INF = pow(10,9)+7;
  ll N,M; cin>>N >> M;
  ll a;
  ll mask[N]; INIT(mask,N,1);
  REP(i,M){
    cin >> a;
    --a;
    mask[a] = 0;
  }
  ll r[N] = {0};
  r[0] = mask[0];
  r[1] = (mask[1]==1 ? r[0]+1:0);
  for(int i=2;i<N;i++){
    if(mask[i]==0){r[i] = 0;}
    else{r[i] = (r[i-2]+r[i-1])%INF;}
  }
  cout << r[N-1];
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;
template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a/b; a -= t*b; swap(a, b); u -= t*v; swap(u, v); }
        return ModInt(u);
    }
    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if (e%2 == 0) { p = (p*p)%mod; e /= 2; }
            else { a = (a*p)%mod; e--; }
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

void compression(vector<int> &v) {
    int rank = 0;
    set<int> s;
    map<int, int> m;
    for (auto &c : v) s.emplace(c);
    for (auto &c : s) m[c] = rank++;
    for (auto &c : v) c = m[c];
    v.erase(unique(v.begin(), v.end()), v.end());
}

int main() {
    using mint = ModInt<MOD>;
    int n;
    cin >> n;
    vector<int> c(n);
    for (auto &e : c) cin >> e;
    compression(c);
    int m = *max_element(c.begin(), c.end());
    
    mint ans = 1;
    vector<mint> data(m+1, 0);
    for (auto e : c) {
        ans += data[e];
        data[e] = ans;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 19840
#import bisect,collections,copy,heapq,itertools,math,numpy,string
#from operator import itemgetter
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
S = [S() for _ in range(N)]
dict = {}

for s in S:
	dict[s] = 1
print(len(dict))


Measured memory_bytes: 38468
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] A = new int[N];

        for(int i=0; i<N; i++){
            A[i] = sc.nextInt();
        }

        if((N-1)%(K-1)==0){
            System.out.println((N - 1) / (K - 1));
        }
        else{
            System.out.println((N - 1) / (K - 1) + 1);
        }
    }
}

Measured memory_bytes: 51876
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int MOD;

int addm(int a, int b)
{
	return (0LL + a + b) % MOD;
}

int mulm(int a, int b)
{
	return (1LL * a * b) % MOD;
}

int main()
{
	long long N;
	int X, M;
	cin >> N >> X >> M;
	MOD = M;

	vector<int> a;
	vector<bool> v(M, false);

	a.push_back(X);
	v[X] = true;
	int loop;
	for (;;) {
		int y = mulm(a.back(), a.back());
		if (v[y]) {
			loop = find(a.begin(), a.end(), y) - a.begin();
			break;
		}
		a.push_back(y);
		v[y] = true;
	}

	int length = a.size();
	int prefix = loop;
	int period = length - prefix;

	long long ans = 0;
	for (int i = 0; i < N && i < prefix; ++i) {
		ans += a[i];
	}
	if (N > prefix) {
		N -= prefix;
		auto q = N / period;
		auto r = N % period;

		long long sum = 0;
		for (int i = prefix; i < length; ++i) {
			sum += a[i];
		}
		ans += sum * q;
		for (int i = prefix; i < prefix + r; ++i) {
			ans += a[i];
		}
	}

	cout << ans << endl;
}



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

#define PB              push_back
#define MP              make_pair
#define xx              first
#define yy              second
#define abs(x)          ((x)<0?-(x):(x))
#define D(x)            cout << #x << ": " << x << endl
#define un(v)           (v).erase(unique((v).begin(),(v).end()),(v).end())
#define ITERATE(it, v)  for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)

typedef long long LL;
typedef pair <int, int> pii;

const LL oo = 2147383647;
const double pi = 2 * acos (0.0);
const double eps = 1e-9;

inline LL gcd(LL a, LL b) {
    a = abs(a); b = abs(b);
    while (b) { a = a % b; swap (a, b); } return a;
}

LL ext_gcd(LL A, LL B, LL *X, LL *Y) {
    LL x2, y2, x1, y1, x, y, r2, r1, q, r;
    x2 = 1; y2 = 0;
    x1 = 0; y1 = 1;
    for(r2 = A, r1 = B; r1 != 0; r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y ) {
        q = r2 / r1;
        r = r2 % r1;
        x = x2 - (q * x1);
        y = y2 - (q * y1);
    }
    *X = x2; *Y = y2;
    return r2;
}

inline LL modInv(LL a, LL m) {
    LL x, y;
    ext_gcd(a, m, &x, &y);
    x %= m;
    if ( x < 0 ) x += m; //modInv is never negative
    return x;
}

inline LL power(LL a, LL p) {
    LL res = 1, x = a;
    while (p) {
        if (p & 1) res = (res * x);
        x = (x * x); p >>= 1;
    }
    return res;
}

inline LL bigmod(LL a, LL p, LL m) {
    LL res = 1 % m, x = a % m;
    while (p) {
        if (p & 1) res = (res * x) % m;
        x = (x * x) % m; p >>= 1;
    }
    return res;
}

///<-------------------------------------------------END OF TEMPLATE-------------------------------------------------->

const int N = 100001;

int x[N], y[N];
LL dpX[N], dpY[N];
const LL mod = 1e9 + 7;

int main() {

    int n, m;
    scanf("%d %d", &n, &m);

    for(int i = 1; i <= n; i++) scanf("%d", x + i);
    for(int i = 1; i <= m; i++) scanf("%d", y + i);

    for(int i = 1; i <= n; i++) {
        dpX[i] = (LL) (i - 1) * (LL) x[i];
        dpX[i] -= (LL) (n - i) * (LL) x[i];
        while(dpX[i] < 0) dpX[i] += mod;
        dpX[i] %= mod;
    }

    for(int i = 1; i <= m; i++) {
        dpY[i] = (LL) (i - 1) * (LL) y[i];
        dpY[i] -= (LL) (m - i) * (LL) y[i];
        while(dpY[i] < 0) dpY[i] += mod;
        dpY[i] %= mod;
    }

    for(int i = 2; i <= n; i++) dpX[i] += dpX[i - 1], dpX[i] %= mod;
    for(int i = 2; i <= m; i++) dpY[i] += dpY[i - 1], dpY[i] %= mod;

    printf("%lld\n", (dpX[n] * dpY[m]) % mod);

    return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
#include<math.h>
#define DEBUG 0

struct Icetea
{
	unsigned long long int price;
	double amount;
	long double perprice;
	int index;
	int n;
};

void print_tea(struct Icetea size[])
{
	int i;
	for(i=0; i<4; i++)printf("price:%lld, price_perL:%Lf\n", size[i].price, size[i].perprice);
}

int main()
{
	struct Icetea size[4];
	unsigned long long int N, n;
	int i, j;
	unsigned long long sum;
	struct Icetea tmp;
	float amount_table[4] = {0.25, 0.5, 1, 2};

	//input
	for(i=0; i<4; i++)
	{
		scanf("%lld", &size[i].price);
		size[i].perprice = (float)size[i].price/amount_table[i];
		size[i].index = i;
		size[i].amount = amount_table[i];
	}
	scanf("%lld", &N);	

	//sort
	for(i=0; i<4; ++i){
		for(j=i+1; j<4; ++j){
			if(size[i].perprice > size[j].perprice)
			{
				tmp = size[i];
				size[i] = size[j];
				size[j] = tmp;
			}
		}
	}

#if DEBUG
print_tea(size);
printf("%lld\n", N); 
#endif

	sum = 0;
	for(i=0; i<4; i++){
		n = N/size[i].amount;
		if(n>=1)sum += size[i].price*n;
		N = N - n*size[i].amount;
		//printf("[%d] n: %lld,  sum:%lld, N:%lld\n", i, n, sum, N);
		if(N<=0)break;
	}

	printf("%lld\n", sum);

	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  int H, W;
  cin>>H>>W;
  int d[10][10];
  REP(i, 10) REP(j, 10){
    cin>>d[i][j];
  }
  REP(k, 10) REP(i, 10) REP(j, 10){
    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  }

  int work;
  int ans=0;
  REP(i, H)REP(j, W){
    cin>>work;
    if(work!=-1) ans += d[work][1];
  }
  cout<<ans<<endl;



  return 0;
}


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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int H, W;
string S[440];
bool visited[440][440];
pint dfs(int y, int x) {
    if (visited[y][x]) { return {0, 0}; }
    visited[y][x] = true;
    pint ret = {0, 0};
    if (S[y][x] == '#') { ret.first++; }
    else { ret.second++; }
    rep(i, 4) {
        int ny = y + dy[i], nx = x + dx[i];
        if (ny < 0 || ny >= H || nx < 0 || nx >= W || S[y][x] == S[ny][nx]) { continue; }
        pint p = dfs(ny, nx);
        ret.first += p.first;
        ret.second += p.second;
    }
    return ret;
}
signed main() {
    cin >> H >> W;
    rep(i, H) { cin >> S[i]; }
    int ans = 0;
    rep(i, H) {
        rep(j, W) {
            pint p = dfs(i, j);
            ans += p.first * p.second;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 18176
/*
(1)for binary shift operator always use 'LL' 1LL<<63

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set_pair tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
  const double  pi=3.1415926535; 
  struct pair_hash
{
	template <class T1, class T2>
	std::size_t operator () (std::pair<T1, T2> const &pair) const
	{
		std::size_t h1 = std::hash<T1>()(pair.first);
		std::size_t h2 = std::hash<T2>()(pair.second);

		return h1 ^ h2;
	}
};
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll a,b,c;
	set<ll> s;
	cin>>a>>b>>c;
	s.insert(a);
	s.insert(c);
	s.insert(b);
	cout<<s.size();

	return 0;
} 

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


typedef string::const_iterator State;


int expression(State &begin);


int number(State &begin)
{
	int ret = 0;
	
	for(; isdigit(*begin); begin++) {
		ret = ret * 10 + *begin - '0';
	}

	return ret;
}

int factor(State &begin)
{
	if(*begin == '(') {
		begin++;
		int ret = expression(begin);
		begin++;
		
		return ret;
	} else {
		return number(begin);
	}
}

int term(State &begin)
{
	int ret = factor(begin);

	while(true) {
		if (*begin == '*') {
			begin++;
			ret *= factor(begin);
		} else if (*begin == '/') {
			begin++;
			ret /= factor(begin);
		} else {
			break;
		}
	}

	return ret;
}

int expression(State &begin)
{
	int ret = term(begin);

	while(true) {
		if (*begin == '+') {
			begin++;
			ret += term(begin);
		} else if (*begin == '-') {
			begin++;
			ret -= term(begin);
		} else {
			break;
		}
	}

	return ret;
}


int main()
{
	int N;
	cin >> N;
	cin.ignore();
		
	for (int i = 0; i < N; i++) {
		string s;
		getline(cin, s);

		State begin = s.begin();
		cout << expression(begin) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1212
#include <iostream>
using namespace std;
typedef long long ll;
bool seen[5];
ll cnt[5];

int main() {
  int N;
  cin >> N;
  string s[N];
  int kind = 0;
  for (int i = 0; i < N; i++) cin >> s[i];
  for (int i = 0; i < N; i++) {
    char f = s[i].at(0);
    if (f == 'M') {
      if (!seen[0]) {
        seen[0] = true;
        kind++;
      }
      cnt[0]++;
    }
    if (f == 'A') {
      if (!seen[1]) {
        seen[1] = true;
        kind++;
      }
      cnt[1]++;
    }
    if (f == 'R') {
      if (!seen[2]) {
        seen[2] = true;
        kind++;
      }
      cnt[2]++;
    }
    if (f == 'C') {
      if (!seen[3]) {
        seen[3] = true;
        kind++;
      }
      cnt[3]++;
    }
    if (f == 'H') {
      if (!seen[4]) {
        seen[4] = true;
        kind++;
      }
      cnt[4]++;
    }
  }
  if (N < 3) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 0;
  for (int i = 0; i < 5; i++) {
    for (int j = i + 1; j < 5; j++) {
      for (int k = j + 1; k < 5; k++) {
        ans += cnt[i] * cnt[j] * cnt[k];
      }
    }
  }

  if (ans <= 0) {
    cout << 0 << endl;
  } else
    cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6144
N,K=gets.split.map(&:to_i)
p=gets.split.map(&:to_i)

sum=Array.new(N-K+1,0)

p.map!{|i| (i+1)/2.0}
sum=0
K.times do |i|
  sum+=p[i]
end
max=sum
(N-K).times do |i|
  sum=sum-p[i]+p[i+K]
  if sum > max
    max=sum
  end
end

puts max

Measured memory_bytes: 16260
import sys
input = sys.stdin.readline
num = []
num = [int(i) for i in input().split()]

syou = []
dai = []

for temp in range(num[1]):
    suuzi = []
    suuzi = [int(i) for i in input().split()]
    syou.append(suuzi[0])
    dai.append(suuzi[1])

result= min(dai) - max(syou) + 1
if result > 0:
    print(result)
else:
    print(0)

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

using namespace std; 

int main()
{
	int n,k,q,aux,auxq;
	cin>>n>>k>>q;
	auxq=q;
	vector<int>v(n,k);
	while(q--)
	{
		cin>>aux;
		v[aux-1]++;
	}
	for(int i=0;i<n;i++)
	{
		if(v[i]>auxq)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	}
	return 0;		
}




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

#define ll  long long int

#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>



void boost()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

ll mod=1e9+7;



int main()
{
    
    boost();
    ll n,i,j,t,x,y,m,k;
    cin>>n;
    ll a[n][3],dp[n][3];
    for(i=0;i<n;i++)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for(i=1;i<n;i++)
    {
        dp[i][0]=max({dp[i-1][0],a[i][0]+dp[i-1][1],a[i][0]+dp[i-1][2]});
        dp[i][1]=max({dp[i-1][1],a[i][1]+dp[i-1][0],a[i][1]+dp[i-1][2]});
        dp[i][2]=max({dp[i-1][2],a[i][2]+dp[i-1][1],a[i][2]+dp[i-1][0]});
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
    return 0;
}

Measured memory_bytes: 4992
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    vector<int> v;
    rep(i, 4) v.push_back(S[i] - '0');
    if(v[0] + v[1] + v[2] + v[3] == 7) {cout << v[0] << "+" << v[1] << "+" << v[2] << "+" << v[3] << "=7" << endl;}
    else if(v[0] + v[1] + v[2] - v[3] == 7) {cout << v[0] << "+" << v[1] << "+" << v[2] << "-" << v[3] << "=7" << endl;}
    else if(v[0] + v[1] - v[2] + v[3] == 7) {cout << v[0] << "+" << v[1] << "-" << v[2] << "+" << v[3] << "=7" << endl;}
    else if(v[0] + v[1] - v[2] - v[3] == 7) {cout << v[0] << "+" << v[1] << "-" << v[2] << "-" << v[3] << "=7" << endl;}
    else if(v[0] - v[1] + v[2] + v[3] == 7) {cout << v[0] << "-" << v[1] << "+" << v[2] << "+" << v[3] << "=7" << endl;}
    else if(v[0] - v[1] + v[2] - v[3] == 7) {cout << v[0] << "-" << v[1] << "+" << v[2] << "-" << v[3] << "=7" << endl;}
    else if(v[0] - v[1] - v[2] + v[3] == 7) {cout << v[0] << "-" << v[1] << "-" << v[2] << "+" << v[3] << "=7" << endl;}
    else if(v[0] - v[1] - v[2] - v[3] == 7) {cout << v[0] << "-" << v[1] << "-" << v[2] << "-" << v[3] << "=7" << endl;}

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

#define MAXN 100000
const int M[15]={0,1,6,9,36,81,216,729,1296,6561,7776,46656,59049};
int N,MaxD;
int dp[MAXN+5];

int main(){
    scanf("%d",&N);
    memset(dp,0x3f,sizeof dp);
    dp[0]=0;
    for(int i=1;i<=12;i++)
        for(int j=M[i];j<=N;j++)
            dp[j]=min(dp[j],dp[j-M[i]]+1);
    printf("%d",dp[N]);
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<tuple<string, int, int>> p(n);
    rep(i, n) {
        string s;
        int x;

        cin >> s >> x;
        p[i] = make_tuple(s, -x, i+1);
    }
    sort(p.begin(), p.end());
    rep(i, n) {
        cout << get<2>(p[i]) << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main {
   public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int input = scan.nextInt();
		int[] num = new int[input];
		
		for(int i = 0; i < input; i++){
			num[i] = scan.nextInt();
		}
		
		shellSort(num, input);
		
		for(int n = 0; n < input; n++){
			System.out.println(num[n]);
		}
	}
	
	static int insertionSort(int A[], int n, int g){
		int v;
		int j;
		int c = 0;
		
		for(int i = g; i <= n - 1; i++){
			v = A[i];
			j = i - g;
			while(j >= 0 && A[j] > v){
				A[j + g] = A[j];
				j = j - g;
				c++;
			}
			A[j + g] = v;
		}
		return c;
	}
	
	static void shellSort(int A[], int n){
		int cnt = 0;
		int m = 0;
		int h = 1;
		
		while(h < n){
			h = h * 3 + 1;
			m++;
		}
		if(n == 1 && A[0] == 1){
			m = 1;
		}
		
		System.out.println(m);
		int[] G = new int[m];
		
		int temp = 0;
		for(int j = 0; j < m; j++){
			for(int i = 0; i < m - j; i++){
				temp = temp * 3 + 1;
				G[j] = temp;
				
			}
			if(j != m - 1){
				System.out.print(G[j] + " ");
			}else{
				System.out.println(G[j]);
			}
			temp = 0;
		}
		for(int i = 0; i <= m - 1; i++){
			cnt += insertionSort(A, n, G[i]);
		}
		
		System.out.println(cnt);
	}
}

Measured memory_bytes: 298864
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;


int main(){
	int N, Y;
	cin >> N >> Y;
	int check = 0;
	for(int i=0;i<=N;i++){
		for(int j=0;j<=N-i;j++){
			if(i * 1000 + j * 5000 + (N - i - j) * 10000 == Y){
				cout << N - i - j << " " << j << " " << i << endl;
				check = 1;
				break;
			}
		}
		if(check) break;
	}
	if(!check) cout << -1 << " " << -1 << " " << -1 << endl;
}





Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;

/*
 n m p a b
 t1 t2 ... tn
 x1 y1 z1
 x2 y2 z2
 ...
 xp yp zp 

 nÍCnÔÌÅ éD 1Èã8ÈºÆ¼èµÄæ¢D mÍCssÌÅ éD 2Èã30ÈºÆ¼èµÄæ¢D
 pÍCssÔ¹HÌ{Å éD ¹HÌ{ª0Ì±Æà éD
 */
public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		for (;;) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			int p = sc.nextInt();
			int a = sc.nextInt();
			int b = sc.nextInt();
			if ((n | m | p | a | b) == 0) {
				break;
			}
			a -= 1;
			b -= 1;

			int[][] cost = new int[m][m];
			for (int i = 0; i < m; i++) {
				Arrays.fill(cost[i], Integer.MAX_VALUE);
			}
			int[] ticket = new int[n];
			for (int i = 0; i < n; i++) {
				ticket[i] = sc.nextInt();
			}
			for (int i = 0; i < p; i++) {
				int x = sc.nextInt() - 1;
				int y = sc.nextInt() - 1;
				int z = sc.nextInt();
				cost[x][y] = cost[y][x] = z;
			}

			int left = (1 << n) - 1;
			double[][] dp = new double[1<<n][m];
			for (int i = 0; i < 1<<n; i++) {
				Arrays.fill(dp[i], Double.MAX_VALUE);
			}
			int now = a;
			dp[left][now] = 0;
			for (; left >= 0; left--) {
				for (int i = 0; i < n; i++) {
					int sh = 1 << i;
					if ((left & sh) != 0) {
						continue;
					}
					int previous = left | sh;
					for (int j = 0; j < m; j++) {
						for (int k = 0; k < m; k++) {
							if (cost[j][k] == Integer.MAX_VALUE) {
								continue;
							}
							dp[left][j] = Math.min(dp[left][j], dp[previous][k]
									+ (double)(cost[j][k]) / (double)ticket[i]);
						}
					}
				}
			}
			double res = Double.MAX_VALUE;
			for(int i = 0; i< 1<<n;i++){
//				System.out.println(dp[i][b]);
				res = Math.min(dp[i][b], res);
			}
			if(res > 1e6){
				System.out.println("Impossible");
			}else{
				System.out.println(res);
			}
		}

	}

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
}

Measured memory_bytes: 12000
<?php 
$num = trim(fgets(STDIN));
$tmp = explode(' ', $num);
if ($tmp[0] > $tmp[1]) {
 echo "a > b".PHP_EOL;
} else if ($tmp[0] < $tmp[1]) {
 echo "a < b".PHP_EOL;
} else {
 echo "a == b".PHP_EOL;
}

Measured memory_bytes: 15304
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <cctype>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

locale l = locale::classic();

int main(){
    int r,d,x;
    cin >> r >> d >> x;
    rep(i,10){
        x=r*x-d;
        cout << x << endl;
    }
}

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

typedef long long ll;
typedef pair<int,int> P;
ll const mod = 1e9+7;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    ll n,k;
    cin >> n >> k;
    int m = ceil(sqrt(n));
    map<ll,ll> mp1,mp2;
    for (ll i = 1;i*i <= n;++i) {
        mp1[i] = n/i;
        mp1[n/i] = i; 
    }
    {
        int i = 0;
        for (auto p : mp1) {
            mp2[i] = p.first;
            i++;
        }
    }
    mp2[-1] = 0;
    m = mp1.size();
    vector<vector<ll>> dp(k+1,vector<ll>(m,0));
    for (int i = 0;i < m;++i) dp[0][i] = 1;
    // p_ary(dp[0],0,m,i);
    int s = 0;
    for (int i = 0;i < k;++i) {
        ll sum = 0;
        for (int j = 0;j < m;++j) (dp[i][j] *= mp2[j]-mp2[j-1]) %= mod;
        for (int j = 0;j < m;++j) {
            (sum += dp[i][j]) %= mod;
            dp[i+1][m-j-1] = sum;
        }
    }
    ll ans = 0;
    for (int i = 0;i < m;++i) (ans += dp[k-1][i]) %= mod;
    cout << (ans+mod)%mod << endl;
    // for (int i = 0;i < k;++i) p_ary(dp[i],0,m,j);
}

Measured memory_bytes: 60304
#pragma  warning (disable:4996) 
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<utility>
#include<iomanip>
#include<set>
#include <numeric>
#include<map>
using namespace std;
typedef long long ll;

int main()
{
	int n, r;
	scanf("%d%d", &n, &r);
	if (n > 0 && n <= 10) printf("%d\n", r + 100 * (10 - n));
	else printf("%d\n", r);
}



Measured memory_bytes: 256
n=gets.to_i
y=$<.map{|e|e.split.map &:to_i}.transpose.map{|x,y|x-y}.sort
x=y.dup
l=0
r=n-1
while l<r && x[l]<0
	r-=1 if x[r]==0
	x[l]+=z=[x[r],-x[l]].min
	x[r]-=z
	l+=1 if x[l]==0
end
p x[l]<0 ? -1 : (0...n).count{|i|x[i]!=y[i]}

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

int calchp(vector<int> x, int p) {
  int sum = 0, i;
  const int N = x.size();
  rep (i, N)
    sum += (x[i] - p) * (x[i] - p);
  return sum;
}
int main() {
  int i, j, N; cin >> N;
  vector<int> x(N);
  rep (i, N) scanf("%d", &x.at(i));
  int min = 1100000;
  rep (i, 110) {
    int sumhp = 0;
    sumhp = calchp(x, i);
    if (sumhp < min) min = sumhp ;
  }
  printf("%d\n", min);
  return 0;
}


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

int main() {
	int n;
	cin >> n;
	int ans=n;
	vector <int> v(n);
	map <int,int> m;
	for(int i=0; i<n; i++)
	{
		cin >> v[i];
		if(m[v[i]]==0) m[v[i]]=1;
		else m[v[i]]=2;
	}
	for(int i=0; i<n; i++)
	{
		for(int j=1; j<=sqrt(v[i]); j++)
		{
			if(v[i]%j==0)
			{
				if(m[j]>0)
				{
					ans-=1;
					break;
				}
				else
				{
					if(v[i]/j!=v[i])
					{
						if(m[v[i]/j]>0)
						{
							ans-=1;
							break;
						}
					}
					else if(m[v[i]]==2)
					{
						ans-=1;
						break;
					}
				}
			}
		}
	}
	if(m[1]==1) cout << 1 << endl;
	else
	{
		if(m[1]==2) cout << 0 << endl;
		else cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 32588
n, L = map(int, input().split())
a = list(map(int, input().split()))
st = -1
for i in range(n-1):
    if a[i] + a[i+1] >= L:
        st = i
        break
if st < 0:
    print("Impossible")
else:
    print("Possible")
    for i in range(st):
        print(i+1)
    for i in range(n-2, st, -1):
        print(i+1)
    print(st+1)

Measured memory_bytes: 14052
#include <iostream>

using namespace std;

int main() {
	string S, T, U;
	int A, B;
	cin >> S;
	cin >> T;
	cin >> A;
	cin >> B;
	cin >> U;
	if (U == S) {
		cout << A-1 << " " << B << endl;
	} else {
		cout << A << " " << B-1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
// ?????????????????????

#include <bits/stdc++.h>

using namespace std;

struct Bipartite_Matching
{
  vector< vector< int > > graph;
  vector< int > match, alive, used;
  int timestamp;

  Bipartite_Matching(int n)
  {
    timestamp = 0;
    graph.resize(n);
    alive.assign(n, 0);
    used.assign(n, 0);
    match.assign(n, -1);
  }

  void add_edge(int u, int v)
  {
    graph[u].push_back(v);
    graph[v].push_back(u);
  }

  bool dfs(int v)
  {
    used[v] = timestamp;
    for(int i = 0; i < graph[v].size(); i++) {
      int u = graph[v][i], w = match[u];
      if(alive[u] == 0) continue;
      if(w == -1 || (used[w] != timestamp && dfs(w))) {
        match[v] = u;
        match[u] = v;
        return (true);
      }
    }
    return (false);
  }

  int bipartite_matching()
  {
    int ret = 0;
    for(int i = 0; i < graph.size(); i++) {
      if(alive[i] == 0) continue;
      if(match[i] == -1) {
        ++timestamp;
        ret += dfs(i);
      }
    }
    return (ret);
  }

  int add(int k)
  {
    alive[k] = 1;
    ++timestamp;
    return (dfs(k));
  }

};

int main()
{
  int N, A[150000], idx[150000];
  vector< int > g[150000];
  bool dep[150000] = {};

  cin >> N;
  ++N;
  for(int i = 1; i < N; i++) {
    cin >> idx[i];
    g[idx[i]].push_back(i);
    dep[i] = dep[idx[i]] ^ 1;
  }

  Bipartite_Matching flow(N);
  vector< int > left, right;
  for(int i = 0; i < N; i++) {
    if(dep[i]) left.push_back(i);
    else right.push_back(i);
  }

  for(int i = 1; i < N; i++) {
    int oi, beet;
    if(dep[i]) oi = lower_bound(begin(left), end(left), i) - begin(left);
    else oi = (int) (lower_bound(begin(right), end(right), i) - begin(right)) + left.size();

    if(dep[idx[i]]) beet = lower_bound(begin(left), end(left), idx[i]) - begin(left);
    else beet = (int) (lower_bound(begin(right), end(right), idx[i]) - begin(right)) + left.size();

    flow.add_edge(oi, beet);
  }
  flow.alive[(int) (lower_bound(begin(right), end(right), 0) - begin(right)) + left.size()] = true;

  flow.bipartite_matching();
  int ret = 0;
  for(int i = 1; i < N; i++) {
    int oi;
    if(dep[i]) oi = lower_bound(begin(left), end(left), i) - begin(left);
    else oi = (int) (lower_bound(begin(right), end(right), i) - begin(right)) + left.size();
    ret += flow.add(oi);
    cout << ret << endl;
  }


}

Measured memory_bytes: 7044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int n;
const int maxN = (int)1e5 + 100;
bool touched[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    vector < ll > all(n);
    for (int i = 0; i < n; i++) {
        cin >> all[i];
    }
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        int b;
        cin >> b;
        all[i] -= b;
        sum += all[i];
    }
    if (sum < 0) {
        cout << -1;
        return 0;
    }
    sort(all.begin(), all.end());
    int i = 0;
    while (i < all.size()) {
        if (all[i] >= 0) break;
        touched[i] = true;
        if (all.back() + all[i] > 0) {
            touched[all.size() - 1] = true;
            all.back() += all[i];
            i++;
            continue;
        }
        else {
            touched[all.size() - 1] = true;
            all[i] += all.back();
            all.pop_back();
            continue;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (touched[i]) ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1152
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        r1: usize,
        c1: usize,
        r2: usize,
        c2: usize
    }
    let d = 1000000007;
    println!("{}", (solve(r2, c2, d) + solve(r1 - 1, c1 - 1, d) + 2 * d - solve(r1 - 1, c2, d) - solve(r2, c1 - 1, d)) % d);
}

fn solve(r: usize, c: usize, d: usize) -> usize {
    (r + 2..r + c + 3).fold(1, |ac, x| ac * x % d) * inv_m((1..c + 2).fold(1, |ac, x| ac * x % d), d) % d - 1
}

fn pow_m(n: usize, mut p: usize, d: usize) -> usize {
    let mut r = n;
    let mut ret = 1;
    while p > 0 {
        if p % 2 == 0 {
            r = r * r % d;
            p /= 2;
        } else {
            ret = ret * r % d;
            p -= 1;
        }
    }
    ret
}

fn inv_m(n: usize, d: usize) -> usize {
    pow_m(n, d - 2, d)
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N,M,arr[10005],sum=0;
    cin>>N>>M;
    for(int i=1;i<=M;i++)
    {
       cin>>arr[i];
       sum+=arr[i];
    }
    if(sum<=N)
        cout<<N-sum<<endl;
    else
        cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 3660