akhauriyash/Code-Regression huggingface dataset:
def d_simple_knapsack(N, W, Baggage):
    from collections import defaultdict
    # dp[w]:ナップサックに重さがwになるように荷物を入れたときの価値の最大値
    dp = defaultdict(int)
    dp[0] = 0  # 重さ0で達成できる価値は0とする
    for w, v in Baggage:
        # dpの各要素(現時点におけるナップサック内の荷物の重さ)に対して、
        # 注目した荷物を入れても重さがWを超えなければ、
        # ナップサックに荷物を入れて価値の最大値を更新する
        latest_dp = list(dp.items())
        for kw, kv in latest_dp:
            if kw + w <= W:
                dp[kw + w] = max(dp[kw + w], kv + v)
    ans = max(dp.values())
    return ans

N, W = [int(i) for i in input().split()]
Baggage = [[int(i) for i in input().split()] for j in range(N)]
print(d_simple_knapsack(N, W, Baggage))

Measured memory_bytes: 4012
#include<bits/stdc++.h>
using namespace std;
int n,a[200005];
bool check(int k)
{
	for (int i=1;i<=n;i++)
	{
		if (a[n+i]>k && a[n+i-1]>k || a[n-i]>k && a[n-i+1]>k) return 0;
		if (a[n+i]<=k && a[n+i-1]<=k || a[n-i]<=k && a[n-i+1]<=k) return 1;
	}
	return a[1]<=k;
}
int main()
{
	//freopen("pyramid.in","r",stdin);
	//freopen("pyramid.out","w",stdout);
	scanf("%d",&n);
	for (int i=1;i<=2*n-1;i++) scanf("%d",&a[i]);
	int l=1,r=2*n-1;
	while (l<r)
	{
		int mid=(l+r)/2;
		if (check(mid)) r=mid;
		else l=mid+1;
	}
	printf("%d",l);
	return 0;
}

Measured memory_bytes: 1024
#include <climits>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <map>

using namespace std;


int main()
{
	int n;
	scanf("%d", &n);
	int64_t m;
	scanf("%lld", &m);

	multimap<int64_t, int64_t> p;
	for (int i = 0; i < n; i++)
	{
		int64_t a, b;
		scanf("%lld", &a);
		scanf("%lld", &b);

		p.emplace(a, b);
	}
	int64_t count=0;
	for (auto itr = p.begin(); itr != p.end(); itr++)
	{
		if (m > (*itr).second)
		{
			count += (*itr).second * (*itr).first;
			m -= (*itr).second;
		}
		else
		{
			count += (*itr).first * m;
			break;
		}
	}

	printf("%lld\n", count);
	return 0;
}


Measured memory_bytes: 6528
S = input()
temp = ["a", "b", "c"]
abc = [S.count(x) for x in temp]
abc.sort(reverse=True)
if abc.count(0) == 1:
    if len(S) == 2:
        print("YES")
    else:
        print("NO")
elif abc.count(0) == 2:
    if len(S) == 1:
        print("YES")
    else:
        print("NO")
elif abc[0] == abc[1] == abc[2]:
    print("YES")
elif abc[0] == abc[1] == abc[2]+1:
    print("YES")
elif abc[0] == abc[1]+1 == abc[2]+1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3316
N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = sum(b)
for i in range(1,len(a)):
    if a[i-1]+1 == a[i]:
        ans += c[a[i-1]-1]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

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

void solve() {
    LL n;
    cin >> n;
    VLL c(n);
    REP(i,0,n) cin >> c[i];
    VI next(n,-1);
    VI before(2*100000,-1);
    REP(i,0,n) {
        c[i]--;
        if (before[c[i]] > -1) {
            next[before[c[i]]] = i;
        }
        before[c[i]] = i;
    }
    VI dp(n,0);
    dp[n-1] = 1;
    RREP(i,0,n-1) {
        dp[i] = dp[i+1];
        if (next[i] > i + 1) dp[i] = (dp[i] + dp[next[i]]) % MOD;
    }
    //REP(i,0,n) dump(dp[i]);
    cout << dp[0] << endl;
}

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

Measured memory_bytes: 4224
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
const int maxn=1e5+10;
using namespace std;
typedef long long ll;
ll n,m; 
ll solve()
{
	if(n==1&&m==1)return 1;
	if(n==1)return m-2;
	return (n-2)*(m-2);//把外面一圈抠掉 
}
int main()
{
	scanf("%lld%lld",&n,&m);
	if(n>m)swap(n,m);
	printf("%lld\n",solve());
	return 0;
} 

Measured memory_bytes: 256
def dfs(i, f, sum):
    if i == 3:
        if sum == 7:
            # 答えは1つ出力すれば良いので =7 になれば終了
            print(f + "=7")
            exit()

    else:
        # 式 f の末尾に符号と次の数字を追加し、その分 sum に加減する
        dfs(i + 1, f + "-" + s[i + 1], sum - int(s[i + 1]))
        dfs(i + 1, f + "+" + s[i + 1], sum + int(s[i + 1]))


s = input()

dfs(0, s[0], int(s[0]))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
const ll MOD=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    vector<ll> A_height(N);
    vector<ll> Righthand(N);
    vector<ll> Lefthand(N);

    for(int i=0;i<N;i++){
       cin>>A_height[i];
    }
    //身長分だけ横にずらす
    for(int i=0;i<N;i++){
       if(i-A_height[i]>=0){
          Lefthand[i-A_height[i]]++;
       }
       if(i+A_height[i]<N){
          Righthand[i+A_height[i]]++;
       }
    }
    ll count=0;
    for(int i=0;i<N;i++){
       count+=Lefthand[i]*Righthand[i];
    }
    cout<<count<<endl;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;
const int N = 3002;

int n;
ll f[N][N];
string s;

int main() {
    cin >> n;
    f[1][1] = 1;
    for (int i = 2; i <= n; ++i) {
        char ch;
        cin >> ch;
        for (int j = 1; j <= i; ++j) {
            if (ch == '<') {
                f[i][j] = f[i - 1][j - 1];
            } else {
                f[i][j] = (f[i - 1][i - 1] + MOD - f[i - 1][j - 1]) % MOD;
            }
        }
        for (int j = 1; j <= i; ++j)
            (f[i][j] += f[i][j - 1]) %= MOD;
    }
    cout << f[n][n] << "\n";
    return 0;
}

Measured memory_bytes: 68992
S=input()
if(S[0]=='A'):
  S_1=S[1:]
else:
  print('WA')
  exit()
if(S[2:(len(S)-1)].count('C')==1):
  S_2=S_1[0:len(S_1)-1].replace('C','')
else:
  print('WA')
  exit()
S_3=S_2+S[-1]
#print(S_1)
#print(S_2)
#print(S_3)
print('AC' if (S_3.islower()) else 'WA')

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lcm(a, b) ((a * b) / gcd(a, b))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define UN(v) sort(all(v)), v.resize(unique(all(v))-v.begin())

#define endl '\n'

const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

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

lli gcd(lli a , lli b) {
    if(b == 0) return a;
    a %= b;
    return gcd(b,a);
}

void solve() {
    lli n;
    cin >> n;
    lli a[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    bool chk1 = true;
    for (int k = 1; k < n; ++k) {
        if (a[k] < a[k - 1]) {
            chk1 = false;
            break;
        }
    }
    if (chk1) {
        cout << "YES\n";
        return;
    }

    for (int i = 0; i < n - 1; ++i) {
        for (int j = i + 1; j < n; ++j) {
            swap(a[i], a[j]);
            bool chk = true;
            for (int k = 1; k < n; ++k) {
                if (a[k] < a[k - 1]) {
                    chk = false;
                    break;
                }
            }
            if (chk) {
                cout << "YES\n";
                return;
            }
            swap(a[i], a[j]);
        }
    }
    cout << "NO\n";
}

int main()
{
    IOS;
    lli t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

// https://beta.atcoder.jp/contests/abc069/tasks/abc069_b

int main() {
    string s; cin >> s;
    printf("%c%lu%c\n", s[0], s.length()-2, s[s.length()-1]);
    return 0;
}


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

using namespace std;
string r, a;

const int INF = 1 << 29;

int main(void)
{
	while(cin >> r >> a && r != "0" && a != "0")
	{
		int blow = 0, hit = 0;
		for (int i = 0; i < 4; i++)
		{
			for (int j = 0; j < 4; j++)
			{
				if(r[i] == a[j])
				{
					if(i == j) hit++;
					else blow++;
				}
			}
		}
		cout << hit << " " << blow << endl;
	}
	return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
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;}

int main(){
    ll W,H,N;cin>>W>>H>>N;
    ll a1_max=0,a2_min=W,a3_max=0,a4_min=H;
    rep(i,N){
        ll x,y,a;cin>>x>>y>>a;
        if(a==1){
            chmax(a1_max,x);
        }else if(a==2){
            chmin(a2_min,x);
        }else if(a==3){
            chmax(a3_max,y);
        }else{
            chmin(a4_min,y);
        }
    }

    ll ans=W*H;
    ans=ans*max(0ll,(a2_min-a1_max))/W;
    ans=ans*max(0ll,(a4_min-a3_max))/H;

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

Measured memory_bytes: 3580
//
//  main.cpp
//  AISING2020C
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;
ll ans[11234]={};
void f(int n){
    ll sums=0;
    for(int x=1;x<(int)sqrt(n);x++){
        for(int y=1;y<(int)sqrt(n);y++){
            for(int z=1;z<(int)sqrt(n);z++){
                sums=x*x+y*y+z*z+x*y+y*z+z*x;
                if(sums>n) break;
                ans[sums]++;
            }
        }
    }
}
int main(int argc, const char * argv[]) {
    int n;
    cin>>n;
    f(n);
    for(int i=1;i<=n;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3212
N=int(input())

if N<105:
    print(0)
    exit()

ans=1
for i in range(106,N+1):
    if i%2!=0:
        res=0
        for j in range(1,i+1):
            if i%j==0:
                res+=1
        if res==8:
            ans+=1
print(ans)


Measured memory_bytes: 2940
n, m = map(int, input().split())
a =[]
b =[]
for i in range(n):
    x1, y1 = [int(i) for i in input().split()]
    a.append(x1)
    b.append(y1)

c = zip(a, b)
c=sorted(c)
a, b = zip(*c)
a=list(a)
b=list(b)

d = 0
money = 0
for i in range(n):
    if d == m:
        break
    else:
        if m-d <= b[i]:
            num = m-d
            d += num
            money += num*a[i]
        else:
            num = b[i]
            d += num
            money += num*a[i]

    #print(d,money)

print(money)


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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265359;

const ll MOD = (ll) 1e9 + 7;
const ll MAXN = (ll) 2e5 + 10;
const ll INF = (ll) 2242545357980376863;
const ld EPS = (ld) 1e-8;

ll cnt[MAXN];

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll k,a ,b;
	cin >>k >> a >>b;
	if(a + 2 >= b){
		cout << k + 1;
		return 0;
	}
	ll t = min(a - 1, k);
	ll ans = t + 1;
	ll r = k - t;
	ans += ( ((r / 2)*(b - a)) + r %2);
	cout << ans;
	return 0;
}


/*

                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/


Measured memory_bytes: 256
#include <stdio.h>
 
int main(void) {
    int change[30][30];
    int saki[30];
    int i,j,max;
    int a,b;
    int maxyoko;
    int now;
    for(i=0;i<30;i++) {
        for(j=0;j<30;j++) {
            change[i][j]=i;
        }
    }
    scanf("%d",&max);
    scanf("%d",&maxyoko);
    for(i=0;i<maxyoko;i++) {
        scanf("%d,%d",&a,&b);
        change[a-1][i]=b-1;
        change[b-1][i]=a-1;
    }
    for(i=0;i<max;i++) {
        now=i;
        for(j=0;j<maxyoko;j++)now=change[now][j];
        saki[now]=i;
    }
    for(i=0;i<max;i++)printf("%d\n",saki[i]+1);
    return 0;
}

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

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

//#define _USE_MATH_DEFINES
//#include <math.h>

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

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>
#define sqr(x) (x) * (x)

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

using namespace std;
using namespace std::chrono;

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

const double eps = 1e-10;


const i64 MAXN = 300004;

i64 n, h;
i64 a[MAXN];

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);
    i64 h, n;
    cin >> h >> n;
    for (i64 i = 0; i < n; i++) {
        cin >> a[i];
    }

    i64 s = 0;
    for (i64 i = 0; i < n; i++) {
        s += a[i];
    }

    if (s >= h) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
//Never stop chasing!-MdSourav.
#include <bits/stdc++.h>
#define ll long long int
#define l long int
#define start ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;

int main()
{

    int a,i,b[300006],c[300006]={0};
    cin >> a;
    for(i=0;i<a-1;i++)
    {
       cin >> b[i];

    }
    for(i=0;i<a;i++)
    {
        c[b[i]]++;
    }
    for(i=1;i<=a;i++)
    {
        cout << c[i] << endl;
    }
	  return 0;
}


Measured memory_bytes: 5584
// In god we trust
 
#include <bits/stdc++.h>
#include <chrono>
#include <algorithm>
#include <signal.h>
#include <thread>
#include <pthread.h>
#include <omp.h>
 
#define pb push_back
#define fi first
#define se second
#define Vi vector<int>
#define Vb vector<bool>
#define Pi pair<int, int>
#define MP make_pair
#define MT make_tuple
#define Q queue
#define Qi Q<int>
#define INF 1000000000 
#define LINF 1000000000000000000
#define int long long
#define _USE_MATH_DEFINES
using namespace std;
using namespace std::chrono;


int mod_power(int x, int y, int mod){
  int ans = 1;
  x %= mod;
  while(y){
    if (y & 1)
      ans *= x, ans %= mod;
    y /= 2;
    x = (x * x) % mod;
  }
  return ans;
}

int mod_inverse(int n, int mod){
  return mod_power(n, mod - 2, mod);
}

int mod_ncr(int n, int r, int mod){
  if (r == 0 or r == n)
    return 1;
  int fact = 1;
  for (int i = 1; i <= r; i++)
    fact *= i, fact %= mod;
  int ans = 1;
  for (int i = n; i > n - r; i--)
    ans *= i, ans %= mod;
  ans *= mod_inverse(fact, mod), ans %= mod;
  return ans;
}

unordered_map<int, int> factor(int n){
  int cnt = 0;
  unordered_map<int, int> m;
  int nn = n;
  while (!(nn & 1))
    cnt++, nn /= 2;
  if(cnt)
    m[2] = cnt;
  for (int i = 3; i <= sqrt(n); i++){
    cnt = 0;
    while(nn % i == 0)
      nn /= i, cnt++;
    if (cnt)
      m[i] = cnt;
  }
  if (nn > 2)
    m[nn] = 1;
  
  return m;
}



signed main(){
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL);

  string s;
  cin >> s;
  int n = s.size();
  int mod = 2019;
  int a = s[n - 1] - '0';
  unordered_map<int, int> m;
  m[a] = 1;

  int ans = 0;
  for (int i = n - 2; i >= 0; i--){
    a += ((s[i] - '0') * mod_power(10, n - 1 - i, mod)) % mod, a %= mod;
    if (m.find(a) != m.end())
      ans += m[a], m[a]++;
    else
      m[a] = 1;
  }
  
  if (m.find(0) != m.end())
    ans += m[0];
  cout << ans << endl;
}


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

int main(){
  int N,min=0;
  cin >> N;
  for(int i=0;i<N;i++){
    int x,c=0;
    cin >> x;
    while(x%2==0){
      x /= 2;
      c++;
      if(x==0) break;
    }
    if(i==0) min=c;
    if(c<=min) min=c;
  }
  cout << min << endl;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

MOD = 1000000007

def smax(a,b):
    if a>b:
        return a
    else:
        return b

def smin(a,b):
    if a<b:
        return a
    else:
        return b

def main():
    N = int(readline())
    A = [int(readline()) for i in range(N)]
    prev = 0
    count = 0
    flag = True
    for i in range(N):
        if A[i]>prev:
            flag = False
            break
        elif A[i]==prev:
            prev+=1
            if prev!=1:
                count += 1
        else:
            prev = A[i]+1
            count += A[i]
    if flag:
        print(count)
    else:
        print(-1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 47896
de = false
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
n,k = gets.chomp.split.map(&:to_i)
h = {}
td = []
n.times do
  tmp = gets.split.map(&:to_i)
  td.push tmp
  t,d = tmp
  h[t] ||= []
  h[t].push d
end

k_values = {}
used_t = Set.new
td.sort_by{|t,d| -d}.slice(0,k).each do |t,d|
  k_values[t] ||= []
  k_values[t].push d
  used_t.add t
end
current = k_values.values.flatten.inject(&:+)

k_values = k_values.map do |k,values|
  index = values.each_with_index.max[1]
  values.delete_at(index)
  values
end
k_values.flatten!.sort!.reverse!
p ['h',h] if de
p ['k_values', k_values] if de

max_values = []
(h.keys - used_t.to_a).each do |key|
  max_values.push h[key].max
end
p ['max_values', max_values] if de

kcount = used_t.size

current += kcount ** 2
p current if de
ans = current
max_values.sort.reverse.each do |max_v|
  k_values_min = k_values.pop
  break if k_values_min.nil?
  current = current - k_values_min + max_v - kcount ** 2 + (kcount+1) ** 2
  ans = current if ans < current
  kcount += 1
  # p [k_values, kcount**2, current] if de
end

puts ans


Measured memory_bytes: 46556
#include <cstdio>  
using namespace std;  
int main() { 	
	int a,b,c; 	
	scanf("%d %d %d", &a, &b, &c); 	
	if(a%3==0 || b%3==0 || (a+b)%3==0){
		printf("Possible");
	}
	else{
		printf("Impossible");
	}
	
} 

Measured memory_bytes: 128
n,m,x,y = map(int,input().split())
x_list = list(map(int,input().split()))
y_list = list(map(int,input().split()))
x_list.append(x)
y_list.append(y)
if max(x_list) < min(y_list):
    print('No War')
else:
    print('War')


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

int main() {
   	int a, b;
  	string s;
  	cin >> a >> b >> s;
  	if(s[a] != '-'){
    	cout << "No" << endl;
      	return 0;
    }
  	s.erase(a, 1);
  	rep(i, s.length()) {
    	if(s[i] < '0' || '9' < s[i]){
        	cout << "No" << endl;
          	return 0;
        }
    }
  	cout << "Yes" << endl;
    return 0;
}

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

int main(){
  int N,A;
  cin >> N >> A;
  vector<int> v(N);
  for (int i=0;i<N;i++){
    cin >> v[i];
    v[i]-=A;
  }
  long long dp[N+1][5000];
  for (int i=0;i<5000;i++){
    dp[0][i]=0;
  }
  dp[0][2500]=1;
  for (int i=0;i<N;i++){
    for (int j=0;j<5000;j++){
      dp[i+1][j]=dp[i][j]+dp[i][j-v[i]];
    }
  }
  cout << dp[N][2500]-1 << endl;
}

Measured memory_bytes: 2176
from collections import defaultdict
d = defaultdict(lambda:0)
N,M = map(int,input().split())
for i in range(N):
    K = list(map(int,input().split()))
    for j in range(1,K[0]+1):
        d[K[j]] += 1
ans = 0
for key in d:
    if d[key] == N:
        ans += 1
print(ans)

Measured memory_bytes: 3316
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------



int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    vector<int> cnt(101,0);
    int mx = 0;
    for(int i=0; i<N; i++){
        cnt[A[i]]++;
        chmax(mx,A[i]);
    }
    bool can = true;
    for(int i=0; i<(mx+1)/2; i++){
        if(cnt[i]) can = false;
    }
    if(mx%2 == 0){
        if(cnt[mx/2] != 1) can = false;
    }else{
        if(cnt[(mx+1)/2] != 2) can = false;
    }
    for(int i=(mx+1)/2+1; i<=mx; i++){
        if(cnt[i] < 2) can = false;
    }
    if(can){
        cout << "Possible" << "\n";
    }else{
        cout << "Impossible\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define EXIST(v,i) (find(all(v), i) != (v).end())
#define ERASE(v,i) (v).erase(remove(all(v), i), (v).end())
#define INDEX(v,i) (find(all(v), i) - (v).begin())
#define rep(i,n) for(int i = 0; i < (int)n; ++i)
#define debug(x) cerr << #x << " = " << (x) << endl;

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();}

const int INF = 100000000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

int main() {
	map<string, int> m;
	string line;
	getline(cin, line);
	istringstream is(line);
	for(string word; is >> word;) {
		m[word]++;
	}
	int lmax = 0, cmax = 0;
	string wlmax = "", wcmax = "";
	for(map<string, int>::iterator it = m.begin(); it != m.end(); ++it) {
		if(static_cast<int>(it->first.length()) > lmax) {
			lmax = it->first.length();
			wlmax = it->first;
		}
		if(it->second > cmax) {
			cmax = it->second;
			wcmax = it->first;
		}
	}
	cout << wcmax + " " << wlmax << endl;
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef pair<ll,P>  PP;
typedef vector<ll> Vector;
typedef vector<Vector> DVector;
typedef priority_queue<PP, vector<PP>, greater<PP>> PPQueue;

#define fi          first
#define se          second
#define sfi         se.fi
#define sse         se.se
#define pb          push_back
#define INF         INT_MAX
#define MOD         1000000007
#define bcnt        __builtin_popcount
#define all(x)      (x).begin(),(x).end()
#define uni(x)      x.erase(unique(all(x)),x.end())
#define ub(x,y)     (upper_bound(all(x),y)-x.begin())
#define lb(x,y)     (lower_bound(all(x),y)-x.begin())
#define rep(i,n)    repl(i,0,n-1)
#define usort(x)    sort(all(x))
#define dsort(x)    sort(all(x),greater<ll>())
#define mkp(x,y)    make_pair(x,y)
#define mmax(x,y)   (x>y?x:y)
#define mmin(x,y)   (x<y?x:y)
#define maxch(x,y)  x=mmax(x,y)
#define minch(x,y)  x=mmin(x,y)
#define exist(x,y)  (find(all(x),y)!=x.end())
#define each(itr,v) for(auto itr:v)
#define repl(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);i++)

int main(){
  cin.sync_with_stdio(false);
  ll n,k;
  cin >> n >> k;
  Vector a(n);
  rep(i,n)cin >> a[i];
  usort(a);
  vector<bitset<5001>> table(n);
  rep(i,n)table[i].set(i);
  vector<bitset<5001>> dp(k,~bitset<5001>());
  dp[0] = ~dp[0];
  rep(i,n)for(ll j=k-1;j>=a[i];j--)if(!dp[j-a[i]][5000])dp[j] &= (dp[j-a[i]] | table[i]);
  ll cou = n;
  rep(i,n)repl(j,mmax(0,k-a[i]),k-1)if(!dp[j][i]){cou--;break;}
  cout << cou << endl;
}


Measured memory_bytes: 6656
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::cmp::max;
use std::collections::BinaryHeap;

fn main() {
    let n: usize = read();
    let m: usize = read();
    let mut menu: Vec<Vec<i64>> = vec![];
    let mut maxv = 0;

    for _ in 0..n {
        let x: i64 = read();
        let y: i64 = read();
        let z: i64 = read();
        menu.push(vec![x, y, z]);
    }
    // for a in [-1, 1].iter() {
    //     for b in [-1, 1].iter() {
    //         for c in [-1, 1].iter() {
    //             let mut iroha = vec![0; n];
    //             for i in 0..n {
    //                 iroha[i] = a * menu[i][0] + b * menu[i][1] + c * menu[i][2];
    //             }
    //             iroha.sort();
    //             iroha.reverse();
    //             let tot = iroha[0..m].iter().sum();
    //             maxv = max(maxv, tot);
    //         }
    //     }
    // }

    for i in 0..2_u32.pow(3) {
        // let mut bh: BinaryHeap<i64> = BinaryHeap::new();
        let mut bh: Vec<i64> = vec![];

        for j in 0..menu.len() {
            let mut item = 0;
            for k in 0..3 {
                if i & 1 << k == 0 {
                    item += menu[j][k];
                } else {
                    item -= menu[j][k];
                }
            }
            bh.push(item);
        }
        bh.sort();
        bh.reverse();

        // for _ in 0..m {
        //     ans += bh.pop().unwrap().abs();
        // }
        let ans = bh[0..m].iter().sum();
        maxv = max(maxv, ans);
    }
    println!("{}", maxv);
}


Measured memory_bytes: 4352
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
S=get_nsp
ans=0
1.upto(N-2) do|i|
    ans=max(ans,(S[0..i]&S[i+1..N-1]).size)
end
puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> int_pair;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, -1, sizeof(mat))
const int N=100000;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a+b>c+d){
		cout<<"Left"<<endl;
	}else if(a+b<c+d){
		cout<<"Right"<<endl;
	}else{
		cout<<"Balanced"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
"use strict"

function main(input) {

    let num = Number(input.split('\n')[0])
    let n = input.length
    let tmp = num
    let sum = 0
    for (let i = 1; i <= n; i++) {
        sum += tmp % 10
        tmp = (tmp-(tmp % 10)) / 10
    }
    if (num % sum == 0) console.log('Yes')
    else console.log('No')
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
MOD = 10**9 + 7
n = int(input())
t = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]

height = [0] * n
height[0] = t[0]
for i in range(1, n):
    if t[i] > t[i-1]:
        height[i] = t[i]
        if t[i] > a[i]:
            print(0)
            exit()
if height[-1] == 0:
    height[-1] = a[-1]
elif height[-1] != a[-1]:
        print(0)
        exit()

for i in range(n-1, 0, -1):
    if a[i] < a[i-1]:
        if height[i-1] == 0:
            height[i-1] = a[i-1]
            if a[i-1] > t[i-1]:
                print(0)
                exit()
        elif height[i-1] != a[i-1]:
            print(0)
            exit()

ans = 1
for i, item in enumerate(height):
    if item == 0:
        ans *= min(t[i], a[i])
        ans %= MOD

print(ans)

Measured memory_bytes: 19776
import math

a, b, C = input().split()
a = float(a)
b = float(b)
C = float(C)

# 面積
S = a * b * math.sin(math.radians(C)) / 2

# 最後の一辺(余弦定理)
c = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(C)))
L = a + b + c

# aを底辺としたときの高さ
h = b * math.sin(math.radians(C))

# 出力
print(S)
print(L)
print(h)


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

int main(){
    set<int> S;
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        int d;
        cin >> d;
        S.insert(d);
    }
    cout << S.size() << endl;
}

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

int main(){
    ll n, k; cin >> n >> k;
    ll h[n]; rep(i,n) cin >> h[i];

    ll ans = 0;
    rep(i,n){
        if(h[i] >= k) ans++;
    }

    cout << ans << endl;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0; i<n; i++){
        cin >> v[i];
    }
    auto s = v;
    sort(v.begin(), v.end());
    int count = 0;
    for(int i=0; i<n; i++){
        if(v[i] != s[i]) count++;
    }
    if(count == 2 || count == 0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 1; i <= (n); ++i)
int main(void){
    // Your code here!
   int n;
   cin >> n;
   ll ans = 0;
   rep(i,n) rep(j,n) rep(k,n) ans+= gcd(i,gcd(j,k));
   cout << ans << endl;
 
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define neko 510
#define fi first
#define se second
#define pb push_back
#define f(i,a,b) for(register int i=(a);i<=(b);i=-(~(i)))
using namespace std;
typedef pair<int,int> pi;
struct node
{pi L,R,U,D;};
node p;
int n,m;
char s[neko][neko],A[neko][neko],B[neko][neko];
int id(int x,int y){return (x-1)*m+y;}
void solve()
{
	f(i,1,n)
	 f(j,1,m)
	 {
		if(i==1)A[i][j]='#';
		else if(i==n)B[i][j]='#';
		else
		{
			if(s[i][j]=='#')A[i][j]=B[i][j]='#';
			if(j&1)A[i][j]='#';
			else B[i][j]='#';
		}
		if(A[i][j]^'#')A[i][j]='.';
		if(B[i][j]^'#')B[i][j]='.';
	 }
}
int main()
{
	scanf("%d%d",&n,&m);
	f(i,1,n)scanf("%s",s[i]+1);
	solve();
	f(i,1,n)printf("%s\n",A[i]+1);
	putchar('\n');
	f(i,1,n)printf("%s\n",B[i]+1);
	return 0;
}

Measured memory_bytes: 1536
//Zory-2018
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
#ifdef DEBUG
const int LOCAL=1;
#else
const int LOCAL=0;
#endif

namespace mine
{
	typedef long long ll;
	const int INF=0x3f3f3f3f;

	const int MAX_N=410;
	bitset<MAX_N> s[MAX_N];
	int a[110000],b[110000];
	void main()
	{
		int n,m;scanf("%d%d",&n,&m);
		for(int i=1;i<=m;i++) scanf("%d%d",&a[i],&b[i]);

		for(int i=1;i<=n;i++)
		{
			s[i][i]=1;
			for(int t=m;t>=1;t--)
			{
				if(s[i][a[t]] and s[i][b[t]]) {s[i][i]=0;break;}
				else if(s[i][a[t]]) s[i][b[t]]=1;
				else if(s[i][b[t]]) s[i][a[t]]=1;
			}
		}

		int ans=0;
		for(int i=1;i<=n;i++)
			for(int j=i+1;j<=n;j++)
				ans+=(s[i][i] and s[j][j] and (s[i]&s[j]).none());
		printf("%d",ans);
	}
};
int main()
{
	mine::main();
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
  int n,i,j;
  cin >> n;
  for(i=1;i<=9;i++){
    for(j=1;j<=9;j++){
      if(i*j==n){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3628
a, b, c, d, e, k = [int(input()) for _ in range(6)]
# print(a, k)
if (
    b - a > k
    or c - a > k
    or d - a > k
    or e - a > k
    or c - b > k
    or d - b > k
    or e - b > k
    or d - c > k
    or e - c > k
    or e - d > k
):
    print(":(")
else:
    print("Yay!")


Measured memory_bytes: 2940
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int N;
  while (cin >> N) {
    vec<ll, 2> a = make_v(N, 3, 0ll);
    for (int i = 0; i < N; i++) cin >> a[i][0] >> a[i][1] >> a[i][2];
    vector<ll> dp(3, 0);
    for (int i = 0; i < N; i++) {
      vector<ll> ndp(3, 0);
      for (int j = 0; j < 3; j++) {
        for (int k = 0; k < 3; k++) {
          if (j == k) continue;
          ndp[k] = max(ndp[k], dp[j] + a[i][k]);
        }
      }
      dp = ndp;
    }
    ll res = *max_element(dp.begin(), dp.end());
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
#define ll long long

int a[300][300],vs[300],mx[300];
char s[300][300];
int main()
{
    IO;
    double i, j, m, k, n, t, l=0, mxx,mx1,r,c,x,y;
    cin>>n;
    cout<<setprecision(22)<<2*acos(-1.0)*n<<endl;
    return 0;

}


Measured memory_bytes: 3792
#include <stdio.h>

int main(void){
    int a[3],i,j,cp;
    scanf("%d %d %d",&a[0],&a[1],&a[2]);
    for(i = 0; i < 3; i++){
        for(j = i+1; j < 3; j++){
            if(a[i] > a[j]){
                cp = a[i]; a[i] = a[j]; a[j] = cp;
            }
        }
    }
    printf("%d %d %d\n",a[0],a[1],a[2]);
    return 0;
}

Measured memory_bytes: 596
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const inputs = input.trim().split('\n');
const n = Number(inputs.shift());
const adj = inputs.map((s) => s.split(' ').map(Number));

class Node {
  constructor(id) {
    this.id = id;
    this.measure = {};
    this.children = [];
  }
  add(node) {
    this.children.push(node);
  }
  isMeasured() {
    return !!this.measure.start;
  }
  setMeasure(time) {
    this.measure.start = time;
    this.children.sort((a, b) => a.id > b.id);
    this.children.forEach(node => {
      if (!node.isMeasured()) {
        time = node.setMeasure(++time);
      }
    });
    return this.measure.end = ++time;
  }
  toString() {
    return [this.id, this.measure.start, this.measure.end].join(' ');
  }
}

class Tree {
  constructor() {
    this.map = new Map();
  }
  getNode(id) {
    if (!this.map.has(id)) {
      this.map.set(id, new Node(id));
    }
    return this.map.get(id);
  }
  print() {
    for (let i = 1; i <= this.map.size; i++) {
      const node = this.map.get(i);
      console.log(node.toString());
    }
  }
  calc() {
    let time = 0;
    for (let i = 1; i <= this.map.size; i++) {
      const node = this.map.get(i);
      if (!node.isMeasured()) {
        time = node.setMeasure(++time);
      }
    }
  }
}

const tree = new Tree();
adj.forEach(([u, k, ...vk]) => {
  const parent = tree.getNode(u);
  vk.forEach(v => {
    const node = tree.getNode(v);
    parent.add(node);
  });
});

tree.calc();
tree.print();



Measured memory_bytes: 16940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int d,n;
	cin>>d>>n;
	int cnt=0;
	FOR(i,1,INF){
		int m=i,now=0;
		while(m && m%100==0){
			now++;
			m/=100;
		}
		if(now==d){
			cnt++;
		}
		if(cnt==n){
			cout<<i<<endl;
			return 0;
		}
	}	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
  
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
  
typedef long long ll;
typedef pair<int, int> ii;
 
int main(){
 
    vector<int> prime;
    vector<bool> check(300002);
     
    REP(i, 2, 300001){
        if(i % 7 != 1 && i % 7 != 6) continue;
        if(!check[i]) prime.push_back(i);
        for(int j  = 2; i * j < 300001; j++){
            check[i * j] = true;
        }
    }
 
    ll num;
    while(cin >> num){
        if(num == 1) break;
         
        cout << num << ":";
        for(int i = 0; i < prime.size(); i++){
            if(num % prime[i] == 0){
                cout << " " << prime[i];
            }
        }
         
        cout << endl;
         
    }
     
  
    return 0;
}

Measured memory_bytes: 3188
#include <iostream>
 
using namespace std;
long long NMAX,NMIN;
int K;
int A[100005];
long long eval(long long N){
    for(int i = 1;i <= K;i++){
        N =N - N % A[i];}
    return N;
}
int main()
{
    cin >> K;
    for(int i = 1;i <= K;i++){
        cin >> A[i];
    }
    long long st = 0,dr = 1e18;
    while(dr - st > 1){
        long long mid = (st + dr) / 2;
        if(eval(mid) >= 2){
            dr = mid;
        }
        else {
            st = mid;
        }
    }
  long long L = dr;
    st = 0,dr = 1e18;
    while(dr - st > 1){
        long long mid = (st + dr) / 2;
        if(eval(mid) <= 2){
            st = mid;
        }
        else {
            dr = mid;
        }
    }
long long R = st;
if(L > R) puts("-1");
else cout << L << ' '<< R << endl;
    return 0;
}

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

using namespace std;
const int N = 200005;

stack < pair <int,int> > fwd, bwd;
int n, a[N], fi[N], bi[N];
long long res, v;

void init(){
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
	}
	fwd.push(make_pair(0,0));
	for(int i = 1; i <= n; i++){
		while(fwd.top().first > a[i]){
			fwd.pop();
		}
		fi[i] = fwd.top().second;
		fwd.push(make_pair(a[i],i));
	}
	bwd.push(make_pair(0,n + 1));
	for(int i = n; i >= 1; i--){
		while(bwd.top().first > a[i]){
			bwd.pop();
		}
		bi[i] = bwd.top().second;
		bwd.push(make_pair(a[i],i));
	}
	for(int i = 1; i <= n; i++){
		v = (long long)(i - fi[i]) * (bi[i] - i);
		res += v * a[i];
	}
	printf("%lld\n",res);
}

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

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

int main()
{
  int N;
  cin >> N;
  vector<int> h(N);
  for (int i = 0; i < N; i++)
  {
    cin >> h[i];
  }

  //高さが0になるまでやる
  int res = 0;
  while (true)
  {
    //最高高さが0だったらおしまい
    if (*max_element(h.begin(), h.end()) == 0)
      break;

    //区間分割する
    int i = 0;
    while (i < N)
    {
      if (h[i] == 0)
        i++; //0なら何もせずに進む
      else
      {
        res++; //区間の始まり
        while (i < N && h[i] > 0)
        {
          h[i]--; //ついでに引いとく
          i++;    //区間の終わりまで一気に
        }
      }
    }
  }
  cout << res << endl;
}


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

using namespace std;

int main() {
  string S;
  cin >> S;
  int r = 0, b = 0;
  for (char c : S) {
    if (c == '0') r++;
    else b++;
  }
  cout << min(r, b) * 2 << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t h,w;
  int64_t ans;
  
  cin >> h >> w;
  
  if(h==1 || w==1) ans = 1;
  else if(h%2==0 || w%2 ==0) ans = (h*w)/2;
  else  ans = (h*w+1)/2;
  
  cout << ans << endl;
  
  return 0;
}

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

using namespace std;

int main(){

    map<int,int> mp;

    int N;
    cin >> N;

    set<int> s;
    for(int i = 0;i < N;i++){
    	int a;
    	cin >>a;
    	s.insert(a);
    	mp[a]++;
    }

    int ans = 0;

    for(auto a:mp){
      if(a.first < a.second){
    	  ans += a.second - a.first;
      }else if(a.first > a.second){
    	  ans += a.second;
      }
    }

    cout << ans << endl;

	return 0;

}


Measured memory_bytes: 9216
/*
* be kind, work hard
*/
/******************************************************************************/
/**///#include <boost/multiprecision/cpp_int.hpp>
/**/#include <bits/stdc++.h>                                                
/**/
/**/#define endl            "\n"
/**/#define pb              push_back
/**/#define X               first
/**/#define Y               second
/**/#define setZero(array)  memset((array), 0, sizeof (array))
/**/#define setOne(array)   memset((array), 1, sizeof (array))
/**/#define setTrue(array)  memset((array), true, sizeof (array))
/**/#define setFalse(array) memset((array), false, sizeof (array))
/**/#define HAYAKU          ios_base::sync_with_stdio(false);cin.tie(NULL);
/**/#define int             long long
/**/#define LIVE            return
/**/#define FREE            1
/**/#define OR              and
/**/#define DIE             0
/******************************************************************************/
/*
using boost::multiprecision::cpp_int;
*/

typedef long long ll;

using namespace std;

const int MOD = 1e9 + 7;
const int N   = 1e5;

void preprocess(){
    return;
}

int inline solve(){
    int n, i;
    
    cin >> n;
    
    cout << (n + n*n + n*n*n) ;
    return 0;
}

signed main(){
    HAYAKU
    
    preprocess();
    
    int t = 1;
    
//    cin >> t;
    
    for(int i=1; i<=t; ++i){
//        cout << "Case #" << i << ": ";
//        cout << 
            solve();
//        cout << endl;
    }
    
    LIVE FREE OR DIE;
}

Measured memory_bytes: 3624