akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ar array
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll mod = 1e9 + 7;
const ll inf = 2e9 + 5;
double PI = 3.14159265358979323846;

template <ll M> struct ModInt {
	int val;
	ModInt(ll x = 0): val((x % M + M) % M) {}

	ModInt pow(ll n) const {
		ModInt ans = 1, x = val;
		while (n) {
			if (n & 1) ans *= x;
			x *= x;
			n /= 2;
		}
		return ans;
	}

	ModInt inverse() const { return pow(M - 2); }
	ModInt operator+ (const ModInt& m) { return val + m.val < M ? val + m.val : val + m.val - M; }
	ModInt operator- (const ModInt& m) { return val - m.val >= 0 ? val - m.val : val - m.val + M; }
	ModInt operator* (const ModInt& m) { return val * (ll) m.val % M; }
	ModInt operator/ (const ModInt& m) { return *this * m.inverse(); }
	ModInt operator+=(const ModInt& m) { return *this = *this + m; }
	ModInt operator-=(const ModInt& m) { return *this = *this - m; }
	ModInt operator*=(const ModInt& m) { return *this = *this * m; }
	ModInt operator/=(const ModInt& m) { return *this = *this / m; }

	friend ostream& operator<<(ostream& os, const ModInt& m) {
		os << m.val;
		return os;
	}

	friend istream& operator>>(istream& is, ModInt& m) {
		is >> m.val;
		return is;
	}
};

using mint = ModInt<mod>;


void solve() {

	int n, k;
	cin >> n >> k;
	vi a(n + 1);

	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	vector<vector<mint>> dp(n + 1, vector<mint>(k + 1, 0));

	dp[0][0] = 1;

	for (int i = 1; i <= n; i++) {

		vector<mint> pre(k + 1, 0);
		pre[0] = dp[i - 1][0];
		for (int j = 1; j <= k; j++) {
			pre[j] = (pre[j - 1] + dp[i - 1][j]);
		}

		/*
			if I have j candies I can give ith child any candies from 0...j
			say I give x to ith child then remaining can be divided
			among i-1 children something like:
			dp[i-1][j-x]+dp[i-1][j-x-1]+++dp[i-1][0] i,e prefix_sum(dp[i-1][0...j-x])

			Take care: when j > a[i];
		*/

		for (int j = 0; j <= k; j++) {

			mint temp;
			if (j - a[i] > 0) {
				temp = (pre[j] - pre[j - a[i] - 1]);
			} else {
				temp = pre[j];
			}
			dp[i][j] = temp;
		}
	}
	cout << dp[n][k];

}

int32_t main()
{
	IOS
	// int T; cin >> T; while (T--)
	solve();
	return 0;
}


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

int main() {
    int q;
    int right_n;
    int left_n;
    cin >> q;
    vector<int> A;
    for(int i = 0; i < q; i++) {
        cin >> left_n;
        if(left_n == 0) {
            cin >> right_n;
            A.push_back(right_n);
        } else if(left_n == 1) {
            cin >> right_n;
            cout << A[right_n] << endl;
        } else if(left_n == 2) {
            A.pop_back();
        }
    }
    return 0;
}


Measured memory_bytes: 3936
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String t = sc.next();
    int ans = 0;
    for(int i = 0; i < 3; i++) {
      if(s.charAt(i) == t.charAt(i)) ans++;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}

int main()
{
	int D=read(),N=read();
	For(i,1,2000000)
	{
		if(i%(int)pow(100,D)==0 && i%(int)pow(100,D+1)!=0)N--;
		if(N==0)
		{
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}



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

using ll=long long; 

void solve(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int cnt=0;
	for(int i=0; i<=100; i++){
		if((i>=a&&i<b) && (i>=c&&i<d)){
			cnt++;
		}
	}
	cout<<cnt<<endl;
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main()
    {
        var inp = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        bool ans = false;
        for (int i = 1; i <= inp[1]; i++) if (i * inp[0] % inp[1] == inp[2]) ans = true;
        Console.WriteLine(ans ? "YES" : "NO");
    }
}


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

int main() {
    int H, A;
    cin >> H >> A;
    int count = 0;
    count = H / A;
    if(H % A != 0) count++;
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from heapq import heappush,heappop

n,m = map(int,input().split())
ab = []
for line in sys.stdin:
    a,b = map(int,line.split())
    if a <= m:
        ab.append([a,b])
ab.sort()

stock = []
ans = 0
for i in range(1,m+1):
    while ab and ab[0][0] <= i:
        a = ab.pop(0)
        heappush(stock,-a[1])
    if stock:
        ans += -heappop(stock)

print(ans)

Measured memory_bytes: 21668
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,s[22],d[111];
int dp[111][1<<15],sum[1<<15];
main()
{
	while(cin>>n>>m,n)
	{
		for(int i=0;i<n;i++)cin>>s[i];
		for(int i=0;i<1<<n;i++)
		{
			sum[i]=0;
			for(int j=0;j<n;j++)if(i&1<<j)sum[i]+=s[j];
		}
		for(int i=0;i<m;i++)cin>>d[i];
		sort(d,d+m);
		for(int i=0;i<m;i++)
		{
			for(int j=0;j<1<<n;j++)
			{
				dp[i+1][j]=dp[i][j]+abs(d[i]-sum[j]);
				for(int k=0;k<n;k++)
				{
					if(j&1<<k)dp[i+1][j]=min(dp[i+1][j],dp[i+1][j&~(1<<k)]);
				}
			}
		}
		cout<<dp[m][(1<<n)-1]<<endl;
	}
}



Measured memory_bytes: 15940
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  string S, T;
  cin >> S >> T;
  string ans;
  for (int i = 0; i < N; i++) ans += S[i], ans += T[i];
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define ll long long
#define ii pair<string,int>ii;

string IntToStr(int tmp){
    ostringstream out;
    out << tmp;
    return out.str();
}

int main()
{
    int n,k;
    cin>>n>>k;
    vector<ll>v;
    while(n--){
        ll x;
        cin>>x;
        v.pb(x);
    }
    sort(v.begin(),v.end());
    int len=v.size();
    ll min=100000000000000;
    for(int i=0; i<len-k+1; i++){
        ll kk=abs(v[i]-v[i+k-1]);
        if(min>kk)
            min=kk;
    }
    cout<<min<<endl;
}














Measured memory_bytes: 1400
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new KK(); }
class KK
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	double[] GR => Strs.Select(double.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	public const int MOD = 1000000007;
	public const long INFL = 4011686018427387913L;
	public KK()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var N = F;
		var S = Str;
		// dp[i,j]=p[0,i]をうめる && p[i]=j (0<=i<N, 0<=j<=i)
		var dp = new long[N, N];
		dp[0, 0] = 1;
		for (var i = 1; i < N; i++)
		{
			var sum = new long[N + 1];
			for (var j = 0; j < N; j++) sum[j + 1] = (sum[j] + dp[i - 1, j]) % MOD;
			for (var j = 0; j <= i; j++)
			{
				if (S[i-1]=='>')
				{
					// dp[i,j]=sum(dp[i-1,k-1],j<k<=i)=sum(dp[i-1,k],j=<k<i)
					dp[i, j] = sum[i] - sum[j];
				}
				else
				{
					// dp[i,j]=sum(dp[i-1,k],0<=k<j)
					dp[i, j] = sum[j] - sum[0];
				}
			}
		}
		var ans = 0L;
		for (var j = 0; j < N; j++) ans += dp[N - 1, j];
		ans %= MOD;
		if (ans < 0) ans += MOD;
		WriteLine(ans);
	}
}


Measured memory_bytes: 104760
#include <bits/stdc++.h>
using namespace std;
//解答例写し
int main(){
  long long n;
  cin>>n;
  long long V=0;
  long long E=0;
  for(long long i=1;i<=n;i++){
    V+=i*(n-i+1);
  }
  for(long long i=0;i<n-1;i++){
    long long a,b;
    cin>>a>>b;
    if(a>b)swap(a,b);
    E+=a*(n-b+1);
  }
  long long ans=V-E;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3592
a=int(input())
b=int(input())
c=int(input())
x=int(input())
cnt=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if(i*500+j*100+k*50==x):
                cnt+=1
print(cnt)


Measured memory_bytes: 3060
/**
  @file c.cpp
  @title D - Megalomania
  @brief https://atcoder.jp/contests/abc131/tasks/abc131_d
**/

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;

template <class T>
void show(vector<T>& v) {
  for (uint i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << "\n";
}

template <class T1, class T2>
void show(vector<pair<T1, T2>>& v, int x) {
  if (x == 1) {
    for (uint i = 0; i < v.size(); i++) {
      cout << v[i].first << "\t";
    }
  } else if (x == 2) {
    for (uint i = 0; i < v.size(); i++) {
      cout << v[i].second << "\t";
    }
  } else {
    cout << "Wrong Argument";
  }
  cout << "\n";
}

bool compare_by_second(pair<LL, LL> a, pair<LL, LL> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

int main() {
  int N;
  cin >> N;
  vector<pair<LL, LL>> AB(N);
  LL tmpA, tmpB;
  for (int i = 0; i < N; i++) {
    cin >> tmpA >> tmpB;
    AB[i] = make_pair(tmpA, tmpB);
  }

  // for debug
  // cout << "Before Sort" << endl;
  // show(AB, 1);
  // show(AB, 2);
  // cout << endl;

  sort(AB.begin(), AB.end(), compare_by_second);

  // for debug
  // cout << "After Sort" << endl;
  // show(AB, 1);
  // show(AB, 2);

  LL time = 0;
  for (int i = 0; i < N; i++) {
    time += AB[i].first;
    if (time > AB[i].second) {
      cout << "No" << endl;
      exit(0);
    } else {
      //do nothing
      // cout << i << " "; // for debug
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		int N,Q;
		String str;

		N=sc.nextInt();
		Q=sc.nextInt();
		str=sc.next();

		int[] l=new int[Q];
		int[] r=new int[Q];

		for(int i=0;i<Q;i++) {
			l[i]=sc.nextInt();
			r[i]=sc.nextInt();
		}

		int[] sum=new int[N+1];

		char a='A';
		char c='C';

		for(int i=1;i<N;i++) {
			if(str.charAt(i-1)==a && str.charAt(i)==c) {
				sum[i+1]=sum[i]+1;
			}else {
				sum[i+1]=sum[i];
			}
		}


		for(int i=0;i<Q;i++) {
			int ans=sum[r[i]]-sum[l[i]];
			System.out.println(ans);
		}

		sc.close();

	}

}


Measured memory_bytes: 85128
N, K = map(int, input().split())
hn = []
for i in range(N):
  hn.append(int(input()))
hn = sorted(hn,reverse=True)
min = 10**9+7
for i in range(N-K+1):
#  print("hn[i] is {} , hn[K+i] is {}".format(hn[i],hn[K+i-1]))
  if min > (hn[i]-hn[K+i-1]):
    min = hn[i]-hn[K+i-1]
print(min)


Measured memory_bytes: 8280
n=input()
arr=map(float,raw_input().split())
if n==2:
        print (arr[0]+arr[1])/2
else:
        arr.sort()
        tot=arr[0]+arr[1]
        c=2
        for i in range(2,n):
                tot+=c*arr[i]
                c*=2
        print tot/pow(2,n-1)


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

#define f first
#define s second
#define ins insert
#define eb emplace_back
#define endl '\n'
#define ll long long
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define ii pair<int,int>
#define no cout << "NO" << endl;
#define yes cout << "YES" << endl;
#define tc int t; cin >> t; while (t--)
#define sz(c) (int) (c).size()
#define trav(x,c) for(auto &x : c)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define _for(i,a,n) for(int i = a ; i < n; ++i)
#define _rfor(i,n,a) for(int i = n-1 ; i >= a; --i)
#define db(x) cout << #x << ": " << x << endl;
#define _db(c) trav(x,c) cout << x << " "; cout << endl;
#define godspeed ios::sync_with_stdio(0); cin.tie(0);
template<typename... T> void read(T&... x) {((cin >> x),...);}


int main() {
    godspeed;
    
    ll n, m, k; cin >> n >> m >> k;
    vl a(n), b(m);
    for (ll i = 0 ; i < n ; ++i) cin >> a[i];
    for (ll i = 0 ; i < m ; ++i) cin >> b[i];

    vl asum(n+1), bsum(m+1);
    for (ll i = 0 ; i < n ; ++i) asum[i+1] = a[i] + asum[i];
    for (ll i = 0 ; i < m ; ++i) bsum[i+1] = b[i] + bsum[i];

    ll ans = 0;
    for (ll i = 0 ; i <= n ; ++i) {
        ll other = k - asum[i];
        if (other < 0) continue;

        ll l = lower_bound(all(bsum),other) - bsum.begin();
        if (l > m || bsum[l] > other) l--;

        ans = max(ans,i+l);
    }

    cout << ans;
}

Measured memory_bytes: 9516
/*
First, solve the problem.Then write the code. - John Johnson
@author: returnAC
*/
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define need_for_speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); // Thanks Joshua :)
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c)) 
typedef long long ll;
typedef unsigned long long llu;
const double PI = 2*acos(0.0);

signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	need_for_speed;
	int n,m;
	cin>>n>>m;
	map<int,int> count;
	for(int i=0;i<n;i++)
	{
		int q;
		cin>>q;
		while(q--)
		{
			int a;
			cin>>a;
			count[a]++;
		}
	}
	int res = 0;
	for(int i=1;i<=m;i++)
		if(count[i]==n)
			++res;
	cout<<res<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a; }
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int g = gcd(a, b);

    yn(c % g == 0);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n,k,a[51],o=0;
    cin>>n>>k;
    for (i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+n+1);
    for (i=n;i>n-k;i--) o=o+a[i]; 
 	cout<<o<<endl;
}

Measured memory_bytes: 256
#a,b,c,d=map(int,input().split())
n=int(input())
s=input()
ans=0
hantei=0
for i in s:
  if i=="I":
    ans+=1
  elif i=="D":
    ans-=1
  if ans>hantei:
    hantei=ans
  
print(hantei)


Measured memory_bytes: 2940
from itertools import combinations

n, x, y = map(int, input().split())

c = [0] * (n-1)
for a, b in combinations(range(1, n+1), 2):
    p = b - a
    q = abs(x-a)+1+abs(y-b)
    r = min(p, q)
    c[r-1] += 1

print('\n'.join([str(num) for num in c]))


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

ll MOD = 1e9+7;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	vi T (N);
	vi A (N);
	F0R(i, N) cin >> T[i];
	F0R(i, N) cin >> A[i];

	vi arr (N, -1);
	arr[0] = T[0];
	FOR(i, 1, N) if (T[i] != T[i-1]) arr[i] = T[i];
	arr[N-1] = A[N-1];
	ROF(i, 0, N-1) if (A[i] != A[i+1]) arr[i] = A[i];

	int hi = arr[0];
	F0R(i, N) {
		hi = max(hi, arr[i]);
		if (hi != T[i]) {
			print(0);
			return 0;
		}
	}

	hi = arr[N-1];
	R0F(i, N) {
		hi = max(hi, arr[i]);
		if (hi != A[i]) {
			print(0); 
			return 0;
		}
	}

	ll res = 1;
	vi height (N, 1e9+10);
	F0R(i, N) height[i] = min(height[i], T[i]);
	R0F(i, N) height[i] = min(height[i], A[i]);
	F0R(i, N) if (arr[i] == -1) {
		res *= height[i]; res %= MOD;
	}
	print(res);
}

Measured memory_bytes: 4740
// Why I am so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int MAXN = (int)3e5 + 5;                                           
                         
vector<string> vv[20];

string s1[MAXN], t1[MAXN];

string s2[MAXN], t2[MAXN];

char s[55];

int pw[20];

ll ans;

int n;

void pre() {
    pw[0] = 1;

    for (int i = 1; i < 20; ++i) {
        pw[i] = (pw[i - 1] << 1);
    }
}

bool bit(int x, int p) {
    return x & pw[p];
}

void solve() {                   
    scanf("%d %s", &n, s);

    for (int m = 0; m < pw[n]; ++m) {
        for (int i = 0; i < n; ++i) {
            if (bit(m, i)) {
                s1[m].pb(s[i]);
                s2[m].pb(s[i + n]);
            }
            else {
                t1[m].pb(s[i]);
                t2[m].pb(s[i + n]);
            }
        }

        reverse(all(t1[m]));
        reverse(all(t2[m]));
    }    

    for (int m = 0; m < pw[n]; ++m) {
        vv[s2[m].size()].pb(t2[m] + s2[m]);          
    }

    for (int i = 0; i < 20; ++i) {
        sort(all(vv[i]));
    }

    for (int m = 0; m < pw[n]; ++m) {
        auto it = equal_range(all(vv[t1[m].size()]), s1[m] + t1[m]);
        ans += (it.se - it.fi);        
    }    
         
    printf("%lld\n", ans);
}

int main() {    
    int tt = 1;

    pre();

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

    return 0;
}

Measured memory_bytes: 87008
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#include <bits/stdc++.h>
using namespace std;

int main() {
  int a,b;
  cin>>a>>b;
  
  if(a>=13) cout << b << endl;
  else if(a<6) cout << 0 << endl;
  else cout << b/2 << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n;
  scanf("%d", &n);
  int x=10,res=0;
  while(x<=n){
    res += x-x/10;
    x*=100;
  }
  if(n>=x/10) res += n-x/10+1;
  printf("%d\n", res);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;
int main(void){
    
    //変数 N, Kの宣言
    int N, K;
    
    //変数 N, Kの入力
    cin >> N >> K;
    
    //NとKの差が「 1 」かどうか判定
    if(K * 2 - 1 <= N) cout << "YES" << endl;
    else cout << "NO" << endl;
    
}

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

int main(){
    int n,r;
    cin >> n >> r;
    if(n<10) r+=100*(10-n);
    cout << r << endl;
    return 0;
}

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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
const ll mod = 1000000007;
const ll INF = 10010010010010010;

int main() {
    int n; cin >> n;
    int a[n];
    int idx[n];
    rep(i,n) {
        cin >> a[i];
        a[i]--;
        idx[a[i]] = i;
    }
    //rep(i,n) {printf("%d ", idx[i]);} printf("\n");
    multiset<int> Set;
    for (ll i = -1; i < n+1; i++) Set.insert(i);
    Set.insert(-1); Set.insert(n);
    ll ans = 0;
    rep(i,n-1) {
        int p = idx[i];
        auto itr = Set.lower_bound(p);
        auto itr2 = itr; itr2--;
        auto itr3 = itr; itr3++;
        auto itr1 = itr2; itr1--;
        auto itr4 = itr3; itr4++;
        int p1 = (*itr1);
        int p2 = (*itr2);
        int p3 = (*itr3);
        int p4 = (*itr4);
        //printf("%d %d %d %d %d\n", p1,p2,p,p3,p4);
        ans += ((ll)i+1)*((p2-p1)*(p3-p)+(p4-p3)*(p-p2));
        //cout << ans << endl;
        Set.erase(p);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9048
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define int ll
#define INF 1e18
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
signed main(){
    int n,m,r; cin>>n>>m>>r;
    vector<int>_r;
    rep(i,r){int a; cin>>a; _r.push_back(--a);}
    sort(all(_r));
    vector<vector<int>>d(201,vector<int>(201,INF));
    rep(i,201)d[i][i]=0;
    rep(i,m){
        int a,b,c; cin>>a>>b>>c;
        d[--a][--b]=c;
        d[b][a]=c;
    }
    rep(k,n)rep(i,n)rep(j,n)cmin(d[i][j],d[i][k]+d[k][j]);
    int ans=INF;
    do{
        int temp=0;
        for(int i=0;i<r-1;i++)
            temp+=d[_r[i]][_r[i+1]];
        cmin(ans,temp);
    }while(next_permutation(_r.begin(),_r.end()));
    cout<<ans<<endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int d = scan.nextInt();

		if (a < b) {
			if (c < d) {
				System.out.println(a + c);
			} else {
				System.out.println(a + d);
			}
		} else {
			if (c < d) {
				System.out.println(b + c);
			} else {
				System.out.println(b + d);
			}
		}
	}

}


Measured memory_bytes: 22868
#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>
using namespace std;
//using ll=long long;
//#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}

int gcd(int a, int b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) {      //最小公倍数
    return a * b / gcd(a, b);
}

int keta(int n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}

int ketasum(int n) {    //各桁の和
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
//最小化問題(DP)
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
//最大化問題(DP)
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//dp注意点
//問題の種類	 初期化する値	 備考
//最小化問題 	INF	
//最大化問題	    -INF	 テーブル全体で 00 以上の値しかとらないことがわかっていれば −1−1 でもいいですし、00 でもいい場合もあります
//数え上げ問題	00	
//確率問題	      00	
//Yes/No 判定問題	False
/*-------------ここまで---------------------------------------------*/

/*signed*/int main() {
    int n;
    cin >> n;
    cout << n * n * n << endl;
    return 0;
}

Measured memory_bytes: 3540
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}


int main() {

    int N, M;
    cin >> N >> M;

    vector<long long> x(N), y(N), z(N);
    for (int i = 0; i < N; i++)cin >> x[i] >> y[i] >> z[i];

    vector<vector<long long>> xyz(3, vector<long long>(N));
    for (int i = 0; i < N; i++) xyz[0][i] = x[i];
    for (int i = 0; i < N; i++) xyz[1][i] = y[i];
    for (int i = 0; i < N; i++) xyz[2][i] = z[i];

    for (int i = 0; i < 3; i++) SHOW_VECTOR(xyz[i]);

    long long ans = LONG_LONG_MIN;
    for (int bit = 0; bit < (1 << 3); bit++) {
        vector<long long> a(N, 0);
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < 3; j++) {
                if (bit & (1 << j)) {
                    a[i] += -xyz[j][i];
                } else {
                    a[i] += xyz[j][i];
                }
            }
        }
        sort(a.begin(), a.end());
        reverse(a.begin(), a.end());
        long long sum = 0;
        for (int i = 0; i < M; i++) sum += a[i];
        ans = max(ans, sum);
    }
    cout << ans << endl;
}



























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


int main()
{
   int n,x,i,j,count=0,a;

   scanf("%d",&n);


   for(i=0;i<n;i++)
  {
    scanf("%d",&x);
    if(x==2) count++;
    if(x<2 || (x%2)==0) continue;

    for(j=3;j<=sqrt(x);j=j+2)
    {
        if((x%j)==0) 
        {
            a=1;
            continue;
        }
            
    }
   if(a==1) 
   {
       a=0;
       continue;
   }
    count++;
    
  }

  printf("%d\n",count);

    return 0;
}




Measured memory_bytes: 2044
#include <cstdio>
#include <map>
#define LL long long
using namespace std;

const int N = 200005;
int n, a[N];
map<LL,LL>mp;

int main()
{
    scanf("%d", &n);
    mp[0] = 1;
    LL sum = 0, cnt = 0;

    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        sum += (LL)a[i];
        cnt += mp[sum];
        mp[sum]++;
    }

    printf("%lld", cnt);
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;

int n, panjang, dp[5005][5005];
long long hasil;
string s;

int hitung(int pos, int sisa) {
    if (sisa == 0) {
        if (pos == panjang)
            return 1;
        return 0;
    }
    int &ret = dp[pos][sisa];
    if (ret != -1)
        return ret;
    ret = (2 * hitung(pos + 1, sisa - 1)) % mod;
    if (pos > 0)
        ret = (ret + hitung(pos - 1, sisa - 1)) % mod;
    else
        ret = (ret + hitung(pos, sisa - 1)) % mod;
    return ret;
}
long long pangkat(int base, int ekspo) {
    if (ekspo == 0)
        return 1;
    if (ekspo == 1)
        return base % mod;
    long long temp = pangkat(base, ekspo / 2);
    temp = (temp * temp) % mod;
    if (ekspo % 2 == 1)
        temp = (temp * base) % mod;
    return temp;
}

int main() {
    memset(dp, -1, sizeof dp);
    scanf("%d", &n);
    cin >> s;
    panjang = s.length();
    hasil = hitung(0, n);
    hasil = (hasil * pangkat(pangkat(2, panjang), mod - 2)) % mod;
    printf("%d\n", hasil);
    return 0;
}

Measured memory_bytes: 98432
n,m=map(int,input().split())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    divisors.reverse()
    return divisors

l=make_divisors(m)

for i in l:
    if i*n<=m:
        print(i)
        import sys
        sys.exit()


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

int main(){
    ll N, A, B;
    cin>>N>>A>>B;

    ll num=N/(A+B);
    N-=(A+B)*num;
    ll ans=A*num;
    if(N>=A) ans+=A;
    else ans+=N;

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

Measured memory_bytes: 3568
#![allow(unused_mut, non_snake_case, unused_macros,unused_imports)]
use std::cmp::{max, min, Ordering};
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque};
use std::iter::FromIterator;

//　高速 EOF要
//macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();input_inner!{iter, $($r)*}};($($r:tt)*) => {let mut s = {use std::io::Read;let mut s = String::new();std::io::stdin().read_to_string(&mut s).unwrap();s};let mut iter = s.split_whitespace();input_inner!{iter, $($r)*}};}
//macro_rules! input_inner {($iter:expr) => {};($iter:expr, ) => {};($iter:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($iter, $t);input_inner!{$iter $($r)*}};}
//macro_rules! read_value {($iter:expr, ( $($t:tt),* )) => {( $(read_value!($iter, $t)),* )};($iter:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()};($iter:expr, chars) => {read_value!($iter, String).chars().collect::<Vec<char>>()};($iter:expr, usize1) => {read_value!($iter, usize) - 1};($iter:expr, $t:ty) => {$iter.next().unwrap().parse::<$t>().expect("Parse error")};}
// 低速 EOF不要
macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

/*
 <url:https://beta.atcoder.jp/contests/abc109/tasks/abc109_b>
 問題文============================================================
 =================================================================
 解説=============================================================
 愚直に調べる
 ================================================================
 */
fn main(){
    input!{N:usize,W: [chars; N]}
    let N:usize = N;
    let W:Vec<Vec<char>> = W;
    let mut set:HashSet<String> = HashSet::new();
    for i in 1..N{
        if W[i-1][W[i-1].len()-1] != W[i][0]{
            println!("No");
            return;
        }
    }
    for i in 0..N{ set.insert(W[i].iter().map(|&s| s as char).collect::<String>()); }
    println!("{}",if set.len() != N {"No"} else {"Yes"});
}


Measured memory_bytes: 4352
def main():
    n,ma,mb = map(int,input().split())
    dp = [[[float("inf") for _ in range(401)] for _ in range(401)] for _ in range(n+1)]
    dp[0][0][0]=0

    for i in range(1,n+1):
        a,b,c = map(int,input().split())
        for j in range(401):
            for k in range(401):
                if a<=j and b<=k:
                    dp[i][j][k] = min(dp[i-1][j][k],dp[i-1][j-a][k-b]+c)
                else:
                    dp[i][j][k] = dp[i-1][j][k]
    ans = float("inf")
    for i in range(1,401):
        for j in range(1,401):
            if i*mb == j*ma:
                ans = min(ans,dp[n][i][j])
    if ans==float("inf"):
        print(-1)
    else:
        print(ans)
if __name__ == "__main__":
    main()


Measured memory_bytes: 141404
fun main(args: Array<String>) {
    val (a, b) = readLine()!!.split(" ").map(String::toInt)
    val result = a / (2 * b + 1)

    if ((a % (2 * b + 1)) > 0) {
        println(result + 1)
    } else {
        println(result)
    }
}

Measured memory_bytes: 37640
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>
#include<time.h>
#include<bitset>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<sstream>

//by Skeef79

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define for1(i,n) for(int i = 1;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>
#define REP(a,i,b) for (int i = a;i<b;i++);

using namespace std;

const int INF = 2000000000;
const ll LINF = 2000000000000000000;

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

template <typename T> void input(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a[i].size(); j++)
			cin >> a[i][j];
}

void solve()
{
	string s, t;
	cin >> s >> t;
	cout << t + s;

}

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


#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif

	//freopen("journey.in", "r", stdin);
	//freopen("journey.out", "w", stdout);


	int tst = 1;
	//cin >> tst;
	while (tst--)
		solve();


}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)

int T[100003] = {};

int main()
{
	int N;
	cin >> N;
	REP(i, N)
	{
		int t1, t2;
		cin >> t1 >> t2;
		T[t1]++;
		T[t2+1]--;
	}
	int ans = 0;
	int temp = 1;
	REP(i, 100003)
	{
		temp += T[i];
		if(i<=temp)ans = i;
	}
	cout << ans-1 << endl;
	return 0;
}

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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int MAX = 1 << 19;
int n,nn;
PII dp[MAX];
int t[MAX],laz[MAX],fen[MAX],gd[MAX];
void add(int x){
  for(x++;x; x-=x&-x){
    fen[x]++;
  }
}
int sum(int x){
  int res = 0;
  for(x++;x < MAX; x+= x&-x){
    res += fen[x];
  }
  return res;
}

void touch(int nr){
  if(laz[nr]){
    laz[nr*2] += laz[nr];
    dp[nr*2].FI += laz[nr];
    laz[nr*2 + 1] += laz[nr];
    dp[nr*2 + 1].FI += laz[nr];
    laz[nr] = 0;
  }
}
int get_max(int a){
  debug("get_max", a);
  PII res = {(int)-1e15,0};
  function<void(int,int,int)> rec = [&](int nr,int beg,int end){
    if(end <= a)return;
    if(beg >= a){
      maxi(res, dp[nr]);
      return;
    }
    touch(nr);
    rec(nr * 2, beg, (beg + end) / 2);
    rec(nr * 2 + 1, (beg + end) / 2, end);
  };
  rec(1,0,nn);
  debug(res);
  return res.SE;
}
void dodaj(int a){
  function<void(int,int,int)> rec = [&](int nr,int beg,int end){
    if(end <= a)return;
    if(beg >= a){
      laz[nr] ++;
      dp[nr].FI ++;
      return;
    }
    touch(nr);
    rec(nr * 2, beg, (beg + end) / 2);
    rec(nr * 2 + 1, (beg + end) / 2, end);
    dp[nr] = max(dp[nr*2],dp[nr*2+1]);
  };
  rec(1,0,nn);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n;
  set<int> secik;
  R(i,n){
    cin >> t[i];
    secik.insert(t[i]);
  }
  nn = 1;while(nn <= SZ(secik)) nn *= 2;
  int j = 0;
  map<int,int> scal;
  for(int el:secik){
    scal[el] = j;
    gd[j] = el;
    dp[j + nn] = {-el,j};
    j++;
  }
  for(int i = SZ(secik); i < nn; i++){
    dp[i + nn] = {(int)-1e12, 0ll};
  }
  for(int i = nn-1; i; i--){
    dp[i] = max(dp[i*2],dp[i*2+1]);
    debug(i, dp[i]);
  }
  int res = 0;
  R(i,n){
    int pom = get_max(scal[t[i]]);
    debug(pom,gd[pom] - t[i]);
    res += gd[pom] - t[i];
    debug(sum(pom + 1));
    res += sum(pom + 1);
    dodaj(pom);
    add(pom);
  }
  cout << res << "\n";
}


Measured memory_bytes: 40064
#include<stdio.h>

int main(void)
{
  int a,b,i;
  scanf("%d%d",&a,&b);
  if(a<b)
    for(i=0;i<b;i++)
      printf("%d",a);
  else
    for(i=0;i<a;i++)
      printf("%d",b);
  printf("\n");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl


signed main(){
    int N,M;
    int K[57]={},A[57]={};
    int f;
    cin >> N >> M;
    REP(i,N){
        cin >> K[i];
        REP(j,K[i]){
            cin >> f;
            A[f-1]++;
        }
    }
    int Ans=0;
    REP(i,M){
        if(A[i]==N)Ans++;
    }
    cout << Ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <queue>
#define INF (1 << 30)
using namespace std;
struct Edge {
	//to : Edge(from ??? to)   cap:capacity	cost:cost	rev:reverse
	int to, cap, cost, rev;
	Edge(int to, int cap, int cost, int rev) :to(to), cap(cap), cost(cost), rev(rev) {}
};

#define P vector<vector<Edge>>
vector<int> dist;
bool bellman_ford(P& Graph, int s, int t, vector<int>& parent_v, vector<int>& parent_at) {
	dist = vector<int>(t + 1, INF);
	dist[s] = 0;
	for (int i = 0; i <= t;i++) {
		for (int v = 0; v <= t;v++) {
			if (dist[v] == INF)continue;
			for (int at = 0; at < Graph[v].size();at++) {
				Edge &e = Graph[v][at];
				if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
					//cout << i << " " << v << endl;
					dist[e.to] = dist[v] + e.cost;
					parent_v[e.to] = v;
					parent_at[e.to] = at;
					if (i == t) return false;
				}
			}
		}
	}
	return true;
}

int primal_dual(P& Graph, int s, int t, int F) {
	vector<int> parent_v(t + 1);
	vector<int> parent_at(t + 1);
	int min_cost_flow = 0;
	while (bellman_ford(Graph, s, t, parent_v, parent_at)) {
		if (dist[t] == INF) { return -1; }
		int path_flow = F;
		for (int v = t; v != s; v = parent_v[v]) {
			path_flow = min(path_flow, Graph[parent_v[v]][parent_at[v]].cap);
		}

		F -= path_flow;
		min_cost_flow += path_flow*dist[t];

		if (F == 0) { return min_cost_flow; }
		if (F < 0) { return -1; }

		for (int v = t; v != s; v = parent_v[v]) {
			Edge & e = Graph[parent_v[v]][parent_at[v]];
			e.cap -= path_flow;
			Graph[v][e.rev].cap += path_flow;
		}
	}
	return min_cost_flow;
}
int main() {
	int V, E, F; cin >> V >> E >> F;
	P G(V);
	for (int i = 0; i < E;i++) {
		int u, v, c, d; cin >> u >> v >> c >> d;
		G[u].emplace_back(Edge(v, c, d, G[v].size()));
		G[v].emplace_back(Edge(u, 0, -d, G[u].size() - 1));
	}
	cout << primal_dual(G, 0, V - 1, F) << endl;
	return 0;
}

Measured memory_bytes: 3160
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>



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

using namespace std;
int a,b;

int main(){
  cin >> a >> b;
  cout << max(0,a-b) << endl;
  return 0;
}


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

int main(void) {

	int dn[6];
	int idn[6];
	char way[101];
	int i, ii, a, b;

	for (i = 0; i < 6; i++) {
		scanf("%d", &dn[i]);
		idn[i] = dn[i];
	}

	scanf("%s", way);

	a = strlen(way);
	
	for (i = 0; i < a; i++) {
		for (ii = 0; ii < 6; ii++) {
			idn[ii] = dn[ii];
		}
		b = way[i];
		switch (b) {
  		case 78:   //N
 			dn[0] = idn[1];
			dn[1] = idn[5];
			dn[4] = idn[0];
			dn[5] = idn[4];
			break;
		case 69:   //E
			dn[0] = idn[3];
			dn[2] = idn[0];
			dn[3] = idn[5];
			dn[5] = idn[2];
			break;
		case 87:   //W
			dn[0] = idn[2];
			dn[2] = idn[5];
			dn[3] = idn[0];
			dn[5] = idn[3];
			break;
		case 83:   //S
			dn[0] = idn[4];
			dn[1] = idn[0];
			dn[4] = idn[5];
			dn[5] = idn[1];
			break;
		}
	}
	printf("%d\n", dn[0]);
	scanf("%d", &b);
	return 0;

}

Measured memory_bytes: 596
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>

using namespace std;
int main() {
    int A;
    cin>>A;

    cout<<3*A*A<<endl;



}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "YES" : "NO") << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))

vector<string> split(string,string);

//template<typename T>
//void swap(T*,T*);
//char ToUpper (char cX) { return toupper(cX); }

int main()
{
    int X,A,B;
    cin >> X >> A >> B;
    if(A >= B)
    {
        cout << "delicious";
    }
    else if(X - (B - A) >= 0)
    {
        cout << "safe";
    }else
    {
        cout << "dangerous";
    }
}


Measured memory_bytes: 256
def counting_sort(a, b, k):
	c = [0] * (k + 1)
	for i in range(len(a)):
		c[a[i]] += 1

	for i in range(1, k+1):
		c[i] = c[i] + c[i - 1]

	for i in range(len(a) - 1, -1, -1):
		num = a[i]
		b[c[num] - 1] = num
		c[num] -= 1

n = int(input())
a = list(map(int, input().split()))
b = [0] * n
k = max(a)
counting_sort(a, b, k)
print(b[0], end='')
for i in range(1, n):
	print(' ' +  str(b[i]), end='')
print()



Measured memory_bytes: 224376