akhauriyash/Code-Regression huggingface dataset:
// itne me hi thakk gaye?
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("-O3")
#define ll long long 
#define ull unsigned long long
using ld = long double;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const ll rk = 256;
const ld PI = 3.141592653589793;
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define print(a) for(auto j:a) {cout<<j<<",";} cout << "\n";
#define endl '\n'
#define whatis(x) cout << "> "<<#x << " ==> " << x << endl;
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
// // Printing pair
ostream & operator << (ostream & os, pair <ll, ll> const& x) {
    os << x.first << "," << x.second;
    return os;
}
 
// printing vector
template <class T>
ostream & operator << (ostream & os, vector <T> const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
 
// printing set
template <class T>
ostream & operator << (ostream & os, set <T> const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
 
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
 
template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
    return os << "[ " << p.first << ", " << p.second << "]" ;
}
const int mxn = 1e5+5;

int32_t main(){
    int n, k;cin>>n >> k;
    vc <ll> arr(n);
    for(int i=0; i<n; i++) cin >> arr[i];
    vc <ll> dp(n, inf);
    dp[0] = 0;
    for(int i=0; i<n; i++) {
        for(auto j=i+1; j<=i+k; j++) {
            if (j<n) {
                dp[j] = min(dp[j], dp[i] + abs(arr[i] - arr[j]));
            }
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}

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

using namespace std;

#define ll long long
#define pb push_back

const int mod = 1e9 + 7;
const int INF = 1e9;
const int N = 2e5 + 5;

int main(){
	ll n, m, k;
	cin >> n >> m >> k;
	ll a[N], b[N];
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= m; i++) cin >> b[i];
	vector <ll> prefa(n + 1);
	prefa[0] = 0;
	for(ll i = 1; i <= n; i++){
		prefa[i] = prefa[i - 1];
		prefa[i] += a[i];
	}
	vector <ll> prefb(m + 1);
	prefb[0] = 0;
	for(ll i = 1; i <= m; i++){
		prefb[i] = prefb[i - 1];
		prefb[i] += b[i];
	}
	ll ans = 0;
	for(ll i = 1; i <= n; i++){
		if(prefa[i] > k) break;
		ll pos = upper_bound(prefb.begin(), prefb.end(), k - prefa[i]) - prefb.begin();
		pos--;
		ans = max(ans, i + pos);
	}
	for(int i = 1; i <= m; i++){
		if(prefb[i] > k) break;
		ll pos = upper_bound(prefa.begin(), prefa.end(), k - prefb[i]) - prefa.begin();
		pos--;
		ans = max(ans, i + pos);
	}
	cout << ans << endl;
}

Measured memory_bytes: 9528
#include<bits/stdc++.h>
#include <atcoder/all>
#define mp make_pair
#define fi first
#define se second
#define INF 10000000000000000LL
#define ll  long long 
const long long  inf =1e18+44;
const int MAX=3e5+9;
const ll MOD=1e9+7;
const int TOT_PRIMES=1e6+9;
const int MAX_A=71;
const int LN=20;
const double eps=1e-1;
using namespace std;
using namespace atcoder;
int dp[2000][2000];
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int n;
    cin>>n;
    string s= "ACL";
    for(int i=0;i<n;i++)
        cout<<s;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>

using namespace std;

typedef long long ll;

int main() {
    ll x, a, b; cin >> x >> a >> b;

    cout << x - a - (x-a)/b *b << endl;

    return 0;   
}

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

// const int mod=1e9+7;
// int n,k;
// long long a[100010];
// long long jc[100010]={1},inv[100010]={1};

// long long pow(long long a,int b)
// {
// 	long long ans=1;
// 	while(b)
// 	{
// 		if(b&1) ans=ans*a%mod;
// 		a=a*a%mod;
// 		b>>=1;
// 	}
// 	return ans;
// }

// inline long long c(int n,int m){return jc[n]*inv[m]%mod*inv[n-m]%mod;}

// int main()
// {
// 	// freopen("test.in","r",stdin);
// 	scanf("%d%d",&n,&k);
// 	if(k==1)
// 	{
// 		puts("0");
// 		return 0;
// 	}
// 	for(int i=1;i<=n;i++)
// 		scanf("%lld",a+i),jc[i]=jc[i-1]*i%mod,inv[i]=pow(jc[i],mod-2);
// 	std::sort(a+1,a+1+n);
// 	for(int i=1;i<=n;i++) a[i]+=a[i-1],a[i]%=mod;
// 	long long ans=0;
// 	for(int i=k;i<=n;i++)
// 	{
// 		long long s=((a[n]-a[i-1]-a[n-i+1])%mod+mod)%mod;
// 		ans+=s*c(i-2,k-2)%mod;
// 		ans%=mod;
// 	}
// 	printf("%lld\n",ans);
// 	return 0;
// }
#include<bits/stdc++.h>


int n,m;
char mp[23][23];
int dis[23][23];
int d[4][2]={0,-1,0,1,-1,0,1,0};
int main()
{
	// freopen("test.in","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
		scanf("%s",mp+i);
	int ans=-1;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(mp[i][j]=='#') continue;
			memset(dis,-1,sizeof(dis));
			std::queue<std::pair<int,int> > q;
			dis[i][j]=0;
			q.push(std::make_pair(i,j));
			while(!q.empty())
			{
				std::pair<int,int> temp=q.front();
				q.pop();
				int x=temp.first,y=temp.second;
				ans=std::max(ans,dis[x][y]);
				for(int dd=0;dd<4;dd++)
				{
					int xx=x+d[dd][0],yy=y+d[dd][1];
					if(xx>=n||xx<0||yy>=m||yy<0) continue;
					if(mp[xx][yy]=='#') continue;
					if(dis[xx][yy]>-1) continue;
					dis[xx][yy]=dis[x][y]+1;
					q.push(std::make_pair(xx,yy));
				}
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {

	int a, b, x, y, z;
	int max = 0;
	cin >> a >> b;

	x = a + b;
	max = x;
	y = a - b;
	if (max < y) {
		max = y;
	}
	z = a * b;
	if (max < z) {
		max = z;
	}


	cout << max << endl;
	

	

}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX 100000

int parent (int i)
{
  return i/2;
}

int left (int i)
{
  return 2*i;
}

int right (int i)
{
  return 2*i+1;
}

int main()
{
  int n, i, a[MAX+1];

  scanf("%d", &n);
  for(i=1; i<=n; i++)
    scanf("%d", &a[i]);

  for(i=1; i<=n; i++) {
    printf("node %d: key = %d, ", i, a[i]);
    if(parent(i) >= 1)
      printf("parent key = %d, ", a[parent(i)]);
    if(left(i) <= n)
      printf("left key = %d, ", a[left(i)]);
    if(right(i) <= n)
      printf("right key = %d, ", a[right(i)]);
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 608
#include <iostream>
using namespace std;
int main()
{
  int d,n,count;
  cin >> d >> n;
  int x = 1;
  for(int i = 0;i < d;i++)
  {
    x = x * 100;
  }
  if(n != 100)
  {
    cout << n * x << "\n";
  }
  else
  {
    cout << (n + 1) * x << "\n";
  }


  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

int main() {
	// your code goes here
	ll a;
	long double b;
	cin>>a>>b;
	ll res = a*b;
// 	cout<<res<<endl;
	cout<<res<<endl;
	return 0 ;
	
}


Measured memory_bytes: 3720
#include <iostream>
#include <queue>
#include <functional>
#include <vector>
#include <cmath>
#include <stack>

using namespace std;

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

#define INF 10000000000

int main() {
	int n;
	cin >> n;
	vector<Q> d(n);
	for (int i = 0; i < n; i++) {
		cin >> d[i].first >> (d[i].second).first >> (d[i].second).second;
	}
	vector< vector< vector<long long int> > > dp(1<<n, vector< vector<long long int> >(n, vector<long long int>(2, INF)));
	for (int i = 0; i < (1<<n); i++) {
		for (int j = 0; j < n; j++) {
			if (i == 0) {
				dp[i][j][0] = dp[i][j][1] = 0;
				for (int k = 0; k < n; k++) {
					if ((i & (1<<k)) == 0) {
						dp[(i|(1<<k))][k][0] = 0;
						dp[(i|(1<<k))][k][1] = (d[k].second).second;
					}
				}
			} else if (dp[i][j][0] != INF){
				for (int k = 0; k < n; k++) {
					if ((i & (1<<k)) == 0) {
						if (dp[(i|(1<<k))][k][0] > dp[i][j][0] + abs((d[j].second).first-(d[k].second).first)*(70+20*dp[i][j][1])) {
							dp[(i|(1<<k))][k][0] = dp[i][j][0] + abs((d[j].second).first-(d[k].second).first)*(70+20*dp[i][j][1]);
							dp[(i|(1<<k))][k][1] = dp[i][j][1] + (d[k].second).second;
						}
					}
				}
			}
		}
	}
	long long int MIN = dp[(1<<n)-1][0][0];
	int p = 0;
	for (int i = 0; i < n; i++) {
		if (dp[(1<<n)-1][i][0] < MIN) {
			MIN = dp[(1<<n)-1][i][0];
			p = i;
		}
	}
	stack<int> stk;
	stk.push(p);
	long long int k = (1<<n)-1;
	long long int r = dp[k][p][0];
	k -= (1<<p);
	while (k != 0) {
		for (int i = 0; i < n; i++) {
			if (i != p && dp[k][i][0] != INF && dp[k][i][0]+abs((d[i].second).first-(d[p].second).first)*(70+20*dp[k][i][1])==r) {
				r = dp[k][i][0];
				p = i;
				break;
			}
		}
		k -= (1<<p);
		stk.push(p);
	}
	cout << d[stk.top()].first;
	stk.pop();
	while (!stk.empty()) {
		cout << ' ' << d[stk.top()].first;
		stk.pop();
	}
	cout << endl;
	return 0;
}

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

int main() {
  int n, p;
  cin >> n >> p;
  string s;
  cin >> s;
  if (10%p == 0) { // 2,5
    ll ans = 0;
    for(int r = 0; r < n; r++) {
      if ((s[r]-'0') % p == 0) {
        ans += r+1;
      }
    }
    cout << ans << endl;
    return 0;
  }

  vector<int> d(n+1);
  int ten = 1;
  for (int i = n-1; i >= 0; --i) {
    int a = (s[i]-'0') * ten % p;
    d[i] = (d[i+1]+a) % p;
    ten *= 10; ten %= p;
  }
  vector<int> cnt(p);
  ll ans = 0;
  for (int i = n; i >= 0; --i) {
    ans += cnt[d[i]];
    cnt[d[i]]++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1412
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double PI = 3.14159265358979;
const double E = 2.718281828459045;
const double root2 = sqrt(2);
typedef pair<int, int> P;
typedef unsigned int ui;
int main() {
	string s; int k; cin >> s >> k;
	vector<string> t;
	int n = s.length();
	for (int i = 0; i < n; i++) {
		for (int j = i; j < i+5; j++) {
			t.push_back(s.substr(i, j - i + 1));
		}
	}
	sort(t.begin(), t.end());
	int count = 0; int now = 0; string memo;
	while (count < k) {
		count++;
		memo = t[now];
		while (now<(int)t.size() && memo == t[now])now++;
	}
	cout << memo << endl;
	char nyaa;
	std::cin >> nyaa;
	return 0;
}


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

int main()
{
	while (true) {
		int n;
		cin >> n;

		if (n == 0) {
			break;
		}

		int count = 0;
		bool leftdown = true;
		bool rightdown = true;
		bool up = false;

		for (int i = 0; i < n; i++) {
			string str;
			cin >> str;

			if (str == "lu") {
				leftdown = false;
				if (up == false && rightdown == false) {
					up = true;
					count++;
				}
			}
			else if (str == "ru") {
				rightdown = false;
				if (up == false && leftdown == false) {
					up = true;
					count++;
				}
			}
			else if (str == "ld") {
				leftdown = true;
				if (up == true && rightdown == true) {
					up = false;
					count++;
				}
			}
			else {
				rightdown = true;
				if (up == true && leftdown == true) {
					up = false;
					count++;
				}
			}
		}

		cout << count << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3112
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman001 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
typedef long long ll;
using namespace std;
ll n,m;
priority_queue<ll>q;
int main()
{
    abdelrahman001
    cin >> n >> m;
    for(int i = 0,x;i<n;i++)
        cin >> x,q.push(x);
    while(m--)
    {
        ll x = q.top();
        q.pop();
        q.push(x/2);
    }
    ll ans = 0;
    while(!q.empty())
        ans+=q.top(),q.pop();
    cout << ans;
    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
	int count = 0;
	cin >> n;
	int x = n+1;
	vector<int> p(n);
	for(int i=0;i<n;i++) cin >> p.at(i);
	// vector<int> q(n);
	// q = p;
	for(int i=0;i<n;i++){
		if(x > p.at(i)){
			count++;
			x = p.at(i);
		}
		continue;
	}
	cout << count;
	vector<int>().swap(p);
	// vector<int>().swap(q);
}


Measured memory_bytes: 1024
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"


def main():
    S = input()
    t = "JOI"
    idx = 0
    ans = 0
    num = [0, 0, 0]
    for k, g in groupby(S):
        if k == t[idx]:
            num[idx] = len(list(g))
            if k == "I":
                if num[1] <= num[0] and num[1] <= num[2]:
                    ans = max(ans, num[1])
                idx = 0
            else:
                idx += 1
        else:
            if k == "J":
                idx = 1
                num[0] = len(list(g))
            else:
                idx = 0

    print(ans)


if __name__ == '__main__':
    main()



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

int n;
char s[102], t[102];

int main(){
	scanf("%d%s%s", &n, s, t);
	for(int i = n; i >= 1; i--){
		int fl = 1;
		for(int j = 0; j < i; j++){
			if(s[n - i + j] != t[j]){ fl = 0; break; }
		}
		if(!fl) continue;
		printf("%d\n", 2 * n - i);
		return 0;
	}
	printf("%d\n", 2 * n);
}

Measured memory_bytes: 256
package main

import(
    "fmt"
    "sort"
    "strings"
)



func main() {
    var n int
    fmt.Scan(&n)
    ans := "ABC"
    if n>=1000{
        ans = "ABD"
    }
    fmt.Println(ans)
}





func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func scanTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func SortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}


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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    cout << "A" << b[0] << "C" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<(int)N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=0;i--)
#define p(s) cout<<(s)<<endl
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf=1e9;

int N;
int ans;
int main() {
	cin>>N;
	REP(i,0,N){
		int l,r;
		cin>>l>>r;
		ans+=r-l+1;
	}
	p(ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define fs first
#define sc second
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<tuple<ll,ll>> vtl;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

void solve(){
    ll n,m;
    cin>>n>>m;
    vl a(n),b(n);
    rep(i,n)cin>>a[i]>>b[i];
    vtl v(n);
    rep(i,n)v[i]=make_tuple(a[i],b[i]);
    sort(v.begin(),v.end());
    ll sum=0,cnt=0;
    rep(i,n){
        rep(j,get<1>(v[i])){
            sum+=get<0>(v[i]);
            cnt++;
            if(cnt==m)break;
    }
    if(cnt==m)break;
    }
    cout<<sum;
}

int main(){
    cout<<std::fixed<<std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
}

Measured memory_bytes: 3456
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.conv, std.stdio, std.typecons;

void main()
{
  auto rd = readln.split.map!(to!int);
  auto a = rd[0], b = rd[1];
  writeln(a * b, " ", (a + b) * 2);
}

Measured memory_bytes: 2504
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int main()
{
	int f=0;
	int i;
    char ch[102];
    scanf("%s",ch);
    for(i=0;i<3;i++)
    {
    	if(ch[i]=='7')
    	{
    		f=1;
    		printf("Yes");
    		break;
		}
	}
	if(f!=1)
	printf("No");
}


Measured memory_bytes: 3776
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define Q_MAX 100000

int main(void) {
  int Q, *l, *r;
  int n[Q_MAX+1] = {}, p[Q_MAX+1] = {};
  scanf("%d", &Q);
  l = (int*)calloc(Q, sizeof(int));
  r = (int*)calloc(Q, sizeof(int));
  for (int i = 0; i < Q; i++) {
    scanf("%d %d", &l[i], &r[i]);
  }
  for (int i = 2; i <= Q_MAX; i++) {
    p[i] = 1;
  }

  for (int i = 2; i <= Q_MAX; i++) {
    if (p[i] && i <= Q_MAX / 2) {
      for (register int k = 2; i*k <= Q_MAX; k++) {
        p[i*k] = 0;
      }
    }
    n[i] = n[i-1] + (p[i] && p[(i+1)/2]);
  }

  for (int i = 0; i < Q; i++) {
    printf("%d\n", n[r[i]] - n[l[i]-1]);
  }

  return 0;
}


Measured memory_bytes: 2048
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    if N == 0:
        if A[0] > 1:
            print(-1)
            return
        elif A[0] == 1:
            print(1)
            return

    else:
        if A[0] >= 1:
            print(-1)
            return


    for i in range(N+1):
        if A[i] > 2**i:
            print(-1)
            return
    

    safe_line = [0]*(N+1)
    safe_line[N] = A[N]
    for i in range(N-1,-1,-1):
        safe_line[i] = safe_line[i+1]+A[i]

    prev = 1
    answer = 1
    
    for i in range(1,N+1):
        cur = min(prev*2,safe_line[i])
        answer += cur
        prev = cur - A[i]
        
        if prev <= 0 and i < N:
            print(-1)
            return
        elif prev < 0 and i <= N:
            print(-1)
            return
    
    print(answer)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N - 0 + 1)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 81672
#include <stdio.h>
int main(void)
{
  char x[128], y[128], z[256];
  int n, m, i, j, k;
  
  scanf("%s",&x);
  scanf("%s",&y);
 
  n = strlen(x);
  m = strlen(y);
  
  for(i = 0; i < 2 * n; i++){
    z[i] = x[i % n];
  }
 
  for(i = 0; i < n; i++){
    for(j = 0; j < m; j++){
      if(z[i + j] == y[j])
	k++;
    }
    if(k == m){
      printf("Yes\n");
      break;
    }
    k = 0;
  }
  
  if(k == 0)
    printf("No\n");
  
  return 0;
} 


Measured memory_bytes: 2148
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
#include<stdlib.h>
//#include<math.h>
#include<string.h>
//#include<time.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
int Xtoi(char*, int);
int main() {
	char f[127], s[127], sum[127];
	char tf[127],ts[127],tsum[127];
	int i, a, b, c;
	while (~fscanf(stdin, "%[0-9X]+%[0-9X]=%[0-9X]", f,s,sum) != NULL) {
		getchar();
		for (i = 0; i < 10; i++) {		
			a = Xtoi(f, i);
			b = Xtoi(s, i);
			c = Xtoi(sum, i);
			if (a + b == c) break;
		}
		if(i!=10) P(d, i);
		else puts("NA");
	}
	return 0;
}

int Xtoi(char *s, int n){
	int val = 0, i;
	if (*s == 'X'&&s[1] != '\0'&&n == 0) return -1;
	for (i = 0; i < (signed)strlen(s); i++) {
		val *= 10;
		if (s[i] == 'X') val += n;
		else val += s[i] - '0';
	}
	return val;
}

Measured memory_bytes: 564
N, D = map(int, input().split())
X = []
for i in range(N):
    X.append([int(a) for a in input().split()])

def isint(a, b):
    s = 0
    for i in range(D):
        s += (X[a][i]-X[b][i])**2
    if int(s**0.5+0.5) ** 2 == s:
        return 1
    return 0

ans = 0
for a in range(N):
    for b in range(a+1, N):
        ans += isint(a, b)
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
const int n=100000000;
#define r(i,n) for(int i=2; i<n; i++)
typedef long long ll;
using namespace std;

int main(void){
  int a, b;
  cin >> a >> b;
  if(a%b==0){cout << "-1" << endl;return 0;}
  r(i,n){
    if(a*i%b!=0){cout << a*i << endl;return 0;}
  }
  return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using p  = pair<int, int>;
using vec_int = vector<int>;
using vec_str = vector<string>;
#define INF (1<<29)
ll ans = 0;

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}

void debug_input(vec_str& argv)
{
    // デバッグ用引数読み込み
    ifstream file("./input.txt");
    string str;
    while( getline(file, str) ) {
        argv.push_back(str);
    }
}

void debug_split_string(const string& str, vec_str& v)
{
    stringstream ss{str};
    string buf;
    while (getline(ss, buf, ' ')) {
        v.push_back(buf);
    }
}

void debug_split_int(const string& str, vec_int& v)
{
    stringstream ss{str};
    string buf;
    while (getline(ss, buf, ' ')) {
        istringstream ss(buf);
        int temp;
        ss >> temp;
        v.push_back(temp);
    }
}

int main()
{
    ll X = 0;
	cin >> X;

    ans = 1;
    ll money = 100;
    while(1) {
    
        money = (ll)(money * 1.01);
        if( money >= X ) {
            break;
        }
        ans++;
    }

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

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

struct Problem{
    int n,m;
    vector<pair<int,pair<int,int>>> c;
    vector<vector<LL>> dp_;
    vector<LL> sum_;
    Problem(LL n, LL m):n(n),m(m),dp_ (n+1,vector<LL>(n+1)),sum_(n+1){};

    void solve(){
        auto dp = [&](int x, int y) -> auto& {return dp_[x+1][y+1];};
        auto sum = [&](int x) -> auto& {return sum_[x+1];};
        for(int i=0; i<m; ++i){
            int l,r,x;
            cin >> l >> r >> x;
            --l;--r;
            c.push_back({r,{l,x}});
        }
        sort(c.begin(),c.end());

        dp(-1,-1)=3;
        sum(-1)=3;
        int k = 0;
        while(k<(int)c.size() and c[k].first==0){
            if(c[k].second.second>1){
                cout << 0 <<"\n";
                return;
            }
            k++;
        }
        for(int i=1; i<n; ++i){
            for(int j=-1; j<i-1; ++j){
                DBG(i,j)
                dp(i-1,j)+=sum(j)+(j==-1?dp(-1,-1):0);
                dp(i-1,j)%=MOD;
                sum(i-1)+=sum(j)+(j==-1?dp(-1,-1):0);
                sum(i-1)%=MOD;
                sum(j)+=sum(j)+(j==-1?dp(-1,-1):0);
                sum(j)%=MOD;
            }
            DBG(dp_)
            while(k<(int)c.size() and c[k].first==i){
                DBG(c[k])
                for(int j=-1; j<i; ++j){
                    int ub = j==-1?-1:j-1;
                    for(int l=-1; l<=ub; ++l){
                        int cnt = (j>=c[k].second.first)+(l>=c[k].second.first)+1;
                        if(cnt!=c[k].second.second){
                            sum(j)+=MOD-dp(j,l);
                            sum(j)%=MOD;
                            if(j>-1){
                                sum(l)+=MOD-dp(j,l);
                                sum(l)%=MOD;
                            }
                            dp(j,l)=0;
                        }
                    }
                }
                k++;
            }
            DBG(dp_)
            DBG(sum_)
        }
        LL ans =0;
        for(int i=-1; i<n-1; ++i){
            for(int j=-1; j<n-1; ++j){
                DBG(i,j,dp(i,j))
                ans += dp(i,j);
                ans %= MOD;
            }
        }
        cout << ans << "\n";
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    long long n=0,m;
    cin >> n >> m;
    Problem p(n,m);
    p.solve();
    return 0;
}



Measured memory_bytes: 1024
#include <stdio.h>
#define MXSZ 5005
#define INF 10000000001
typedef struct mk{
    long long u,v,c;
}data;
data input[MXSZ];
long long cost[MXSZ];
long long max(long long a,long long b){return (a<b)?b:a;}
long long min(long long a,long long b){return (a>b)?b:a;}
void bellmanFord(long long n,long long m){
    for(int i = 0;i<=n;i++) cost[i] = INF;
    cost[1]= 0;
    for(int i = 0;i<n+n;i++){
        for(int j = 0;j<m;j++){
            long long u = input[j].u;
            long long v = input[j].v;
            long long c = input[j].c;
            if(cost[u]!=INF && cost[u]+c<cost[v]){
                if(i<=n) cost[v] = max(-INF, min(INF,cost[u]+c));
                else cost[v] = -INF;
            }
        }
    }
}
void MRoy(){
    long long n,m,p,a,b,c;
    scanf("%lld%lld%lld",&n,&m,&p);
    for(long long i = 0;i<m;i++){
        scanf("%lld%lld%lld",&a,&b,&c);
        input[i].c = -c+p;
        input[i].u = a;
        input[i].v = b;
    }
    bellmanFord(n,m);
    if(cost[n]==-INF) printf("-1\n");
    else printf("%lld\n",max(0,-cost[n]));
}
int main(){
    MRoy();
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

typedef pair<ll,const char*> parsed;

parsed expr(const char*);
parsed term(const char*);
parsed fact(const char*);

parsed expr(const char* s)
{
	//cout<<"expr(\""<<s<<"\")"<<endl;
	parsed now=term(s);
	while(*now.second=='+' || *now.second=='-'){
		char op=*now.second;
		parsed next=term(now.second+1);
		if(op=='+')
			now=parsed(now.first+next.first,next.second);
		else
			now=parsed(now.first-next.first,next.second);
	}
	//cout<<"expr(\""<<s<<"\")="<<now.first<<endl;
	return now;
}

parsed term(const char* s)
{
	//cout<<"term(\""<<s<<"\")"<<endl;
	parsed now=fact(s);
	while(*now.second=='*' || *now.second=='/'){
		char op=*now.second;
		parsed next=fact(now.second+1);
		if(op=='*')
			now=parsed(now.first*next.first,next.second);
		else
			now=parsed(now.first/next.first,next.second);
	}
	//cout<<"term(\""<<s<<"\")="<<now.first<<endl;
	return now;
}

parsed fact(const char* s)
{
	//cout<<"fact(\""<<s<<"\")"<<endl;
	//if(s[0]=='('){
	//	parsed res=expr(s+1);
	//	res.second++;
	//	return res;
	//}
	//else{
	//	const char* p=s;
	//	if(*p=='-')
	//		p++;
	//	ll n=0;
	//	while(isdigit(*p)){
	//		n=n*10+*p-'0';
	//		p++;
	//	}
	//	return parsed(n,p);
	//}
	
	if(isdigit(s[0])){
		const char* p=s;
		if(*p=='-')
			p++;
		ll n=0;
		while(isdigit(*p)){
			n=n*10+(*p-'0');
			p++;
		}
		return parsed(n,p);
	}
	else if(s[0]=='('){
		parsed res=expr(s+1);
		//if (*res.second!=')') exit(0);
		res.second++;
		return res;
	}
	else
		exit(0);
}

int main()
{
	string s;
	getline(cin,s);
	while(getline(cin,s))
		cout<<expr(s.c_str()).first<<endl;
	
	return 0;
}

Measured memory_bytes: 0
from math import gcd
K = int(input())
ans =0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        a = gcd(i, j)
        if a == 1:
            ans += K
            continue
        for k in range(1, K + 1):
            ans += gcd(a, k)
print(ans)


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

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

	int ans=0;
	if(x<=3) ans+=(4-x)*100000;
	if(y<=3) ans+=(4-y)*100000;
	if(x==1 && y==1) ans+=400000;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
fn main() {
 let v: Vec<usize>=r();
 let (x, y, z) = (v[0], v[1],v[2]);
 let a = s(v[0]);
 let b = s(v[1]);
 let mut c = vec![vec![0usize; z]; x];
 for k in 0..z{
  for i in 0..x{
   for j in 0..y{
    c[i][k] += a[i][j] * b[j][k]
   }
  }
 }
 for i in 0..c.len(){
  let mut d=c[i].len();
  for j in 0..d {
   if j != d-1{
    print!("{} ", c[i][j]);
   }else{
    println!("{}", c[i][j]);
   }
  }
 }
}
fn r<T:std::str::FromStr>()->Vec<T>{
 let mut b=String::new();
 let s=std::io::stdin();
 s.read_line(&mut b).unwrap();
 b.split_whitespace().flat_map(str::parse).collect()
}
fn s(i:usize)->Vec<Vec<usize>>{
 let mut a: Vec<Vec<_>> = vec![];
 for _ in 0..i{
  let w: Vec<usize>=r();
  a.push(w);
 }
 a
}



Measured memory_bytes: 5056
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)

using ll=long long;

int main() {
  int X;
  cin >>X;
  int vec[41];
  vec[0]=1;
  vec[1]= 4;
  vec[2]= 8;
  vec[3]= 9;
  vec[4]= 16;
  vec[5]= 25;
  vec[6]= 27;
  vec[7]= 32;
  vec[8]=36 ;
  vec[9]= 49;
  vec[10]=64;
  vec[11]= 81;
  vec[12]= 100;
  vec[13]= 121;
  vec[14]= 125;
  vec[15]= 128;
  vec[16]= 144;
  vec[17]= 169;
  vec[18]=196 ;
  vec[19]=216 ;
  vec[20]= 225;
  vec[21]= 243;
  vec[22]= 256;
  vec[23]=289 ;
  vec[24]= 324;
  vec[25]= 343;
  vec[26]=361;
  vec[27]= 400;
  vec[28]= 441;
  vec[29]= 484;
  vec[30]=512 ;
  vec[31]= 529;
  vec[32]= 576;
  vec[33]= 625;
  vec[34]= 676;
  vec[35]= 729;
  vec[36]=784 ;
  vec[37]= 841;
  vec[38]= 900;
  vec[39]= 961;
  vec[40]= 1000;
  if(X !=1000) {
  rep(i,40) {
    if((X>=vec[i])&&(X<vec[i+1])) {
      cout<<vec[i]<< endl;
      break;
    }
  }
  }
    
    
  else {
    cout <<1000<< endl;
  }
  
  
}
  


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

int main() {
    while(1){
        char str[1001];
        scanf("%s",str);
        if(str[0]=='0') break;
        int sum=0;
        for(int i=0;i<strlen(str);i++){
            sum+=str[i]-'0';
        }
        printf("%d\n",sum);
    }

}


Measured memory_bytes: 3200
#include <iostream>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=10000;

int main(){
	int N;
	cin>>N;
	int M=0,Sum=0,p;
	rep(i,N){
		cin>>p;
		Sum+=p;
		M=max(M,p);
	}
	Sum-=M/2;
	cout<<Sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Maxn 5007
using namespace std;
int n,k,cnt=0;
int last[Maxn],pre[Maxn],other[Maxn];
void insert(int u,int v)
{
	other[++cnt]=v,pre[cnt]=last[u],last[u]=cnt;
}
int dfs(int u,int fa,int now)
{
	int res=1;
	if (now<k/2)
	{
		for (int q=last[u];q;q=pre[q])
		{
			int v=other[q];
			if (v!=fa) res+=dfs(v,u,now+1);
		}
	}
	return res;
}
int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		insert(u,v),insert(v,u);
	}
	int ans=0;
	if (k%2==0)
	{
		for (int i=1;i<=n;i++)
			ans=max(ans,dfs(i,-1,0));
	} else
	{
		for (int i=1;i<=n;i++)
			for (int q=last[i];q;q=pre[q])
			{
				int v=other[q];
				ans=max(ans,dfs(v,i,0)+dfs(i,v,0));
			}
	}
	printf("%d\n",n-ans);
	return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

bool solve() {
	ll a, b, v, w, t;
	cin >> a >> v >> b >> w >> t;
	return abs(a-b) <= (v-w)*t;
}

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

	cout << (solve() ? "YES" : "NO") << endl;
}



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

using namespace std;

int main()
{
    int L, R, d;
    int n = 0;
    while (cin >> L >> R >> d) {
        for (int i = d; i <= R; i += d) {
            if (i < L)
                continue;
            n++;
        }
    }
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <stack>
using namespace std;
string s;
stack<char> w;
main()
{
	ios::sync_with_stdio(false);
	cin>>s;
	int len=s.length();
	for (int i=0;i<len;i++)
	 if (s[i]=='T')
	 {
	 	if (!w.empty())
	 	{
	 		if (w.top()=='S') w.pop();
	 		else w.push(s[i]);
		}
		else w.push(s[i]);
	 }
	 else w.push(s[i]);
	int ans=0;
	while (!w.empty())
	{
		w.pop();
		ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 720
#include<stdio.h>

int main(int argc, char *argv[])
{
	int a,b;
	scanf("%d%d", &a, &b);

	if (1 <= a && b <= 100) 
	{
		int A = a * b; 
		int S = a + a + b + b; 
		printf("%d %d\n", A, S);

	}
	else
	{
		printf("error");
	}
	return 0;
}

Measured memory_bytes: 2720
#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 1e6 + 5;

int in[N];
int cnt[N];
vector< int> divs[N];

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

    for (int i = 1; i < N; i++) {
        for (int j = i + i; j < N; j += i) {
            divs[j].push_back(i);
        }
    }
    
    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> in[i];
        cnt[in[i]]++;
    }

    int res = 0;
    for (int i = 0; i < n; i++) {
        int ok = 1;
        for (int x : divs[in[i]]) {
            if (cnt[x] > 0) {
                ok = 0;
                break;
            }
        }
        if (cnt[in[i]] > 1) ok = 0;
        res += ok;
    }

    cout << res << endl;
}

Measured memory_bytes: 122364
a[200],b[200],c[1000],d[1000],n,m,i,j,k,t,w,q;main(){for(;;){scanf("%d",&n);if(n==0)break;for(i=0;i<n;i++){scanf("%d%d",&a[i],&b[i]);}scanf("%d",&m);for(i=0;i<m;i++){scanf("%d%d",&c[i],&d[i]);}for(i=0;i<m;i++){w=c[i]-a[0];q=d[i]-b[0];for(j=1;j<n;j++){for(k=0;k<m;k++){if(a[j]+w==c[k]){if(b[j]+q==d[k]){t++;break;}}}}if(t==n-1){printf("%d %d\n",w,q);t=0;break;}t=0;}}return 0;} 

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

int main(){
  
    int m, n;
    cin >> m >> n;
    
    int aux = 1;
    int res = 0; 
        
    while(true){
        if(aux >= n){break;}
        --aux;
        aux += m;
        res++;
    }

    cout << res <<"\n";
    
    
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<ll> vll;
const int MN = 1e5+5, MOD=1e9+7;
ll lcm (ll a, ll b) {return a*b/__gcd(a,b);}
ll multiplyMod(ll a, ll b) { return (a % MOD * b % MOD) % MOD; }
ll addMod(ll a, ll b) { return (a % MOD + b % MOD) % MOD; }
ll subMod(ll a, ll b) { return (a % MOD - b % MOD) % MOD; }
ll fpow(ll b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
ll a, b;
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> a >> b;
    cout << lcm(a, b) << "\n";

    return 0;

}

Measured memory_bytes: 256
N, K = map(int, input().split())
S = input()

R = []
tmp = None
for i in range(N):
  if tmp == None:
    tmp = (1, S[i])
  else:
    if S[i] == tmp[1]:
      tmp = (tmp[0]+1, S[i])
    else:
      R.append(tmp)
      tmp = (1, S[i])
else:
  R.append(tmp)

len_r = len(R)
for k in range(K):
  if len_r >= 3:
    len_r -= 2
  elif len_r == 2:
    len_r -= 1
  else:
    break
print(N - len_r)

Measured memory_bytes: 10356
package main

import (
	"fmt"
	"strings"
)

func main() {
	var N int
	var S string
	var count, max int
	fmt.Scan(&N)
	fmt.Scan(&S)
	a := "abcdefghijklmnopqrstuvwxyz"
	for i := 1; i < N; i++ {
		count = 0
		X := S[0:i]
		Y := S[i:len(S)]
		for j := 0; j < len(a); j++ {
			if strings.Contains(X, string(a[j])) && strings.Contains(Y, string(a[j])) {
				count++
			}
			if count > max {
				max = count
			}
		}
	}
	fmt.Println(max)
}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#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...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

struct work_t {
  int day, gain;
  bool operator<(const work_t& rhs) const {
    if (day != rhs.day) return day < rhs.day;
    return gain < rhs.gain;
  }
};

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N, M;
  while (cin >> N >> M) {
    vector<work_t> works(N);
    for (auto& w : works) cin >> w.day >> w.gain;
    sort(works.begin(), works.end());
    priority_queue<int> q;
    ll res = 0;
    for (int d = N - 1, i = 0; d >= 0; d--) {
      while (i < N && d + works[i].day <= M) {
        q.push(works[i].gain);
        ++i;
      }
      if (!q.empty()) {
        res += q.top();
        q.pop();
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 1660
#include "math.h"

#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
using namespace std;
typedef long long  ll;
/** Problem0162 : Hamming Numbers **/
int main()
{
	set<int> h;

	rep(i, 20) {
		rep(j, 20) {
			rep(k, 20) {
				h.insert(pow(2.0, i)*pow(3.0, j)*pow(5.0,k));
			}
		}
	}
	
	int m, n, ans;
	while (cin>>m>>n, m) {
		ans=0;
		set<int>::iterator it = h.begin();
		for (; it!=h.end(); it++) {
			if (m<=*it && *it<=n) {
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1316
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt(), b = in.nextInt(), k = in.nextInt();
        Set<Integer> set = new TreeSet<>();
        set.add(a);
        for (int i = a; i < Math.min(a + k, b); i++) {
            set.add(i);
        }
        for (int i = Math.max(a, b - k) + 1; i <= b; i++) {
            set.add(i);
        }
        set.add(b);
        set.forEach(System.out::println);
    }
}



Measured memory_bytes: 26836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e5 + 5;
ll N, A[MAX];

bool check(int x){
    unordered_map<ll, ll> mp;
    ll piv = 0, sum = 1, ret = 0;
    mp[0] = 1;
    for(int i = 0; i < N; i++){
        if(A[i] >= x){
            piv++;
            sum += mp[piv];
        }
        else{
            sum -= mp[piv];
            piv--;
        }
        ret += sum;
        mp[piv]++;  sum++;
    }
    return (2LL * ret < N * (N + 1) / 2);
}

int main(){
    scanf("%lld", &N);
    for(int i = 0; i < N; i++){
        scanf("%lld", A + i);
    }
    if(N == 1){
        cout <<A[0] <<endl;
        return 0;
    }
    //sort(vt.begin(), vt.end());
    //vt.erase(unique(vt.begin(), vt.end()), vt.end());
    ll l = 0, r = 1e10 + 5;
    while(l < r){
        int mid = (l + r + 1) / 2;
        if(check(mid)){
            r = mid - 1;
        }
        else{
            l = mid;
        }
    }
    cout << l << endl;
    return 0;
}


Measured memory_bytes: 5192
#include<iostream>
using namespace std;
int main()
{
	int K;
	cin>>K;
	int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	cout<<a[K-1]<<endl;
	return 0;
}

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

#define real() cout<<"\n";

#define debug(arguments...) {string pri=#arguments;replace(pri.begin(),pri.end(),',',' ');stringstream prii(pri);istream_iterator<string> _iterat(prii);error(_iterat,arguments);}
void error(istream_iterator<string> _iterat) {}
template<typename T,typename...args>
void error(istream_iterator<string> _iterat,T a,args...arguments)
{
    cerr<<*_iterat<<"="<<a<<"\n";
    error(++_iterat,arguments...);
}

#define debugmp(z) {string pri=#z;error(pri,z);}
template<typename T,typename V>
void error(string pri,const pair<T,V> &z)
{
    cerr<<pri<<"="<<"{"<<z.first<<","<<z.second<<"}"<<"\n";
}
template<typename T,typename V>
void error(string pri,const map<T,V> &z)
{
    cerr<<pri<<" is={";
    for(auto it=z.begin();it!=z.end();++it)
    {
        cerr<<it->first<<":"<<it->second;
        auto _it=z.end();
        _it--;
        if(it!=_it) cerr<<",";
    }
    cerr<<"}";
    cerr<<"\n";
}

#define debugc(z,st,ed) {string pri=#z;error(pri,z,st,ed);}
template<typename T>
void error(string pri,const vector<T> &z,long long st,long long ed)
{
    cerr<<pri<<" in range["<<st<<","<<ed<<")=[";
    for(long long i=st;i<ed;++i)
    {
        cerr<<z[i];
        if(i!=ed-1) cerr<<" ";
    }
    cerr<<"]";
    cerr<<"\n";
}
template<typename T>
void error(string pri,const set<T> &z,long long st,long long ed)
{
    cerr<<pri<<" in range["<<st<<","<<ed<<")=[";
    long long tempcount=0;
    for(auto it=z.begin();it!=z.end();++it)
    {
        if(tempcount>=st and tempcount<ed)
        {
            cerr<<*it;
            if(tempcount!=ed-1) cerr<<" ";
        }
        tempcount++;
    }
    cerr<<"]";
    cerr<<"\n";
}
template<typename T>
void error(string pri,const T z[],long long st,long long ed)
{
    cerr<<pri<<" in range["<<st<<","<<ed<<")=[";
    for(long long i=st;i<ed;++i)
    {
        cerr<<z[i];
        if(i!=ed-1) cerr<<" ";
    }
    cerr<<"]";
    cerr<<"\n";
}

void logic()
{
    long long n;
    cin>>n;
    if(n%2==0) cout<<n;
    else cout<<2*n;
    cout<<"\n";
    //incase of wrong answer...stress test your code...do not stress test yourself
    //overflow,bounds,size,constraints
    //sample tests,corner case/special case(n==0 or n==1 or negative numbers...),some hand written tests
    //read statement carefully
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    long long t;
    //cin>>t;
    //while(t--)
    {
        logic();
    }
}


Measured memory_bytes: 3644
use proconio::input;
use proconio::marker::{Bytes, Chars};
use std::cmp::{max, min};

fn main() {
    input! {
        (x, y): (isize, isize),
    }
    let ans = if x == 0 || y == 0 {
            if x < y {
                (x.abs() - y.abs()).abs()
            } else if y < x {
                (x.abs() - y.abs()).abs() + 1
            } else {
                0
            }
        } else if x < 0 && y < 0 {
        if y < x {
            (x.abs() - y.abs()).abs() + 2
        } else {
            (x.abs() - y.abs()).abs()
        }
    } else if x < 0 || y < 0 {
        (x.abs() - y.abs()).abs() + 1
    } else {
        if y < x {
            (x.abs() - y.abs()).abs() + 2
        } else {
            (x.abs() - y.abs()).abs()
        }
    };
    println!("{}", ans);
}


Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(x) push_back(x)
#define f(i,st,n) for(i=st;i<n;i++)
#define qu queue
#define ps(x) push(x)
#define vec vector
#define ft() front()
#define mst(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define sfl(x) scanf("%lld",&x)
#define pfl(x) printf("%lld\n",x)
#define pf(x) printf("%lld",x)
#define mpr make_pair
#define fs first
#define se second
 
 
 
 
ll gcd(ll a,ll b){
    if(a==0){
        return b;
    }                     
    return gcd(b%a,a);
}
ll power(ll x,ll y){            
    ll res=1;
    while(y>0){
        if(y%2==1){
            res=(res*x);
        }
        x=(x*x);
        y=y/2;
    }
    return res;
}
 
 
int main(){
 
/* #ifndef ONLINE_JUDGE
    
   freopen("input.txt", "r", stdin);
   
   freopen("output.txt", "w", stdout);
   #endif
   */
ll n,i,x,k;

sfl(n);sfl(k);

ll a[n];
f(i,0,n)sfl(a[i]);
sort(a,a+n);
ll ans=lower_bound(a,a+n,k)-a;
cout<<n-ans;
 
 
 
  
 
 
 
 
 
 
 
 
 
 
 
 
   return 0;
 }

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

typedef long long ll;

const int N = 1 * 1e5 + 10;
const ll inf = 1 * 1e9 + 10;

ll res;
ll a[N];

void solve() {
	ll  n;
	cin >> n;
	ll dp[n][3];
	cin >> dp[0][0] >> dp[0][1] >> dp[0][2];
	for (int i = 1; i < n; ++i){
		for (int j = 0; j < 3; ++j){
			cin >> a[j];
		}
		dp[i][0] = max(dp[i - 1][2], dp[i - 1][1]) + a[0];
		dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + a[1];
		dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + a[2];
	}
	cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});
}

int main(int argc, char const *argv[]){
  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
  ll t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
    return 0;
}

Measured memory_bytes: 2560