akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b){
  if(a < b){ a = b; return true;} return false;
}
template<class T> inline bool chmin(T& a, T b){
  if(a > b){ a = b; return true;} return false;
}

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i=0;i < n;i ++){
    cin >> a.at(i);
  }
  vector<int> dp(k+1);
  for(int i =0;i < a.at(0);i++){
    dp.at(i) = 1;
  }
  for(int i = a.at(0);i < k+1;i++){
    for(int j = 0;j < n;j ++){
      if(a.at(j) == i){
        dp.at(i) = 0;
        break;
      }
      if(i - a.at(j) > 0){
        if(dp.at(i - a.at(j)) == 1){
          dp.at(i) = 0;
          break;
        }
        else{
          dp.at(i) = 1;
        }
      }
    }
  }
  /*
  for(int i=0;i < k+1;i++){
    cout << dp.at(i) << endl;
  }*/
  if(dp.at(k) == 1){
    cout << "Second" << endl;
  }
  else {
    cout << "First" << endl;
  }
      
}

Measured memory_bytes: 3792
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  string S, T;
  ll count = 0;
  std::cin >> S;
  std::cin >> T;
  std::vector<set<int> > alpha(26);
  for(int i=0;i<S.size();i++) alpha[S[i]-'a'].insert(i);
  int now = -1;

  for(int i=0;i<T.size();i++){
    if(alpha[T[i]-'a'].size()==0){
      std::cout << -1 << '\n';
      return 0;
    }
  }

  for(int i=0;i<T.size();i++){
    auto itr = alpha[T[i]-'a'].lower_bound(now+1);
    if(itr==alpha[T[i]-'a'].end()){
      now = -1;
      count++;
      itr = alpha[T[i]-'a'].lower_bound(now+1);
    }
    now = *itr;
  }
  std::cout << count * S.size() + now + 1 << '\n';
  return 0;
}


Measured memory_bytes: 5248
N=input()

if N[2]==N[1]==N[0]:
    A=N

elif N[2]>N[0] or N[1]>N[0]:
    B=int(N[0])+1
    C=str(B)
    A=str(C+C+C)


else:
    A=str(N[0]+N[0]+N[0])


    
print(A)

Measured memory_bytes: 3060
from itertools import combinations as comb

def fits(m: iter):
    a, b, c = m
    return a!=b!=c and c!=a and a<b+c and b<a+c and c<a+b

n = int(input())
l = map(int, input().split())
ans = 0

for cwr in comb(l, 3): ans += fits(cwr)
print(ans)

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

#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define fs first
#define sc second
#define fr(i, a, b) for(int i = a ; i < b ; i++)
#define frr(i, a, b) for(int i = a ; i >= b ; i--)
#define tr(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define trr(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define its(x) static_cast< ostringstream & >( ( ostringstream() << dec << x ) ).str() // int to string
#define fill1(a, c, x) fr(_I, 0, (c)) (a)[_I] = (x);
#define fill2(a, r, c, x) fr(_I, 0, (r)) fr(_J, 0, (c)) (a)[_I][_J] = (x);
#define sz(x) ((int)(x).size())
#define deb(x) cout << #x" = " << x << '\n';

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ull x;

int main() {
//    freopen("input.in", "r", stdin);
	scanf("%I64d", &x);
	if(x % 2 == 0) printf("%I64d", x);
	else printf("%I64d", x*2LL);
	return 0;
}

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

using namespace std;

int main()
{
  int n, p;
  char s[200001];
  
  scanf("%d %d", &n, &p);
  scanf("%s", s);
  
  long long ans = 0;
  
  for (int i = 0; i < n; i++) s[i] -= '0';
  
  if (p == 2 || p == 5) {
    for (int i = 0; i < n; i++) {
        if (s[i] % p == 0) ans += i + 1;
     }
  }
  else {
    vector<int> lf_cnt(p), rg_cnt(p);
    fill(lf_cnt.begin(), lf_cnt.end(), 0);
    fill(rg_cnt.begin(), rg_cnt.end(), 0);
    int pow_10[200001];
    int lf_num[200001], rg_num[200001];
    pow_10[0] = 1;
    for (int i = 0; i < n; i++) {
      pow_10[i + 1] = pow_10[i] * 10 % p;
    }
    
    lf_cnt[0] = 1;
    int lf_tmp = 0, rg_tmp = 0;
    for (int i = 0; i < n; i++) {
      lf_tmp = (lf_tmp + s[i] * pow_10[n - 1 - i]) % p;
      rg_tmp = (rg_tmp + s[n - i - 1] * pow_10[i]) % p;
      lf_num[i] = lf_tmp;
      rg_num[n - i - 1] = rg_tmp;
      lf_cnt[lf_num[i]]++;
      rg_cnt[rg_num[n - i - 1]]++;
    }
    
    int all = rg_num[0];
    for (int i = n - 1; i >= 0; i--) {
      lf_cnt[lf_num[i]]--;
      int sub = (i == n - 1 ? 0 : rg_num[i + 1]);
      ans += lf_cnt[(all - sub + p) % p];
    }
  }
  
  printf("%lld\n", ans);
  
  return 0;
}

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

int main() { 
  int n, b_, ans = 0;
  vector<int> a, b;
  cin >> n;
  for(int i = 0; i < n; ++i) {
    cin >> b_;
    b.push_back(b_);
  }
  while(b.size()) {
    for(int i = b.size()-1; i >= 0; --i) {
      if(b[0] != 1) {
        cout << -1 << '\n';
        return 0;
      }
      if(b[i] == i+1) {
        a.push_back(b[i]);
        b.erase(b.begin()+i);
        break;
      }
    }
  }
  for(int i = n-1; i >= 0; --i) {
    cout << a[i] << '\n';
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int G[100][100];
  
  for(int i=0;i<100;i++)
    for(int j=0;j<100;j++)
      G[i][j]=(i==j?0:1000);
  
  int n,e;
  cin>>n>>e;
  
  for(int i=0;i<e;i++){
    int a,b;
    cin>>a>>b;
    G[a][b]=-1;
  }
  
  for(int k=0;k<n;k++)
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
        G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
  
  for(int i=0;i<n;i++){
    if(G[i][i]<0){
      cout<<1<<endl;
      return 0;
    }
  }
  
  cout<<0<<endl;
  return 0;
}

Measured memory_bytes: 3136
/* author: jeetganatra */

#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define fo(i,n)         for(int i=0;i<n;i++)
#define Fo(i,k,n)       for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define tr(it, a)       for(auto it = a.begin(); it != a.end(); it++)
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define deb(x)          cout << #x << "=" << x << endl
#define deb2(x, y)      cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x)          x.begin(), x.end()
#define clr(x)          memset(x, 0, sizeof(x))
#define sortall(x)      sort(all(x))
#define endl            "\n"
#define PI              3.14159265
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
#define INT_BITS         32 

 
void jpg()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int mpow(int base, int exp); 

 



int32_t main()
{
	jpg();
	string s;
	cin>>s;
	if (s.back()=='s')
	{
		s+="es";
	}

	else
	{
		s+="s";
	}

	cout<<s;

}


int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((int)result * base) % mod;
    base = ((int)base * base) % mod;
    exp >>= 1;
  }
  return result;
}




Measured memory_bytes: 3632
using System;

namespace ChokudaiScanner
{
    class MainClass
    {
        static void Main()
        {
            Scanner cin = new Scanner();
            int a = cin.NextInt();
            int b = cin.NextInt();
            int c = cin.NextInt();
            int x = cin.NextInt();
            int ans = 0;

            for(int i = 0; i <= a; i++)
            {
                for(int j = 0; j <= b; j++)
                {
                    for(int k = 0; k <= c; k++)
                    {
                        int sum = i * 500 + j * 100 + k * 50;
                        if (sum==x)
                        {
                            ans++;
                        }                 
                    }
                }
            }
            Console.WriteLine(ans);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string Next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return Next();
            i = 0;
            return s[i++];
        }

        public string[] ArrayNext(int N)
        {
            string[] Array = new string[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = Next();
            }
            return Array;
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextInt() + add;
            }
            return Array;
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextLong() + add;
            }
            return Array;
        }

        public double NextDouble()
        {
            return double.Parse(Next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextDouble() + add;
            }
            return Array;
        }
    }
}



Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
#define deb debug("line %d\n",__LINE__)
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("-1");exit(0);}

	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=998244353;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int MM=5e6+10;
	ll fac[MM],facinv[MM],Inv[MM];ll Comb(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,MM-1) fac[i]=fac[i-1]*i%MOD;
		facinv[MM-1]=invm(fac[MM-1]);fd(i,MM-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,MM-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}
	const int N=1e3+10;
	//------------------FIXED------------------
	char mp[N][N];int dp[N][N];
	void main()
	{
		int n=qread(),m=qread();fo(i,1,n) scanf("%s",mp[i]+1);
		mem(dp,0x3f);dp[1][1]=(mp[1][1]=='#');
		fo(i,1,n) fo(j,1,m)
		{
			if(i>1) chmin(dp[i][j],dp[i-1][j]+(mp[i-1][j]=='.' and mp[i][j]=='#'));
			if(j>1) chmin(dp[i][j],dp[i][j-1]+(mp[i][j-1]=='.' and mp[i][j]=='#'));
		}write(dp[n][m]);
	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::PRE();
	mine::main();
	debug("\n------------------------------------------\nTime: %.2lf s\n",1.0*clock()/CLOCKS_PER_SEC);
}

Measured memory_bytes: 122368
n = input()
a, b, c, d = n[0], n[1], n[2], n[3]

if int(a)+int(b)+int(c)+int(d) is 7:
  print(a+"+"+b+"+"+c+"+"+d+"=7")
elif int(a)+int(b)+int(c)-int(d) is 7:
  print(a+"+"+b+"+"+c+"-"+d+"=7")
elif int(a)+int(b)-int(c)+int(d) is 7:
  print(a+"+"+b+"-"+c+"+"+d+"=7")
elif int(a)+int(b)-int(c)-int(d) is 7:
  print(a+"+"+b+"-"+c+"-"+d+"=7")
elif int(a)-int(b)+int(c)+int(d) is 7:
  print(a+"-"+b+"+"+c+"+"+d+"=7")
elif int(a)-int(b)+int(c)-int(d) is 7:
  print(a+"-"+b+"+"+c+"-"+d+"=7")
elif int(a)-int(b)-int(c)+int(d) is 7:
  print(a+"-"+b+"-"+c+"+"+d+"=7")
elif int(a)-int(b)-int(c)-int(d) is 7:
  print(a+"-"+b+"-"+c+"-"+d+"=7")

Measured memory_bytes: 3064
N = int(input())
i = 0
list26 = []
while (N > 0):
    list26.append(N%26)
    N = int(N/26)

for i in range(len(list26)):
    if(i != len(list26)-1):
        if(list26[i] <= 0):
            list26[i] = list26[i] + 26
            list26[i+1] = list26[i+1] - 1
    else:
        if(list26[i]==0):
            list26.pop(i)
            
list26.reverse()

ans = ""

for x in list26:
    ans += str(chr(ord('a')+x-1))
print(ans)

Measured memory_bytes: 61716
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
#include <set>
#include <map>
#include <unordered_map>
#include <cassert>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    int n; std::cin >> n;
    std::string s,t;
    std::cin >> s >> t;

    int ans = 2*n;
    for(int i=n-1; i>=0; i--){
        std::string si = s.substr(i);
        std::string ti = t.substr(0,n-i);
        if(si==ti){
            ans = 2*n - si.size();
        }
    }

    std::cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <algorithm>

int main() {
	int n, a[110], total = 0, diff, min = 1000000000, ans;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		total += a[i];
	}
	for (int i = 0; i < n; i++) {
		a[i] *= n;
		diff = abs(a[i] - total);
		if (diff < min) {
			ans = i;
			min = diff;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
N = int(input())
zeros = [0 for i in range(10050)]
for x in range(1,105):
    for y in range(1,105):
        for z in range(1,105):
            n = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if n < 10050:
                zeros[n]+=1

for i in range(N):
    print(zeros[i+1])

Measured memory_bytes: 9180
#include <iostream> 
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <queue>
#include <stack>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <cctype>
#include <climits>

using namespace std;

using ll = long long int;

using ii = pair<int, int>;
using vi = vector<ll>;
using vii = vector<ii>;
using vvi = vector<vi>;



#define mp(a,b) make_pair(a,b)

const int MOD = 1000 * 1000 * 1000 + 7;

bool comprobar(ll tam, vi const& v, ll k) {
	ll cortesUsados = 0;

	for (int i = 0; i < v.size(); ++i) {
		if (v[i] % tam == 0) cortesUsados += v[i] / tam - 1;
		else cortesUsados += v[i] / tam ;

		if (cortesUsados > k) return false;
	}
	return true;
}

int busBin(int ini, int fin, vi const& v, int k) { 
	if (ini >= fin) return ini;
	else { 
		int mitad = (ini + fin - 1) / 2; 
		if(comprobar(mitad, v, k)) return busBin(ini, mitad, v, k); 
		else return  busBin(mitad + 1, fin, v, k);
	} 
}

int main() {
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	ll n, k;
	cin >> n >> k;
	
	vi v(n);
	for (int i = 0; i < n; ++i) cin >> v[i];

	cout << busBin(1, 1000000000, v, k) << '\n';

	return 0;
}

Measured memory_bytes: 4716
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a, b;
	cin >> a >> b;
	if (a == b)
	{
		cout << "Draw" << endl;
	}else if (a == 1)
	{
		cout << "Alice" << endl;
	}else if(b == 1){
		cout << "Bob" << endl;
	}else if (a > b)
	{
		cout << "Alice" << endl;
	}else if (a < b)
	{
		cout << "Bob" << endl;
	}
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>

using namespace std;

const int maxm = 1000 + 10;
const int maxn = 30 + 10;
int n, c, d[maxn][maxn], t[4][maxn], x, y, z, ans;

int main() {
	cin >> n >> c;
	ans = INT32_MAX;
	int i, j, k, l;
	for (i = 1; i <= c; i++) {
		for (j = 1; j <= c; j++) {
			cin >> d[i][j];
		}
	}
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			cin >> x;
			t[(i + j) % 3][x]++;
		}
	}
	for (i = 1; i <= c; i++) {
		x = 0;
		for (j = 1; j <= c; j++) {
			x += t[0][j] * d[j][i];
		}
		for (j = 1; j <= c; j++) {    //枚举余数为1统一变成颜色j,其代价为y 
			if (j == i) continue;    //不同余数的颜色不能相同 
			y = 0;
			for (k = 1; k <= c; k++) {
				y += t[1][k] * d[k][j];
			}
			for (k = 1; k <= c; k++) {    //枚举余数为2统一变成颜色k,其代价为z 
				if (k == j || k == i) continue;    //不同余数的颜色不同 
				z = 0;
				for (l = 1; l <= c; l++) {
					z += t[2][l] * d[l][k];
				}
				if (ans>x + y + z) {
					ans = x + y + z;
				}
			}
		}
	}
	cout << ans << endl;
}

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

// Aliases
#define enable_fast_io()  	ios_base::sync_with_stdio(false); 	\
			  				cin.tie(nullptr); 					\
							cout.tie(nullptr)  

#define N 300010LL
#define round(n) int64_t(n+0.5)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pi;


int main(){
	enable_fast_io();

	ll n;
	cin >> n;

	vector<int> a(n + 1);
	for (int i = 1; i <= n / i; i++) {
		for (int j = i; j <= n / i; j++) {
		a[i * j] += 2;
		if (i == j) a[i * j]--;
		}
	}
	
	ll ans = 0;
	for (ll i = 1; i <= n; i++) {
		ans += i * a[i];
	}

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

Measured memory_bytes: 42288
def bubble_sort(buff):
	count = 0
	k = len(buff) - 1
	for i in xrange(k):
		for j in xrange(k, i, -1):
			if buff[j - 1] > buff[j]:
				count += 1
				temp = buff[j]
				buff[j] = buff[j - 1]
				buff[j - 1] = temp
	print " ".join(map(str, buff))
	print count

N = int(raw_input())
buff = map(int, raw_input().split(' '))
bubble_sort(buff)

Measured memory_bytes: 4228
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int main() {
	int n, z, w, a[2000];
	scanf("%d %d %d", &n, &z, &w);
	for (int i = 0; i < n; i++)
		scanf("%d", a + i);

	if (n != 1) {
		printf("%d\n", max(abs(w - a[n - 1]), abs(a[n - 1] - a[n - 2])));
	} else {
		printf("%d\n", abs(w - a[0]));
	}
}

Measured memory_bytes: 128
N = int(input())
A = list(map(int,input().split()))

if N == 0:
    print(1 if A[0] == 1 else -1)
    exit()

nodeS = [0 for i in range(N+1)]
nodeS[0] = 1
laS = [0 for i in range(N+1)]
laS[-1] = A[-1]

for i in range(N):
    laS[-2-i] = A[-2-i] + laS[-1-i]
    nodeS[i+1] = (nodeS[i]-A[i])*2

for i in range(N+1):
    if nodeS[i] <= 0:
        print(-1)
        exit()

for i in range(N+1):
    if nodeS[i] >= laS[i]:
        break
    if i == N:
        print(-1)
        exit()

print(sum(nodeS[:i]) + sum(laS[i:]))


Measured memory_bytes: 702272
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		setIO();

		int N = ni();
		
		int l = Integer.toString(N).length();
		int m = 0;
		for (int i = 0; i < l; i++) {
			m = (10 * m + 7) % N;
		}
		
		int i = l;
		boolean[] vis = new boolean[N];
		
		while (true) {
			if (vis[m]) {
				out.println(-1);
				break;
			}
			
			vis[m] = true;
			
			if (m == 0) {
				out.println(i);
				break;
			}
			
			m = (10 * m + 7) % N;
			i++;
		}
		
		f.close();
		out.close();
	}

	static final int MOD = 1000000007;

	static BufferedReader f;
	static PrintWriter out;

	static int ni(StringTokenizer st) {
		return Integer.parseInt(st.nextToken());
	}

	static int ni() throws IOException {
		return Integer.parseInt(f.readLine());
	}

	static StringTokenizer nl() throws IOException {
		return new StringTokenizer(f.readLine());
	}

	static int[] nia(int N) throws IOException {
		StringTokenizer st = nl();
		int[] A = new int[N];
		for (int i = 0; i < N; i++)
			A[i] = ni(st);
		return A;
	}

	static void setIO(String s) throws IOException {
		f = new BufferedReader(new FileReader(s + ".in"));
		out = new PrintWriter(new FileWriter(s + ".out"));
	}

	static void setIO() {
		f = (new BufferedReader(new InputStreamReader(System.in)));
		out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	}
}


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

#define int long long
#define loop(i,n) for(int i=1;i<=n;i++)
int n,m,k,s,ppp,qqq;
const int INF=1000000000000000;

int danger[100002];

typedef pair<int,int> P;
vector<int> G[100002];
int d[100002];
void dijk(){
  priority_queue<P,vector<P>,greater<P> > que;
  loop(i,n)d[i]=INF;
  d[1]=0;
  que.push(P(0,1));
  while(!que.empty()){
    P p=que.top();que.pop();
    int v=p.second;
    if(d[v]<p.first)continue;
    loop(i,G[v].size()){
      int to=G[v][i-1];
      if(danger[to]>s)continue;
      int cost=danger[to]?qqq:ppp;
      if(d[to]>d[v]+cost){
        d[to]=d[v]+cost;
        que.push(P(d[to],to));
      }
    }
  }
}

void bps(){
  queue<int> que;
  que.push(0);
  danger[0]=s+2;
  while(!que.empty()){
    int p=que.front();que.pop();
    loop(i,G[p].size()){
      int to=G[p][i-1];
      if(!danger[to]){
        danger[to]=danger[p]-1;
        if(!danger[to])continue;
        que.push(to);
      }
    }
  }
}

signed main(){
  cin>>n>>m>>k>>s;
  cin>>ppp>>qqq;
  int c,a,b;
  loop(i,k){
    cin>>c;
    G[0].push_back(c);
  }
  loop(j,m){
    cin>>a>>b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  bps();
  dijk();
  cout<<(d[n]-(danger[n]?qqq:ppp))<<endl;
  return 0;
}

Measured memory_bytes: 13636
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

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

int main()
{
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int ans = 0;
    for(int i = 0; i< a+1; i++){
        int tmp = 0;
        tmp += 500 * i;
        for(int j = 0; j < b +1; j++){
            int tmp1 = tmp;
            tmp1 += 100 * j;
            for(int k = 0; k < c + 1; k++){
                int tmp2 = tmp1;
                tmp2 += 50 * k;
                if(tmp2 == x) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

int main(){
    int H, W, D;
    cin >> H >> W >> D;

    using P = pair<int, int>;
    vector<P> v(H*W);
    rep(i, H){
        rep(j, W){
            int a;
            cin >> a;
            v[a-1] = {i, j};
        }
    }

    vector<int> d(H*W);
    rep(i, D){
        for(int j=i; j<H*W-D; j+=D){
            int cost = abs(v[j+D].first - v[j].first) + abs(v[j+D].second - v[j].second);
            d[j+D] += d[j] + cost;
        }
    }

    int q;
    cin >> q;
    rep(i, q){
        int l, r;
        cin >> l >> r;
        l--; r--;
        cout << (d[r] - d[l]) << endl;
    }
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int i=0;7*i<=n;i++){
		n -= 7*i;
		if(n%4==0){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int n; cin >> n;
    vector<int>v(n);
    vector<int>dp(n,INF);
    for(auto & e : v) cin >> e;
    rep(i,n-1){
        dp[0] = 0LL;
        cmin(dp[i+1],dp[i] + abs(v[i] - v[i+1]));
        if(i+2<n)cmin(dp[i+2],dp[i]+abs(v[i] -v[i+2]));
    }
    cout << dp.back() << endl;
    
}



Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int N = 2e6 + 10;
const ll mod = 1e9 + 7;
int n, m, k;
ll a[3010][3010];
ll dp[3010][3010][4];
int main() {
	scanf("%d%d%d", &n, &m, &k);
	//for (int i = 1; i <= n; i++)for (int j = 1; j <= m; j++)a[i][j] = -inf;
	for (int i = 1; i <= k; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		scanf("%lld", &a[x][y]);
	}
	//for (int i = 0; i <= n; i++)for (int j = 0; j <= m; j++)for (int x = 0; x <= 3; x++)dp[i][j][k] = -inf;
	for (int i = 0; i <= n; i++)for (int j = 0; j <= m; j++)dp[i][j][0] = 0;
	dp[1][1][0] = 0; if (a[1][1] >= 0)dp[1][1][1] = a[1][1];
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			dp[i][j][0] = 0;
			if (i == 1 && j == 1)continue;
			if (a[i][j] <= 0) {
				for (int x = 0; x <= 3; x++) {
					dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][x]);
					dp[i][j][x] = max(dp[i][j][x], dp[i][j - 1][x]);
				}
				continue;
			}
			dp[i][j][0] = max(dp[i][j][0], dp[i][j - 1][0]);
			for (int x = 0; x <= 3; x++)dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][x]), dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j][x] + a[i][j]);
			for (int x = 1; x <= min(j, 3); x++) {
				dp[i][j][x] = max(dp[i][j][x], max(dp[i][j - 1][x], dp[i][j - 1][x - 1] + a[i][j]));
			}
		}
	}
	for (int i = 0; i <= 3; i++)ans = max(ans, dp[n][m][i]);
	printf("%lld\n", ans);
	return 0;
}


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

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

	int cnt = 0;
	for (int i = 0; i < n; i++) if (a[i] % 2 == 0) cnt++;
	



	cout << pow(3, n) - (1 << cnt) << endl;
	return 0;
}

Measured memory_bytes: 4288
#include<iostream> 
#include<vector>
using namespace std;
int main(){
  int n=0,m=0;
  bool check = true,ans = false;
  cin >> n >> m;
  char a[n][n],b[m][m];
  for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin >> a[i][j];
  for(int i=0;i<m;i++) for(int j=0;j<m;j++) cin >> b[i][j];
  for(int i=0;i<n;++i){
    for(int j=0;j<n;++j){
      if(i+m-1>=n || j+m-1>=n) continue;
      //画像の照合
      check = true;
      for(int k = 0;k<m;k++){
        for(int l = 0;l<m;l++){
          if(a[k+i][l+j] != b[k][l]){ check = false;}
        }
      }
      if(check) ans = true;
     }
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
} 


  


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int mp[2020];
int main()
{
	int l, r;
	scanf("%d%d", &l, &r);
	for (int i = l; i <= r; i++)
	{
		mp[i % 2019]++;
		if (i % 2019 == 0)
		{
			cout << 0 << endl;
			return 0;
		}
	}
	int ans = 2020;
	for (int i = 0; i < 2019; i++)
	{
		for (int j = 0; j < 2019; j++)
		{
			if (i == j)
			{
				if (mp[i] > 1)
					ans = min(ans, (i * j) % 2019);
				continue;
			}
			if (mp[i] && mp[j])
				ans = min(ans, (i * j) % 2019);
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
 
int main() {
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define debug(x) cout<<"### x is: "<<x<<"###"<<endl
#define all(a) a.begin(),a.end()
#define tc int t;scanf("%d",&t);while (t--0)
#define int long long
typedef vector<int> vll;
typedef vector<vll> vvll;
const int N=2e5+5;

const int MOD=1e9+7;

int power(int x, int p) 
{
    int res = 1;
    while (p) 
   {
        if (p % 2) 
	{
            res = (res * x) % MOD;
            --p;
        }
        else {
            x = (x * x) % MOD;
            p /= 2;
        }
    }
    return res;
}
int invmod(int x) {return power(x,MOD-2);}

int32_t main()
{
	
	int n;
	cin>>n;
	int a[n+1];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	if(n==2)
	{
		cout<<abs(a[1]-a[0])<<endl;
		return 0;
	}
	int dp[N];
	for(int i=0;i<n+5;i++)
	{
		dp[i]=LLONG_MAX;
		dp[i]=LLONG_MAX;

	}
	dp[0]=0;
	dp[0]=0;
	for(int i=0;i<n;i++)
	{
		if(i+1<n)
		{
			dp[i+1]=min(dp[i+1],dp[i]+abs(a[i+1]-a[i]));
		}
		if(i+2<n)
		{
			dp[i+2]=min(dp[i+2],dp[i]+abs(a[i+2]-a[i]));
		}
		
	}
	cout<<dp[n-1]<<endl;
}

	
	


	




	


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

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);

    for (int i = 1; i < n; ++i) cin >> a.at(i);

    vector<ll> ans(n, 0);
    for (int i = 1; i < n; ++i) {
        ans.at(a.at(i)-1)++;
    }

    for (int i = 0; i < n; ++i) {
        cout << ans.at(i) << endl;
    }

    return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rrepn(i, n) for (int i = ((int)(n)); i > 0; --i)
#define SZ(x) ((int)(x).size())
template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
vector<pair<string, P> > vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long N, std::vector<long long> A) {
    ll c = 1000000000000000000;
    ll res = 1;
    rep(i, N) {
        if (A[i] == 0) {
            cout << "0" << endl;
            return;
        }
    }
    rep(i, N) {
        if (res >1+ c/A[i]) {
            cout << "-1" << endl;
            return;
        } else {
            res *= A[i];
        }
    }
    if (res <= c)
        cout << res << endl;
    else
        cout << "-1" << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 4052
Arr=list(map(int,input().split()))
L=[]
for i in range(Arr[0]):
    S=input()
    if S=="AB":
        L.append([1,2])
    elif S=="BC":
        L.append([2,3])
    else:
        L.append([1,3])
D={}
D[1]="A"
D[2]="B"
D[3]="C"

if Arr[L[0][0]]+Arr[L[0][1]]==0:
    print("No")
else:
    ANS=["Yes"]
    for i in range(len(L)):
        if Arr[L[i][0]]==Arr[L[i][1]] and Arr[L[i][0]]==1:
            if i!=len(L)-1 and L[i]!=L[i+1]:
                if L[i][0] in L[i+1]:
                    ANS.append(D[L[i][0]])
                    Arr[L[i][0]]+=1
                    Arr[L[i][1]]-=1
                else:
                    ANS.append(D[L[i][1]])
                    Arr[L[i][1]]+=1
                    Arr[L[i][0]]-=1
            else:
                ANS.append(D[L[i][0]])
                Arr[L[i][0]]+=1
                Arr[L[i][1]]-=1
        elif Arr[L[i][0]]+Arr[L[i][1]]==0:
            print("No")
            exit()
        else:
            if Arr[L[i][0]]>=Arr[L[i][1]]:
                ANS.append(D[L[i][1]])
                Arr[L[i][1]]+=1
                Arr[L[i][0]]-=1
            else:
                ANS.append(D[L[i][0]])
                Arr[L[i][0]]+=1
                Arr[L[i][1]]-=1
    for j in range(len(ANS)):
        print(ANS[j])

Measured memory_bytes: 95100
#include <iostream>
#include <vector>
#include <stdio.h>
#include <string>

#define rep(i,n) for(int i = 0; i < n; i++)

typedef long long ll;

using namespace std;

const int INF = 1e9;
const double PI=3.14159265358979323846;

int main(){
  int n;
  cin >> n;
  int a[4][3][10] = {{{}}};

  rep(i,n){
    int b, f, r, v;
    cin >> b >> f >> r >> v;
    a[b-1][f-1][r-1] += v;
  }
  string l = "####################";
  rep(i,4){
    rep(j,3){
      rep(k,10){
	cout << " " << a[i][j][k];
      }
      cout << endl;
    }
    if(i == 3) break;
    cout << l << endl;
  }
}



Measured memory_bytes: 3172
#include <iostream>

using namespace std;

int main()
{
    int n, a[10001]={0}, m, cnt=0;
    cin>>n;
    for (int i=0; i<n; i++)
    {
        cin>>m;
        a[m]++;
    }
    for (int i=0; i<10001; i++)
    {
        for (int j=0; j<a[i]; j++)
        {
            cnt++;
            if (cnt!=n) cout<<i<<' ';
            else cout<<i<<'\n';
        }
    }
    return 0;
}



Measured memory_bytes: 3136
# coding: utf-8
# Your code here!

s = input()
t = input()

ls = len(s)
lt = len(t)

dp = [[0]*(lt+1) for _ in [0]*(ls+1)]

for i in range(1,ls+1):
    for j in range(1,lt+1):
        if s[i-1] != t[j-1]:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])
        else:
            dp[i][j] = 1+dp[i-1][j-1]

L=dp[ls][lt]
ans = [0]*L
idx=L-1
while idx >= 0:
#    print(i,j,idx)
    if i>0 and dp[i-1][j] == dp[i][j]:
        i -= 1
    elif j>0 and dp[i][j-1] == dp[i][j]:
        j-=1
    else:
        i-=1
        j-=1
        ans[idx] = s[i]
        idx -= 1

#print(dp)
print(''.join(ans))








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

template <class Monoid> struct SegmentTree{
    using Func = function<Monoid(Monoid, Monoid)>;

    int size;
    vector<Monoid> seg;
    const Func merge;
    const Monoid def;

    SegmentTree(int n, Monoid d, const Func f): merge(f), def(d){
        for(size = 1; size <= n; size <<= 1);
        seg.assign(size*2, def);
    }

    Monoid& operator[] (int i) { return seg[i+size]; };
    void build(){ for(int i = size-1;i >= 0;i--) seg[i] = merge(seg[i*2], seg[i*2+1]); }

    void update(int i, Monoid val){
        seg[i += size] = val;
        while(i >>= 1) seg[i] = merge(seg[i*2], seg[i*2+1]);
    }

    void add(int i, Monoid val){ update(i, val+seg[i+size]); }

    Monoid get(int a, int b){
        Monoid l = def, r = def;
        for(a += size, b += size; a < b; a >>= 1, b >>= 1){
            if(a & 1) l = merge(l, seg[a++]);
            if(b & 1) r = merge(r, seg[--b]);
        }
        return merge(l, r);
    }
};

int n;
int a[100010];

bool isOK(int num){
    int b[100010] = {};
    unordered_map<int, int> mp;
    vector<int> vec;
    vec.push_back(0);
    for(int i = 0;i < n;i++){
        b[i+1] += b[i];
        if(a[i] >= num){
            b[i+1]++;
            vec.push_back(b[i+1]);
        }else{
            b[i+1]--;
            vec.push_back(b[i+1]);
        }
    }
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());

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

    long long ans = 0;
    SegmentTree<int> seg(n, 0, [](int a, int b){ return a + b;});
    seg.update(mp[0], 1);

    for(int i = 1;i <= n;i++){
        ans += seg.get(0, mp[b[i]]+1);
        seg.add(mp[b[i]], 1);
    }

    return ans >= ((((long long)n * (long long)(n+1)) / 2)+1) / 2;
}

signed main(){
    cin >> n;

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

    int l = 1, r = 1000000001;

    while(r-l > 1){
        int mid = (r+l)/2;

        if(isOK(mid)){
            l = mid;
        }else{
            r = mid;
        }
    }

    cout << l << endl;
    return 0;
}

Measured memory_bytes: 6608
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    map<int, int> RS;
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        if(a == 1){
            RS[b]++;
        }
        if(b == N){
            RS[a]++;
        }
    }

    bool F = false;
    for(auto p : RS){
        if(p.second >= 2){
            F = true;
            break;
        }
    }

    if(F == true){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }


    return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <vector>

using namespace std;

long long solve(long long A, long long B){
	if(A > B) swap(A, B);
	long long L = 0, R = B;
	while(R - L > 1){
		long long mid = (L+R)/2;
		if(mid * mid < A * B) L = mid;
		else R = mid;
	}
	if(L < A) return 2 * L;
	if(L * (L+1) < A * B) return 2 * L - 1;
	return 2 * L - 2;
}

int main(){
	int Q;
	while(cin >> Q){
		while(Q--){
			long long A, B; cin >> A >> B;
			cout << solve(A, B) << endl;
		}
	}
}


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

int main(){
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;

	if(r <= x &&  r <= y && r <= W -x && r <= H - y){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

	return 0;
}

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

int main() {
  LL n, m;
  cin >> n >> m;
  vector<pair<LL, LL>> a(n);
  rep(i, n) {
    cin >> a[i].first >> a[i].second;
  }

  sort(all(a));
  priority_queue<LL> pq;
  LL ans = 0, x = 0;
  for (int i = m - 1; i >= 0; i --) {
    while (x < n) {
      if (i + a[x].first <= m) {
        pq.push(a[x].second);
        x ++;
      } else {
        break;
      }
    }
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 2936
#include<iostream>
int main()
{
	int n;
	int a[300], b[300], c[300], m[300];
	std::cin >> n;
	for ( int i = 0; i < n; i++ )
	{
		std::cin >> a[i] >> b[i] >> c[i] >> m[i];
	}
	char *arr = new char[315];
	
	for ( int i = 0; i < 15; i++ )
	{
		for ( int j = 0; j < 20; j++ )
		{
			arr[j+20*i] = '0';
		}
	}
	
	for ( int i = 0; i < 15; i++ )
	{
		for ( int j = 0; j < 20; j+=2 )
		{
			arr[j+20*i] = ' ';
		}
	}

	for ( int i = 1; i <= 3; i++)
	{
		for ( int j = 0; j < 20; j++)
		{
			arr[i*80-20+j] = '#';
		}
	}

	for ( int i = 0; i < n; i++ )
	{
		if( arr[(a[i]-1)*80 + (b[i]-1)*20 + c[i]*2-1] != 0 )
		{
			int x = m[i] + (char)(arr[(a[i]-1)*80 + (b[i]-1)*20 + c[i]*2-1] + '0' );
			arr[(a[i]-1)*80 + (b[i]-1)*20 + c[i]*2-1] = (char)(x-'0');
		}
		else
		{
			arr[(a[i]-1)*80 + (b[i]-1)*20 + c[i]*2-1] = (char)(m[i]+'0');
		}
	}


	for ( int i = 0; i < 15; i++ )
	{
		for ( int j = 0; j < 20; j++ )
		{
			std::cout << arr[j+20*i];
		}
		std::cout << "\n";
	}	
	return 0;
}


Measured memory_bytes: 3084
def area(px,py,x,y):
    if py > y:
        py,y = y,py
    return py*(x-px)+(x-px)*abs(y-py)/2

count = 1
while True:
    res = 0
    n = int(input())
    if n == 0:
        break
    px,py = map(int,input().split())
    sx,sy = px,py
    for _ in range(n-1):
        x,y = map(int,input().split())
        res += area(px,py,x,y)
        px,py = x,y
    res += area(px,py,sx,sy)
    print(count,res)
    count += 1
    input()



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

int main() {
    int a, b;
    int ans = false;
    
    cin >> a >> b;
    
    if ((a % 3) == 0) {
        ans = true;
    }
    else if ((b % 3) == 0) {
        ans = true;
    }
    else if (((a + b) % 3) == 0) {
        ans = true;
    }
    
    cout << (ans ? "Possible" : "Impossible") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}

int main(){
    ll H,W;
    cin >> H >> W;
    vector<string> S(H);
    vector<vector<ll>> L(H,vector<ll>(W)), R(H,vector<ll>(W)), U(H,vector<ll>(W)), D(H,vector<ll>(W));
    rep(i,H){
        cin >> S[i];
    }
    rep(i,H){
        ll cnt = 0;
        rep(j,W){
            if(S[i][j] == '.'){
                cnt++;
                L[i][j] = cnt;
            }else{
                cnt = 0;
                L[i][j] = 0;
            }
        }
    }
    rep(i,H){
        ll cnt = 0;
        rep(j,W){
            if(S[i][W-1-j] == '.'){
                cnt++;
                R[i][W-1-j] = cnt;
            }else{
                cnt = 0;
                R[i][W-1-j] = 0;
            }
        }
    }
    rep(j,W){
        ll cnt = 0;
        rep(i,H){
            if(S[i][j] == '.'){
                cnt++;
                U[i][j] = cnt;
            }else{
                cnt = 0;
                U[i][j] = 0;
            }
        }
    }
    rep(j,W){
        ll cnt = 0;
        rep(i,H){
            if(S[H-1-i][j] == '.'){
                cnt++;
                D[H-1-i][j] = cnt;
            }else{
                cnt = 0;
                D[H-1-i][j] = 0;
            }
        }
    }
    ll ans = 0;
    rep(i,H){
        rep(j,W){
            if(S[i][j]=='.'){
                cmax(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 129664
#include <iostream>
using namespace std;
#define rep(i, N) for(i = 0; i < N; i++)
#define ll long long

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

  ll ans = 0;
  ans = (long int)(X / 500) * 1000;
  ans += X % 500 / 5 * 5;

  cout << ans;
  return 0;
}

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

int main() {
  string S;
  cin >> S;

  int cnt = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == 'x') cnt++;
  }

  if (cnt >= 8)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin >> n >> m;
    int s[m], c[m], num[n] = {0}, flag[n] = {0};
    bool no = false;
    for (int i = 0; i < m; i++){
        cin >> s[i] >> c[i];
        if(flag[s[i] - 1] && num[s[i] - 1] != c[i])
            no = true;
        num[s[i] - 1] = c[i];
        flag[s[i] - 1] = 1;
    }
    
    //先頭が 0 指定された時だけにする
    // if(num[0] == 0 && n != 1)
    //     no = false;
    if(num[0] == 0 && n != 1){
        if (flag[0] == 1)
            no = true;
        else
            num[0] = 1;
    }
        

    // for (int i = 0; i < n; i++)
    //     cout << num[i];

    // if(m == 0) {
    //     cout << 0 << endl;
    //     return 0;
    // }
    
    if(no)
        cout << -1;
    else
        for (int i = 0; i < n; i++)
            cout << num[i];
    
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
s = gets.chomp
a = Hash.new(0)
if s.size > 2
  a[s[0]] += 1
  a[s[1]] += 1
  for i in 0..s.size-3
    a[s[i+2]] += 1
    if a[s[i]] >= 2 || a[s[i+1]] >= 2
      puts "#{i+1} #{i+3}"
      exit
    end
    a[s[i]] -= 1
  end
else
  if s[0] == s[1]
    puts "1 2"
    exit
  end
end
puts "-1 -1"

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

int main(void){
  int n;
  cin >> n;
  int abcount = 0,headB = 0,tailA = 0;
  vector<string> str(n);
  bool bigflag = false;
  for(int i = 0; i != n; i++){
    vector<bool> flag(2,false);
    cin >> str[i];
    for(int j = 1; j != str[i].size(); j++){
      if(str[i][j - 1] == 'A' && str[i][j] == 'B')abcount++;
    }

    if(str[i][0] == 'B'){
      headB++;
      flag[0] = true;
    }
    if(str[i][str[i].size() - 1] == 'A'){
      tailA++;
      flag[1] = true;
    }
    if(flag[0] != flag[1])bigflag = true;
  }
  int temp = 1;
  if(bigflag == true || min(headB,tailA) == 0)temp = 0;
  /*cout << "abcount:" << abcount << endl;
  cout << "min(headB,tailA):" << min(headB,tailA) << endl;
  cout << "temp:" << temp << endl; */
  cout << abcount + min(headB,tailA) - temp << endl;
  return 0;
}

Measured memory_bytes: 768
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::HashSet;
use std::cmp;
use std::f64::consts;

fn main() {
    let n: i64  = read();
    let k: i64 = read();

    let ans: i64 = if k % 2 == 0 {
        let mut count: i64 = 0;
        count += ((1..n+1).collect::<Vec<i64>>()
            .into_iter().filter(|i| i%k==0).count() as i64).pow(3);
        count += ((1..n+1).collect::<Vec<i64>>()
            .into_iter().filter(|i| i%k==k/2).count() as i64).pow(3);
        count
    } else {
        ((1..n+1).collect::<Vec<i64>>()
            .into_iter().filter(|i| i%k==0).count() as i64).pow(3)
    };
    println!("{}", ans);

//    let mut count = 0;
//
//    if k % 2 == 0 {
//        let mut count1: i64 = 0;
//        // kで割ったあまりが0の場合
//        for i in 1..n+1 {
//            if i % k == 0 {
//                count1+=1;
//            }
//        }
//        count+=(count1*count1*count1);
//
//        let mut count2: i64 = 0;
//        // 全部 kで割ったあまりが k/2 の場合
//        for i in 1..n+1 {
//            if i % k == (k/2) {
//                count2+=1;
//            }
//        }
//
//        // 全部 k / 2の場合
//        count += (count2*count2*count2);
//    } else {
//        let mut count1: i64 = 0;
//        // kで割ったあまりが0の場合
//        for i in 1..n+1 {
//            if i % k == 0 {
//                count1+=1;
//            }
//        }
//        count+=(count1*count1*count1);
//    }
//
//    println!("{}", count);
}

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

// 最大公約数
fn gcd(a: i32, b: i32) -> i32 {
    match b {
        0 => a,
        _ => gcd(b, a % b)
    }
}

// 最小公倍数
fn lcm(a: i32, b: i32) -> i32 {
    a * b / gcd(a, b)
}

// 階乗
fn kaijou(n: i32)->i32 {
    if n == 1 {
        return n;
    }
    return n * kaijou(n-1);
}

Measured memory_bytes: 8444