akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << endl; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;

VV G;
V c, sz;
Vll ans;
vector<map<int, int>> dp;

void dfs(int u, int p=-1) {
  for (auto v : G[u]) {
    if (v == p) continue;
    dfs(v, u);
    ll x = sz[v] - dp[v][c[u]];
    ans[c[u]] -= x*(x+1)/2;
    if (dp[u].size() < dp[v].size()) swap(dp[u], dp[v]);
    for (auto &[a, b] : dp[v]) dp[u][a] += b;
    sz[u] += sz[v];
  }
  dp[u][c[u]] = sz[u];
}

int main() {
  ll n; cin >> n;

  G.assign(n, V());
  c.assign(n, 0);
  sz.assign(n, 1);
  ans.assign(n, n*(n+1)/2);
  dp.assign(n, map<int, int>());

  rep(i, n) {
    cin >> c[i];
    --c[i];
  }
  rep(i, n-1) {
    int a, b; cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  dfs(0);
  rep(i, n) {
    ll x = sz[0] - dp[0][i];
    ans[i] -= x*(x+1)/2;
  }

  cout << ans;
  return 0;
}


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

const ll MOD=1000000007;

int main(){
    ll X;
    cin>>X;
    bool flag=true;
    for(ll i=-300;i<300;i++){
        if(flag==false){
            break;
        }
        for(ll j=-300;j<300;j++){
            if(i*i*i*i*i-j*j*j*j*j==X){
                cout<<i<<" "<<j<<endl;
                flag=false;
                break;
            }
        }
    }
}

Measured memory_bytes: 3672
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  cout << fixed << setprecision(10);
  int n;
  while(cin >> n,n){
    vi a(n);
    REP(i,n) cin >> a[i];
    double m = 0;
    REP(i,n) m += a[i];
    m /= n;
    double s = 0;
    REP(i,n) s += (a[i]-m)*(a[i]-m);
    s /= n;
    cout << sqrt(s) << endl;
  }
}


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

using namespace std;

int main(){
	char s[200005];
	scanf("%s",s+1);
	long long sum=0;
	for(int i=1;i<=strlen(s+1);i++){
		sum+=s[i]-'0';
	}
	if(sum%9==0)
		printf("Yes");
	else
		printf("No");
}

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

using namespace std;

int main() {
	int n;
	while (cin >> n, n) {

		vector<vector<int>>list(n, vector<int>(n, 0));
		int number;

		for (int i = 0;i < n;i++) {
			cin >> number;
			for (int j = 0;j < number;j++) {
				int codename;
				cin >> codename;
				list[i][codename - 1] = 1;
			}
		}//list[a][b]:a know b

		cin >> number;
		
		vector<int>ans(n,1);
		int leaked;
		for (int i = 0;i < number;i++) {
			cin >> leaked;
			for (int j = 0;j < n;j++) {
				if (list[j][leaked - 1] == 0) ans[j] = 0;
			}
		}//who is imposible
		int sum = 0,telltale;

		for (int i = 0;i < n;i++) {
			sum += ans[i];
			if (ans[i] == 1) telltale = i + 1;
		}

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

	}
	return 0;
}

Measured memory_bytes: 3112
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
    int main(){
      vector<pint> v[2];
      int h,w;
      cin >> h >> w;
      int a[h][w+1];
      rep(i,h){
       rep(j,w)cin >> a[i][j];
      }
      rep(i,h){
       rep(j,w){
        if(a[i][j]%2==1 && j+1<=w-1){
          v[0].push_back({i,j});
          v[1].push_back({i,j+1});
          a[i][j+1]++;
        }
         else if(a[i][j]%2==1 && j==w-1 && i+1<=h-1){
          v[0].push_back({i,j});
          v[1].push_back({i+1,j});
           a[i+1][j]++;
         }
       }
      }
      cout << v[0].size() << endl;
      rep(i,v[0].size()){
        cout << v[0][i].first+1 << ' ' << v[0][i].second+1 << ' ' << v[1][i].first+1 << ' ' << v[1][i].second+1 << endl;
      }
      return 0;}

Measured memory_bytes: 5228
s = list(input())
if ((s[0] == s[1] and s[2] == s[3]) or (s[0] == s[2] and s[1] == s[3]) or (s[0] == s[3] and s[2] == s[1])) and not(s[0] == s[1] == s[2] == s[3]):
         print("Yes")
else:
         print("No")


Measured memory_bytes: 3060
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back

/*
#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64
#endif
*/

const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

typedef long long ll;

long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}


int main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    int A = readInt(), B = readInt();
    if (A <= 0 && 0 <= B) {
    	cout << "Zero";
    	return 0;
    }
    if (A > 0) {
		cout << "Positive";
		return 0;    
    }
	int cnt = abs(A - B);
	if (cnt & 1) {
		cout << "Positive";
	} else {
		cout << "Negative";
	}
    return 0;
}

Measured memory_bytes: 256
C = []
for _ in range(3):
    c = list(map(int, input().split()))
    C.append(c)

ans = 'Yes'
for i in range(2):
    d = C[2][i+1] - C[2][i]
    for j in range(2):
        if C[j][i+1] - C[j][i] != d:
            ans = 'No'
print(ans)



Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 500001
#define MOD 1000000007

typedef long long int lli;

lli Sum(lli x) {
  return (1 + x) * x / 2;;
}

int main(void) {
  char s[MAX];
  scanf("%s", s);

  lli n = strlen(s);

  lli vsize = 0, val[MAX]; // <,>,...,<,>となる配列
  char now = '<';
  lli cnt = 0;
  rep(i, 0, n) {
    if (s[i] == now) cnt++;
    else {
      val[vsize++] = cnt;
      now = now == '<' ? '>' : '<';
      cnt = 1;
    }
  }
  val[vsize++] = cnt;

  if (vsize % 2 == 0) val[vsize++] = 0;

  lli ans = 0;
  for (int i = 0; i < vsize; i += 2) {
    if (val[i] > val[i + 1]) 
      ans += Sum(val[i]) + Sum(val[i + 1] - 1);
    else
      ans += Sum(val[i] - 1) + Sum(val[i + 1]);
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 4608
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int H,W;
	while(true){
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0) break;
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				if((i+j)%2 == 0) printf("#");
				else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
}


Measured memory_bytes: 2668
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m,v,p = LI()
    a = LI()
    a.sort()
    l = -1
    r = n-1
    while r-l > 1:
        i = (l+r) >> 1
        ai = a[i]
        aim = ai+m
        ri = bisect.bisect_right(a,aim)
        if n-ri >= p:
            l = i
            continue
        cnt = 0
        for j in range(n-p+1):
            if i == j:
                continue
            cnt += min(m,aim-a[j])
        if cnt >= m*(v-p):
            r = i
        else:
            l = i
    print(n-r)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 58736
void main()
{
    long n = readln.chomp.to!long;
    long[] a = readln.split.to!(long[]);

    a.sort!"a < b";
    long ind;
    long size = a[0];
    foreach (i; 1 .. n)
    {
        if (size * 2 < a[i]) ind = i;
        size += a[i];
    }

    writeln(n - ind);
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 4532
n = int(input())
a = [0] + list(map(int, input().split()))
x = a[:]
ans = []
for i in range(n, 0, -1):
    j = 2 * i
    while j <= n:
        x[i] ^= x[j]
        j += i
    if x[i] == 1:
        ans.append(i)

print(len(ans))
if ans:
    print(' '.join(list(map(str, ans))))

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

long long int dp[100001];
int n,m;
const long long int INF = 1e18;
struct line
{
	int l,r,c;
};
vector <line> l;
bool cmp(line a,line b)
{
	if(a.l==b.l)
	{
		return a.c < b.c;
	}
	return a.l < b.l;
}


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

	cin >> n >> m;

	for(int i=0;i<m;i++)
	{
		cin >> t.l >> t.r >> t.c;
		l.push_back(t);
	}

	fill(dp,dp+100001,INF);
	sort(l.begin(),l.end(),cmp);

	if(l[0].l!=1)
	{
		cout << -1 << '\n';
		return 0;
	}

	multiset <long long int> S;
	priority_queue <pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pque;

	for(int i=0;i<m;i++)
	{
		while(!pque.empty())
		{
			if(pque.top().first < l[i].l)
			{
				S.erase(S.find(dp[pque.top().second]));
				pque.pop();
			}
			else
			{
				break;
			}
		}

		if(l[i].l==1)
		{
			dp[i] = l[i].c;
			S.insert(dp[i]);
			pque.push(make_pair(l[i].r,i));
		}
		else
		{
			if(S.size()!=0)
			{
				dp[i] = *S.begin() + l[i].c;
				S.insert(dp[i]);
				pque.push(make_pair(l[i].r,i));
			}
		}
	}

	long long int res = INF;
	for(int i=0;i<m;i++)
	{
		if(l[i].r==n)
		{
			res = min(res,dp[i]);
		}
	}

	if(res==INF)
	{
		res = -1;
	}

	cout << res << '\n';

	return 0;
}


Measured memory_bytes: 5236
/*      西江月·证明
	即得易见平凡，仿照上例显然。
   留作习题答案略， 读者自证不难。

	反之亦然同理，推论自然成立。
	略去过程QED，由上可知证毕。*/
# pragma GCC optimize (1)
# pragma GCC optimize (2)
# pragma GCC optimize (3)
# pragma GCC optimize ("Ofast")
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstdio>
#define kkk register
#define ll long long
#define inf 2147098934832ll
using namespace std;
ll read(){ll ans=0,f=1;char a=getchar();while(a>'9'||a<'0'){if(a=='-')f=-1;a=getchar();}while(a>='0'&&a<='9')ans=(ans<<3)+(ans<<1)+a-'0',a=getchar();return ans*f;}
//一条long long的黄金分割线-----------------------------------------------------------------------------------------------------------------------------------
ll a[2000005],S,n;
int main(){
	n=read();
	for(int i=1;i<=n;i++)a[i]=read(),S^=a[i];
	for(int i=1;i<=n;i++)printf("%lld ",S^a[i]);
	return 0; 
} 

Measured memory_bytes: 5220
#include <bits/stdc++.h>
#pragma GCC optimize("O999")
//示例：#define ll long long
//unsigned long long ;
const int INF=0x3f3f3f3f;
const int maxn=50000005;
using namespace std;

int main(){
	//freopen(".in", "r",stdin );
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(0);
	long long a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	if(fabs(a-c)<=e*(b-d))
		cout<<"YES"<<endl;
	else
		cout<<"NO" <<endl;
	return 0;
}

Measured memory_bytes: 3608
n=int(input())
A=list(map(int,input().split()))
from collections import deque
b=deque()
for i in range(n):
    if i%2==0:
        b.appendleft(A[i])
    elif i%2==1:
        b.append(A[i])
ans=''
if n%2==0:
    for i in range(n):
        ans+=str(b[n-i-1])+' '
else:
    for i in range(n):
        ans+=str(b[i])+' '
print(ans[:-1])

Measured memory_bytes: 26020
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    int a,b,c;cin>>a>>b>>c;
    int d=10*a+b+c;
    int e=10*b+c+a;
    int f=10*c+a+b;
    cout<<max({d,e,f})<<endl;

    
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main() {
  int k; cin >> k;
  string s; cin >> s;
  if(s.size() <= k) {
    cout << s << endl;
  }
  else {
    for(int i = 0; i < k; i++) {
      cout << s.at(i);
    }
    cout << "..." << endl;
  }
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define SZ(X) ((int)(X).size())
#define endl "\n";
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	string a,b;
	int n;
	cin>>a>>b;
    n=stoi(a+b);
    for (int i = 1; i*i <= n; ++i)
    {
    	if(i*i==n){
    		cout<<"Yes";
    		return 0;
    	}

    }
	cout<<"No";

   return 0;
}


Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define H 50
#define W 50
#define INF 1e+9
int h;
int w;
char m[H][W];
int dfs(int y, int x)
{
    int res = 0;
    for (int i = -1; i <= 1; i++)
    {
        for (int j = -1; j <= 1; j++)
        {
            int ny = y + i;
            int nx = x + j;
            if (0 <= ny && ny < h && 0 <= nx && nx < w)
            {
                if (m[ny][nx] == '#')
                {
                    res++;
                }
            }
        }
    }
    return res;
}
int main()
{
    cin >> h >> w;
    rep(i, h)
    {
        rep(j, w)
        {
            cin >> m[i][j];
        }
    }
    rep(i, h)
    {
        rep(j, w)
        {
            if (m[i][j] == '#')
            {
                cout << '#';
            }
            else
            {
                cout << dfs(i, j);
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
# O(n * log(n)) で解く

def g(i, n, t) $a_sums[i] + h(i+1, n, t) end    # O(n)
def h(i, n, t) (i..n).inject(0) do |s,j| s + t / $fs[j] end end    # O(n)
def afs(i) $as[i] * $fs[i] end    # O(1)
def nlr(n, l, i) [n - i, l - $a_sums[i], $rs[i+1]] end    # O(1)

n, k = gets.split.map(&:to_i)
$as = gets.split.map(&:to_i)
$fs = gets.split.map(&:to_i)
 
l = $as.sum - k

if (l <= 0)
  p 0
  exit
end

# O(n)
max_f = $fs.max
min_a, max_a = l, 0
# O(n)
$as.each do |a|
  min_a = a if (a < min_a)
  max_a = a if (a > max_a)
end

ub_af = max_a * max_f
q = max_f + ub_af

# O(n)
r = h(0, n-1, q)
t = (l + n) * q / r

if (min_a > t)
  ub = t

  rr = r + n
  lb = (l * q + rr - 1)/ rr

  s = 0
  xs = []
  # O(n)
  # push の回数は 3 * n を超えないはず
  (0..n-1).each do |i|
    f = $fs[i]
    aa = ub / f
    s += aa
    (aa * f).step(lb, -f) do |x| xs.push(-x) end
  end
else
  # O(n * log(n))
  $as.push(0).sort!
  $fs.push(max_f).sort_by! {|f| -f}

  # O(n * log(n))
  $as, $fs = $as.zip($fs).sort_by do |a,f| a*f end.transpose

  r = 0
  # O(n)
  $a_sums = $as.map do |a| r += a end

  $rs = []
  # O(n)
  n.downto(1).inject(0) do |r,i| $rs[i] = r + q / $fs[i] end

  lb = ub = nil
  ilb = nil

  # O(n + log(n))
  m = (0..n).bsearch do |i|
    next false if (i == 0)
    next true if (i == n)

    nn, ll, r = nlr(n, l, i)
    af = afs(i)

    next false if (af * (r + nn) / q < ll)
    next true if ((af * r + q - 1) / q - nn >= ll)

    next false if (lb)
    next true if (ub)

    # ここは一度しか通らない

    # O(n)
    if (h(i+1, n, af) < ll)
      lb, ilb = af, i
      next false
    else
      ub = af
      next true
    end
  end

  # O(n)
  if (lb)
    af = afs(m-1)
    ub = af if (g(m-1, n, af) > l)
  elsif (ub)
    af = afs(m)
    lb, ilb = af, m if (g(m, n, af) < l)
  end

  # O(1)
  unless (lb && ub)
    ilb = m == 1 ? 1: m - 1

    nn, ll, r = nlr(n, l, m-1)

    lbm, ubm = afs(m-1), afs(m)

    ub = [ub || ub_af, (ll + nn) * q / r, ubm].min

    rr = r + nn
    lb = [lb || 0, (ll * q + rr - 1)/ rr, lbm].max
  end

  s = $a_sums[ilb-1]
  xs = []
  # O(n)
  # push の回数は 3 * n を超えないはず
  (ilb..n).each do |i|
    a, f = $as[i], $fs[i]
    aa = [ub / f, a].min
    s += aa
    (aa * f).step(lb, -f) do |x| xs.push(-x) end
  end
end

# O(n) のアルゴリズムもあるが、この問題のサイズでは組み込みの sort を使った方が速いようだ
# O(n * log(n))
p(- xs.sort[s - l])

Measured memory_bytes: 68044
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 + 7

lcm = a[0]
for i in range(1,n):
    lcm = lcm*a[i]//gcd(lcm,a[i])

lcm %= mod

ans = 0
for i in range(n):
    ans += pow(a[i],mod-2,mod)
    ans %= mod
ans *= lcm
ans %= mod
print(ans)

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

int main() {
  string s;
  cin >> s;
  
  for(int i=0; i<19; i++) {
    if(s.at(i) == ',') {
      s.at(i) = ' ';
      }
    }
  
  cout << s << 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 A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int K = sc.nextInt();
		
		sc.close();
		
		int ans = 0;
		
		if(K<A) {
			ans = K;
		}else if(K<=A+B) {
			ans = A;
		}else {
			ans = 2*A+B-K;;
		}
		
		System.out.println(ans);
	}

}

Measured memory_bytes: 35792
n = int(input())
a = [None]
for j in range(n):
    a.append(int(input()))

i = 1
c = 0
r = [1]
while True:
    c += 1
    i = a[i]
    if i == 2:
        print(c)
        break
    if c > (10**5):
        print(-1)
        break


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

#define watch(x) cout << (#x) << " is " << (x) << endl
#define fr(i,n) for(int i=0; i<n; i++)
#define rep(i, st, en) for(int i=st; i<=en; i++)
#define repn(i, st, en) for(int i=st; i>=en; i--)
#define sq(a) (a*a)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll mod = 1e9+7;


bool comp(pii a, pii b){
    return a.second > b.second;
}

void solve(){
    int n;
    cin>>n;
    string s;
    int lb, rb;
    vector<pii> v[2];

    pii pst = {-1, -1}, pen = {-1, -1};


    fr(i, n){
        cin>>s;
        int m = s.size();
        lb = rb = 0;
        stack<char> st;
        fr(j, m){
            if(s[j] == '(') {
                st.push('(');
                rb++;
            } else {
                if(st.size()){
                    st.pop();
                    rb--;
                } else lb++;
            }
        }

        if(lb == 0 && rb == 0) continue;
        if(!lb){
            pst.first = lb;
            pst.second = rb;
        }

        if(!rb){
            pen.first = lb;
            pen.second = rb;
        }

        v[lb > rb].push_back({lb, rb});

    }

    sort(v[0].begin(), v[0].end());
    sort(v[1].begin(), v[1].end(), comp);

    int sm = 0;
    bool f = true;
    for(auto it: v[0]){
        // cout<<it.first<<endl;
        sm -= it.first;
        if(sm < 0) f = false;
        sm += it.second;
    }

    for(auto it: v[1]){
        sm -= it.first;
        if(sm < 0) f = false;
        sm += it.second;
    }

    f = f && (sm == 0);

    cout<<(f ? "Yes": "No");

}

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

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

    return 0;
}



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

typedef long long ll;


int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	string s;
	while(cin>>s){
		int a=0,b=0;
		for(int i=0;i<(int)s.length();i++){
			if(s[i]=='-') a++;
			else b++;
		}
		cout<<b-a<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,x,y) for(int i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

signed main(){
   IOS;
   int n; cin >> n;
   n%=10;
   if(n == 3) cout << "bon\n";
   else if (n == 0 or n == 1 or n == 6 or n == 8) cout << "pon\n";
   else cout << "hon\n";  
}

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

int main(){
int n;
cin>>n;
long long s=0;
  for(int i=1;i<n+1;i++){
    if(i%3!=0 && i%5!=0)
      s+=i;
  }
  printf("%lld\n",s);
}

Measured memory_bytes: 3772
//Har Har Mahadev
using namespace std;
#include <bits/stdc++.h>
#define booga cout << "booga" << endl
#define ll long long int
#define pb push_back
#define mp make_pair
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " -> " << a << endl;
	err(++it, args...);
}

void testcase(){
	int h,w,m;
	pair<int,int> a[300005];
	set<pair<int,int>> all;
 	cin >> h >> w >> m;
	vector<int> row(h,0),col(w,0);
	for(int i{0};i < m;i++){
		cin >> a[i].first >> a[i].second;
		a[i].first--;
		a[i].second--;
		all.insert(a[i]);
		row[a[i].first]++;
		col[a[i].second]++;
	}
	int lar1 = -1,lar2 = -1;
	for(int i{0};i < h;i++)lar1 = max(lar1,row[i]);
	for(int i{0};i < w;i++)lar2 = max(lar2,col[i]);
	//debug(lar1,lar2);
	vector<int> big1,big2;
	for(int i{0};i < h;i++)if(row[i] == lar1)big1.pb(i);
	for(int i{0};i < w;i++)if(col[i] == lar2)big2.pb(i);
	for(int x : big1){
		for(int y: big2){
			if(all.find({x,y}) == all.end()){
				//debug(x,y);
				cout << lar1 + lar2;return;
			}
		}
	}
	cout << lar1 + lar2 - 1 ;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	while(t--){
		testcase();
	}
	return 0;
}


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

int main(void) {
    string S;cin>>S;
    int A = stoi(S.substr(0, 1));
    int B = stoi(S.substr(1, 1));
    int C = stoi(S.substr(2, 1));
    int D = stoi(S.substr(3, 1));
    for (int bit = 0; bit < (1 << 3); bit++) {
        int result = 0;
        char symbol1;
        if ((bit>>0) & 1) {
            result += A + B;
            symbol1 = '+';
        } else {
            result += A - B;
            symbol1 = '-';
        }

        char symbol2;
        if ((bit>>1) & 1) {
            result += C;
            symbol2 = '+';
        } else {
            result -= C;
            symbol2 = '-';
        }

        char symbol3;
        if ((bit>>2) & 1) {
            result += D;
            symbol3 = '+';
        } else {
            result -= D;
            symbol3 = '-';
        }

       if (result == 7) {
           printf("%d%c%d%c%d%c%d=%d\n",A,symbol1,B,symbol2,C,symbol3,D,result);
           break;
       }
    }

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		int t = int.Parse(input[0]);
		int x = int.Parse(input[1]);
		Console.WriteLine((float)t/x);
	}
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int h, w;
    cin >> h >> w;
    vvi a(h, vi(w));
    rep(i, h) rep(j, w) cin >> a[i][j];
    vp from, to;
    rep(i, h) {
        rep(j, w) {
            if (a[i][j] % 2 == 1) {
                if (j != w-1) {
                    from.eb(i+1, j+1);
                    to.eb(i+1, j+2);
                    a[i][j]--;
                    a[i][j+1]++;
                } else if (i != h-1 || j != w-1) {
                    from.eb(i+1, j+1);
                    to.eb(i+2, j+1);
                    a[i][j]--;
                    a[i+1][j]++;
                }
            }
        }
    }
    int n = sz(from);
    cout << n << endl;
    rep(i, n) {
        printf("%d %d %d %d\n", from[i].fi, from[i].se, to[i].fi, to[i].se);
    }
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using edge = pair<ll, P>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    cin >> N;
    vector<int> B(N-1);
    vector<int> A;
    rep(i, N-1) cin >> B[i];
    A.push_back(B[0]);
    rep(i, N-2) {
        A.push_back(min(B[i], B[i+1]));
    }
    A.push_back(B[N-2]);
    cout << accumulate(A.begin(), A.end(), 0) << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,x,i,j,k,cnt=0;
    scanf("%d%d%d%d", &a, &b, &c, &x);
    for (i=0;i<=a&&500*i<=x;i++){
		for (j=0;j<=b&&100*j+500*i<=x; j++){
            for (k=0; k <= c && 50*k+100*j+500*i<=x; k++){
                if (500*i+100*j+50*k==x)
                    cnt++;}}}
    printf("%d",cnt);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  int a,b;
  while(cin >> a >> b){
    int i=1;
    int sum = a+b;
    while(1){
      int a = pow(10,i);
      if(sum/a == 0) break;
      i++;
      //cout << a << endl;
    }
    cout << i << endl;
  }
  return 0;
}



Measured memory_bytes: 3280
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n ; cin  >> n;
    n %= 10;
    if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) cout << "hon\n";
    else if (n == 3) cout << "bon\n";
    else cout << "pon\n";
    return 0;
}

Measured memory_bytes: 3624
#include<algorithm>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
#include<iomanip>
#include<cmath>
using namespace std;

int main(){
//    cout << fixed << setprecision(10);
    int N, M;
    cin >> N >> M;
    vector<int> x;
    int sum = 0;
    for (int i = 0; i < N; i++) {
        int X;
        cin >> X;
        sum += X;
        x.push_back(X);
    }
    sort(x.begin(), x.end());
    if (x[N - M] * 4 * M >= sum) {
        cout << "Yes";
    } else {
        cout << "No";
    }

    return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define PI (acos(-1))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

#define MAXN 1123456
#define MOD 1000000007

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<vi> vvi;

const ll mod = 1e9+7;
ll modpow(ll b, ll e) {
  ll ans = 1;
  while (e) {
    if (e&1) ans *= b;
    b *= b;
    ans %= mod;
    b %= mod;
    e >>= 1;
  }
  return ans;
}

ll inv(ll x) { return modpow(x, mod-2); }

const int N = 212345;
vl fac = {1};

ll ncr(ll n, ll r) {
  if ( r < 0 or r > n ) return 0;
  return (fac[n] * inv(fac[r]))%mod * inv(fac[n-r]) % mod;
}


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

  rep(i,1,N+1) fac.pb(fac.back()*i%mod);

  int n, k;
  cin >> n >> k;

  vi a(n);
  rep(i,0,n) cin >> a[i];
  sort(all(a));

  ll ans = 0;
  rep(i,0,n) {
    ans += (a[i]*ncr(i, k-1))%mod; 
    ans -= (a[i]*ncr(n-i-1, k-1))%mod;
    ans %= mod;
  }

  ans %= mod;
  ans += mod;
  ans %= mod;
  cout << ans << '\n';

}

Measured memory_bytes: 2420
#include <cstdint>
#include <iostream>

int32_t childlen[200000];

void CallMyFunc(std::istream &input_stream) {
  input_stream.tie(0);
  std::ios::sync_with_stdio(false);
  try {
    int32_t N;
    input_stream >> N;
    for (int32_t i = 0; i < N; ++i) {
      childlen[i] = 0;
    }
    for (int32_t i = 0; i < N - 1; ++i) {
      int32_t parent_id;
      input_stream >> parent_id;
      ++childlen[parent_id - 1];
    }
    for (int32_t i = 0; i < N; ++i) {
      std::cout << childlen[i] << std::endl;
    }
  } catch (...) {
    std::cerr << "ERROR: CallQuickSort()" << std::endl;
    throw;
  }
}

int main() {
  CallMyFunc(std::cin);
  return 0;
}


Measured memory_bytes: 4400
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let k: usize = sc.read();

    let mut cur = 0;
    for i in 1..=k {
        cur = (cur * 10 + 7) % k;
        if cur == 0 {
            println!("{}", i);
            return;
        }
    }
    println!("-1");
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write_all(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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


#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))

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



template <class T> inline T biton(T n, T pos)
{
    return n | ((T)1 << pos);
}
template <class T> inline T bitoff(T n, T pos)
{
    return n & ~((T)1 << pos);
}
template <class T> inline T ison(T n, T pos)
{
    return (bool)(n & ((T)1 << pos));
}
template <class T> inline T gcd(T a, T b)
{
    while (b)
    {
        a = a % b;
        swap(a, b);
    }
    return a;
}
template <class T> inline T bigmod(T p, T e, T m)
{
    T ret = 1;
    for (; e > 0; e >>= 1)
    {
        if (e & 1)
            ret = (ret * p) % m;
        p = (p * p) % m;
    }
    return (T)ret;
};

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
    cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " is " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define debug(...)
#endif


long long get(int a){

    if(a==1){
        return 300000;
    }

    if(a==2){
        return 200000;
    }
    if(a==3){
        return 100000;
    }
     return 0;
}

void solve()
{
  int a,b;
  cin>>a>>b;

  if(a==1 && b==1){
    cout<<(300000+300000+400000)<<endl;
    return;
  }

  cout<<get(a)+get(b)<<endl;


}

int main()
{
    ios_base::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    cout.tie(nullptr);
    cin.tie(nullptr);


    int t = 1;


    while (t--)
    {
        solve();
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;

using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;

int main() {
    int n;
    cin>>n;
    vector<int> t(n);
    int tsum=0;
    rep(i,n){cin>>t[i];tsum+=t[i];}
    int m;cin>>m;
    vector<pair<int,int>> v;
    rep(i,m){
        int a,b;
        cin>>a>>b;
        v.push_back({a,b});
    }
    rep(i,m){
    int ans=tsum-t[v[i].first-1]+v[i].second;
    cout<<ans<<endl;
    }


    return 0;
}



Measured memory_bytes: 256
n, m = map(int,input().split())
success = [0] * (n+1)
penalty = [0] * (n+1)


for ind in range(m):
    p, s = input().split()
    p = int(p)
    if s == "WA" and success[p] == 0:
        penalty[p] += 1
    elif s == "AC":
        success[p] = 1
penalty = [penalty[ind] * success[ind] for ind in range(n+1)]
print("{} {}".format(sum(success), sum(penalty)))

Measured memory_bytes: 5528
#include <bits/stdc++.h>
using namespace std;
#define   ll long long int
#define maxn 200005







ll mod=1e9+7;
int main(){
  ll n;
  cin>>n;
  ll ans1=1;
  ll ans2=1;
  ll ans3=1;
  for(int i=0;i<n;i++){
    ans1=ans1*10;
    ans2=ans2*9;
    ans3=ans3*8;
    ans1=ans1%mod;
    ans2=ans2%mod;
    ans3=ans3%mod;
  }
  cout<<(ans1 - (2*ans2)%mod + ans3 +mod)%mod<<endl;
}


Measured memory_bytes: 3616
import java.util.*;
class Main {
  final static int INF = 1001001001;

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

    // 入力データを変数に格納する
    int n = sc.nextInt();
    int m = sc.nextInt();
    int x = sc.nextInt();
    int[][] a = new int[12][12];
    int[] c = new int[n];
    for (int i = 0; i < n; i++) {
      c[i] = sc.nextInt();
      for (int j = 0; j < m; j++) {
        a[i][j] = sc.nextInt();
      }
    }
    sc.close();

    // 回答=コストの最小値なので最小値比較のために大きな数値で初期化しておく。
    int ans = INF;

    // 全ての組み合わせパターンをチェックする
    for (int s = 0; s < 1<<n; s++) {
      int cost = 0;         // このs番目の組み合わせのコスト
      int[] d = new int[m]; // このs番目の組み合わせでの各アルゴリズムの理解度

      // ２進数で各ビットが1になっているかどうか調べる
      for (int i = 0; i < n; i++) {

        // 右からi番目のビットが1になっていれば、購入する参考書としてコストとアルゴリズムを加算する
        if ( (s & 1<<i) == 1<<i) {
          // コストを足す
          cost += c[i];

          // 各アルゴリズムの理解度に足す
          for (int j = 0; j < m; j++) {
            d[j] += a[i][j];
          }
        }
      }

      // 全てのアルゴリズムの理解度がxを超えているかチェックする
      boolean ok = true;
      for (int j = 0; j < m; j++) {
        if (d[j] < x) ok = false; // １つでもx未満があれば。
      }
      // チェックOKであれば、そのコストが最小値を更新するかどうか。
      if (ok) ans = Math.min(ans, cost);

    }

    // 全てのアルゴリズムの理解度がxを超えるパターンが１つもない場合はansがINFのままになってる
    if (ans == INF) System.out.println(-1);
    else System.out.println(ans);

  }
}

Measured memory_bytes: 37528
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		int minval = Integer.parseInt(std.next());;
		int maxpro = (int)-1e+9;
		int nextval = 0;
		for (int i=1; i<n; i++){
			nextval = Integer.parseInt(std.next());
			if(maxpro<(nextval-minval)){maxpro = nextval - minval;}
			if(nextval<minval){minval = nextval;}
		}
		System.out.println(maxpro);
	}
}

Measured memory_bytes: 71328
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 

using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))

int main()
{
	long long n, a, b, c, d, e;
	cin >> n >> a >> b >> c >> d >> e;
	long long x = min({ a,b,c,d,e });
	long long ans = 4 + (n + x - 1) / x;
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <typeinfo>
using namespace std;

int main(){
    int N,Y;
    int num;
    std::cin >> N >> Y;
    num = Y/1000 - N;
    if(num < 0){
        std::cout << -1 <<" "<< -1 <<" "<< -1 << "\n";
    }else{
        for (int i = 0; i < num/9 + 1; ++i)
        {
            for (int j = 0; j < num/4 + 1; ++j)
            {
                if((9*i + 4*j == num)&&(N - i - j >= 0))
                {
                    std::cout << i <<" "<< j <<" "<< N - i - j<< "\n";
                    exit(0);
                }
            }
        }
        std::cout << -1 <<" "<< -1 <<" "<< -1 << "\n";
    }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,fast-math,unroll-loops,inline,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,avx,avx2,abm,mmx,popcnt")

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define int long long

typedef
tree<
pair<int,int>,
null_type,
less<pair<int,int>>,
rb_tree_tag,
tree_order_statistics_node_update>
        ordered_set;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vector<int> A(n + 1);
    for (int i = 1; i <= n; i++) cin >> A[i];
    vector<int> P(n + 1);
    for (int i = 1; i <= n; i++) {
        P[i] = P[i - 1] + A[i];
    }
    for (int i = 0; i <= n; i++) {
        P[i] -= k * i;
        // cout << P[i] << ' ';
    }
    ordered_set X;
    int ans = 0;
    int s = 0;
    for (auto x : P) {
        ans += X.order_of_key({x+1,-1});
        X.insert({x,s++});
        // cout << ans << '\n';
    }
    cout << ans;

}

Measured memory_bytes: 15872
#include<iostream>

using namespace::std;

int ar[85][85];
bool dp[85][85][12801],cnt[12801];

int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin>>ar[i][j];
    for(int i=0;i<n;/*cout<<'\n',*/i++)
        for(int j=0,t;j<m;j++)
            cin>>t,ar[i][j]-=t;//,cout<<ar[i][j]<<' ';
    dp[0][0][abs(ar[0][0])]=1;
    for(int i=0;i<n;/*cout<<'\n',*/i++)
        for(int j=0;j<m;j++){
                for(int k=0;k<12801;k++)
                    cnt[k]=(i?dp[i-1][j][k]:0)||(j?dp[i][j-1][k]:0);//,cout<<k<<' '<<cnt[k]<<'\n';
                for(int k=0;k<12801;k++)
                    if(cnt[k]){
                        if(k+abs(ar[i][j])<12801)
                            dp[i][j][abs(ar[i][j])+k]=1;
                        dp[i][j][abs(k-abs(ar[i][j]))]=1;
                    }
                /*for(int k=0;k<85;k++)
                    if(dp[i][j][k]){
                        cout<<k<<' ';
                        break;
                    }*/
            }
    for(int i=0;i<12801;i++)
        if(dp[n-1][m-1][i])
            return cout<<i<<'\n',0;
}

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

int main(){
    int n, x, l, i, d = 0, c = 0;
    cin >> n >> x;
    if(d <= x) c++;
    for(i = 0; i<n; i++){
        cin >> l;
        d += l;
        if(d <= x){
            c++;
        }
    }
    cout << c;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<numeric>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    queue<int> que;
    que.push(0);
    vector<int> cnt(n, 1e8);
    cnt[0] = 0;
    while ( !que.empty() ) {
        int now_shima = que.front();
        que.pop();
        for ( auto tmp_g : g[now_shima] ) {
            if ( cnt[tmp_g] != 1e8 ) continue;
            cnt[tmp_g] = cnt[now_shima] + 1;
            que.push(tmp_g);
        }
    }
    if ( cnt[n-1] == 2 ) cout << "POSSIBLE" << endl;
    else                 cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 13296
s=input()
q=int(input())
cnt=0
a1,a2=[],[]
for _ in range(q):
  t=list(input().split())
  if t[0]=='1':
    cnt+=1
    a1,a2=a2,a1
  else:
    if t[1]=='1':
      a1.append(t[2])
    else:
      a2.append(t[2])
if cnt%2==1:
  s=s[::-1]
print(''.join(a1[::-1])+s+''.join(a2))

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if (A + B > C + D){
    cout << "Left" << endl;
  }
  else if (A + B < C + D){
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 3628