akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void){
  int n,a,b;
  scanf("%d%d%d",&n,&a,&b);
  int max,min;
  if(a>b)max = b;
  else max  = a;
  if(a > b){
    min = a;
  }else{
    min = b;
  }
  if(a+b> n){
    min = a+b-n;
  }else{
    min = 0;
  }
  printf("%d %d",max,min);
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int kotae;
		int Mini;
		Mini = 0;

		int N = sc.nextInt();
		int X = sc.nextInt();

		int [] M;
		M = new int[N];

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

		for (int i = 0; i < N; i++){
			X = X - M[i];
		}

		Mini = M[0];

		for (int i = 0; i < N; i++){
			if (Mini < M[i]){
				Mini = Mini;
			} else {
				Mini = M[i];
			}
		}

		kotae = (X / Mini) + N;

		System.out.println(kotae);

	}
}


Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1e9+7;

int main()
{    
    ll n,k;
    cin >> n >> k;
    ll arr[n];
    for(ll i=0;i<n;++i) cin >> arr[i];
        vector<ll> ans(n+1,1000000000);
    ans[0]=0;
    for(ll i=1;i<n;++i)
    {   for(ll j=1;j<=k;++j)
        {   if(i-j>=0)
                ans[i]=min(ans[i-j]+abs(arr[i]-arr[i-j]),ans[i]);
        }
    }
    cout << ans[n-1];
    return 0;
}

Measured memory_bytes: 1792
def main():
    N, M = map(int, input().split())

    digits = [-1] * N
    for _ in range(M):
        s, c = map(int, input().split())
        s -= 1
        if ~digits[s] and digits[s] != c:
            print(-1)
            return
        digits[s] = c

    if N == 1:
        print(max(0, digits[0]))
        return

    if digits[0] == 0:
        print(-1)
        return

    if digits[0] == -1:
        digits[0] = 1

    ans = ''.join(map(str, (d if ~d else 0 for d in digits)))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9132
N,M = map(int,input().split())

lis = [float("inf")] * (2 ** N)
lis[0] = 0

for i in range(M):

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

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

    num = 0
    for j in c:
        num += 2 ** (j-1)

    nlis = lis.copy()
    for j in range(2 ** N):

        if lis[j | num] > nlis[j] + a:
            lis[j | num] = nlis[j] + a

#print (lis)
if lis[2 ** N -1] == float("inf"):
    print (-1)

else:
    print (lis[2 ** N - 1])


Measured memory_bytes: 3316
/* 
    Author : Jeff Ahn
    Sun 05 Jul 2020 05:03:59 AM PDT 
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define all(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define uint unsigned long long
#define endl '\n'

signed main() {
  fastio;
  int T; cin >> T;
  unordered_map<string,int>mp;
  while(T--){
    string s; cin >> s;
    mp[s]++;
  }
  cout << "AC x " << mp["AC"] << endl;
  cout << "WA x " << mp["WA"] << endl;
  cout << "TLE x " << mp["TLE"] << endl;
  cout << "RE x " << mp["RE"] << endl;
}


Measured memory_bytes: 3620
import java.util.*;

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

        int a = scn.nextInt();
        String op = scn.next();
        int b = scn.nextInt();

        while (!(op.equals("?"))) {
            if (op.equals("+")) {
                System.out.println((a + b));
            } else if (op.equals("-")) {
                System.out.println((a - b));
            } else if (op.equals("*")) {
                System.out.println((a * b));
            } else {
                System.out.println((a / b));
            }
            a = scn.nextInt();
            op = scn.next();
            b = scn.nextInt();


        }

        scn.close();


    }
}


Measured memory_bytes: 26056
/**
 * C - Candles
 * https://atcoder.jp/contests/abc107/tasks/arc101_a
 **/
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

#define ll long long

using namespace std;

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> x(n);
    for(int i=0; i<n; i++) cin >> x[i];
    ll ans = 1000000000;
    for(int i=0; i<n-k+1; i++) {
        ll dst = 0;
        if(x[i]<0&x[i+k-1]>0) {
            ll m_dst = 0, p_dst = 0;
            p_dst = abs(x[i])*2+x[i+k-1];
            m_dst = abs(x[i])+2*x[i+k-1];
            dst = min(p_dst, m_dst);
        } else {
            dst = max(abs(x[i+k-1]), abs(x[i]));
        }
        ans = min(ans, dst);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef vector<lld> vi;
typedef pair<lld,lld> pi;
#define F first
#define S second
#define MOD 1000000000
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for (lld i = a; i < b; i++)
lld r,j,l,x,y,m,c,n,s,f,q,i,z,p,k,d,t,u,e,g,w;string s1,s2,s3,s4,str;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);cout.tie(NULL);
  cin>>n;lld a[n];
  rep(i,0,n)
  {
    cin>>a[i];
  }s=0;
  rep(i,1,n)
  {
    s+=abs(a[i]-a[i-1]);
  }
  rep(i,0,n)
  {
    if(i==0)
    {
      cout<<s-abs(a[1]-a[0])+abs(a[1])+abs(a[n-1]);
    }
    else if(i==n-1)
    {
      cout<<s-abs(a[n-1]-a[n-2])+abs(a[0])+abs(a[n-2]);
    }
    else
    {
      cout<<s-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[0])+abs(a[n-1])+abs(a[i+1]-a[i-1]);
    }
    cout<<endl;
  }
}

Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<set>
#include<string> 
#include<vector>
#include<stack>
#include<queue> 
#define PI 3.14159265358979323846
typedef long long ll;
using namespace std;
const ll Mod=1e9+7;
ll gcd(ll a, ll b) 
{
    if (b == 0) return a;
    else gcd(b, a % b);
}
long long quick_mod(long long a,long long b)//a的b次方对Mod取余 
{
    long long ans = 1;
    a %= Mod; //对刚进来的a进行取模运算，避免后面第一次求平方运算溢出
    while(b)
    {
        if(b&1) //对二进制下的 b 进行按位与1运算，求二进制下 b 的最低位是否为1
            ans = ans * a % Mod; //对结果进行保存
        b>>=1; //二进制下的 b 右移一位，相当于十进制下的 b 除以2
        a = a * a % Mod; 
    }
    return ans % Mod;
}
const int inf=0x3f3f3f3f;
int main()
{
	ll h=0,ans=0,t=0;
	cin>>h;
	while(h!=1)
	{
		h/=2;
		t++;
	}
	ans=pow(2,t+1)-1;
	cout<<ans<<endl;
	return 0;
} 






Measured memory_bytes: 256
a, b, k = map(int, input().split())

num = range(a, b + 1)

a_k = num[:k]
k_e = num[-k:]

# print(a_k, k_e)
ans_set = set(a_k) | set(k_e)
ans_list = sorted(ans_set)
for i in ans_list:
    print(i)
    

Measured memory_bytes: 3060
import numpy as np
N = int(input())
table = np.array([[i for i in input().split()] for _ in range(N)])

vals = table[:, 0].astype(float)
conts = table[:, 1]

rates = (conts == "JPY") * 1 + (conts == "BTC") * 380000
s = (vals * rates).sum()
print(s)

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

int main()
{
  i64 m1, d1, m2, d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if (m1 == m2)
    cout << 0 << endl;
  else
    cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    int n = b - a;
    int h = 0;
    rep(i, n) h += i;
    put(h - a);
    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()

int main(){
  string S,T;cin>>S>>T;
  ll ans=0;
  rep(i,S.size()){
    if(S[i]!=T[i]) ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3916
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 20:10:24 2020

@author: Kanaru Sato
"""

n,a,b = list(map(int, input().split()))

main = (n//(a+b))*a

if n%(a+b)>a:
    print(main+a)
else:
    print(main+n%(a+b))

Measured memory_bytes: 2940
from sys import stdin
from math import factorial


def make_combinations(N, K):
    output=[]
    while(True):
        length = len(output)
        if length==0:
            output.append([i+1 for i in range(K)])
        else:
            previous = output[length-1].copy()
            for i in range(K):
                if previous[K-i-1]!=N-1-i:
                    newone = previous
                    newone[K-i-1] = previous[K-i-1]+1
                    for j in range(i):
                        newone[K-i-1+j+1] = newone[K-i-1+j]+1
                    output.append(newone)
                    break
                else:
                    continue
            if len(output) == length:
                break

    return output

def calc_sum(S, combinations):
    total_sum=0
    for combi in combinations:
        for i in range(len(combi)):
            if i==0:
                total_sum += int(S[:combi[i]])
            else:
                total_sum += int(S[combi[i-1]:combi[i]])
        total_sum += int(S[combi[len(combi)-1]:])
    return total_sum




S = str(stdin.readline().rstrip())

length = len(S)
total_number = int(S)
#total_number = 0

for i in range(length): #i:使用する+の数, 0~length-1
    if i==0: continue
    combinations = make_combinations(length,i)
    total_number += calc_sum(S, combinations)
#    combi = combination(length,i)
#    for j in range(i+1):
print(total_number)

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

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

  vector<int> a(N);
  rep(i, N) { cin >> a[i]; }
  a.push_back(0);

  int64_t result = 1'000;
  int64_t stock = 0;
  rep(i, N) {
    if (a[i] < a[i + 1]) {
      stock += result / a[i];
      result = result % a[i];
    } else if (a[i] > a[i + 1]) {
      result += stock * a[i];
      stock = 0;
    }
  }
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define all(v) v.begin(),v.end()
template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
const ll INFL = 1LL << 60;

struct Edge { int to; ll len; };

class Solver {
  public:
    vector<vector<Edge>> E;

    // => <cost to go all sub node which is not branch, longest path>
    tuple<ll, ll> solve2(int root, int prev) {
        ll sum = 0, maxi = 0;
        bool branch = true;
        for(Edge e : E[root]) {
            if(e.to == prev) continue;
            branch = false;
            auto ret = solve2(e.to, root);
            if(get<0>(ret) < 0) continue;
            set_max(maxi, get<1>(ret) + e.len);
            sum += get<0>(ret) + e.len;
        }
        return make_tuple(branch ? -INFL : sum, maxi);
    }
    
    bool solve() {
        int N; cin >> N;
        if(N == 0) return 0;
        vector<int> P(N - 1), D(N - 1); cin >> P >> D;
        E.resize(N);
        rep(i, N - 1) {
            E[i + 1].push_back(Edge{P[i] - 1, D[i]});
            E[P[i] - 1].push_back(Edge{i + 1, D[i]});
        }

        ll ans = INFL;
        rep(i, N) {
            auto ret = solve2(i, -1);
            set_min(ans, get<0>(ret) * 2 - get<1>(ret));
        }
        
        cout << ans + accumulate(all(D), 0LL) << endl;
        
        return 1;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        Solver s;
        if(!s.solve()) break;
    }
    return 0;
}

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

int main()
{
    bool prime[100005] = {};
    int sum[100005] = {};
    prime[2] = true; 
    for(int i = 3; i <= 100005; i += 2) prime[i] = true;
    for(int i = 3; i * i <= 100005; i++) {
        if(prime[i]) {
            for(int j = i * i; j <= 100005; j += 2 * i) prime[j] = false;
        }
    }
    for(int i = 3; i <= 100005; i++) {
        if(prime[i] && prime[i / 2 + 1]) sum[i]++;
        sum[i] += sum[i - 1];
    }

    int Q;
    cin >> Q;
    for(int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;
        cout << sum[r] - sum[l - 1] << endl;
    }
    return (0);
}
    

Measured memory_bytes: 1152
/* C++標準ヘッダファイル */
/* 文字列ライブラリ */
#include <string>

/* コンテナライブラリ */
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <forward_list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>

/* アルゴリズムライブラリ */
#include <algorithm>

/* 数値演算ライブラリ */
#include <cmath>

/* 入出力ライブラリ */
#include <iostream>

/* std使用<-namespace */
using namespace std;

/* define, typedef */
#define rpt(i, n) for(ll i = 0; i < (n); i++)  // リピート
typedef long long ll;

/* main関数 */
int main(void) {
	ll n;
	cin >> n;

	ll ma, mb;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ma = i; mb = n / i;
		}
	}

	cout << ma + mb - 2;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <istream>
#include <vector>
using namespace std;

int main()
{

	long long H, W;
	cin >> H >> W;
	long long answer;
	if (H == 1 || W == 1)
	{
		answer = 1;
	}else
	{
	answer = (H / 2) * W + ((H % 2 == 0) ? 0 : ((W + 1) / 2));
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;
 
ll gcd(ll a, ll b){
if(a<b){return gcd(b,a);}
else if(a%b){return gcd(b,a%b);}
else{return b;}
}
int main(){
  ll x;
  cin>>x;
  int ans = 1;
  for(int i=1; i<=x; ++i){
    for (int j=2;pow(i,j)<=x&&j<=9; j++){
    ans =max(ans,(int)pow(i,j));
    
    
    }
  }
cout << ans <<endl;
}



  


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include <algorithm>
#include <set>
#include<math.h>
#include<vector>
#include<map>
#include<vector>
#include<cstring>

using namespace std;

int main(){
    int A,B,T;cin >> A >> B >> T;
    int biscuits = 0;
    biscuits += (T/A) * B; 
    cout << biscuits << endl;



}

Measured memory_bytes: 256
import fractions
n=int(input())
t = list(map(int, input().split()))
x=0
ans = t[0]
for i in range(1, n):
    ans = ans * t[i] // fractions.gcd(ans, t[i])
for j in range(n):
    x+=ans//t[j]
print(x%(10**9+7))

Measured memory_bytes: 6200
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define con_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define con_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
using namespace std;
struct point{int x;int y;};
int i,j,k,count1=0,count2=0;

int main(){
    int x,price;
    cin>>x;
    //x*=100;
    int ans=0;
    for(i=1;i<=x;i++){
        price=i*1.08;
        if(price==x){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<":("<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, H, W;
	cin >> N >> H >> W;
	int A[N], B[N];
	rep(i, 0, N) cin >> A[i] >> B[i];

	int rsl = 0;
	rep(i, 0, N) {
		if(A[i] >= H and B[i] >= W) rsl++;
	}

	cout << rsl << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long ans=9e18,n,k,x[100001];
int main(){
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>x[i];
    for(int i=0;i<n-k+1;i++)
        if(x[i+k-1]-x[i]+min(abs(x[i]),abs(x[i+k-1]))<ans)
            ans=x[i+k-1]-x[i]+min(abs(x[i]),abs(x[i+k-1]));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;++i)
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;
const int Width = 101;
const int Height = 101;
bool mp[Height][Width]={};
int w,h;
void init(){
  fol(i,Height){
    fol(j,Width){
      mp[i][j]=1;
    }
  }
}
void printmap(){
  fol(i,h){
    fol(j,w){
      printf("%d ",mp[i][j]);
    }printf("\n");
  }
}
void solve(int x,int y,int a){
  if(a%2){
    if(a==1){
      for(int i=0;i<h;i++){
        for(int j=x-1;j>=0;j--){
          mp[i][j]=0;
        }
      }
    }else{
      for(int i=0;i<w;i++){
        for(int j=y-1;j>=0;j--){
          mp[j][i]=0;
        }
      }
    }
  }else{
    if(a==2){
      for(int i=0;i<h;i++){
        for(int j=x;j<w;j++){
          mp[i][j]=0;
        }
      }
    }else{
      for(int i=0;i<w;i++){
        for(int j=y;j<h;j++){
          mp[j][i]=0;
        }
      }
    }
  }
}
int main(){
  int n;cin>>w>>h>>n;
  int x,y,a;
  init();
  // printmap();
  fol(i,n){
    cin>>x>>y>>a;
    solve(x,y,a);
  }
  int ans = 0;
  fol(i,w){
    fol(j,h){
      ans+=mp[h-j-1][i];
    }
  }
  // printmap();
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include<stack>
using namespace std;
#define PI 3.14159265358979
typedef  long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>
int main(void)
{
    int n;
    cin>>n;
    ll ans = 0;

    for(int i=1;i<n;i++)
    {
        int ab = n-i;
        for(int j=1;j*j<=ab;j++)
        {
            if(ab%j==0)
            {
                if(ab/j==j) ans ++;
                else ans +=2;
            }
        }


    }
    cout<<ans<<endl;
}

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

using namespace std;

int main(){
	long long n,min,max,sum,a,i;
	
	cin>>n;
	
	min=LONG_LONG_MAX;
	max=LONG_LONG_MIN;
	sum=0;
	for(i=1;i<=n;i++){
		cin>>a;
		if(a<min) min=a;
		if(a>max) max=a;
		sum+=a;
	}
	
	cout<<min<<" "<<max<<" "<<sum<<"\n";
}


Measured memory_bytes: 3104
object Main extends App {
	val N = scala.io.StdIn.readInt
	val X = scala.io.StdIn.readLine.split(" ").map(_.toInt)

	val sum1 = X.map(z => z*z).sum
	val sum2 = X.sum

	if(sum2%N == 0) println(sum1 - sum2*sum2/N)
	else{
		val p1 = sum2/N
		val p2 = (sum2 + N - 1)/N

		println(math.min(N*p1*p1 - 2 * sum2 * p1 + sum1, N*p2*p2 - 2*sum2*p2 + sum1))
	}
}

Measured memory_bytes: 27328
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
void solve(){
	ll n,res=0;
	cin>>n;
	vector<ll> v(n);
	map<ll,ll> m;
	for(ll i=0;i<n;i++)
	cin>>v[i];
	for(ll i=0;i<n;i++)
	m[i-v[i]]++;
	for(ll i=0;i<n;i++){
		m[i-v[i]]--;
		res+=m[i+v[i]];
	}
	cout<<res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    for(ll i=1;i<=qc;i++)
    solve();
}


Measured memory_bytes: 27400
def solve():
  N = int(input())
  ans = [0]
  if N%2==0:
    for i in range(1,N+1):
      for j in range(i+1,N+1):
        if i+j!=N+1:
          ans[0] += 1
          ans.append(' '.join([str(i),str(j)]))
  else:
    for i in range(1,N):
      for j in range(i+1,N):
        if i+j!=N:
          ans[0] += 1
          ans.append(' '.join([str(i),str(j)]))
    for i in range(1,N):
      ans[0] += 1
      ans.append(' '.join([str(N),str(i)]))
  return ans
print(*solve(),sep='\n')

Measured memory_bytes: 9416
n,m=map(int,input().split())
d=[list(map(int,input().split())) for i in range(n)]
d.sort()
i=0
cnt=0
while m>0:
  if m-d[i][1]>=0:
    cnt+=d[i][0]*d[i][1]
    m-=d[i][1]
    i+=1
  else:
    cnt+=d[i][0]*m
    m=0
    i+=1
    
print(cnt)

Measured memory_bytes: 27756
import java.util.Scanner;

class A {
    public static void main(String... args) {
        final Scanner sc = new Scanner(System.in);
        final int H1 = sc.nextInt();
        final int M1 = sc.nextInt();
        final int H2 = sc.nextInt();
        final int M2 = sc.nextInt();
        final int K = sc.nextInt();
        final int d = H2 * 60 + M2 - H1 * 60 - M1;
        System.out.println(d - K);
    }
}
public class Main {
    public static void main(String... args) {
        A.main();
    }
}


Measured memory_bytes: 35788
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
void solve()
{
    int n;cin>>n;
    int abc[n][3];
    REP(i,n)cin>>abc[i][0]>>abc[i][1]>>abc[i][2];
    vector<vector<int> >dp(n,vector<int>(3,0));
    dp[0][0]=abc[0][0];dp[0][1]=abc[0][1];dp[0][2]=abc[0][2];
    rep(i,1,n)REP(j,3)rep(k,1,3){
        dp[i][j]=max(dp[i][j],dp[i-1][(j+k)%3]+abc[i][j]);
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
}

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

Measured memory_bytes: 6912
#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 main(){
	int n;
	cin >> n;
	vector<int> l(n);
	int ml = 0;
	int mn = 11;
	rep(i,n){
		cin >> l[i];
		if(l[i] > ml){
			ml = l[i];
			mn = i;
		}
	}
	int sum = 0;
	rep(i,n){
		if(i == mn) continue;
		sum += l[i];
	}
	if(sum > ml) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

int main() {
    int N;
    int a[110];  // 最大 100 個ですが余裕をもたせます
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> a[i];

    sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート
    int total = 0;
    for (int i = 0; i < N; ++i) {
        total += (i % 2 == 0)? a[i] : -a[i];
    }
    cout << total << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a == 5 && b == 5 && c == 7) cout << "YES\n";
    else if(a == 5 && b == 7 && c == 5) cout << "YES\n";
    else if(a == 7 && b == 5 && c == 5) cout << "YES\n";
    else cout << "NO\n";
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <map>
#include <string>
#include <tuple>
#include <vector>

const std::string wrong("WRONG");

int main() {
    int T, P, R;
    while (scanf("%d %d %d", &T, &P, &R) != EOF) {
        if (T == 0 && P == 0 && R == 0)
            break;
        
        std::map<int, std::map<int, long long int>> wrong_v;
        std::map<int, int> right_v;
        std::map<int, int> penalty_v;

        int tID, pID, time;
        char result[8];
        for (int i = 0; i < R; ++i) {
            scanf("%d %d %d %s", &tID, &pID, &time, result);
            if (result == wrong) {
                ++wrong_v[tID][pID];
            } else {
                ++right_v[tID];
                penalty_v[tID] += wrong_v[tID][pID] * 1200 + time;
            }
        }
        
        std::map<int, std::vector<std::tuple<long long int, int>>> rank;
        for (int i = 1; i <= T; ++i) {
            rank[right_v[i]].push_back(std::make_tuple(penalty_v[i], i));
        }
        for (auto it = rank.rbegin(); it != rank.rend(); ++it) {
            if (it->second.size() > 1) {
                std::sort(it->second.begin(), it->second.end());
            }
            for (auto i : it->second) {
                printf("%d %d %lld\n", std::get<1>(i), it->first, std::get<0>(i));
            }
        }
    }
}

Measured memory_bytes: 1112
from copy import deepcopy
S = input()
T = input()
s_num = len(S)
t_num = len(T)
ans = []
if s_num < t_num:
  print('UNRESTORABLE')
else:
  for i in range(s_num-t_num+1):
    s_key = S[i:i+t_num]
    judge = 0
    for s, t in zip(s_key, T):
      if s=='?':
        judge += 1
      elif s == t:
        judge += 1
    if judge == t_num:
      tmp = S[:i] + T + S[i+t_num:]
      tmp = tmp.replace('?', 'a')
      ans.append(tmp)
  if ans:
    print(sorted(ans)[0])
  else:
    print('UNRESTORABLE')

Measured memory_bytes: 9272
import numpy as np
n = int(input())
A = np.fromstring(input(), dtype=np.int32, sep=' ')
T = np.zeros(n, dtype=np.int32)

ans = []
for i in range(n-1, -1, -1):
  x = A[i]^np.logical_xor.reduce(T[i:n:i+1])
  if x:
    T[i] = 1
    ans.append(i+1)

print(len(ans))
print(*ans)

Measured memory_bytes: 34468
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author 9080384
 */
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<String> rest_list = new ArrayList<String>();
        int rest_num = sc.nextInt();
        StringBuilder sb;
        for (int i = 0; i < rest_num; i++) {
            sb = new StringBuilder();
            sb.append(sc.next());
            sb.append(-1*sc.nextInt()+1100);
            sb.append("_");
            sb.append(i+1);
            rest_list.add(sb.toString());
        }
        Collections.sort(rest_list);
        
        for(String obj : rest_list) {
            System.out.println(obj.split("_")[1]);
        }
    }
}


Measured memory_bytes: 21972
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<llint,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );
//priority_queue< int,vector<int>,greater<int> >
struct edge { int to; llint a, b; };

bool to[2510];
bool ot[2510];

void dfs(int v,vector<vector<Pint>>&G) {
	if (!to[v]) {
		to[v] = true;
		for (auto x : G[v]) {
			dfs(x.first,G);
		}
	}
}

void Rdfs(int v, vector<vector<int>>&g) {
	if (!ot[v]) {
		ot[v] = true;
		for (int  x : g[v]) {
			Rdfs(x,g);
		}
	}
}


int main(){
	int n, m, p;
	cin >> n >> m >> p;
	hei(bool) ok(n, false);
	vector<vector<Pint>> G(n);
	whei(int) g(n);
	rep(i, 0, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		c -=p;
		c = -c;
		G[a].emplace_back(b, c);
		g[b].push_back(a);

	}
	dfs(0,G);
	Rdfs(n - 1,g);
	rep(i, 0, n)ok[i] = to[i] & ot[i];
	hei(llint) dist(n, INF);
	dist[0] = 0;
	bool updata = true;
	int count = 0;
	while (updata) {
		updata = 0;
		rep(i, 0, n) {
			if (!ok[i])continue;
			for (Pint x : G[i]) {
				if (!ok[x.first])continue;
				llint New = dist[i] + x.second;
				if (New < dist[x.first]){
					dist[x.first] = New;
					updata = 1;
				}
			}
		}
		count++;
		if (count > n) {
			cout << -1 << endl;
			return 0;
		}
	}
	int ans = max((llint)0, dist[n - 1] * -1);
	cout << ans << endl<<endl;
	return 0;
}

Measured memory_bytes: 4008
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

//using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
template<typename T> void chadd(T& a, T b) { a = a + b; }

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}
}

using namespace std;

int main() {

	int N, M;
	cin >> N >> M;
	string S, T;
	cin >> S >> T;
	long L = lcm(N, M);

	int g = 1;
	for (int i = min(N, M); i > 0; i--) {
		if (N % i == 0 && M % i == 0) {
			g = i;
			break;
		}
	}
	int n = N / g;
	int m = M / g;
	for (int i = 0; i < g; i++) {
		if (S.substr(i * n, 1) != T.substr(i * m, 1)) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << L << endl;

	return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> jobs(m + 1);
    int a,b;
    for(int i=0;i < n;i++){
        cin >> a >> b;
        if(a > m) continue;
        jobs[m - a].push_back(b);
    }
    priority_queue<int> q;
    ll ans = 0;
    for(int i = m - 1;i >= 0;i--){
        for(int b : jobs[i]){
            q.push(b);
        }
        if ( !q.empty()){
            ans += q.top();
            q.pop();
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    ll a[N];
    ll t = 0;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        t = (t ^ a[i]);
    }
    for (int i = 0; i < N; i++) {
        if (i == N - 1) {
            cout << (t ^ a[i]) << "\n";
        } else {
            cout << (t ^ a[i]) << " ";
        }
    }
    return 0;
}

Measured memory_bytes: 5112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef pair<int, int> P;

const long double EPS = 1e-10;
const long long INF = 1e18;
const int MOD = (int)1e9 + 7;
const long double PI = acos(-1.0L);

const int MAX_N = 200050;

int main() {  // TODO
  ll N;
  vector<ll> AN(MAX_N);
  cin >> N;
  vector<ll> A(N);
  rep(i, N) {
    cin >> A[i];
    AN[A[i]]++;
  }
  ll base = 0;
  rep(i, MAX_N) {
    if (AN[i] < 2) continue;
    base = base + (AN[i] * (AN[i] - 1) / 2);
  }

  rep(i, A.size()) {
    ll a = A[i];
    if (AN[a] < 2) {
      cout << base << endl;
      continue;
    }
    if (AN[a] == 2) {
      cout << base - 1 << endl;
      continue;
    }
    ll diff = ((AN[a]) * (AN[a] - 1)) - ((AN[a] - 1) * (AN[a] - 2));
    cout << base - (diff / 2) << endl;
  }
  return 0;
}


Measured memory_bytes: 6336
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		int k = sc.nextInt();

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

		Arrays.sort(l);

		int sum = 0;
		for (int i = n - 1; i >= n - k; i--) {
			sum += l[i];
		}

		System.out.println(sum);

		sc.close();
	}

}


Measured memory_bytes: 23380
a, b, m = map(int, input().split())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
ans = min(arr) + min(brr)
for _ in range(m):
    x, y, c = map(int, input().split())
    ans = min(ans, arr[x - 1] + brr[y - 1] - c)
print(ans)


Measured memory_bytes: 70892
#include<iostream>
#include<string>
#include<sstream>

const int MAX = 9;

class result{
        private:
                int num[MAX + 1][MAX + 1];

        public:
                result(void);
                int getResult(int, int);
};

class output{
        private:
                result *m_pResult;
                std::string m_strLine[MAX * MAX];

        public:
                output(void);
                ~output(void);
                std::string getLine(int);
};

class screan{
        private:
                output *m_pOp;

        public:
                void setOp(output*);
                void writeLine(void);
};

class consoleApp{
        private:
                output *m_pOutput;
                screan *m_pScrean;

        public:
                consoleApp(void);
                ~consoleApp(void);
                void run(void);
};

// class result method
result::result(){
        for(int i = 1; i <= MAX; i++){
                for(int j = 1; j <= MAX; j++){
                        num[i][j] = i * j;
                }
        }
}

int result::getResult(int x, int y){
        if(x <= MAX && y <= MAX){
                return num[x][y];
        }
}

// class output method
output::output(){
        m_pResult = new result;

        int count = 0;

        for(int i = 1; i <= MAX; i++){
                for(int j = 1; j <= MAX; j++){
                        std::stringstream ss;
                        ss << i << "x" << j << "=" << m_pResult->getResult(i, j);
                        m_strLine[count] = ss.str();
                        count++;
                }
        }
}

output::~output(){
        delete m_pResult;
}

std::string output::getLine(int x){
        return m_strLine[x];
}

// class screan method
void screan::setOp(output *op){
        m_pOp = op;
}

void screan::writeLine(){
        for(int i = 0; i < MAX * MAX; i++){
                std::cout << m_pOp->getLine(i) << std::endl;
        }
}

// class consoleApp method
consoleApp::consoleApp(){
        m_pOutput = new output;
        m_pScrean = new screan;
}

consoleApp::~consoleApp(){
        delete m_pScrean;
        delete m_pOutput;
}

void consoleApp::run(){
        m_pScrean->setOp(m_pOutput);

        m_pScrean->writeLine();
}

// main function
int main(int argc, char **argv){
        consoleApp *ca = new consoleApp;

        ca->run();

        return 0;
}

Measured memory_bytes: 1180
import java.util.*;
import java.util.Arrays;
 
public class Main{
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int n = sc.nextInt();
    ArrayList<Integer> list = new ArrayList<>();
    for(int i = 0; i < n; i++){
         list.add(sc.nextInt());
    }
    
    if(n == 0){
      System.out.println(x);
      return;
    }else if(!list.contains(x)){
      System.out.println(x);
      return;
    }else{
 
      int i = 1;
      while(true){
        int a = x-i;
        int b = x+i;
        if(!list.contains(a)){
          System.out.println(a);
          return;
        }else if(!list.contains(b)){
          System.out.println(b);
          return;
        }else{
          i++;
        } 
      }
      
    }
    
  }
}

Measured memory_bytes: 36044
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

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

    for(int i = 0; i < s.size(); ++i) {
        s[i] += n;
        if(s[i] > 'Z') {
            s[i] = s[i] - 'Z' + 'A' - 1;
        }
    }

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
words = [input() for _ in range(N)]

ans = 'Yes'
if len(words) != len(set(words)):
    ans = 'No'
else:
    next_words = words[1:]+['']
    for s1,s2 in zip(words,next_words):
        if s2 and s1[-1] != s2[0]:
            ans = 'No'
            break

print(ans)

Measured memory_bytes: 3064
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    S = rl().rstrip()
    
    i = 0
    while i < len(S):
        sub_str = S[i:i + 5]
        if sub_str == 'dream':
            i += 5
            if i < len(S) - 2 and S[i:i + 2] == 'er' and S[i + 2] != 'a' or \
               i == len(S) - 2 and S[i:i + 2] == 'er':
                i += 2
        elif sub_str == 'erase':
            i += 5
            if i < len(S) and S[i] == 'r':
                i += 1
        else:
            print('NO')
            return
    print('YES')


if __name__ == '__main__':
    solve()


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

int main(){
string S; cin>>S;
if(S.size() %2 != 0){
	S.pop_back();
}
else{
	S.pop_back();
	S.pop_back();
}
	while(true){
		if(S.substr(0,S.size()/2) == S.substr(S.size()/2,S.size()/2)){
			break;
		}
		S.pop_back();
		S.pop_back();
	}
	cout << S.size() << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll;

const int N=100005,P=1000000007;
int n,k,a[N],Ans;
int Fac[N],Inv[N];

ll Pow(ll a,int b,ll s=1){for(;b;b>>=1,a=a*a%P)if(b&1)s=s*a%P;return s%P;}
inline ll C(int n,int m){return (ll)Fac[n]*Inv[m]%P*Inv[n-m]%P;}

int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;++i)scanf("%d",&a[i]);
    for(int i=Fac[0]=1;i<=n;++i)Fac[i]=(ll)Fac[i-1]*i%P;
    Inv[n]=Pow(Fac[n],P-2);
    for(int i=n;i>=1;--i)Inv[i-1]=(ll)Inv[i]*i%P;
    std::sort(a+1,a+n+1);
    for(int i=k;i<=n;++i)Ans=(Ans+(ll)a[i]*C(i-1,k-1))%P;
    for(int i=1;i<=n-k+1;++i)Ans=(Ans-(ll)a[i]*C(n-i,k-1))%P;
    printf("%d\n",(Ans+P)%P);
    return 0;
}


Measured memory_bytes: 1536
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

char s[9];
int main(){
	scanf("%s",s);
	if(strcmp(s,"RRR")==0)puts("3");
	else if(strcmp(s,"SSS")==0)puts("0");
	else if(strcmp(s,"RRS")==0||strcmp(s,"SRR")==0)puts("2");
	else puts("1");
}

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

int main() {
    int N, K, S;
    cin >> N >> K >> S;
    
    vector<int> A;
    for (int i = 0; i < K; i++) A.push_back(S);

    int x = 1;
    if (S < 1000000000) x += S;

    for (int i = 0; i < N - K; i++) A.push_back(x);

    for (int i = 0; i < N; i++) {
        if (i) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, ll> pil;

int main(void) {
  int k, n;
  ll L, R;
  cin >> n >> k >> L >> R;

  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  int n2 = n / 2, num;
  ll sum;
  vector<pil> v;
  for (int i = 0; i < (1 << n2); i++) {
    num = 0, sum = 0;
    for (int j = 0; j < n2; j++) {
      if (!(i >> j & 1)) continue;
      num++;
      sum += a[j];
    }
    v.push_back(pil(num, sum));
  }
  sort(v.begin(), v.end());

  ll ans = 0;
  for (int i = 0; i < (1 << (n - n2)); i++) {
    num = 0, sum = 0;
    for (int j = 0; j < n - n2; j++) {
      if (!(i >> j & 1)) continue;
      num++;
      sum += a[j + n2];
    }
    ans += upper_bound(v.begin(), v.end(), pil(k - num, R - sum)) - lower_bound(v.begin(), v.end(), pil(k - num, L - sum));
  }
  cout << ans << endl;

  return 0;
}


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


int main() {
    int N,M;
    cin >> N >> M;
    vector<int> A(M);
    for(int i=0;i<M;i++) cin >> A[i];

    int sum = 0;
    for(const auto& i:A) sum +=i;

    if(N>=sum) cout << N-sum << endl;
    else cout << -1 << endl;


    return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;
int main()
{
    ll a, b, c;
    cin >> a >> b >> c;

    if ((c - b - a) > 0 & 4 * a * b < (c - b - a) * (c - a - b))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int d = sc.nextInt();
		int[] c = new int[27];
		for (int i = 1; i < 27; i++) {
			c[i] = sc.nextInt();
		}
		int[][] s = new int[d + 1][27];
		for (int i = 1; i < d + 1; i++) {
			for (int j = 1; j < 27; j++) {
				s[i][j] = sc.nextInt();
			}
		}
		sc.close();

		int[] last = new int[27];
		int v = 0;
		for (int i = 1; i <= d; i++) {
			int maxType = 0;
			int maxV = 0;
			int[] vlist = new int[27];
			for (int j = 1; j < 27; j++) {
				int lastTmp = last[j];
				last[j] = i;
				int tmpV = v;
				tmpV += s[i][j];
				int downSatis = 0;
				for (int k = 1; k < 27; k++) {
					downSatis += (c[k] * (i - last[k]));
				}
				tmpV -= downSatis;
				vlist[j] = tmpV;
				if (j == 1) {
					maxType = j;
					maxV = tmpV;
				}
				if (maxV < tmpV) {
					maxV = tmpV;
					maxType = j;
				}
				last[j] = lastTmp;
			}
			v = vlist[maxType];
			last[maxType] = i;
			System.out.println(maxType);
		}
	}
}


Measured memory_bytes: 37988
#include <bits/stdc++.h>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;
int n;
double ans=0.0;
int main(int argc,char const* argv[])
{
  cin >> n;
  double money;
  string kind;
  for(int i=0;i<n;i++)
    {
      cin >> money >> kind;
      if(kind=="JPY")
	{
	  ans+=money;
	}
      else if(kind=="BTC")
	{
	  ans+=money*380000.0;
	}
    }
  cout << fixed << setprecision(9) << ans << endl;
  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int x,y;cin>>x>>y;
    if(y%2==0&&(y-2*x)>=0&&(4*x-y)>=0){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3620
<?php
fscanf(STDIN, "%d", $k);
fscanf(STDIN, "%d %d", $a, $b);
 
for ($i = $a; $i <= $b; $i++) {
    if (($i % $k) === 0) {
        echo "OK".PHP_EOL;
        exit;
    }
}
 
echo "NG".PHP_EOL;


Measured memory_bytes: 16092
#include <iostream>
#include <vector>
#include <algorithm>
int N; 
std::vector<int> p, q;
int main(){
    std::cin >> N;
    p.resize(N);
    q.resize(N);
    std::vector<int> num(N);
    for(int i = 0; i < N; i++) {
        std::cin >> p[i];
        num[i] = i + 1;
    }
    for(int i = 0; i < N; i++) std::cin >> q[i];
    int i = 0, p1, q1;
    do{
        if(num == p) p1 = i;
        if(num == q) q1 = i;
        i++;
    }while(std::next_permutation(num.begin(), num.end()));
    std::cout << std::abs(q1 - p1) << std::endl;
}

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

int main() {
	int n;
	int s = 0;
	std::vector<int> v;
	std::cin >> n;
	for (int i = 1; s + i <= n; i++) {
		v.push_back(i);
		s += i;
	}
	while (n - s >= v.size()) {
		for (int i = 0; i < v.size(); i++) {
			v[i]++;
		}
		s += v.size();
	}
	for (int i = v.size() - (n - s); i < v.size(); i++) {
		v[i]++;
	}
	for (int i = 0; i < v.size(); i++) {
		std::cout << v[i] << std::endl;
	}
	return 0;
}


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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  int n;
  cin >> n;
  vector<long> a(n);
  for (long &x : a) {
    cin >> x;
  }

  long sum = 0;
  long lmax = 0;

  for (long x : a) {
    lmax = max(lmax, x);
    sum += lmax - x;
  }
  cout << sum << endl;
}


Measured memory_bytes: 4836