akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

  int n;

  cin >> n;

  vector<int> p(n), q(n), v(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }

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

  for (int i = 0; i < n; i++) {
    v[i] = i + 1;
  }

  int idx = 1;
  int pidx;
  int qidx;
  do {
    bool pok = true;
    bool qok = true;
    for (int i = 0; i < n; i++) {
      if (v[i] != p[i]) {
        pok = false;
      }

      if (v[i] != q[i]) {
        qok = false;
      }
    }

    if (pok) {
      pidx = idx;
    }

    if (qok) {
      qidx = idx;
    }

    idx++;
  } while (next_permutation(v.begin(), v.end()));

  cout << abs(pidx - qidx) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	int a = s.length();
	int b = t.length();
	int dp[a+1][b+1];
	for(int i = 0;i<=a;i++)
		dp[i][0] = 0;
	for(int j = 0;j<=b;j++)
		dp[0][j] = 0;
	for(int i = 1;i<=a;i++)
	{
		for(int j = 1;j<=b;j++)
		{
			if(s[i-1] == t[j-1])
			{
				dp[i][j] = dp[i-1][j-1]+1;
			}
			else
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
		}
	}
	int i = a,j = b;
	string ans;
	while(i>0 && j>0)
	{
		if(dp[i][j] == dp[i-1][j])
			i--;
		else if(dp[i][j] == dp[i][j-1])
			j--;
		else
		{
			ans+=s[i-1];
			i--;
			j--;
		}
	}
	reverse(ans.begin(),ans.end());
	cout<<ans;

}


Measured memory_bytes: 35456
s=[]; h=[]; c=[]; d=[]
gets.to_i.times{m,n=gets.chomp.split; eval(m.downcase)[n.to_i-1]=1}
["s","h","c","d"].each{|m1| 13.times {|i| if eval(m1)[i]==nil then  print "#{m1.upcase} #{i+1}\n" end}}



Measured memory_bytes: 6928
#include <bits/stdc++.h>
using namespace std;
using ll= long long ;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i<(ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t =rep_jijo(n,x/2);
        return t*t%mod;
  }
  return n*rep_jijo(n,x-1)%mod;
}
ll c2(ll n){
    return n*(n-1)/2;
}

int main(){
  ll x,n;
  cin>>x>>n;
  ll anl=300,anh=300;
  vcl p(n);
  rep(i,n) cin>>p[i];

  for(ll i=x;i>=0;i--){
      bool a=true;
      rep(j,n)if(p[j]==i)a=false;
      anl=i;
      if(a)break;
  }
for(ll i=x;i<=101;i++){
      bool a=true;
      rep(j,n)if(p[j]==i)a=false;
      anh=i;
      if(a)break;
  }

  if(abs(anl-x)>abs(anh-x))cout<<anh<<endl;
  else cout<<anl<<endl;
}
  

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n;
    cin>>n;
    vector<P> p(n);
    rep(i,n-1) cin>>p[i].first>>p[i].second;
    vector<vector<int>> node(n+5);
    rep(i,n+5) node[i].clear();
    vector<int> ans(n+5,0);
    rep(i,n-1){
        node[min(p[i].first, p[i].second)].push_back(max(p[i].first, p[i].second));
    }
    node[1].push_back(0);
    int cnt=1;
    deque<int> d;
    d.push_back(1);
    while(!d.empty()){
        int a=d.front(),c=1;
        d.pop_front();
        for(auto v: node[a]){
            d.push_back(v);
            if(c==ans[a]) c++;
            ans[v]=c;
            c++;
        }
    }
    rep(i,n-1) cnt=max(cnt, ans[i+2]);
    cout<<cnt<<endl;
    rep(i,n-1) cout<<ans[max(p[i].first, p[i].second)]<<endl;
    return 0;
}

Measured memory_bytes: 5632
N = int(input())
query = []
ans = 0

for i in range(N):
    A = int(input())
    query.append([list(map(int, input().split())) for j in range(A)])

for i in range(1<<N):
    count = 0
    FLG = True
    for j in range(N):
        if (i >> j) & 1:
            count += 1
            for x, y in query[j]:
                if (i >> (x - 1)) & 1 != y:
                    FLG = False
                    break   
        if not FLG:
            break
    else:
        ans = max(ans, count)

print(ans)


Measured memory_bytes: 74236
def kisu(s,num):
    for n in range(len(s)):
        if s[n]%2 == 1:
            return s,num,1
        s[n] = s[n]/2
    return s,num+1,0

n = int(input())
check = 0
num = 0
a = list(map(int,input().split()))
while check == 0:
    a,num,check = kisu(a,num)
print(num)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std ;
#define ll long long int
int main(){
	ll n , i , sum = 0 , j;
	int x ;
	cin >> n ;
	vector<string>v(n) ;
	bool flag = false ;
	for(i = 0 ; i < n ; i++){
		cin >> v[i] ;
	}
	for(i = 0 ; i < n ; i++){
		x = stoi(v[i]) ;
		if(x % 2 == 0){
			if(x % 5 != 0 && x % 3 != 0){
				cout << "DENIED " ;
				flag = true ;
				break ;
			}
		}
	}
	if(!flag){
		cout << "APPROVED" ;
	}
}

Measured memory_bytes: 256
MOD = 2019

l, r = map(int, input().split())
if r - l >= 2019:
    print(0)
    exit()
lst = []
for num in range(l, r + 1):
    lst.append(num % MOD)
ans = 2020
ll = len(lst)
for i in range(ll):
    for j in range(i + 1, ll):
        tmp = (lst[i] * lst[j]) % MOD
        ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 9200
S = list(input())
y = 1000*int(S[0])+100*int(S[1])+10*int(S[2])+int(S[3])
m = 10*int(S[5])+int(S[6])
d = 10*int(S[8])+int(S[9])

if y < 2019 :
    print("Heisei")
elif y == 2019 and m <= 4 :
    print("Heisei")
else :
    print("TBD")


Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll Pow(ll n,ll p){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}

const int M=2000005;
ll F[M];

void Init(){
	F[0]=1;
	for(int i=1;i<M;i++) F[i]=F[i-1]*i%mod;
}

ll Div(ll n,ll m){
	return n*Pow(m,mod-2)%mod;
}

ll nCk(ll n,ll k){
	return Div(F[n],F[n-k]*F[k]%mod);
}

int a,b,c,d;

ll f(int a,int b){
	return nCk(a+b+2,b+1);
}

int main(){
	Init();
	cin>>a>>c>>b>>d;
	cout<<(f(b,d)-f(a-1,d)-f(b,c-1)+f(a-1,c-1)+2*mod)%mod<<endl;
}

Measured memory_bytes: 15872
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\Space))
  "Note that the returned string will be reused."
  (let ((buffer (gensym))
        (character (gensym))
        (idx (gensym)))
    `(let ((,buffer (load-time-value (make-string ,buffer-size
                                                  :element-type 'base-char))))
       (declare (simple-base-string ,buffer))
       (loop for ,character of-type base-char =
                #-swank (code-char (read-byte ,in nil #.(char-code #\Newline)))
                #+swank (read-char ,in nil #\Newline)
             for ,idx from 0
             until (char= ,character #\Newline)
             do (setf (schar ,buffer ,idx) ,character)
             finally (when (< ,idx ,buffer-size)
                       (setf (schar ,buffer ,idx) ,terminate-char))
                     (return (values ,buffer ,idx))))))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil

(defun main ()
  (declare #.OPT)
  (let* ((n (read))
         (as (make-array n :element-type 'uint32)))
    (dotimes (i n)
      (setf (aref as i) (parse-integer (buffered-read-line 10) :junk-allowed t)))
    (let ((sum 0))
      (declare (uint32 sum))
      (labels ((skip-zero (i)
                 (cond ((= i n))
                       ((zerop (aref as i)) (skip-zero (1+ i)))
                       (t (traverse i 0))))
               (traverse (i res)
                 (declare (uint32 i res))
                 (cond ((= i n)
                        (incf sum (floor res 2)))
                       ((zerop (aref as i))
                        (incf sum (floor res 2))
                        (skip-zero i))
                       (t (traverse (1+ i) (+ res (aref as i)))))))
        (skip-zero 0))
      (println sum))))

#-swank(main)


Measured memory_bytes: 8800
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}

int main(void){
	int a=in(),b=in();
	print((a+b+1)/2);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mx=100001;
ll n=0,k=0;
vector<ll> a(mx);
vector<int> dp(mx,-1);
ll foo(int src){
	if(dp[src]!=-1) return dp[src];
	if(src==n-1) return 0;
	// else if (src>=n) return INT_MAX;
	else {
		ll ans = abs(a[src]-a[src+1])+foo(src+1);
		for(int v=2;v<=k;v++)
		if(src+v<n)
		ans=min(ans,abs(a[src]-a[src+v])+foo(src+v));
		return dp[src]=ans;
	}
	// if(i==n-2) { return abs(h[n-1]-h[n-2]);}
	// if(i==n-1) return abs(h[n-1]-h[n-3]);
	// return cost+=min(dp(i+1,h,n),dp(i+2,h,n));
}
int main() {
	// int n;
	cin>>n>>k;
	// int a[n];
	for(ll i=0;i<n;i++) cin>>a[i];
	
	cout<<foo(0)<<endl;
	return 0;
}

Measured memory_bytes: 12144
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		long[] a = new long[n];
		long total = 0;

		for (int i=0; i<n; i++){
			a[i] = sc.nextLong();
			total += a[i];
		}

		long ans = 0;
		for (int i=0; i<n-1; i++){
			total -= a[i];
			ans += a[i] * (total % 1000000007);
			ans %= 1000000007;
		}
		System.out.println(ans);
	}


}

Measured memory_bytes: 60968
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int A, B, X;
    cin >> X;
    cin >> A;
    cin >> B;
    // buy A
    X -= A;

    // buy B
    while (X>=B){
        X -= B;
    }
    cout << X << endl;

    return 0;
}

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

using ll = long long;

void min_self(ll& a, ll b) {
    a = min(a, b);
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int& x : a) {
        cin >> x;
    }
    vector<vector<ll>> dp(n, vector<ll>(n, 1e13+5));
    vector<ll> prefix(n);
    prefix[0] = a[0];
    for(int i = 1; i < n; i++) {
        prefix[i] = a[i]+prefix[i-1];
    }

    for(int L = n-1; L >= 0; L--) {
        for(int R = L; R < n; R++) {
            if(L == R) {
                dp[L][R] = 0;
            }
            else {
                for(int k = L; k < R; k++) {
                    min_self(dp[L][R], dp[L][k]+dp[k+1][R]+prefix[R]-(L > 0 ? prefix[L-1] : 0));
                }
            }
        }
    }
    cout << dp[0][n-1] << endl;
}


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

int main() {
   int N;
   cin >> N;
   long long L[N];
   for (int i=0; i<N; i++) {
       cin >> L[i];
   }
   sort(L,L+N);
   long long count=0;
   for (int i=0; i<N; i++) {
       for (int j=i+1; j<N; j++) {
           if (L[i]==L[j]) continue;
           for (int k=j+1; k<N; k++) {
               if (L[j]==L[k]) continue;
               if (L[i]+L[j]>L[k]) count++;
           }
       }
   }
   cout << count << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <queue>
#include <utility>
 
#define rep(i,n) for(int i = 0; i < n; i++)
 
using namespace std;
 
const int INF = 1e9;
 
int main(){
  int H, W;
  cin >> H >> W;
  
  int D[H][W];
  rep(i,H) fill(D[i], D[i]+W, INF);
  
  queue<pair<int,int> > que;
  rep(i,H){
    rep(j,W){
      char c;
      cin >> c;
      if(c == '#'){
        que.push(make_pair(i,j));
        D[i][j] = 0;
      }
    }
  }
  
  while(!que.empty()){
    pair<int,int> p = que.front();
    que.pop();
    
    int dy[] = {1,-1,0,0};
    int dx[] = {0,0,1,-1};
    
    rep(m,4){
      int y = p.first + dy[m];
      int x = p.second + dx[m];
      if(y < 0 || H <= y || x < 0 || W <= x) continue;
      if(D[y][x] != INF) continue;
      D[y][x] = D[p.first][p.second] + 1;
      que.push(make_pair(y,x));
    }	
  }
  
  int ans = 0;
  rep(n,H){
    rep(o,W){
      ans = max(ans,D[n][o]);
    }
  }
  cout << ans;
}

Measured memory_bytes: 12304
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;

void main()
{
    auto hw = readln.split.to!(int[]);
    auto H = hw[0];
    auto W = hw[1];

    wchar[][] MAP;
    MAP.length = H;
    foreach (i; 0..H) {
        MAP[i] = readln.chomp.to!(wchar[]);
    }

    int cnt;
    foreach (l; MAP)
        foreach (e; l)
            if (e == '.') ++cnt;

    bool[][] FLG;
    FLG.length = H;
    foreach (ref l; FLG) l.length = W;

    int[2][] SS;
    SS ~= [0, 0];

    int stp;
    bool can;
    while (!SS.empty) {
        int[2][] NSS;
        foreach (ss; SS) {
            auto x = ss[0];
            auto y = ss[1];

            if (MAP[y][x] == '#' || FLG[y][x]) continue;
            FLG[y][x] = true;

            if (x == W-1 && y == H-1) {
                can = true;
                break;
            }

            if (x > 0) NSS ~= [x-1, y];
            if (x < W-1) NSS ~= [x+1, y];
            if (y > 0) NSS ~= [x, y-1];
            if (y < H-1) NSS ~= [x, y+1];
        }
        SS = NSS;
        ++stp;
        if (can) break;
    }
    if (can)
        writeln(cnt - stp);
    else
        writeln("-1");
}

Measured memory_bytes: 508
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
    return a / GCD(a, b) * b;
}

int main() {
  int N;
  cin>>N;
  ll T[N];
  rep(i,N){
    cin>>T[i];

  }
  ll ans=1;
  rep(i,N){
    ans=LCM(ans,T[i]);
  }
  cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int n;
  cin>>n;
  string x;
  cin>>x;
  int px = 0;
  int pxm, pxp;
  REP(i, n) if(x[i] == '1') px++;
  pxm = px - 1;
  pxp = px + 1;
  int powers[n];
  int powersm[n];
  int powersp[n];
  for(int i = n - 1; i >= 0; i--){
    if(i == n - 1){
      powers[i] = 1;
      powersm[i] = 1;
      powersp[i] = 1;
      continue;
    }else{
      powers[i] = (powers[i + 1] * 2) % px;
      if(pxm > 0){
        powersm[i] = (powersm[i + 1] * 2) % pxm;
      }
      powersp[i] = (powersp[i + 1] * 2) % pxp;
    }
  }
  int modx = 0;
  int modxp = 0;
  int modxm = 0;
  REP(i, n){
    modx += ((x[i] - '0') * powers[i]);
    modx %= px;
    modxm += ((x[i] - '0') * powersm[i]);
    if(pxm > 0) modxm %= pxm;
    modxp += ((x[i] - '0') * powersp[i]);
    modxp %= pxp;
  }
  vector<int> ans(n, 0);
  REP(i, n){
    int cnt = 1;
    long long temp;
    if(x[i] == '0'){
      temp = (modxp + powersp[i]) % pxp;
    }else{
      if(pxm == 0){
        ans[i] = 0;
        continue;
      }
      temp = ((modxm - powersm[i]) % pxm + pxm) % pxm;
    }
    while(temp > 0){
      int p = __builtin_popcount(temp);
      temp %= p;
      cnt++;
    }
    ans[i] = cnt;
  }
  REP(i, n) cout << ans[i] << endl;
  return 0;
}


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

typedef long long ll;

int pow(int n)
{
    int ans = 1;
    int i;
    for(i = 0;i < n;++i){
        ans *= 10;
    }
    return ans;
}

int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> digi(n,-1);
    int i;
    int s,c;
    for(i = 0;i < m;++i){
        cin >> s >> c;
        if(digi.at(s-1) != -1 && digi.at(s-1) != c){
            cout << -1 << endl;
            return 0;
        }else{
            digi.at(s-1) = c;
        }
    }

    int ans = 0;
    if(n == 1){
        if(digi.at(0) == -1){
            cout << 0 << endl;
        }else{
            cout << digi.at(0) << endl;
        }
        return 0;
    }
    if(digi.at(0) == 0){
        cout << -1 << endl;
        return 0;
    }
    
    for(i = 0;i < n;++i){
        int j = n-i-1;
        if(i == 0){
            if(digi.at(i) == -1){
                ans += pow(j);
            }else{
                ans += digi.at(i)*pow(j);
            }
        }else{
            if(digi.at(i) == -1){
                ans += 0;
            }else{
                ans += digi.at(i)*pow(j);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  ll n;
  cin >> n;
  ll sum = 0;
  rep(i, n) {
    if((i + 1) % 3 != 0 && (i + 1) % 5 != 0) sum += i + 1;
  }
  cout << sum << endl;
} 

Measured memory_bytes: 3560
N, capW = map(int, input().split())
items = [tuple(map(int, input().split())) for _ in range(N)]

def knapsack01(items, capW):
    dp = [0] * (capW+1)
    for wi, vi in items:
        for w in reversed(range(wi, capW+1)):
            v0 = dp[w-wi] + vi
            if v0 > dp[w]:
                dp[w] = v0
    return max(dp)

print(knapsack01(items, capW))


Measured memory_bytes: 9588
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define LL long long
#define int LL
#define P pair<int, int>
const LL N = 2e3 + 10;
const LL mod = 1e9 + 7;
const LL inf = 0x3f3f3f3f;
using namespace std;
template <typename tp>
inline void read(tp &x)
{
    x = 0;char c = getchar();bool f = 0;
    for (; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}
LL n, x, ans;
LL Gcd(LL x, LL n)
{
    if (n % x == 0)
        return n * 2 - x;
    ans = n / x * x * 2 + Gcd(n % x, x);
    return ans;
}
signed main()
{
    read(n),read(x);
    printf("%lld\n",Gcd(x, n - x) + n);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=998244353;
const int MAXN=200010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, s;
ll dp[MAXN][3][3], ans;
string S;
set<string> st;

void dfs(string S){
	st.insert(S);
	for (int i=1; i<n; i++) if (S[i]!=S[i-1]){
		string T=S;
		char ch='a'+'b'+'c'-S[i]-S[i-1];
		T[i]=T[i-1]=ch;
		if (!st.count(T)) dfs(T);
	}
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>S;
	n=S.size();
	if (n<=3){
		dfs(S);
		cout<<st.size()<<"\n";
		return 0;
	}
	for (int i=1; i<n; i++){
		if (S[i]!=S[i-1]) a=1;
		else b=1;
	}
	if (!a) kill(1)
	for (char ch:S) s=(s+ch-'a')%3;
	dp[1][0][0]=dp[1][1][1]=dp[1][2][2]=1;
	for (int i=2; i<=n; i++)
		for (int j:{0, 1, 2})
			for (int last:{0, 1, 2})
				for (int l:{0, 1, 2}) if (l!=last)
					dp[i][j][last]=(dp[i][j][last]+dp[i-1][(j+3-last)%3][l])%mod;
	ans=1;
	for (int i=2; i<=n; i++) ans=ans*3%mod;
	ans-=dp[n][s][0]+dp[n][s][1]+dp[n][s][2];
	
	if (!b) ans++;
	ans%=mod;
	if (ans<0) ans+=mod;
	cout<<ans<<"\n";
	
	return 0;
}


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

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; ++i){
    	cin >> v[i];
    }
    int o = 0;
    for(int i = 1; i < n-1; i++){
    	int a, b;
    	a = max({v[i], v[i-1], v[i+1]});
    	b = min({v[i], v[i-1], v[i+1]});
    	o += ((a == v[i+1] and b == v[i-1]) or (b == v[i+1] and a == v[i-1])) ? 1 : 0; 
    }

    cout << o << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
  #pragma GCC target("avx,avx2,fma")
  #include <bits/stdc++.h>
  using namespace std;
  //---------------------------------//
  void __print(int x) {cerr << x;}
  void __print(long x) {cerr << x;}
  void __print(long long x) {cerr << x;}
  void __print(unsigned x) {cerr << x;}
  void __print(unsigned long x) {cerr << x;}
  void __print(unsigned long long x) {cerr << x;}
  void __print(float x) {cerr << x;}
  void __print(double x) {cerr << x;}
  void __print(long double x) {cerr << x;}
  void __print(char x) {cerr << '\'' << x << '\'';}
  void __print(const char *x) {cerr << '\"' << x << '\"';}
  void __print(const string &x) {cerr << '\"' << x << '\"';}
  void __print(bool x) {cerr << (x ? "true" : "false");}

  template<typename T, typename V>
  void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
  template<typename T>
  void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
  void _print() {cerr << "]\n";}
  template <typename T, typename... V>
  void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
  #ifndef ONLINE_JUDGE
  #define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
  #else
  #define deb(x...)
  #endif
 //------------------------------//

  typedef long long int ll;
  typedef pair<int,int> pi;
  typedef pair<ll,ll> pll;
  typedef vector<int> vi;
  typedef vector<ll> vll;
  typedef vector<pi> vpi;
  typedef vector<pll> vpll;

  #define  ff           first
  #define  ss           second
  #define  pb           push_back
  #define  IOS          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define  all(x)       (x).begin(), (x).end()
  #define  ps(x,y)      fixed<<setprecision(y)<<x
  #define  rep(i,a,b)   for(ll i=a ; i<b ; ++i)

  const ll MOD = 1e9 + 7;
  const ll INF = 1e18;
  const ll maxn = 1e6 + 4;


  void solve(){
     ll a,b,c,d;
     cin >> a >> b >> c >> d;
     cout << max({a*c,a*d,b*c,b*d});
  }

  int main(){
    IOS
    	solve();
    //cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }

// integer overflow

Measured memory_bytes: 3652
#include <iostream>
#include <cassert>
#define REP(i,l,n) for(int i=l;i<n;++i)
#define rep(i,n) REP(i,0,n)
int ans;
int Q,n;
using namespace std;
int main() {
  cin >> Q;
  rep(i,Q){
    cin >> n;
    ans = 0;
    while(n > 9){
      ans++;
      int max = 0,div = 1;
      rep(j,5){
        div *= 10;
        int post = (n/div)*(n%div);
        if(post>max) max = post;
      }
      n = max;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  char a,b,c;
  int cup[]={1,0,0},x,y,z;
  for(;;){
    if(scanf("%c,%c%*c",&a,&b) == EOF) break;
    x = a-'A';
    y = b-'A';
    z = cup[x];
    cup[x] = cup[y];
    cup[y] = z;
  }
  for(int i=0; i<3; i++) if(cup[i] == 1) cout <<(char)('A'+i)<<endl;
  return 0;
}

Measured memory_bytes: 1152
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<math.h>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
#include<unordered_map>
#include<list>
#include<fstream>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
const ll E=1e18+7;
#define F first
#define S second
#define MK make_pair
const ll MOD=1000000007;

ll gcd(ll a,ll b){
    if(a%b==0){return b;}
    return gcd(b,a%b);
}


int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> a;
    for(int i=0;i<n;i++){
        ll b;
        cin>>b;
        a.push_back(b);
    }
    ll x=a[0];
    bool j=false;
    for(int i=1;i<n;i++){
        x=gcd(x,a[i]);
    }
    for(int i=0;i<n && !j;i++){
        if(k<=a[i] && k%x==a[i]%x){j=true;}
    }
    cout<<(j?"POSSIBLE":"IMPOSSIBLE")<<endl;
    
    
    return 0;
}



Measured memory_bytes: 1400
#include<iostream>
#include<cstdio>
#include<array>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>

#define rep(i, a) for (int i = 0; i < a; i++)
#define reps(i, s, a) for (int i = s; i < a; i++)
#define llint long long int
using namespace std;

const int N_MAX = 505;
const int INF = 9999999;

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

    llint n = k / 2;
    int m = k % 2;

    rep(i, n) {
        if (a % 2 == 1) --a;
        b += a / 2;
        a /= 2;

        if (b % 2 == 1) --b;
        a += b / 2;
        b /= 2;
    }

    if (m == 1) {
        if (a % 2 == 1) --a;
        b += a / 2;
        a /= 2;
    }

    cout << a << ' ' <<  b;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P, ll> T;
 
long long int INF = 1e18;
const ll fact_table = 800008;
double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
// #define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
#define pc(x) cout << x << ",";
 
 
// ll mod = 998244353;
 ll mod = 1000000007;
  
ll mypow(ll number1,ll number2, ll mod){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = mypow(number1,number2 / 2, mod);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5];
 
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = rui(fact[fact_table],mod - 2);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/
bool multicase = false;

ll n,m,num,sum,a,b,c,d,e,h,q;
ll w, ans;
ll k;
char s[500005], t[500005];

void solve(){
    cin >> a >> b;
    for(ll i=1;i<=10000;i++){
        ll eight = i * 108 / 100;
        ll ten = i * 110 / 100;
        if(eight == a + i && ten == b + i){
            p(i);
            return;
        }
    }
    p(-1);
    return;
}

int main(){
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q;
    if(multicase){
        cin >> q;
    }else{
        q = 1;
    }
    while(q--){
        solve();
    }
    return 0;

}


















Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;

int main(){
    int k;
    string s;
    cin >> k >> s;
    if(s.size() <= k){
        cout << s << endl;
    }else{
        cout << s.substr(0,k) + "..." << endl;
    }

    return 0;

}

Measured memory_bytes: 3628
import copy
S = list(input())
N = len(S)
s0 = copy.deepcopy(S)
S.reverse()
s1 = S[:(N-1)//2]
s2 = S[(N+3)//2-1:]
s3 = S[:(N-1)//2]
s4 = S[(N+3)//2-1:]
s3.reverse()
s4.reverse()

if S == s0 and s1 == s3 and s2 == s4:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3700
//#pragma warning(disable:4996)
//#include <Windows.h>
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>
//#include <stdio.h>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;

template<class T>
inline void chmin(T& a, T b) {
	a = min(a, b);
}

template<class T>
inline void chmax(T& a, T b) {
	a = max(a, b);
}

void input();
void solve();

void daminput();

int main() {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	input();
	//daminput();
	solve();
	return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////

int N;
VI X, Y;

void input() {
	cin >> N;
	X.resize(N-1);
	Y.resize(N-1);
	for (int n = 0; n < N-1; n++)
	{
		cin >> X[n] >> Y[n];
	}
}

void daminput() {
}
template<class T>
struct Gedge {
	int src, to;
	T cost;
	int id;
	Gedge(int s, int t, T c, int i = -1) :src(s), to(t), cost(c), id(i) {}
	Gedge(int t, T c) :src(-1), to(t), cost(c), id(-1) {}
};

template<class T>
using WeightedGraph = vector<vector<Gedge<T>>>;
using UnweightedGraph = vector<vector<LL>>;
template<class T>
using Gedges = vector<Gedge<T>>;

template<class T>
struct TNode {
	int parent;
	VI childs;
	T cost;
	int id;
	TNode() :parent(-1), cost(0), id(-1) {};
};
template<class T>
using Tree = vector<TNode<T>>;
template<class Type>
void SetTree(WeightedGraph<Type>& G, Tree<Type>& T, int root = 0) {
	int N = G.size();
	T.resize(N);
	queue<int> q;
	q.push(root);
	T[root].parent = -1;
	T[root].id = -1;
	T[root].cost = 0;
	while (!q.empty()) {
		int cur = q.front();
		q.pop();
		for (Gedge<Type>& e : G[cur]) {
			if (e.to == T[cur].parent)continue;
			T[e.to].parent = cur;
			T[cur].childs.push_back(e.to);
			T[e.to].id = e.id;
			T[e.to].cost = e.cost;
			q.push(e.to);
		}
	}
}

WeightedGraph<int> G;
Tree<int> T;

int dp(int n) {
	int ans = 0;
	for (int ch : T[n].childs) {
		int chxor = dp(ch);
		ans = ans ^ (chxor + 1);
	}
	return ans;
}

void solve() {
	G.resize(N);
	for (int n = 0; n < N - 1; n++)
	{
		G[X[n] - 1].push_back({ Y[n] - 1, 1 });
		G[Y[n] - 1].push_back({ X[n] - 1, 1 });
	}
	SetTree(G, T, 0);
	int grundy = dp(0);
	if (grundy == 0)cout << "Bob\n";
	else cout << "Alice\n";
}

Measured memory_bytes: 20948
n,m=map(int,input().split())
edge=[[] for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    edge[a].append(b)
    edge[b].append(a)
rank=[100000 for i in range(n)]
low=[100000 for i in range(n)]
visited=[False for i in range(n)]
k=0
def dfs(pos,parent):
    global k
    rank[pos]=low[pos]=k
    k+=1
    visited[pos]=True
    for i in edge[pos]:
        if not visited[i]:
            dfs(i,pos)
            low[pos]=min(low[pos],low[i])
        elif i!=parent:
            low[pos]=min(low[pos],rank[i])
dfs(0,-1)
cnt=0
for i in range(n):
    for j in edge[i]:
        if low[i]>rank[j]:
            cnt+=1
print(cnt)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a,b;
	cin>>n>>a>>b;
	int p[n+1],x=0,y=0,z=0,minv=1000000000;
	for(int i=1;i<=n;i++)
	{
		cin>>p[i];
	}
	for(int i=1;i<=n;i++)
	{
		if(p[i]<=a)
			x++;
		if(p[i]>=a+1&&p[i]<=b)
			y++;
		if(p[i]>b)
			z++;
	}
	minv=min(min(x,y),z);
	cout<<minv<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Objects;

public class Main {
  public static void main(String[] args ){

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();

    System.out.println(Math.min(B, A * N));

  }
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





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

    int n;
    cin>>n;
    double res = 0;
    while (n--) {
	double x; string s;
	cin>>x>>s;
	if (s[0]=='J') {
	    res += x;
	} else {
	    res += 380000.0*x;
	}
    }

    cout<<fixed<<setprecision(15)<<res<<endl;
    
    
    return 0;
}


Measured memory_bytes: 3844
#include <bits/stdc++.h>
#define dcout cout << fixed << setprecision(15)
#define rep(i, a) for(int i = 0; i < a; i++)
#define arep(i, x) for(auto i : x)
#define all(v) v.begin(), v.end()
#define int long long
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
using namespace std;
signed main() {
    string s;
    cin >> s;
    string v;
    rep(i, (int)s.size()) {
        if(s[i] != 'B')
            v += s[i];
        else {
            if(v.size() > 0) v.erase((v.size() - 1));
        }
    }
    cout << v;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll n, k, res;
int main(void){
    // Your code here!
    cin >> n >> k;
    for (ll i = k + 1; i <= n; i++) {
        res += n / i * (i - k) + (n % i - k + 1 > 0 ? n % i - k + 1 : 0);
        if (k == 0) res--;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
def solve():
    H,N = map(int,input().split())
    attack = []
    mp = []
    for i in range(N):
        a,b = map(int,input().split())
        attack.append(a)
        mp.append(b)
    
    max_attack = max(attack)
    dp = [[float('inf')] * (H+max_attack) for _ in range(N+1)]

    for i in range(N+1):
        dp[i][0] = 0
    
    for i in range(N):
        for j in range(H+max_attack):
            if j - attack[i] >= 0:
                dp[i+1][j] = min(dp[i+1][j], dp[i][j-attack[i]]+mp[i], dp[i+1][j-attack[i]]+mp[i])
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
    
    ans = float('inf')
    for i in range(N+1):
        for j in range(H,H+max_attack):
            ans = min(ans, dp[i][j])
    
    print(ans)

if __name__ == '__main__':
    solve()

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



int32_t main(){
	
	// string s1,s2;cin>>s1>>s2;
	// int c=0;
	// for(int i=0;i<s1.length();i++){
	// 	if(s1[i]==s2[i]){
	// 		c++;
	// 	}
	// }
	// cout<<c<<endl;
	int a,b;cin>>a>>b;
	int ans=(b-1)/(a-1);
	if((b-1)%(a-1)!=0){
		ans++;
	}
	cout<<ans<<endl;


	return 0;
}

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

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

typedef long long LL;
typedef unsigned long UL;

using namespace std;


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

	int temp, a, e, k;

	REP(i, 6)
	{
		if (i == 0)
		{
			cin >> a;
		}
		else if (i == 4)
		{
			cin >> e;
		}
		else if (i == 5)
		{
			cin >> k;
		}
		else
		{
			cin >> temp;
		}
	}

	if (e - a > k)
	{
		cout << ":(" << endl;
	}
	else
	{
		cout << "Yay!" << endl;
	}

	return 0;
}


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

#define MOD 1000000007;

int main(){
    int n; cin >> n;
    int ans = 0;
    for(int i=1;i<=n;i+=2){
        int num = 0;
        int x = i;
        for(int j=1;j<=x;j++) if(x%j==0) num++;
      //  cout << i << ":" << num << endl;
        if(num==8) ans++;
    }
    cout << ans << endl;
    return 0;
}

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


int main(int argc, char const *argv[])
{
	int a, b, c, x; cin >> a >> b >> c >> x;
	int ans = 0;
	rep(i, a + 1)rep(j, b + 1)rep(k, c + 1) {
		if (500 * i + 100 * j + 50 * k == x) ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	weather := []string{"Sunny", "Cloudy", "Rainy", "Sunny"}
	for i, v := range weather {
		if s == v {
			fmt.Println(weather[i+1])
			return
		}
	}
}


Measured memory_bytes: 512
N = int(input())
A = list(map(int, input().split()))
n = N % 2

DP = [[0] * (N+1) for _ in range(N+1)]

for w in range(1, N+1):
    for i in range(N):
        j = i + w
        if j > N:
            continue
        if (w+n) % 2 == 1:
            DP[i][j] = min(DP[i+1][j] - A[i], DP[i][j-1] - A[j-1])
        else:
            DP[i][j] = max(DP[i+1][j] + A[i], DP[i][j-1] + A[j-1])

print(DP[0][N])


Measured memory_bytes: 115036
#pragma GCC optimize(2)

#include "bits/stdc++.h"

using namespace std;

#define all(a) begin(a), end(a)
#define MOD 1000000007
#define PII pair<int, int>
#define REP(x, l, u) for (ll x = l; x < u; x++)
#define RED(x, l, u) for (ll x = l; x >= u; x--)
#define complete_unique(a) a.erase(unique(begin(a), end(a)), end(a))
#define mst(x, a) memset(x, a, sizeof(x))
typedef vector<int> VI;
typedef long long ll;

ll quick_pow(ll a, ll b) {
    long long res = 1;
    while (b) {
        if (b & 1) {
            res = a * res;
        }
        a = a * a;
        b >>= 1;
    }
    return res;
}

ll gcd(ll a, ll b) {
    a = abs(a), b = abs(b);
    while (b != 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}

bool is_prime(int n) {
    if (n == 0)return false;
    if (n == 1)return false;
    if (n == 2)return true;
    if (n % 2 == 0)
        return false;
    int j = sqrt(n);
    for (int i = 2; i <= j; ++i) {
        if (n % i == 0)
            return false;
    }
    return true;
}

ll reverse_num(ll n) {
    ll x = 0, t = n;
    while (t != 0) {
        x = x * 10 + t % 10;
        t /= 10;
    }
    return x;
}

void solve() {
    //    freopen("C:\\Users\\26019\\Downloads\\P1195_4.in", "r", stdin);
    //    fclose(stdin);
    int t = 1;
    cin >> t;
    double D;
    cin >> D;
    int res = 0;
    while (t--) {
        ll x, y;
        cin >> x >> y;
        long double d = sqrt(x * x + y * y);
        if (d <= D) res++;
    }
    cout << res;
}


int main() {
    // 加速输入和输出
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
    return 0;
}



Measured memory_bytes: 3784
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL){
    x = x->right;
  }
  return x;
}

Node treeSearch(Node u,int k){
  if(u == NIL || k == u->key) return u;
  if(k < u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y;
  Node x;
  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);
  if(y->left != NIL) x = y->left;
  else x = y->right;
  if(x != NIL) x->parent = y->parent;
  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;
  if(y != z) z->key = y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z -> key = k;
  z -> left = NIL;
  z -> right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if(u == NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}


void preorder(Node u){
  if(u == NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(){
  int n,i,x;
  char com[20];
  scanf("%d",&n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25236
N = int(input())#地点の数
temp = input().rstrip().split(" ")
T = int(temp[0])#平均気温は T − H * 0.006度
A = int(temp[1])#最も平均気温がAに近い地点を探す
temp = input().rstrip().split(" ")
ans = []
for i in range(N):
    #平均気温を求める式
    H = int(temp[i])
    AVG = T - H * 0.006
    DIF = A - AVG
    ans.append(DIF * DIF)
print(ans.index(min(ans))+1)


Measured memory_bytes: 3060
n = int(input())
list_S = list(input())

left_E, left_W = 0, 0
right_E, right_W = list_S.count("E"), list_S.count("W")
ans = pow(10, 18)

for i in range(n):
    if list_S[i] == "E":
        right_E -= 1
        ans = min(ans, right_E + left_W)
        left_E += 1
    elif list_S[i] == "W":
        right_W -= 1
        ans = min(ans, right_E + left_W)
        left_W += 1

print(ans)

Measured memory_bytes: 6048
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long N,A,B;
    cin>>N>>A>>B;

    long long  ans=0;
    long long rem=0;
    ans = N/(A+B)*A;
    rem = N%(A+B);
    ans += min(rem,A);
   
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	int W, H;
	cin >> W >> H;
	vector<pair<long long, int>> list;
	for (auto i = 0; i < W; ++i)
	{
		long long temp;
		cin >> temp;
		list.push_back(make_pair(temp, i));
	}
	for (auto i = 0; i < H; ++i)
	{
		long long temp;
		cin >> temp;
		list.push_back(make_pair(temp, i + W));
	}

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

	auto x = W + 1;
	auto y = H + 1;
	auto result = 0ll;
	for (auto& p : list)
	{
		auto rem = x;
		if (p.second < W)
		{
			rem = y;
			--x;
		}
		else
		{
			--y;
		}
		result += p.first * rem;
	}
	cout << result << endl;

	return 0;
}

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

int main() {
	  string s;
      cin>>s;
      
     if(s[0]=='S')
     {
         cout<<"Cloudy";
     }
    else if(s[0]=='C')
        cout<<"Rainy";
    else
        cout<<"Sunny";
	return 0;
}


Measured memory_bytes: 256