akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
import sys
ans = {"a":0,"b":0,"c":0,"d":0,"e":0,"f":0,"g":0,"h":0,
    "i":0,"j":0,"k":0,"l":0,"m":0,"n":0,"o":0,"p":0,
    "q":0,"r":0,"s":0,"t":0,"u":0,"v":0,"w":0,"x":0,
    "y":0,"z":0}
lines = sys.stdin.readlines()
for line in lines:
    chars = list(line)
    for ch in chars:
        if ch == 'A' or ch =='a':
            ans["a"] += 1
        elif ch == 'B' or ch == 'b':
            ans["b"] += 1
        elif ch == 'C' or ch == 'c':
            ans["c"] += 1
        elif ch == 'D' or ch == 'd':
            ans["d"] += 1
        elif ch == 'E' or ch == 'e':
            ans["e"] += 1
        elif ch == 'F' or ch == 'f':
            ans["f"] += 1
        elif ch == 'G' or ch == 'g':
            ans["g"] += 1
        elif ch == 'H' or ch == 'h':
            ans["h"] += 1
        elif ch == 'I' or ch == 'i':
            ans["i"] += 1
        elif ch == 'J' or ch == 'j':
            ans["j"] += 1
        elif ch == 'K' or ch == 'k':
            ans["k"] += 1
        elif ch == 'L' or ch == 'l':
            ans["l"] += 1
        elif ch == 'M' or ch == 'm':
            ans["m"] += 1
        elif ch == 'N' or ch == 'n':
            ans["n"] += 1
        elif ch == 'O' or ch == 'o':
            ans["o"] += 1
        elif ch == 'P' or ch == 'p':
            ans["p"] += 1
        elif ch == 'Q' or ch == 'q':
            ans["q"] += 1
        elif ch == 'R' or ch == 'r':
            ans["r"] += 1
        elif ch == 'S' or ch == 's':
            ans["s"] += 1
        elif ch == 'T' or ch == 't':
            ans["t"] += 1
        elif ch == 'U' or ch == 'u':
            ans["u"] += 1
        elif ch == 'V' or ch == 'v':
            ans["v"] += 1
        elif ch == 'W' or ch == 'w':
            ans["w"] += 1
        elif ch == 'X' or ch == 'x':
            ans["x"] += 1
        elif ch == 'Y' or ch == 'y':
            ans["y"] += 1
        elif ch == 'Z' or ch == 'z':
            ans["z"] += 1

for al, count in ans.items():
    print(al + " : " + str(count))


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

int main() {
  int A, a, b, c, d;
  cin >> A;
  a=A/1000;
  b=(A-a*1000)/100;
  c=(A-(a*1000+b*100))/10;
  d=A-(a*1000+b*100+c*10);
  if ( a==b && b==c ) {
  cout << "Yes" << endl;
  }
  else if ( b==c && c==d ) {
  cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
using System.Collections.Generic;
using System.Linq;
using System;

public class Cake
{
    public int w { get; set; }
    public int d { get; set; }
    public int s { get; set; }
}

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var cakes = new List<Cake>();
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]);
            var w = int.Parse(line[1]);
            var d = int.Parse(line[2]);
            if (n == 0 && w == 0 && d == 0) break;
            cakes.Add(new Cake { w = w, d = d, s = w * d });
            for (int i = 0; i < n; i++)
            {
                string[] line2 = Console.ReadLine().Trim().Split(' ');
                var p = int.Parse(line2[0]);
                var s = int.Parse(line2[1]);
                cutCake(cakes, p, s);
            }
            var retlist = cakes.OrderBy(x => x.s).Select(x => x.s).ToArray();
            for (int j = 0; j < retlist.Length; j++)
                if (j == retlist.Length - 1) Console.WriteLine(retlist[j]);
                else Console.Write("{0} ", retlist[j]);
        }
    }
    public static void cutCake(List<Cake> c, int p, int s)
    {
        var nw = c[p - 1].w;
        var nd = c[p - 1].d;
        while (true)
        {
            if (s < nw)
            {
                c.RemoveAt(p - 1);
                if (s < nw - s)
                {
                    c.Add(new Cake { d = nd, w = s, s = nd * s });
                    c.Add(new Cake { d = nd, w = nw - s, s = nd * (nw - s) });
                }
                else
                {
                    c.Add(new Cake { d = nd, w = nw - s, s = nd * (nw - s) });
                    c.Add(new Cake { d = nd, w = s, s = nd * s });
                }
                return;
            }
            else if (s - nw < nd)
            {
                c.RemoveAt(p - 1);
                if (s - nw < nd - s + nw)
                {
                    c.Add(new Cake { d = s - nw, w = nw, s = (s - nw) * nw });
                    c.Add(new Cake { d = nd - s + nw, w = nw, s = (nd - s + nw) * nw });
                }
                else
                {
                    c.Add(new Cake { d = nd - s + nw, w = nw, s = (nd - s + nw) * nw });
                    c.Add(new Cake { d = s - nw, w = nw, s = (s - nw) * nw });
                }
                return;
            }
            else s -= (nd + nw);
        }
    }
}

Measured memory_bytes: 10300
# -*- coding: utf-8 -*-
import math
import sys
import itertools
import numpy as np
import functools
import string

ret = {}
n = int(input())
for i in range(n):
    s = input()
    d = {x : s.count(x) for x in s}
    for c in  string.ascii_lowercase:
        if c in d:
            continue
        d[c] = 0

    for c in d:
        if c in ret:
            ret[c] = min(ret[c], d[c])
        else:
            ret[c] = d[c]

s = ''
for c in ret:
    s += c * ret[c]
print(''.join(sorted(s)))


Measured memory_bytes: 12460
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
 int main(){
 int  b = 0, c = 0, count = 0, ans = 0, n = 0,h=0,l=0,d=0,e=0,f=0,g=0,m,v,p;
	string s,t;
	vector<int> a(0);
	cin >> s >> t ;
	cout << t << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
using namespace std;
const int N = 1e6 + 5;
const ll inf = -1e18;
const ll MOD = 998244353;

ll fact[N];
map<pair<ll, pair<ll, ll> > , bool> mp;
ll power(ll x, ll y){
    x %= MOD;
    ll ans = 1;
    while(y){
        if(y & 1)
            ans = (ans * x) % MOD;
        y >>= 1LL;
        x = (x * x) % MOD;
    }
    return ans;
}
ll ad(ll a, ll b){
    return((a % MOD + b % MOD) % MOD);
}
ll sub(ll a, ll b){
    return((a % MOD - b % MOD + MOD) % MOD);
}
ll mul(ll a, ll b){
    return(((a % MOD) * (b % MOD)) % MOD);
}
ll divi(ll a, ll b){
    return(mul(a, power(b, MOD - 2)) % MOD);
}

int main(){
   fast; 
   ll n, a, b, k, t, tt, ttt, ans = 0;
   cin >> n >> a >> b >> k;
   fact[0] = fact[1] = 1;
   for(int i = 2; i <= n + 1; i += 1){
      fact[i] = mul(fact[i - 1], i);
   }
   // a * (x + z) + b * (y + z);
   for(int i = 0; i <= n; i += 1){
      t = k - (a * i);
      if(t < 0)
         break;
      if(t % b)
         continue;
      t = t / b;
      if(t > n)
         continue;
      tt = mul(fact[i], fact[n - i]);
      tt = divi(fact[n], tt);
      ttt = mul(fact[n - t], fact[t]);
      ttt = divi(fact[n], ttt);
      ans = ad(ans, mul(tt, ttt));

   }
      cout << ans;



   return 0;
} 

Measured memory_bytes: 4352
##B
N = int(input())
S = list(input() for i in range(N))
a=0
b=0
c=0
d=0
for i in S:
    if i =="AC":
        a +=1
    elif i =="WA":
        b +=1
    elif i =="TLE":
        c +=1
    elif i =="RE":
        d +=1
print("AC x "+ str(a))
print("WA x "+ str(b))
print("TLE x "+ str(c))
print("RE x "+ str(d))

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

int main(){
  int N,sum;
  cin >>N;
  sum=0;
  
  vector<int> food(N),addsatisfy(N-1);
  
  for (int i=0;i<N;i++){
    cin >>food.at(i);
  }
  for (int i=0;i<N;i++){
    int bi;
    cin >>bi;
    sum+=bi;
  }
  for (int i=0;i<N-1;i++){
    cin >>addsatisfy.at(i);
  }
  for (int i=0;i<N-1;i++){
    if (food.at(i)+1==food.at(i+1)){
      sum+=addsatisfy.at(food.at(i)-1);
    }
  }
  cout << sum <<endl;
}

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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for(int i = m; i < (int)(n); ++i)
#define pb(e) push_back(e)

typedef long long ll;

int main()
{
    int ans = 0, sz;
    string str;
    cin >> str; sz = str.size();
    rep(i, sz / 2) {
        switch(str[i]) {
            case 'i': if(str[sz-i-1] != 'i') ++ans; break;
            case 'w': if(str[sz-i-1] != 'w') ++ans; break;
            case '(': if(str[sz-i-1] != ')') ++ans; break;
            case ')': if(str[sz-i-1] != '(') ++ans; break;
        }
    }
    if(sz & 1 && (str[sz/2] != 'i' && str[sz/2] != 'w'))
        ++ans;
    cout << ans << endl;
}

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

#define ll long long
#define ld long double
#define ii pair<int ,int >
#define S second
#define F first
#define PI 3.1415926535897932384626
#define SPEED std::ios_base::sync_with_stdio(false);



int main(){
    SPEED
    vector<char>ans;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='B'){
            if(ans.size()>0)ans.pop_back();
        }
        else ans.push_back(s[i]);
    }
    for(auto x : ans){
        cout<<x;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 21474836

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

  int ans=0;
  rep(i,n){
    int k;
    cout << "lst " << i << endl;
    cin>>k;
    ans += k * (k-1);
    rep(j,k){
      int d;
      cin>>d;
    }
  }

  cout << "ans " << ans << endl;

  return 0;
}

Measured memory_bytes: 3112
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
#N, K = map(int, input().split())
# 文字列の入力
N = int(input())
#開業されたN個要素を受け付ける
#list = [input() for i in range(N)]
#input_list = [list(map(int, input().split())) for i in range(N)]

ans = ""
if N%10 == 0:
    ans = "pon"
elif N%10 == 1:
    ans = "pon"
elif N%10 == 2:
    ans = "hon"
elif N%10 == 3:
    ans = "bon"
elif N%10 == 4:
    ans = "hon"
elif N%10 == 5:
    ans = "hon"
elif N%10 == 6:
    ans = "pon"
elif N%10 == 7:
    ans = "hon"
elif N%10 == 8:
    ans = "pon"
elif N%10 == 9:
    ans = "hon"

print(ans)


Measured memory_bytes: 61592
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

// fatorial.cpp depend on this.
#ifndef MOD_INT
#define MOD_INT
template<int mod>
struct ModInt{
	private:
		int x;

	public:
		ModInt() : x(0){}
		ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod){}
	
		ModInt &operator+=(const ModInt &p){
			if((x += p.x) >= mod) x -= mod;
			return *this;
		}
		ModInt &operator-=(const ModInt &p){
			if((x += mod - p.x) >= mod) x -= mod;
			return *this;
		}
		ModInt &operator*=(const ModInt &p){
			x = (int) (1LL * x * p.x % mod);
			return *this;
		}
		ModInt &operator/=(const ModInt &p){
			*this *= p.inverse();
			return *this;
		}
	
		ModInt operator-() const {return ModInt(-x);}
		ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;}
		ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;}
		ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;}
		ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;}
		bool operator==(const ModInt &p) const {return x == p.x;}
		bool operator!=(const ModInt &p) const {return x != p.x;}
	
		template<typename T>
		operator T() const {return (T)x;}
	
		ModInt inverse() const {
			int a = x, b = mod, u = 1, v = 0, t;
			while(b > 0) {
				t = a / b;
				swap(a -= t * b, b);
				swap(u -= t * v, v);
			}
			return ModInt(u);
		}
	
		ModInt pow(int64_t n) const {
			ModInt ret(1), mul(x);
			while(n > 0) {
				if(n & 1) ret *= mul;
				mul *= mul;
				n >>= 1;
			}
			return ret;
		}
	
		friend ostream &operator<<(ostream &os, const ModInt &p){
			return os << p.x;
		}
	
		friend istream &operator>>(istream &is, ModInt &a){
			int64_t t;
			is >> t;
			a = ModInt< mod >(t);
			return (is);
		}
	
		static int get_mod(){return mod;}
};

using mint = ModInt<MOD>;
#endif

mint dp[100010][2];

int main(void){
	string L;
	cin >> L;
	int len = (int)L.size();

	dp[0][0] = 1;
	// dp[0][1] = 1;
	for(int i = 0; i < len; i++){
		int num = L[i] - '0';
		dp[i+1][1] += dp[i][1] * 3;
		if(num){
			dp[i+1][1] += dp[i][0];
			dp[i+1][0] += dp[i][0] * 2;
		}else{
			dp[i+1][0] += dp[i][0];
		}
		// cout << "dp[" << i+1 << ", " << 0  <<"] = " << dp[i+1][0] << '\n';
		// cout << "dp[" << i+1 << ", " << 1  <<"] = " << dp[i+1][1] << '\n';
	}

	cout << dp[len][0] + dp[len][1] << '\n';

	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i< n; i++)
        cin >> a[i];
    sort(a.begin(),a.end(),greater<int>());
    int alice = 0;
    for(int i = 0; i < n; i+=2)
        alice += a[i];
    int bob= 0;
    for(int i = 1; i < n; i+=2)
        bob += a[i];
    cout << alice - bob;
   return 0;
}

Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // min, max, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <stack> // stack
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)

using namespace std;

typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;

int main() {
	int n;
	cin >> n;
	vector<pair<string, pair<int, int>>> v(n);
	for (int i = 0; i < n; i++) {
		string a;
		int b;
		cin >> a >> b;
		v[i] = make_pair(a, make_pair((-1) * b, i + 1));
	}

	sort(v.begin(), v.end());

	for (int i = 0; i < n; i++) {
		cout << v[i].second.second << endl;
	}
}

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

using namespace std;

int main(){
    int n;
    int *a;

    cin >> n;
    a = new int[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a,a+n);
    int left = a[n-1];
    int right = min(a[0],left - a[0]);
    for(int i=0;i<n-1;i++){
        int tmp = min(a[i],left - a[i]);
        if(tmp > right){
            right = a[i];
        }
    }
    cout << left << " " << right << endl;
    delete[] a;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
char str[10];
bool jay1,jay2;

int main()
{
	scanf("%s",&str);
	for (register int i=0; i<3; ++i) 
	{
		if (str[i]=='A') jay1=true;
		if (str[i]=='B') jay2=true;
	}	
	if (!jay1 || !jay2) puts("No");
	else puts("Yes"); 
	return 0;
}

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

int main() {
  std::string x(3, ' ');
  scanf("%s", &x[0], x.size());
  if (x[0] != x[1] && x[1] != x[2] && x[2] != x[0])
    printf("Yes");
  else
    printf("No");
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {

            String N = Console.ReadLine();
            int len = N.Length;
            long sum = 0;

            for(int i = 0; i < len; i++)
            {
                sum += long.Parse(N[i].ToString());
            }
            if (sum % 9 == 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            //BigInteger N = BigInteger.Parse(Console.ReadLine());
            //string S = N.ToString();
            //BigInteger A = 0;
            //for (int i = 0; i < S.Length; i++)
            //{
            //    BigInteger I = BigInteger.Parse(S.Substring(i, 1));
            //    A += I;
            //}
            //if (A % 9 == 0)
            //{
            //    Console.WriteLine("Yes");
            //}
            //else
            //{
            //    Console.WriteLine("No");
            //}
        }
    }
}
//int[] N = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();

Measured memory_bytes: 32996
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    int A,B,C,D;
    scanf("%d%d%d%d",&A,&B,&C,&D);
    cout<<max(A*B,C*D)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll N=1e6+5,inf=1e18,mod=1e9+7;
#define test ll testcases;cin>>testcases; while(testcases--)
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define vld vector<ld>
#define pll pair<ll,ll> 
#define pld pair<ld,ld> 
#define vpll vector<pll>
#define vpld vector<pld>
#define all(X) X.begin(),X.end()
#define sz(x) ((ll)((x).size()))
const ld pi=3.141592653589793238;

bool check_prime(ll n)
{
	ll flag=0,i;
	for(i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			flag=1;
			break;
		}
	}
	if(n==1)
	{
		return false;
	}
	else if(flag==0 || n==2 || n==3)
	{
		return true;
	}
	else
	{
		return false;
	}
}

ll fastexpo(ll a,ll b,ll MOD) 
{
	ll result=1;
	while(b>0)
	{
		if(b%2==1)
		{
			result=(result*a)%MOD;
		}
		a=(a*a)%MOD;
		b=b/2;
	}
	return result;
}

vll G[N];
ll 	dp[N][2];

ll dfs(ll node,ll parent,ll k)
{
	if(sz(G[node])==1 && node!=1)
	{
		dp[node][k]=1;
		return 1;
	}
	if(dp[node][k]!=-1)
	{
		return dp[node][k];
	}
	ll i,ans=1;
	for(i=0;i<sz(G[node]);i++)
	{
		if(parent!=G[node][i])
		{
			if(k==0)
			{
				ans=(ans*(dfs(G[node][i],node,0)+dfs(G[node][i],node,1)))%mod;
			}
			else
			{
				ans=(ans*dfs(G[node][i],node,0))%mod;
			}
		}
	}
	dp[node][k]=ans;
	return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,u,v,ans,k1,k2;
    cin>>n;
    for(i=1;i<n;i++)
    {
    	cin>>u>>v;
    	G[u].pb(v);
    	G[v].pb(u);
    }
    memset(dp,-1,sizeof(dp));
    k1=dfs(1,1,0);
    k2=dfs(1,1,1);
    ans=(k1+k2)%mod;
    cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 54140
#include <stdio.h>
#include <string.h>
char tolower(char *);//char Large to Small

int main(){
  int i=0,count=0;
  char t,txt[1001]={},word[11]={},end[]={"END_OF_TEXT"};
  scanf("%s",word);
  tolower(word);
  scanf("%c",&t);
  while( scanf("%s",txt)){
    if( strcmp(txt,end)==0 ) break;
    tolower(txt);
    if( strcmp(txt,word)==0 ) count++;
  }
    
  printf("%d\n",count);

  return 0;
}

char tolower(char *c){
  int i,len=strlen(c);
  for(i=0;i<len;i++){
    if((int)c[i]>=65&&(int)c[i]<=90){
      c[i]+=32;
    }
  }
  return c;
}

Measured memory_bytes: 560
import java.util.*;
public class Main{
	public static void main(String args[]){
	    Scanner input = new Scanner(System.in);
	    
	    Queue<Integer>num = new LinkedList<Integer>();
	    Queue<String> p = new LinkedList<String>();
	    int number = input.nextInt();
	    int time = input.nextInt();
	    int timer = 0;
	    for(int i = 0; i < number; i++ ){
	    	p.add(input.next());
	        num.add(input.nextInt());
	    }//for
	    
	    while(!num.isEmpty()){
	    	String test2 = p.remove();
	        int test = num.remove();
	        if(test - time <= 0 ){
	            timer += test;
	            System.out.println(test2 +  " " +(timer));
	        }//if
	        if(test - time > 0){
	        	p.add(test2);
	            num.add(test - time);
	            timer += time;
	        }//if
	        
	    }//while
	    
}//main
}//main


Measured memory_bytes: 78004
n,m,c = map(int, input().split())
b_lst = list(map(int, input().split()))
ans = 0
for i in range(n):
    a_lst = list(map(int, input().split()))
    ttl = c
    for a,b in zip(a_lst,b_lst):
        ttl+=a*b
    if ttl > 0:
        ans += 1
print(ans)

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

#define LIMIT 1000000

char in[LIMIT], *p = in;

template <class T>
__inline void get(T &res) {

	res = 0;

	while (*p < '0')++p;

	while (*p >= '0')
		res = res * 10 + *p++ - '0';

}

#define ri register int
#define rl register long long
#define min(x, y) (x < y ? x : y)

int n, m, num[100005];

signed main(void) {
	
	fread(in, 1, LIMIT, stdin);
	
	get(n);
	get(m);
	
	for (ri i = 1; i <= n; ++i)
		get(num[i]);
		
	ri ans = 0x3f3f3f3f, sum = 0;
	
	for (ri i = 1, j = 0; i <= n; ++i) {
		
		while (j < n && sum < m)
			sum += num[++j];
			
		if (sum >= m)
			ans = min(ans, j - i + 1);
		sum -= num[i];
		
	}
	
	if (ans < 0x3f3f3f3f)
		printf("%d\n", ans);
	else
		printf("%d\n", 0);
	
}

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

int main() {
//	freopen("input.txt", "r", stdin);
	int n;
	cin >> n;
	int arr[2][103] = {0};
	for (int i = 0; i < 2; ++i)
	{
		for (int j = 0; j < n; ++j)
			cin >> arr[i][j];
	}
	int ans = INT_MIN;
	for (int i = 1; i <= n; ++i)
	{
		int temp = 0;
		for (int j = 0; j < i; ++j)
		{
			temp += arr[0][j];
		}
		for (int j = i-1; j < n; ++j)
			temp += arr[1][j];
		ans = max(temp, ans);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scanIn = new Scanner(System.in);
        int a = scanIn.nextInt();
        int b = scanIn.nextInt();
        int c = scanIn.nextInt();
        if((a==5 && b==5) || (b==5 && c==5) || (c==5 && a==5)){
            if(a==7 || b==7 || c==7){
                System.out.println("YES");
            }
        }else{
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 9552
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)




int main() {

	ll v_max = pow(10, 18);
	ll N;
	
	std::cin >> N;

	unsigned long long ans = 1,A;
	bool flg0=false, flgm=false;
	rep(i, 0, N) {
		std::cin >> A;
		if (A == 0) {
			flg0 = true;
		}
		if (!flg0 && !flgm) {
			if (A > v_max || ans > v_max) {
				flgm = true;
			}
			else {
				unsigned long long tmp = ans;
				ans *= A;
				if (ans > v_max || ans < tmp) {
					flgm = true;
				}
			}
		}
	}
	if (flg0) {
		std::cout << 0 << endl;
	}
	else if (flgm) {
		std::cout << -1 << endl;
	}
	else {
		std::cout << ans << endl;
	}
	return 0;
}


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

limit = [0, w, 0, h]

for i in range(n):
  x, y, a = map(int, input().split())
  a -= 1
  if a == 0:
    limit[a] = max(limit[a], x)
  if a == 1:
    limit[a] = min(limit[a], x)
  if a == 2:
    limit[a] = max(limit[a], y)
  if a == 3:
    limit[a] = min(limit[a], y)
    
dx = max(0, limit[1] - limit[0])
dy = max(0, limit[3] - limit[2])
print(dx * dy)

Measured memory_bytes: 3064
#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 k,s;
  cin >>k>> s;
  int ans=0;
  rep(i,k+1){
    rep(j,k+1){
      
        if(s-i-j>=0&&s-i-j<=k){
          ans++;
        }
      
    }
  }
  cout<<ans<<endl;
 
}






Measured memory_bytes: 256
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

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

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

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	N := readInt()
	a := 0
	for i := 0; i < N; i++ {
		a |= readInt()
	}

	count := 0
	for a&1 != 1 {
		count++
		a /= 2
	}
	println(count)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    int X,N,hako = 0,min=10000;
    cin >> X >> N;
    vector<int> P(N);
    bool fla =true;

    for(int i = 0;i < N;i++)
        cin >> P.at(i);

    sort(P.begin(),P.end());

    for(int i = 0;i <= 101;i++){
        fla = true;
        for(int j = 0;j < N;j++){
            if(P.at(j) == i){
                fla = false;
                break;
            }
        
        }
        if(fla){
            if(abs(X - i) < min){
                hako = i;
                min = abs(X -i);
            }
        }
    }

    cout << hako << endl;    
    
}

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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define F first
#define S second

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main ()
{
    fastio
    lli x , a , b ;
    cin >> x >> a >> b ;
    cout << (b <= x ? "delicious" : (b <= a + x ? "safe" : "dangerous")) ;

    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[]str = Console.ReadLine().Split();
		long A = long.Parse(str[0]);
		long B = long.Parse(str[1]);
		long C = long.Parse(str[2]);
		long K = long.Parse(str[3]);
		long ans = 0;
		ans += Math.Min(A,K) * 1;
		K -= Math.Min(A,K);
		K -= Math.Min(B,K);
		if(K>=0){
			ans -= Math.Min(C,K) * 1;
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 17860
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n;
    cin >> n;
    ll x = 1;
    while(x <= n){
      x*=2;
    }
    cout << x/2 << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using P = pair<ll,int>;
using G = vector<vector<int>>;
const long long INF = 1LL << 60;


int main(){
  string s,ans;
  bool rev = false ;//反転ているかどうか，反転：１，反転なし：０
  ll q;
  cin >> s >> q;
  deque<char> Q;
  for(char c:s) Q.push_back(c);

  for(ll i = 1LL;i<=q;i++){
    int t=0,f=0;
    char c;
    //scanf("%d %d %s", &t,&f,&c);
    scanf("%d",&t);
    if(t == 1){ 
      rev = !rev;
    }else{
      cin >> f >> c;
      if(rev) f = 3-f;
      if(f == 1 ){
        Q.push_front(c);
      }else{
        Q.push_back(c);
      }
    }
  }
  
  if(rev) reverse(Q.begin(),Q.end());
  for(char c:Q) ans+=c;
  cout << ans << endl;
  
}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const double PI = 3.14159265358979323846;
template <class T, class U>
void chmin(T& t, const U& u) {
  if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
  if (t < u) t = u;
}

int main(void) {
  int n;
  cin >> n;
  vector<ll> a(n);
  ll sum = 0;
  rep(i, n) cin >> a[i], sum += a[i];
  ll res = 0;
  for (int i = 0; i < n; i++) {
    sum -= a[i];
    ll tmp = a[i] * (sum % MOD);
    res += tmp % MOD;
    res %= MOD;
  }
  cout << res << endl;
  return 0;
}

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

int main() {
	int N, T;
	cin >> N >> T;
	vector<int> A(N), B(N);
	for (int i = 0; i < N; i++) cin >> A[i] >> B[i];
	
	vector<vector<int>> dp1(N+1, vector<int>(T));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < T; j++) {
			if (j < A[i]) { 
				dp1[i+1][j] = dp1[i][j];
			}
			else {
				dp1[i+1][j] = max(dp1[i][j], dp1[i][j-A[i]]+B[i]);
			}
		}
	}

	vector<vector<int>> dp2(N+2, vector<int>(T));
	for (int i = N-1; i >= 0; i--) {
		for (int j = 0; j < T; j++) {
			if (j < A[i]) {
				dp2[i+1][j] = dp2[i+2][j];
			}
			else {
				dp2[i+1][j] = max(dp2[i+2][j], dp2[i+2][j-A[i]]+B[i]);
			}
		}
	}

	int ans = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= T-1; j++) {
			ans = max(ans, dp1[i-1][j]+dp2[i+1][T-1-j]+B[i-1]);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 70912
def main():
  n = int(input())
  ans = [0 for _ in range(10050)]
  for i in range(1, 105):
    for j in range(1, 105):
      for k in range(1, 105):
        v = i * i + j * j + k * k + i * j + j * k + k * i
        if v < 10050:
          ans[v] += 1
  
  for i in range(n):
    print(ans[i + 1])


if __name__ == '__main__':
  main()


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

int main() {
  int n;
  int *h = new int[n];
  int ans = 0;
  int finished = -1;
  int nextzero;
  int minimum = 0;
  int sum = 0;
  
  cin >> n;
  for (int i = 0; i <= n-1; i++)
  {
    cin >> h[i];
  }
  
  nextzero = n;
  
  for(int i = 0; i <= n-1; i++)
  {
    sum += h[i];
  }
  
  while(sum != 0)
  {
    nextzero = n;
    
    while(h[finished + 1] == 0 && finished <= n-1) finished ++;
    for(int i = finished + 1; i <= n-1; i++)
    {
      if(h[i] == 0) {nextzero = i; break;}
      else if(minimum == 0) minimum = h[i];
      else minimum = min(minimum, h[i]);
    }
    
    for(int i = finished + 1; i <= nextzero - 1; i++)
    {
      h[i] -= minimum;
    }
    
    ans += minimum;
    minimum = 0;
    
    sum = 0;
    for(int i = 0; i <= n-1; i++)
    {
      sum += h[i];
    }
  }
  
  cout << ans << endl;
  
  // delete[] h;
  
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

struct Point
{
  long x;
  long y;
};

int solve(long n, long d, const std::vector<Point>& points)
{
  int result = 0;
  long dd = d * d;
  for (const auto& p : points) {
    if (p.x * p.x + p.y * p.y <= dd) ++result;
  }
  return result;
}

int main()
{
  long n, d;
  std::cin >> n >> d;
  std::vector<Point> points(n);
  for (auto& p : points) {
    std::cin >> p.x >> p.y;
  }

  std::cout << std::setprecision(20);
  std::cout << solve(n, d, points) << std::endl;
}


Measured memory_bytes: 6372
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF 100000000000
#define MAX 200001
#define MOD 1000000007

int main(){
    int N; 
    int ans = 0;
    cin >> N;
    vector<queue<int>> P(N);
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N - 1; j++){
            int p;
            cin >> p;
            p--;
            P[i].push(p);
        }
    }
    while(true){
        int flag = 0;
        vector<int> seen(N, 0);
        for(int i = 0; i < N; i++){
            if(P[i].empty() or seen[i] == 1) continue;
            flag = max(1, flag);
            int n = P[i].front();
            if(seen[n] == 1) continue;
            if(P[n].front() == i){
                P[i].pop();
                P[n].pop();
                seen[i] = 1;
                seen[n] = 1;
                flag = 2;
            }
        }
        if(flag == 2) ans++;
        else if(flag == 1){
            ans = -1;
            break;
        }
        else break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 7916
#include <iostream>
#include <string>
#include <sstream>
#include <istream>
#include <vector>
#include <cmath>
using namespace std;

int main()
{
	long double L;
	cin >> L;

	long double s = (L/3) * (L/3) * (L/3);

	cout.precision(13);
	cout << showpoint << s << endl;

	return 0;
}

Measured memory_bytes: 256
from collections import Counter
from itertools import permutations

N, C = map(int, input().split())
D = [[int(x) for x in input().split()] for _ in range(C)]

cnt = [Counter() for _ in range(3)]

for i in range(N):
    c = [int(x)-1 for x in input().split()]
    for j in range(3):
        cnt[j].update(c[(3-(i+2)+j)%3::3])

ans = 1000*500*500+5
for p in permutations(range(C), 3):
    s = 0
    for j in range(3):
        for k, v in cnt[j].items():
            s += D[k][p[j]] * v
    ans = min(ans, s)

print(ans)

Measured memory_bytes: 44636
def main():
    n = int(input())
    a_lst1 = list(map(int, input().split()))
    a_lst2 = list(map(int, input().split()))
    candies_lst = []

    tmp = 1
    while tmp <= n:
        a1_tmp = a_lst1[:tmp]
        a2_tmp = a_lst2[tmp-1:]
        a1 = sum(a1_tmp)
        a2 = sum(a2_tmp)

        tmp += 1
        candies = a1 + a2
        candies_lst.append(candies)

    maximum = max(candies_lst)
    print(maximum)


if __name__ == '__main__':
    main()

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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long ll;

ll n, w;
pair<ll, ll> a[105];

ll memo[105][100005];

ll dp(ll pos, ll curw){
	if(curw > w)	return -1*(1e12 + 5);
	if(pos == n)	return 0;
	if(memo[pos][curw] != -1)	return memo[pos][curw];
	return memo[pos][curw] = max(dp(pos+1, curw), a[pos].S + dp(pos+1, curw + a[pos].F));
}

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

	memset(memo, -1, sizeof(memo));

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

	cout << dp(0, 0);

	return 0;
}

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

int main(void){
    int n;cin>>n;
    int a[200001];
    int tmp;
    for(int i=0;i<n;++i)cin>>a[i];
    sort(a, a+n);
    for(int i=0;i<n-1;i++){
        if(a[i]==a[i+1]){cout<<"NO"<<endl;return 0;}
    }
    cout<<"YES"<<endl;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
int q,a,b,c,d,k,p;
using namespace std;
bool check(int mid){
	int bb=(mid-1)/k;
	return b-bb<=1ll*(a-mid+1)*k;
}
int main(){
	scanf("%d",&q);while(q--){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		k=(max(a,b)+min(a,b))/(min(a,b)+1);
		int l=1,r=min(1ll*a,1ll*(b+1)*k),res=0;
		while(l<=r){
			int mid=l+r>>1;
			if(check(mid))res=mid,l=mid+1;
			else r=mid-1;
		}
		if(res)res+=(res-1)/k;
		for(int i=c;i<=d;++i)
			if(i<=res)putchar(i%(k+1)?'A':'B');
			else putchar((a+b-i+1)%(k+1)?'B':'A');
		puts("");
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n, a, b; vector<int>h;

bool check(int s) {
	int c = a - b;
	vector<int>t = h;
	for (int i = 0; i < n; i++) {
		t[i] = max(0LL, t[i] - 1LL * s * b);
	}
	long long req = 0;
	for (int i = 0; i < n; i++) {
		req += (t[i] + c - 1) / c;
	}
	return req <= s;
}

int main() {
	cin >> n >> a >> b; h.resize(n);
	for (auto&& x : h)cin >> x;
	int L = 0, R = 1e9;
	while (L + 1 < R) {
		int mid = (L + R) / 2;
		if (check(mid))R = mid; else L = mid;
	}
	cout << R << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
using P = pair <int,int>; //to, cost
using WeightedGraph = vector<vector <P>>; //to cost
const long long INF = 1LL << 60;
const int MOD = 1000000007;
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; }
//https://www.creativ.xyz/dump-cpp-652/
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
 
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

#ifdef DEBUG_
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

signed main(void) { cin.tie(0); ios::sync_with_stdio(false);
    int h,n; cin>>h>>n;
    vector <vector<int>> dp(n+10,vector <int>(10100,1145141919));
    rep(i,n){
        dp[i][0] = 0;
    }
    rep(i,n){
        int a,b; cin>>a>>b;
        rep(j,11451){
            if(j+a < 10100) 
            chmin(dp[i][j+a], dp[i][j] + b);
            chmin(dp[i+1][j], dp[i][j]);
        }
    }
    int ans = 1145141919;
    for(int i=h;i<10100;i++){
        chmin(ans, dp[n][i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 40192
import java.util.*;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Pair> pairs = new ArrayList<Pair>();
        for (int i = 0; i < n; i++) {
            String s = sc.next();
            int p = sc.nextInt();
            Pair pa = new Pair(s, p, i + 1);
            pairs.add(pa);
        }
        Collections.sort(pairs);
        for (int i = 0; i < n; i++) {
            int ans = pairs.get(i).pos;
            System.out.println(ans);
        }
        sc.close();
    }
}

class Pair implements Comparable {
    String key;
    int value;
    int pos;

    Pair(String key, int value, int pos) {
        this.key = key;
        this.value = value;
        this.pos = pos;
    }

    @Override
    public int compareTo(Object other) {
        Pair otherPair = (Pair) other;
        if (this.key.equals(otherPair.key)) {
            return otherPair.value - this.value;
        }
        return this.key.compareTo(otherPair.key);
    }
}

Measured memory_bytes: 20948
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        //値を取得
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();   //冷蔵庫の種類数
        int B = sc.nextInt();   //電子レンジの種類数
        int M = sc.nextInt();   //割引券の種類数
        int[] a = new int[A];   //冷蔵庫の値段
        int[] b = new int[B];   //電子レンジの値段
        int[] x = new int[M];
        int[] y = new int[M];
        int[] c = new int[M];   //割引額
        
        for (int i = 0; i < A; ++i){
            a[i] = sc.nextInt();
        }
        for (int j = 0; j < B; ++j){
            b[j] = sc.nextInt();
        }
        for (int i = 0; i < M; ++i){
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
            c[i] = sc.nextInt();
        }
        
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < M; ++i){
            int total = a[x[i]-1] + b[y[i]-1] - c[i];
            min = Math.min(min,total);
        }
        
        Arrays.sort(a);
        Arrays.sort(b);
        
        if (a[0] + b[0] < min){  //昇順に並べた配列の合計が、割引した額のうちの最小値よりも少ない場合
            min = a[0] + b[0];
        }
        
        System.out.println(min);

    }
}

Measured memory_bytes: 63500
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define ll long long int
#define sp ' '
#define intmax 2147483647
#define intmin –2147483648
#define llmax 9223372036854775807
#define llmin -9223372036854775808
using namespace std;

int n, m;
int g[200000][2];
bool x[200000];

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	ll g = gcd(x, y);
	return x / g * y;
}

int main(){
	cin >> n >> m;
	lp(n) 
		x[i] = false;
	lp(m) {
		cin >> g[i][0] >> g[i][1];
		if (g[i][0] == 1)x[g[i][1] - 1] = true;
	}
	lp(m){
			if ((x[g[i][0]-1] && g[i][1] == n) || (x[g[i][1]-1] && g[i][0] == n)) {
				cout << "POSSIBLE" << endl;
				return 0;
			}
		}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 2048
K = int(input())

from collections import deque
d = deque()
for i in range(1,10):
  d.append(str(i))

for _ in range(K):
  a = d.popleft()
  #print(a)
  if a[-1] != '0':
    d.append(a+str(int(a[-1])-1))
  d.append(a+a[-1])
  if a[-1] != '9':
    d.append(a+str(int(a[-1])+1))

ans = a
print(ans)
#print(*ans,sep=' ')


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

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

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

  int n, d;
  cin >> n >> d;
  vector<vector<float>> vec(n, vector<float>(d));
  rep(i, n) {
    rep(j, d) { cin >> vec.at(i).at(j); }
  }

  int ans = 0;
  rep(i, n - 1) {
    for (int j = i + 1; j < n; j++) {
      float tmp = 0;

      rep(k, d) { tmp += pow(vec.at(i).at(k) - vec.at(j).at(k), 2.0); }
      tmp = sqrt(tmp);
      if (floor(tmp) == ceil(tmp)) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
s = int(input())
a = [s]
for i in range(1, 1000001):
    if a[i-1]%2 == 0:
        x = a[i-1]//2
        if x in a:
            print(i+1)
            break
        else:
            a.append(x)
    else:
        y = a[i-1]*3 + 1
        if y in a:
            print(i+1)
            break
        else:
            a.append(y)

Measured memory_bytes: 9020
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()

 
int main() {
  ll X;
  cin>>X;
  ll ans=1;
  for(ll i=2;i<=sqrt(X);i++) {
ll a=i;
    while(a<=X) {
a*=i;
    }
    a/=i;
    ans=max(ans,a);
  }
  
  cout<<ans<<endl;
}
  
  

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

static const int MOD = 1e9+7;
typedef long long ll;

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

    ll ans = 0;

    for(ll i=K; i<=N+1; i++){
        ll mi = i*(i-1)/2;
        ll ma = (N*2-i+1)*i/2;
        ll add = ma - mi +1;
        ans += add;
        ans %= MOD;
    }    

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3600