akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<complex>
using namespace std;
typedef long long int llint;


int main(){
	llint n;
	cin >> n;
	llint m = n;
	llint s = 0;
	while (0 < m){
		s += m % 10;
		m /= 10;
	}
	if (n%s == 0){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

int main(){
  string s1, s2;
  cin >> s1 >> s2;
  vector<vector<int>> dp(s1.size()+1, vector<int>(s2.size()+1));
  dp[0][0] = 0;
  rep(i, s1.size()) dp[i+1][0] = i+1;
  rep(i, s2.size()) dp[0][i+1] = i+1;
  rep(i, s1.size()) rep(j, s2.size()) {
    dp[i+1][j+1] = min({dp[i][j+1]+1, dp[i+1][j]+1, dp[i][j]+(s1[i]==s2[j] ? 0 : 1)});
  }
  cout << dp[s1.size()][s2.size()] << endl;
  return 0;
}


Measured memory_bytes: 6904
#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <bitset>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int N, m;
	scanf("%d%d", &N, &m);
	vector<int> minc(N+2, N+1);
	rep(i, m) {
		int c, d;
		scanf("%d%d", &c, &d);
		amin(minc[d], c);
	}
	vector<vi> dp(N+2, vector<int>(N+2, INF));
	dp[0][N+1] = 0;
	rep(i, N+1) rep(j, N+2) {
		int x = dp[i][j];
		if(x == INF) continue;
		amin(dp[i+1][min(minc[i+1], j)], x + 1);
		if(j != N+1)
			amin(dp[i+1][minc[i+1]], x + (i - j) * 2 + 1);
	}
	int ans = dp[N+1][N+1];
	printf("%d\n", ans);
	return 0;
}

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

int main(){
	int i, j;
	char c[10][10];
	for(i=0; i<3; i++){
		for(j=0; j<3; j++) cin>>c[i][j];
	}
	cout<<c[0][0]<<c[1][1]<<c[2][2]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
using namespace std;
#define int long long
#define fr(i,n) for (int i = 0; i < n; i++)
#define fro(i,m,n) for (int i = m; i < n; i++)
#define pb push_back
#define iter ::iterator
#define fi first
#define se second


void io(){
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif
}

void solve(){
  //io();
  int n;
  cin>>n;
  int a[n];
  fr(i,n){
    cin>>a[i];
  }
  int dp[n+1]={0};
  dp[1]=abs(a[1]-a[0]);
  fro(i,2,n){
    dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
  }
  std::cout << dp[n-1] << '\n';
}



int32_t main(){
  std::ios::sync_with_stdio(false);
  solve();
  return 0;
}


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

int main() {
	int H, W; cin >> H >> W;
	for (int i = 1, pre = 0; i <= H; ++i) {
		char A[10];
		cin >> A + 1;
		int cnt = 0;
		for (int j = 1; j <= W; ++j) {
			if (A[j] == '#') {
				if (A[j-1] == '.') ++cnt;
				if (pre > j) return !printf("Impossible");
				pre = j;
			}
		}
		if (cnt > 1) return !printf("Impossible");
	}
	printf("Possible");
	return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  if(a>=b){
    for(int i=0;i<a;i++){
      cout << b;
    }
    cout << endl;
  }
  else{
     for(int i=0;i<b;i++){
      cout << a;
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <unordered_map>
#include <set>
#include <fstream>
#include <cstring>
#include <climits>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

#define ll long long
#define mod 1000000007

ll dp[3001][3001];

int main() {

	int n;
	cin >> n;
	ll a[n];

	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	memset(dp, 0, sizeof(dp));

	for (int l = n-1; l >= 0; l--) {
		for (int r = l; r < n; r++) {
			if (l == r) {
				dp[l][r] = a[l];
			} else {
				dp[l][r] = max(a[l] - dp[l + 1][r], a[r] - dp[l][r - 1]);
			}
		}
	}
	cout << dp[0][n - 1];

	return 0;
}

Measured memory_bytes: 70656
N = int(input())
H = [int(i) for i in input().split()]

is_break = False
for i in range(N - 1):
    j = N - i - 1
    if H[j - 1] > H[j]:
        H[j - 1] -= 1
    if H[j - 1] > H[j]:
        is_break = True

if is_break:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 14396
#include <bits/stdc++.h>
using namespace std;
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)

int main() {
  int n;
  cin>>n;
  nvec(double, a, n);
  for (size_t i = 0; i < n; i++) {
    a[i]=1/a[i];
  }
  cout<<setprecision(12)<<1/accumulate(a.begin(),a.end(),0.0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define Rall(a) (a).rbegin(), (a).rend()
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define mp make_pair
#define pb push_back
const ll MOD=1e9+7;
using namespace std;

int dy[]={1,-1,0,0,1,1,-1,-1,0};
int dx[]={0,0,1,-1,1,-1,1,-1,0};

int main(){
	int s;
	cin >> s;
	int a[2];
	int i=1;
	while(s>0){
		a[i--] = s%100;
		s /= 100;
	}

	if( (1<=a[0]&&a[0]<=12) && (1<=a[1]&&a[1]<=12) ){
		cout << "AMBIGUOUS" << endl;
	}else if( (1<=a[0]&&a[0]<=12) ){
		cout << "MMYY" << endl;
	}else if(  (1<=a[1]&&a[1]<=12) ){
		cout << "YYMM" << endl;
	}else if(a[0]==0 || a[1]==0){
		cout << "NA" << endl;
	}else{
		cout << "NA" << endl;
	}
}

Measured memory_bytes: 256
H, W = list(map(int, input().split(' ')))
xs = []
for i in range(H):
    xs.append(list(map(int, input().split(' '))))
# best でなくても良い？
ans = []  # x,y -> p, q
seeds = []
for i in range(H):  # 500
    for j in range(W):  # 500
        if xs[i][j] % 2 != 0:
            seeds.append((i, j))
used = {}
def f(st, ed):
    res = []
    while(st != ed):
        old = st
        if (st[0] % 2 == 0):
            if st[1] < W - 1:
                st = (st[0], st[1] + 1)
            else:
                st = (st[0]+1, st[1])
        else:
            if st[1] > 0:
                st = (st[0], st[1] - 1)
            else:
                st = (st[0]+1, st[1])
        res.append('%d %d %d %d' % (old[0]+1, old[1]+1, st[0]+1, st[1]+1))
    return res

ans = []
# print (seeds)
seeds = sorted(seeds, key=lambda x:(x[0] * 9999999 + x[1] * (-1 if x[0]%2 == 1 else 1)))
# print (seeds)
for i in range(0, len(seeds)-1, 2):
    st = seeds[i]
    ed = seeds[i+1]
    ans += f(st, ed)
print(len(ans))
print('\n'.join(ans))


Measured memory_bytes: 43384
# -*- coding:utf-8 -*-
import sys

def solve():
    N, K, Q = list(map(int, sys.stdin.readline().split()))
    ans = [0] * N
    for i in range(Q):
        a = int(sys.stdin.readline())
        ans[a-1] += 1

    for i in range(N):
        if K - (Q-ans[i]) > 0:
            print("Yes")
        else:
            print("No")


if __name__ == "__main__":
    solve()


Measured memory_bytes: 4680
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;

const int N = 10000;
int n;
int a[N];

int main()
{
	scanf("%d", &n);
	n *= 2;
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	sort(a, a + n);
	int ans = 0;
	for (int i = 0; i < n; i += 2)
		ans += a[i];
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 764
# -*- coding: utf-8 -*-
s = input()
k = "keyence"

pre = None
for i in range(1,7+1):
    if s[:i]==k[:i]:
        pre = i

if pre is None:
    print("NO")
elif pre==7:
    print("YES")
elif k[pre:]==s[-(7-pre):]:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;
 
int main(){ 
   string s,t;
   cin>>s>>t;
   int flag=0;
   for(int i=0;i<s.size();i++){
      char u=s[s.size()-1];
      s=u+s;
      s.pop_back();
      if(s==t) flag=1;
 
   }
   (flag==1)? cout<<"Yes":cout<<"No";
 
   
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define oo 1000000007
using namespace std;
long long k;
long long dp[10005][105][2];
string s;
vector<long long>num;
long long solve(long long idx, long long sum, long long tight)
{
    if (idx == num.size())
        return (sum%k==0);
    if (dp[idx][sum][tight] != -1)
        return dp[idx][sum][tight];
    long long res = 0;
    long long biggest;
    if (tight)
     biggest= (num[idx]) ;
     else
        biggest=9;
    for (int i = 0; i <= biggest; i++)
    {
        long long newtight = ((num[idx])== i) ? tight : 0;
        res =(res+solve(idx + 1, (sum + i) % k, newtight))%oo;
    }
    return dp[idx][sum][tight] = res;
}
long long khoitao(string s)
{
 
    for(long long i=0;i<s.size();i++)
        num.push_back(s[i]-'0');
    return solve(0,0,1);
}
main()
{
    num.clear();
    memset(dp,-1,sizeof(dp));
    cin>>s>>k;
    cout<<(khoitao(s)-1+oo)%oo;
    return 0;
}

Measured memory_bytes: 17664
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <cstdlib>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}

vector<ll> fact, factinv, inv;
ll mod = 1e9 + 7;
void prenCkModp(ll n) {
	fact.resize(n + 5);
	factinv.resize(n + 5);
	inv.resize(n + 5);
	fact.at(0) = fact.at(1) = 1;
	factinv.at(0) = factinv.at(1) = 1;
	inv.at(1) = 1;
	for (ll i = 2; i < n + 5; i++) {
		fact.at(i) = (fact.at(i - 1) * i) % mod;
		inv.at(i) = mod - (inv.at(mod % i) * (mod / i)) % mod;
		factinv.at(i) = (factinv.at(i - 1) * inv.at(i)) % mod;
	}

}
ll nCk(ll n, ll k) {
	return (fact.at(n) * ((factinv.at(k) * factinv.at(n - k)) % mod)) % mod;
}


int main() {
	ll X, Y;
	cin >> X >> Y;
	if ((X + Y) % 3 != 0) {
		cout << 0 << endl; return 0;
	}
	ll N = (2 * Y - X) / 3;
	ll M = (X + Y) / 3 - N;
	if (N < 0 || M < 0) {
		cout << 0 << endl; return 0;
	}
	prenCkModp(N + M);
	cout << nCk(N + M, N) << endl;
}

Measured memory_bytes: 16000
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>


using namespace std;
int main(){
  vector<vector<string>> s(10,vector<string>());
  vector<int> k(10,0);
  string l;
  int c,x=0,p;
  cin>>c;
  for(int i=0;i<c;i++){
    cin>>l;
    p=l.size();
    s.at(p-1).push_back(l);
    k.at(p-1)+=1;
    if(i%1000==0){
      for(int q=0;q<10;q++){
        if(k.at(q)!=s.at(q).size()){
      sort(s.at(q).begin(),s.at(q).end());
      s.at(q).erase(unique(s.at(q).begin(),s.at(q).end()),s.at(q).end());
        }
      }
    }
  }
for(int q=0;q<10;q++){
      sort(s.at(q).begin(),s.at(q).end());
      s.at(q).erase(unique(s.at(q).begin(),s.at(q).end()),s.at(q).end());
}
  for(int i=0;i<10;i++)
    x+=s.at(i).size();
  cout<<x;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    int n,m;
    cin>>n>>m;
    vi s(m);
    vc<char> c(m);
    rep(i,m)cin>>s[i]>>c[i];
    

    string ans;
    rep(i,n)ans+='#';
    
    rep(i,m){
        if(ans[s[i]-1]!='#' && ans[s[i]-1]!=c[i]){
            cout<<-1<<"\n";
            return 0;
        }
        ans[s[i]-1]=c[i];
    }

    if(n>1 && ans[0]=='0'){
        cout<<-1<<"\n";
        return 0;
    }

    rep(i,n){
        if(ans[i]=='#'){
            if(n>1 && i==0)ans[i]='1';
            else ans[i]='0';
        }
    }
    
    cout<<ans<<"\n";

    return 0;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Control.Monad.ST
import Data.List
import Data.Maybe (fromJust)

data Pair = Pair Integer Integer deriving Show


getDivisorPairs :: Integer -> Integer -> [Pair]
getDivisorPairs a b
    | a < b * b = []
    | a `mod` b == 0 = (Pair (a `div` b) b):(getDivisorPairs a (b + 1))
    | otherwise = getDivisorPairs a (b + 1)


getDigitCountPair :: Pair -> Integer
getDigitCountPair (Pair a b) = max (getDigitCount a) (getDigitCount b)


getDigitCount :: Integer -> Integer
getDigitCount 0 = 0
getDigitCount n = 1 + (getDigitCount (n `div` 10))


solve :: Integer -> Integer
solve n = minimum counts
    where
        pairs = getDivisorPairs n 1
        counts = map getDigitCountPair pairs


main :: IO ()
main = do
    n <- fst . fromJust . BS.readInteger <$> BS.getLine
    print $ solve n


Measured memory_bytes: 892
import java.util.*;



/**
 * Created by santa on 2016/10/16.
 */

public class Main {

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

        int N = scanner.nextInt();
        int[] map = new int[N];
        int flag = 0;
        int migi = N - 1;
        int hidari = 0;
        flag = 0;
        int[] s = new int[N];
        for (int i = 0; i < N; i++) {
            s[i] = scanner.nextInt();
        }
        for (int i = N - 1 ; i >=  0; i--) {
            if(flag == 1){
                map[migi] = s[i];
                migi -= 1;
                flag = 0;
            }else{
                map[hidari] = s[i];
                hidari += 1;
                flag = 1;
            }
        }
        System.out.print(map[0]);
        for (int i = 1; i < N; i++) {
            System.out.print(" " + map[i]);
        }

        System.out.println();

    }






} // MainClass


Measured memory_bytes: 91388
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<vector<int>> s(h, vector<int>(w));
  rep(i, h) {
    rep(j, w) {
      char c;
      cin >> c;
      s[i][j] = c - '0';
    }
  }

  int ans = inf;
  rep(i, 1 << (h - 1)) {
    int n = 1;
    rep(j, h - 1) {
      if (i >> j & 1) n++;
    }
    int cnt = n - 1;
    vector<vector<int>> res(n, vector<int>(w, 0));
    int idx = 0;
    res[0] = s[0];
    rep(j, h - 1) {
      if (i >> j & 1) idx++;
      rep(l, w) res[idx][l] += s[j + 1][l];
    }
    bool f = true;
    rep(j, n) rep(l, w) if (res[j][l] > k) f = false;
    if (!f) continue;
    rep(l, w - 1) {
      bool f2 = true;
      rep(j, n) {
        if (res[j][l] + res[j][l + 1] > k) {
          f2 = false;
          break;
        }
      }
      if (!f2) cnt++;
      else {
        rep(j, n) {
          res[j][l + 1] += res[j][l];
        }
      }
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;


  
  return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, ll> P;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, k;
int t[100100];
ll d[100100];

ll solve() {
    vector<P> vec(n);
    for (int i = 0; i < n; i++) {
        vec[i] = make_pair(d[i], t[i]);
    }
    sort(RALL(vec));

    ll dil = 0;
    stack<ll> rem_cand;
    set<int> kinds;
    for (int i = 0; i < k; i++) {
        const P p = vec[i];
        dil += p.first;
        if (kinds.count(p.second) == 0) {
            kinds.insert(p.second);
        } else {
            rem_cand.push(p.first);
        }
    }
    ll k = (ll)kinds.size();
    ll res = dil + k * k;
    for (int i = k; i < n; i++) {
        const P p = vec[i];
        if (kinds.count(p.second) == 0 && !rem_cand.empty()) {
            ll r = rem_cand.top(); rem_cand.pop();
            dil += p.first - r;
            k++;
            kinds.insert(p.second);
            res = max(res, dil + k * k);
        }
    }
    return res;
}

void input() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> t[i] >> d[i];
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 6272
#include <stdio.h>

int main(){
  char line[100];
  int m, f, r;
  int sum;
  while(1){
	fgets(line, sizeof(line), stdin);
	sscanf(line, "%d %d %d", &m, &f, &r);
	if((m==-1)&&(f==-1)&&(r==-1))
	  break;
	if((m==-1)||(f==-1))
	  printf("F\n");
	else{
	  sum=m+f;
	  if(sum>=80)
		printf("A\n");
	  else if(sum>=65)
		printf("B\n");
	  else if(sum>=50)
		printf("C\n");
	  else if(sum>=30){
		if(r>=50)
		  printf("C\n");
		else
		  printf("D\n");
	  }
	  else
		printf("F\n");
	}
  }
  return 0;
}



Measured memory_bytes: 2032
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 2e5+100;
const int mod = 1e9+7;
int main() {
	ll n,a,b;
	slld(a);slld(b);slld(n);
	ll gg=min(b-1,n);
	gg*=a;gg/=b;
	plld(gg);
	return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

ll digitcal(ll x){
  ll n=0;
  while(x>0){
    x/=10;
    n++;
  }
  return n;
}

int main() {
  ll a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  ll ans=1e18;
  if(x<y){
    swap(x,y);swap(a,b);
  }
  for(int i=0;i<=x;i++){
    ll temp=0;
    temp+=i*a;
    temp+=(x-i)*2*c;
    temp+=max((ll)0,y-(x-i))*b;
    ans=min(ans,temp);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3560
using System;

namespace ABC106D
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] bufs = Console.ReadLine().Split(' ');
            int N = int.Parse(bufs[0]);
            int M = int.Parse(bufs[1]);
            int Q = int.Parse(bufs[2]);

            int[,] term = new int[N + 1, N + 1];

            for (int i = 0; i < M; i++)
            {
                bufs = Console.ReadLine().Split(' ');
                int L = int.Parse(bufs[0]);
                int R = int.Parse(bufs[1]);

                for (int j = R; j <= N; j++)
                {
                    term[L, j]++;
                }
            }

            for (int i = 0; i < Q; i++)
            {
                bufs = Console.ReadLine().Split(' ');
                int p = int.Parse(bufs[0]);
                int q = int.Parse(bufs[1]);

                int res = 0;

                for (int j = p; j <= q; j++)
                {
                    res += term[j, q];
                }

                Console.WriteLine(res);
            }

        }
    }
}


Measured memory_bytes: 17832
#include<stdio.h>

int dp[50];

int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}

int main(){
  int n, i;

  for(i = 0 ; i < 50 ; i++){
    dp[i] = -1;
  }

  scanf("%d",&n);
  printf("%d\n",fib(n));

  return 0;
}

Measured memory_bytes: 596
#include<stdio.h>

int main(void)
{
        int n, i;
        double x, r=0;
        char v[4];

        scanf("%d", &n);

        for(i = 0; i < n; i++) {
                scanf("%lf%s", &x,&v);
                if(strcmp(v ,"JPY") == 0) {
                        r += x;
                } else {
                        r += x*380000;
                }
        }
        printf("%lf",r);
        return 0;
}


Measured memory_bytes: 128
#coding: utf-8
import math
import heapq
import bisect

MOD = 10**9+7

N = int(input())

# 複数個の数値を、intの配列として取得
A = list(map(int, input().split()))

# (A[i],i)のタプルリストを作って、昇順ソート
L = []
for i,v in enumerate(A):
    a = tuple([i+1,A[i]])
    L.append(a)
L = sorted(L, key=lambda x:x[1])

for i in range(N):
    print(L[i][0])

Measured memory_bytes: 20324
n,d=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
cnt=0
for i in range(n-1):
  for j in range(i+1,n):
    sum=0
    for dd in range(d):
      sum+=(l[i][dd]-l[j][dd])**2
    if sum**0.5==int(sum**0.5):
      cnt+=1
print(cnt)

Measured memory_bytes: 3064
N = int(input())
A = [int(_) for _ in input().split()]

def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

#l = 1
#for a in A:
#    l = lcm(l, a)

#r = sum((l - 1) % a for a in A)
r = sum(a - 1 for a in A)

print(r)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int r;
  cin >> r;
  cout << 3*r*r << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)
/*
a b c
b+c a+c a+b -a+b
2a+b+c a+2b+c a+b+2c a-b
2a+3b+3c 3a+2b+3c 3a+3b+2c  -a+b
6a+5b+5c 5a+6b+5c 5a+5b+6c  a-b
*/

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll A,B,C,K;
	while(cin>>A>>B>>C>>K) {
		ll ans = K%2==0 ? A-B : -A+B;
		if(abs(ans)>1000000000000000000LL) {
			cout<<"Unfair"<<endl;
		} else {
			cout<<ans<<endl;
		}
	}
	
	return 0;
}


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

using namespace std;

int ans = 0;

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

        for (int i = 0; i < N; i++)
        {
                string str;
                cin >> str;
                if (str == "Y")
                {
                        ans++;
                        break;
                }
        }

        if (ans == 0)
        {
                cout << "Three" << endl;
        }else{
                cout << "Four" << endl;
        }
        return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef int_fast64_t ll;
typedef int_fast32_t intt;
typedef int_fast32_t tmp_m;
#define deb(x) cout << #x << ' ' << x << endl
#define rep(i, a, b) for (tmp_m i = a; i < b; ++i)
#define repp(i, a, b) for (tmp_m i = a; i >= b; --i)
#define pb push_back
#define st stack
#define pa pair
#define vc vector
#define qu queue
#define pq priority_queue
#define fr first
#define sc second
#define mp map
const intt mod = 1e9 + 7;

struct pr {
  intt x;
  intt y;
  intt dst;
  pr() {}
  pr(intt x, intt y, intt dst) : x(x), y(y), dst(dst) {}
  inline bool operator<(const pr& b) const {
    if (dst != b.dst) return dst > b.dst;
    if (x != b.x) return x > b.x;
    return y > b.y;
  }
};

struct point {
  intt x;
  intt y;
  point() {}
  point(intt x, intt y) : x(x), y(y) {}
  inline bool operator<(const point& b) const {
    if (x != b.x) return x > b.x;
    return y > b.y;
  }
};

inline bool spoint(point a, point b) {
  if (a.x != b.x) return a.x < b.x;
  return a.y < b.y;
}

inline bool spr(pr a, pr b) {
  if (a.dst != b.dst) return a.dst < b.dst;
  if (a.x != b.x) return a.x < b.x;
  return a.y < b.y;
}



void solve() {
  intt n, m;
  cin >> n >> m;
  rep(i, 0, m){
    intt a;
    cin >> a;
    n -= a;
  }
  if(n < 0)puts("-1");
  else cout << n << endl;
}

void init() {
  // remove if interactive
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(time(0));
  // memset(dp, -1, sizeof dp);
}

int main() {
  init();
  solve();
  return 0;
}


Measured memory_bytes: 3664
#define _[2<<17]
n,i;A _,B _,T _,F _;long M,D _,P _,R _;s(u,i,p,I){i?s(u,I=T[i],p),R[i]=R[I]*-~((I=B[i])-p?s(I,F[I],u),D[u]=D[u]*-~D[I]%M,D[I]:0)%M:++D[u];}S(u,x,p,i,I){for(i=F[u];I=B[i];I-p?S(I,R[i]*x%M+1,u),x=x*-~D[I]%M:0)i=T[i];P[u]=x%M;}main(u,v){for(;~scanf("%d%d",&u,&v);)i++?A[i-1]=B[i]=u,B[i-1]=A[i++]=v:(n=u,M=v);for(;--i;F[A[i]]=i)T[i]=F[A[i]];s(*R=1,F[1]);for(S(1,1);i++<n;)printf("%d ",P[i]);}

Measured memory_bytes: 15360
#include<bits/stdc++.h>
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define of(i,l,r) for(int i=l;i>=r;i--)
#define fe(i,u) for(int i=head[u];i;i=e[i].next)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline void open(const char *s)
{
	#ifndef ONLINE_JUDGE
	char str[20];
	sprintf(str,"%s.in",s);
	freopen(str,"r",stdin);
//	sprintf(str,"%s.out",s);
//	freopen(str,"w",stdout);
	#endif
}
inline int rd()
{
	static int x,f;
	x=0;f=1;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return f>0?x:-x;
}
const int N=1010;
int n,a[N],b[N],B;

inline void gao(int x,int y,int k)
{
	if(k==-1)return;
	if(abs(x)>=(1<<k)){
		if(x>0){
			cout<<'R';
			x-=(1<<k);
			return gao(x,y,k-1);
		}
		else{
			cout<<'L';
			x+=(1<<k);
			return gao(x,y,k-1);
		}
	}
	if(abs(y)>=(1<<k)){
		if(y>0){
			cout<<'U';
			y-=(1<<k);
			return gao(x,y,k-1);
		}
		else{
			cout<<'D';
			y+=(1<<k);
			return gao(x,y,k-1);
		}
	}
	if(abs(x)>abs(y)){
		if(x>0){
			cout<<'R';
			x-=1<<k;
			return gao(x,y,k-1);
		}
		else{
			cout<<'L';
			x+=1<<k;
			return gao(x,y,k-1);
		}
	}
	else{
		if(y>0){
			cout<<'U';
			y-=1<<k;
			return gao(x,y,k-1);
		}
		else{
			cout<<'D';
			y+=1<<k;
			return gao(x,y,k-1);
		}
	}
}

int main()
{
	n=rd();fo(i,1,n)a[i]=rd(),b[i]=rd();
	fo(i,1,n-1)if((abs(a[i])^abs(b[i])^abs(a[i+1])^abs(b[i+1]))&1)
		return puts("-1"),0;
	int f=~(abs(a[1])+abs(b[1]))&1;
	B=30;
	cout<<B+f+1<<'\n';
	of(i,B,0)cout<<(1<<i)<<' ';
	if(f){cout<<1;fo(i,1,n)++a[i];}
	cout<<'\n';
	fo(i,1,n){
		gao(a[i],b[i],B);
		if(f)cout<<'L';
		cout<<'\n';
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long x = sc.nextLong();
        System.out.println(f(b,x) - f(a-1,x));
    }
    public static long f(long n,long x){
        if(n == -1){
            return 0;
        }
        return n/x +1;
    }
}


Measured memory_bytes: 24020
'use strict';

var hasN = false;
// p1: 2D split
// p2: space split
// p3: line split
function main(p1, p2, p3, so) {
  if (p3[0] == 1) console.log("Hello World");else {
    console.log(Number(p3[1]) + Number(p3[2]));
  }
}
function common(a) {
  var line = a.split('\n').slice(0, a.split('\n').length - 1);
  var p2 = line[0].split(' ');
  if (hasN) line = line.slice(1);
  var p1 = line.map(function (e) {
    return e.split(' ');
  });
  main(p1, p2, line, a);
}
common(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
//        while (true){
//            int a = sc.nextInt();
//            int b = sc.nextInt();
//            if (a == 0 && b==0) break;
//            if ( a > b){
//                b = swap(a, a=b);
//            }
//            System.out.println(a + " " +b);
//        }
        int count = 0;
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        for (int i = a ; i<=b ; i++){
            if (c % i == 0){
                count++;
            }
        }
        System.out.println(count);
        
    }
}


Measured memory_bytes: 26188
#include<stdio.h>

int main()
{
    int a,b;
    char choice;
    scanf("%d %c %d",&a,&choice,&b);
    switch(choice)
   {
    case '+':
    printf("%d\n",a+b);
    break;
    case '-':
    printf("%d\n",a-b);
    break;
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  string s;
  cin>>s;
  vector<string> v(16);
  v[0]="KIHBR";
  v[1]="KIHBRA";
  v[2]="KIHBAR";
  v[3]="KIHBARA";
  v[4]="KIHABR";
  v[5]="KIHABRA";
  v[6]="KIHABAR";
  v[7]="KIHABARA";
  v[8]="AKIHBR";
  v[9]="AKIHBRA";
  v[10]="AKIHBAR";
  v[11]="AKIHBARA";
  v[12]="AKIHABR";
  v[13]="AKIHABRA";
  v[14]="AKIHABAR";
  v[15]="AKIHABARA";
  rep(i,16)if(s==v[i]){
    cout<<"YES"<<endl;
    return 0;
  }
  cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      (int)1e9+7
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;

int main(){
	int n;
	cin>>n;
	
	vi c(n-1),s(n-1),f(n-1);
	REP(i,n-1) cin>>c[i]>>s[i]>>f[i];
	
	vi ans(n,0);
	int now=0;
	REP(i,n-1){
		for(int j=0;j<=i;++j){
			if(ans[j]<=s[i]) ans[j]=s[i];
			else ans[j]=f[i]*(ans[j]/f[i]+((ans[j]%f[i])?1:0));
			ans[j]+=c[i];
		}
	}
	
	REP(i,n) cout<<ans[i]<<endl;
	return 0;
}

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



int main()
{
    int n,flag=0,i;
    char a[10000];
    cin>>a;
    n=strlen(a);
    int n1=n;
    for(i=0;i<=(n-1)/2;i++)
        {
            if(a[i]!=a[n1-i-1])
                flag=1;
        }
    n1=(n-1)/2;
    for(i=0;i<=(n1-1)/2;i++)
        {

            if(a[i]!=a[n1-i-1])
                flag=1;
        }
    n1=n;

    for(i=(n-1)/2;i<=(n-1)/2;i++)
    {
            if(a[i]!=a[n1-i-1])
                flag=1;

    }
    if(flag==0)
        cout<<"Yes\n";
    else 
        cout<<"No\n";


    // int t;

    // cin>>t;
    // while(t--)
    // {

    // }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int x;cin>>x;
    if(x>=30)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }


// import here

int main(){
    vector<LL> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());

    LL cnt1 = (a[1] - a[0]) / 2;
    a[0] += cnt1 * 2;
    LL cnt2 = a[2] - a[1];
    a[0] += cnt2;
    a[1] += cnt2;
    if(a[0] < a[1]){
        cout << cnt1 + cnt2 + 2 << endl;
    }else{
        cout << cnt1 + cnt2 << endl;
    }
    return 0;
}



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

N = m + 100
MOD = 10 ** 9 + 7
fact = [0 for _ in range(N)]
invfact = [0 for _ in range(N)]
fact[0] = 1
for i in range(1, N):
    fact[i] = i * fact[i - 1] % MOD

invfact[N - 1] = pow(fact[N - 1], MOD - 2, MOD)

for i in range(N - 2, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % MOD
    
def nCk(n, k):
    if k < 0 or n < k:
        return 0
    else:
        return fact[n] * invfact[k] * invfact[n - k] % MOD
        
def nPk(n, k):
    return fact[n] * invfact[n - k] % MOD
    
ans = 0
sign = 1

for i in range(n + 1):
    ans = (ans + nPk(m, i) * nCk(n, i) * nPk(m - i, n - i) ** 2 * sign) % MOD
    sign *= -1
    
print(ans)
    
    

Measured memory_bytes: 48384
#include <cstdio>
#include <algorithm>
using namespace std;
int n,i,l[205],ans;
int main()
{
	scanf("%d",&n);
	for (i=1;i<=2*n;i++)
		scanf("%d",&l[i]);
	sort(l+1,l+2*n+1);
	for (i=1;i<=2*n;i+=2)
		ans+=l[i];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");
        String arr02[] = mylist.get(1).split(" ");

        int n = Integer.valueOf(arr01[0]);

        Stream<String> stream = Arrays.stream(arr02);
        int arr03[] = stream.mapToInt(Integer::parseInt).toArray();
        Arrays.sort(arr03);

        double temp = arr03[0];

        for (int i = 1; i < arr03.length; i++) {
            temp = (temp + arr03[i]) / 2;

        }
        System.out.println(temp);
    }

}


Measured memory_bytes: 27860
#include <iostream>
using namespace std;
int main()
{
  for(;;){
    int L;
    cin >> L;
    if(L == 0) break;
    int count = 1;
    for(int i=0; i<12; i++){
      int in,out;
      cin >> in >> out;
      L -= in - out;
      if(L > 0) count++;
    }
    if(L > 0) cout << "NA" << endl;
    else cout << count << endl;
  }
  return 0;
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;


int main(){

    ll n;
    cin >> n;

    ll ans = n;
    int i = 2;
    while((ans%n != 0) || (ans%2 != 0) ){
        ans *= i;
        i++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

typedef pair<uint64,uint64> P;

struct edge{
private:
public:
    edge(){}
    edge(uint64 to_in, uint64 cost_in): to(to_in), cost(cost_in) {}
    ~edge(){}
    uint64 to;
    uint64 cost;
};

vector<uint64> dijkstra(const vector<vector<edge>>& graph, uint64 s){
    vector<uint64> vCost(graph.size(), UINT64_MAX); vCost[s]=0ull;
    priority_queue<P,vector<P>,greater<P>> que; que.push( P(0,s) );
    
    while(!que.empty()){
        P p = que.top(); que.pop();
        uint64 cost = p.first;
        uint64 idx  = p.second;
        if(vCost[idx] < cost){ continue; }
        for(uint i=0; i<graph[idx].size(); ++i){
            edge e = graph[idx][i];
            if(vCost[e.to] <= vCost[idx] + e.cost){ continue; }
            vCost[e.to] = vCost[idx] + e.cost;
            que.push( P(vCost[e.to], e.to) );
        }
    }
    return vCost;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    uint64 n, m, s, t;
    cin >> n >> m >> s >> t; --s; --t;
    
    vector<vector<edge>> graph_a(n), graph_b(n);
    for(uint64 i=0; i<m; ++i){
        uint64 u, v, a, b;
        cin >> u >> v >> a >> b; --u; --v;
        
        graph_a[u].push_back( edge(v, a) );
        graph_b[u].push_back( edge(v, b) );
        
        graph_a[v].push_back( edge(u, a) );
        graph_b[v].push_back( edge(u, b) );
    }
    
    vector<uint64> vCost_a = dijkstra(graph_a, s); // cost of s to i as vCost_a[i].
    vector<uint64> vCost_b = dijkstra(graph_b, t); // cost of t to i as vCost_b[i].
    
    vector<uint64> vCost(n);
    vCost[n-1] = vCost_a[n-1] + vCost_b[n-1];
    for(uint i=n-2; i!=UINT_MAX; --i){
        vCost[i] = vCost_a[i] + vCost_b[i];
        if(vCost[i] > vCost[i+1]){ vCost[i] = vCost[i+1]; }
    }
    
    for(uint i=0; i<n; ++i){
        cout << (uint64)1e15 - vCost[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 19072
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
int main()
{
	int n=read(),k=read();
	if(k>1)
		cout<<n-k;
	else
		cout<<0;
	return 0;
}


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

const int MAXW = 6000;
const int INF = 1<<28;
const int V[6] = {380,550,850,380*5*0.8,550*4*0.85,850*3*0.88};
const int W[6] = {200,300,500,200*5,300*4,500*3};

int dp[MAXW];
int w;

int main() {
  fill(dp, dp+MAXW, INF);
  dp[0] = 0;
  for(int i = 0; i < 6; ++i) {
    for(int j = W[i]; j < MAXW; ++j) {
      dp[j] = min(dp[j], dp[j-W[i]]+V[i]);
    }
  }
  while(cin >> w && w) {
    cout << dp[w] << endl;
  }
  return 0;
}

Measured memory_bytes: 1188
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static int round(int x) {
		if (x < 0) x = 0;
		else if (255 < x) x = 255;
		return x;
	}

	static boolean solve() {
		int n = in.nextInt();
		int m = in.nextInt();
		if (n + m == 0) return false;

		int[] c = new int[m];
		for (int i=0; i<m; i++) {
			c[i] = in.nextInt();
		}

		int[] x = new int[n];
		for (int i=0; i<n; i++) {
			x[i] = in.nextInt();
		}

		int INF = 1<<30;
		int[][] dp = new int[n+1][256];
		for (int i=0; i<=n; i++) {
			Arrays.fill(dp[i], INF);
		}
		dp[0][128] = 0;
		for (int i=0; i<n; i++) {
			for (int j=0; j<256; j++) {
				if (dp[i][j] == INF) continue;

				for (int k=0; k<m; k++) {
					int y = round(j + c[k]);
					int d = x[i] - y;
					dp[i+1][y] = Math.min(dp[i+1][y], dp[i][j] + d*d);
				}
			}
		}

		int min = INF;
		for (int i=0; i<256; i++) {
			min = Math.min(min, dp[n][i]);
		}

		out.println(min);

		return true;
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		while(solve());
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

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

void test(long& a, long b) {
  if (a > b) a = b;
}

int main() {
  int n;

  cin >> n;

  vector<long> h(n), ans(n);

  for (int i = 0; i < n; i++) {
    cin >> h[i];
    ans[i] = 1e9;
  }

  ans[0] = 0;
  ans[1] = abs(h[0] - h[1]);
  for (int i = 2; i < n; i++) {
    for (int j = 1; j < 2 + 1; j++) {
      // ans[i] = min(ans[i], abs(h[i] - h[i - j]) + ans[i - j]);
      test(ans[i], abs(h[i] - h[i - j]) + ans[i - j]);
      // test(ans[i], abs(h[i] - h[i - 1]) + ans[i - 1]);
      // test(ans[i], abs(h[i] - h[i - 2]) + ans[i - 2]);
    }
  }

  cout << ans[n - 1];

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#include "string"
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios_base::sync_with_stdio(false);cin.tie(nullptr)


int32_t main() { 
    boost;
	string s;
	cin>>s;
	if(s[1]=='B')
		s[1] ='R';
	else
		s[1] = 'B';
	cout<<s<<endl;     
}

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

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

int main(){

    int A, B;
    cin >> A >> B;

    cout << max(0, A - 2 * B) << endl;

}

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

#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define FILL(v,p) memset(v,p,sizeof v)
#define FIO ios::sync_with_stdio(NULL); cin.tie(NULL)
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()
#define PI acos(-1.0)

const ll MOD = 1000000007;
const ll INF = 2000000000000000001LL;
const ld EPS = 1e-9;

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


Measured memory_bytes: 256
S = input()
ff = S[:2]
bb = S[2:]

if (int(ff) > 12 or int(ff) <= 0) and (int(bb) > 12 or int(bb) <= 0):
	print('NA')
elif (int(ff) <= 12 and int(ff) > 0) and (int(bb) <= 12 and int(bb) > 0):
	print('AMBIGUOUS')
elif (int(ff) > 12 or int(ff) <= 0) and (int(bb) <= 12 and int(bb) > 0):
	print('YYMM')
else:
	print('MMYY')


Measured memory_bytes: 3064