akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

s = int(input())

def nCr_mod_p(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 5  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p), 0! = 1! = 1
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p), 0! = 1! = 1
inv = [0, 1]  # inv[n] = n^(-1) mod p, 0! = 1　だけど便宜上inv[0]=0にしてる

for i in range(2, N + 2):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

p = 10**9+7
ans =0

maxnum = -(-s//3)

for shikiri in range(maxnum):

    maru = s-(shikiri+1)*3
    if maru < 0: continue
    ans += nCr_mod_p(maru+shikiri,shikiri,p)
    ans %= p

print(ans%p)



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

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<string>
#include<math.h>
#include<vector>

using namespace std;

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

#define fst first 
#define snd second

const int maxn=1500005;
const double pi=acos(-1.0);
const ll mod=1000000007;

int n,k;

int main()
{
	//ios_base::sync_with_stdio(false);
	int i,j;
	scanf("%d %d",&n,&k);
	if(k==1) printf("0\n");
	else printf("%d\n",n-k);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

signed main(){
	int x,y;cin>>x>>y;
	cout<<x+y/2<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int h = sc.nextInt();
            int w = sc.nextInt();
            if (h <= 0 && w <= 0) {
                break;
            }
            for (int j = 0; j < h; j++) {
                for (int i = 0; i < w; i++) {
                    System.out.printf("#");
                }
                System.out.println();
            }
            System.out.println();
        }
        sc.close();
    }
}


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

using namespace std;

#define ll long long
#define ull unsigned long long
#define pl pair<ll, ll>
#define vll vector<ll>
#define pll vector<pair<ll, ll>>
#define f(i,a, b) for (ll i = a; i < b; i++)
#define ft int t; cin>>t; while(t--)
#define mp make_pair
#define pb push_back
#define ld float
#define fd(i,a, b) for (ll i = a; i >= b; i--)

 /*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
     typedef tree<ll ,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;*/

int main() {

  ll a,b,c;
  cin>>a>>b>>c;
  cout<<c<<" "<<a<<" "<<b;


}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)

int N;
string tail[16][16], str[16];

string shorter(string a, string b){
  if(a.size() == b.size()) return a<b?a:b;
  else return a.size() < b.size()?a:b;
}

string connect(string a, string b){
  rep(i,a.size()){
    if(a[i] == b[0]){
      int f = 1;
      rep(j,a.size()-i){
	if(j == b.size() || a[i+j] != b[j]){
	  f = 0;
	  break;
	}
      }
      if(f){
	b.erase(b.begin(), b.begin()+a.size()-i);
	return a + b;
      }
    }
  }
  return a + b;
}

int main(){
  while(cin >> N, N){
    int del[16];
    vector<string> in(N);
    memset(del,0,sizeof del);
    rep(i,N) cin >> in[i];
    sort(in.begin(), in.end());
    in.erase(unique(in.begin(), in.end()), in.end());
    N = in.size();
    rep(i,N) rep(j,N){
      if(i!=j && in[i].find(in[j]) != string::npos) del[j] = 1;
    }
    int cnt = 0;
    rep(i,N) if(!del[i]) str[cnt++] = in[i];

    N = cnt;
    rep(i,N) rep(j,N){
      if(i!=j) tail[i][j] = connect(str[i], str[j]).substr(str[i].size());
    }

    string dp[1<<11][11];
    rep(i,N) dp[1<<i][i] = str[i];

    rep(S,1<<N) rep(v,N) if((S>>v)&1){
      rep(u,N) if(!((S>>u)&1)){
	string tar = dp[S][v] + tail[v][u];
	if(dp[S|(1<<u)][u] != "") dp[S|(1<<u)][u] = shorter(dp[S|(1<<u)][u], tar);
	else dp[S|(1<<u)][u] = tar;
      }
    }

    string res = dp[(1<<N)-1][0];;
    rep(i,N)  res = shorter(res, dp[(1<<N)-1][i]);

    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1844
N,M = map(int,input().split())
ab = [[int(x) for x in input().split()]for i in range(N)]
cd = [[int(x) for x in input().split()]for i in range(M)]
for i in range(N):
  a,b = ab[i]
  ans = [10**9,-1]
  for j in range(M):
    if ans[0] > abs(cd[j][0]-a)+abs(cd[j][1]-b):
      ans = [abs(cd[j][0]-a)+abs(cd[j][1]-b),j+1]
  print(ans[1])

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

int main() {
  int N;
  std::cin >> N;
  std::vector<int> a(N);
  for (int i = 0; i < N; ++i) {
    std::cin >> a[i];
  }
  
  int ma = *std::max_element(a.begin(), a.end());
  int mi = *std::min_element(a.begin(), a.end());
  
  std::cout << ma - mi << std::endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int A,B,max=0,sum=0;
	scanf("%d %d",&A,&B);
	int A1 = A + (A-1);
	int B1 = B + (B-1);
	if(A1 > B1){
		max=A1;
	}else{
		max=B1;
	}

	for(int i=A;i>=A-1;i--){
		sum=0;
		for(int j=B;j>=B-1;j--){
			sum=i+j;
			if(max<sum){
				max=sum;
			}
		}
	}
	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define PI 3.14159265358979323846
const int MOD = 1e9 + 7 ;
const int EPS = 1e-9;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N=201010;
int sum(int x)
{
      return ((x)*((x+1))/2);
}

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
 
      int n;
      cin>>n;
      int s=0;
      if(n==2){
            cout<<"0";
            return 0;
      }
      for(int i=2;i*i<=n;i++)
      {
            if(n%i==0)
            {
                  if(n/i==i)
                  {
                        if(n/(i-1)==n/i) s+=i-1;
                  }
                  else{
                        int a=i;
                        int b=n/i;
                        if(n/(a-1)==n/a)
                        {
                              s+=a-1;
                        }
                        if(n/(b-1)==n/b) s+=b-1;
                  }
            }
      }
      cout<<s+(n-1);
} 



Measured memory_bytes: 256
import java.util.Scanner;
import java.util.regex.Pattern;

public class Main {
    private static final Pattern REGREX_PATTERN = Pattern.compile("(dream|dreamer|erase|eraser)*");    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        System.out.println(REGREX_PATTERN.matcher(S).matches() ? "YES" : "NO"); 
    }
}

Measured memory_bytes: 34868
#include<stdio.h>

main()

{
int a=0;
int W,H,x,y,r=0;

scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

if(x-r>=0&&x+r<=W){
	if(y-r>=0&&y+r<=H){
		a=1;
	}
}


else{
	a=0;
}
	if(a==1){
		printf("Yes\n");
	}
	else if(a==0){
		
		printf("No\n");
}
return 0;

}

Measured memory_bytes: 584
n = int(input())
a_list = list(map(int, input().split()))
can_path = True

for a in a_list:
    if a % 2 == 0:
        if not(a % 3 == 0 or a % 5 == 0):
            can_path = False

if can_path:
    print('APPROVED')
else:
    print('DENIED')


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

int main() {
	int a;
	int b;
	cin>>b;
	cin>>a;
	if(a%2!=0){
		cout<<"No"<<endl;
	}
	else if(a<=b*4&&a>=b*2){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>

int main(){
	int n;
	long long ans=INT_MAX;
	std::vector<long long> aList;
	std::vector<long long> aSumList;

	std::cin>>n;
	aList.resize(n);
	aSumList.resize(n, 0);

	for(int i=0; i<n; i++)
		std::cin>>aList[i];

	aSumList[0]= aList[0];
	for(int i=1; i<n; i++)
		aSumList[i]= aSumList[i-1]+aList[i];

	for(int i=0; i<n-1; i++)
		ans= std::min(ans ,std::abs(aSumList[i]- (aSumList[n-1]-aSumList[i])));


	std::cout<<ans<<std::endl;

	return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<cmath>
#include<utility>
#include<vector>
using namespace std;
int main() {
  int n,m;
  cin >> n >> m;
  long long ans=0;
  vector<pair<int,int>> p(n);
  for(int i=0; i<n; i++) {
    cin >> p[i].first >> p[i].second;
  }
  sort(p.begin(),p.end());
  for(int i=0; i<n; i++) {
    ans+=(long long)min(m,p[i].second)*p[i].first;
    m-=min(m,p[i].second);
    if(m==0) {
      break;
    }
  }
  cout << ans << endl;
}


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

using namespace std;

int main()
{
  string S, T; cin >> S >> T;

  map<char, char> sm, tm;
  for (int i = 0; i < S.size(); ++i) {
    char ss = S[i], tt = T[i];

    if (sm.count(ss) and sm[ss] != tt) {
      cout << "No" << endl;
      return 0;
    }
    if (tm.count(tt) and tm[tt] != ss) {
      cout << "No" << endl;
      return 0;
    }

    sm[ss] = tt;
    tm[tt] = ss;
  }

  cout << "Yes" << endl;
}

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

typedef long long int ll;

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

    ll ans = a[2] - a[1];
    ll t = a[1] - a[0];
    if(t % 2 == 0){
        ans += t / 2;
    }
    else{
        ans += t / 2 + 2;
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
 
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 100005;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));

void solve()
{
    ll n;
    cin >> n;
    map<string,ll> y;
    for(ll i=0;i<n;i++)
    {
        string s;
        cin >> s;
        y[s]++;
    }
    cout<<"AC x "<<y["AC"]<<"\nWA x "<<y["WA"]<<"\nTLE x "<<y["TLE"]<<"\nRE x "<<y["RE"];
}

int main()
{
    FAST;
    ll t = 1;
  //  cin >> t;
    while(t--)
    {
      solve();
    }
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

void Main(){

  int x;
  cin>>x;

  cout << (x<1200 ? "ABC" : "ARC") <<"\n";

}
//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


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

const int N = 100001;
int happi[N][3];
int dp[N][4];
int fun(int day,int choice){
	if(day<1){
		return 0;
	}
	else if(dp[day][choice]!=-1){
		return dp[day][choice];
	}
	else{
		vector<int> ans;
		for(int i=1;i<=3;i++){
			if(i==choice) continue;
			ans.push_back(happi[day][i-1]+fun(day-1,i));
		}
		return dp[day][choice] = *max_element(ans.begin(),ans.end());
	}
}


int main(){

	memset(dp,-1,sizeof(dp));

	int n;
	cin>>n;

	for(int i=1;i<=n;i++){
		for(int j=0;j<3;j++){
			cin>>happi[i][j];
		}
	}

	cout<<fun(n,0)<<endl;



	return 0;
}

Measured memory_bytes: 15488
import sys
from bisect import bisect_right as bsr
from collections import Counter as cnt
from collections import defaultdict as dd
from collections import deque
from fractions import gcd
from itertools import permutations as perm
from math import ceil, factorial, floor
from operator import itemgetter as ig

sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def yesno(v, yes="Yes", no="No", upper=False):
    if upper:
        print([yes.upper(), no.upper()][not v])
    else:
        print([yes, no][not v])


def main():
    """エントリーポイント"""
    A, B = input(int, int)
    ans = A - B - B
    print(ans if 0 < ans else 0)


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


Measured memory_bytes: 5040
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]

N,M=mint()
A=lint()
H=[-a for a in A]
heapify(H)
for _ in range(M):
    x = heappop(H)
    x = -(-x//2)
    heappush(H,x)
print(-sum(H))

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

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi std::vector<int>
#define vvi std::vector<std::vector<int> >
#define vpi std::vector<pi >
#define pi std::pair<int,int>
#define fi first
#define se second
#define all(n) n.begin(), n.end()

#define FROMTO(var, from, to) for (int var = (from), var##down = ((int)(to)) < ((int)(from));var##down ? (var >= (int)(to)) : (var <= (int)(to));var##down ? var-- : var++)
#define UPTO(var, from, to)   for (int var = (from); var <= ((int)(to)); var++)
#define DOWNTO(var, from, to) for (int var = (from); var >= ((int)(to)); var--)
#define FOR(var, to)		  UPTO(var, 0, (to)-1)
#define DOWN(var, from)	   DOWNTO(var, (from)-1, 0)

#define INIT(var, val) FOR(i,countof(var)) var[i] = val
#define INPUT(var) FOR(i,countof(var)) std::cin >> var[i]
#define INPUT1(var) FOR(i,countof(var)) std::cin >> var[i], var[i]--

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

static const int MOD = 1000000007;
static const int INF = ((1<<30)-1);
static const s64 LINF = ((1LL << 62)-1);

struct Comb {
	std::vector<std::vector<s64> > a;
	Comb(int n) { // O(n^2)
		a.resize(n+1);
		FOR(i,n+1) {
			a[i].resize(i+1, 1);
			UPTO(j,1,i-1) a[i][j] = a[i-1][j] + a[i-1][j];
		}
	}
	s64 ncr(int n, int r) {
		assert(n >= 0);
		assert(n <= (int)a.size());
		assert(r >= 0);
		assert(r <= n);
		return a[n][r];
	}
};

#define gc(c) (c)=getchar()
int ri() {
	int c,s=0,r=0;
	for(;;){gc(c);if(c=='-'){s=1;break;}if(c>='0'&&c<='9'){r=c-'0';break;}}
	for(;;){gc(c);if(c<'0'||c>'9')break;r*=10;r+=c-'0';}
	if(s)r=-r;
	return r;
}
s64 rs64() {
	s64 r = 0;
	int c,s = 0;
	for(;;){gc(c);if(c=='-'){s=1;break;}if(c>='0'&&c<='9'){r=c-'0';break;}}
	for(;;){gc(c);if(c<'0'||c>'9')break;r*=10;r+=c-'0';}
	if(s)r=-r;
	return r;
}

int int_less(const void *a, const void *b) {
	return (*(const int*)a - *(const int*)b);
}
int int_greater(const void *a, const void *b) {
	return (*(const int*)b - *(const int*)a);
}
std::string operator*(const std::string &s, int n){ std::string res; FOR(i,n) res += s; return res; }

template<class T> std::ostream& operator<<(std::ostream& os, std::vector<T> a) { for (auto i : a) os << i << " "; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, std::set<T> a) { for (auto i : a) os << i << " "; return os; }
template<class A, class B> std::ostream& operator<<(std::ostream&os, std::pair<A,B> a) { os << a.fi << "," << a.se; return os; }


int main() {
	std::string s;
	std::cin >> s;
	int res = INF;
	FOR(i,2) {
		int cur = 0;
		FOR(j,s.size()) {
			if ((i + j) % 2 != s[j] - '0') cur++;
		}
		res = std::min(res, cur);
	}
	std::cout << res << std::endl;
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 100000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
    int n,m;
    cin>>n>>m;
    int ans=-INF;
    for(int i=1;i*i<=m;i++){
        if(m%i==0){
            int a=i,b=m/i;
            if(a>ans and a<=m/n){
                ans=a;
            }
            if(b>ans and b<=m/n){
                ans=b;
            }
        }
    }
    cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
# include<iostream>
# include<vector>
# include<bits/stdc++.h>
using namespace std;
vector <int> vc;
int main(){
int n,k,l=0;
cin>>n;
for(int i=0; i<n ; i++){
    cin>>l;
    vc.push_back(l);
}
sort(vc.begin(),vc.end());
cout<<vc[vc.size()-1]-vc[0];
}


Measured memory_bytes: 256
from sys import stdin,stdout
Pi = lambda x: stdout.write(str(x) + '\n')
S = lambda x: x*(x+1) // 2
I = lambda x: 1+(2*x)
R = lambda:stdin.readline()
Ri = lambda x:map(int,x.split())
Rs = lambda x:map(str,x.split())
Rf = lambda x:map(float,x.split())
 
def main():	
	# t = int(R())
	for x in stdin:
		n = int(x)
		ans = (n//500)*1000
		n %= 500
		ans += (n//5)*5
		Pi(ans)



if __name__=='__main__':
	main()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> data_t;

int main() {
  int n,m;
  int a[114514];
  long long sum=0;
  cin >> n >> m;
  vector<data_t> b(m+1);
  a[0]=0;
  b[0].first=0;
  b[0].second=0;
  for(int i=1;i<=n;i++)cin >> a[i];
  for(int i=1;i<=m;i++)cin >> b[i].second >> b[i].first;
  sort(a,a+n+1);
  sort(b.begin(),b.end());
  int nokori=n;
  while(nokori>0){
    if(a[n]>b[m].first){
      sum+=a[n];
      n--;
      nokori--;
    }else if(nokori>b[m].second){
      sum+=b[m].first*b[m].second;
      nokori-=b[m].second;
      m--;
    }else{
      sum+=nokori*b[m].first;
      nokori=0;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 2176
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数 __builtin_popcount bitの個数

int main() {
  int N;
  ci(N);
  ve<st> W(N);
  rep(i, N){
    ci(W.at(i));
  }
  rep(i, N - 1){
    if(W.at(i).at(sz(W.at(i)) - 1) != W.at(i + 1).at(0)){
      co("No");
      rt;
    }
  }
  rep(i, N){
    rep(j, N){
      if(i != j && W.at(i) == W.at(j)){
        co("No");
        rt;
      }
    }
  }
  co("Yes");
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int T = sc.nextInt();
		int A = sc.nextInt();
		int ans = 0;
		double min = 10000;
		for (int i = 1; i <= N; i++) {
			double temp = sc.nextDouble();
			double dif = Math.abs(A - (T - temp * 0.006));
			if (dif < min) {
				ans = i;
				min = dif;
			}
		}
		System.out.println(ans);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

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

int main() {
    int n;
    long long a;
    long long minValue = 1000000;
    long long maxValue = -1000000;
    long long sum = 0;

    cin >> n;

    for(int i = 0; i < n; i++) {
        cin >> a;
        if(a < minValue)minValue = a;
        if(a > maxValue)maxValue = a;
        sum += a; 
    }
    cout << minValue << " " << maxValue << " " << sum << endl;

    return 0; 
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)

using namespace std;
int main(){
    long long N;
    cin>>N;
    map<long long,int> a;
    REP(i,N){
        long long k;
        cin>>k;
        if(a[k]){
            cout<<"NO"<<endl;
            return 0;
        } else {
            a[k] = 1;
        }
    }
    cout<<"YES"<<endl;
}

Measured memory_bytes: 12800
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())


ans = 0
M = inp()
zan = []
for m in range(M):
    d,c = inpl()

    while True:
        if c == 1:
            zan.append(d)
            break
        elif c%2 == 0:
            if d == 0:
                ans += c
                break
            elif d <= 4:
                ans += c//2
                d *= 2
                c //= 2
            else:
                ans += c
                d = d*2 - 9
                c //= 2
        else:
            zan.append(d)
            c -= 1

zan.reverse()

bx = zan[0]
for x in zan[1:]:
    d = x + bx
    if d >= 10:
        bx = d - 10 + 1
        ans += 2
    else:
        bx = d
        ans += 1

print(ans)


Measured memory_bytes: 142736
#include <bits/stdc++.h>
using namespace std;
int main() {
  int S;
  cin >> S;
  int n1, n2, n3, n4, a;
  n1 = S/1000%10;
  n2 = S/100%10;
  n3 = S/10%10;
  n4 = S%10;
  if (n1 == n2)
      a++;
  if (n2 == n3)
      a++;
  if (n3 == n4)
      a++;
  if ( a == 0 )
    cout << "Good" << endl;
  else
    cout << "Bad" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, less<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 100'000;
const int LOGN = 18;

int n, m, k;
int64 d[2002][2002];

void solve(int test)
{
  cin >> n >> k;
  for (int i = 0; i <= n + 1; ++i) {
    d[1][i] = 1;
  }
  for (int i = 2; i <= n + 1; ++i) {
    int64 s = 0;
    for (int j = 0; j <= n + 1; ++j) {
      s += d[i - 1][j];
      s %= mod;
      d[i][j] = s;
    }
  }
  for (int i = 1; i <= k; ++i) {
    if (n - k - i + 1 < 0) {
      cout << "0\n";
      continue;
    }
    int v1 = d[i][k - i];
    int v2 = d[i + 1][n - k - i + 1];
    cout << v1 * 1ll * v2 % mod << '\n';
  }
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
    solve(i);
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 31616
#include <iostream>
using namespace std;
int main()
{
    int K, A, B;
    cin >> K;
    std::cin >> A >> B;
    int Act = B / K * K;

    if (A <= Act && Act <= B)   cout << "OK\n" << endl;
    else cout << "NG\n" << endl;
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DBG(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define DBG(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define CIN(type, ...) \
  type __VA_ARGS__;    \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define COUT(...) write_to_cout(__VA_ARGS__);

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, n) for (auto i : (n))
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

template <typename T>
std::map<T, int> Factorize(T x) {
  std::map<T, int> m;
  for (T i = 2; i * i <= x;) {
    if (x % i == 0) {
      m[i]++;
      x /= i;
    } else {
      ++i;
    }
  }
  if (x > 1) m[x]++;
  return m;
}

int main() {
  ll N;
  cin >> N;
  map<ll, int> m = Factorize(N);
  int ans = 0;
  for (const auto p : m) {
    DBG(p.first, p.second);
    int x = p.second;
    for (int i = 1; i <= x; ++i) {
      x -= i;
      ++ans;
      DBG(i, x);
    }
  }
  COUT(ans);
}


Measured memory_bytes: 3628
#include<cstdio>
#include<algorithm>
#define INF 2147483647
using namespace std;

int n,q;
int com;
int tree[311111]; 

void init();
void update(int i, int x);
int segtree_find(int x, int y, int now, int left, int right);

int main(){

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

  init();

  for(int i=0;i<q; i++){
    scanf(" %d",&com);

    if(com){
      int x,y;
      scanf(" %d %d",&x,&y);
      printf("%d\n",segtree_find(x, y, 0, 0, n-1));
    } else {
      int x, y;
      scanf(" %d %d",&x,&y);
      update(x, y);
    }
  }

  return 0;
}


void init(){

  int m = n;
  n = 1;
  while(n < m)n = (n<<1);

  fill(tree, tree+n*2, INF);

  return;
}

void update(int i, int x){
  i = i + n - 1;
  tree[i] = x;

  while(i > 0){
    i = (i - 1) / 2;
    tree[i] = min(tree[i * 2 + 1], tree[i * 2 + 2]);
  }

  return;
}

int segtree_find(int x, int y, int now, int left, int right){

  if(right < x || y < left)return INF;


  if(x <= left && right <= y)return tree[now];

  if(now > n * 2)return -1;

  int find_left = segtree_find(x, y, (now * 2 + 1), left, ((right + left) / 2));
  int find_right = segtree_find(x, y, (now * 2 + 2), ((right + left) / 2 + 1), right);

  return min(find_left, find_right);
}

Measured memory_bytes: 3688
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){
    string S,T;

    cin >> S >> T;

    S = S+S;

    for(int i = T.length(); i > 0; i--){
        string s = S.substr(i, T.length());

        if(s == T){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
 
    return 0;
}

Measured memory_bytes: 256
s=raw_input()
l=len(s)

i=0
cnt=0
ans=0
while i<l:
	x=s[i]
	if x=="A":
		i+=1
		cnt+=1
	elif i+1<l and s[i]=="B" and s[i+1]=="C":
		i+=2
		ans+=cnt
	else:
		i+=1
		cnt=0


print ans

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

using i64 = long long;
using u64 = unsigned long long;

const int mod = (int)1e9+7;

void __print() {cerr << "]\n";}

template<typename T, typename... V>
void __print(T t, V... v)
{ cerr << t; if(sizeof...(v)) cerr << ", "; __print(v...);}

#define dbg(x...) cerr << __LINE__ << " : [" << #x << "] = ["; __print(x)


int main()
{
    string s;
    cin >> s;
    int len = s.length();
    s += '#';
    int a[len+5];
    memset(a, 0, sizeof(a));
    for(int i = 0; i < len; i++) {
        if(s[i] == 'R' && s[i+1] == 'L') {
            int j = i;
            while(j >=0 && s[j] == 'R') j--;
            if(s[j] == 'R') j--;
            int k = i+1;
            while(k < len && s[k] == 'L') k++;
            if(s[k] == 'L') k++;
            a[i] = i-j;
            a[i+1] = k-i-1;
            int x = a[i] + a[i+1];
            // dbg(x);
            if(x%2==0) a[i] = x/2, a[i+1] = x/2;
            else {
                if(a[i+1] > a[i]) {
                    if(a[i+1] % 2) {
                        a[i] = x/2 ;
                        a[i+1] = x - a[i];
                    } else {
                        a[i] = x/2 + 1;
                        a[i+1] = x - a[i];
                    }
                } else {
                    if(a[i] % 2) {
                        a[i+1] = x/2;
                        a[i] = x - a[i+1];
                    } else {
                        a[i+1] = x/2 + 1;
                        a[i] = x - a[i+1];
                    }
                }
            }
        }
    }
    for(int i = 0; i < len; i++) printf("%d ", a[i]);
    puts("");
}


Measured memory_bytes: 4252
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;


int main() {
  long long n;
  cin >> n;
  vector<pair<long long, long long> > a(n);
  for(int i = 0; i < n; ++i){
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.rbegin(), a.rend());
  vector<vector<long long> > d(n + 1, vector<long long>(n + 1));
  for(int i = 0; i < n; ++i)
      for(int j = 0; i + j < n; ++j){
        long long k = i + j;
        d[i + 1][j] = max(d[i + 1][j], d[i][j] + a[k].first * abs(a[k].second - i));
        d[i][j + 1] = max(d[i][j + 1], d[i][j] + a[k].first * abs(-n + j + 1 + a[k].second));
      }
  long long ans = 0;
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j) ans = max(ans, d[i][j]);
  }
  cout << ans;
}

Measured memory_bytes: 34600
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    k = int(input())
    n = 50
    s = k // n
    amari = k % n
    res = list(range(n-1, -1, -1))
    for i in range(n):
        res[i] += s
    cnt = 0
    while cnt < amari:
        cnt += 1
        res[-cnt] += n+1
        for i in range(n):
            res[i] -= 1
    print(n)
    print(*res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38512
/* template.cpp [[[ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)s)
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)s)
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* ]]] */

int main(){
  int n;
  cin >> n;
  cout << n * (n + 1) / 2 << endl;
}



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

using namespace std;

int main(void) {
	int N, M;
	cin >> N >> M;
	vector<vector<int> > ss;
	for(int i = 0; i < M; ++i) {
		int k;
		cin >> k;
		vector<int> s;
		for(int j = 0; j < k; ++j) {
			int t;
			cin >> t;
			s.push_back(t - 1);
		}
		ss.push_back(s);
	}
	vector<int> p;
	for(int i = 0; i < M; ++i) {
		int t;
		cin >> t;
		p.push_back(t);
	}
	int ans = 0;
	for(unsigned int b = 0; b < (1 << N); ++b) {
		bool ok = true;
		for(int i = 0; i < M; ++i) {
			bool sw = false;
			for(int j = 0; j < ss[i].size(); ++j) {
				sw ^= ((b & (1 << ss[i][j])) != 0);
			}
			if(sw != p[i]) ok = false;
		}
		if(ok) ++ans;
	}
	cout << ans << '\n';
	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  cout << (a-1)*(b-1) << endl;
  return 0;
}

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

int main() {
	// your code goes here
	
	
	int n;
	cin>>n;
	
	int a[n], b[n], c[n];
	
	for(int i = 0; i < n; i++) cin>>a[i]>>b[i]>>c[i];
	
	int dp[n+1][3];
	
	dp[1][0] = a[0];
	dp[1][1] = b[0];
	dp[1][2] = c[0];
	
	for(int i = 2; i <=n; i++){
	    for(int j = 0;j < 3; j++){
	        if(j == 0) {
	            dp[i][j] = a[i-1] + max(dp[i-1][1], dp[i-1][2]);
	        }
	        if(j == 1){
	            dp[i][j] = b[i-1] + max(dp[i-1][0], dp[i-1][2]);
	        }
	        
	        if(j == 2) {
	            dp[i][j] = c[i-1] + max(dp[i-1][0], dp[i-1][1]);
	        }
	    }
	}
	
	
	cout<<max(dp[n][0], max(dp[n][1],dp[n][2]));
	
	
	
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
long long i, j, k;
long long MOD = 1e9+7;

long long power_mod(long long num, long long power){
    long long prod = 1;
    num %= MOD;
    while(power > 0){
        if((power&1) == 1){
            prod = prod * num % MOD;
        }
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}
long long N, C;
long long A[400], B[400];
long long accum[401][401];
long long dp[401];

int main(){
    cin >> N >> C;
    for(i=0; i<N; i++){
        cin >> A[i];
    }
    for(i=0; i<N; i++){
        cin >> B[i];
    }
    for(i=1; i<=400; i++){
        for(j=0; j<=C; j++){
            accum[i][j] = accum[i-1][j] + power_mod(i, j);
            accum[i][j] %= MOD;
        }
    }
    dp[0] = 1;
    for(i=0; i<N; i++){
        for(j=C; j>=0; j--){
            dp[j] *= B[i]-A[i]+1;
            dp[j] %= MOD;
            for(k=1; k<=j; k++){
                dp[j] += dp[j-k] * (accum[B[i]][k] - accum[A[i]-1][k] + MOD);
                dp[j] %= MOD;
            }
        }
    }
    cout << dp[C] << endl;
    return 0;
}

Measured memory_bytes: 1536
n=int(input())
l=[['M',0],['A',0],['R',0],['C',0],['H',0]]
for i in range(n):
  s=str(input())
  string=s[0]
  if string=='M':
    l[0][1]+=1
  if string=='A':
    l[1][1]+=1
  if string=='R':
    l[2][1]+=1
  if string=='C':
    l[3][1]+=1
  if string=='H':
    l[4][1]+=1
sum=0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      sum+=l[i][1]*l[j][1]*l[k][1]
print(sum)

Measured memory_bytes: 3064
using System.Linq;
using System.Collections.Generic;
using System;

public class P
{
    public string cut { get; set; }
    public int p { get; set; }
    public int sum { get; set; }
}

public class hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var t = line[0];
            var s = line[1];
            if (t == "0" && s == "0") break;
            getAns(t, s);
        }
    }
    static bool check(string t, string s)
    {
        if (t == s) { Console.WriteLine("{0} {1}", t, s); return false; }
        var sum = 0;
        for (int i = 0; i < s.Length; i++)
            sum += s[i] - '0';
        if (sum > int.Parse(t)) { Console.WriteLine("error"); return false; }
        else return true;
    }
    static void getAns(string t, string s)
    {
        if (!check(t, s)) return;
        var ta = int.Parse(t);
        var sL = s.Length;
        var q = new Queue<P>();
        for (int i = 1; i <= sL; i++)
        {
            var w = s.Substring(0, i);
            var ip = int.Parse(w);
            if (ip <= ta) q.Enqueue(new P { cut = i.ToString(), p = i, sum = ip });
            else break;
        }
        var ans = 0;
        var ansp = new List<P>();
        while (q.Count() > 0)
        {
            var a = q.Dequeue();
            if (a.p >= sL)
            {
                if (a.sum == ans)
                {
                    ansp.Add(a);
                }
                else if (a.sum > ans)
                {
                    ansp.Clear();
                    ansp.Add(a);
                    ans = a.sum;
                }
            }
            for (int i = 1; i <= sL - a.p; i++)
            {
                var w = s.Substring(a.p, i);
                var ip = int.Parse(w);
                if (a.sum + ip <= ta) q.Enqueue(new P { cut = a.cut + i.ToString(), p = a.p + i, sum = a.sum + ip });
                else break;
            }
        }
        if (ansp.Count() > 1) Console.WriteLine("rejected");
        else print(ansp[0], s);
    }
    static void print(P a, string s)
    {
        var cut = new List<int>() { a.sum };
        var sp = 0;
        var cp = 0;
        while (cp < a.cut.Length)
        {
            var w = a.cut[cp++] - '0';
            var w2 = s.Substring(sp, w);
            sp += w;
            cut.Add(int.Parse(w2));
        }
        Console.WriteLine(string.Join(" ", cut));
    }
}


Measured memory_bytes: 16764
import bisect
N = int(input())
Ln = list(map(int,input().split(' ')))

def binary_area_search(target_list: list, target_item: int) -> int:
    '''
    @params
    target_list: [1,3,5](ACC)
    target_item: 2

    @return
    return index
    '''
    low = 0
    high = len(target_list) - 1
    while low <= high:
        mid = (low + high) //2
        guess = target_list[mid]
        if guess > target_item:
            if mid == 0:
                return 0
            if target_item > target_list[mid-1]:
                return mid 
            high = mid -1
        else:
            if mid == len(target_list) - 1:
                return None
            if target_list[mid+1] > target_item:
                return mid + 1 
            low = mid + 1
    return None

def main():
    '''
    N^2*logN
    '''
    Ln.sort()
    count = 0
    for a in range(N):
        a_l = Ln[N-a-1]
        for b in range(a+1, N):
            b_idx = N-b-1
            b_l = Ln[b_idx]
            c_threshold = a_l - b_l
            #c_list = Ln[0:N-b-1]
            c_idx = bisect.bisect_right(Ln,c_threshold)
            #c_idx = binary_area_search(c_list,c_threshold)
            if c_idx >= b_idx:
                continue
            count += b_idx - c_idx
    print(count)

def main2():
    '''
    N^2
    '''
    Ln.sort(reverse=True)
    count = 0
    for a in range(N):
        a_l = Ln[a]
        current_min = N-1
        b = a +1
        while b <= current_min:
            c_idx = current_min
            bc = Ln[b] + Ln[c_idx]
            if a_l < bc:
                count += (current_min - b)
                b += 1
                continue
            current_min -= 1
    print(count)

def main3():
    '''
    N^2*logN
    '''
    Ln.sort()
    count = 0
    for a in range(N):
        a_l = Ln[N-a-1]
        for b in range(a+1, N):
            b_idx = N-b-1
            b_l = Ln[b_idx]
            c_threshold = a_l - b_l
            #c_list = Ln[0:b_idx+1]
            c_idx = bisect.bisect_right(Ln,c_threshold)
            #c_idx = binary_area_search(c_list,c_threshold)
            if c_idx >= b_idx:
                continue
            count += b_idx - c_idx
    print(count)

main3()

Measured memory_bytes: 3192
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] v = new int[N];
		int[] c = new int[N];
		int[] num = new int[N];

		for (int i = 0; i < N; i++) {
			v[i] = sc.nextInt();
			num[i] = v[i] - c[i];
		}
		for (int i = 0; i < N; i++) {
			c[i] = sc.nextInt();
		}
		for (int i = 0; i < N; i++) {
			num[i] = v[i] - c[i];
		}

		int sum = 0;
		for (int i = 0; i < N; i++) {
			if (num[i] > 0) {
				sum += num[i];
			}
		}

		System.out.println(sum);
	}
}


Measured memory_bytes: 21844
#include <iostream>

int main()
{
    char c;
    for (int i = 0; i < 3; ++i)
    {
        std::cin >> c;
        if (c == '7')
        {
            std::cout << "Yes\n";
            return 0;
        }
    }
    std::cout << "No\n";
    return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>
#include<math.h>
int main(void){
    double n,large,pw,i;
    scanf("%lf",&n);
    large=1000000007;
    pw=1;
    for(i=1;i<=n;i++){
        pw*=i;
        pw=fmod(pw,large);
    }
    printf("%.0lf\n",pw);
    return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;
int main(){
    int N; cin >> N; 
    string S, S_=""; cin >> S;
    int l=0, r= 0;
    for(int i = 0; i < N; i++){
        if(S[i] == '('){
            l++;
        }
        else{
            if(l > 0) l--;
            else r++;
        }
    }
    for(int i = 0; i < r; i++){
        S_+= '(';
    }
    S_+=S;
    for(int i = 0; i < l; i++){
        S_+=')';
    }
    cout << S_ << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

using namespace std;
int main(void)
{
	double a[10];
	double v[2];
	double ans;
	while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9],&v[0],&v[1]) != EOF)
	{
		double all = 0;
		double kari = 0;
		for(int i = 0;i < 10;i++) all += a[i];
		ans = (v[0] * all) / (v[0] + v[1]);
		if(ans == 0) printf("1\n");
		else
		{
			for(int i = 0;i < 10;i++)
			{
				kari += a[i];
				if(kari >= ans)
				{
					printf("%d\n",i+1);
					break;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1052
#include <iostream>
#include <set>

using namespace std;

int main() {
  int n;
  string str;
  cin >> n;
  set<string> st;
  for(int i=0; i<n; i++){
    cin >> str;
    st.insert(str);
  }
  cout << st.size() << endl;
  return 0;
}

Measured memory_bytes: 19228