akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,ans;
int main(){
    scanf("%lld",&n);
    ans=n-1;
    for (int i=2;i<=sqrt(n);i++)
    if (n%i==0){
        ll x,y;
        x=i;y=n/i;
        if (x+y-2ll<ans)ans=x+y-2ll;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	a := nextInt()
	b := nextInt()

	x1 := a + b
	x2 := a - b
	x3 := a * b

	if x1 < x2 {
		if x2 < x3 {
			fmt.Println(x3)
		} else {
			fmt.Println(x2)
		}
	} else {
		if x1 < x3 {
			fmt.Println(x3)
		} else {
			fmt.Println(x1)
		}

	}

}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1772
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

using vi = vector<int>;
int main() {
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	vi S;
	vi W;
	for (int i = 0; i*a < f; i++) {
		for (int j = 0; j*b < f; j++) {
			W.push_back(i*a + j*b);
		}
	}
	for (int i = 0; i*c < f; i++) {
		for (int j = 0; j*d < f; j++) {
			S.push_back(i*c + j*d);
		}
	}
	sort(S.begin(), S.end());
	sort(W.begin(), W.end());
	unique(S.begin(), S.end());
	unique(W.begin(), W.end());
	int s = 0;
	int w = 0;
	int ansS = 0;
	int ansW = a; 
	
	while (true) {
		s++;
		while (W[w] * e < S[s]) {
			w++;
		}
		if ((S[s] + W[w] * 100) > f)break;
		if (S[s] * (100 * ansW + ansS) > ansS * (100 * W[w] + S[s])) {
			ansS = S[s];
			ansW = W[w];
		}
	}
	cout << ansW * 100 + ansS << " " << ansS << endl;
}

Measured memory_bytes: 5232
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define ps push
#define pf push_front
#define mp make_pair
#define And &&
#define Or ||
#define inf INT_MAX
#define sz(name) name.size()
#define len(name) name.length()
#define ig cin.ignore()
#define sc(name) scanf("%d",&name)
#define ssc(name1,name2) scanf("%d%d",&name1,&name2)
#define sssc(name1,name2,name3) scanf("%d%d%d",&name1,&name2,&name3)
#define scl(name) scanf("%lld",&name)
#define sscl(name1,name2) scanf("%lld%lld",&name1,&name2)
#define ssscl(name1,name2,name3) scanf("%lld%lld%lld",&name1,&name2,&name3)
#define Sort(name) sort(name.begin(),name.end())
#define For(name,start,finish) for(int name=start;name<finish;name++)
#define Forr(name,start,finish) for(int name=start;name>=finish;name--)
#define fast_in_out ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


//int row[]={-1,0,1,0};
//int col[]={0,1,0,-1};

const ll N=2e5+10;
const ll M=1e9+7;

ll logx(ll a,ll b){return log(a)/log(b);}
ll Max(ll a,ll b){if(a>b)return a;return b;}
ll Min(ll a,ll b){if(a>b)return b;return a;}
ll big_mul(ll a,ll b,ll m){ll x=0,y=a%m;while(b>0){if(b&1)x=(x+y)%m;y=(2*y)%m;b>>=1;}return x%m;}
ll big_mod(ll a,ll b,ll m){ll x=1,y=a%m;while(b>0){if(b&1)x=(x*y)%m;y=(y*y)%m;b>>=1;}return x%m;}
ll Big_mod(ll a,ll b,ll m){ll x=1,y=a%m;while(b>0){if(b&1)x=big_mul(x,y,m);y=big_mul(y,y,m);b>>=1;}return x%m;}
ll mod_inverse(ll a,ll m){return big_mod(a,m-2,m);}  //a^-1 mod m = a^(m-2) mod m



int main()
{
    fast_in_out;


    int cnt=0;
    string str1,str2;
    cin>>str1>>str2;

    For(i,0,sz(str1))
    {
        if(str1[i]==str2[i])
            cnt++;
    }

    cout<<cnt<<endl;

    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n, m;
    cin >> n >> m;
    vector<int> b(3, -1);
    bool flg = true;
    for(int i=0;i<m;i++){
        int s, c;
        cin >> s >> c;
        if(s == 1 && n != 1 && c == 0){
            flg = false;
        }
        if(b[s-1] == -1){
            b[s-1] = c;
        }else if(b[s-1] != c){
            flg = false;
        }
    }
    for(int i=0;i<n;i++){
        if(b[i] == -1) b[i] = 0;
    }
    if(b[0] == 0 && n != 1) b[0] = 1;
    
    if(flg){
        for(int i=0;i<n;i++){
            cout << b[i];
        }
        cout << endl;
    }else{
        puts("-1");
    }
}


Measured memory_bytes: 256
import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
import itertools
input=sys.stdin.readline
##import numpy as np
#sys.setrecursionlimit(10**7)
mo=10**9+7
def cin():
    return map(int,sin().split())
def ain():            
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
##def power(x, y):
##    if(y == 0):return 1
##    temp = power(x, int(y / 2))%mo
##    if (y % 2 == 0):return (temp * temp)%mo 
##    else:
##        if(y > 0):return (x * temp * temp)%mo 
##        else:return ((temp * temp)//x )%mo
##
for _ in range(1):
    n,x,t=cin()
    if(n%x==0):
        print((n//x)*t)
    else:
        print(((n//x)+1)*t)

Measured memory_bytes: 9408
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

ll MOD = int(1e9) + 7;

int main(void)
{
    cin.sync_with_stdio(false);
    string S;
    cin >> S;
    ll len = SIZE(S);

    map<ll, ll> v;
    REP(i, len) {
        auto ch = S[i];
        auto d = (ch - '0');
        map<ll, ll> next_v;
        if (i == 0) {
            if (ch == '?') {
                REP(j, 10) next_v[j] = 1;
            } else {
                next_v[d] = 1;
            }
        } else {
            if (ch == '?') {
                for(auto kv: v) {
                    REP(d2, 10) {
                        auto next_k = (kv.first * 10 + d2) % 13;
                        next_v[next_k] += kv.second;
                        next_v[next_k] %= MOD;
                    }
                }
            } else {
                for(auto kv: v) {
                    auto next_k = (kv.first * 10 + d) % 13;
                    next_v[next_k] += kv.second;
                    next_v[next_k] %= MOD;
                }
            }
        }
        // for(auto kv: next_v) {
        //     cout << "(" << kv.first << "," << kv.second << "),";
        // }
        // cout << endl;

        v = next_v;
    }
    cout << v[5] << endl;

    return 0;
}


Measured memory_bytes: 512
""" AtCoder """

import sys
input = sys.stdin.readline

S = input()

min_a = 1000000000

for i in range(len(S)-3):
    min_a = min(min_a, abs(753 - (int(S[i])*100 + int(S[i+1])*10 + int(S[i+2]))))

print(min_a)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(void)
{
    int N;
    cin >> N;

    int a[] = {0, 0, 0, 0};
    for(auto& e : a)
    {
        e = N % 10;
        N /= 10;
    }
    if(a[1] == a[2])
    {
        if(a[0] == a[1] || a[2] == a[3])
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vel;
typedef vector<string> ves;
typedef vector<int> vei;
typedef vector<vector<ll>> vvel;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main() {
    int k,n;cin>>n>>k;
    vei p(n);
    rep(i,n) {
        cin>>p[i];
    }
    sort(p.begin(),p.end());
    ll ans=0;
    rep(i,k) {
        ans+=p[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define itn int
#define gI gi

using namespace std;

typedef long long ll;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + (c ^ 48), c = getchar();
	return f * x;
}

inline ll gl()
{
	ll f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + (c ^ 48), c = getchar();
	return f * x;
}

const int maxn = 100003;

int n, m, a[maxn];
stack <int> v[5], ans;

int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	n = gi();
	for (int i = 1; i <= n; i+=1)
	{
		a[i] = gi();
		if (a[i] % 4 == 0) v[4].push(a[i]);
		else if (a[i] & 1) v[1].push(a[i]);
	}
	while (v[1].size())
	{
		ans.push(v[1].top()); v[1].pop();
		if (ans.size() == n) {puts("Yes"); return 0;}
		if (v[4].size()) ans.push(v[4].top()), v[4].pop();
		else {puts("No"); return 0;}
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int X;
  cin >> X;
  if (X==3||X==5||X==7) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>

// naive method would be to do dfs for all vertices and print the maximum depth

void dfs(int index,vector<int> graph[],int dp[],bool visited[]){
    visited[index]=true;
    for(int i=0;i<graph[index].size();i++){
        if(!visited[graph[index][i]])
            dfs(graph[index][i],graph,dp,visited);
        dp[index] = max(dp[index],1+dp[graph[index][i]]);
    }
}

int longestPath(vector<int> graph[],int n){
    int dp[n+1];    // store maximum depth from ith node
    bool visited[n+1];
    memset(dp,0,sizeof dp);
    memset(visited,false,sizeof visited);
    for(int i=1;i<=n;i++){
        if(!visited[i])
            dfs(i,graph,dp,visited);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        ans = max(ans,dp[i]);
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,x,y;
    cin>>n>>m;
    vector<int> graph[n+1];
    for(int i=0;i<m;i++){
        cin>>x>>y;
        graph[x].pb(y);
    }
    cout<<longestPath(graph,n)<<endl;
}


Measured memory_bytes: 9600
import sys
input=sys.stdin.readline

n=int(input())
c=input().rstrip()

l=0
r=n-1
ans=0
while True:
    while c[l]=='R':
        l+=1
        if l==n:
            break
    while c[r]=='W':
        r-=1
        if r==-1:
            break
    if l>r:
        break
    ans+=1
    l+=1
    r-=1

temp=0
for i in c:
    if i=='R':
        temp+=1
temp=min(temp,n-temp)
ans=min(ans,temp)
print(ans)

Measured memory_bytes: 68124
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include<numeric>
#include<cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#define ll long long int
#define CON 100010
//#define N 1500000
//const long long mod=1e9+7;
//const int INF=1001001001;
//const int inf=100000;
//const ll ful=1e18;
const double PI=3.1415926535897932;
using namespace std;
//namespace mp = boost::multiprecision;
int main() 
{
	double a,b,h,m;
	cin>>a>>b>>h>>m;
	double sho=h*30+m/2;
	double lar=m*6;
	double rad=abs(sho-lar);
	double num=pow(a,2)+pow(b,2)-2*a*b*cos(PI*rad/180);
	double ans=sqrt(num);
	printf("%17.13f",ans);
	return 0;
}

Measured memory_bytes: 4252
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 1e5 + 5;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n; string s;
    cin >> n >> s;
    if (n & 1) cout << "No\n";
    else {
        int len = n / 2;
        cout << (s.substr(0,len)==s.substr(n/2,len) ? "Yes" : "No") << '\n';
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

// 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
// 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

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

    // 特殊パターン対応
//    if(n.size() == k) {
//        ll ans = 0;
//        int already_use = 0;
//        rep(i, n.size()) {
//            FOR(j,1,n[i]-'0') {
//                int already_use2 = already_use;
//                if(j > 0) already_use2++;
//                //if(already_use2 > k) continue;
//                // 計算
//                int select_num = k-already_use2;
//                ll tmp_cross = 1;
//                rep(k, select_num) {
//                    tmp_cross *= n.size()-i-1-k;
//                }
//                ll tmp_div = 1;
//                rep(k, select_num) {
//                    tmp_div *= select_num-k;
//                }
//                ll tmp = tmp_cross/tmp_div;
////            cout << tmp << endl;
////            cout << " - " << endl;
////            //cout << tmp*pow(9,select_num) << endl;
//////            cout << i << endl;
//////            cout << tmp << endl;
//                ans += tmp*pow(9,select_num);
//            }
//            already_use++;
//            if(already_use >= k) {
//                if()
//                break;
//            }
//        }
//
//        cout << ans << endl;
//        return 0;
//    }

    ll ans = 0;
    int already_use = 0;
    rep(i, n.size()) {
        bool flag = false;
        rep(j, n[i]-'0') {
            flag = true;
            if(i == n.size()-1 && already_use+1 == k) {
                ans += n[i]-'0';
                cout << ans << endl;
                return 0;
            }
            int already_use2 = already_use;
            if(j > 0) already_use2++;
            //if(already_use2 > k) continue;
            // 計算
            int select_num = k-already_use2;
            ll tmp_cross = 1;
            rep(l, select_num) {
                int a = n.size()-i-1-l;
                tmp_cross *= a;
            }
            ll tmp_div = 1;
            rep(l, select_num) {
                tmp_div *= select_num-l;
            }
            ll tmp = tmp_cross/tmp_div;
//            cout << tmp << endl;
//            cout << " - " << endl;
//            //cout << tmp*pow(9,select_num) << endl;
////            cout << tmp << endl;
            ans += tmp*pow(9,select_num);
        }
        if(flag) already_use++;
        if(already_use >= k) {
            if(n[i]-'0' != 0) {
                ans++;
            }
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  int N,A,B;
  cin>>N>>A>>B;
  if(N!=1) cout<<A+B<<endl;
  else cout<<"Hello World";
return 0;}

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

int main(){
    ll h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, 0, h) cin >> s[i];
    vector<vector<int>> pts(h, vector<int>(w, 0));

    rep(i, 0, h){
        char pre = s[i][0];
        ll pi = 0;
        rep(j, 1, w){
            if(pre != s[i][j]){
                if(pre == '.'){
                    rep(k, pi, j){
                        pts[i][k] += (j - pi);    
                    }
                }
                pre = s[i][j];
                pi = j;
            }
        }
        if(pre == '.'){
            rep(k, pi, w){
                if(pts[i][k] != 0) pts[i][k]--;
                    pts[i][k] += (w - pi);
            }
        }
    }
    rep(i, 0, w){
        char pre = s[0][i];
        ll pi = 0;
        rep(j, 1, h){
            if(pre != s[j][i]){
                if(pre == '.'){
                    rep(k, pi, j){
                        if(pts[k][i] != 0) pts[k][i]--;
                        pts[k][i] += (j - pi);
                    }
                }
                pre = s[j][i];
                pi = j;
            }
        }
        if(pre == '.'){
            rep(k, pi, h){
                if(pts[k][i] != 0) pts[k][i]--;
                    pts[k][i] += (h - pi);
            }
        }
    }
    
    int ans = 0;
    rep(i, 0, h){
        rep(j, 0, w){
            ans = max(ans, pts[i][j]);
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 20096
#include <stdio.h>
int main() {
	int n, x = 0, max = 0;
	char s[101];
	scanf("%d%s", &n, s);
	for (int i = 0; i < n; i++) {
		if (s[i] == 'I')
			x++;
		else
			x--;
		if (max < x) {
			max = x;
		}
	}
	printf("%d\n", max);
	return 0;
}

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

int main(){
	int N, M;
	int *x;
	int a, b;
	scanf("%d%d", &N, &M);
	x = (int *)malloc(sizeof(int) * N);
	for(int i = 0; i < N; i++) x[i] = 0;
	for(int i = 0; i < M; i++){
		scanf("%d%d", &a, &b);
		x[a - 1]++;
		x[b - 1]++;
	}
	for(int i = 0; i < N; i++){
		printf("%d\n", x[i]);
	}
}

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

int n;
string s;
int rem[200200];
int cnt[2222];

int main(){
	ios::sync_with_stdio(false);
	cin >> s;
	n = s.size();
	int base = 1;
	cnt[0]++;
	for(int i = n-1; i >= 0; i--){
		rem[i] = (rem[i+1] + (s[i] - '0') * base) % 2019;
		cnt[rem[i]]++;
		base = base * 10 % 2019;
	}
	long long ans = 0; 
	rep(i, 2019) ans = ans + 1LL * cnt[i] * (cnt[i] - 1) / 2LL;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4460
#include<iostream>
using namespace std;
int main(){
  int a,total=0;
  for(int i=0;i<5;i++){
    cin >> a;
    if(a<40){
      total+=40;
    }
    else{
      total+=a;
    }
  }
  total/=5;
  cout << total << endl;
}

Measured memory_bytes: 1160
#include<stdio.h>
long long int max_k(int m,int *Max);
long long int min_k(int m,int *Min);
long long int sum_k(int m,int *Sum);
    int main(void){
	int n,i;
	int a[10000];
	long long int max;
	long long int min;
	long long int sum;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		}
	max=max_k(n,a);
	min=min_k(n,a);
	sum=sum_k(n,a);
	printf("%lld %lld %lld\n",min ,max ,sum);
	return 0;
}

	long long int max_k(int m,int* Max){
		int h;
		long long int max_s=-1000000;
		for(h=0;h<m;h++){
				if(Max[h]>max_s){
					max_s=Max[h];
				}
		}
			return max_s;
	}
	
	long long int min_k(int m,int* Min){
		int h;
		long long int min_s=1000000;
		for(h=0;h<m;h++){
				if(Min[h]<min_s){
					min_s=Min[h];
				}
		}
			return min_s;
	}
	
	long long int sum_k(int m,int* Sum){
		int h;
		long long int sum_s=0;
		for(h=0;h<m;h++){
				sum_s+=Sum[h];
		}
			return sum_s;
	}


Measured memory_bytes: 2120
n = int(input())
b = list(map(int, input().split()))[::-1]

l = [n]
ans = []
for i in range(n):
    x = 0
    f = 0
    for j in range(i+1):
        if i+1-j in b[x:l[j]]:
            ans.append(i+1-j)
            l.append(b.index(i+1-j))
            b[l[-1]] = 0
            l.sort()
            f = 1
            break
        x = l[j]
    if f == 0:
        print(-1)
        exit()

for i in ans:
    print(i)

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

int main(void){
	int N,K,sum=0,res=0;
	cin>>N>>K;
	int a[N];
	rep(i,N)cin>>a[i];
	sort(a,a+N,greater<int>());
	rep(i,N)if((sum+=a[i])>=K){
		res = max(res,i+1);
		sum -= a[i];
	}
	cout<<N-res<<endl;
	return 0;
}


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

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

using namespace std;

typedef long long ll;

const int MAX_N=2e5,MOD=998244353;

string S;

ll dp[MAX_N][3][3][2];

map<string,bool> mp;

char c(char a,char b){
	REP(i,3){
		if (a!='a'+i && b!='a'+i){
			return 'a'+i;
		}
	}
	return 0;
}

void solve(){
	int n=S.size();
	bool flg=true;
	REP(i,n-1){
		if (S[i]!=S[i+1]){
			flg=false;
		}
	}
	if (flg){
		cout<<1<<endl;
		return;
	}
	if (n<=3){
		mp[S]=true;
		queue<string> que;
		que.push(S);
		while(!que.empty()){
			string s=que.front();
			que.pop();
			REP(i,n-1){
				if (s[i]!=s[i+1]){
					string t=s;
					t[i]=t[i+1]=c(s[i],s[i+1]);
					if (mp.find(t)==mp.end()){
						mp[t]=true;
						que.push(t);
					}
				}
			}
		}
		cout<<mp.size()<<endl;
		return;
	}
	REP(i,3){
		REP(j,3){
			dp[0][i][j][1]=0;
			dp[0][i][j][0]=(i==j ? 1 : 0);
		}
	}
	REP(i,n-1){
		REP(j,3){
			REP(k,3){
				dp[i+1][j][k][0]=(dp[i][(j+1)%3][(k-j+3)%3][0]+dp[i][(j+2)%3][(k-j+3)%3][0])%MOD;
				REP(l,3){
					dp[i+1][j][k][1]+=dp[i][l][(k-j+3)%3][1];
					dp[i+1][j][k][1]%=MOD;
				}
				dp[i+1][j][k][1]+=dp[i][j][(k-j+3)%3][0];
				dp[i+1][j][k][1]%=MOD;
			}
		}
	}
	int s=0;
	REP(i,n){
		s+=(S[i]-'a');
	}
	s%=3;
	ll ans=0;
	REP(i,3){
		ans+=dp[n-1][i][s][1];
	}
	flg=false;
	REP(i,n-1){
		if (S[i]==S[i+1]){
			flg=true;
		}
	}
	if (!flg){
		ans++;
	}
	ans%=MOD;
	cout<<ans<<endl;
}

int main(){
	cin>>S;
	solve();
	return 0;
}


Measured memory_bytes: 28676
#include<stdio.h>
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int p;
	char s[4];
	int ac[100005], pena[100005];
	int i;
	for (i = 0; i < n; i++)
		ac[i] = pena[i] = 0;
	for (i = 0; i < m; i++)
	{
		scanf("%d %s", &p, s);
		p--;
		if (s[0] == 'A')
			ac[p] = 1;
		else
		{
			if (ac[p] == 0)
				pena[p]++;
		}
	}
	int c = 0;
	for (i = 0; i < n; i++)
		if (ac[i] > 0)
			c++;
	printf("%d ", c);
	c = 0;
	for (i = 0; i < n; i++)
		if (ac[i] > 0)
			c += pena[i];
	printf("%d\n", c);
	return 0;
}

Measured memory_bytes: 896
import sys
n, p = map(int, input().split())

if n == 1:
    print(p)
    sys.exit()


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


ans = 1
for k, v in factorization(p):
    if v >= n:
        coef = v // n
        ans *= k**coef

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>


using namespace std;

void func144b (){
	int n;
	cin >> n;
	for (int i = 1; i < 10; i++) {
		if (n / i < 10 && n % i == 0) {
			cout << "Yes\n";
			return;
		}
	}
	cout << "No\n";
}


int main()
{
	func144b();
	return 0;	
}



Measured memory_bytes: 256
#include <iostream>


using namespace std;

int main()
{
    int n,b;
    cin>>n;
    b=n;
    n/=100;
    int a=n;
    a=n+n*10+n*100;
    if(a>=b)
    cout << a<< endl;
    else
        cout<<a+111<<endl;
    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
a = Array.new(n){
  gets.split.map{|i|
    if !i.match(/(S|H|C|D)/)
      i.to_i
    else
      i
    end
  }
}

$INF = 10**9

def partition(a, p, r)
  x = a[r][1]

  i=p-1
  p.upto(r-1) do |j|
    if a[j][1] <= x
      i = i+1
      a[i], a[j] = a[j], a[i]
    end
  end
  a[i+1], a[r] = a[r], a[i+1]
  return i+1
end

def quick_sort(a, p, r)
  if p < r
    q = partition(a, p, r)
    quick_sort(a, p, q-1)
    quick_sort(a, q+1, r)
  end
end

def marge(l, r)
  l.push([nil, $INF])
  r.push([nil, $INF])
  length = l.length-1 + r.length-1
  return Array.new(length){(l.first[1] <= r.first[1] ? l : r).shift}
end

def marge_sort(s)
  if s.length >= 2
    mid = s.length/2
    l = marge_sort(s[0..mid-1])
    r = marge_sort(s[mid..-1])
    s = marge(l, r)
  end
  return s
end

b = marge_sort(a)
quick_sort(a, 0, n-1)

puts a == b ? "Stable" : "Not stable"
puts a.map{|item| item.join(" ")}


Measured memory_bytes: 38812
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <sstream>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int main()
{   
    string ret;
    rep(i,3)
    {
        string s;
        cin >> s;
        ret += s.substr(i,1);
    }
    cout << ret << endl;
    return 0;
}

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

int main() {
  int x;
  cin >> x;

  if (x == 1) {
    cout << 0 << endl;
  } else {
    cout << 1 << endl;
  }
}

Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
const int inf=1000000007;
const int MOD=1000000007;
int dp[3][100050]={};
int dpr[3][100050]={};
signed main(){
  string s;cin>>s;
  int n=(int)s.length();
  int res=0;
  dp[1][0]=0;
  int q=1;
  if(s[0]=='A'||s[0]=='?'){
    dp[1][0]=1;
    if(s[0]=='?')q=3;
  }
  dp[2][0]=0;
  int rate=1;
  rep1(i,n-1){
    if(s[i]=='?'){
      res*=3;
      res+=dp[2][i-1];
      dp[2][i]=dp[2][i-1]*3+dp[1][i-1];
      dp[1][i]=dp[1][i-1]*3+q;
      q*=3;q%=MOD;
    }
    else{
      if(s[i]=='C'){
        res+=dp[2][i-1];
        dp[2][i]=dp[2][i-1];
        dp[1][i]=dp[1][i-1];
      }
      else if(s[i]=='B'){
        dp[2][i]=dp[2][i-1]+dp[1][i-1];
        dp[1][i]=dp[1][i-1];
      }
      else if(s[i]=='A'){
        dp[2][i]=dp[2][i-1];
        dp[1][i]=dp[1][i-1]+q;
      }
    }
    //cout<<res<<endl;
    res%=MOD;
    dp[1][i]%=MOD;dp[2][i]%=MOD;
  }
  cout<<res<<endl;
  rep(i,n){
    //printf("dp[1][%d]=%d, dp[2][%d]=%d\n",i,dp[1][i],i,dp[2][i]);
    //printf("dp[1][%lld]=%lld, dp[2][%lld]=%lld\n",i,dp[1][i],i,dp[2][i]);
  }
  return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) ((a>b)?a:b);
#define min(a,b) ((b>a)?a:b);
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert                                                                      //copy NUL check.cpp
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)                                 //g++ atc.cpp -o atc.exe
#define zeroes(x) memset(x,0,sizeof(x))                                        //all elements to 0
#define all(x) (x).begin(), (x).end()
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100000;







bool sortbysec(const pair<int,int> &a,                         //sorting of elements wrt second
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 




int main()
{
	int n;
	int p;
	//cout<<"enter";
	cin>>n;
	p=(n/2);
	p++;
	
	
	if(n%2!=0)

		cout<< (double)p/n;
	if(n%2==0)
		cout<<1.0/2;
	
	
	return 0;
}

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

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

    int z;
    int cou = 0;

    for(int i = 0; i <= k; i++){
        for(int j = 0; j <= k; j++){
            z = s - i - j;
            if(z <= k && z >= 0){
                //cout << i << " " << j << " " << z << endl;
                cou++;
            }
        }
    }

    cout << cou << endl;
}

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

using namespace std;

typedef unsigned long long ll;

int main(){
        ll a, b, x;
        cin>>a>>b>>x;
        if(a==0){
                a=0;
        }
        else{
                a=(a-1)/x+1;
        }
        b=b/x+1;
        cout<<b-a<<endl;
        return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    ll SN=0;
    ll N2=N;
    while(N2){
        SN +=(N2%10);
        N2/=10;
    }
    if(N%SN==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }



    return 0;
    

}

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

void maxHeapify(int *,int,int);

int main(){
  int i;
  int H;
  int *A;

  scanf("%d",&H);
  H++;
  A=(int *)malloc(H*sizeof(int));

  for(i=1;i<H;i++){
    scanf("%d",&A[i]);
  }
  for(i=H/2;i>0;i--){
    maxHeapify(A,i,(H-1));
  }


  for(i=1;i<H;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
return 0;
}
void maxHeapify(int *A,int i,int H){
  int l;
  int r;
  int largest;
  int temp;
  l=i*2;
  r=i*2+1;
  if(l<=H&&A[l]>A[i]) largest=l;
  else largest=i;
  
  if(r<=H&&A[r]>A[largest]) largest=r;

  if(largest!=i){
    temp=A[i];
    A[i]=A[largest];
    A[largest]=temp;
    maxHeapify(A,largest,H);
  }
  return;
}
    



Measured memory_bytes: 3676
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
#define INF 2000'000'000

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	//freopen("in", "r", stdin);
	int n;
	cin >> n;
	cout << (n >= 30 ? "Yes" : "No") << "\n";
	return 0;
}


Measured memory_bytes: 3648
use std::cmp;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let a: Vec<u64> = sc.vec(1 << n);
    let mut max2: Vec<Vec<(u64, usize)>> =
        a.iter().enumerate().map(|(i, &a)| vec![(a, i)]).collect();
    for mask in 0..(1 << n) {
        for i in 0..n {
            let next = mask | (1 << i);
            let from = max2[mask].clone();
            max2[next].extend(from);
            max2[next].sort();
            max2[next].reverse();
            max2[next].dedup();
            max2[next].resize(2, (0, 0));
        }
    }

    let mut ans = vec![0; 1 << n];
    for mask in 1..(1 << n) {
        let (a0, _) = max2[mask][0];
        let (a1, _) = max2[mask][1];
        ans[mask] = cmp::max(ans[mask], a0 + a1);
        ans[mask] = cmp::max(ans[mask], ans[mask - 1]);
        println!("{}", ans[mask]);
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 44028
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
int main()
{
  ll n,k;cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];

  vector<ll> sum(n+1);
  sum[0] = 0;
  rep(i,n) {
    sum[i+1] = sum[i] + a[i];
  }
  rep1(i,n) sum[i]  = (sum[i] - (ll)i) % k;

  map<ll,ll> mp;
  rep(i,min(n+1,k)) {
    mp[ sum[i] ]++;
  }

  ll res = 0;
  for(auto m : mp) {
    res += m.second * (m.second - (ll)1) / (ll)2;
  }

  rep(i,n-k+1) {
    mp[ sum[i] ]--;
    res += mp[ sum[i+k] ];
    mp[ sum[i+k] ]++;
  }
  cout << res << "\n";
  
  return 0;
}


Measured memory_bytes: 15872
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pb push_back
#define pll pair<ll,ll> 
#define mll map<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0; i<n; i++)
#define All(x,v) for(auto x:v)
#define arrin(a,n) ll a[n]; rep(i,n) cin>>a[i]
#define vi vector<int>
#define nl "\n"
#define print(arr) All(x,arr) cout<<x<<" "; cout<<nl
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define ing(m,ad) rep(i,m){ int u,v; cin>>u>>v; u--;v--; ad[u].pb(v); ad[v].pb(u);}
#define vdsort(v) sort(v.begin(),v.end(),greater<int>())
#define F first
#define S second
#define mod 1000000007
const int MAXN=100001;
int spf[MAXN];
int gcd(int x, int y){ return y?gcd(y,x%y):x; }

void precal(){  
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++)  spf[i] = i; 
    for (int i=4; i<MAXN; i+=2) spf[i] = 2; 
    for (int i=3; i*i<MAXN; i++) { 
        if (spf[i] == i) 
            for (int j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j)  spf[j] = i; 
    } 
} 
vector<int> getFactorization(int x){
    vector<int> ret; 
    while (x != 1) { 
        ret.push_back(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
}

ll exp(ll n, ll m){
    ll a = 1;
    while (m){
        if (m & 1) a = (a * n % mod) % mod;
        m /= 2;
        n = (n*n) % mod;
    }
    return a;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    ll n,t=1;
    // cin>>t;
    while(t--){
        cin>>n;
        arrin(h,n);
        ll dp[n];
        dp[0]=0; dp[1]=abs(h[1]-h[0]);
        for(int i=2; i<n; i++) dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
        cout<<dp[n-1]<<nl;
    }
    return 0;
}

Measured memory_bytes: 4708
import java.util.Scanner;
class Main{
    int n,x;
    public void solve(){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();

        for(x = 1; x <= n; x++){
            if(x % 3 == 0 || x % 10 == 3){
                System.out.printf(" %d",x);
            }else if(x / 10 == 3 || x / 100 == 3 || x / 1000 == 3 || x / 10000 == 3){
                System.out.printf(" %d",x);
            }else if(x - x / 100 * 100 > 29 && x - x / 100 * 100 < 40){
                System.out.printf(" %d",x);
            }else if(x - x / 1000 * 1000 >= 300 && x - x / 1000 * 1000 < 400){
                System.out.printf(" %d",x);
            }else if(x - x / 10000 * 10000 >= 3000 && x - x / 10000 * 10000 < 4000){
                System.out.printf(" %d",x);
            }
        }

        System.out.println();
    }
    public static void main(String[] args){
        new Main().solve();
    }
}

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

long long n;

long long WS(long long);

int main(void){
	scanf("%lld",&n);
    for(int i=sqrt(n);i>=1;i--)
        if(n%i==0)
            return printf("%lld\n",WS(n/i)),0;
    return 0;
}

long long WS(long long num){
	long long sum=1;
    while(num>=10)
        sum++,
        num/=10;
    return sum;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>

using namespace std;

char S = 'S';
char W = 'W';
char N = 'N';
char E = 'E';

class dice{
  private:
    int up;
    int down;
    int east;
    int west;
    int north;
    int south;
  public:
    dice(int up, int south, int east, int west, int north, int down);
    void move(char to);
    int get_value();
};

dice::dice(int _up, int _south, int _east, int _west, int _north, int _down) {
  up = _up;
  south = _south;
  east = _east;
  west = _west;
  north = _north;
  down = _down;
}

void dice::move(char to) {
  if(to == S) {
    int tmp = down;

    down = south;
    south = up;
    up = north;
    north = tmp;
  } else if (to == N) {
    int tmp = down;

    down = north;
    north = up;
    up = south;
    south = tmp;
  } else if (to == W) {
    int tmp = down;

    down = west;
    west = up;
    up = east;
    east = tmp;
  } else if (to == E) {
    int tmp = down;

    down = east;
    east = up;
    up = west;
    west = tmp;
  }
}

int dice::get_value(){
  return up;
}

int main() {
  int up, south, east, west, north, down;
  string move;

  cin >> up;
  cin >> south;
  cin >> east;
  cin >> west;
  cin >> north;
  cin >> down;

  cin >> move;

  dice d = dice(up, south, east, west, north, down);

  for (int i = 0; i < (int)move.size(); i++) {
    d.move(move[i]);
  }  

  cout << d.get_value() << endl;

  return 0;
}



Measured memory_bytes: 3212
#!/usr/bin/env python3
import sys
from itertools import chain
from itertools import product


def check(N, ptn, m_assert):
    for i in range(N):
        if ptn[i] == 1:
            for j in range(i + 1, N):
                if ptn[j] == 1:
                    if m_assert[i][j] == 0:
                        return False
                    if m_assert[j][i] == 0:
                        return False
                else:
                    if m_assert[i][j] == 1:
                        return False
        else:
            for j in range(i + 1, N):
                if ptn[j] == 1:
                    if m_assert[j][i] == 1:
                        return False
    return True


def solve(N, m_assert):
    ans = 0
    for ptn in product([1, 0], repeat=N):
        if check(N, ptn, m_assert):
            ans = max(sum(ptn), ans)
    return ans


def main():
    N = int(input())
    m_assert = [[-1] * N for _ in range(N)]
    for n in range(N):
        A = int(input())
        for a in range(A):
            x, y = map(int, input().split())
            m_assert[n][x - 1] = y
    answer = solve(N, m_assert)
    print(answer)


if __name__ == "__main__":
    main()


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

char s[100060];
int main()
{
    int n,b,a,len,i,cnt=0;
    scanf("%d %d %s",&a,&b,s);
    len=strlen(s);

    if(len!=a+b+1)
    {
        printf("No");
        return 0;
    }

    for(i=0; i<a; i++)
    {
        if(s[i]=='-')
        {
            cnt++;
        }
    }

    if(s[a]!='-') cnt++;
    for(i=a+1; i<a+b+1; i++)
    {
        if(s[i]=='-') cnt++;
    }

    if(cnt==0) printf("Yes");
    else printf("No");

    return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using bint = boost::multiprecision::cpp_int;

int main()
{
    int N, W;
    std::cin >> N >> W;
    std::vector<int> ws(N);
    std::vector<bint> vs(N);
    for (int i = 0; i < N; i++) {
        std::cin >> ws.at(i) >> vs.at(i);
    }
    std::vector<std::vector<bint>> dp(N + 1, std::vector<bint>(W + 1, 0));
    for (int i = 1; i < N + 1; i++) {
        for (int j = 1; j < W + 1; j++) {
            if (j >= ws.at(i - 1)) {
                if (dp.at(i - 1).at(j) > dp.at(i - 1).at(j - ws.at(i - 1)) + vs.at(i - 1)) {
                    dp.at(i).at(j) = dp.at(i - 1).at(j);
                } else {
                    dp.at(i).at(j) = dp.at(i - 1).at(j - ws.at(i - 1)) + vs.at(i - 1);
                }
            } else {
                dp.at(i).at(j) = dp.at(i - 1).at(j);
            }
        }
    }
    std::cout << *std::max_element(dp.at(N).begin(), dp.at(N).end()) << std::endl;
    return 0;
}

Measured memory_bytes: 319360
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define Test ll t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define loopS(i,a,b,step) for(ll i=a;i<b;i+=step)
#define loopRS(i,a,b,step) for(ll i=a;i>=b;i-=step)
#define ull unsigned long long int
#define pll pair<ll,ll>
#define puu pair<ull, ull>
#define V vector
#define M map
#define UM unordered_map
#define mp(x,y) make_pair(x,y)
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define inf INT_MAX
#define S3(a,b,c) cin >> a >> b >> c
#define S2(a,b) cin >> a >> b
#define debug(x) cout << #x << " = " << x << endl;
using namespace std;

void input(ll n, double arr[]) {
	rep(i, 1, n + 1)cin >> arr[i];
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cout.tie(NULL);
	ll n; cin >> n;
	double pHead[n];
	input(n, pHead);
	double dp[n + 1][n + 1];
	init(dp, double(0));
	// probability of getting i heads from j tails.
	dp[0][0] = 1;
	/*We have two possibilities for the j - th coin.
	Case 1 - It is a heads.
	The probability of getting a head is p[j].
	And we need to get exactly (i - 1) heads from the previous (j - 1) coins.
	This is given by p[j] x f(i - 1, j - 1)
	Case 2 - It is tails
	The probability is given by (1 - p[j])
	We need i heads from the first j - 1 coins.
	The probability is (1 - p[j]) x f(i, j - 1)*/
	rep(i, 1, n + 1) {
		double t = 1 - pHead[i], p = pHead[i];
		// 0 heads hai
		dp[0][i] = t * (dp[0][i - 1]);
		rep(head, 1, i + 1) {
			dp[head][i] = p * dp[head - 1][i - 1] + t * dp[head][i - 1];
		}
	}
	double ans = 0;
	rep(i, n / 2 + 1, n + 1) {
		ans += dp[i][n];
	}
	cout << setprecision(9) << ans;
}


Measured memory_bytes: 70656
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

long long int n,m;
long long int a,b,c;

int main(void){
scanf("%lld",&n);
scanf("%lld",&m);
a = n - m / 2;


if(a <= 0){
b = n + -1 * a / 2;
}else{
b = m/2;
}
printf("%lld",b);

return 0;
}


Measured memory_bytes: 128
import math

n = int(input())
nn = 2 * math.factorial(n-1)
cnt = 1
ave = 0
x = [0]*n
y = [0]*n
for i in range(n):
    x[i],y[i] = (int(l) for l in input().split())
for i in range(n):
    if i == n-1:
        print(ave / math.factorial(n))
    else:
        for j in range(n-cnt):
            k = i + j + 1
            ave += float(((x[i]-x[k]) ** 2 + (y[i]-y[k]) ** 2)) ** 0.5 * nn
        cnt += 1

Measured memory_bytes: 3064
#include<cstdio>
#include<vector>


int main(void)
{
	int n, m, i, a, b;
	std::vector<int> v;

	while(scanf("%d%d", &n, &m)==2)
	{
		v.clear();
		v.resize(n+1);
		for(i=0;i<m;i++)
		{
			scanf("%d%d", &a, &b);
			v[a]++;
			v[b]++;
		}
		for(i=1;i<=n;i++)
		{
			if(v[i]&1) break;
		}
		printf("%s\n", (i>n)?"YES":"NO");
	}
	return 0;
}


Measured memory_bytes: 640
#zero_sum slow
import sys

N = int(input())
A =  list(map(int,input().split()))


res = 0
s = 0
s_list = {}
s_list.update({0:0})
i = 0
while i < N:
    s += A[i]
    try:
        s_temp = s_list[s]
        s_list[s] += 1
        res -= s_temp * (s_temp + 1) / 2.
        res += (s_temp + 1) * (s_temp + 2) / 2.
    except:
        s_list.update({s:0})
    i += 1
    
print(int(res))

Measured memory_bytes: 39532
#include <stdio.h>

int a[4][4];

int main(void)
{
	int n, i, j;

	for (i = 1; i <= 3; i++)
		for (j = 1; j <= 3; j++)
			scanf("%d", &a[i][j]);
	scanf("%d", &n);
	while (n--)
	{
		int num;
		scanf("%d", &num);
		for (i = 1; i <= 3; i++)
			for (j = 1; j <= 3; j++)
				if (a[i][j] == num)
					a[i][j] = 0;
	}

	int cnt = 0;

	for (i = 1; i <= 3; i++)
	{
		int sum = 0;
		for (j = 1; j <= 3; j++)
			sum += a[i][j];
		if (sum == 0)
			++cnt;
	}
	for (i = 1; i <= 3; i++)
	{
		int sum = 0;
		for (j = 1; j <= 3; j++)
			sum += a[j][i];
		if (sum == 0)
			++cnt;
	}

	if (a[1][1] + a[2][2] + a[3][3] == 0)
		++cnt;
	if (a[1][3] + a[2][2] + a[3][1] == 0)
		++cnt;

	if (cnt)
		puts("Yes");
	else
		puts("No");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
typedef long long int ll;
using namespace std;
int main()
{
	int n;
	cin >> n;
	vector<int> ascii(128,0);
	string s;
	cin >> s;
	for(int i=0; i<s.size(); i++){
		ascii.at(s.at(i))++;
	}
	for(int i=0; i<n-1; i++){
		cin >> s;
		vector<int> tmpascii(128,0);
		for(int j=0; j<s.size(); j++){
			tmpascii.at(s.at(j))++;
		}
		for(int j='a'; j<='z'; j++){
			if(tmpascii.at(j)<ascii.at(j)){
				ascii.at(j)=tmpascii.at(j);
			}
		}
	}

	for(int i='a'; i<='z'; i++){
		for(int j=0; j<ascii.at(i); j++){
			char c=i;
			cout << c;
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n, m;
    int i, j;
    int cn;

    scanf("%d %d", &n, &m);
    int a[n][m], b[m];

    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            scanf("%d", &a[i][j]);
        }
    }
    for(i = 0; i < m; i++){
        scanf("%d", &b[i]);
    }

    for(i = 0; i < n; i++){
        cn = 0;
        for(j = 0; j < m; j++){
            cn += a[i][j] * b[j];
        }
        printf("%d\n", cn);
    }
    return 0;
}

Measured memory_bytes: 1772
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO.Pipes;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();
        string t = Console.ReadLine();
        if(s == t.Substring(0,s.Length))
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 25876