akhauriyash/Code-Regression huggingface dataset:
import bisect,sys

input=sys.stdin.readline

N,Q=map(int,input().split())
que=[(N,0)]
for i in range(Q):
    q=int(input())
    que.append((q,i+1))

que.sort(reverse=True)

ext=[]
while que:
    q,id=que.pop()
    if not ext:
        ext.append((q,id))
    else:
        if ext[-1][1]<id:
            if ext[-1][0]==q:
                ext.pop()
            ext.append((q,id))

Q=len(ext)
data=[1]*Q
data[0]=ext[0][0]
edge=[[] for i in range(Q)]
nowext=[ext[0][0]]
for i in range(1,Q):
    q=ext[i][0]
    rest=q
    while True:
        id=bisect.bisect_right(nowext,rest)
        if id==0:
            break
        else:
            edge[id-1].append((i,rest//nowext[id-1]))
            rest%=nowext[id-1]
    nowext.append(ext[i][0])
    data[i]=rest

#print(edge)

dp=[1]*Q
for i in range(Q-2,-1,-1):
    temp=0
    for nv,c in edge[i]:
        temp+=dp[nv]*c
    dp[i]=temp

#print(dp)
#print(data)

minus=[0]*(ext[0][0]+1)
for i in range(Q):
    minus[data[i]]+=dp[i]

base=sum(dp)
for i in range(1,N+1):
    if i-1<=ext[0][0]:
        base-=minus[i-1]
    print(base)


Measured memory_bytes: 157748
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
constexpr int INF = (numeric_limits<int>::max() == INT_MAX ? (int)1e9 : (long long)1e18);
constexpr long double eps = 1e-6;
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; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;using pii = pair<int,int>;using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
void fast_io(){ios::sync_with_stdio(false); cin.tie(nullptr);}
signed main(){
    int N; cin >> N;
    int crt = 0, cx = 0, cy = 0;
    for(int i = 0; i < N; ++i){
        int t,x,y; cin >> t >> x >> y;
        int difx = abs(x - cx); int dify = abs(y - cy);
        int dift = abs(t - crt);
        if( dift < difx + dify)return puts("No") * 0;
        if((dift - difx - dify) % 2) return puts("No") *0;
        cx = x; cy = y; crt = t;
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

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

using namespace std;
//        tmp = stoi(S.substr(i,3));
int main(){
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());
    ll N,K,res;

    string S;
    cin >> N >> K;

    cin >> S;

    ll cnt = 0;
    vector <ll> L0(N);
    vector <ll> L1(N);
    ll ren0 = 0;
    ll ren1 = 0;
    
    ll ima = 1;
    ll kai = 0;

    REP(i,N)
    {
        if(S[i] == '0')
        {
            ren0++;
            if(ima == 1)
            {
                L1[kai] = ren1;
                ren1 = 0;
                ima = 0;
            }
        }
        else if(S[i] == '1')
        {
            ren1++;
            if(ima == 0)
            {
                L0[kai] = ren0;
                ren0 = 0;
                ima = 1;
                kai++;
            }
        }
    }
    //末尾の処理
    if(ren0 != 0)
    {
        L0[kai] = ren0;
        kai++;
        L1[kai] = 0;
    }
    else
    {
        L1[kai] = ren1;
        //L0[kai]は値を入れなくて良い
    }
    //K を使う
    ll iMax;

    //1つ目だけ作る
    res = 0;
    REP(i,K)
    {
        res += L1[i] + L0[i];
    }
    res += L1[K];

    iMax = res;

    for(int i = 0; i < kai - K; i++)
    {   
        res -= L1[i];
        res -= L0[i];

        res += L0[i + K];
        res += L1[i + K + 1];
        //res += accumulate(L1.begin() + i, L1.begin() + i + K, 0LL);
        //res += accumulate(L0.begin() + i, L0.begin() + i + K - 1, 0LL);
        iMax = max(iMax,res);
    }

    cout << iMax << endl;

    return 0;
}

Measured memory_bytes: 2048
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
typedef long long ll;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int keta(ll N) {
    int ret = 0;
    while(N > 0) {
        N /= 10;
        ret++;
    }
    return ret;
}

int main() {
    ll N;
    cin >> N;
    int res = 100;
    for(ll i = 1; i * i <= N; i++) {
        if(N % i != 0)
            continue;
        res = min(res, max(keta(i), keta(N / i)));
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int s, i=0, j, k;
    scanf("%d", &s);
    if (s % 10 != 0){
        i++;
    }
    k = (s - s%10)/10;
    if (k % 10 != 0){
        i++;
    }
    j = (k - k%10)/10;
    if (j == 1){
        i++;
    }
    printf("%d\n", i);
    return 0;
}

Measured memory_bytes: 128
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
typedef vector<vector<ll>> matrix;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll n,x,t;
    cin>>n>>x>>t;
    cout<<((n+x-1)/x)*t;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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



#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)

using namespace std;

template <class T>
using vec = std::vector<T>;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL<<60;

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


string S;



int main()
{
    cin>>S;
    int len=S.size();
    int ans=len;
    rep(i,len-1){
        if(S[i]!=S[i+1]){
            chmin(ans,max(i+1,len-i-1));
        }
    }

    cout<<ans<<endl;
    

    return 0;

}




Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

map<P,i64> dp;

i64 n;

i64 MOD = 1e9 + 7;

i64 rec(i64 s,i64 x)
{
    if(dp.count({s,x})) return dp[{s,x}];

    i64 result = 0;

    (result += rec(s / 2,x / 2)) %= MOD;
    if(s - 1 >= 0 && x - 1 >= 0)
        (result += rec((s - 1) / 2, (x - 1) / 2)) %= MOD;
    if(s - 2 >= 0)
        (result += rec((s - 2) / 2, x / 2)) %= MOD;

    return dp[{s,x}] = result;
}

int main()
{
    cin >> n;
    dp[{0,0}] = 1;
    cout << rec(n,n) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int n,x,num=0;
while(1){
  cin>>n>>x;
  if(n+x==0)break;
  for(int i=1;i<=n-2;i++){
    for(int j=i+1;j<=n-1;j++){
      for(int k=j+1;k<=n;k++){
        if(i+j+k==x)num+=1;
      }
    }
  }
  cout<<num<<endl;
  num=0;
}
  return 0;
}

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

int main()
{
    int n,i;
    while(scanf("%d",&n)!=EOF)
    {
        long long int sum=1;
        for(i=1;i<=n;i++)
        {
            sum=(i*sum)%1000000007;
        }
            printf("%lld\n",sum);
    }
    return 0;
}


Measured memory_bytes: 128
while(True):
    try:
        a,c = input().split("=")
        a,b = a.split("+")
        for i in range(10):
            if i==0 and ((len(a)>1 and a[0]=="X") or (len(b)>1 and b[0]=="X") or (len(c)>1 and c[0]=="X")):
                continue
            if int(a.replace("X",str(i)))+int(b.replace("X",str(i))) == int(c.replace("X",str(i))):
                print(i)
                break
        else:
            print("NA")
    except:
        break


Measured memory_bytes: 5608
#include <iostream>
#include <cmath>

using namespace std;

int main(){
	int a,b;
	cin >> a >> b;
	for(double i=1.0;i<1250.0;i+=1.0){
		if(floor(0.08*i)==a&&floor(0.1*i)==b){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<(x)<<endl
#define ps(x) cout<<(x);
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define fi first
#define se second
ll a[27],b[27],c,d,n,m,x,y,z,h,w,sum,mi,ma,ans,s,t,l,r,res,tmp,itr,p,q;
bool flag;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int dx8[8]={1,1,0,-1,-1,-1,0,1},dy8[8]={0,1,1,1,0,-1,-1,-1};
char cha;
string st;
typedef map<ll, ll> imap;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<pair<ll,ll> > VP;


int main(void){
    string ta;
    cin>>st>>ta;
    rep(i,27){a[i]=-1;b[i]=-1;}
    rep(i,st.size()){
        if(st[i]!=ta[i]){
            if(a[st[i]-'a']!=-1 && a[st[i]-'a']!=ta[i]-'a'){
                p("No");
                return 0;
            }
            a[st[i]-'a']=ta[i]-'a';
            d(ta[i]-'a')
            if(b[ta[i]-'a']!=-1 && b[ta[i]-'a']!=st[i]-'a'){
                p("No");
                return 0;
            }
            b[ta[i]-'a']=st[i]-'a';
        }
        else{
            a[st[i]-'a']=ta[i]-'a';
            b[ta[i]-'a']=st[i]-'a';
        }
    }
    p("Yes");
    return 0;
}


Measured memory_bytes: 904
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <memory.h>
#include <algorithm>

using namespace std;
const int maxn = 200000 + 50;
int N, X[maxn], nu[maxn];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> X[i];
		nu[i] = X[i];
	}
	sort(nu, nu + N);

	int mid = N / 2;
	int lm = nu[mid - 1], rm = nu[mid];
	for (int i = 0; i < N; i++) {
		if (X[i] <= lm)
			cout << rm << endl;
		else
			cout << lm << endl;
	}
	return 0;
}

Measured memory_bytes: 3712
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var n = next();
  var l = nexts(n).sort((a,b)=>a-b);
  var ans = 0;
  for(var i = 0; i < n; i++)
  for(var j = i+1; j < n; j++)
  for(var k = j+1; k < n; k++){
    if(l[i] === l[j] || l[j] === l[k])continue;
    if(l[i] + l[j] > l[k])ans++;
  }
  return ans;
}

Measured memory_bytes: 32428
#include<iostream>

using namespace std;

int main(){
  long long n,sum = 0;
  cin >> n;
  for(int i = 0;i < n;i++){
    long long a;
    cin >> a;
    if(a%2 == 1)
      sum++;
  }
  if(sum%2 == 1){
    cout << "NO"<< endl;
  }
  else
    cout << "YES" << endl;
}


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

int main(){
  int N;cin>>N;
  vector<long long>L(N);
  int ans;
  ans= 0;
  for (int i=0;i<=N;i++)cin >>L[i];
  sort(L.begin(),L.end());
  for (int i=N-1;i>=0;i--){
    for (int j=i-1;j>=0;j--){
      int k = upper_bound(L.begin(),L.end(),L[i]-L[j])-L.begin();
      ans+= max(j-k,0);
    }
  }
  cout<<ans<<endl;

}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

#define INF 1e9
#define LLINF 1e18
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;


int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    cout << a.at(a.size() - 1) - a.at(0) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
typedef complex<double> P;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 30;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };
  
bool collision_detection( double x1, double y1, double x2, double y2, double x3, double y3, double xp, double yp ) {
    x2 -= x1;
    x3 -= x1;
    xp -= x1;
    y2 -= y1;
    y3 -= y1;
    yp -= y1;
    double t_size = fabs( ( x2 * y3 - y2 * x3 ) / 2 );
    t_size -= fabs( ( x2 * yp -  y2 * xp ) / 2 );
    t_size -= fabs( ( x3 * yp -  y3 * xp ) / 2 );
    x2 -= xp;
    x3 -= xp;
    y2 -= yp;
    y3 -= yp;
    yp = xp = 0;
    t_size -= fabs( ( x2 * y3 - y2 * x3 ) / 2 );
    return fabs( t_size ) < 1e-10;
}
  
int main() {
    double x[ 4 ], y[ 4 ];
    while ( ~scanf( "%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &x[ 0 ], &y[ 0 ], &x[ 1 ], &y[ 1 ], &x[ 2 ], &y[ 2 ], &x[ 3 ], &y[ 3 ] ) ) {
        bool print_yes = true;
        for ( int i = 0; i < 4; i++ ) {
            if ( collision_detection( x[ ( i + 1 ) % 4 ], y[ ( i + 1 ) % 4 ], x[ ( i + 2 ) % 4 ], y[ ( i + 2 ) % 4 ], x[ ( i + 3 ) % 4 ], y[ ( i + 3 ) % 4 ], x[ i ], y[ i ] ) ) {
                print_yes = false;
                break;
            }
        }
        printf( "%s\n", print_yes ? "YES" : "NO" );
    }
    return 0;
}

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


void solve(int A, int B, int H, int M){
    long double rad = M_PI * 2.0 * ((long double)H/12.0 + ((long double)M/60.0)/12.0 - (long double)M/60.0);
    //cout << rad << endl;
    long double rsq = (long double)(A * A + B * B) - (long double)(2.0 * A * B) * cosl(rad);
    //cout << rsq << endl;
    cout << fixed << setprecision(20) << sqrtl(rsq) << endl;
}

int main(){
    int A;
    scanf("%d",&A);
    int B;
    scanf("%d",&B);
    int H;
    scanf("%d",&H);
    int M;
    scanf("%d",&M);
    solve(A, B, H, M);
    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    vector< pair<ll,int> > a(n);
    rep(i,n) {cin >> a[i].first; a[i].second = i;}
    sort(a.begin(),a.end(),greater<pair<ll,int>>());

    vector<vector<ll>> dp(n+1,vector<ll>(n+1));

    ll ans = 0;
    rep(l,n+1) {
        rep(m,n+1){
            if(l+m == n) {ans = max(ans, dp[l][m]); break;} // ansの更新
            ll activeness = a[l+m].first;
            int position = a[l+m].second;
            dp[l+1][m] = max(dp[l+1][m],dp[l][m] + activeness * abs(l-position));
            dp[l][m+1] = max(dp[l][m+1],dp[l][m] + activeness * abs(n-m-1-position));
        }
    }

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

Measured memory_bytes: 34588
from collections import defaultdict

N, *A = map(int, open(0).read().split())

ctr1 = defaultdict(int)
ctr2 = defaultdict(int)
for i in range(N):
    ctr2[i + A[i]] += 1
    if i - A[i] > 0:
        ctr1[i - A[i]] += 1

ans = 0
for v in ctr1:
    ans += ctr1[v] * ctr2[v]
print(ans)


Measured memory_bytes: 137944
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    string S,T;
    int cnt=0;
    cin>>S>>T;
    for(int i=0;i<3;i++)
    {
         if(S[i]==T[i])
            {
                cnt++;
            }
    }
    cout<<cnt<<endl;


  return 0;
}


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

using namespace std;
using i64 = int64_t;

const i64 MOD = 1000000007;

int main(){
  i64 N, K;
  cin >> N >> K;
  i64 NN = 1;
  while(NN * NN <= N)NN++;
  NN--;
  deque<i64> D;
  D.push_back(1);
  if((N / NN) != NN)D.push_front(N / NN - N / (NN + 1));
  while(NN >= 2){
    NN--;
    D.push_back(1);
    D.push_front(N / NN - N / (NN + 1));
  }
  deque<i64> C = D;
  K--;
//  for(auto&& x:D){
//	cerr << x << " ";
//  }cerr << endl;
  while(K--){
    reverse(D.begin(), D.end());
    D[0] %= MOD;
    for(int i=0;i<(int)D.size()-1;i++){
      D[i+1] += D[i];
      D[i+1] %= MOD;
    }
    for(int i=0;i<(int)D.size();i++){
      D[i] *= C[i];
      D[i] %= MOD;
    }
  }
  i64 ans = 0;
  for(auto&& x:D){
    ans += x;
    ans %= MOD;
  }
    cout << ans << endl;
}


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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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


int main() {
    cout<<fixed<<setprecision(10);

    ll x,y; cin>>x>>y;

    rep(i,x+1){
        ll j = x - i;
        if(i*2+j*4==y){
            puts("Yes");
            return 0;
        }
    }

    puts("No");

    return 0;

}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  ll M;
  cin >> M;
  ll ketasum = 0;
  ll keta = 0;
  for(int i = 0; i < M; i++){
    ll d, c;
    cin >> d>> c;
    ketasum += d * c;
    keta += c;
  }
  cout << ((ketasum + 8)/ 9 - 1 + keta - 1) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define clr1(arr) memset(arr,-1,sizeof(arr));
#define clr0(arr) memset(arr,0,sizeof(arr));
#define pi pair<int,int>
#define pii pair<int,pi>
#define aint(v) v.begin(),v.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define ump gp_hash_table<int,int,custom_hash>
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
/*int **dp,in main function,int row,col;dp=new int*[n];rep(i,n)dp[i]=new int[m]*/
//**** Maths Section*******/
int power(int x,int y);
bool isPrime(int n);
int modInv(int a,int b);
int gcdExtended(int a,int b,int *x,int* y);
int mpower(int a,int b,int p);
/***************************/
int32_t main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  fastio
  int n,r;
  cin>>n>>r;
  int ans;
  if(n>=10)ans=r;
  else ans=r+100*(10-n);
  cout<<ans<<endl;
  return 0;
}

int modInv(int a, int m)
{
int x, y;
int g = gcdExtended(a, m, &x, &y);
int res = (x%m + m) % m;
return res;
}

int gcdExtended(int a, int b, int *x, int *y)
{
if (a == 0){
    *x = 0, *y = 1;
    return b;
  }
  int x1, y1;
  int gcd = gcdExtended(b%a, a, &x1, &y1);
  *x = y1 - (b/a) * x1;
  *y = x1;
  return gcd;
}

int mpower(int x, int y, int p)
{
int res = 1;
x = x % p;
while(y > 0){
    if(y & 1) res = (res*x) % p;
      y = y>>1;
      x = (x*x) % p;
    }
    return res;
}
int power(int x, int y)
{
int res = 1;
while (y > 0){
    if (y & 1) res = res*x;
      y = y>>1;
      x = x*x;
    }
    return res;
}

bool isPrime(int n)
{
if (n <= 1)  return false;
  if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
      int p=sqrt(n);
      for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
          return false;
      return true;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    int s[m],c[m];
    for(int i=0;i<m;i++)scanf("%d %d",&s[i],&c[i]);
    int r[n]={0};
    r[0]=1;
    int e=0;
    if(m==0&&n==1){
        printf("%d",e);
        return 0;
    }
    for(int i=0;i<m;i++){
        if(s[i]==1&&c[i]==0&&n!=1){
            e=-1;
            printf("%d",e);
            return 0;
        }
        if(r[s[i]-1]==0){
            r[s[i]-1]=c[i];
        }else if(s[i]==1&&r[s[i]-1]==1){
            r[s[i]-1]=c[i];
        }else if(r[s[i]-1]==c[i]){
            r[s[i]-1]=c[i];
        }else{
            e=-1;
            printf("%d",e);
            return 0;
        }
    }
    for(int i=0;i<n;i++){
        e=(e*10)+r[i];
    }
    printf("%d",e);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>

#ifdef _MSC_VER
#include <Windows.h>
#else
#include <unistd.h>
#endif

using namespace std;

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

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

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD=(LL)1e9+7;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

#define INF 1LL << 50

LL x[100004],y[100004];
int main(){
    int n,m;
    cin>>n>>m;
    REP(i,n){
        cin>>x[i];
    }
    REP(i,m){
        cin>>y[i];
    }
    LL sumx=0,sumy=0;
    REP(i,n){
        sumx+=(i*x[i]-(n-1-i)*x[i]);
        sumx%=MOD;
    }
    REP(i,m){
        sumy+=(i*y[i]-(m-1-i)*y[i]);
        sumy%=MOD;
    }
    cout<<sumx*sumy%MOD<<endl;
    //sum(x[i1]-x[i2])*sum(y[j1]-y[j2])
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  long long n,a[100000],b[100000],ans=0,cnt;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i] >> b[i];
  }
  for(int i=n-1; i>=0; i--) {
    a[i]+=ans;
    if(a[i]%b[i]!=0) {
      ans+=((a[i]/b[i])+1)*b[i]-a[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String[] line = s.split("/", 4);
        int[] num = new int[3];
        for(int i=0; i<3; i++){
        	num[i] = Integer.parseInt(line[i]); 
        }
		if(num[0] < 2019) System.out.println("Heisei");
        else if(num[1] < 5) System.out.println("Heisei");
        else System.out.println("TBD");
	}
}

Measured memory_bytes: 22608
import heapq as hq
N = int(input())
edges = [[] for _ in range(N)]
for _ in range(N-1):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    edges[a].append((b, c))
    edges[b].append((a, c))
Q, K = map(int,input().split())
INF = float("inf")
d = [INF]*N
K -= 1
d[K] = 0
q = [(0,K)]
while q:
    dist, i = hq.heappop(q)
    if d[i] < dist:
        continue
    for j, w in edges[i]:
        if d[j] > d[i]+w:
            d[j] = d[i]+w
            hq.heappush(q, (d[j], j))
for _ in range(Q):
    x, y = map(int,input().split())
    x -= 1
    y -= 1
    print(d[x]+d[y])

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

int main(){
	int N; cin >> N;
	
	map<string, vector<pair<int,int>>> m;
	for(int i = 0; i < N; i++){
		string S; int P;
		cin >> S >> P;

		pair<int,int> p = make_pair(P, i + 1);
		m[S].push_back(p);
	}

	 for(auto itr = m.begin(); itr != m.end(); itr++){
		sort((*itr).second.begin(), (*itr).second.end(),greater<pair<int,int> >());
		
		for(auto x:(*itr).second){
			cout << x.second << endl;
		}
	 }
	return 0;
}

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

const int N = 3e5 + 10;

int n;
int times[N], cnt[N], times2[N];

int get(int x) {
  return times[x] + (times2[x - 1]) / x;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    ++cnt[x];
  }
  for (int i = 0; i <= n; ++i) {
    if (cnt[i] > 0) {
      ++times[cnt[i]];
      times2[cnt[i]] += cnt[i];
    }
  }
  for (int i = n; i >= 0; --i)
    times[i] += times[i + 1];
  for (int i = 1; i <= n; ++i)
    times2[i] += times2[i - 1];
  for (int k = 1; k <= n; ++k) {
    int low = 0, high = n + 1;
    while (low + 1 < high) {
      int mid = (low + high) / 2;
      if (get(mid) >= k)
        low = mid;
      else
        high = mid;
    }
    printf("%d\n", low);
  }
  return 0;
}

Measured memory_bytes: 4352
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

  if (A + B == 0) {
    cout << 0 << endl;
    return 0;
  }

  int64_t q = N / (A + B), r = N % (A + B);
  cout << q * A + min(r, A) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define forn(i, a, b) for (int i = a; i < b; ++i)
#define SZ(x) int(x.size())
#define pb push_back
#define F first
#define S second
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}

const int N = 21;
ll n, m, a[N], b, c;

int main() {
#ifdef LOCAL
  freopen("d.txt", "r", stdin);
// freopen("main.txt", "w", stdout);
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
  ios::sync_with_stdio(0);
  cin.tie(0);
#define endl '\n'
#define dbg(...) 18
#endif
  ll cur, ans = 0;
  cin >> n >> m >> c;
  for (int i = 0; i < m; i++) cin >> a[i];
  while (n--) {
    cur = 0;
    for (int i = 0; i < m; i++) {
      cin >> b;
      cur += b * a[i];
    }
    cur += c;
    ans += (cur > 0);
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
	ios::sync_with_stdio(false);
	int x;
	while(cin>>x){
		if(x==1){
			cout<<"Hello World"<<endl;
		}else{
			int a,b;
			cin>>a>>b;
			cout<<a+b<<endl;
		}
	}
	
	return 0;
}

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

using namespace std;

int main(){
	
	int n;
	cin>>n;
	int dp[n][3];
	int a[n],b[n],c[n];
	for (int i=0;i<n;i++){
		cin>>a[i]>>b[i]>>c[i];
	}
	dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
	for(int i=1; i<n; i++) {
      	dp[i][0] = a[i] + max(dp[i-1][1],dp[i-1][2]);
      	dp[i][1] = b[i] + max(dp[i-1][0],dp[i-1][2]);
      	dp[i][2] = c[i] + max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
	
}

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

int main() {
  int N;
  string S;
  cin>>N>>S;
  int count=0;
  int max=0;
  for(int i=1; i<=N-1; i++){
    map<char, int> zenhan;
    map<char, int> kouhan;
    string X=S.substr(0, i);
    string Y=S.substr(i, N-i);
    for(int j=0; j<i; j++){
      zenhan[X.at(j)]=1;
    } //X
    for(int j=0; j<N-i; j++){
      if(zenhan.count(Y.at(j)) && !kouhan.count(Y.at(j))){
        count++;
        kouhan[Y.at(j)]=1;
      }
    } //Y
    if(count>max) max=count;
    count=0;
  }
  cout<<max<<endl;
}


Measured memory_bytes: 256
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;



int main() {
	int n,z,w; cin>>n>>z>>w;
	vector<int> a(n);
	rep(i,0,n) cin>>a[i];
	if(n==1) cout<<abs(a[0]-w)<<endl;
	else cout<<max(abs(a[n-1]-w),abs(a[n-1]-a[n-2]));
	return 0;
}


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

using namespace std;

int main(){
  int A,B,C;cin>>A>>B>>C;
  set<int> s;
  s.insert(A);
  s.insert(B);
  s.insert(C);
  if(s.size()==2)cout<< "Yes"  << "\n";
  else cout<< "No"  << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    while(cin >> n){
        int c = 0;
        f1(n){
            int add;
            cin >> add;
            if(add!=i){
                c++;
            }
        }
        if(c<=2){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
 
}

Measured memory_bytes: 256
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

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

if A <= 0 and B >= 0:
    print("Zero")
elif A > 0:
    print("Positive")
else:
    print("Positive") if (B - A + 1) % 2 == 0 else print("Negative")


Measured memory_bytes: 12444
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		sc.close();

		int[] list = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
		System.out.println(list[K-1]);
	}
}


Measured memory_bytes: 23764
#include <iostream>

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    double s = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        s += 1.0 / a;
    }

    cout << 1 / s << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
int main()
{
    int h,a,t;
    while(cin>>h>>a)
    {
        t=h/a;
        if(h%a!=0)
            t++;
        cout<<t<<endl;
    }
    return 0;
}


Measured memory_bytes: 888
import sys


lines = 1
inp = list()

for _ in range(lines):
    inp.append(sys.stdin.readline().strip())

inp = inp[0].split()
n = int(inp[0])
a = int(inp[1])
b = int(inp[2])

result = 0

for i in range(n+1):
    s = sum([int(j) for j in str(i)])
    if a <= s <= b:
        result += i

print(result)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (1<<29)
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);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/gcd(a,b)*b;
}
bool prime(int p){
	for(int i=2;i<=sqrt(p);i++){
		if(!p%i)return false;
	}
	return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b==1)return a%MOD;
    if(b%2)return modpow(a,b-1)*a%MOD;
    else return modpow(a,b/2)*modpow(a,b/2)%MOD;
}
int comb(int a,int b){
    if(b==0||a==b)return 1;
    if(b==1)return a%MOD;
    return (comb(a-1,b-1)+comb(a-1,b))%MOD;
}
// Library End !
int n,c,k,t[114514],h=0,i=0,ans=0;
signed main(){
    cin>>n>>c>>k;
    rep(i,n)cin>>t[i];
    sort(t,t+n);
    while(i<n){
        while(i-h+1<=c&&t[i]<=t[h]+k&&i<n)i++;
        h=i;
        ans++;
        if(i==n-1){cout<<ans+1<<endl;return 0;}
    }
    cout<<ans<<endl;
	return 0;
}

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

using flow_type = int;

struct dinic {
    struct edge {
        int s, d;
        flow_type c, f;
        int r;
    };
    int n, s, t;
    std::vector<std::vector<edge>> g;
    std::vector<int> level, prog, que;
    std::vector<std::pair<std::pair<int, int>, flow_type>> edges;

    dinic(int n_ = 0) : n(n_) {}

    // Compute the maximum-flow from `s_` to `t_` by Dinic's algorithm.
    flow_type maximum_flow(int s_, int t_) {
        s = s_;
        t = t_;
        make_graph();
        que.resize(n);
        flow_type res = 0;
        while (levelize()) {
            prog.assign(n, 0);
            res += augment(s, std::numeric_limits<flow_type>::max());
        }
        return res;
    }

    // Add an edge from `u` to `v` with capacity `c`. Note that the edge will be
    // added to `g` when `make_graph` was called instead of just after calling
    // this function.
    void add_edge(int u, int v, flow_type c) {
        if (u != v && c != 0) {
            edges.emplace_back(std::make_pair(u, v), c);
        }
    }

    void make_graph() {
        g.assign(n, {});
        std::sort(edges.begin(), edges.end());
        for (auto it = edges.begin(); it != edges.end();) {
            flow_type c = 0;
            auto uv = it->first;
            while (it != edges.end() && it->first == uv) {
                c += it->second;
                ++it;
            }
            int u = uv.first, v = uv.second;
            g[u].push_back({u, v, c, 0, (int)g[v].size()});
            g[v].push_back({v, u, c, c, (int)g[u].size() - 1});            
        }
    }

    bool levelize() {
        int fst = 0, lst = 0;
        que[lst++] = s;
        level.assign(n, -1);
        level[s] = 0;
        while (fst != lst) {
            int v = que[fst++];
            if (v == t) break;
            for (auto &e : g[v]) {
                if (level[e.d] == -1 && residue(e) != 0) {
                    level[e.d] = level[v] + 1;
                    que[lst++] = e.d;
                }
            }
        }
        return level[t] != -1;
    }

    flow_type augment(int v, flow_type lim) {
        flow_type res = 0;
        if (v == t) return lim;
        for (int &i = prog[v]; i < (int)g[v].size(); ++i) {
            if (lim == 0) break;
            auto &e = g[v][i];
            if (level[v] < level[e.d] && residue(e) != 0) {
                flow_type aug = augment(e.d, std::min(lim, residue(e)));
                if (aug == 0) continue;
                e.f += aug;
                reverse(e).f -= aug;
                res += aug;
                lim -= aug;
            }
        }
        return res;
    }

    flow_type residue(const edge &e) { return e.c - e.f; }

    edge &reverse(const edge &e) { return g[e.d][e.r]; }
};

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

int main() {
    int N, M;
    while (cin >> N >> M) {
        dinic g(N);
        for(int i = 0; i < M; ++i){
            int a, b, c;
            cin >> a >> b >> c;
            g.add_edge(a, b, c);
        }
        dinic d(g);
        cout << d.maximum_flow(0, N-1) << endl;
    }
}

Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string num;
map<int,int> mp;
int main(){
    mp[0]=1;
    ll ans=0,cnt=0,p=1,x;
    cin>>x>>x>>num;
    if(x==2||x==5){
        for(int i=0;i<num.length();i++){
            if((num[i]-'0')%x==0) ans+=(ll)i+1;
        }
    }
    else{
    for(int i=num.length()-1;i>=0;i--){
        cnt=(cnt+(ll)(num[i]-'0')*p)%x;
        ans+=mp[cnt],mp[cnt]++;
        p=p*10%x;
    }
    }
    printf("%lld",ans);
}


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

int main() {
  string s;
  cin >> s;
  string hi = "";
  for(int i=0;i<5;i++){
    hi += "hi";
    if(hi == s){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl; 
    return 0;
      
}
        
      

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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void solve() {
		int n, k;
		cin >> n >> k;
		vector<bool> ng(10, 0);
		for(int i=0; i<k; i++){
			int d;
			cin >> d;
			ng[d] = true;
		}
		while(1){
			int _n = n;
			bool ok = true;
			while(_n){
				if(ng[_n%10]){
					ok = false;
					break;
				}
				_n /= 10;
			}
			if(ok){
				cout << n << "\n";
				return;
			}
			n++;
		}
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int C[4] = {0};
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    switch (S[0]) {
      case 'A':
        C[0]++; break;
      case 'W':
        C[1]++; break;
      case 'T':
        C[2]++; break;
      case 'R':
        C[3]++; break;
    }
  }
  cout << "AC x " << C[0] << endl;
  cout << "WA x " << C[1] << endl;
  cout << "TLE x " << C[2] << endl;
  cout << "RE x " << C[3] << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e5;
const long inf=1e15;
int n,m;int s,t;
long d[2*size];
vector<pair<int,long>> g[2*size];
void dijkstra(){// O(NlogN+M)
	priority_queue<pair<long,int>> pq;
	rep(i,0,2*n){
		d[i] = inf;
		pq.push({-d[i] , i});
	}
	d[s] = 0; pq.push({0, s});
	d[t+n] = 0; pq.push({0, t+n});
	int v; long temp;
	while(!pq.empty()){
		v = pq.top().second;
		pq.pop();
        int u;
		for(pair<int,long> p:g[v]){
            u = p.first;
			temp = d[v] + p.second;
			if(d[u] > temp){
				d[u] = temp;
				pq.push({-d[u], u});
			}
		}
	}return;
}
int main(){
	cin>>n>>m; cin>>s>>t; s--; t--;
	int u,v; long a,b;
	rep(i,0,m){
		cin>>v>>u>>a>>b; v--; u--;
		g[v].push_back({u, a});
		g[u].push_back({v, a});
		g[v+n].push_back({u+n, b});
		g[u+n].push_back({v+n, b});
	}
	dijkstra();
	long ans[n+1]; ans[n] = inf;
	for(int i = n-1; i >= 0; i--){
		ans[i] = min(ans[i+1], d[i] + d[i+n]);
	}rep(i,0,n){
		cout<<inf - ans[i]<<endl;
	}
}

Measured memory_bytes: 22768
N,M,*xyzs=$<.read.split.map(&:to_i)
class UnionFind attr_reader :parents
  def initialize(n)
    @parents = [*0..n]
  end

  def find(x)
    @parents[x] == x ? x : (@parents[x] = find(@parents[x]))
  end

  def union(x,y)
    x = find(x)
    y = find(y)
    @parents[y] = x
  end
end

t = UnionFind.new(N)

xyzs.each_slice(3).each do |x,y,z|
  t.union(x,y)
end

N.times {|i| t.find(i+1)}
p t.parents.uniq.count - 1


Measured memory_bytes: 32052
#include <iostream>
#include <vector>
#include <string>

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

using namespace std;

const char S[] = {'7', '5', '3'};
bool is753(const string& s)
{
  ll seven = 0, five = 0, three = 0;
  rep(i, s.length())
  {
    seven += (s[i] == '7');
    five += (s[i] == '5');
    three += (s[i] == '3');
  }
  bool ret = (seven > 0 && five > 0 && three > 0);
  ret = ret && (s.length() - 1 == (seven + five + three));
  return ret;
}
ll f(string sx, ll n)
{
  ll ix = stoll(sx);
  if(ix > n) return 0;
  ll ret = is753(sx);
  rep(i, 3)
    ret += f(sx + S[i], n);
  return ret;
}

int main()
{
  ll n;
  cin >> n;
  ll ans = f("0", n);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#![allow(dead_code, unused_imports, deprecated)]
use std::cmp;
use std::collections::*;
use maplit::*;
use num::Integer;
use proconio::input;
use proconio::marker::*;
use proconio::fastout;

const INF : usize = 1000000007;

#[fastout]
fn main() {
  input! {
    n: usize, k: usize,
  };

  let m = 300_000;
  let mut seg = SegmentTree::<usize>::new(m + 1, cmp::max, 0);

  let mut res = 0;
  for _ in 0..n {
    input! {
      a: usize,
    };

    let l = cmp::max(k, a) - k;
    let r = cmp::min(m, a + k);
    let v = seg.query(l, r + 1) + 1;
    res = cmp::max(res, v);
    seg.update(a, v);
  }
  
  println!("{}", res);
}

struct SegmentTree<T: Default = usize>
  where T : {
  node: Vec<T>,
  offset: usize,
  op: fn(T, T) -> T,
  id: T,
}

impl<T> SegmentTree<T>
  where T : std::default::Default
    + std::clone::Clone
    + Copy {
  fn new(n: usize, opr: fn(T, T) -> T, e: T) -> Self {
    let mut ofs = 1usize;
    while ofs < n {
      ofs <<= 1;
    }

    Self {
      id: e,
      node: vec![e; (ofs << 1) - 1],
      offset: ofs - 1,
      op: opr,
    }
  }

  fn update(&mut self, i: usize, x: T) {
    let mut cur = i + self.offset;
    assert!(cur < self.node.len());

    self.node[cur] = x;
    while cur > 0 {
      cur = (cur - 1) >> 1;
      self.node[cur] = (self.op)(self.node[(cur << 1) + 1], self.node[(cur << 1) + 2]);
    }
  }
  
  fn query(&self, l: usize, r: usize) -> T {
    let mut l = l + self.offset;
    let mut r = r + self.offset;
    assert!(l >= self.offset && r < self.node.len());

    let mut res = self.id;
    while l < r {
      if l & 1 == 0 {
        res = (self.op)(res, self.node[l]);
      }
      if r & 1 == 0 {
        res = (self.op)(res, self.node[r - 1]);
      }

      l = l >> 1;
      r = (r - 1) >> 1;
    }

    res
  }
}

Measured memory_bytes: 8808
#include<iostream>
#include<deque>
#include<list>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<iterator>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main() {
	int x;
	cin >> x;
	cout << (x / 2)*(x / 2 + x % 2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr long double EPS = 1e-15;
const long double PI = acos(-1);
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;
//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

int a[100],b[100],c[100];

void solve() {
    int n;
    cin >> n;
    REP(i,n) {
        cin >> a[i];
    }
    REP(i,n) {
        cin >> b[i];
    }
    REP(i,n-1) {
        cin >> c[i];
    }
    int ans = 0;
    REP(i,n) {
        ans += b[a[i]-1];
        if (i+1 < n && a[i+1] == a[i] + 1) ans += c[a[i]-1];
    }
    cout << ans << endl;
}

int main(int argc, char *argv[]){
    // /* Regular */
    // int case_num = 1;
    // if (argc > 1 && stoi(argv[1])) cin >> case_num;
    // REP(case_no, case_num) {
    //   cerr << endl << "case " << case_no + 1 << endl;
    //   solve();
    // }
    /* AOJ */
    solve();
    return 0;
}

Measured memory_bytes: 256