akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

		public static void main(String[] args){
			Scanner sc = new Scanner(System.in);
			// 整数の入力
			int X = sc.nextInt();
			int t = sc.nextInt();
			
			int ans = X - t;
			if (ans > 0){
	       		// 出力
	        	System.out.println(ans);
			}else{
	       		// 出力
	        	System.out.println(0);
			}
		}

}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<ll> vll;

int main() {

    string s; cin >> s;
    string a = "CODEFESTIVAL2016";

    int ans = 0;
    for(int i=0; i<s.size(); i++) {
	if(s[i] != a[i] ) ans++;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll long long
 
#define vi vector<int>
#define vl vector<long>
#define vll vector<long long>
 
#define infi INT_MAX
#define infl LONG_MAX
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)
#define F first
#define S second
#define G(a,b) get<a>(b)
#define MP make_pair
#define MT make_tuple

void func()
{
 ll n;
 cin>>n;
 ll a[n+1],b[n+1],c[n+1],dp1[n+1],dp2[n+1],dp3[n+1];
 f(i,1,n+1)  cin>>a[i]>>b[i]>>c[i];
 dp1[0]=dp2[0]=dp3[0]=0;
 //f(i,1,n+1)  cout<<a[i]<<" "<<b[i]<<" "<<c[i]<<endl;
 f(i,1,n+1)
 {
  dp1[i]=a[i]+max(dp2[i-1],dp3[i-1]);
  dp2[i]=b[i]+max(dp1[i-1],dp3[i-1]);
  dp3[i]=c[i]+max(dp1[i-1],dp2[i-1]);
 }
 //f(i,1,n)  cout<<dp1[i]<<" "<<dp2[i]<<" "<<dp3[i]<<endl;
 ll ans=(ll)max((ll)max(dp1[n],dp2[n]),dp3[n]);
 cout<<ans<<endl;
}
 
int main() 
{
    fast
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    
    ll q=1;
    //cin>>q;
    while(q)
    {
      func();
      q--;
    }
 
    return 0;
}

Measured memory_bytes: 4992
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////
#define R(i,n) for(int i=0;i<(n);++i)
/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

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

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////

void solve() {
	int A, B;
	cin >> A >> B;
	cout << max(0, A - 2*B) << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}

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

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;
template<typename T>
struct Edge {
    int u, v;
    T cost;
    Edge(int u, int v, T c) : u(u), v(v), cost(c) {}
    bool operator< (const Edge &e) const {return cost < e.cost;}
};

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

ll ans;

int main(void) {
    int t, x, n;
    cin >> n >> x >> t;
    ans = ((n+x-1)/x)*t;

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





Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
using vi = vector<int>;
using vl = vector<i64>;
using vd = vector<double>;
using pi = pair<int, int>;
using pl = pair<i64, i64>;
using pd = pair<double, double>;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
void print(vector<T> &v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<uint16_t> s(m);
  REP(i, n) {
    int k;
    cin >> k;
    REP(j, k) {
      int ss;
      cin >> ss;
      s[i] += ((uint16_t)1 << (ss - 1));
    }
  }
  vi p(m);
  REP(i, n) cin >> p[i];
  int ans = 0;
  for (uint16_t i = 0; i < (uint16_t)1 << n; ++i) {
    bool flag = true;
    REP(j, m) {
      if (__builtin_popcount(i & s[j]) % 2 != p[j]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace C___Energy_Drink_Collector
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var n = int.Parse (input[0]);
            var m = int.Parse (input[1]);
            var a = new Tuple<long, int>[n];
            for (var i = 0; i < a.Length; i++)
            {
                input = Console.ReadLine ().Split (' ');
                a[i] = Tuple.Create (long.Parse (input[0]), int.Parse (input[1]));
            }
            var quary = a.OrderBy (x => x.Item1);
            var ans = 0L;
            foreach (var p in quary)
            {
                m -= p.Item2;
                if (m > 0)
                {
                    ans += p.Item1 * p.Item2;
                }
                else if (m == 0)
                {
                    ans += p.Item1 * p.Item2;
                    break;
                }
                else
                {
                    ans += p.Item1 * (p.Item2 + m);
                    break;
                }
            }
            Console.WriteLine (ans);
        }
    }
}

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

int main(void)
{
    int A, B;
    cin >> A >> B;

    int ans = B * 10;
    for (int i = ans; i < (B+1)*10; i++) {
        if (i * 8 / 100 == A) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int c[110][110];
bool vis[110][110];
int h,w,n,x1,y1,x2,y2;
void DFS(int y,int x){
	vis[y][x]=true;
	int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
	lol(i,4){
		int xx=x+dx[i],yy=y+dy[i];
		if(xx<0||yy<0||xx==w||yy==h)continue;
		if(c[y][x]==c[yy][xx]&&!vis[yy][xx])DFS(yy,xx);
	}
}
int main(){
	while(cin>>w>>h&&w+h){
		cin>>x1>>y1>>x2>>y2>>n;
		x1--,x2--,y1--,y2--;
		lol(i,h)lol(j,w)c[i][j]=0,vis[i][j]=false;
		lol(i,n){
			int x,y,a,b;
			cin>>a>>b>>x>>y;x--,y--;
			int xx=2,yy=4;if(b==0)xx=4,yy=2;
			lol(j,yy)lol(k,xx){
				c[j+y][k+x]=a;
			}
		}
		DFS(y1,x1);
		if(vis[y2][x2]==true)cout<<"OK"<<endl;
		else cout<<"NG"<<endl;
	}
	return 0;
}

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

int N;
char A[110],B[110],C[110];

int main(){
	scanf("%d%s%s%s",&N,A,B,C);

	int ret = 0;
	for(int i=0;i<N;++i){
		char a = A[i], b = B[i], c = C[i];
		if(a==b&&b==c) ret+=0;
		else if(a == b || b == c || c==a) ret+=1;
		else ret+=2;
	}
	printf("%d\n", ret);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long mas[10000005];
void findDivisors(long long n)
{
    long long ans=0;
    for (long long i = 1; i <= n; i++) {
        for (long long j = 1; j * i <= n; j++)
            mas[i * j]++;
    }
    for (long long i = 1; i <= n; i++)
        ans+=mas[i]*i;
    cout<<ans;
}
int main()
{
    long long n;
    cin>>n;
    findDivisors(n);
    return 0;
}


Measured memory_bytes: 81728
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<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;}
/*----------------------------------------------------------------*/
// const int MOD = 998244353;
const int MOD = 1000000007;

/*----------------------------------------------------------------*/
signed main(){

	
	int a,b,c;
	cin >> a >> b >> c;

	rep(i,100000){
		if((i*a)%b == c){
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;




	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://abc060.contest.atcoder.jp/tasks/abc060_b

Measured memory_bytes: 3628
import numpy as np


def solve(string):
    n, m, *x = map(int, string.split())
    x = sorted(np.diff(sorted(x)))
    return str(sum(x)) if n == 1 else str(sum(x[:-n + 1]))


if __name__ == '__main__':
    print(solve("\n".join([input(), input()])))


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

const int NMAX = 100005;
const int MOD = 1000000007;

int n;
int A[NMAX], B[NMAX];
int inv[NMAX];
int sum[NMAX];

int lgput(int b, int e)
{
    int rez = 1, p = b;
    for (int i = 0; (1 << i) <= e; i++)
    {
        if (e & (1 << i))
        {
            rez = (rez * p) % MOD;
        }
        p = (p * p) % MOD;
    }
    return rez;
}

void faInverse()
{
    for (int i = 1; i <= n; i++)
        inv[i] = lgput(i, MOD - 2);
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> A[i];

    faInverse();

    int fact = 1;
    for (int i = 2; i <= n; i++)
        fact = fact * i % MOD;

    for (int i = 1; i <= n; i++)
        sum[i] = (sum[i - 1] + inv[i]) % MOD;

    int rez = 0;
    for (int i = 1; i <= n; i++)
    {
        int b = sum[i] + sum[n - i + 1] - inv[1];
        if (b < 0)
            b += MOD;

        rez = (rez + A[i] * b) % MOD;
    }

    cout << rez * fact % MOD;

    return 0;
}


Measured memory_bytes: 2560
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

alp = "abcdefghijklmnopqrstuvwxyz"
S = sys.stdin.readline().rstrip()

for a in alp:
    if a not in S:
        print(a)
        exit()
print("None")

Measured memory_bytes: 64748
#include <stdio.h>
int main(){
	int n, m=0, i, a, s=0;
	scanf("%d", &n);
	for(i=1; i<=n; i++){
		scanf("%d", &a);
		s += a;
		if(a > m) m = a;
	}
	printf("%d\n", s-m/2);
	return 0;
}

Measured memory_bytes: 128
min_abc = ord('A')
max_abc = ord('Z')
n = int(input())
s = input()
result=[]
for c in s:
    ascii_c = ord(c) + n
    if(ascii_c > max_abc):
        ascii_c = (min_abc-1) + (ascii_c-max_abc)
    result.append(chr(ascii_c))
print("".join(result))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;
 
 
signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int N=S.size();
  int ans=0;
  rep(i,N/2){
    if(S[i] != S[N-i-1]) ans++;
  }
  cout << ans << endl;
  
 
}

Measured memory_bytes: 256
s = str(input())

if s == "SUN":
    print("7")
elif s == "MON":
    print("6")
elif s == "TUE":
    print("5")
elif s == "WED":
    print("4")
elif s == "THU":
    print("3")
elif s == "FRI":
    print("2")
elif s == "SAT":
    print("1")

Measured memory_bytes: 3060
while True:
    #m,f,rの入力
    m,f,r = map(int,input().split())
    #試験を受けてないとき-1を入力
    #m,f,rがそれぞれ-1のとき終了
    if m == -1 and f == -1 and r == -1:
        break
    #中間試験、期末試験のいずれかを欠席した場合成績は F。
    if m == -1 or f == -1:
        print("F")
    # 中間試験と期末試験の合計点数が 80 以上ならば成績は A 。
    elif (m + f) >= 80:
        print("A")
    # 中間試験と期末試験の合計点数が 65 以上 80 未満ならば成績は B。
    elif (m + f) >=65 and (m + f) <80:
        print("B")
    # 中間試験と期末試験の合計点数が 50 以上 65 未満ならば成績は C。
    elif (m + f) >= 50 and (m + f) < 65:
        print("C")
    # 中間試験と期末試験の合計点数が 30 以上 50 未満ならば成績は D。 ただし、再試験の点数が 50 以上ならば成績は C。
    elif (m + f) >= 30 and (m + f) < 50 and r <50:
        print("D")
    elif (m + f) >= 30 and (m + f) < 50 and r >= 50:
        print("C")
    # 中間試験と期末試験の合計点数が 30 未満ならば成績は F
    elif (m + f) < 30:
        print("F")



Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
const int N = 3e4+5;

int a[N],k[N];
bool vis[10][10];

inline int cal(int x){
	int res = 0;
	while(x){
		x -= (x&(-x));
		res++;
	}
	return res;
}

int main()
{
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= n;++i) scanf("%1d",&a[i]);
	int t = 0;
	for(int i = n;i >= 1;--i){
		t |= (1 << a[i]);
		k[i] = t;
	}
	
	int ans = 0;
	for(int i = 1;i <= n-2;++i){
		for(int j = i+1;j <= n-1;++j){
			if(vis[a[i]][a[j]]) continue;
			vis[a[i]][a[j]] = 1;
			ans += cal(k[j+1]);
		}
	}
	
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    long long solve(int n, long long X, long long D) {
        if (D == 0) {
            if (X == 0) {
                return 1;
            }
            return n + 1;
        }

        if (D < 0) {
            X = -X;
            D = -D;
        }

        map<int, vector<pair<long long, long long>>> S;
        S[0].emplace_back(0, 0);
        long long L = 0;
        long long R = 0;
        long long XX = 0;
        for (int i = 0, l = 0, r = n - 1; i < n; ++i, ++l, --r) {
            L += l;
            R += r;
            XX += X;
            auto key = XX % D;
            if (key < 0) {
                key += D;
            }
            S[key].emplace_back(XX + L * D, XX + R * D);
        }

        for (auto& P : S) {
            sort(P.second.begin(), P.second.end());
        }

        long long res = 0;
        for (auto& P : S) {
            auto& V = P.second;
            int n = V.size();

            for (int i = 0; i < n; ++i) {
                auto l = V[i].first;
                auto r = V[i].second;
                while (i + 1 < n && V[i + 1].first <= r) {
                    r = max(r, V[++i].second);
                }
                // res += r / D - (l - D) / D;
                res += (r - l + D) / D;
            } 
        }
        return res;
    }

private:
    long long gcd(long long a, long long b) {
        while (a != 0) {
            b %= a;
            swap(a, b);
        }
        return b;
    }
    long long lcm(long long a, long long b) {
        return a / gcd(a, b) * b;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, X, D;
    cin >> n >> X >> D;

    Solution sol;
    cout << sol.solve(n, X, D) << '\n';

    return 0;
}

Measured memory_bytes: 22144
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <algorithm>
using namespace std;

#define Rep(i,l,r) for (int i = (l); i <= (r); ++ i)
#define RepD(i,r,l) for (int i = (r); i >= (l); -- i)
#define RepG(i,x) for (int i = hd[x]; i; i = e[i].nxt)

typedef long long ll;
const int N = 4e5+5;
int n, bd, f[N][35], ne[N]; ll l, r;
char s[N];

void pre () {
	Rep(i,1,n) {
		++ f[i][s[i]-'a'+1];
		Rep(j,1,26) f[i][j] += f[i-1][j];
	}
	int t = 2, k = ne[1] = 0;
	while (t<=n) {
		while (k && s[k+1]!=s[t]) k = ne[k];
		if (s[k+1]==s[t]) ++ k; ne[t++] = k;
	}
	bd = n-ne[n];
}

ll calc (ll k, int c) {
	if (k<=n) return f[k][c];
	if (k<=(n<<1)) return f[n][c]+f[k-n][c];
	ll lsf = f[n][c], nwf = f[n][c]+f[bd][c], lsl = n, nwl = n+bd;
	while (k>lsl+nwl) {
		swap (lsl, nwl); nwl = lsl+nwl;
		swap (lsf, nwf); nwf = lsf+nwf;
	}
	return nwf+calc (k-nwl, c);
}

int main () {
	scanf ("%s%lld%lld", s+1, &l, &r);
	n = strlen (s+1)>>1; pre ();
	Rep(i,1,26) printf ("%lld ", calc (r,i)-calc (l-1,i));
	puts ("");
	return 0;
}


Measured memory_bytes: 15232
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int n,i,p,m=-INF,ans=0;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> p;
		m = max(m,p);
		ans += p;
	}
	cout << (ans-m/2) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll n;
int main(void){
    // Your code here
    cin>>n;
    ll s[n];
    s[0]=2;
    s[1]=1;
    for(ll i=2;i<=n;i++){
        s[i]=s[i-1]+s[i-2];
    }
    cout<<s[n]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }

int cnt_digits(ll N){
    int digits = 0;
    while (N>0) {
        N /= 10;
        digits++;
    }

    return digits;
}


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

    ll sq = (ll)floor(sqrt(n));

    int ans = INF;

    for (ll i=1;i<=sq;++i) {
        if (n % i == 0) {
            ll a = n / i;

            int digits = max(cnt_digits(a), cnt_digits(i));

            ans = min(ans, digits);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using Yorukatsu046.Questions;
using Yorukatsu046.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu046.Questions
{
    /// <summary>
    /// ABC135 C
    /// </summary>
    public class QuestionB : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var n = inputStream.ReadInt();
            var monsters = inputStream.ReadIntArray();
            var braverPower = inputStream.ReadIntArray();
            var sum = 0L;

            for (int i = 0; i < braverPower.Length; i++)
            {
                var killed = Math.Min(monsters[i], braverPower[i]);
                braverPower[i] -= killed;
                sum += killed;
                killed = Math.Min(monsters[i + 1], braverPower[i]);
                monsters[i + 1] -= killed;
                sum += killed;
            }

            yield return sum;
        }
    }
}


namespace Yorukatsu046
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionB();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu046.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu046.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 36188
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

inline int read()
{
	int x=0;char ch=getchar();
	while(ch<'0' || '9'<ch)ch=getchar();
	while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
	return x;
}

inline void write(int x)
{
	if(x>=10)write(x/10);
	putchar('0'+x%10);
}

const int N=20009;

int n;
int p[N],a[N],b[N];

int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		p[i]=read();
	a[1]=1;
	for(int i=1;i<=n;i++)
		a[i]=a[i-1]+N;
	memcpy(b,a,sizeof(a));
	reverse(b+1,b+n+1);

	for(int i=1;i<=n;i++)
		b[p[i]]+=i;
	for(int i=1;i<=n;i++)
		write(a[i]),putchar(i==n?'\n':' ');
	for(int i=1;i<=n;i++)
		write(b[i]),putchar(i==n?'\n':' ');
	return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int a, b, c, d;
  std::cin >> a >> b >> c >> d;
  int u = min(d,b);
  int l = max(a,c);
  std::cout << max(0, u - l) << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <vector>
#include <map>
#include <math.h>
#include <limits.h>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> vec(n);
	map<int, int> m;
	int total = 0;
	int ma = INT_MIN;
	int mi = INT_MAX;
	for (int i = 0; i < n; i++) {
		cin >> vec[i];
		m[vec[i]]++;
		ma = max(ma, vec[i]);
		mi = min(mi, vec[i]);
	}
	int ans = INT_MAX;
	for (int i = 1; i <= 100; i++) {
		int count = 0;
		for (int j : vec) {
			count += pow(j - i, 2);
		}
		ans = min(ans, count);
	}
	cout << ans << endl;
	return 0;
}

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

int N, D[401], L;
int ld[20];
vector< vector< int > > res;

void read_input(void);
void solve(void);
void dfs(int, int);

inline int find_max_ln(void) {
  for (int i = 400; i > 0; --i)
    if (D[i] > 0)
      return i;
  return 0;
}

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

  return 0;
}

void read_input(void) {
  fill(&D[0], &D[401], 0);
  for (int i = 0; i < N * (N - 1) / 2; ++i) {
    int di;
    cin >> di, ++D[di];
  }
}

void solve(void) {
  L = find_max_ln();
  res.clear(), ld[0] = 0, ld[N - 1] = L, --D[L];
  dfs(0, N - 1);

  sort(res.begin(), res.end());
  res.resize(unique(res.begin(), res.end()) - res.begin());
  for (int i = 0; i < res.size(); ++i, cout << "\n")
    for (int j = 0; j < res[i].size(); ++j) {
      if (j > 0)  cout << " ";
      cout << res[i][j];
    }
  cout << "-----\n";
}

void dfs(int lft, int rgh) {
  if (lft + 1 == rgh) {
    res.push_back(vector< int >());
    for (int i = 1; i < N; ++i) {
      res.back().push_back(ld[i] - ld[i - 1]);
    }

    return;
  }

  int ln = find_max_ln(), i, j;
  bool is_valid;

  if (ld[lft] < ln && ln < ld[rgh]) {
    is_valid = true;
    for (i = 0; i < N && is_valid; ++i)
      if (i <= lft || rgh <= i) {
        --D[abs(ln - ld[i])];
        if (D[abs(ln - ld[i])] < 0)
          is_valid = false;
      }

    if (is_valid)
      ld[rgh - 1] = ln, dfs(lft, rgh - 1);

    for (j = 0; j < i; ++j)
      if (j <= lft || rgh <= j)
        ++D[abs(ln - ld[j])];
  }

  if (ld[lft] < L - ln && L - ln < ld[rgh]) {
    is_valid = true;
    for (i = 0; i < N && is_valid; ++i)
      if (i <= lft || rgh <= i) {
        --D[abs(L - ln - ld[i])];
        if (D[abs(L - ln - ld[i])] < 0)
          is_valid = false;
      }

    if (is_valid)
      ld[lft + 1] = L - ln, dfs(lft + 1, rgh);

    for (j = 0; j < i; ++j)
      if (j <= lft || rgh <= j)
        ++D[abs(L - ln - ld[j])];
  }
}

Measured memory_bytes: 1352
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = 10;
int ans, n, m;
struct edge {
	int v, next;
}e[maxn * maxn * 2];
int head[maxn], cnt;
bool vis[maxn];

void adde(const int &u, const int &v) {
	e[++cnt] = (edge) {v, head[u]};
	head[u] = cnt;
}

void dfs(int u, int step) {
	vis[u] = 1;
	if(step == n) {
		++ans, vis[u] = 0;
		return;
	}
	for(register int i = head[u]; i; i = e[i].next) {
		int v = e[i].v;
		if(!vis[v]) {
			dfs(v, step + 1);
		}
	}
	vis[u] = 0;
}

int main() {
	scanf("%d%d", &n, &m);
	int u, v;
	for(register int i = 1; i <= m; ++i) {
		scanf("%d%d", &u, &v);
		adde(u, v), adde(v, u);
	}
	dfs(1, 1);
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T = ll> constexpr T TEN(int n) {return (n==0)?1:10*TEN<T>(n-1);}

template <class E>
using Graph = vector<vector<E>>;

template<class D, D INF>
struct Dijkstra {
    vector<D> res; //res[i] = sからiまでの最短距離
    
    template<class E>
    Dijkstra(const Graph<E> &g, int s) {
        int V = (int)g.size();
        res = vector<D>(V, INF);
        
        using P = pair<D, int>;
        priority_queue<P, vector<P>, greater<P>> q;
        q.push(P(0, s));
        res[s] = 0;
        while (!q.empty()) {
            P p = q.top(); q.pop();
            if (res[p.second] < p.first) continue;
            for (E e: g[p.second]) {
                if (p.first+e.dist < res[e.to]) {
                    res[e.to] = p.first+e.dist;
                    q.push(P(res[e.to], e.to));
                }
            }
        }
    }
};

const int MN = 100100;

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    using P = pair<int, int>;
    set<int> gc[MN];
    vector<P> g[MN];
    for (int i = 0; i < m; i++) {
        int p, q, c;
        scanf("%d %d %d", &p, &q, &c); p--; q--;
        gc[p].insert(c);
        gc[q].insert(c);
        g[p].push_back(P(q, c));
        g[q].push_back(P(p, c));
    }

    int co = 0;
    map<P, int> p2id;
    for (int i = 0; i < n; i++) {
        gc[i].insert(0);
        for (int c: gc[i]) {
            p2id[P(i, c)] = co;
            co++;
        }
    }

    struct Edge {
        int to, dist;
    };
    Graph<Edge> gdist(co);
    for (int i = 0; i < n; i++) {
        for (P p: g[i]) {
            int j = p.first;
            int c = p.second;
            int mid = p2id[P(i, c)];
            int yid = p2id[P(j, c)];
            gdist[mid].push_back(Edge{yid, 0});
        }
        for (int c: gc[i]) {
            if (c == 0) continue;
            int mid = p2id[P(i, c)];
            int yid = p2id[P(i, 0)];
            gdist[mid].push_back(Edge{yid, 0});
            gdist[yid].push_back(Edge{mid, 1});
        }
    }
    int sid = p2id[P(0, 0)];
    int tid = p2id[P(n-1, 0)];
    int ans = Dijkstra<int, TEN(9)>(gdist, sid).res[tid];
    if (ans == TEN(9)) ans = -1;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 100476
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N, H, P;
pair<int, int>p[5000];
ll DP[5001];

int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> H >> P;
		p[i] = mkp(H + P, P);
	}
	sort(p, p + N);
	for (int i = 1; i <= N; ++i) {
		DP[i] = 0xE869120E869120;
	}
	for (int i = 0; i < N; ++i) {
		for (int j = i; j >= 0; --j) {
			if (DP[j] <= p[i].first - p[i].second) {
				DP[j + 1] = min(DP[j + 1], DP[j] + p[i].second);
			}
		}
	}
	for (int i = N; i >= 0; --i) {
		if (DP[i] != 0xE869120E869120) {
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
	int n; cin >> n;
  	int arr[n];
  	bool flag = false;
  	for (int i = 0; i < n; ++i) {
    	cin >> arr[i];
      	if (arr[i] == 1) {
        	flag = true;
        }
    }
  	if (flag) {
      	int upto = 0;
    	for (int i = 0; i < n; ++i) {
        	if (arr[i] == upto + 1) {
            	++upto;
            }
        }
      	cout << n - upto << endl;
    } else {
    	cout << -1 << endl;
    }
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <map>
#include <limits.h>

using namespace std;

int n,m;

long long cal(vector<vector<long long>> &da,vector<bool> ju){
    vector<long long> su(n,0);
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            if (ju[j]){
                su[i]+=da[i][j];
            }
            else{
                su[i]-=da[i][j];
            }
        }
    }
    sort(su.begin(),su.end());
    reverse(su.begin(),su.end());
    long long ret=0;
    for(int i=0;i<m;i++){
        ret+=su[i];
    }
    return ret;
}

int main(){
    cin >> n >> m;
    vector<vector<long long>> da(n,vector<long long> (3,0));
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin >> da[i][j];
        }
    }
    long long ans=0;
    for(int i=0;i<8;i++){
        vector<bool> ju(3);
        int k=i;
        for(int j=0;j<3;j++){
            ju[j]=bool(k%2);
            k/=2;
        }
        ans=max(ans,cal(da,ju));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int n,m;
vector<int>G[1<<17];
bool used[1<<17];
int f(int u)
{
	int ans=1;
	used[u]=1;
	for(int i=0;i<G[u].size();i++)
	{
		int v=G[u][i];
		if(!used[v])ans+=f(v);
	}
	return ans;
}
main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int a,b;cin>>a>>b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int a=f(1);
	int b=f(2);
	if(a<b)a^=b^=a^=b;
	a+=n-a-b;
	cout<<(1L*a*~-a/2+1L*b*~-b/2-m)<<endl;
}


Measured memory_bytes: 11264
s=input()
n=len(s)
for i in range(n-1):
  if s[i]==s[i+1]:
    print(i+1,i+2)
    break
  elif i<n-2 and s[i]==s[i+2]:
    print(i+1,i+3)
    break
else:
  print(-1,-1)

Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

// del

const i64 MAXN = 1003;

i64 h, w, a, b;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> h >> w >> a >> b;

    stringstream ss0;
    stringstream ss1;

    for (i64 i = 0; i < a; i++) {
        ss0 << '0';
        ss1 << '1';
    }

    for (i64 i = a; i < w; i++) {
        ss0 << '1';
        ss1 << '0';
    }


    stringstream ss;
    for (i64 i = 0; i < b; i++) {
        ss << ss0.str() << endl;
    }

    for (i64 i = b; i < h; i++) {
        ss << ss1.str() << endl;
    }

    cout << ss.str();

    return 0;
}


Measured memory_bytes: 3332
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long
#define num(a) a-'0'
#define charr(a) (a - 'A' + 1)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define maxs(a,b) if(b>a)a=b
#define mins(a,b) if(b<a)a=b
#define debug(x) cerr<<"["<<#x<<":"<<x<<"] "
#define debug2(a,b) debug(a);debug(b)
#define debug3(a,b,c) debug2(a,b);debug(c)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/(__gcd(a,b))
#define print(arr) for(auto it = arr.begin();it < arr.end();it ++){cout << *it << " ";}cout << ln;
#define all(a) (a).begin(), (a).end()
#define vi vector<long long>
#define v vector
// #define p pair
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"
typedef long double ld;
typedef double d;
using namespace std;
int modF=1e9+7;
int INF=1e11;

void solve(){
	int n;
	cin>>n;
	vi p(n);
	rep(i,0,n){
		cin>>p[i];
	}
	int min=p[0];
	int ans=0;
	for(int i=0;i<n;i++){
		if(min>=p[i]){
			ans++;
			min=p[i];
		}
	}
	cout<<ans<<ln;
}

signed main(){
	boost_io;
	solve();
	return 0;
}

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

int main() {
  int n; cin >> n;
  vector<vector<int>> to(n), len(n);
  rep(i, n-1) {
    int a, b, w;
    cin >> a >> b >> w;
    a--; b--; w %= 2;
    to[a].push_back(b); len[a].push_back(w);
    to[b].push_back(a); len[b].push_back(w);
  }
  vector<int> ans(n, -1);
  queue<int> q;
  ans[0] = 0;
  q.push(0);
  while(!q.empty()) {
    int now = q.front(); q.pop();
    rep(i, to[now].size()) {
      int next = to[now][i];
      if (ans[next] != -1) continue;
      ans[next] = ans[now] ^ len[now][i];
      q.push(next);
    }
  }
  rep(i, n) cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 11904
#include<bits/stdc++.h>
 
using namespace std;
 
int main(void)
{
    int K,A,B,i;
    bool ans = false;

    cin >> K;
    cin >> A >> B;

    for(i=A;i<=B;i++){
        if(i%K == 0){
            ans = true;
        }
    }

    if(ans){
        cout << "OK" << endl;
    }else{
        cout << "NG" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                    \
  ifstream in("abc169/abc169_d.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

// 素因数分解
vector<pair<ll, ll>> prime_factorize(ll N) {
  vector<pair<ll, ll>> res;
  for (ll a = 2; a * a <= N; ++a) {
    if (N % a != 0) continue;
    ll ex = 0;  // 指数

    while (N % a == 0) {
      ++ex;
      N /= a;
    }

    res.push_back({a, ex});
  }

  // 最後に残った数について
  if (N != 1) res.push_back({N, 1});
  return res;
}

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  ll N;
  cin >> N;

  vector<pair<ll, ll>> primes = prime_factorize(N);

  ll ans = 0;
  for (auto p : primes) {
    ll tmp = p.second;
    repi(i, 1, 100) {
      tmp -= i;
      if (tmp >= 0) {
        ans++;
      } else {
        break;
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3588
def main():
    n = int(input())
    *a, = map(int, input().split())

    memo = [[-1] * n for _ in range(n)]
    for i, x in enumerate(a):
        memo[i][i] = x

    for l in range(n - 1, -1, -1):  # ここの感覚がつかめない
        for r in range(l + 1, n):
            memo[l][r] = max(
                a[l] - memo[l + 1][r],
                a[r] - memo[l][r - 1]
            )

    print(memo[0][n - 1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 112988
/* Don't try to copy it!
                    nhi too,
                         goli maar ke cheed bana dunga...;););)
 
                 
    _/﹋\_
    (҂`_´)
    <,︻╦╤─҉- - - - - - - - => - => - =>
    _/﹋\_
                
*/
 
#include "bits/stdc++.h"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define pb push_back
#define f(a) for(ll i = 0;i<a;i++)
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define rrep(i,a,b) for(ll i = a;i>b;i--)
#define vll vector<ll>
#define T ll t; cin>>t; while(t--)
#define freeopen freopen("input.txt","r",stdin);
#define freeclose freopen("output.txt","w",stdout);
#define MOD 1000000007
using namespace std;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
ll n,k;
ll a[100005];
ll m;
ll dp[100005];
ll tarr(ll total)
{
    // cout<<total<<"\n";
    if(total==0)
        return 0;
    if(dp[total]!=-1)
        return dp[total];

    dp[total]=0;
        for(ll i=0;i<n;i++)
        {
            if(a[i]<=total)
            {
                if(tarr(total-a[i])==0)
                    dp[total]=1;
            }

        }
        return dp[total];
}



main()
{
    memset(dp,-1,sizeof(dp));
    cin>>n>>k;

    f(n)
    cin>>a[i];

    ll tf;
    ll m=*min_element(a,a+n);
    tf=tarr(k);
    if(tf)
        cout<<"First";
    else
        cout<<"Second";
}



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

template<long long mod>
class modint{
private:
  long long a;
public:
  constexpr modint(const long long x = 0) noexcept : a(x%mod) {}
  constexpr long long& value() noexcept { return a; }
  constexpr const long long& value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint& operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if(a >= mod) a -= mod;
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if(a < rhs.a) a += mod;
    a -= rhs.a;
    return *this;
  }
  constexpr modint& operator*=(const modint rhs) noexcept {
    a = a*rhs.a%mod;
    return *this;
  }
  constexpr modint& operator/=(modint rhs) noexcept {
    long long k = mod-2;
    while(k > 0){
      if(k&1){
        *this *= rhs;
      }
      rhs *= rhs;
      k /= 2;
    }
    return *this;
  }
  friend ostream& operator<<(ostream &os, const modint &X){
    return os << X.a;
  }
  friend istream& operator>>(istream &is, modint &X){
    is >> X.a;
    X.a %= mod;
    if(X.a < 0) X.a += mod;
    return is;
  }
};

int main(){
  using mint = modint<(int)998244353>;
  int N;
  cin >> N;
  vector<int> D(N);
  for(int i = 0; i < N; ++i) cin >> D[i];
  if(D[0] != 0){
    cout << 0 << endl;
    return 0;
  }
  sort(D.begin(), D.end());
  if(N > 1 and D[1] == 0){
    cout << 0 << endl;
    return 0;
  }
  mint ans = 1;
  vector<int> DD(N,0);
  DD[0] = 1;
  for(int i = 1; i < N; ++i){
    ans *= DD[D[i]-1];
    ++DD[D[i]];
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main() {
    ll x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    ll p[a], q[b], r[c];
    rep(i, a) {
        cin >> p[i];
    }
    rep(i, b) {
        cin >> q[i];
    }
    rep(i, c) {
        cin >> r[i];
    }
    sort(p, p + a);
    reverse(p, p + a);
    vector<ll> v;
    rep(i, x) {
        v.emplace_back(p[i]);
    }
    sort(q, q + b);
    reverse(q, q + b);
    rep(i, y) {
        v.emplace_back(q[i]);
    }
    sort(ALL(v));
    reverse(ALL(v));
    ll sum[x + y + 1] = {};
    rep(i, x + y) {
        sum[i + 1] = sum[i] + v[i];
    }
    sort(r, r + c);
    reverse(r, r + c);
    ll ans = 0;
    ll now = 0;
    rep(i, min(x+y,c)) {
        ans = max(ans, now + sum[x + y - i]);
        now += r[i];
    }
    ans = max(ans, now + sum[x + y - min(x + y, c)]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5488
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
struct edge{
    ll to,cost;
    edge(ll to,ll cost):to(to),cost(cost) {}
};
vector<vector<edge>> graph;
ll n;
ll prim(){
    vector<bool> used(n,false);
    priority_queue<P,vector<P>,greater<P>> pq;
    ll res=0;
    pq.push(P(0,0));
    while(!pq.empty()){
         ll cst = pq.top().fi, v = pq.top().se;
        pq.pop();
        if(used[v]) continue;
        used[v]=true;
        res += cst;
        for(int i = 0; i < graph[v].size(); i++){
            edge e=graph[v][i];
            pq.push(P(e.cost, e.to));
        }
    }
    return res;
}
int main(){
  cin>>n;
  graph.resize(n);
  V<P> x(n),y(n);
  for(int i=0;i<n;i++){
    cin>>x[i].fi>>y[i].fi;
    x[i].se=i;y[i].se=i;
  }
  sort(all(x));sort(all(y));
  for(int i=0;i<n-1;i++){
    graph[x[i].se].emplace_back(x[i+1].se,x[i+1].fi-x[i].fi);
   graph[x[i+1].se].emplace_back(x[i].se,x[i+1].fi-x[i].fi);
  }
  for(int i=0;i<n-1;i++){
    graph[y[i].se].emplace_back(y[i+1].se,y[i+1].fi-y[i].fi);
    graph[y[i+1].se].emplace_back(y[i].se,y[i+1].fi-y[i].fi);
  }
  cout<<prim()<<"\n";
}


Measured memory_bytes: 21876
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<20)
#define LLINF (1LL<<60)
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
    ll n, k;
    ll ans=0;
    cin >> n >> k;
    for (ll i = k; i <= n + 1;i++){
        ll MAX = (((n + (n - i + 1)) * i) / 2);
        ll MIN = (((0 + (i - 1)) * i) / 2);
        ans += (MAX - MIN + 1)%MOD;
    }
    cout << ans%MOD << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <queue>
using namespace std;

class Input {
public:
	static int NextInt() { int N; cin >> N; return N; }
};

int main()
{
	int N = Input::NextInt();
	vector<long> a(3 * N);
	for (int i = 0; i < 3 * N; i++) { cin >> a[i]; }

	long first_half = 0;
	priority_queue<long, vector<long>, greater<long>> pq1;
	for (int i = 0; i < N; i++) { first_half += a[i]; pq1.push(a[i]); }

	vector<long> memo(3 * N);
	for (int i = 0; i < 3 * N; i++)memo[i] = 0;
	memo[N - 1] = first_half;
	for (int i = N; i < 2 * N; i++) {
		first_half += a[i];
		pq1.push(a[i]);
		first_half -= pq1.top();
		memo[i] = first_half;
		pq1.pop();
	}

	long later_half = 0;
	priority_queue<long> pq2;
	for (int i = 2 * N; i < 3 * N; i++) { later_half += a[i]; pq2.push(a[i]); }

	long ans = memo[2 * N - 1] - later_half;
	for (int i = 2 * N - 1; i >= N; i--) {
		later_half += a[i];
		pq2.push(a[i]);
		later_half -= pq2.top();
		pq2.pop();
		ans = max(ans, memo[i - 1] - later_half);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7284