akhauriyash/Code-Regression huggingface dataset:
// Course＞Introduction to Programming I ＞ ITP1_2_A:   Small, Large, or Equal
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_2_A&lang=jp

// 以下のソースコードには(複数の？)誤りがあるので、このまま提出しても「誤り」と判定されます。
// ソースコード中の誤りを修正し、「正解」（Accepted）を出してください。

// 適宜、paiza.io (https://paiza.io/ja/projects/new) などのC++実行環境を、確認に用いることを推奨します。


#include <iostream>
using namespace std;

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

		if( a == b )
		{
		cout << "a == b" << endl;
		}else{
			if( a > b)
			{
			cout << "a > b" << endl;
			}else{
			cout << "a < b" << endl;
			}
		}

}


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

int main(){
    long long a,b,c,x,y,z,counter=0;
    cin>>a>>b>>c;
    if(a==b && b==c && a%2==0)cout<<-1,exit(0);
    while(!(a%2) && !(b%2) && !(c%2)){
        x=y=z=0;
        x=b/2 + c/2;
        y=a/2 + c/2;
        z=a/2 + b/2;
        a=x;
        b=y;
        c=z;
        counter++;
    }
    cout<<counter<<endl;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
using namespace std;
const int N = 5e2 + 10;
int n, m, q;
int dp[N][N], a[N][N];
int main()
{
    scanf("%d%d%d", &n, &m, &q);
    for (int i = 1; i <= m; i++)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        a[x][y]++;
    }
    for (int i = n; i >= 1; i--)
        for (int j = i; j <= n; j++)
            dp[i][j] = dp[i + 1][j] + dp[i][j - 1] - dp[i + 1][j - 1] + a[i][j];
    for (int i = 1; i <= q; i++)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        printf("%d\n", dp[x][y]);
    }
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  ll N,K,A[2000];
  cin>>N>>K;
  for (int i(0);i<N;i++)cin>>A[i];
  ll B[2000]={0},C[2000]={0};
  for (int i(0);i<N;i++) {
    for (int j(i+1);j<N;j++) {
      if(A[i]>A[j]) B[i]++;
    }
  }
  for (int i(0);i<N;i++) {
    for (int j(0);j<N;j++) {
      if(A[i]>A[j]) C[i]++;
    }
  }
  ll ans(0);
  for (int i(0);i<N;i++) {
    ans+=(K*B[i]%mod+C[i]*(((K*(K-1))/2)%mod));
    ans%=mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
def render_rect(H,W):
    for i in range(H):
        if i in [0,H-1]:
            print("#"*W)
        else:
            print("#"+"."*(W-2)+"#")
    print()

while True:
    H,W = [int(x) for x in input().split()]
    if H==0 and W==0:
        break
    render_rect(H,W)


Measured memory_bytes: 5624
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP((i),0,(n))
#define ALL(v) (v).begin(),(v).end()

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int left = a + b;
	int right = c + d;
	if (left > right)cout << "Left" << endl;
	else if (left < right)cout << "Right" << endl;
	else cout << "Balanced" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;


int main () {
	int a, b,sum=0;
	cin >> a >>b;

	if (a < b) {
		sum += b;
		b--;
	}
	else {
		sum += a;
		a--;
	}

	if (a < b) {
		sum += b;
		b--;
	}
	else {
		sum += a;
		a--;
	}
	cout << sum;

}

Measured memory_bytes: 256
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

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

    int A, B, C;
    cin >> A >> B >> C;
    int a = A * 10 + B + C;
    int b = A + B * 10 + C;
    int c = A + B + C * 10;
    int ans = max({a, b, c});
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main (){
  int x, y;
  std::cin >> x >> y;
  for (int i=0; x!=0 || y!=0; i++)
    {
      if (x>y)
        std::cout << y << " " << x << std::endl;
      else
        std::cout << x << " " << y << std::endl;

      std::cin >> x >> y;
    }
}



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

int main() {
  string S;
  cin >> S;
  int count = 0;
  for (int i = 0; i < 4; i++) {
    if (S.at(i) == '+')
      count++;
    else
      count--;
  }
  cout << count << endl;
  
}


Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>

#include<vector>
#include<string>

#include<algorithm>
#include<cmath>

#include<deque>

using namespace std;
typedef long long ll;
const ll INF = 1e12+1;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}

ll N, K;

int main() {
    cin >> N >> K;
    vector<ll> a(N), b(N);
    vector<pair<ll, ll>> p(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i] >> b[i];
        p[i] = make_pair(a[i],b[i]);
    }
    sort(p.begin(),p.end());
    
    for (int i = 0; i < N; i++) {
        K -= p[i].second;
        if  (K <= 0) {
            cout << p[i].first << endl;
            break;
        }    
    }

}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

#define rep(i,n)  for(int i = 0; i < (int)(n);    i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  long double A, B; std::cin >> A >> B;
  std::cout << (ll)std::floor( A*B ) << std::endl;
  return 0;
}



Measured memory_bytes: 3800
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#define mop 1000000007
using namespace std;

int main() {
    


    long long n;
    cin >> n;
    vector <long long> a;
    for (long long i=0;i<n;i++){
        long long p;
        cin >> p;
        a.push_back(p);
    }
    long long sum = 0;
    long long cnt = 0;
    for (long long i=0;i<n;i++){
        sum += a[i];
        if (i%2 == 0){
            if (sum <= 0){
                cnt += abs(sum) + 1;
                sum += abs(sum) + 1;
            }
        }else{
            if (sum >= 0){
                cnt += sum + 1;
                sum -= sum + 1;
            }
        }

    }
    long long cnt1 = cnt;
    cnt = 0;
    sum = 0;
    for (long long i=0;i<n;i++){
        sum += a[i];
        if (i%2 == 1){
            if (sum <= 0){
                cnt += abs(sum) + 1;
                sum += abs(sum) + 1;

            }
        }else{
            if (sum >= 0){
                cnt += sum + 1;
                sum -= sum + 1;

            }
        }
    }
    long long cnt2 = cnt;
    cout << min(cnt1, cnt2) << endl;

}

Measured memory_bytes: 1400
#include <iostream>


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

    int min = 1;
    int max = N;
    for (int i = 0; i < M; i++) {
        int l, r;
        std::cin >> l >> r;
        if (min < l) {
            min = l;
        }
        if (max > r) {
            max = r;
        }
    }
    if (max >= min) {
        std::cout << max - min + 1 << std::endl;
    } else {
        std::cout << 0 << std::endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
#include <string>
#include <stdio.h>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std;
 
int main(){
    int A, B;
    cin >> A >> B;
    for (int i=1; i<1101; i++){
        if (floor(i * 0.08) == A and floor(i * 0.1) == B){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3620
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb(x)           push_back(x)
#define mkp(x,y)        make_pair(x,y)
#define L               length()
#define int             long long
#define bs              binary_search
#define mod             1e9+7
#define IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define mem0(a)         memset(a,0,sizeof(a))
#define mem1(a)         memset(a,-1,sizeof(a))
#define F               first
#define S               second
#define pii             pair<int,int>
#define vi              vector<int>
#define vs              size()
#define gcd(a,b)        __ gcd(a,b)
#define endl            '\n'
#define atoi            stoi
#define elasped_time    1.0 * clock() / CLOCKS_PER_SEC
#define si              set <int>
#define vpii            vector < pair <int,int> >
#define memf(a)         memset(a,false,sizeof(a))
#define memt(a)         memset(a,true,sizeof(a))
#define xxx             998244353
#define pi              3.141592653589
#define ninf            INT_MIN
#define inf             INT_MAX
#define sz(v)           ((int)(v).size())
#define rep(i,a,b)      for(int i=a;i<=b;i++)
int max(int a,int b){if(a>b){return a;}else{return b;}}
int min(int a,int b){if(a<b){return a;}else{return b;}}
int power(int b,int e)
{
    if(e==0)
    return 1;
    if(e%2)
    return ((b*power((b)*(b),(e-1)/2)));
    else
    return power((b)*(b),e/2);
}
int modpower(int b,int e,int q)
{
    int MOD=q;
    if(e==0)
    return 1;
    if(e%2)
    return ((b%MOD)*modpower((b%MOD)*(b%MOD),(e-1)/2,q))%MOD;
    else
    return modpower((b%MOD)*(b%MOD),e/2,q)%MOD;
}
void dpv(vi v)
{
    for(int i=0;i<v.vs;i++)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
void dpv(vpii v)
{
    for(int i=0;i<v.vs;i++)
    {
        cout<<v[i].F<<" "<<v[i].S<<endl;
    }
}
void dpv(set <int> v)
{
    for(auto i:v)
    {
        cout<<i<<" ";
    }
    cout<<endl;
}
//////////////////////**TREE MOVES STARTS**//////////////////////////////
///// **TREE MOVES ENDS**////////////////////////////

////*SOLUTION TO THE QUESTION STARTS HERE*///////
void oblivious()
{
    int d,t,s;
    cin>>d>>t>>s;
    double j=double(d)/t;
    if(j<=s)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}
signed main()
{
    IOS;
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    int t=1;
    //cin>>t;
    //int z=t;
    while(t--)
    {
        //cout<<"Case #"<<(z-t)<<": ";
        oblivious();
    }
    return 0;
}
//Editorial
/*

    */

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

using namespace std;
set<long long>se;
int main()
{
    int n;
    long long s;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        se.insert(s);
    }
    if(se.size()==n)
        cout<<"YES";
    else cout<<"NO";
    return 0;
}


Measured memory_bytes: 9600
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a,b;
        a = sc.nextInt();
        b = sc.nextInt();
        
        if(a == b){
            System.out.println("a == b");
        }
        else if(a < b){
            System.out.println("a < b");
        }
        else if(a > b){
            System.out.println("a > b");
        }
        
    }
}


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

int main()
{

	int n;
	cin >> n;
	map<int, int> ml;
	map<int, int> mr;
	vector<int> v(n+1);
	for (int i=1;i<=n;++i)
	{
		int a;
		cin >> a;
		v[i]=a;
		//fprintf(stderr,"i: %d a: %d\n",i,a);
		ml[i+a]++;
		mr[i-a]++;
		//m.insert(make_pair(a,i));
	}

	int64_t count=0;
	for (pair<int,int> p: ml)
	{
		if (mr.count(p.first)>0)
		{
			count+=(int64_t)p.second*mr[p.first];
		}
	}
	cout << count << endl;
}






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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define MOD 1000000007

int N;
char S[101010];
int cnt[26];

int main(){
	scanf("%d%s",&N,S);
	for(int i = 0; i < N; ++i){
		cnt[S[i] - 'a']++;
	}
	ll ret = 1;
	for(int i = 0; i < 26; ++i){
		ret = ret * (1+cnt[i]) % MOD;
	}
	ret = (ret + MOD-1)%MOD;
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 384
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
As = nl()

from fractions import gcd
gcds_left = [0] * N
gcds_right = [0] * N
gcds_left[0] = As[0]
gcds_right[N-1] = As[N-1]

for i in range(1, N):
    gcds_left[i] = gcd(As[i], gcds_left[i-1])
    gcds_right[N-1-i] = gcd(As[N-1-i], gcds_right[N-i])

max_gcd = -1
for i in range(1, N-1):
    g = gcd(gcds_left[i-1], gcds_right[i+1])
    if g > max_gcd:
        max_gcd = g
print(max(max_gcd, gcds_right[1], gcds_left[N-2]))


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  ll a, b;
  cin >> a >> b;
  ll w = (100 * a + 7) / 8, x = (100 * a + 99) / 8, y = 10 * b, z = 10 * b + 9;
  cout << (max(w, y) <= min(x, z) ? max(w, y) : -1) << endl;
}

Measured memory_bytes: 256
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <map>
#include <stdio.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll MOD = (ll)pow(10.0, 9.0) + 7;
pint dx[4] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

ll min(ll a, ll b)
{

	return (a < b) ? a : b;
}
ll max(ll a, ll b) { return (a > b) ? a : b; }




ll N;

vector <ll> P;
ll sum[2 * 100005];

int main() {
	cin >> N;

	P.resize(N);
	rep(i, N) {
		cin >> P[i];
		if (i != 0)
			sum[i] = sum[i - 1] + P[i];
		else
			sum[i] = P[i];
	}
	
	ll m = inf;

	rep(i, N-1) {

		m = min(abs( (sum[N-1] - sum[i]) - sum[i]), m);
	}

	cout << m << endl;

	return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

int n;
char s[51];

char p[51];
char q[51];
int np,nq;
int dp[51][51];
int main()
{
    int i,j,k,times;

    cin>>n;
    cin>>s+1;

    long long ans=0;

    for(k=0;k<(1<<n);k++)
    {
        np=nq=0;
        for(j=1;j<=n;j++)
        {
            if((k&(1<<(j-1)))!=0)
            {
                np++;
                p[np]=s[j];
            }
            else
            {
                nq++;
                q[nq]=s[j];
            }
        }
        p[np+1]=0;
        q[nq+1]=0;

        //cout<<p+1<<endl<<q+1<<endl;

        memset(dp,0,sizeof(dp));
        dp[0][0]=1;
        for(i=0;i<=np;i++)
        {
            for(j=0;j<=nq;j++)
            {
                int pos=2*n-i-j;
                if(s[pos]==p[i+1])
                {
                    dp[i+1][j]+=dp[i][j];
                }
                if(s[pos]==q[j+1])
                {
                    dp[i][j+1]+=dp[i][j];
                }

                //cout<<dp[i][j]<<' ';
            }
            //cout<<endl;
        }
        //cout<<" ddpp"<<endl;
        //system("pause");

        ans+=dp[np][nq];
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
//
// Created by moono on 2018/10/27.
//

#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;



int main() {
    string A, B;
    cin >> A;
    cin >> B;

    int A_len = A.size(), B_len = B.size();

    if(A_len < B_len){
        cout << "LESS" << endl;

    }else if(A_len > B_len){
        cout << "GREATER" << endl;

    } else {
        bool is_equal = true;
        for (int i = 0; i < A_len; ++i) {
            if(A[i] < B[i]){
                is_equal = false;
                cout << "LESS" << endl;
                break;
            }else if(A[i] > B[i]){
                is_equal = false;
                cout << "GREATER" << endl;
                break;
            }
        }
        if(is_equal)
            cout << "EQUAL" << endl;

    }


    return 0;
}

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

int main() {
	int n, l;
	cin >> n >> l;
	vector<string> vec;
	for (int i=0; i < n; ++i){
		string s;
		cin >> s;
		vec.push_back(s);
	}
	sort(vec.begin(), vec.end());
	string s_out;
	auto itr = vec.begin();
	for (itr ; itr != vec.end(); ++itr){
		s_out += *itr;
	}
	cout << s_out << endl;
	return 0;
}

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

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 50;

char a[MAX_N][MAX_N];
char b[MAX_N][MAX_N];

int main()
{
	int n,m;
	bool flag = false;
	bool ans = false;
	cin >> n;
	cin >> m;
	rep(i,n){
		rep(j,n){
			cin >> a[i][j];
		}
	}
	rep(i,m){
		rep(j,m){
			cin >> b[i][j];
		}
	}
	rep(i,n-m+1){
		rep(j,n-m+1){
			if(b[0][0] == a[i][j]){
				flag = true;
				for(int k=i;k<i+m;k++){
					for(int l=j;l<j+m;l++){
						if(b[k-i][l-j] != a[k][l]){
							flag = false;
							break;
						}
					}
					if(!flag){
						break;
					}
				}
				if(flag){
					ans = true;
					break;
				}
			}
		}
		if(ans){
			break;
		}
	}
	if(ans){
		cout << "Yes\n";
	}else{
		cout << "No\n";
	}
}

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

int main() {
	int i,j,H,W;
	
	for(;;){
		cin>>H>>W;
		
		if(W==0&&H==0){
			break;
		}
		
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				
				if(i%2==0){
					if(j%2==0){
						cout<<"#";
					}else{
						cout<<".";
					}
					
				}if(i%2==1){
						if(j%2==0){
						cout<<".";
					}else{
						cout<<"#";
					}
				}
			}
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
int n;
int a[10005], b[10005];
long long ta, tb;
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 1; i <= n; i++) {
		scanf("%d", &b[i]);
		a[i] -= b[i];
		if (a[i] > 0) ta += a[i];
		else tb += (-a[i]) / 2;
	}
	if (ta > tb) printf("No\n");
	else printf("Yes\n");
	return 0;
}

Measured memory_bytes: 384
# import sys
import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
    # combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    n,d = readInt()
    ans = 0
    for i in range(n):
        a,b = readInt()
        if a**2+b**2<=d**2:
            ans += 1
    print(ans)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 9168
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main(){
    ll a,b;
    cin >> a >> b;
    a=a%500;
    if (a<=b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}


Measured memory_bytes: 256
#include <stdio.h>

int main() {

    int a, b;

    scanf("%d%d", &a, &b);

    if (a == b)
        printf("Draw\n");

    else if (a == 1 && b != 1)
        printf("Alice\n");

    else if (a != 1 && b == 1)
        printf("Bob\n");

    else if (a != 1 && b != 1) {

        if (a > b)
            printf("Alice\n");

        else if (a < b)
            printf("Bob\n");

    }

    return 0;
}

Measured memory_bytes: 128
D=int(input())
*c,=map(int,input().split())
s=[]
for i in range(D):
    *x,=map(int,input().split())
    s.append(x)

dt=[]
last=[-1]*26
v=0
for d in range(D):
    news=[s[d][i]-c[i]*(d-last[i])*(d-last[i]-1) for i in range(26)]
    maxi=0
    tmp=-float('inf')
    for i in range(26):
        if tmp<news[i]:
            maxi=i
            tmp=news[i]
    last[maxi]=d
    v+=s[d][maxi]
    for i in range(26):
        v-=c[i]*(d-last[i])
    dt.append(maxi+1)

def score(T):
    last=[-1]*26
    v=0
    for d in range(D):
        v+=s[d][T[d]-1]
        last[T[d]-1]=d
        for i in range(26):
            v-=c[i]*(d-last[i])
    return v

v0=score(dt)

for d in range(0,D,13):
    y=-1
    newdt=dt+[]
    for i in range(26):
        if dt[d]!=i+1:
            newdt[d]=i+1
            v1=score(newdt)
            if v0<v1:
                y=i+1
                v0=v1
    if y!=-1:
        dt[d]=y

for i in dt:
    print(i)

Measured memory_bytes: 74960
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0

const ll MOD = 1000000007;

ll solve()
{
    ll N;
    string S1,S2;
    cin >> N;
    cin >> S1;
    cin >> S2;
    ll ans = 0;
    ll pre = 0;
    for1 (i, N) {
        if (S1[i] == S2[i]) {
            if (i == 0) {
                ans = 3;
            } else if (pre == 1) {
                ans = (ans * 2) % MOD;
            } else {
                ans = (ans * 1) % MOD;
            }
            pre = 1;
        } else {
            if (i == 0) {
                ans = 6;
            } else if (pre == 1) {
                ans = (ans * 2) % MOD;
            } else {
                // 1 22 22 33
                // 2 11 33 11
                ans = (ans * 3) % MOD;
            }
            i += 1;
            pre = 2;
        }
    }

    return ans;
}

int main()
{
    do {
        cout << solve() << endl;
    } while (DEBUG);
}


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


def solve(N: int, K: int, S: int):
    answer = []
    if S != 10**9:
        answer += [S]*K
        answer += [10**9]*(N-K)
    else:
        answer += [S]*K
        answer += [10**8+1]*(N-K)  
    print(*answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    solve(N, K, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 6780
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

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

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

int main() {
    ios::sync_with_stdio(false);
    ll Q, H, S, D, N;
    cin >> Q >> H >> S >> D >> N;
    Q *= 4;
    H *= 2;
    ll r = min(Q, min(H, S));
    if (D < 2 * r) {
    	cout << D * (N / 2) + r * (N % 2) << endl;
    }
    else cout << r * N << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int n = sc.nextInt();
        HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
        for(int i = 0; i < n; i++){
            int k = sc.nextInt();
            int v = sc.nextInt();
            if(map.containsKey(k)){
                if(map.get(k) > v){
                    map.put(k,v);   
                }
            }else{
                map.put(k,v);
            }
        }
        long[] dp = new long[h+1];
        Arrays.fill(dp,Integer.MAX_VALUE);
        dp[0] = 0;
        for(int i = 1; i <= h; i++){
            for(Map.Entry<Integer,Integer> entry :map.entrySet()){
                int k = entry.getKey();
                int v = entry.getValue();
                if(i < k){
                    dp[i] = Math.min(dp[i], v);
                }else{
                    dp[i] = Math.min(dp[i], dp[i-k] + v);
                }
            }
        }
        System.out.println(dp[h]);
    }
}

Measured memory_bytes: 28896
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i=1; i < (int)(n); i++)
#define rrep(i, n) for (int i=((int)(n)-1); i>=0; i--)
#define rreps(i, n) for (int i=((int)(n)-1); i>0; i--)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long;
using p = pair<int, int>;
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; }

int main() {
  int N;
  scanf("%d", &N);
  int mod = N % 10;
  if (mod == 0 || mod == 1 || mod == 6 || mod == 8) {
    cout << "pon" << endl;
  }else if (mod == 3) {
    cout << "bon" << endl;
  }else {
    cout << "hon" << endl;
  }
  return 0;
}


Measured memory_bytes: 3760
import sys
from statistics import *
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

li = na()
li.sort()
ct = 0
dif = li[1] - li[0]
ct += dif // 2
li[0] += (dif // 2) * 2
if li[0] == li[1]:
    ct += li[2] - li[1]
else:
    ct += li[2] - li[0] + 1
print(ct)

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

long jump(long arr[],long n){
  long dp[n+1];
	//initialization
  	dp[0]=0;
    dp[1]=abs(arr[0]-arr[1]);
	
  for(long i=2;i<n;i++)
	dp[i]= min(abs(arr[i]-arr[i-1])+dp[i-1],abs(arr[i]-arr[i-2])+dp[i-2]);
  return dp[n-1];
}


int main(){
  //memset(dp,-1,sizeof(dp));
	long n;
	cin>>n;
	long arr[n];
	for(long i=0;i<n;i++){
		cin>>arr[i];
	}
	cout<<jump(arr,n);
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <list>
#include <string>
#include <cstring>
#include <sstream>
#include <cctype>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <stack>
#include <fstream>
#include <cstdlib>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <iomanip>
#include <queue>
#include <deque>
#include <iterator>
#include <assert.h>
#include <bitset>
#include <climits>
#include <ctime>
#include <complex>
using namespace std;
inline void FAST_IO() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }

using ll = long long;

int main()
{	
	FAST_IO();
	ll x,y;
	cin>>x>>y;
	ll ans=0,ans2=0;
	if(x==1)
		ans=300000;
	else if(x==2)
		ans=200000;
	else if(x==3)
		ans=100000;
	if(y==1)
		ans2=300000;
	else if(y==2)
		ans2=200000;
	else if(y==3)
		ans2=100000;

	if(x==1 and y==1)
	{
		cout<<1000000<<endl;return 0;
	}

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



Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
//*********************************************DO IT NOW****************************************************************
#include<bits/stdc++.h> 
#include<random>
#define int long long   
#define pp pair<int,int> 
#define ss second 
#define ff first 
#define pb push_back
#define mod 1000000007
#define pi 3.14159265359
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "YES"<<endl
#define no  cout<< "NO"<<endl
#define all(v) (v).begin(),(v).end()
#define s(v)   sort(v,v+n)
#define  mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" "
#define for1(i,a,n)  for(int i=0;i<n;i++)
#define rep(i, c) for(int i = 0; i < (int)c; i++)
#define set(x) cout<<fixed<<setprecision(x);
using namespace std;
//**********************************************DO IT NO****************************************************************
void fastio()
{  
  #ifndef ONLINE_JUDGE
  freopen("INPUT.txt","r",stdin);
  freopen("OUTPUT.txt","w",stdout); 
  #endif
  ios_base :: sync_with_stdio(false); 
  cin.tie(NULL) ; 
  cout.tie(NULL);
}
int dp[101][1001],ans1=1e9,dp1[1000001];
int num[10];
int a[1000000];
signed main()
{   
    fastio();
    int t=1;
    //cin>>t;
    while(t--)
    {  
      
      int n,x;
      cin>>n>>x;
      int a[n];
      read(a,n);
      int sum=0;
      int ans=0;
      for(int i=0;i<n-1;i++)
      {    
          
          sum=a[i]+a[i+1];
          if(sum>x)
          {
          if(sum-x>=a[i+1])
          {
              ans+=sum-x;
              a[i+1]=0;
          }
          else
          {
             ans+=sum-x;
             a[i+1]=a[i+1]-(sum-x);
          }
          }
          
      }
      cout<<ans;
    }
}
// 🍪 🍪 🍪


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

int main(){
    int a,b;
    cin >> a >> b;
    int sub = b-a;
    int temp = 0;
    for(int i=1;i<sub;i++){
        temp += i;
    }
    cout << temp - a << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

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

int main(){
  int i, j;

  REP(i,1,10) REP(j,1,10) printf("%dx%d=%d\n", i, j, i*j);

  return 0;
}

Measured memory_bytes: 0
/*	[]__________[][][][]____[][][][][]__{}__[][][][]____[][][][][]__[][][][]
    []__________[]______________[]__________[]__________[]__________[]____[]
    []__________[][][][]________[]__________[][][][]____[]__________[]____[]
    []__________[]______________[]________________[]____[]__[][][]__[]____[]
    []__________[]______________[]________________[]____[]______[]__[]____[]
    [][][][]____[][][][]________[]__________[][][][]____[][][][][]__[][][][]
*/
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define endl '\n'
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define decimal(x) cout<<fixed<<setprecision(x);
bool prime[100005]; 
void Sieve(int n) {
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
} 
vector<int>grapj[100005];
bool vis[100005];
void solve()
{
    int x;
    cin>>x;
    if(x==0)
    cout<<1;
    else
    {
        cout<<0;
    }
    
}	
signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
      // cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 5996
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7

n,k=map(int,input().split())
p=list(map(int,input().split()))
ans=0
for i in range(k):
    ans+=(p[i]+1)/2

tmp=ans
for i in range(k,n):

    tmp-=(p[i-k]+1)/2
    tmp+=(p[i]+1)/2
    ans=max(ans,tmp)
print(ans)

Measured memory_bytes: 97388
use std::cmp::{max, min};

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (w, h, n) = scan!(i64, i64, usize);
    let (mut x, mut y, mut z, mut w) = (0, w, 0, h);

    for _ in 0..n {
        let (x0, y0, a0) = scan!(i64, i64, usize);
        match a0 {
            1 => x = max(x, x0),
            2 => y = min(y, x0),
            3 => z = max(z, y0),
            4 => w = min(w, y0),
            _ => (),
        }
    }

    println!("{}", max(0, y - x) * max(0, w - z))
}


Measured memory_bytes: 4352
ll = []
for i in range(3):
    l = list(map(int, input().split()))
    ll.append(l)

n = int(input())

for i in range(n):
    nn = int(input())
    for j in range(3):
        for k in range(3):
            if ll[j][k] == nn:
                ll[j][k] = "#"

flag = False
for i in range(3):
    if ll[i][0] == "#" and ll[i][1] == "#" and ll[i][2] == "#":
        flag = True
        break
    elif ll[0][i] == "#" and ll[1][i] == "#" and ll[2][i] == "#":
        flag = True
        break
if ll[0][0] == "#" and ll[1][1] == "#" and ll[2][2] == "#":
    flag = True
elif ll[0][2] == "#" and ll[1][1] == "#" and ll[2][0] == "#":
    flag = True

if flag:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (INT_MAX / 4)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" \
                              << "\n";

int main()
{
  int ans = 0,tmp=0;
  string s;
  cin >> s;

  REP(i, s.size())
  {
    if (s.at(i) == 'A' || s.at(i) == 'C' || s.at(i) == 'G' || s.at(i) == 'T'){
      tmp++;
    }else{
      tmp = 0;
    }
    ans = max(ans, tmp);
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
def inpl():
    return list(map(int, input().split()))


S = input()

ans = 0
for i in range(2**(len(S) - 1)):
    tmp = S[0]
    for j in range(len(S) - 1):
        # print(i, j, i >> j)
        if (i >> j) % 2 == 1:
            ans += int(tmp)
            tmp = ""
        tmp += S[j + 1]
    ans += int(tmp)
print(ans)


Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String input = sc.next();

		String[] inputChar = input.split("");
		List<String> output = new ArrayList<String>();
		for (int i = 0; i < inputChar.length; i++) {
			if ("0".equals(inputChar[i])) {
				output.add("0");
			} else if ("1".equals(inputChar[i])) {
				output.add("1");
			} else {
				if (!(output.size() == 0)) {
					output.remove(output.size() - 1);
				}
			}
		}
		for (String s : output) {
			System.out.print(s);
		}
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
const int N=55;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,k,s,t,m,a[N];
ll C[N][N];

void No() {
	cout<<0;exit(0);
}

int main() {
	cin>>n>>k>>s>>t;
	if((s&t)!=s) No();
	for(int i=0;i<N;i++) {
		C[i][0]=1;
		for(int j=1;j<=i;j++) C[i][j]=C[i-1][j-1]+C[i-1][j];
	}
	for(int i=0;i<N;i++) {
		C[i][0]=0;
		for(int j=1;j<=i;j++) C[i][j]+=C[i][j-1];
	}
	for(int i=1;i<=n;i++) {
		cin>>a[i];
		if((a[i]&s)!=s||(a[i]&t)!=a[i]) --i,--n;
	}
	int key=0;
	for(int i=0;i<18;i++)
		if((s>>i&1)!=(t>>i&1)) key|=1<<i;
	m=__builtin_popcount(key);
	for(int i=1;i<=n;i++) {
		int now=0,val=0;
		for(int j=0;j<18;j++)
			if(key>>j&1) {
				if(a[i]>>j&1) val|=1<<now;
				++now;
			}
		a[i]=val;
		//cerr<<a[i]<<'\n';
	}
	ll ans=0;
	for(int i=0;i<(1<<m);i++) {
		int sgn=__builtin_parity(i)?-1:1;
		unordered_map<int,int> cnt;
		for(int j=1;j<=n;j++) ++cnt[a[j]&i];
		for(auto t:cnt) ans+=C[t.se][min(t.se,k)]*sgn;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3660
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<functional>
#include<stack>
#include<queue>
#include<cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

int main() {

	int n = 0, h[100] = {}, ans = 0;

	cin >> n;
	rep(i, n) {
		cin >> h[i];
	}

	rep(left, n) {
		
		while (h[left] > 0) {
			int right = 0, water = 0;

			for (right = left + 1; right < n; right++) {
				if (h[right] == 0)break;
			}

			for (water = left; water < right; water++) {
				h[water]--;
			}

			ans++;
		
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
long n;
vector<long>a;
long ans;
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		long x;cin>>x;a.push_back(x);
	}
	while(1)
	{
		sort(a.begin(),a.end(),greater<long>());
		if(a[0]<n)break;
		long k=0;
		while(k+1<n&&a[k+1]+k+1>=n&&a[k]-a[k+1]<n+1)k++;
		if(k==n-1)
		{
			k=0;
			while(k+1<n&&a[k+1]+k+1>=n&&a[0]-a[k+1]<=k+1)k++;
		}
		if(k<n-1)
		{
			long L=(a[0]-a[k+1])/(1+n);
			if(L<=0)L=1;
			ans+=L*(k+1);
			for(int i=0;i<n;i++)
			{
				if(i>k)a[i]+=L*(k+1);
				else a[i]+=L*(k-n);
			}
		}
		else
		{
			long L=a[0]-n+1;
			if(L>a[n-1])L=a[n-1];
			ans+=L*n;
			for(int i=0;i<n;i++)a[i]-=L;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
check=dict()
N,a,b,c,d=0,0,0,0,0
#ttfは235、chaはabc
def dfs_sub(n,ttf,cha):
    global check,d
    if 0 in check:
        check[0]=min(check[n]+n*d,check[0])
    else:
        check[0]=check[n]+n*d
    if n//ttf==0:
        if n//ttf in check:
            if check[n//ttf]>check[n]+(n%ttf)*d:
                check[n//ttf]=check[n]+(n%ttf)*d
        else:
            check[n//ttf]=check[n]+(n%ttf)*d
    else:
        if n//ttf in check:
            if check[n//ttf]>check[n]+(n%ttf)*d+cha:
                check[n//ttf]=check[n]+(n%ttf)*d+cha
                dfs(n//ttf)
        else:
            check[n//ttf]=check[n]+(n%ttf)*d+cha
            dfs(n//ttf)
    if 1+n//ttf in check:
        if check[1+n//ttf]>check[n]+(ttf-n%ttf)*d+cha:
            check[1+n//ttf]=check[n]+(ttf-n%ttf)*d+cha
            dfs(1+n//ttf)
    else:
        check[1+n//ttf]=check[n]+(ttf-n%ttf)*d+cha
        dfs(1+n//ttf)


def dfs(n):
    global check,a,b,c,d
    dfs_sub(n,2,a)
    dfs_sub(n,3,b)
    dfs_sub(n,5,c)

t=int(input())
ans=[0]*t
for i in range(t):
    N,a,b,c,d=map(int,input().split())
    check={N:0}
    dfs(N)
    ans[i]=check[0]
for i in range(t):
    print(ans[i])

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

#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
#define endl '\n'
// #define int long long

typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int a, p;
int32_t main()
{
	IOS
	//freopen("input.txt", "r", stdin);
	cin >> a >> p;
	cout << (3*a + p) /2 << endl;
	
	return 0;
}


Measured memory_bytes: 256
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n
def f(v):
    d = v.find(".")
    if d == -1:
        return int(v), 1
    a = int(v[:d]+v[d+1:])
    n = 10**(len(v)-d-1)
    if a == 0:
        return 0, 1
    g = gcd(n, a)
    return int(a/g), int(n/g)
s = input()
d = s.find(".")
l = s.find("(")
r = s.find(")")
if l == -1:
    res = f(s)
else:
    assert l>=2 and r == len(s)-1
    aa, na = f(s[:l])
    ab, nb = f("0." + "0"*(l-d-1) + s[l+1:r])
    t = r-l-1
    a = (10**t - 1)*aa*nb + 10**t*ab*na
    n = (10**t - 1)*na*nb

    g = gcd(a, n)
    res = int(a/g), int(n/g)
print("%d/%d" % res)

Measured memory_bytes: 7780
// Author: Mohammad Faisal
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int * arr = new int [n];
	for(int i=0;i<n;i++)
		cin >> arr[i];
		
	int i=0,j=n-1;
	int sum=arr[i],sum1=arr[j];
	while(1)
	{
		if(i+1 == j)
			break;
		if(sum >= sum1)
		{

			j--;
			sum1 +=arr[j]; 
		}
		else
		{
			i++;
			sum+=arr[i];
		}
	}
//	cout<<"Sum "<<sum<<" Sum1= "<<sum1<<endl;
	(sum>=sum1) ? cout<<sum-sum1 : cout<<sum1-sum;
	delete [] arr;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>

using namespace std;
typedef long long int ll;typedef pair<int, int> P;
const long long mod = 1e9 + 7;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
const double PI = 3.14159265359;

int main(void) {
	string str; cin >> str;
	bool x = 1;
	rep(i, str.length()) {
		if (i % 2 == 0) {
			if (str[i] != 'R' && str[i] != 'U' && str[i] != 'D')
				x = 0;
		}
		else {
			if (str[i] != 'L' && str[i] != 'U' && str[i] != 'D')
				x = 0;
		}
	}
	cout << (x ? "Yes" : "No") << endl;
	return 0;
}

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


void push(int);
int pop(void);
int top=0;
int S[];
int main(){
  int x,a,b;
  char s[100];

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      b=pop();
      a=pop();
      push(a+b);
    } else if ( s[0] == '-' ){
      b=pop();
      a=pop();
      push(a-b);
    } else if ( s[0] == '*' ){
      b=pop();
      a=pop();
      push(a*b);
    } else {
      x = atoi(s);
      push(x);
    }
  }
  a=pop();
  printf("%d\n",a);

  return 0;
}

void push(int x){
  top++;
  S[top]=x;
}

int pop(){
  top--;
  return S[top+1];
}



Measured memory_bytes: 2052
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map> 
#include<bitset>
#include<vector>
using namespace std;
#define re register int
inline int read(){
    int x=0,ff=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')ff=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
    return x*ff;
}
int f[10005],n,x,y,k;
signed main(){
	k=read();n=read();
	memset(f,0x3f,sizeof(f));f[0]=0;
	for(re i=1;i<=n;i++){
		x=read();y=read();
		for(re j=0;j<k;j++){
			f[min(j+x,k)]=min(f[min(j+x,k)],f[j]+y);
		}
	}
	cout<<f[k]<<endl;
   	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  double s = 0.0, A;
  for (int i = 0; i < N; ++i) {
    cin >> A;
    s += 1.0 / A;
  }
  
  double ans = 1.0 / s;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include<stack>
#include<queue>
using namespace std;
int main()
{
    string s;
    cin>>s;
    long long k;
    scanf("%lld",&k);
    int i=0;
    while(s[i]-48==1&&k>0)
    {
        k=k-1;
        i=i+1;
    }
    if(k==0)
    {
        printf("1\n");
    }
    else
    {
        printf("%d\n",s[i]-48);
    }
}


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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

const int MAX = 4000;
const int mod = 1000000007;
ll fac[MAX], inv[MAX], finv[MAX];
void cominit(){
  fac[0] = fac[1] = 1;
  inv[1] = 1;
  finv[0] = finv[1] = 1;
  rep(i, 2, MAX){
    fac[i] = fac[i-1]*i%mod;
    inv[i] = mod- inv[mod%i]*(mod/i)%mod;
    finv[i] = finv[i-1]*inv[i]%mod;
  }
}

ll com(int n, int k){
  if(n < k)
    return 0;
  if(n < 0 || k < 0)
    return 0;
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

int main(){
  int s;
  cin >> s;
  int mod = 1000000007;
  int n = s/3;
  ll ans = 0;
  
  cominit();
  
  rep(i, 0, n+1){
    int p = s -3 *i;
    ans += com(p + i-1, p);
    ans %= mod;
  }
  
  cout << ans << endl;
  
  return 0;
  
}

Measured memory_bytes: 3628