akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX_H = 1000;
static const int MAX_W = 1000;
static const int MAX_N = 10;
static const int INF = 1 << 30;
typedef pair<int, int> P;

int H, W, N;
char s[MAX_H][MAX_W + 1];
P p[MAX_N];
int dist[MAX_H][MAX_W];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

int bfs(int n, int m){
	queue<P> qa;
	fill(dist[0], dist[H], INF);
	qa.push(p[n]);
	dist[p[n].first][p[n].second] = 0;
	while(!qa.empty()){
		P t = qa.front(); qa.pop();
		if(t == p[m]) break;
		for(int i = 0; i < 4; i++){
			int nx = t.first + dx[i];
			int ny = t.second + dy[i];
			if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
			if(s[nx][ny] == 'X') continue;
			if(dist[nx][ny] == INF){
				qa.push(make_pair(nx, ny));
				dist[nx][ny] = dist[t.first][t.second] + 1;
			}
		}
	}
	return dist[p[m].first][p[m].second];
}

int main(){
	cin >> H >> W >> N;
	for(int i = 0; i < H; i++){
		cin >> s[i];
		for(int j = 0; j < W; j++){
			if(s[i][j] == 'S'){
				p[0] = make_pair(i, j);
			}else if(s[i][j] >= '1' && s[i][j] <= '9'){
				p[s[i][j] - '0'] = make_pair(i, j);
			}
		}
	}
	int ans = 0;
	for(int i = 0; i < N; i++){
		ans += bfs(i, i + 1);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7988
#include<iostream>
using namespace std;
int main(){
    int i,n,q,key,c=0,nc,k,l;
    cin>>n;
    int S[n];
    for(i=0;i<n;i++) cin>>S[i];
    cin>>q;
    nc=n/2;
    for(i=0;i<q;i++){
        cin>>key;
        if(S[nc]!=key){
            if(S[nc]<key) k=nc,l=n;
            else if(S[nc]>key) k=0,l=nc;
            for(int j=k;j<l;j++){
            if(S[j]==key){
                c++;
                break;
                }
            }
        }
        else if(S[nc]==key) c++;
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 3388
from heapq import heappush, heappop

n, m = map(int, input().split())

abl = []
for i in range(n):
    abl.append(tuple(map(int, input().split())))
abl.sort()

q = []
count = 0
ans = 0

for i in range(1, m+1):
    while count < n:
        a, b = abl[count]
        if a > i:
            break
        heappush(q, -b)
        count += 1
    if q:
        ans += -heappop(q)

print(ans)


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

using namespace std;
int main(void){
    int h,n,buf,sum=0;
    vector<int> a;
    cin>>h>>n;
    for(int i=0;i<n;i++){
        cin>>buf;
        a.push_back(buf);
        sum+=buf;
    }
    if(sum>=h){
        cout<<"Yes";
    }
    else{
        cout<<"No"<<endl;
        
    }
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 0x3F3F3F3F;
const int maxn = 2e5 + 555;
const int MOD = 1e9 + 7;
template <typename base_type, base_type MOD> struct IntMod {
    base_type n;
    IntMod(long long d = 0) { n = (d >= 0 ? d % MOD : (d % MOD + MOD) % MOD); }
    IntMod operator-() const { return build(n == 0 ? 0 : MOD - n); }
    IntMod &operator+=(IntMod a) {
        n = (n >= MOD - a.n ? n - MOD + a.n : n + a.n);
        return *this;
    }
    IntMod &operator-=(IntMod a) {
        n = (n >= a.n) ? n - a.n : n - a.n + MOD;
        return *this;
    }
    IntMod &operator*=(IntMod a) {
        *this = *this * a;
        return *this;
    }
    static IntMod build(base_type n) {
        IntMod r;
        r.n = n;
        return r;
    }
    friend bool operator==(IntMod a, IntMod b) { return a.n == b.n; }
    friend bool operator!=(IntMod a, IntMod b) { return a.n != b.n; }
    friend IntMod operator+(IntMod a, IntMod b) { return build(a.n >= MOD - b.n ? a.n - MOD + b.n : a.n + b.n); }
    friend IntMod operator-(IntMod a, IntMod b) { return build(a.n >= b.n ? a.n - b.n : a.n - b.n + MOD); }
    friend IntMod operator*(IntMod a, IntMod b) { return build(static_cast<base_type>(static_cast<long long>(a.n) * b.n % MOD)); }
    friend istream &operator>>(istream &stream, IntMod &a) {
        stream >> a.n;
        return stream;
    }
    friend ostream &operator<<(ostream &stream, const IntMod &a) {
        stream << a.n;
        return stream;
    }
};
using Int = IntMod<int, MOD>;
Int a[maxn];
Int b[maxn];
int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(10);
    cout << fixed;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        b[i] = a[i] + b[i - 1];
    }
    Int ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += a[i] * (b[n] - b[i]);
    }
    cout << ans.n << endl;
    return 0;
}

Measured memory_bytes: 5220
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int wayLength = sc.nextInt();
        int houseCnt = sc.nextInt();


        int[] place = new int[houseCnt];

        for(int index=0;index<houseCnt;index++){
            place[index] = sc.nextInt();
        }
        sc.close();
        // max計算
        int[] distance = new int[houseCnt];
        for(int i=0;i<houseCnt-1;i++){
            distance[i] = place[i+1] - place[i];
        }
        distance[houseCnt-1] = place[0] + (wayLength-place[houseCnt-1]);

        int max = distance[0];
        for (int ind=0;ind<houseCnt;ind++){
            if(max < distance[ind]){
                max = distance[ind];
            }
        }

        System.out.println(wayLength-max);
    }
}

Measured memory_bytes: 84524
N = [int(s) for s in input()]
M = len(N)

eq = 0
ov = 1

for n in N:
    a = min(eq + n, ov + 10 - n)
    b = min(eq + (n + 1), ov + 10 - (n + 1))
    eq, ov = a, b

print(eq)


Measured memory_bytes: 13632
#define taskname ""
#include <bits/stdc++.h>

using namespace std;

const int maxN = 1e5;

int n;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
    cin >> n;
    int k = n;
    int cnt = 0;
    do
    {
        ++cnt;
        k /= 10;
    }
    while (k != 0);
    switch(cnt)
    {
    case 1:
        cout << n;
        break;
    case 2:
        cout << 9;
        break;
    case 3:
        cout << 9 + n - 100 + 1;
        break;
    case 4:
        cout << 9 + 999 - 100 + 1;
        break;
    case 5:
        cout << 9 + 999 - 100 + 1 + n - 10000 + 1;
        break;
    case 6:
        cout << 9 + 999 - 100 + 1 + 99999 - 10000 + 1;
    }
    return 0;
}


Measured memory_bytes: 256
import math

A, B = map(int, input().split())

priceA1 = math.ceil(A / 0.08)
priceA2 = (A+1) / 0.08
priceB1 = math.ceil(B / 0.10)
priceB2 = (B+1) / 0.10

if math.floor(priceA2) < priceA2:
    priceA2 = math.floor(priceA2)
else:
    priceA2 = math.floor(priceA2) - 1


if math.floor(priceB2) < priceB2:
    priceB2 = math.floor(priceB2)
else:
    priceB2 = math.floor(priceB2) - 1

if priceA1 <= priceB1 <= priceA2:
    print(math.ceil(priceB1))
elif math.ceil(priceB1) < math.ceil(priceA1) < priceB2:
    print(math.ceil(priceA1))
elif math.ceil(priceA1) == math.ceil(priceB1):
    print(math.ceil(priceA1))
else:
    print(-1)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <cstdlib>
#include <algorithm>
using namespace std;

vector<pair<int, char>> expr;
int idx = 0;

int calc() {
    int ret;
    int depth = expr[idx].first;
    char op = expr[idx].second;
    idx++;

    if (op == '+') ret = 0;
    else if (op == '*') ret = 1;
    else ret = op - '0';

    while (idx < expr.size() && expr[idx].first == depth + 1) {
        int val;
        if (expr[idx].second == '+' || expr[idx].second == '*') {
            val = calc();
        } else {
            val = expr[idx++].second - '0';
        }

        if (op == '+') {
            ret += val;
        } else if (op == '*') {
            ret *= val;
        }
    }
    return ret;
}

void solve(int n) {
    idx = 0;
    expr.clear();
    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        int depth = s.size() - 1;
        char c = s[s.size() - 1];
        expr.push_back({depth, c});
    }
    cout << calc() << endl;
}

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



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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int N = nextInt();
  map<int,int> count;
  REP(i, N) {
    int a = nextInt();
    ++count[a];
  }
  vector<int> v;
  for (auto it = count.begin(); it != count.end(); ++it) v.push_back(it->second);

  map<int,int> P;
  for (int x : v) ++P[x];
  auto Porg = P;


  vector< pair<int,int> > moves;
  for (int K = 1; K <= N; K++) {
    if (K == 1) { printf("%d\n", N); continue; }
    if (K > (int)v.size())  { printf("%d\n", 0); continue; }
    P = Porg;
    int ans = 0;
    while (true) {
      int k = K;

      moves.clear();
      for (auto it = P.rbegin(); it != P.rend(); ++it) {
        int move = min(k, it->second);
        moves.push_back({it->first, move});
        k -= move;
        if (k == 0) break;
      }
      if (k > 0) break;

      int step = max(1, moves.back().first - 1);
      ans += step;
      for (auto move : moves) {
        P[move.first] -= move.second;
        if (move.first - step >= 1) P[move.first - step] += move.second;
      }
    }

    printf("%d\n", ans);
  }
  return 0;
}

int main() {
#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 15988
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>
#define _USE_CMATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); //1.15*10^18

long h, n, sum;

int main(){
    scanf("%ld%ld", &h, &n);
    for(int i = 0; i < n; i++){
        long a;
        scanf("%ld", &a);
        sum += a;
    }
    if(sum < h){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
}


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

const int N = 500020 , mod = 998244353;

inline int qpow(int x , int y = mod - 2) {
	int res = 1;
	for(; y ; y >>= 1 , x = 1ll * x * x % mod)
		if(y & 1) res = 1ll * res * x % mod;
	return res; 
} 
int fac[N] , inv[N];
int C(int x , int y)
{
	if(y < 0 || y > x) return 0;
	return 1ll * fac[x] * inv[y] % mod * inv[x - y] % mod; 
}
typedef long long int64;

void C_init(int n) {
    fac[0] = 1;
    for(int i = 1 ; i <= n ; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
    inv[n] = qpow(fac[n]);
    for(int i = n-1 ; ~i ; i--) inv[i] = inv[i + 1] * (i + 1ll) % mod;
}

int n , k , ans;

int main() {
    cin >> n >> k;
    C_init(k);
    for(int i = max((k+1)/2,n) ; i <= k ; ++i) {
        int v = k - (i*2==k);
        ans = (ans + C(v , i)) % mod;
        ans = (ans - C(v, 2*i - n + 1) + mod) % mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
using namespace std;
int ans[100500],sz[100500];
int main(){
    int n,m,x,y;
    scanf("%d%d",&n,&m);
    rep(i,1,n) sz[i]=1;
    ans[1]=1;
    rep(i,2,n) ans[i]=0;
    rep(i,1,m){
        scanf("%d%d",&x,&y);
        sz[x]--;
        sz[y]++;
        if (ans[x]) ans[y]=1;
        if (sz[x]==0&&ans[x]) ans[x]=0;
    }
    int cnt=0;
    rep(i,1,n) if (ans[i]) cnt++;
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 1024
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        n: usize,
        aa: [isize; n]
    };
    let mut min = std::isize::MAX;
    let mut x = 0isize;
    let mut y: isize = aa.iter().sum();
    for i in 0..(n - 1) {
        let a = aa[i];
        x += a;
        y -= a;
        min = std::cmp::min(min, (x - y).abs());
    }
    println!("{}", min);
}


Measured memory_bytes: 4800
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    int a;
    cin >> a ;
    //*/
    
    /*
    vector<int> vec(4);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;
    
    sort(vec.begin(), vec.end());
    */
    
    /*
    if(a <= b){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    */
    
    cout << a / 3 << endl;

    return 0; 
}


Measured memory_bytes: 3644
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
#define int long long
int INF = 1e9+7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
  return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
  int M,N;
  cin>>M>>N;
  int ans=0;
  vector<int>A(M);
  rep(i,M){
    cin>>A[i];
    ans+=A[i];
  }
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  cout<<(A[N-1]*N*4>=ans? "Yes":"No")<<endl;
}

Measured memory_bytes: 3640
/*
ID: rajiv
TASK: test
LANG: C++14
*/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>
#include<sstream>
#include<iterator>
#include<random>
#include<chrono>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ONLINE_JUDGE

using namespace std;

#define deb(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) { cout << '\n';}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << '[' << *it << " = " << a << "]  ";
    err(++it, args...);
}
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
int rnd(int a, int b){ // including a and b
	return a+(rng()%(b-a+1));
}
#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sortr(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb push_back
#define endl '\n'

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<lli, lli> tii;
typedef tuple<lli, lli, lli> tiii;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

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

void solve(){
	int n,k; cin>>n>>k;
	vi a(n);
	rep(i,n) cin>>a[i];
	sortr(a);
	lli ans=0;
	rep(i,k) ans+=a[i];
	cout<<ans<<endl;
}

int main(){
	fast_io
	#ifndef ONLINE_JUDGE
	freopen("test.in", "r", stdin);
	freopen("test.out", "w", stdout);
	#endif 
	int tc=1;
	//cin>>tc;
	while(tc--){solve();}
	return 0;
}

Measured memory_bytes: 3540
def main():
    n, m = input().split(' ')
    print(mul(n, m))


def mul(n: str, m: str) -> int:
    n = int(n)
    m = int(f'{m[:-3]}{m[-2:]}')

    return (n * m) // 100


if __name__ == '__main__':
    main()


Measured memory_bytes: 9044
#include <stdio.h>
 
int main(void) 
{
    int A[4][3][10] = {0},n, i,j,k;
     
    scanf("%d", &n);
    for(i = 0; n> i; i++)
    {
        int b,f,r,v;
        scanf("%d%d%d%d",&b,&f,&r,&v);
        A[b-1][f-1][r-1] += v;
    }
    
    for(i = 0; 4 > i; i++)
    {
        for(j = 0; 3 > j; j++)
        {
            for(k = 0; 10 > k; k++)
            {
                printf(" %d", A[i][j][k]);
            }
            printf("\n");
        }
        if(i == 3) break;
        for(k = 0; 20 > k; k++)
        {
                printf("#");
        }
        
        printf("\n");
    }
    
    return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
ll n,cnt=0;

int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  cin>>n;
  string s[n];
  REP(i,n) cin>>s[i];
  REP(i,n){
    REP(j,n)REP(k,n){
      if(s[(j+i)%n][k]!=s[(k+i)%n][j])goto E;
    }
    cnt++;E:;
  }
  P(cnt*n);

  return 0;
}


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

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

  int n, q; cin >> n >> q;
  VI c(n); rep(i, n) cin >> c[i];
  vector<pair<int, int>> lr(q); rep(i, q) cin >> lr[i].first >> lr[i].second;
  rep(i, q) lr[i].first--;

  const int sq = 700;
  vector<tuple<int, int, int>> lri(q);
  rep(i, q) lri[i] = make_tuple(lr[i].first / sq, lr[i].second, i);
  sort(lri.begin(), lri.end());

  VI ans(q);

  VI cnt(n+1);
  int prev = -1;
  int lx, rx; lx = rx = get<0>(lri[0]);
  int sum = 0;
  VI changed;
  for (auto [ls, r, i] : lri) {



    // ここのコメントを外すとhandmade03-05, random06がWAになる

    if (ls != prev) {
      fill(cnt.begin(), cnt.end(), 0);
      lx = rx = r;
      prev = ls;
      sum = 0;
    }



    int l = lr[i].first;
    assert(r == lr[i].second);  // assert(rx <= r);
    int cx;
    while (lx > l) if (cnt[cx=c[--lx]]++ == 0) sum += 1;//, changed.push_back(cx);
    while (lx < l) if (--cnt[c[lx++]] == 0) sum -= 1;
    while (rx < r) if (cnt[cx=c[rx++]]++ == 0) sum += 1;//, changed.push_back(cx);
    ans[i] = sum;
  }
  rep(i, q) cout << ans[i] << "\n";
}


Measured memory_bytes: 19316
#include<stdio.h>

int main(void)
{
  int a;
  int b;
  int c;
  int d;
  int e;
  int max;
  
  scanf("%d", &a);
  scanf("%d", &b);
  
  c = a + b;
  d = a - b;
  e = a * b;
  
  max = c;
  if(max < d){
    max = d;
  }
  if(max < e){
    max = e;
  }
  printf("%d", max);
  
  return 0;
}



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

int main()
{
    string s;
    cin>>s;
    bool a[10] = {0};
    int j=0;
    for(auto &i:s)
    {
        if( i == '0')
            a[j++] = 0;
        else if ( i == '1')
            a[j++] = 1;
        else if ( i == 'B')
            j = max(0,j-1);
    }

    forn(i,j)
        cout<<a[i];
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1e18
#define pb push_back
#define int long long
#define fi first
#define se second
#define bw(i,r,l) for (int i=r-1;i>=l;i--)
#define fw(i,l,r) for (int i=l;i<r;i++)
#define fa(i,x) for (auto i:x)
using namespace std;
int n,s,tmp;
int get(int n,int b) {return n<b?n:get(n/b,b)+n%b;}
bool check(int i) {
	int ans=get(n,i);
	if (ans==s) return true;
	return false;
}
signed main() {
	//freopen("aome.inp","r",stdin);
	//ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n>>s;
	if (n==s) {cout<<n+1; return 0;}
	tmp=n-s;
	int ans=INF;
	fw (i,1,sqrt(tmp)+1) if (tmp%i==0) {
		if (check(i+1)) {ans=min(ans,i+1);}
		if (check(tmp/i+1)) {ans=min(ans,tmp/i+1);}
	}
	if (ans==INF) cout<<"-1";
	else cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<assert.h>

namespace beet{
  
  template<typename T>
  struct Vector{
    int sz,cap;
    T *data;
    Vector():sz(0),cap(1){
      data = new T[cap];
    }    
    Vector(int sz):sz(sz),cap(sz<<1){
      data = new T[cap];
    }
    Vector(int sz,T t):sz(sz),cap(sz<<1){
      data = new T[cap];
      for(int i=0;i<sz;i++) data[i]=t;
    }
    Vector(const Vector &v){    
      sz=v.sz;
      cap=v.cap;  
      data = new T[v.cap];
      for(int i=0;i<sz;i++) data[i]=v[i];
    }    
    ~Vector(){
      // printf("%p\n",data);
      delete[] data;
    }
    void resolve(){
      T *tmp = new T[cap];
      for(int i=0;i<sz;i++) tmp[i]=data[i];
      delete[] data;
      data=tmp;
    }
    void push_back(T x){
      if(sz>=cap){
        cap<<=1;
        assert(sz<cap);
        resolve();
      }      
      data[sz++]=x;
    }
    void pop_back(){
      sz--;
    }
    void shrink(int nx){assert(nx<=sz);sz=nx;}
    int size() const{
      return sz;
    }
    const T operator[](int x) const{
      return data[x];
    }
    T& operator[](int x){
      assert(0<=x&&x<sz);
      return data[x];
    }
  };

  template<typename T>
  void swap(T &a,T &b){
    T x=a;
    a=b;
    b=x;
  }

  template<typename T>
  void sort(Vector<T> &vs){
    int n=vs.size();
    Vector<T> tmp(n);
    
    auto dfs=
      [&](int l,int r,auto &func)->void{
        // printf("%d %d\n",l,r);
        if(l+1==r) return;
        int m=(l+r)>>1;
        func(l,m,func);
        func(m,r,func);        
        for(int k=l;k<r;k++) tmp[k]=vs[k];

        int i=l,j=m,k=l;
        while(i<m&&j<r){
          if(tmp[i]<tmp[j]){
            vs[k++]=tmp[i++];
          }else{
            vs[k++]=tmp[j++];
          }
        }
        while(i<m) vs[k++]=tmp[i++];
        while(j<r) vs[k++]=tmp[j++];
      };
    dfs(0,n,dfs);
  }
}
using namespace beet;
struct Point{
  int x,y;
  Point(){}
  Point(int x,int y):x(x),y(y){}
  Point operator+(Point p) {return Point(x+p.x,y+p.y);}
  Point operator-(Point p) {return Point(x-p.x,y-p.y);}
  bool operator<(const Point &b)const{
    return y!=b.y?y<b.y:x<b.x;
  }
};

typedef Vector<Point> Polygon;

int cross(Point a,Point b){
  return a.x*b.y-a.y*b.x;
}

Polygon convex_hull(Polygon ps){
  int n=ps.size();
  sort(ps);
  
  int k=0;
  Polygon qs(n*2);  
  for(int i=0;i<n;i++){
    while(k>1&&cross(qs[k-1]-qs[k-2],ps[i]-qs[k-1])<0) k--;
    qs[k++]=ps[i];
  }
  for(int i=n-2,t=k;i>=0;i--){
    while(k>t&&cross(qs[k-1]-qs[k-2],ps[i]-qs[k-1])<0) k--;
    qs[k++]=ps[i];
  }
  qs.shrink(k-1);
  return qs;
}

int main(){
  int n;
  scanf("%d",&n);
  Polygon ps(n);
  for(int i=0;i<n;i++)
    scanf("%d %d",&(ps[i].x),&(ps[i].y));

  Polygon qs=convex_hull(ps);  
  
  printf("%d\n",qs.size());
  for(int i=0;i<qs.size();i++)
    printf("%d %d\n",qs[i].x,qs[i].y);
  return 0;
}



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


int main(){
   map<int, int> mx, my;
   int h, w, m;
   cin >> h >> w >> m;
   int X[m], Y[m];
   map<pair<int, int>, int> occ;
   for(int i = 0; i < m; i++){
       int x, y;
       cin >> x >> y;
       occ[{x, y}]++;
       mx[x]++;
       my[y]++;
       X[i] = x;
       Y[i] = y;
   }
   int ans = 0;
   int maxcnt = 0, mxx = 0;
   for(int i = 0; i < m; i++){
       if(mx[X[i]] > maxcnt){
           maxcnt = mx[X[i]];
           mxx = X[i];
       }
   }
   
   for(int j = 1; j <= w; j++){
       if(occ[{mxx, j}]){
           ans = max(ans, mx[mxx] + my[j] - 1);
       }else{
           ans = max(ans, mx[mxx] + my[j]);
       }
   }
   
   int ycnt = 0, maxy = 0;
   
   for(int i = 0; i < m; i++){
       if(my[Y[i]] > ycnt){
           ycnt = my[Y[i]];
           maxy = Y[i];
       }
   }
   
   for(int i = 1; i <= h; i++){
       if(occ[{i, maxy}]){
           ans = max(ans, mx[i] + my[maxy] - 1);
       }else{
           ans = max(ans, mx[i] + my[maxy]);
       }
   }
   cout << ans;
   return 0;
}

Measured memory_bytes: 90292
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
use std::collections::HashMap;
#[fastout]
fn main() {
    input! {
        n: usize,
        s: [Chars; n],
    }
    let mut m = (b'a'..=b'z')
        .map(|c| c as char)
        .map(|c| (c, 50))
        .collect::<HashMap<char, i32>>();
    for i in 0..n {
        let mut m_s = (b'a'..=b'z')
            .map(|c| c as char)
            .map(|c| (c, 0))
            .collect::<HashMap<char, i32>>();
        for j in s[i].iter() {
            let counter = m_s.entry(*j).or_insert(0);
            *counter += 1;
        }
        for k in b'a'..=b'z' {
            let m_s_value = m_s.get_mut(&(k as char)).unwrap();
            let m_value = m.get_mut(&(k as char)).unwrap();
            if m_value > m_s_value {
                *m_value = *m_s_value;
            }
        }
    }
    for i in b'a'..=b'z' {
        let val = m.get(&(i as char)).unwrap();
        if val > &0 && val != &50 {
            for _ in 0..*val {
                print!("{}", i as char);
            }
        }
    }
}


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

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

    vector<vector<array<ll, 2>>> dp(n.size() + 1, vector<array<ll, 2>>(k + 1));
    for(ll p = n.size(); p >= 0; --p){
        for(ll r = 0; r <= k; ++r){
            for(ll s = 1; s >= 0; --s){
                if(r == 0){
                    dp.at(p).at(r).at(s) = 1;
                }else if(p == n.size()){
                    dp.at(p).at(r).at(s) = 0;
                }else if(s == 1){
                    dp.at(p).at(r).at(s) = 9 * dp.at(p + 1).at(r - 1).at(1) + dp.at(p + 1).at(r).at(1);
                }else{
                    ll tmp = 0;
                    const ll d = n.at(p) - '0';
                    if(d > 0){
                        tmp += dp.at(p + 1).at(r - 1).at(0);
                    }
                    if(d > 1){
                        tmp += dp.at(p + 1).at(r - 1).at(1) * (d - 1);
                    }
                    tmp += dp.at(p + 1).at(r).at(d > 0);
                    dp.at(p).at(r).at(s) = tmp;
                }
            }
        }
    }
    cout << dp.at(0).at(k).at(0) << endl;
    return 0;
}


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

using namespace std;

int main(){
  string str;
  int check[26]={0};
  
  cin >> str;
  for(int i = 0;i<str.size();i++){
	check[str[i]-'a']=1;
  }
  for(int i =0;i<26;i++){
	if(check[i]==0){
	  cout << (char)('a'+i)<< endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define INF 1<<28
#define MAX 100005
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

typedef long long ll;

int n, a[100005];
int dp[MAX];

int main()
{
    FASTIO
   /* 
   double start_time = clock();
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
  #endif
    */
    cin>>n;
    for(int i = 1; i <= n; i++)
        cin>>a[i];
    dp[1] = 0;
    for(int i = 2; i <= n; i++){
        dp[i] = dp[i-1] + abs (a[i] - a[i-1]);
        if(i > 2){
            dp[i] = min(dp[i], dp[i-2] + abs(a[i] - a[i-2]));
        }
    }
    cout << dp[n]<<endl;

  //   double end_time = clock();
  //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);
   
    return 0;
}  

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

using namespace std;
#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 1e-8;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int x[N], y[N];

double val (double X, double Y) {
	double ret = 0;
	for (int i = 1; i <= n; i ++) {
		double res = 0;
		res = (x[i] - X) * (x[i] - X) + (y[i] - Y) * (y[i] - Y); 
		ret = max(ret, res);
	}
	return ret;
}

double f(double X) {
	double yl = 0, yr = 1000;
	double res = INF;
	for (int it = 0; it <= 500; it++) {
		double m1 = yl + (yr - yl) / 3;
		double m2 = yr - (yr - yl) / 3;

		if(val(X, m1) < val(X, m2)) {
			yr = m2;
			res = min(val(X, m1), res);
		} else {
			yl = m1;
			res = min(res, val(X, m2));  
		}
	}
	return res;
}

int main () {
	SpeedForce;
	cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> x[i] >> y[i];
	}

	double ans = INF;
	double xl = 0, xr = 1000;

	for (int it = 0; it <= 550; it++) {
		double m1 = xl + (xr - xl) / 3;
		double m2 = xr - (xr - xl) / 3;
		if (f(m1) < f(m2)) {
			xr = m2;
			ans = min(ans, f(m1));
		} else {
			xl = m1;
			ans = min(ans, f(m2));
		}
	}

	ans = min(ans, f(xl + xr / 2));
	
	cout << fixed << setprecision(12) << sqrt(ans) << '\n';
   	return Accepted;
}

// B...a

Measured memory_bytes: 2304
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m, f, r;
		char result = 0;
		while (true) {
			m = sc.nextInt();
			f = sc.nextInt();
			r = sc.nextInt();

			if (m == -1 && f == -1 && r == -1)
				break;

			if (m == -1 || f == -1)
				result = 'F';

			else if ((m + f) >= 80)
				result = 'A';
			else if ((m + f) >= 65)
				result = 'B';
			else if ((m + f) >= 50)
				result = 'C';
			else if ((m + f) >= 30) {
				if (r >= 50)
					result = 'C';
				else
					result = 'D';
			} else
				result = 'F';
			System.out.println(result);
		}
	}

}

Measured memory_bytes: 26220
def main():
    num = int(input())
    num_list = list(map(int, input().split()))

    if 0 in num_list:
        print(0)
    else:
        ans = 1
        for i in num_list:
            ans = ans * i
            if ans > 1000000000000000000:
                print(-1)
                break
        else:
            print(ans)


if __name__ == '__main__':
    main()


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

template<class Iterator, class Compare>
int inversion_number(Iterator l, Iterator r, Compare comp){
	if(r - l <= 1) return 0;
	Iterator i, j, k, h = l + (r - l) / 2;
	int ans = inversion_number(l, h, comp) + inversion_number(h, r, comp);
	auto x = *l;
	vector<decltype(x)> tmp(l, r);
	for(i = l, j = l, k = h; i < r; i++){
		if(k == r || (j < h && !comp(tmp[k - l], tmp[j - l]))){
			*i = tmp[j - l];
			j++;
		}
		else{
			*i = tmp[k - l];
			ans += k - i;
			k++;
		}
	}
	return ans;
}

signed main(){
	int N, i;
	scanf("%lld", &N);
	vector<int> p(N + 1, 0), l(N + 1, 0);
	for(i = 1; i <= N; i++){
		scanf("%lld", &p[i]);
		p[i] += p[i - 1];
	}
	for(i = 1; i <= N; i++){
		scanf("%lld", &l[i]);
	}
	int ans = inversion_number(p.begin() + 1, p.end() - 1, [](auto a, auto b){
		return a < b;
	});
	for(i = 1; i <= N; i++){
		if(p[i] - p[i - 1] < l[i]){
			printf("-1\n");
			return 0;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 5480
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int A[]=new int[N];
		int B[]=new int[N];
		int C[]=new int[N];
		int z=0,ans=0;
		while(z<N){
			A[z]=stdIn.nextInt()-1;
			z++;
		}z=0;
		while(z<N){
			int b=0;
			b=stdIn.nextInt();
			B[z]=b;
			z++;
		}z=0;
		while(z<N-1){
			int c=stdIn.nextInt();
			C[z]=c;
			z++;
		}z=1;
		ans+=B[0];
		while(z<N){
			ans+=B[z];
			if(A[z-1]+1==A[z])
				ans+=C[A[z-1]];
			z++;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdint>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P &element1, const P &element2)
{ //first昇順
	return element1.first < element2.first;
}
bool ps2(const P &element1, const P &element2)
{ //first降順
	return element1.first > element2.first;
}
bool ps3(const P &element1, const P &element2)
{ //second昇順
	return element1.second < element2.second;
}
bool ps4(const P &element1, const P &element2)
{ //second降順
	return element1.second > element2.second;
}
int digits(int n)
{
	int count = 0;

	while (n > 0)
	{
		n /= 10;

		count++;
	}
	return count;
}
int digit(int n)
{

	int ans = 0;
	while (n > 0)
	{
		ans += n % 10;
		n /= 10;
	}
	return ans;
}
ll combination(ll n, ll r)
{
	if (r * 2 > n)
		r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i)
	{
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
int GCD(int x, int y)
{
	return x ? GCD(y % x, x) : y;
}
vector<int> divisor(int n)
{
	vector<int> value;
	FOR(i, 1, pow(n, 0.5) + 1)
	{
		if (i <= sqrt(n))
		{
			if (n % i == 0)
			{
				value.push_back(i);
				if (i * i != n)
				{
					value.push_back(n / i);
				}
			}
		}
	}
	return value;
}

int main()
{
	int n;
	cin>>n;
	vector<int>a(n);
	map<int,int>b;
	rep(i,n){
		cin>>a[i];
		b[i+1]=a[i];
	}
	int cou=0;
	rep(i,n){
		if(b[a[i]]==i+1){
			cou++;
		}
	}
	cout<<cou/2<<endl;

	
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
 
typedef long long ll;

using namespace std;
using Graph = vector<vector<int>>;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++);
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl;

const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

const double PI=3.14159265358979323846; // or M_PI


void Main() {
    vector<ll> a(5);

    REP(i, 5) {
        cin >> a[i];
        if (a[i] == 0) {
            COUT(i + 1);
        }
    }

}

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


Measured memory_bytes: 3652
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal
from argparse import ArgumentParser

args=ArgumentParser()
args.add_argument('-loc', '--local', type=bool,default=False)
LOCAL=args.parse_args().local

def input(): 
    x=sys.stdin.readline(); 
    if x[-1]=="\n": 
        return x.rstrip() 
    return x
    
def printe(*x):_=print("## ",*x,file=sys.stderr) if LOCAL else 0
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 998244353
 
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    S = tuple(tuple(map(int, input().split())) for i in range(K)) #改行行列

    dp=[0]*N
    dp[0]=1
    acc=[0]*N
    tacc=0
    for i in range(N):
        if i!=0:
            tacc=(tacc+acc[i])%mod
            dp[i]=tacc
        for l,r in S:
            if i+l<N:
                acc[i+l]+=dp[i]
                acc[i+l]%=mod
            if i+r+1<N:
                acc[i+r+1]-=dp[i]
                acc[i+r+1]%=mod
        
    print(dp[-1])

if __name__ == "__main__":
    main()

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

const int maxn = 2e5 + 10;
const long long inf = 1e18 + 1;
long long s[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, a; cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a; s[i] = s[i - 1] + a;
    }
    long long ans = inf;
    for (int i = 1; i < n; ++i) {
        ans = min(ans, abs(s[i] + s[i] - s[n]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from datetime import date, timedelta

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
D = LIST()
D.sort()

cnt = Counter(D)
if cnt.most_common()[0][1] >= 3:
	print(0)
	exit()

time = [0]
for i, d in enumerate(D):
	if i % 2 == 0:
		time.append(d)
	else:
		time.append(24-d)
time.sort()
time.append(24)
ans = INF
for i in range(N):
	ans = min(ans, time[i+1]-time[i])
print(ans)


Measured memory_bytes: 5320
#include <iostream>
#include <string>
using namespace std;
 
string str[]={" ","',.!?","abcABC","defDEF","ghiGHI","jklJKL","mnoMNO","pqrsPQRS","tuvTUV","wxyzWXYZ"};
 
int main(){
    string s;
     
    while(cin >> s){
        int len = s.size();
         
        int k = 0;
        if(s[len-1]!='0'){
            s += '0';
            k = 1;
        }
         
        string ans = "";
        for(int i = 0 ; i < len+k ; i++){
            int cnt = 1, j;
            for(j = i+1 ; j < len+k ; j++){
                if(s[i] != s[j]) break;
            }
            if(s[i] == '0'){
                if(j==i+2) ans += " ";
                else if(j==i+3) ans += "  ";
            }
            else{
                ans += str[s[i]-'0'][j-i-1];
            }
            i += j-i-1;
        }
        cout << ans << endl;
    }
     
    return 0;
}

Measured memory_bytes: 3156
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;

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

}

/* 
g++ -std=c++14 main.cpp
*/

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            int n = scan.nextInt();
            int[] bSort = new int[n];
            for(int i = 0;i < n;i++){
                bSort[i] = scan.nextInt();
            }
            int count = 0;
            for(int i = 0;i < n;i++){
                for(int j = n-1;j > i;j--){
                    if(bSort[j] < bSort[j-1]){
                        swap(bSort,j,j-1);
                        count++;
                    }
                }
            }
            PrintOut(bSort,n);
            System.out.println(count);
        }
    }
     
    public static void swap(int[] a,int i,int j){
        int t = a[j];a[j] = a[i];a[i] = t;
    }
     
    public static void PrintOut(int[] a,int n){
        for(int i = 0;i < n;i++){
            System.out.print(a[i] + ((i == n-1)?"\n":" "));
        }
    }
}

Measured memory_bytes: 26328
#include<stdio.h>
int main(){
  int A,B,C,D;
  scanf("%d%d%d%d",&A,&B,&C,&D);
  while(A!=0&&C!=0){
    C-=B;
    if(C<=0){break;}
    A-=D;
    if(A<=0){break;}
  }
  if(A>0)
    {printf("Yes\n");}
  else
    {printf("No\n");}
  return 0;
}


Measured memory_bytes: 1644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    ll n, k; cin >> n >> k;
    COMinit();
    for(int i=1;i<=k;++i){
        ll res = 1;
        res = COM(n-k+1, i) * COM(k-1, i-1) % MOD;
        cout << res  << endl;
    }
}

Measured memory_bytes: 12160
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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 int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
const long long MAX_V = 1010101;

struct edge {
  long long to, cost;
};

long long V;
vector<edge> Graph[MAX_V];
long long dist[MAX_V];

void dijkstra(long long s) {
  priority_queue<Pll, vector<Pll>, greater<Pll>> que;

  // 0-indexed
  fill(dist, dist + V, INF);
  // 1-indexed
  // fill(dist + 1, dist + 1 + V, INF);

  dist[s] = 0;
  que.push(Pll(0, s));

  while (!que.empty()) {
    auto elem = que.top();
    que.pop();

    auto cv = elem.second;

    if (elem.first > dist[cv]) {
      continue;
    }

    for (auto e : Graph[cv]) {
      if (dist[e.to] > dist[cv] + e.cost) {
        dist[e.to] = dist[cv] + e.cost;
        que.push(Pll(dist[e.to], e.to));
      }
    }
  }
}

int H, W;
int A[300][300];

int main() {
  cin >> H >> W;
  repe(i, 0, 9) {
    repe(j, 0, 9) {
      int c;
      cin >> c;
      Graph[j].push_back(edge{i, c});
    }
  }

  V = 10;
  dijkstra(1);
  int ans = 0;
  rep(i, 0, H) {
    rep(j, 0, W) {
      int a;
      cin >> a;
      if (a != -1) {
        ans += dist[a];
      }
    }
  }
  cout << ans << endl;
}


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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int main(){
    int N, M, S[2000], T[2000];
    cin >> N >> M;
    for(int i=0; i<N; i++) cin >> S[i];
    for(int i=0; i<M; i++) cin >> T[i];

    static int64_t dp[2001][2001];
    dp[0][0] = 1;
    for(int i=0; i<N; i++){
        int64_t sum = 0;
        for(int j=0; j<M; j++){
            add(sum, dp[i][j]);
            add(dp[i+1][j], dp[i][j]);
            if(T[j] == S[i]) add(dp[i+1][j+1], sum);
        }
        add(dp[i+1][M], dp[i][M]);
    }

    int64_t ans = 0;
    for(int j=0; j<=M; j++) add(ans, dp[N][j]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 31488
/* include c++ libraries */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <queue>
#include <set>

/* include c-lang libraries */
#include <climits>
#include <cmath>

/* include my libraries */
//#include <show_vec.hh>

using namespace std;

#define LINE DEBUG{ printf("LINE : %d\n", __LINE__); }
#define DEBUG if(false)

using ll = long long;
template<class T> using vec = vector<T>;

const int MOD = 1000000007;

int main(){
  int N;
  cin >> N;
  int all;
  vec<int> A(N);
  for(int i = 0; i < N; i++){
    cin >> A[i];
    if(i == 0){
      all = A[i];
    }else{
      all = all ^ A[i];
    }
  }

  for(int i = 0; i < N; i++){
    cout << (all ^ A[i]) << endl;
  }
  return 0;
}


Measured memory_bytes: 3968
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  int hit,out;
  int score;
  string c;
  cin >> n;
  for(int i=0;i<n;i++){
    hit = 0; 
    out = 0;
    score = 0;
    while(out!=3){
      cin >> c;
      if(c=="HIT"){
	hit++;
	if(hit==4){
	  score += 1;
	  hit = 3;
	}
      }
      else if(c=="HOMERUN"){
	score += (hit+1);
	hit =  0;
      }
      else out++;
    }
    cout << score << endl;
  }
  return 0;
}

Measured memory_bytes: 1208