akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
int n,m;
int a,b; 
int num;
int fa[200000];
int get(int x) 
{
    if (fa[x] == x) 
        return x; 
    return get(fa[x]); 
}
void lian(int x, int y)
{
    x = get(x);
    y = get(y);
    if (x != y) 
        fa[y] = x;
}
int main()
{ 
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		fa[i]=i; 
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&a,&b);
		lian(a,b);
	}
	for(int i=1;i<=n;i++)
	{
		if(fa[i]==i)
			num++;
	}
	printf("%d",num-1);
	 
}

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

int main(){
    int n, Y;
    cin >> n >> Y;

    for(int x = 0; x <= n; x++){
        for(int y = 0; y <= n - x; y++){
            int z = n - x - y;
            if(x * 10000 + y * 5000 + z * 1000 == Y){
                cout << x << " " << y << " " << z << endl;
                return 0;
            }
        }
    }
    /*
    int x = 0;
    if((Y / 10000) > n){
        cout << "-1" << " " << "-1" << " " << "-1" << endl;
        return 0;
    } 

    if(Y >= 10000){
        while(true){
            Y -= 10000;
            x++;
            if(Y < 10000){
               break;
            }
        }
    }

    if(x == n){
        cout << x << " " << "0" << " " << "0" << endl;
        return 0;
    }
    
    for(int y = 0; y <= (n - x); y++){
        for(int z = 0; z <= (n - x); z++){
            if((y * 5000 + z * 1000 == Y) && (y + z == n - x)){
                cout << x << " " << y << " " << z << endl;
                return 0;
            }
        }
    }*/

    /*
    for(int z = 0; z <= n; z++){
        if(z * 1000 <= Y){
            for(int y = 0; y <= n; y++){
                if((z + y <= n) && (z * 1000 + y * 5000 <= Y)){
                    for(int x = 0; x <= n; x++){
                        if((x * 10000 + y * 5000 + z * 1000 == Y) && (x + y + z == n)){
                            cout << x << " " << y << " " << z << endl;
                            return 0;
                        }
                    }
                }
            } 
        }
    }*/

    cout << "-1" << " " << "-1" << " " << "-1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
using namespace std;

#define LEN 100010
int n;
typedef struct{
    int hei;
    int pos;
    int sank;
}RIKU;
RIKU R[LEN];
int PosToIndex[LEN] = {0};
int allzero = 0;

int cmp(RIKU x,RIKU y) {
    return x.hei<y.hei   ; 
}

int main(void)
{
    //------------
    cin >> n;

    // 両端
    R[0].hei = 0;
    R[0].pos = 0;
    R[0].sank = 1;
    R[n+1].hei = 0;
    R[n+1].pos = n+1;
    R[n+1].sank = 1;

    for(int i = 1 ; i <= n ; i++){
        cin >> R[i].hei;
        allzero += R[i].hei;
        R[i].pos = i;
        R[i].sank = -1;
    }
    sort(R+1, R+n+1, cmp);

    // posとindexの変換テーブル
    for(int i=0;i<=n+1;i++){
        PosToIndex[R[i].pos] = i;
    }
    //------------
 
    int now_hight = R[1].hei;
    int shima_max = 0;
    int shima_count = 1;
    if(allzero == 0) shima_count = 0;
    
/*
    if(R[PosToIndex[1]].hei != now_hight && R[PosToIndex[n]].hei != now_hight){
        shima_count++;
    }
*/
    for(int i=1;i<=n;i++){

        //std::cout << "index : " << i << "-----" << endl;

        if(now_hight != R[i].hei || i == n){
            if(shima_max < shima_count) shima_max = shima_count;
            now_hight = R[i].hei;
        }
        // しまをカウント
        shima_count++;
        R[i].sank = 1;

        if(R[PosToIndex[R[i].pos-1]].sank != -1){ //隣が沈んでいれは
            shima_count--;
        }
        if(R[PosToIndex[R[i].pos+1]].sank != -1){ //隣が沈んでいれは
            shima_count--;
        }

        //std::cout << now_hight << ":";
        //std::cout << shima_count << endl;


        /*
        if(R[i].pos == 1){
            hajis++;
        }
        if(R[i].pos == n){
            hajis++;
        }
        
        if(haji_1 == haji_n && 1 != n){   // 両端が沈む対象なら
            hajis++;
        } 
        */     
    }

    std::cout << shima_max << endl;
}



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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
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;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列 -92
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}



int main(){
    int p,q,r;
    cin >> p>>q>>r;
    cout << min({p+q,p+r,q+r}) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> h(n);
    for(int i = 0; i < n; i++) {
        cin >> h[i];
    }
    sort(all(h), greater<ll>());
    ll ans = 0;
    for(int i = k; i < n; i++) {
        ans += h[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res % p;
}
void solve()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int r = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'R')
        {
            r++;
        }
    }
    int ans = 0;
    for (int i = r; i < n; i++)
    {
        if (s[i] == 'R')
            ans++;
    }
    cout << ans << endl;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tc;
    tc = 1;
    //cin >> tc;
    while (tc--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3744
local n, k = io.read("*n", "*n", "*l")
local s = io.read()
local prv = s:sub(1, 1)
local nxt = ""
local changed = 0
local score = 0
for i = 2, n do
  nxt = s:sub(i, i)
  if prv == nxt then
    score = score + 1
  else
    changed = changed + 1
  end
  prv = nxt
end
while 0 < changed and 0 < k do
  if 2 <= changed then
    changed = changed - 2
    k = k - 1
    score = score + 2
  else
    changed = changed - 1
    k = k - 1
    score = score + 1
  end
end
print(score)


Measured memory_bytes: 888
a,b,c,d = map(int,input().split())
mod = 998244353
dp = [[0 for i in range(d+1)] for j in range(c+1)]
dp[a][b] = 1
for i in range(a,c+1):
  for j in range(b,d+1):
    if i == a and j == b:
      continue
    if i > a:
      dp[i][j] += dp[i-1][j]*j
    if j > b:
      dp[i][j] += dp[i][j-1]*i
    if i != a and j != b:
      dp[i][j] -= dp[i-1][j-1]*(i-1)*(j-1)
    dp[i][j] %= mod
print(dp[c][d])

Measured memory_bytes: 147120
s = input()

s_work = s
target_list = ["dream", "dreamer", "erase", "eraser"]

while len(s_work) > 0:
    has_changed = False
    for target in target_list:
        if s_work.endswith(target):
            s_work = s_work[0:-len(target)]
            has_changed = True
            break
    if not has_changed:
        print("NO")
        exit()

print("YES")


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
#define int long long
int arr[15000321];
signed main(){
	int a[10];
	int s=0;
	for(int i=0;i<3;i++){
		cin>>a[i];s+=a[i];
	}if(s>=22) cout<<"bust";
	else cout<<"win";
	return 0;
}
/*

1 6
2 6
4 6
4 9
8 9


1 8
2 8
4 8
7 8
==

1 6 6
1 8 5
1 3 3

3 2 1    1 1 1 2 1
*/

Measured memory_bytes: 256
#include <stdio.h>
int main() {
    int n;
    long long cnt = 0;
    scanf("%i", &n);
    for (int a = 1; a < n; a++) {
        int max_b = n / a;
        cnt += max_b - (n % a == 0);
    }
    printf("%lli", cnt);
}


Measured memory_bytes: 1736
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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

	string s,t;
	cin>>s>>t;
	vvi G(s.size()+1,vi(26,inf));
	for(int i=s.size()-1;i>=0;i--){
		G[i]=G[i+1];
		G[i][s[i]-'a']=i;
	}
	int w=0,c=0;
	rep(i,t.size()){
		int a=G[c][t[i]-'a'];
		if(a==inf){
			w+=s.size();
			c=G[0][t[i]-'a'];
			if(c==inf){
				cout<<-1<<endl;
				return 0;
			}
		}else{
			c=a;
		}
		c++;
	}
	cout<<w+c<<endl;
}


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

n = int(input())
matrix = []
while n > 0:
    values = [int(x) for x in input().split()]
    matrix.append(values)
    n -= 1

official_house = [[[0 for z in range(10)] for y in range(3)] for x in range(4)]

Min = 0
Max = 9
for b, f, r, v in matrix:
    num = official_house[b - 1][f - 1][r - 1]
    if Min <= num or Max >= num:
        official_house[b - 1][f - 1][r - 1] += v

for i in range(4):
    for j in range(3):
        print('',' '.join(str(x) for x in official_house[i][j]))
    if 3 > i:
        print('#' * 20)

Measured memory_bytes: 7748
#include <bits/stdc++.h>
#define ll long long

using namespace std;
int n,x[110];

int main()
{
    cin >> n;
    for(int i = 0;i<n;i++)  cin >> x[i];
    int Min = 1e9;
    for(int i = 0;i<=100;i++){
        int Res = 0;
        for(int j = 0;j<n;j++){
            Res+=(i - x[j]) * (i - x[j]);
        }
        Min = min(Min , Res);
    }
    cout << Min;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int k = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            if(s.Length <= k)
            {
                Console.WriteLine(s);
            }
            else if(s.Length > k)
            {
                for (int i=0; i<k; i++)
                {
                    Console.Write(s[i]);
                }
                Console.WriteLine("...");
            }
        }
    }
}


Measured memory_bytes: 27484
def main():
    N = int(input())
    X = []
    L = []
    for i in range(N):
        x, l = [int(s) for s in input().split()]
        X.append(x)
        L.append(l)

    ranges = []
    for i in range(N):
        ranges.append((X[i] - L[i], X[i] + L[i]))
    ranges.sort(key=lambda x: x[1])

    cnt = len(ranges)
    end = ranges[0][1]
    for i in range(1, len(ranges)):
        if ranges[i][0] < end:
            cnt -= 1
        else:
            end = ranges[i][1]
    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 67288
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
  string s1, s2;
  cin >> s1 >> s2;

  int i, n = s1.size();
  for (i=0; i<n; i++) {
    s1.push_back(s1[0]);
    s1.erase(0, 1);
    if (s1 == s2) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
N,K = map(int, input().split(' '))
a=list(range(1,N+1))
for i in range(K):
  count=int(input())
  b=input().split(' ')
  for j in range(count):
    if int(b[j]) in a:
      a.remove(int(b[j]))
print(len(a))

Measured memory_bytes: 9192
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main() {
    double a, b, degree;
    cin >> a >> b >> degree;

    double radian = degree / 180 * M_PI;
    double S = a * b * sin(radian) / 2;
    double c = sqrt(a * a + b * b - 2 * a * b * cos(radian));
    double L = a + b + c;
    double h = 2 * S / a;

    printf("%.8lf\n", S);
    printf("%.8lf\n", L);
    printf("%.8lf\n", h);
    return 0;
}



Measured memory_bytes: 3472
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000

int main(){
	int n;
	scanf("%d", &n);
	if((n==3)||(n==5)||(n==7))printf("YES\n");
	else printf("NO\n");


	return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <atcoder/fenwicktree>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}










int main(){
    int N, Q; std::cin >> N >> Q;
    atcoder::fenwick_tree<long long> BIT(N);
    {
        int a;
        for(int i(0); i < N; ++i){
            std::cin >> a;
            BIT.add(i, a);
        }
    }
    {
        int op, l, r;
        for(int i(0); i < Q; ++i){
            std::cin >> op >> l >> r;
            if(op) std::cout << BIT.sum(l, r) << "\n";
            else BIT.add(l, r);
        }
    }
    return 0;
}


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

#define ll long long
#define ld long double 
#define endl "\n"
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define fr(i,n) for(i=1;i<=n;i++)

typedef pair<int, int> II;
typedef vector< II > VII;
typedef vector<int> VI;

ll x[100010];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll i,n,k,mn=1e18,l,r;
    cin>>n>>k;
    fr(i,n) cin>>x[i];
    for(i=1;i+k-1<=n;i++)
    {
        l=x[i];
        r=x[i+k-1];
        if(r<=0)
            mn=min(mn, abs(l));
        else if(l>=0)
            mn=min(mn, r);
        else
            mn=min(mn, 2*min(abs(l), abs(r))+max(abs(l), abs(r)));
    }
    cout<<mn<<endl;
    return 0;
}


Measured memory_bytes: 1024
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
X = LI()
max_x = max(X)
ans = INF
for i in range(1,max_x+1):
    temp = 0
    for j in X:
        temp += (j-i)**2
    ans = min(ans,temp)

print(ans)


Measured memory_bytes: 59116
def resolve():
    n=int(input())
    p=list(map(int,input().split()))
    s=0
    for i in range(1,n-1):
        s+=p[i-1]<p[i]<p[i+1] or p[i+1]<p[i]<p[i-1]
    print(s)
        
resolve()

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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int N;
int K;

int kazoeru(ll p, v1 w){
	int j = 0;
	rep(i, K){
		ll sum = 0;
		while(1){
			if(sum + w.at(j) > p) break;
			sum += w.at(j);
			j++;
			if(j == N) return N;
		}
	}
	return j;
}

int main(){
	cin >> N;
	cin >> K;
	v1 w(N);
	ll sum = 0;
	rep(i, N){
		int c;
		scanf("%d", &c);
		w.at(i) = c;
		sum += c;
	}
	int left = 0;
	int right = sum +1;
	ll ans;
	while(left+1 < right){
		ll p = (right + left)/2;
		int v = kazoeru(p, w);
		if(v >= N){
			right = p;
		}else if(v < N){
			left = p;
		}
	}
	ans = right;
	cout << ans << endl;
}



Measured memory_bytes: 3740
#include "bits/stdc++.h"
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
#define sz(x) ((int)(x).size())
#define int ll
#define el '\n'
template<class T> bool rmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool rmx(T &a, T b) { return a < b ? (a = b, true) : false; }
typedef long long ll; typedef long double ld; typedef double dd; typedef pair<int, int> pii;
const ll INFLL=0x7f7f7f7f7f7f7f7f, MOD=1e9+9; const int INF=0x7f7f7f7f;

//////////////////// DEBUG /////////////////////////////////////////
#define D(x) cerr<<#x<<" is:\t"<<x<<'\n';
#define DD(x,y) cerr<<'('<<#x<<','<<#y<<") are:\t"<<x<<' '<<y<<'\n';
#define DDD(x,y,z) cerr<<'('<<#x<<','<<#y<<','<<#z<<") are:\t"<<x<<' '<<y<<' '<<z<<'\n';

/////////////////// VARIABLES & FUNCTIONS//////////////////////////
vv<vv<int>> adj; vv<int> vis, color; 
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
inline ll mexp(ll x,ll n,ll m=MOD){ll res=1;x%=m;while(n){if(n&1)res=(res*x)%m;n>>=1;x=(x*x)%m;}return res;}
inline ll gcd(ll a, ll b){if(a<0) a=-a; if(b<0) b=-b; while (a>0 && b>0){if(a>b)a%=b;else b%=a;}return a+b;}

///////////////////// MAIN STARTS //////////////////////////////////
int32_t main(void){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cout<<fixed;cerr<<fixed; cout<<setprecision(10); cerr<<setprecision(3);
mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count());

int n; cin>>n;
ll arr[n];
for(int i=0;i<n;++i) cin>>arr[i];

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

return 0;
}


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

const int INF = 1e9 + 7;
int n, m, l, q;
int d1[300][300], d2[300][300];
int s[89700], t[89700];

int main() {
    scanf("%d %d %d", &n, &m, &l);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j) continue;
            d1[i][j] = INF;
            d2[i][j] = INF;
        }
    }
    for (int i = 0; i < m; i++) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        d1[a - 1][b - 1] = c;
        d1[b - 1][a - 1] = c;
    }
    scanf("%d", &q);
    for (int i = 0; i < q; i++) scanf("%d %d", &s[i], &t[i]);
     
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                d1[j][k] = min(d1[j][k], d1[j][i] + d1[i][k]);
            }
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (d1[i][j] <= l) d2[i][j] = 1;
        }
    }
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                d2[j][k] = min(d2[j][k], d2[j][i] + d2[i][k]);
            }
        }
    }

    for (int i = 0; i < q; i++) {
        printf("%d\n", (d2[s[i] - 1][t[i] - 1] == INF) ? -1 : d2[s[i] - 1][t[i] - 1] - 1);
    }
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

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

    vector<int> A(N);
    for (int i = 0; i < N; i++)
        cin >> A[i];

    vector<int> a = A;

    for (int i = 0; i < K; i++) {
        vector<int> imos(N+1, 0);
        for (int j = 0; j < N; j++) {
            imos[max(0, j - a[j])]++;
            imos[min(N, j + a[j] + 1)]--;
        }

        for (int j = 0; j < N; j++) {
            imos[j + 1] += imos[j];
        }

        imos.pop_back();
        if (imos == a)
            break;

        a = imos;
    }

    for (int i = 0; i < N; i++)
        cout << a[i] << (i == N - 1 ? '\n' : ' ');

    return 0;
}


Measured memory_bytes: 5596
N, M = map(int, input().split())
ac = [False for _ in range(N)]
wa = [0 for _ in range(N)]

ans_wa = 0
for _ in range(M):
  p, S = input().split()
  p = int(p) - 1
  if S == "AC":
    if ac[p] == False:
      ac[p] = True
      ans_wa += wa[p]
  else:
    wa[p] += 1

ans_ac = ac.count(True)
print("{} {}".format(ans_ac, ans_wa))

Measured memory_bytes: 4656
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int n;
vector<char> crt_str(0);
vector<string> result(0);

void func(int ind, int crt_ch, int next_max)
{
  if (ind == n - 1)
  {
    string str(crt_str.begin(), crt_str.end());
    result.push_back(str + (char)('a' + crt_ch));
  }
  else
  {
    crt_str[ind] = (char)('a' + crt_ch);

    for (int i = 0; i <= next_max - 1; i++)
    {
      func(ind + 1, i, next_max);
    }
    func(ind + 1, next_max, next_max + 1);
  }
}

int main()
{
  cin >> n;

  for (int i = 0; i < n - 1; i++)
  {
    crt_str.push_back('a');
  }

  func(0, 0, 1);

  for (int i = 0; i < result.size(); i++)
  {
    cout << result[i] << endl;
  }

  return 0;
}


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

typedef long long int ll;
typedef double d;

#define tt int t; cin>>t; while(t--)
#define lo(i, a, b) for(int i=a; i<b; i++)
#define rlo(i, a) for(int i=a; i>0; i--)

#define be(a) a.begin(),a.end()
#define sz(x) x.size()

#define nl cout<<"\n";
#define sp cout<<" ";

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

int main()
{
    su;
    ll n,s=0;
    cin>>n;
    lo(i,1,n+1)
    {
       if(i%3==0||i%5==0)
         continue;
       s+=i;
    }
    cout<<s;
    nl;
    return 0;
}


Measured memory_bytes: 3652
class Expression
  def initialize(proc, a, b)
    @proc = proc
    @a = a
    @b = b
  end
  
  def solve
    if @proc == '+'
      @a + @b
    elsif @proc == '-'
      @a - @b
    elsif @proc == '*'
      @a * @b
    elsif @proc == '/'
      @a / @b
    end
  end
end

expressions = Array.new(0)

while true
  expression_array = gets.split
  if expression_array[1] == '?'
    break
  end
  
  a = expression_array[0].to_i
  proc = expression_array[1]
  b = expression_array[2].to_i
  expressions << Expression.new(proc, a, b)
end

expressions.each do |expression|
  puts expression.solve
end

Measured memory_bytes: 8668
n= int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
for i in range(n):
    a[i]-= 1
c.append(0)
s = 0
t = -1
for i in a:
    s += b[i]
    if t +1 == i:
        s+= c[t]
    t = i
print(s) 

Measured memory_bytes: 3064
def main():
    from functools import reduce

    N, X = map(int, input().split())
    A = (int(j) - X for j in input().split())

    def gcd(a, b):
        while b:
            a, b = b, a % b
        return a

    print(abs(reduce(gcd, A)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 11596
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
//#include <ostream>


using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main(){
  string S;
  cin >> S;
  if(S.at(2)==S.at(3) && S.at(4)==S.at(5)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}


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

int main()
{
	int n, l;
	string s;
	vector<string> v;
	cin >> n >> l;
	for (int i = 0; i < n; i++) {
		cin >> s;
		v.push_back(s);
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < n; i++) {
		cout << v[i];
	}
	cout << endl;
	return 0;
}

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

using namespace std;

#define ll long long

int main()
{
	ll N, M, X;
	cin >> N >> M >> X;

	vector < ll > C(N);
	vector < vector < ll >> A(N, vector < ll > (M));
	for (int i = 0; i < N; i++) {
		cin >> C[i];
		for (int j = 0; j < M; j++) {
			cin >> A[i][j];
		}
	}

	ll cost = LLONG_MAX;

	for (ll bits = 1; bits < (1 << N); bits++) {
		vector < ll > understanding(M);
		for (ll i = 0; i < N; i++) {
			if (((bits >> i) & 1) == 0) {
				continue;
			}
			for (ll j = 0; j < M; j++) {
				understanding[j] += A[i][j];
			}
		}

		bool isOk = true;
		for (ll i = 0; i < M; i++) {
			if (understanding[i] < X) {
				isOk = false;
			}
		}
		if (isOk) {
			ll sum = 0;
			for (ll i = 0; i < N; i++) {
				if (((bits >> i) & 1) == 0) {
					continue;
				}
				sum += C[i];
			}
			cost = min(cost, sum);
		}
	}

	if (cost == LLONG_MAX) {
		cout << -1 << endl;
	} else {
		cout << cost << endl;
	}

	return 0;
}


Measured memory_bytes: 3600
using System;
using System.Collections.Generic;
using System.Linq;
 
class Program {
  enum Kind {
    S, H, C, D
  }
 
  static void Main(string[] args) {
 
    var sc = new Scanner();
    int N = sc.NextInt();
    bool[,] have = new bool[4, 13];
    for(int i = 0; i < N; i++) {
      Kind k;
      string s = sc.Next();
      if(s == "S") k = Kind.S;
      else if(s == "H") k = Kind.H;
      else if(s == "C") k = Kind.C;
      else k = Kind.D;
      int j = sc.NextInt();
      j--;
      have[(int)k, j] = true;
    }
 
    for(int i = 0; i < 13; i++) {
      if(have[0, i] == false) Console.WriteLine("S " + (i + 1));
    }
    for(int i = 0; i < 13; i++) {
      if(have[1, i] == false) Console.WriteLine("H " + (i + 1));
    }
    for(int i = 0; i < 13; i++) {
      if(have[2, i] == false) Console.WriteLine("C " + (i + 1));
    }
    for(int i = 0; i < 13; i++) {
      if(have[3, i] == false) Console.WriteLine("D " + (i + 1));
    }
  }
 
  class Scanner {
    string[] inp;
    int ptr;
 
    public Scanner() {
      inp = new string[0];
      ptr = 0;
    }
 
    private void Fetch() {
      if (ptr >= inp.Length) {
        inp = Console.ReadLine().Split(' ');
        ptr = 0;
      }
    }
 
    public int NextInt() {
      Fetch();
      return int.Parse(inp[ptr++]);
    }
 
    public string Next() {
      Fetch();
      return inp[ptr++];
    }
 
    public double NextDouble() {
      Fetch();
      return double.Parse(inp[ptr++]);
    }
  }
 
}

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

int main(){
    int a,b;
    cin>>a>>b;
    int ans=0;
    if(a==b) cout<<2*a;
    else cout<<2*max(a,b)-1;
    return 0;
}

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

using pll = pair<long long, long long>;
int main() {
    int N;
    long long M;
    cin >> N >> M;
    vector<pll> v(N);
    for (int i = 0; i < N; ++i) cin >> v[i].first >> v[i].second;
    sort(v.begin(), v.end());

    long long res = 0;
    for (int i = 0; i < N && M > 0; ++i) {
        res += v[i].first * min(M, v[i].second);
        M -= min(M, v[i].second);
    }
    cout << res << endl;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
const ld PI=3.141592653589793;


int main(){
    ld A,B,H,M; cin>>A>>B>>H>>M;
    ld kaku_H = H*30+M*0.5;
    ld kaku_M = M*6;
    ld kaku = abs(kaku_H-kaku_M);
    kaku = min(kaku,360-kaku);
    kaku *= PI;
    kaku /= 180;
    
    ld ans = sqrt( A*A + B*B - 2*A*B*cos(kaku)  );
    printf("%.10Lf",ans);
}

Measured memory_bytes: 4164
#include <bits/stdc++.h>
using namespace std;
using s64 = signed long long;
using u64 = unsigned long long;
using f128 = long double;

int main()
{
    s64 n;
    cin >> n;
    vector<s64> a(n);
    for(s64 i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    s64 sum = 0;
    for(s64 i = 1; i < n; i++)
    {
        s64 diff = a[i - 1] - a[i];
        if(diff > 0)
        {
            sum += diff;
            a[i] += diff;
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 4784
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef float Item;
static Item *s;
static int N;
void STACKinit(int);
int STACKempty(void);
void STACKpush(Item);
Item STACKpop(void);
int main(void){
  char a[400];
  int i=0;
  scanf("%[^\n]",a);
  int n=strlen(a);
  int stackin=0;
  STACKinit(214748364);
  for(i=0;i<n;i++){
    if(a[i]=='+'){
      STACKpush(STACKpop()+STACKpop());
      stackin--;
    }
    if(a[i]=='-'){
      int l=STACKpop();
      STACKpush(STACKpop()-l);
    }
    if(a[i]=='*'){
      STACKpush(STACKpop()*STACKpop());
    }
    if((a[i]>='0')&&(a[i]<='9')){
      STACKpush(0);
    }
    while((a[i]>='0')&&(a[i]<='9')){
      STACKpush(10*STACKpop()+(a[i++]-'0'));
      stackin++;
    }
  }
  printf("%d\n",(int)STACKpop());
  return 0;
}
void STACKinit(int maxN){
  s=malloc(maxN*sizeof(Item));
  N=0;
}
int STACKempty(void){
  return N==0;
}
void STACKpush(Item item){
  s[N++]=item;
}
Item STACKpop(void){
  return s[--N];
}

Measured memory_bytes: 1832
#include"bits/stdc++.h"
using namespace std;

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

    int64_t ans = 0;
    int64_t left = 0, right = 0;
    int64_t xor_value = 0;

    //まず限界まで右に伸ばす
    for (; right < N; right++) {
        if (A[right] & xor_value) {
            right--;
            break;
        }

        xor_value ^= A[right];
    }
    if (right == N) {
        right--;
    }

    ans += (right + 1) * right / 2 + right + 1;

    while (true) {
        //左を一個消す
        xor_value ^= A[left++];
        if (left >= N) {
            break;
        }

        //右を最大まで伸ばす
        for (right++; right < N; right++) {
            if (A[right] & xor_value) {
                right--;
                break;
            }

            xor_value ^= A[right];
            ans += right - left + 1;
        }
    }

    cout << ans << endl;
}

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

int main() {
  int N;
  int fN = 0;
  cin >> N;
  
  for(int n = N; n > 0; n = n / 10){ 
    fN += n % 10;
  }
  if(N % fN == 0){
    cout << "Yes" << endl;
  }
  else cout << "No " << endl;
}

Measured memory_bytes: 3536
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <complex>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, s;
	cin >> s;
	stack<ll> ss;
	ll cnt = 0;
	while (s != 0) {
		a = s % 26;
		s = s / 26;
		if (a == 0)
			s--;
		ss.push(a);
		cnt++;
		if (s <= 0 && a == 0)
			break;
	}
	char moji;
	for (ll i = 0; i < cnt; i++) {
		int n = 0;
		int x = 1;
		for (moji = 'a'; moji <= 'z'; moji++) {
			if (n + 1 == ss.top()) {
				cout << moji;
				x = 2;
			}
			n++;
		}
		if (ss.top() == 0 && x == 1) {
			cout << 'z';
		}
		ss.pop();
	}
	cout << endl;
	return 0;
}


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

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

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int count[4][3][10];
  int b,f,r,v,i,j,n,k,m,w=0,p=0,a=0,o=0;
  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
	count[i][j][k]=0;
      }
    }
  }
  scanf("%d",&n);
  for(m=0;m<n;m++){
    scanf("%d %d %d %d",&b,&f,&r,&v);
    if(b==1){
      i=0;
      j=f-1;
      k=r-1;
      w=count[i][j][k]+v;
      if(w>9){
	w=9;
      }
      count[i][j][k]=w;
      w=0;
    }else if(b==2){
      i=1;
      j=f-1;
      k=r-1;
      o=count[i][j][k]+v;
      if(o>9){
	o=9;
      }
      count[i][j][k]=o;
      o=0;
    }else if(b==3){
      i=2;
      j=f-1;
      k=r-1;
      p=count[i][j][k]+v;
      if(p>9){
	p=9;
      }
      count[i][j][k]=p;
      p=0;
    }else if(b==4){
      i=3;
      j=f-1;
      k=r-1;
      a=count[i][j][k]+v;
      if(a>9){
	a=9;
      }
      count[i][j][k]=a;
      a=0;
    }
  }
  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
	if(k<10){
	  printf(" ");
	}
	printf("%d",count[i][j][k]);

      }    
      printf("\n");
    }
    if(i<3){
      printf("####################\n");
    }
  }
  return (0);
}

Measured memory_bytes: 612
import math
from heapq import heappop, heappush
N, D, A = map(int, input().split())
D *= 2
enemies = []
for _ in range(N):
    x, h = map(int, input().split())
    enemies.append((x, math.ceil(h / A)))
enemies.sort()

t = 0
ans = 0
attacks = []
attacksum = 0
for f in range(N):
    x, h = enemies[f]
    while attacks:
        if x > attacks[0][0]:
            ax, ad = heappop(attacks)
            attacksum -= ad
        else:
            break
    if h <= attacksum:
        continue
    damage = h - attacksum
    attacksum += damage
    ans += damage
    attacks.append((x + D, damage))

print(ans)

Measured memory_bytes: 95268
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

tenant = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]

n = int(sys.stdin.readline())
for i in range(n):
    b, f, r, v = map(int, sys.stdin.readline().split())
    tenant[b-1][f-1][r-1] += v

separator = '#' * 20
for b in range(4):
    for f in range(3):
        for r in range(10):
            print(' ', tenant[b][f][r], sep='', end='')
        print()
    if b != 3:
        print(separator)



Measured memory_bytes: 5644
n,w=map(int,input().split())

ws=[[] for _ in range(4)]

wi,vi=map(int,input().split())
w1=wi
ws[w1-wi].append(vi)

for i in range(1,n):
    wi,vi=map(int,input().split())
    ws[wi-w1].append(vi)

for i in range(4):
    ws[i]=sorted(ws[i])[::-1]

ans=0
#print(ws)
for i in range(-1,len(ws[0])):
    sum_vi=0
    wi=0

    if(i!=-1):
        sum_vi=sum(ws[0][:i+1])
        wi=w1*(i+1)
    if(wi>w):
#        print("i:{0},wi:{1}".format(i,wi))
        break

    for j in range(-1,len(ws[1])):
        sum_vj=sum_vi
        wj=wi

        if(j!=-1):
            sum_vj=sum_vi+sum(ws[1][:j+1])
            wj=wi+(w1+1)*(j+1)
        if(wj>w):
#            print("i:{0},j:{1},wj:{2}".format(i,j,wj))
            break

        for k in range(-1,len(ws[2])):
            sum_vk=sum_vj
            wk=wj

            if(k!=-1):
                sum_vk=sum_vj+sum(ws[2][:k+1])
                wk=wj+(w1+2)*(k+1)
            if(wk>w):
#                print("i:{0},j:{1},k:{2},wk:{3}".format(i,j,k,wk))
                break

            w_rest=w-wk
            l=w_rest//(w1+3)
            sum_vl=sum_vk
            wl=wk
#            print(sum_vi,sum_vj,sum_vk,wi,wj,wk)
            if(l>len(ws[3])):
                sum_vl+=sum(ws[3])
                wl+=(w1+3)*len(ws[3])
            else:
                sum_vl+=sum(ws[3][:l])
                wl+=(w1+3)*l
#            print("i:{0},j:{1},k:{2},l:{3},wl:{4},w_rest:{5},sum_v:{6}".format(i,j,k,l,wl,w_rest,sum_vl))
            if(ans<sum_vl):
#                print(i,j,k,min(l,len(ws[3])),sum_vl)
                ans=sum_vl
print(ans)

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define pdump(p) cout<<" "<<#p<<"=("<<p.fst<<","<<p.snd<<")"
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std; using lint = long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<lint, lint>;

int main(void) {
    int n; cin >> n;
    vector<int> x(n), y(n), h(n);
    repeat (i, n) cin >> x[i] >> y[i] >> h[i];
    
    auto dist = [](pii p, pii q) -> int {
        return abs(p.fst - q.fst) + abs(p.snd - q.snd);
    };
    
    auto check = [&](pii summit, int height) -> bool {
        repeat (i, n) {
            int d = dist(summit, make_pair(x[i], y[i]));
            if (max(height - d, 0) != h[i]) {
                return false;
            }
        }
        return true;
    };
    
    repeat_to (i, 100) {
        repeat_to (j, 100) {
            pii summit = make_pair(i, j);
            int height = 0;
            repeat (k, n) {
                if (h[k] > 0) {
                    height = h[k] + dist(summit, make_pair(x[k], y[k]));
                    break;
                }
            }
            //dump(i); dump(j); dump(height); el;
            if (check(summit, height)) {
                cout << i << " " << j << " " << height << endl;
            }
        }
    }
}

Measured memory_bytes: 256
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e17;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
const int N=100005;
bool visited[N];int cnt;
int a[N];
void dfs(int u)
{
    visited[u]=1;
    if(u==2)
        return;
    cnt++;
    if(!visited[a[u]])
        dfs(a[u]);
}
void solve()
{

    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    dfs(1);
    if(!visited[2])
    {
        cout<<"-1"<<endl;
    }
    else
        cout<<cnt<<endl;

}

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


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <vector> //動的配列
#include <string>
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <bitset>
#include <numeric>
#include <tuple>




typedef long long ll;


using namespace std;

typedef pair<int, int> P;
#define FOR(i,a,b) for(int i=(int)(a) ; i < (int) (b) ; ++i )
#define rep(i,n) FOR(i,0,n)



ll fast_pow(ll x,ll n,ll mod){
    if (n==0) return 1;
    ll res=fast_pow(x*x %mod,n/2,mod);
    if (n&1) res=res*x%mod;
    return res;
}

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//小さい順から取り出すヒープ
//priority_queue<ll, vector<ll>, greater<ll> > pque1;



int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<int>> v(m);
    rep(i,n){
        int a,b;
        cin>>a>>b;
        a--;
        if (a<m) v[a].push_back(b);
    }
    priority_queue<int> heap;
    int ans=0;
    for (int i=0;i<m;i++){
        for(auto u:v[i]){
            heap.push(u);
        }
        if (heap.size()){
            ans+=heap.top();heap.pop();
        }
    }
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5632
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cstdio>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)

int nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

int main() {
    int N, M;
    cin >> N >> M;

    int ans = 0;

    ans = nCr(N, 2) + nCr(M, 2);

    cout << ans << endl;
    return 0;



}

Measured memory_bytes: 256
import sys
s = list(input())
t = list(input())
ans = float('inf')

for i in range(len(s)):
    count = 0
    for j in range(len(t)):
        if i + j >= len(s):
            print(ans)
            sys.exit()

        if s[i+j] != t[j]:
            count += 1
    ans = min(ans, count)

print(ans)

Measured memory_bytes: 8864
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    int n;
    cin >> n;
    long ans = 0;
    for (int b = 1; b <= n; b++)
    {
        int q = n/b;
        if (q*b < n)
        {
             ans += q;
        }
        else
        {
            ans += q-1;
        }
        
        //cerr << q << ' ' << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0))
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0))
#define P pair<int,int>
#define Sort(a) sort((a).begin(),(a).end())
#define Reverse(a) reverse((a).begin(),(a).end())
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
using namespace std;
void Debug(auto a);

signed main(){
    int k,a,b;
    cin >> k >> a >> b;
    if(b-a<3 || k<=a){
        cout << k+1 << endl;
        return 0;
    }
    int n=a;
    k -= a-1;
    if(k%2==1){
        n++;
        k--;
    }
    int t = k / 2;
    n += t * (b-a);
    cout << n << endl;

    return 0;
}



void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}

Measured memory_bytes: 256