akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
 
using namespace std;
 
int main(){
    int a,b,n,c;
    int d[10000];
    int sorts;
    int best,bests;
    cin>>n;
    cin>>a>>b;
    cin>>c;
    for(int i=0;i<n;i++){
        cin>>d[i];
    }
    for (int i=0;i<n;i++) { 
        for (int j=i+1; j<n; ++j) { 
          if (d[j] > d[i]) { 
            sorts =  d[j]; 
            d[j] = d[i]; 
            d[i] = sorts;
          } 
        } 
    }
    best=a/c;
    for(int i=0;i<n;i++){
        bests=(c+d[i])/(a+b+(b*i));
        c+=d[i];
        if(bests>best)
            best=bests;
        if(bests<=best)
            bests=best;
    }
    cout<<best<<endl;
    return 0;
}

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

int main()
{    
    int n;
    cin >> n;
    vector<int> a(n+1);
    vector<int> b(n);
    rep(i,n+1) cin >> a[i];
    rep(i,n) cin >> b[i];

    i64 sum = 0;
    int r = 0;

    rep(i,n)
    {
        if(b[i] <= a[i])
            sum += b[i];
        else
        {
            sum += a[i];
            int p = min(b[i]-a[i], a[i+1]);
            sum += p;
            a[i+1] -= p;
        }
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1024
<?php
    list($Height, $Width) = explode(" ",trim(fgets(STDIN)));
    $map = array(array());

    for($i = 0; $i < $Height; $i++){
        $map[$i] = str_split(trim(fgets(STDIN)));
    }

    $num = 0;

    for($i = 0; $i < $Height; $i++){
        for($j = 0; $j < $Width; $j++){
            if($map[$i][$j] == '#') $num++;
        }
    }

//    echo $num;

    function recursive($h, $w ,$hei, $wid, $n, $init,$map, $end){
//        echo "height:".$h." width:".$w." num:".$init;
//        echo PHP_EOL;
        global $result;
        if($map[$h+1][$w] == "#"){
            recursive($h+1,$w,$hei,$wid,$n,$init+1,$map);
        }
        if($map[$h][$w+1] == "#"){
            recursive($h,$w+1,$hei,$wid,$n,$init+1,$map);
        }
        if($map[$h+1][$w] != "#" && $map[$h][$w+1] != "#"){
            $end = 1;
        }

        if($end == 1 && $init == $n){
//            echo "Possible";
//            $result = 0;
        } else if ($end == 1) {
//            echo "Impossible";
            $result++;
        }
    }

    recursive(0,0,$Height,$Width,$num,1,$map,0);
//    echo $result;
    if($result == 0){
        echo "Possible";
    } else {
        echo "Impossible";
    }
?>  

Measured memory_bytes: 3580
N = int(input())
L = list(map(int, input().split()))
L.sort()
M = len(L)
ans = 0
for i in range(N):
     for j in range(N):
         for k in range(N):
             if L[i] + L[j] > L[k] and L[i] < L[j] and L[j] < L[k]:
                 ans += 1
print(ans)


Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define ll long long
#define pb push_back
#define mp make_pair
#define nt _int128
#define ld long double
long double PI =3.14159265358979323846;


const ll modo=1e9+7;
const ll inf=2e14;
const ll ms=(2e5) +5;


int main()
{
    idfc;
    string s;
    cin>>s;
    int n=s.length();
    while(n--)cout<<"x";
    return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<<#x<<":"<<x<<'\n'

//↓0-indexか1-indexでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-index昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-index昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-index降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-index降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

/* 円周率は M_PI を使おうね */
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;

/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    int n; cin >> n;
    vll a(n);
    vll s(n+1, 0);
    rep(i,n) {
        cin >> a[i];
        s[i+1] = s[i] + a[i];
    }
    sort(all(s));
    //for(auto i : s) debug(i);

    ll cnt = 1;
    ll ans = 0;
    for(int i = 0; i < n; ++i) {
        if(s[i]==s[i+1]) {cnt++; /*debug(cnt);*/}
        else {
            ans += (cnt*(cnt-1))/2;
            //debug(cnt);
            //debug(ans);
            cnt = 1;
        }
    }
    ans += (cnt*(cnt-1))/2;
        //debug(cnt);
        //debug(ans);
    
    cout << ans << '\n';
}

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

using namespace std;
#define int long long
typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
#define X first
#define Y second
#define all(o) o.begin(), o.end()
const int maxn = 1e5 + 10;
int a[maxn];
vi adj[maxn];
int get(vi v){
	sort(all(v), greater<int>());
	int sm = 0;
	for(int i=1; i<v.size(); i++)
		sm += v[i];
	if(v[0] > sm) return sm;
	return (v[0] + sm) / 2;
}
int dfs(int v,int p){
	if(adj[v].size() == 1)
		return a[v];
	vi o;
	int tot = 0;
	for(int u : adj[v]){
		if(u == p) continue;
		int t = dfs(u, v);
		if(t == -1) return -1;
		o.push_back(t);
		tot += t;
	}
	int i = v;
	int tt = get(o);
	if(a[i] > tot) return -1;
	int mat = tot - a[i];
	if(mat < 0) return -1;
	if(mat > tt) return -1;
	return tot - mat * 2;
}
main(){
	int n;
	cin >> n;
	for(int i=0; i<n; i++)
		cin >> a[i];
	for(int i=0; i<n-1; i++){
		int u, v;
		cin >> u >> v;
		u--, v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	if(n == 2){
		cout << (a[0] == a[1] ? "YES" : "NO") << endl;
		return 0;
	}
	int r;
	for(int i=0; i<n; i++)
		if(adj[i].size() != 1) r = i;
	cout << (dfs(r, r) == 0 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 17920
a, b, c = map(int, input().split())
if a == 5 and b == 5 and c == 7:
  print("YES")
elif a == 5 and b == 7 and c == 5:
  print("YES")
elif a == 7 and b == 5 and c == 5:
  print("YES")
else:
  print("NO")

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

int main(){
  int a,b,i;
  cin >> a >> b;
  for(i = 1; i < 4; i++){
    if((a*b*i)%2){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
n=input()
ans=""
if n[-1]=="2" or n[-1]=="4" or n[-1]=="5" or n[-1]=="7" or n[-1]=="9":
    ans="hon"
elif n[-1]=="0" or n[-1]=="1" or n[-1]=="6" or n[-1]=="8":
    ans="pon"
else:
    ans="bon"
    
print(ans)

Measured memory_bytes: 9064
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = 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 (a > b) { a = b; return 1; } return 0; }


const LL INF = 1e16;

// i個目までの品物について考慮したとき、価値j以上を得るための重さの最小値
// オーバーフローに注意
LL dp[110][101010];

int main(){
    int N, W;
    cin >> N >> W;
    vector<int> w(N), v(N);
    for(int i=0; i<N; i++) cin >> w[i] >> v[i];

    int maxV = N*1000;      // 価値の和の最大値
    for(int i=0; i<=N; i++)for(int j=0; j<=maxV; j++) dp[i][j] = INF;
    dp[0][0] = 0;

    for(int i=0; i<N; i++){
        for(int j=0; j<=maxV; j++){
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            dp[i+1][j+v[i]] = min(dp[i+1][j+v[i]], dp[i][j]+w[i]);
        }
    }

    LL ans = 0;
    for(int j=0; j<=maxV; j++){
        // ナップサックに入る重さか？
        if(dp[N][j] <= W) ans = j;
    }
    cout << ans << endl;
}


Measured memory_bytes: 80128
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

############
############
############

N, M = s_inpl()
ks = []
for _ in range(M):
    k = l_inpl()
    ks.append(k[1:])

ps = l_inpl()
cnt = 0
for i in range(2**N):
    on_ss = []
    for j in range(N):
        if ((i>>j) & 1):
            on_ss.append(j+1)
    # print("JJJ")
    flag = True
    for k, p in zip(ks, ps):
        if len(set(k)&set(on_ss)) % 2 != p:
            flag = False
            break
    if flag:
        cnt += 1

print(cnt)


Measured memory_bytes: 42948
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t=1;
    // cin>>t;
    while(t--)
    {
        int n, x, to;
        cin>>n>>x>>to;
        int y;
        if(n%x==0) y=n/x;
        else y=n/x+1;
        cout<<y*to;
    }
	return 0;
}

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

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

    vector<int> abc(3);
    int sum = 0;
    rep(i, 3) {
      cin >> abc[i];
      sum += abc[i];
    }

    sort(abc.begin(), abc.end());

    int max_mod = (abc[2] * 3) % 2;
    int sum_mod = sum % 2;

    int ans = 0;
    if(max_mod != sum_mod) {
      ans = ((abc[2]+1) * 3 - sum) / 2;
    }
    else ans = ((abc[2] * 3) - sum) / 2;

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int ans=1<<30; 
int main()
{
    string s;
    cin>>s;
    for(int i=1;i<s.length();i++)
        if(s[i]!=s[i-1]) 
            ans=min(ans,max(i,int(s.length())-i)); 
    cout<<min(ans,int(s.length()))<<endl; 
    return 0;
}

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true; } return false; }

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    string s; cin >> s;
    int l = s.length();
    int ans = 0;
    for(int i = 0; i < l/2; i++){
        if(s[i] != s[l-1-i]) ans++;
    }
    cout << ans << endl;

    return 0;
}


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

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    int p,q,r;

    cin>>p>>q>>r;

    cout<<min(p+q,min(p+r,q+r))<<endl;

    return 0;
}


Measured memory_bytes: 256
function Main(input){

input=input.split(" ");
inA=parseInt(input[0]);
inB=parseInt(input[1]);

answer = 0;

C = inB - inA;
D = 0;

for (i = 1; i < C; i++) {
    D = D + i;
}

console.log(D - inA);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
// {{{ by unolight
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

namespace { namespace unolight {
// Read Input
template<class T> void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( int64_t &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); }
// Write Output
template<class T> void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
void _W( const int64_t &x ) { printf("%" PRId64,x); }
void _W( const double &x ) { printf("%.16f\n",x); }
void _W( const char &x ) { putchar(x); }
void _W( const char *x ) { printf("%s",x); }
template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); }

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
// }}}


void main() {
    int d,t,s;
    R(d,t,s);
    if ( (double)d/s<=t ) W("Yes");
    else W("No");
}

}} // {{{ main
int main() { unolight::main(); return 0; }
// }}}

Measured memory_bytes: 3824
#include <bits/stdc++.h> 
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define each(it,o) for(auto it= (o).begin(); it != (o).end(); ++ it)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define inrep(t) int t;cin>>t; while(t--)
#define pb push_back
#define mp make_pair 
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi; 
typedef pair<int,int> pii;
typedef vector<pii > vpii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll > vpll; 
typedef vector<string> vs;
typedef long double ld;


int main(){
	ios_base::sync_with_stdio(false); 
	int n; 
	cin>>n; 
	int t[n+1],x[n+1],y[n+1]; 
	t[0]=x[0]=y[0]=0; 
	reu(i,1,n+1){
		cin>>t[i]>>x[i]>>y[i]; 
	}
	//int x0=0,y0=0,t0=0; 
	reu(i,1,n+1){
		//cout<<abs(x[i]-x[i-1])+abs(y[i]-y[i-1])<<endl; 
		int te=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
		int ate=(t[i]-t[i-1]);  
		if(te>ate || (ate-te)%2==1){
			cout<<"No"; return 0; 
		}
	}
	cout<<"Yes"; 
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int b,c,i,j,a=0;
    string s;
    cin>>s;
    for(i=1; i<s.size(); i++)
    {
        if(s[i]!=s[i-1])
        {
            a=1;
            break;
        }
    }
    if(a)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
n, k = [int(i) for i in input().split()]
hh = [int(i) for i in input().split()]

dp = [float("inf")] * n
dp[0] = 0

for i in range(n-1):
    for j in range(i+1, min(i+k+1, n)):
        dp[j] = min(dp[j], dp[i] + abs(hh[j] - hh[i]))

print(dp[-1])


Measured memory_bytes: 55008
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
int n,ans[maxn];
pair<int,int> a[maxn];

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i].first);
        a[i].second=i;
    }
    sort(a+1,a+1+n);
    for(int i=1;i<n;i++){
        ans[a[i].second]=a[n].first;
    }
    ans[a[n].second]=a[n-1].first;
    for(int i=1;i<=n;i++)
        printf("%d\n",ans[i]);
}
/*
    Good Luck
        -Lucina
*/


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

#define en "\n"
#define INF (int) 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fs first
#define sc second
#define size(a) (int) a.size()
#define deb(x) cerr << #x << " => " << x << en
#define debp(a) cerr << #a << " => " <<"("<<a.fs<<", "<<a.sc<<") " << en;
#define deba(x) cerr << #x << en; for (auto a : x) cerr << a << " "; cerr << en;
#define debpa(x) cerr << #x << en; for (auto a : x)cerr<<"("<<a.fs<<", "<<a.sc<<") "; cerr << en;
#define debm(x) cerr << #x << en; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << en;}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)
int fastpow(int a, int b, int m = HELL) { int res = 1; a %= m;
while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res;}
#define inv(a) fastpow(a, HELL - 2)
#define mul(a, b) ((a % HELL) * (b % HELL)) % HELL

int32_t main() { fastio;
	int n; cin >> n;
	vector<int> arr(n);
	int xr = 0;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
		xr = arr[i] xor xr;
	}
	for (auto a : arr) {
		cout << (a xor xr) << " ";
	} cout << endl;
	return 0;
}


Measured memory_bytes: 4712
int main(void)
{
    int H=1, W=1, i, j;

    

    while ((H != 0) && (W != 0))
    {
        scanf("%d %d", &H, &W);

        if ((H == 0) && (W == 0))
        {
            return 0;
        }
        else
        {
            for (j = 0;j < H;j++)
            {
                for (i = 0;i < W;i++)
                {
                    if ((i !=0 ) && (j != 0)&&(i!=W-1)&&(j!=H-1))
                    {
                        printf(".");
                    }
                    else
                    {
                        printf("#");
                    }
                }
                printf("\n");
            }
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2044
#include "bits/stdc++.h"

using namespace std;
using ll = long long;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint operator-() const { return mint(-x); }

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const { return mint(*this) += a; }

    mint operator-(const mint a) const { return mint(*this) -= a; }

    mint operator*(const mint a) const { return mint(*this) *= a; }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }

    mint &operator/=(const mint a) { return *this *= a.inv(); }

    mint operator/(const mint a) const { return mint(*this) /= a; }
};

istream &operator>>(istream &is, const mint &a) { return is >> a.x; }

ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;

    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }

    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
} comb(200005);

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

    mint ans = 0;
    for (int i = 0; i <= min(k, n - 1); ++i)
        ans += comb(n, i) * comb(n - 1, i);
    cout << ans << endl;
}


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

int main(){
  int TN, TS;
  cin >> TN >> TS;
  vector<vector<int>> box(TS, vector<int>(2));
  for(int i = 0; i < TN; i++){
    cin >> box.at(i).at(0) >> box.at(i).at(1);
  }
  
  int ans = 1e9;
  for(int i = 0; i < (1 << TN); ++i){
    int sum = 0, num = 0, noNum = -1;
    for(int j = 0; j < TN; ++j){
      if(i >> j & 1){
        sum += box.at(j).at(0) * (j + 1) * 100 + box.at(j).at(1);
        num += box.at(j).at(0);
      }
      else {
        noNum = j;
      }
    }
    if(sum < TS){
      
      int Lscore = (noNum + 1) * 100;
      int lack = (TS - sum + Lscore -1) / Lscore;
      if(lack >= box.at(noNum).at(0)){
        continue;
      }
      else{
        num += lack;
      }
    }
    ans = min(ans, num);
  }
  cout << ans << endl;
}

Measured memory_bytes: 577152
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for(ll i = 0; i < n; i++)
using namespace std;
int dy[4] = { 1, 0, -1, 0 }, dx[4] = { 0, 1, 0, -1 };
const ll MOD = 1e9 + 7;
const ll INF = 1e9;


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vector<pair<ll, ll> > ba;
  ba.resize(n);
  rep(i, n) {
    ll a, b;
    cin >> a >>b;
    ba[i] = make_pair(b, a);
  }

  sort(ba.begin(), ba.end());

  ll sum = 0;
  rep(i, n) {
    sum += ba[i].second;
    if (ba[i].first < sum) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
#define lli long long int

int main()
{
    int count = 0, ans = 0;
    string str;
    cin >> str;
    for(int i=0;i<3;i++)
    {
        if(str[i]=='R')
            count++;
        else
            count = 0;
        ans = max(count, ans);
    }

    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
const ll mx = 10000007;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
#define    ss   second
#define    ff   first
#define    pb   push_back
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);


int main() {
    FIO;
    ll n;
    cin >> n;
    vector<ll>a(100009, 0), b(100009, 0);
    for (ll i = 0; i < n; i++) {
        ll x;
        cin >> x;
        if(i % 2 == 1) {
            b[x]++;
        }
        else {
            a[x]++;
        }
    }
    ll ans = 0;
    ll amax = max_element(a.begin(), a.end()) - a.begin();
    ll bmax = max_element(b.begin(), b.end()) - b.begin();

    if(amax != bmax) {
        ans = n - a[amax] - b[bmax];
    }

    else {
        sort(a.begin(), a.end(), greater<ll>());
        sort(b.begin(), b.end(), greater<ll>());

        ans = min(n - (a[0] + b[1]), n - (a[1] + b[0]));
    }

    cout << ans << endl;
    return 0;

}



Measured memory_bytes: 4752
// C++ program to demonstrate insertion 
// into a vector of vectors 



#include <iostream> 
#include <vector> 
using namespace std; 


main() 
{ 
    
	long long int  n, w;
	cin >> n;
	cin >> w;
	vector<long long int> wi(n);
	vector<long long int> pi(n);
	for(int i=0; i< n; i++){
	    cin >> wi[i];
	    wi.push_back(wi[i]);
	    cin >> pi[i];
	    pi.push_back(pi[i]);
	}
	
	vector<vector <long long int> > dp(n+1, vector <long long int> (w+1));
	for(long long int i=0; i <= n; i++ ){
	    for(long long int j= 0; j <= w; j++ ){ 
	        if(i==0 || j==0){
	            dp[i][j]=0;
	            continue;
	        }
	        if(wi[i-1] > j)
	            dp[i][j] = dp[i-1][j];
	        else {
	            long long int temp = j-wi[i-1];
	            dp[i][j] = max(pi[i-1]+dp[i-1][temp], dp[i-1][j]);
	        }
	    }
	}
	
	cout << dp[n][w];
} 


Measured memory_bytes: 83148
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	string s; cin >> s;
    int n = (int)s.size();
    vector<string> vec;
    rep(i, n) {
        string t = s.substr(0, i), u = s.substr(i, n - i);
        string t_ = t, u_ = u;
        reverse(all(t_));
        reverse(all(u_));
        vec.pb(t + u);
        vec.pb(t + u_);
        vec.pb(t_ + u);
        vec.pb(t_ + u_);
        vec.pb(u + t);
        vec.pb(u_ + t);
        vec.pb(u + t_);
        vec.pb(u_ + t_);
    }
    sort(all(vec));
    vec.erase(unique(all(vec)), vec.end());
    cout << (int)vec.size() << endl;
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
    int t; cin >> t; rep(i, t)solve();
	//solve();
    return 0;
}


Measured memory_bytes: 3228
#include<iostream>
#include<numeric>
#include<cmath>
#include<vector>
#include<string>

using namespace std;

int main() {
    
    int x,a,b;
    cin>>x>>a>>b;
    if(abs(x-a)>abs(x-b)){
    cout<<"B"<<endl;
    }
    else if(abs(x-a)<abs(x-b)){
    cout<<"A"<<endl;
    }
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

	vector<int> b(N);
	auto maxA = 0;
	for (auto i = 0; i < N; ++i)
	{
		int a;
		cin >> a >> b[i];
		maxA = max(maxA, a);
	}
	sort(b.begin(), b.end(), greater<int>());

	auto ans = 0;
	for (auto i = 0; i < N && b[i] > maxA; ++i)
	{
		H -= b[i];
		++ans;
		if (H <= 0)
		{
			break;
		}
	}

	if (H > 0)
	{
		ans += (H - 1) / maxA + 1;
	}

	cout << ans << endl;

	return 0;
}

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

int main()
{
	auto start = steady_clock::now();

	random_device rnd;

	int D;
	vector<int> cs(26);
	cin >> D;
	for (auto &&c : cs)
	{
		cin >> c;
	}
	vector<vector<int>> sss(D, vector<int>(26));
	for (auto &&ss : sss)
	{
		for (auto &&s : ss)
		{
			cin >> s;
		}
	}

	vector<int> ts(D);
	for (auto &&t : ts)
	{
		t = rnd() % 26;
	}

	auto calc_score = [&] {
		vector<int> last(26, -1);

		int s = 0;

		for (int d = 0; d < D; d++)
		{
			s += sss[d][ts[d]];

			last[ts[d]] = d;

			for (int i = 0; i < 26; i++)
			{
				s -= cs[i] * (d - last[i]);
			}
		}

		// return max(0, 1000000 + s);
		return s;
	};

	auto calc_diff = [&](int d, int q) {
		int p = ts[d];

		ts[d] = q;

		int ret = calc_score();

		ts[d] = p;

		return ret;
	};

	int score = calc_score();

	while (duration_cast<milliseconds>(steady_clock::now() - start).count() < 1950)
	{
		for (int d = 0; d < D; d++)
		{
			for (int q = 0; q < 26; q++)
			{
				if (ts[d] == q)
				{
					continue;
				}

				int next_score = calc_diff(d, q);

				if (score < next_score)
				{
					ts[d] = q;
					score = next_score;
				}
			}
		}
	}

	for (auto &&t : ts)
	{
		cout << t + 1 << endl;
	}

	return 0;
}

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

using ll = long long int;
typedef long double ld;
typedef pair<ll,ll> pll;

#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;
//K-th smallest element(0-based)=> cout << k << "kth smallest: " << *A.find_by_order(k-1) << endl;
//NO OF ELEMENTS < X => cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

#define sz(v) (ll)v.size()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
string mat[25];
bool vis[25][25];
void reset(ll h,ll w)
{
	for(ll i=0;i<h;i++)
		for(ll j=0;j<w;j++)
			vis[i][j]=0;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	ll h,w;
	cin>>h>>w;
	for(ll i=0;i<h;i++)cin>>mat[i];
	ll ans=0;
	for(ll i=0;i<h;i++)
		for(ll j=0;j<w;j++)
		{
			if(mat[i][j]=='#')
				continue;
			reset(h,w);
			deque<pair<pll,ll>> trav;
			trav.pb(mp(mp(i,j),0));
			while(!trav.empty())
			{
				pair<pll,ll> cur=trav.front();
				trav.pop_front();
				if(vis[cur.f.f][cur.f.s] or mat[cur.f.f][cur.f.s]=='#')
					continue;
				ans=max(ans,cur.s);
				vis[cur.f.f][cur.f.s]=1;
				if(cur.f.f+1<=h-1)
					trav.pb(mp(mp(cur.f.f+1,cur.f.s),cur.s+1));
				if(cur.f.f-1>=0)
					trav.pb(mp(mp(cur.f.f-1,cur.f.s),cur.s+1));
				if(cur.f.s+1<=w-1)
					trav.pb(mp(mp(cur.f.f,cur.f.s+1),cur.s+1));
				if(cur.f.s-1>=0)
					trav.pb(mp(mp(cur.f.f,cur.f.s-1),cur.s+1));
			}
		}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
#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(){
    vector<int>a(3);
    rep(i,3){
        cin>>a.at(i);
    }
    sort(a.begin(),a.end());
    if(a.at(0)==5 && a.at(1)==5 && a.at(2)==7){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}


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

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pull pair<ull, ull>
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	
	ll sum=0;
	for(int i=1 ; i<=n ; ++i){
		for(int j=1 ; j<=n ; ++j){
			for(int k=1 ; k<=n ; ++k){
				sum += __gcd(i, __gcd(j, k));
			}
		}
	}
	
	cout << sum;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

const ll MOD = 1000000007;

const int MAX = 2000005;
ll modFact[MAX];
ll modInv[MAX];
ll modFactInv[MAX];

// calc nCr % mod
ll comb(int n, int r) {
  return modFact[n] * (modFactInv[r] * modFactInv[n - r] % MOD) % MOD;
}

ll modPow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n) {
    if (n & 1) res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

void init() {
  modFact[0] = modFact[1] = 1;
  modFactInv[0] = modFactInv[1] = 1;
  modInv[1] = 1;
  REP(i, 2, MAX) {
    modFact[i] = modFact[i - 1] * i % MOD;
    modInv[i] = MOD - modInv[MOD % i] * (MOD / i) % MOD;
    modFactInv[i] = modFactInv[i - 1] * modInv[i] % MOD;
  }
}

int main() {
  init();

  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  map<int, int> pf;
  rep(i, n) {
    int x = a[i];
    for (int j = 2; j * j <= x; j++) {
      int cnt = 0;
      while (x % j == 0) {
        x /= j;
        cnt++;
      }
      pf[j] = max(pf[j], cnt);
    }
    if (x != 1) pf[x] = max(pf[x], 1);
  }

  ll lcm = 1;
  for (auto it = pf.begin(); it != pf.end(); it++) {
    lcm = lcm * modPow(it->first, it->second, MOD) % MOD;
  }

  ll ans = 0;
  rep(i, n) ans = (ans + lcm * modInv[a[i]]) % MOD;

  cout << ans << endl;
}


Measured memory_bytes: 47744
//be naame khodaa
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
#define F first
#define S second
#define pb push_back
#define sz(x) ((int)(x).size())

inline int in(){ int x, y; y = scanf("%d", &x); return x; }

const int N = 1000*100 + 100;
const int mod = 1e9 + 7;

int cnt[30]; 
int tav[N]; 

int sum(int a, int b) { 
    int c = (a+b); 
    if( c >= mod ) c -= mod; 
    return c;
}

int mul(int a, int b) { 
    return 1ll*a*b % mod; 
}

int main(){
    tav[0] = 1; 
    for(int i =1; i < N; i++) 
        tav[i] = sum(tav[i-1], tav[i-1]); 

    int n;
    string s;
    cin >> n >> s; 

    for(int i = 0; i < n; i++) 
        cnt[s[i]-'a']++; 

    int ans = 1; 
    for(int i = 0; i < 26; i++) 
        ans = mul(ans, cnt[i] + 1); 
    cout << sum(ans, mod-1) << endl;
}


Measured memory_bytes: 896
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;

immutable INF = 10^^7;
int N, M, a, b, c;
Tuple!(int, int)[][] adj;
bool[][] used_in_shortest;

void dijkstra(int s) {
    auto dist = new int[](N);
    fill(dist, INF);
    dist[s] = 0;
    auto prev = new int[][](N);
    alias Tuple!(int, "from", int, "to", int, "cost") Edge;
    auto q = new BinaryHeap!(Array!Edge, "a.cost >= b.cost");
    q.insert(Edge(-1, s, 0));

    while (!q.empty) {
        auto n = q.front;
        q.removeFront;

        if (n.cost == dist[n.to]) {prev[n.to] ~= n.from;}
        if (dist[n.to] < n.cost) continue;
        foreach (e; adj[n.to]) {
            if (dist[n.to] + e[1] < dist[e[0]]) {
                prev[e[0]] = new int[](0);
                prev[e[0]] ~= n.to;
                dist[e[0]] = dist[n.to] + e[1];
                q.insert(Edge(n.to, e[0], dist[e[0]]));
            }
            else if (dist[n.to] + e[1] == dist[e[0]]) {
                prev[e[0]] ~= n.to;
            }
        }
    }

    foreach (n; 0..N) {
        foreach (m; prev[n]) {
            if (m == -1) continue;
            used_in_shortest[n][m] = true;
            used_in_shortest[m][n] = true;
        }
    }

}

void main() {
    scanf("%d %d", &N, &M);
    adj = new Tuple!(int, int)[][](N);
    foreach (i; 0..M) {
        scanf("%d %d %d", &a, &b, &c);
        adj[a-1] ~= tuple(b-1, c);
        adj[b-1] ~= tuple(a-1, c);
    }
    used_in_shortest = new bool[][](N, N);

    foreach (i; 0..N)
        dijkstra(i);

    int ans = 0;
    foreach (n; 0..N) {
        foreach (j; adj[n]) {
            auto m = j[0];
            if (!used_in_shortest[n][m])
                ans += 1;
        }
    }

    (ans/2).writeln;
}


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

void ask(int left, int right, bool male) {
	int mid = (left + right) / 2;
	cout << mid << endl;
	string s;
	cin >> s;
	if (s == "Vacant") return;
	if (((mid - left) % 2 == 0) == (male == (s == "Male"))) ask(left, mid - 1, male);
	else ask(mid + 1, right, s == "Male");
}

int main() {
	int N;
	cin >> N;
	cout << 0 << endl;
	string s;
	cin >> s;
	if (s == "Vacant") return 0;
	ask(1, N - 1, s == "Male");
	return 0;
}

Measured memory_bytes: 852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int mod = 1000000007;
const int N = 100010;
 
int main() 
{
   // freopen("in.txt", "r", stdin);
    int n;

    while (~scanf("%d", &n))
    {
        int ans = 0;
        for (int i = 0; i < n; i++)
        {
            int l, r;
            scanf("%d%d", &l, &r);
            ans += r - l + 1;
        }
        printf("%d\n", ans);
    }
   
    return 0;
}


Measured memory_bytes: 256
def main():
    N, A = map(int, input().split())
    *X, = map(int, input().split())

    ans = editorial_3d(N, A, X)
    ans2 = editorial_2d(N, A, X)
    assert ans == ans2
    if N <= 16:
        ans3 = part(N, A, X)
        assert ans == ans3

    print(ans)


def editorial_3d(N, A, X):
    """
    dp[N][N][sum]
    N枚の選択肢, N枚選ぶ, 合計値
    """
    max_sum = N * A
    dp = [[None] for _ in range(N+1)]
    for i in range(N+1):
        tmp = [[0] * (2 * max_sum + 1) for _ in range(N+1)]
        dp[i] = tmp
    # 0枚選択肢のとき、合計0はあり得る
    dp[0][0][0] = 1

    for i in range(1, N+1):
        for j in range(0, N+1):
            for k in range(max_sum + 1):
                v = dp[i-1][j][k]
                if k >= X[i-1] and j >= 1:
                    v += dp[i-1][j-1][k - X[i-1]]

                dp[i][j][k] = v

    ans = 0
    for j in range(1, N+1):
        if j * A <= max_sum:
            ans += dp[N][j][j * A]

    return ans


def editorial_2d(N, A, X):
    """
    dp[N][sum]
    N枚の選択肢, 合計値
    """
    # X[i] がすべて0なら -A することで最低値になりうる
    # よって2倍確保して対応
    max_sum = 2 * (N * 50)
    dp = [[0] * (max_sum + 1) for _ in range(N+1)]
    # 真ん中の位置を0扱い
    dp[0][max_sum // 2] = 1

    for i in range(1, N+1):
        for k in range(max_sum + 1):
            v = dp[i-1][k]
            s = k - (X[i-1] - A)
            if 0 <= s <= max_sum:
                v += dp[i-1][s]

            dp[i][k] += v

    # 0枚のとき合計0はあり得るが、問題文より
    # これらのカードの中から 1枚以上を選び、
    # 選んだカードに書かれた整数の平均をちょうど Aにしたい
    # よって -1 しないといけない
    # 今回の組合せは、掛け算で増えないためそのまま減算で良い(はず)
    ans = dp[N][max_sum // 2] - 1

    return ans


def part(N, A, X):
    import sys
    sys.setrecursionlimit(10 ** 7)
    a = [0] * N

    def rec(i, n):
        ans = 0
        if i == n:
            s = 0
            c = 0
            # print(a)
            for j, b in enumerate(a):
                if b == 1:
                    s += X[j]
                    c += 1

            if c == 0:
                return 0
            if s / c == A:
                return 1
            else:
                return 0

        a[i] = 0
        ans += rec(i + 1, n)
        a[i] = 1
        ans += rec(i + 1, n)

        return ans

    ans = rec(0, N)
    return ans


if __name__ == '__main__':
    main()


Measured memory_bytes: 141660
N, M = map(int, input().split())
result_list = []
for i in range(M):
    p, y = map(int, input().split())
    result_list.append([p, y , i])
result_list.sort()
# print(result_list)

p_buf = 0
p_index = 1
answer = []
for row in result_list:
    if p_buf != row[0]:
        p_index = 1
        answer.append([str(row[0]).rjust(6, '0')+str(p_index).rjust(6, '0'), row[2]])
        p_buf = row[0]
    else:
        p_index += 1
        answer.append([str(p_buf).rjust(6, '0')+str(p_index).rjust(6, '0'), row[2]])


for r in sorted(answer, key=lambda x:x[1]):
    print(r[0])


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

int main() {
    int N; cin >> N;
    string S; cin >> S;
    string T = S.substr(N, N);
    reverse(T.begin(), T.end());
    S = S.substr(0,N);

    map< pair<string, string>, long long > L;
    map< pair<string, string>, long long > R;
    for(int i=0; i < (1 << N); ++i) {
        string r = "", b="";
        for(int j=0; j<N; ++j) {
            if((i >> j) & 1) r += S[j];
            else b += S[j];
        }
        L[{r,b}] += 1;
    }
    for(int i=0; i < (1 << N); ++i) {
        string r = "", b="";
        for(int j=0; j<N; ++j) {
            if((i >> j) & 1) r += T[j];
            else b += T[j];
        }
        R[{r,b}] += 1;
    }
    long long res = 0;
    for(auto itr = L.begin(); itr != L.end(); ++itr) {
        pair<string, string> tmp = itr->first;
        res += L[tmp] * R[tmp];
    }
    cout << res << endl;
}

Measured memory_bytes: 108288
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;

void main() {
    string str = chomp(readln());
    int[] nx = map!(to!int)(split(str)).array.sort!("a > b").array;
    for (int i = 0; i < nx.length - 1; ++i) {
        writef("%d ", nx[i]);
    }
    writeln(nx[nx.length-1]);
}

Measured memory_bytes: 1088
#include<stdio.h>
int main(void){
	int sum;
	int a, b, c, num, bignum=0,k;
	scanf("%d %d %d", &a, &b, &c);
	scanf("%d", &num);
	if (a < b){
		if (c < b){
			bignum = b;
	k=1;
		}
	}
	if(bignum==0){
		if (a < c){
				bignum = c;
			k=2;
			}
	else{
		bignum=a;
		k=3;
	}
	}
	for (int i = 0; num > i; i++){
		bignum *= 2;
	}
	switch(k){
	case 1:
		b=bignum;
	break;
	case 2:
		c=bignum;
break;
	case 3:
		a=bignum;
break;
}
	printf("%d", a + b + c);
	return 0;
}

Measured memory_bytes: 128
import itertools
import numpy as np

n = input()
p = input().split()
q = input().split()

tmp = []
for p1 in p:
    tmp.append(int(p1))
p = tuple(tmp)

tmp = []
for p1 in q:
    tmp.append(int(p1))
q = tuple(tmp)

aa = list(itertools.permutations(np.arange(1, int(n) + 1)))
id1 = aa.index(p)
id2 = aa.index(q)

print(abs(id1 - id2))

Measured memory_bytes: 21036
#include <stdio.h>
 
int get_uint() {
    int m = 0;
    int a = getchar_unlocked();
    if(a < 48 || 57 < a) return a;
    while(47 < a && a < 58) {
        m = 10 * m + (a & 0xf);
        a = getchar_unlocked();
    }
    return m;
}
void put_uint(int m) {
    if(!m) {
        putchar_unlocked('0');
        return;
    }
    char buf[11];
    int i = 0;
    while(m) buf[i++] = (char)(m % 10 + '0'), m /= 10;
    while(i--)putchar_unlocked(buf[i]);
}
typedef struct Card {
    int i;
    int m;
    char a;
} Card;
 
// retard desu LMAO
void *partition(Card *fir, Card *last) {
    Card pivot = *(last - 1);
    Card *p = fir - 1;
    for(Card *is = fir; is != last - 1; ++is) {
        if(is->m <= pivot.m) {
            p++;
            Card tmp = *p;
            *p = *is;
            *is = tmp;
        }
    }
    Card tmp = *++p;
    *p = pivot;
    *(last - 1) = tmp;
    return p;
}
void quicksort(void *fir, void *last, size_t M) {
    if(last - fir <= M) return;
    void *mid = partition(fir, last);
    quicksort(fir, mid, M);
    quicksort(mid, last, M);
}
 
int main(int argc, char **argv) {
    int m = get_uint();
    Card A[m];
    for(int i = 0; i < m; ++i) {
        A[i].a = getchar_unlocked();
        getchar_unlocked();
        A[i].m = get_uint();
        A[i].i = i;
    }
    quicksort(A, A + m, sizeof(Card));
 
    int flag = 0;
    for(int i = 1; i < m; ++i) {
        if(A[i].m==A[i-1].m && A[i].i < A[i-1].i){
            flag = 1;
            break;
        }
    }
    puts(flag ? "Not stable" : "Stable");
    for(int i = 0; i < m; ++i) {
        putchar_unlocked(A[i].a), putchar_unlocked(' ');
        put_uint(A[i].m), putchar_unlocked('\n');
    }
    return 0;
}



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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int a,b; cin >> a >> b;
    cout << (b-a)*(b-a+1)/2-b << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cassert>
#include <cctype>
using namespace std;
string S="";
int cur=0;
char readchar()
{
  assert(cur<S.size());
  return S[cur++];
}

char peek()
{
  assert(cur<S.size());
  return S[cur];
}

int digit()
{
  assert(isdigit(peek()));
  int n=readchar()-'0';
  return n;
}

int number()
{
  int n=digit();
  while(cur<S.size()&&isdigit(peek()))
  {
    n=n*10+digit();
  }
  return n;
}

int expression();

int factor()
{
  if(peek()!='(') return number();
  cur+=1;
  int n=expression();
  assert(peek()==')');
  cur+=1;
  return n;
}

int term()
{
  int a=factor();
  while(cur<S.size()&&(peek()=='*'||peek()=='/'))
  {
    char op=readchar();
    int b=factor();
    if(op=='*')
    {
      a*=b;
    }
    else
    {
      a/=b;
    }
  }
  return a;
}

int expression()
{
  int sum=term();
  while(cur<S.size()&&(peek()=='+'||peek()=='-'))
  {
    char op=readchar();
    int b=term();
    if(op=='+')
    {
      sum+=b;
    }
    else
    {
      sum-=b;
    }
  }
  return sum;
}



int main()
{
  int n;
  cin>>n;
  for(int i=0;i<n;i++)
  {
    cur=0;
    cin>>S;
    S.resize(S.size()-1);
    cout<<expression()<<endl;
  }
  return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n; cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    vector<int> dp(n+1);
    dp[1] = 0; dp[2] = abs(h[1]-h[0]);

    for (int i=1; i<n-1; i++) {
        dp[i+2] = min(dp[i+1]+abs(h[i+1]-h[i]), dp[i]+abs(h[i+1]-h[i-1]));
    }

    cout << dp[n] << endl;

}




Measured memory_bytes: 1024
#include<bits/stdc++.h>
    #define _USE_MATH_DEFINES
    using namespace std;
    
    #define ll long long int
    #define pb push_back
    #define rep(i , j , n) for(ll i = j ; i < n ; i++)
    #define per(i , j , n) for(ll i = j ; i >= n ; i--)
    #define all(x) x.begin(), x.end()
    typedef pair<int, int>	pii;
    typedef pair<ll, ll>	pl;
    typedef vector<int>		vi;
    typedef vector<ll>		vll;
    typedef vector<bool>	vb;



int main(){ 
    char c;
    cin >> c;
    if(c >= 'A' && c <= 'Z') cout << 'A';
    else cout << 'a';
}

Measured memory_bytes: 3628