akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#include<ctime>
#include<cstdlib>
#define INF long long int(1e18+1)
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main() {
	long long int n, d;
	cin >> n >> d;

	int ans = 0;
	while (n--) {
		long long int x, y;
		cin >> x >> y;
		if (x * x + y * y <= d * d)ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    ll x[100002];
    cin >> x[0];
    ll ans = 0;
    for(int i = 1; i < n; i++){
        cin >> x[i];
        ans += min(a * (x[i] - x[i - 1]), b);
    }
    cout << ans << endl;
}

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

#define int long long int
#define pb push_back
#define mp make_pair

const int N=1e5+5;



int32_t main()
{
    
    int nu,k,a[N],x,rem;
    
    vector <int> n,p;
    
    cin>>nu>>k;
    
    int flag=0;
    
    for(int i=1;i<=nu;i++)
    {
         cin>>x;
         
         a[i]=x;
         
         if(x>0)
         p.pb(x);
         else if(x<0)
         n.pb(x);
         else
         flag=1;
    }
    
     if(flag==1)
     k--;
     
     if(k==0)
     {
          cout<<0;
          return 0;
     }
     
     reverse(n.begin(),n.end());
     
     int ans=1e18,temp1,temp2;
          
         
     for(int i=0;i<p.size();i++)
     {
          rem=k-(i+1);
          
          
          
          if(rem<=0 || rem==k  || rem>n.size())
          continue;
          
          temp1=p[i];
          temp2=(-1)*n[rem-1];
          
       //   cout<<rem<<" "<<temp1<<" "<<temp2<<endl;
          
          ans=min(ans,min(2*temp1+temp2,2*temp2+temp1));
     }
     
     
     
     if(p.size()>=k)
     ans=min(ans,p[k-1]);
     if(n.size()>=k)
     ans=min(ans,-1*n[k-1]);
     
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1656
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n,k = iim()
ans = 0
while k**ans <= n:
    ans += 1

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define ip pair<ll,ll>
#define ff first
#define ss second
#define MAX 100005
const ll MOD = 1000000007;

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

	ll n;
	cin>>n;

	ll k = (n-400)/200;

	cout << 8-k << "\n";			
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
using namespace std;
int main(){
	string s;
	while(getline(cin,s),!cin.eof()){
		while(1){
			size_t p=s.find("@");
			if(p==string::npos)break;
			s.replace(p,3,string(s[p+1]-'0',s[p+2]));
		}
		cout<<s<<"\n";
	}
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
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; }
#define rep(i,n) for(int i=0;i<(int)(n);i++)
static const int mod = 1e9+7;
static const long long INF = 1LL << 60;
typedef long long ll;
int main(){
    int N, M;
    cin >> N >> M;
    vector<int> a(N+1, true);
    rep(i,M){
        int hoge;
        cin >> hoge;
        a[hoge] = false;
    }
    vector<int> dp(N+1);
    dp[0] = 1;
    rep(i,N){
        for(int j = i+1; j <= min(N, i+2); j++){
            if(a[j]){
                dp[j] += dp[i];
                dp[j] %= mod;
            }
        }
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>

using namespace std;

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

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

int main()
{
    int N, Q;
    cin >> N >> Q;
    
    set<int> S;
    rep(i, N){
        int c;
        cin >> c;
        S.insert(c);
    }
    
    rep(i, Q){
        int q;
        cin >> q;
        
        int ans = 0;
        for(int j=0; j*q <= 300000+q; ++j){
            auto itr = S.lower_bound(j*q);
            if(itr != S.begin()){
                --itr;
                ans = max(ans, *itr % q);
            }
        }
        
        cout << ans << endl;
    }
}

Measured memory_bytes: 15256
import java.io.*;
import java.math.*;
import java.util.*;
 
public class Main {
	static final long MOD = 1000000007L;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter pw = new PrintWriter(System.out);
		
		int N = sc.ni();
		long D = (long)Math.pow(sc.nl(),2);
		int ans = 0;
		for (int i = 0; i < N; i++) {
			long X = (long)Math.pow(sc.nl(),2)+(long)Math.pow(sc.nl(),2);
			if (X<=D)
				ans++;
		}
		pw.println(ans);
		pw.close();
	}
	
    static class FastScanner { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastScanner() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        }
        
        int ni() { 
            return Integer.parseInt(next()); 
        }
  
        long nl() { 
            return Long.parseLong(next()); 
        } 
  
        double nd() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() {
            String str = ""; 
            try { 
                str = br.readLine(); 
            } catch (IOException e) {
                e.printStackTrace(); 
            } 
            return str;
        }
    }
}

Measured memory_bytes: 54884
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = [0]*(n+1)
B = [0]*(m+1)
cnt  =0

for i in range(1,n+1):
    A[i] = A[i-1] + a[i-1]
for i in range(1,m+1):
    B[i] = B[i-1] + b[i-1]

j = m
for i in range(n+1):
    if A[i] > k:
        break
    while B[j] + A[i] > k:
        j -= 1
    cnt = max(cnt, i + j)

print(cnt)

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

int main(){
  int W,H,N;
  cin>>W>>H>>N;
  vector<vector<int>> a(H+1, vector<int>(W+1));
  int x,y;
  for(int i=0; i<N; i++){
    cin>>x>>y;
    cin>>a[y][x];
  }
  
  int x_less=0;
  int x_more=W;
  int y_less=0;
  int y_more=H;
  for(int y=0; y<=H; y++){
    for(int x=0; x<=W; x++){
      if(a[y][x]==1){
        if(x>x_less){
          x_less=x;
        }
      }else if(a[y][x]==2){
        if(x<x_more){
          x_more=x;
        }
      }else if(a[y][x]==3){
        if(y>y_less){
          y_less=y;
        }
      }else if(a[y][x]==4){
        if(y<y_more){
          y_more=y;
        }
      }
    }
  }
  //cout<<x_less<<" "<<x_more<<" "<<y_less<<" "<<y_more<<endl;
  if(x_more<=x_less || y_more<=y_less){
    cout<<0<<endl;
  }else{
    cout<<(x_more-x_less) * (y_more-y_less)<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
use std::io::prelude::*;
use std::io;
use std::cmp;

fn main() {
    let mut stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_to_string(&mut buf).unwrap();
    
    let mut lines = buf.lines();
    
    let mut line = lines.next().unwrap().split_whitespace();
    let w: i32 = line.next().unwrap().parse().unwrap();
    let h: i32 = line.next().unwrap().parse().unwrap();
    let n: i32 = line.next().unwrap().parse().unwrap();
    
    let mut left = 0;
    let mut right = w;
    let mut bottom = 0;
    let mut top = h;
    
    for i in 0..n {
        let mut line = lines.next().unwrap().split_whitespace();
        let x: i32 = line.next().unwrap().parse().unwrap();
        let y: i32 = line.next().unwrap().parse().unwrap();
        let a: i32 = line.next().unwrap().parse().unwrap();
        
        if a == 1 {
            left = cmp::max(left, x);
        } else if a == 2 {
            right = cmp::min(right, x);
        } else if a == 3 {
            bottom = cmp::max(bottom, y);
        } else if a == 4 {
            top = cmp::min(top, y);
        }
    }
    
    println!("{}", cmp::max(0, right - left) * cmp::max(0, top - bottom));
    
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    ll n; cin >> n;
    vl a(n); rep(i,n) cin >> a[i];
    ll x = 0;
    REP(i,2,n) x ^= a[i];
    ll s = a[0] + a[1];
    if(s - x < 0 || (s - x) & 1){
        puts("-1");
        return 0;
    }
    ll d = (s - x) / 2;
    ll mx = d;
    for(int i=40; i>=0; i--){
        ll k = mx + (1LL<<i);
        if(x>>i & 1){
            if(d>>i & 1){
                puts("-1");
                return 0;
            }else{
                if(k <= a[0]){
                    mx += 1LL<<i;
                }
            }
        }
    }
    if(mx == 0 || a[0] < mx){
        puts("-1");
        return 0;
    }
    cout << a[0] - mx << endl;
}

Measured memory_bytes: 3624
#include<stdio.h>

int A[2000],n;

int solve(int,int);

int main(){
  int x,m,q;
  int i;

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);

for(i = 0; i < q; i++){
    scanf("%d",&m);
    x = solve(0,m);
      if(x != 0) printf("yes\n");
      else printf("no\n");
  }
  return 0;
}

int solve (int t,int s){
  int y;

  if(s == 0) return 1;
  if(t >= n) return 0;
  y = solve(t + 1,s) || solve(t + 1, s - A[t]);
  return y;
}
  
  



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll H,W;
	cin >> H >> W;
	ll a[H][W];
	FOR(i,0,H)
		FOR(j,0,W)
			cin>>a[i][j];
	vector<ll> x1,x2,x3,x4;
	FOR(i,0,H){
		if(i%2==0)FOR(j,0,W){
			if(a[i][j]&1){
				if(j!=(W-1)){
					x1.push_back(i+1);
					x2.push_back(j+1);
					x3.push_back(i+1);
					x4.push_back(j+2);
					a[i][j+1]++;
					//cout << i+1 << " " << j+1 << " " << i+1 << " " <<j+2<<endl; 
				}else if(i!=(H-1)){
					a[i+1][j]++;
					x1.push_back(i+1);
					x2.push_back(j+1);
					x3.push_back(i+2);
					x4.push_back(j+1);
					//cout << i+1 << " " << j+1 << " " << i+2 << " " <<j+1<<endl; 
				}
			}
		}
		if(i%2==1)FORR(j,0,W){
			if(a[i][j]&1){
				if(j!=0){
					x1.push_back(i+1);
					x2.push_back(j+1);
					x3.push_back(i+1);
					x4.push_back(j);
					a[i][j-1]++;
					//cout << i+1 << " " << j+1 << " " << i+1 << " " <<j<<endl; 
				}else if(i!=(H-1)){
					x1.push_back(i+1);
					x2.push_back(j+1);
					x3.push_back(i+2);
					x4.push_back(j+1);
					a[i+1][j]++;
					//cout << i+1 << " " << j+1 << " " << i+2 << " " <<j+1<<endl; 
				}
			}
		}
	}
	cout << x1.size() << endl;
	FOR(i,0,x1.size()){
		cout << x1[i] << " " << x2[i] << " " << x3[i] << " " << x4[i] <<endl; 
	}
}


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

const int INF = 10000000;
const int E_MAX = 1000005;

int dp[E_MAX][2];

int main(){
    string n;
    cin >> n;
    int e = n.length();
    n = '0' + n;
    memset(dp, 0, sizeof(dp));
    dp[0][1] = 1;
    for(int i = 1; i <= e; i++){
        int num = n[i] - '0';
        dp[i][0] = min(dp[i-1][0] + num,dp[i-1][1] + 10 - num);
        dp[i][1] = min(dp[i-1][0] + num + 1, dp[i-1][1] + 10 - num -1);
    }
    cout << dp[e][0] << endl;
    return 0;
}

Measured memory_bytes: 9136
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=acos(-1);
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a!=c) {
    cout << 1 << endl;
  }
  else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl


typedef long long ll;

ll solve(vector<string> &s,int n,int &y,int x){
    if(isdigit(s[y][x])) return s[y][x] - '0';
    if(s[y][x] == '+'){
        ll term = 0;
        while(y+1 < n && (int)s[y+1].size() > x+1 && s[y+1][x] == '.'){
            y++;
            term += solve(s,n,y,x+1);
        }
        return term;
    }else{
        ll term = 1;
        while(y+1 < n && (int)s[y+1].size() > x+1 && s[y+1][x] == '.'){
            y++;
            term *= solve(s,n,y,x+1);
        }
        return term;
    }
}

int main(void){
    int n;
    while(cin>>n,n){
        vector<string> s(n);
        rep(i,n) cin>>s[i];
        int y = 0;
        cout<<solve(s,n,y,0)<<endl;
    }
    return 0;
}



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

using ll = long long;
using namespace std;
int main() {
    int H, W; cin >> H >> W;
    
    vector<bool> grid(H*W);
    string buf;
    for(int i=0; i < H; i++) {
        cin >> buf;
        for (int j = 0; j < W; j++) {
            if (buf[j] == '#') {
                (grid[i * W + j]) = false;
            } else {
                (grid[i * W + j]) = true;
            }
        }
        
    }

    vector<int> right(H*W);
    for(int i=0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (j != 0) {
                if (grid[i * W + j]) {
                    right[i * W + j] = right[i * W + j - 1] + 1;
                } else {
                    right[i * W + j] = 0;
                }      
            } else {
                if (grid[i * W + j]) {
                    right[i * W + j] = 1;
                } else {
                    right[i * W + j] = 0;
                }      
            }
        }      
    }


    
    vector<int> left(H*W);
    for(int i=0; i < H; i++) {
        for (int j = W-1; j >= 0; j--) {
            if (j != W-1) {
                if (grid[i * W + j]) {
                    left[i * W + j] = left[i * W + j + 1] + 1;
                } else {
                    left[i * W + j] = 0;
                }      
            } else {
                if (grid[i * W + j]) {
                    left[i * W + j] = 1;
                } else {
                    left[i * W + j] = 0;
                }      
            }
        }      
    }


    vector<int> down(H*W);
    for(int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (i != 0) {
                if (grid[i * W + j]) {
                    down[i * W + j] = down[(i-1) * W + j ] + 1;
                } else {
                    down[i * W + j] = 0;
                }      
            } else {
                if (grid[i * W + j]) {
                    down[i * W + j] = 1;
                } else {
                    down[i * W + j] = 0;
                }      
            }
        }      
    }

    


    vector<int> up(H*W);
    for(int i = H-1; i >=0; i--) {
        for (int j = 0; j < W; j++) {
            if (i != H-1) {
                if (grid[i * W + j]) {
                    up[i * W + j] = up[(i+1) * W + j ] + 1;
                } else {
                    up[i * W + j] = 0;
                }      
            } else {
                if (grid[i * W + j]) {
                    up[i * W + j] = 1;
                } else {
                    up[i * W + j] = 0;
                }      
            }
        }      
    }



    vector<int> sum(H*W);

    for(int i=0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            // sum[i * W + j] = right[i * W + j - 1 ] + left[i * W + j + 1] + up[(i - 1) * W + j] + down[(i+1) * W + j];
            //if (grid[i * W + j]) sum[i * W + j] + 1;
            sum[i * W + j] = right[i * W + j ] + left[i * W + j] + up[i * W + j] + down[i * W + j] - 3;
        }
    }


    int max_sum = *std::max_element(sum.begin(), sum.end());
    cout << max_sum  << "\n";


}

Measured memory_bytes: 78848
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<stack>
using namespace std;

void Push(int a1,int a2,vector<int>&v)
{
	v.push_back(a1-1);
	v.push_back(a1);
	v.push_back(a2);
	v.push_back(a2+1);
};
void Unique(vector<int>&v){
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
};
void Erase(int x,vector<int>&v)
{
	vector<int>::iterator ite=find(v.begin(),v.end(),x);
	if(ite!=v.end())
		v.erase(ite);
}
int Press(int x,const vector<int>&v)
{
	return lower_bound(v.begin(),v.end(),x)-v.begin();
}

int h,w;
vector<vector<bool> >m;
struct P{int x,y;P(int x,int y):x(x),y(y){}};
void Fill(int sx,int sy)
{
	const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
	stack<P>s;
	s.push(P(sx,sy));
	while(!s.empty())
	{
		P p=s.top();
		s.pop();
		if(p.x<0||p.y<0||m[0].size()<=p.x||m.size()<=p.y||m[p.y][p.x])continue;
		m[p.y][p.x]=true;
		for(int i=0;i<4;++i)
			s.push(P(p.x+dx[i],p.y+dy[i]));
	}
}

int main()
{
	int n,x1[1000],x2[1000],y1[1000],y2[1000];
	int i,j,k;
	vector<int>pressX,pressY;
	pressX.reserve(4000);
	pressY.reserve(4000);

	while(scanf("%d%d",&w,&h),w)
	{
		pressX.clear();
		pressY.clear();
		scanf("%d",&n);
		for(i=0; i<n; ++i)
		{
			scanf("%d%d%d%d",x1+i,y1+i,x2+i,y2+i);
			--x2[i];
			--y2[i];
			Push(x1[i],x2[i],pressX);
			Push(y1[i],y2[i],pressY);
		}
		Unique(pressX);
		Erase(-1,pressX);
		Erase(w,pressX);
		Unique(pressY);
		Erase(-1,pressY);
		Erase(h,pressY);

		int x,y;
		m = vector<vector<bool> >(pressY.size(), vector<bool>(pressX.size(),false));
		for(i=0; i<n; ++i)
		{
			int lx=Press(x1[i],pressX);
			int rx=Press(x2[i],pressX);
			int uy=Press(y1[i],pressY);
			int dy=Press(y2[i],pressY);
			for(y=uy; y<=dy; ++y)
				for(x=lx; x<=rx; ++x)
					m[y][x]=true;
		}
		int res=0;
		for(y=0; y<m.size(); ++y)
			for(x=0; x<m[0].size(); ++x)
				if(!m[y][x])
				{
					++res;
					Fill(x,y);
				}
		printf("%d\n",res);
	}
	return 0;
}

Measured memory_bytes: 6700
#include <bits/stdc++.h>
using namespace std;
int abs(int x){
  if (x>=0) return x;
  if (x<0) return -x;
}
int main(){
  int N,M;
  cin >> N >> M;
  int a[N],b[N],c[M],d[M];
  for (int i = 0; i < N; i++){
    cin >> a[i] >> b[i];
  }
  for (int i = 0; i < M; i++){
    cin >> c[i] >> d[i];
  }
  for (int i = 0; i < N; i++){
    int point = 0;
    for (int j = 1; j < M; j++){
      if (abs(c[j]-a[i])+abs(d[j]-b[i])<abs(c[point]-a[i])+abs(d[point]-b[i])){
        point = j;
      }
    }
    cout << point+1 << endl;
  }
}

Measured memory_bytes: 764
#include<cstdio>
#include<algorithm>
#define MN 600001
using namespace std;

int read_p,read_ca;
inline int read(){
    read_p=0;read_ca=getchar();
    while(read_ca<'0'||read_ca>'9') read_ca=getchar();
    while(read_ca>='0'&&read_ca<='9') read_p=read_p*10+read_ca-48,read_ca=getchar();
    return read_p;
}
char s[MN];
int n,m,ne[MN][27],NE[MN][20],l,r;
inline int min(int a,int b){return a==0?b:b==0?a:a<b?a:b;}
int main(){
	register int i,j;
	scanf("%s",s);
	
	for (n=0;s[n];n++);
	
	for (i=n-1;i>=0;i--){
		ne[i][s[i]-='a']=i+1;
		for (j=s[i];j<26;j++) ne[i][j+1]=ne[ne[i][j]][j];
		for (j=0;j<s[i];j++) ne[i][j]=min(ne[ne[i][j==0?26:j-1]][j==0?0:j-1],ne[ne[i][26]][j]);
	}
	
	for (i=n-1;i>=0;i--)
	if (NE[i][0]=ne[i][26])
	for (j=1;NE[i][j]=NE[NE[i][j-1]][j-1];j++);
	
	for (m=read();m--;){
		l=read()-1;r=read();
		for (i=19;i>=0;i--)
		if (NE[l][i]&&NE[l][i]<=r) l=NE[l][i];
		puts(l==r?"Yes":"No");
	}
}

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

long long mod = 1000000007;
long long N, B[1 << 18];
long long sz[2009];
long long dp[2009][4009][2];
long long dr[2009][4009][3];
long long fact[2009];
long long power[2009];
vector<int> X[1 << 18];

long long Div(long long a) {
	if (a % 2 == 1) a += mod;
	return a / 2;
}

void dfs(int pos) {
	sz[pos] = 1;
	for (int i : X[pos]) {
		dfs(i);
		sz[pos] += sz[i];
	}

	// DP の計算
	for (int i = 0; i <= X[pos].size(); i++) {
		for (int j = 0; j <= sz[pos]; j++) {
			dr[i][j][0] = 0; dr[i][j][1] = 0; dr[i][j][2] = 0;
		}
	}

	dr[0][0][0] = 1; int S = 0;
	for (int i = 0; i < X[pos].size(); i++) {
		int to = X[pos][i];
		for (int j = 0; j <= S; j++) {
			for (int k = 0; k <= sz[to]; k++) {
				dr[i + 1][j + k][0] += dr[i][j][0] * dp[to][k][0];
				dr[i + 1][j + k][1] += dr[i][j][1] * dp[to][k][0];
				dr[i + 1][j + k][2] += dr[i][j][2] * dp[to][k][0];
				dr[i + 1][j + k][1] += dr[i][j][0] * dp[to][k][1];
				dr[i + 1][j + k][2] += dr[i][j][1] * dp[to][k][1];
				dr[i + 1][j + k][0] %= mod;
				dr[i + 1][j + k][1] %= mod;
				dr[i + 1][j + k][2] %= mod;
			}
		}
		S += sz[to];
	}

	for (int i = 0; i <= S; i++) {
		dp[pos][i + X[pos].size() - 0][0] += Div(dr[X[pos].size()][i][0]);
		dp[pos][i + X[pos].size() - 0][1] += dr[X[pos].size()][i][0];
		if (X[pos].size() >= 1) {
			dp[pos][i + X[pos].size() - 1][0] -= dr[X[pos].size()][i][1];
			dp[pos][i + X[pos].size() - 1][1] -= dr[X[pos].size()][i][1];
		}
		if (X[pos].size() >= 2) {
			dp[pos][i + X[pos].size() - 2][0] += dr[X[pos].size()][i][2];
		}
	}
	for (int i = 0; i <= N; i++) {
		dp[pos][i][0] = (dp[pos][i][0] + mod * mod) % mod;
		dp[pos][i][1] = (dp[pos][i][1] + mod * mod) % mod;
		dp[pos][i][2] = (dp[pos][i][2] + mod * mod) % mod;
	}
}

void init() {
	power[0] = 1; fact[0] = 1;
	for (int i = 1; i <= 2000; i++) power[i] = (2LL * power[i - 1]) % mod;
	for (int i = 1; i <= 2000; i++) fact[i] = (1LL * i * fact[i - 1]) % mod;
}

int main() {
	cin >> N;
	for (int i = 2; i <= N; i++) cin >> B[i];
	for (int i = 2; i <= N; i++) X[B[i]].push_back(i);

	init();
	dfs(1);
	
	long long Answer = 0;
	for (int i = 1; i <= N; i++) {
		long long v1 = dp[1][i - 1][0];
		long long v2 = fact[i];
		long long v3 = power[i];
		Answer += (v1 * v2 % mod) * v3 % mod;
		Answer %= mod;
	}
	cout << Answer << endl;
	return 0;
}

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

using namespace std;

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


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

 int res=0,flag=-1;
 
  rep(i,n) {
    int a;
    cin >> a;
  if(a%4==0) res++;
  else if(a%2==0) flag=0;
  else res--;  
   
  }
   
  if(res>=flag) cout << "Yes" << endl; 
  else cout << "No" << endl;
   
}

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

int n, m;
int field[400][400];
int cost[400];
int a, b ,c;
int ans = 0;
int count;

void dfs(int x, int y){
	if(y == n-1){
		ans = max(ans, count);
	}

	for(int i=0; i < n; i++){
		if(field[y][i] != 0){
			count += field[y][i];
			if(cost[i] < count){
				cost[i] = count;
				dfs(y, i);
				count -= field[y][i];
			}
			else {
				count -= field[y][i];
				continue;
			}
		}
	}
}

int main(){
	for(int i=0; i < 400; i++){
		for(int j=0; j < 400; j++){
			field[i][j] = 0;
			cost[i] = 0;
		}
	}

	cin >> n >> m;
	for(int p=0; p < m; p++){
		cin >> a >> b >> c;
		field[a][b] = c;
	}
	for(int i=0; i < n; i++){
		count = 0;
		dfs(0, i);
	}

	cout << ans << endl;
}

Measured memory_bytes: 1788
N= int(input())
l = [list(map(int, input().split())) for _ in range(N)]

l.sort(key=lambda x: x[1])
count = 0
for i in range(N):
    count += l[i][0]
    if not count <= l[i][1]:
        print('No')
        quit()
print('Yes')

Measured memory_bytes: 88024
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    a, b, c, d = il()
    print('Right' if a + b < c + d else 'Balanced' if a + b == c + d else 'Left')


if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  if (N % 3 != 0) {
    cout << ((A[0] == 0 && A[N - 1] == 0) ? "Yes" : "No") << '\n';
    return 0;
  }
  int M = N / 3;
  for (int i = 0; i < 3; i++) {
    if (A[i * M] != A[(i + 1) * M - 1]) {
      cout << "No" << '\n';
      return 0;
    }
  }
  cout << (((A[0] ^ A[M] ^ A[2 * M]) == 0) ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>; // intの2次元の型に vvi という別名をつける
const ll llMAX=9223372036854775807LL; 
const ll llMIN=-9223372036854775808LL;

ll x,k,d;

//bbbは正の数
constexpr ll floordiv(ll aaa,ll bbb)
{
  if (aaa<0){
    return (aaa-bbb+1)/bbb;
  }else{
    return aaa/bbb;
  }
}
constexpr ll floormod(ll aaa,ll bbb)
{
  ll ret=aaa%bbb;
  if (ret<0)ret+=bbb;
  return ret;
}



int main(){
  ll ans=0;
  cin>>x>>k>>d;
  ll ansp=floordiv(x,d);
  ll pmodx=x-d*ansp;
  ll mmodx=pmodx-d;
  ll ansm=ansp-1;
  ansp=abs(ansp);
  ansm=abs(ansm);

  if ((ansp>k)&(ansm>k)){
    x-=d*k*(1-2*(x<0));
    ans=x;
  }else{
    if (floormod(ansp,2)==k%2)ans=pmodx;
    if (floormod(ansm,2)==k%2)ans=mmodx;
  }
  



  
  cout<<abs(ans)<<endl;
  return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>

main(){
  int n,i,j,k,m,g[100][100];

  scanf("%d",&n);

  for(i=0;i<100;i++){
    for(j=0;j<100;j++){
      g[i][j]=0;
    }
  }

  for(i=0;i<n;i++){ 
    scanf("%d%d",&j,&k);
    for(j=0;j<k;j++){
      scanf("%d",&m);
      g[i][m-1]=1;
    }
  } 
  
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      printf("%d",g[i][j]);
      if(j!=n-1){
	printf(" ");
      }
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 644
// Code by H~$~C
#include <bits/stdc++.h>
using namespace std;

static const int Maxn = 100005;

int n;
int a[Maxn];
int dp[Maxn];

int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    ++u, ++v;
    a[u] ^= w, a[v] ^= w;
  }
  
  int ans = 0;
  int allmask = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] == 0) {
      ++ans;
    }
    else if (allmask & (1 << a[i] - 1)) {
      allmask ^= (1 << a[i] - 1);
      ++ans;
    }
    else {
      allmask ^= (1 << a[i] - 1);
    }
  }
  
  dp[0] = 0;
  for (int mask = 1; mask < (1 << 15); ++mask) {
    dp[mask] = -1;
    int xorsum = 0;
    for (int i = 0; i < 15; ++i) {
      if (mask >> i & 1) {
        xorsum ^= (i + 1);
      }
    }
    if (xorsum != 0) {
      continue;
    }
    
    for (int smask = mask; smask; smask = (smask - 1) & mask) {
      if (dp[smask] == -1) continue;
      dp[mask] = max(dp[mask], dp[smask] + dp[mask ^ smask]);
    }
    dp[mask] = max(dp[mask], 1);
  }
  
  printf("%d\n", n - (ans + dp[allmask]));
  return 0;
}


Measured memory_bytes: 768
use proconio::*;
use proconio::marker::*;
use std::collections::*;
use std::ops::Bound::*;

fn rand_memory() -> usize {
    Box::into_raw(Box::new("I hope this is a random number")) as usize
}

fn rand() -> usize {
    static mut X: usize = 0;
    unsafe {
        if X == 0 {
            X = rand_memory();
        }
        X ^= X << 13;
        X ^= X >> 17;
        X ^= X << 5;
        X
    }
}

const F: usize = 26;

#[fastout]
fn run() {
    input! {
        d: usize,
        c: [i64; F],
        mut s: [[i64; F]; d],
    }
    let mut t = vec![0; d];
    for t in t.iter_mut() {
        *t = rand() % F;
    }
    let mut score = 0;
    let mut set = vec![BTreeSet::new(); F];
    for set in set.iter_mut() {
        set.insert(0);
    }
    for (i, (s, &t)) in s.iter().zip(t.iter()).enumerate() {
        let k = i as i64 + 1;
        score += s[t];
        set[t].insert(i + 1);
        for (c, set) in c.iter().zip(set.iter()) {
            let last = *set.iter().rev().next().unwrap() as i64;
            score -= *c * (k - last);
        }
    }
    for set in set.iter_mut() {
        set.insert(d + 1);
    }
    s.insert(0, vec![]);
    t.insert(0, 0);
    let func = |contest: usize, day: usize| -> i64 {
        let day = day as i64;
        c[contest] * day * (day - 1) / 2
    };
    let mut max = score;
    for _ in 0..1000000 {
        let d = rand() % d + 1;
        let q = rand() % F;
        let save = t[d];
        let x = t[d];
        assert!(set[x].remove(&d));
        let a = *set[x].range((Unbounded, Included(&d))).rev().next().unwrap();
        let b = *set[x].range((Included(&d), Unbounded)).next().unwrap();
        score -= s[d][x];
        score += func(x, d - a) + func(x, b - d);
        score -= func(x, b - a);
        let x = q;
        t[d] = x;
        let a = *set[x].range((Unbounded, Included(&d))).rev().next().unwrap();
        let b = *set[x].range((Included(&d), Unbounded)).next().unwrap();
        assert!(set[x].insert(d));
        score += s[d][x];
        score += func(x, b - a);
        score -= func(x, d - a) + func(x, b - d);
        if score > max {
            max = score;
        } else {
            score = max;
            t[d] = save;
            assert!(set[x].remove(&d));
            assert!(set[save].insert(d));
        }
    }
    let mut ans = vec![];
    for (i, set) in set.into_iter().enumerate() {
        for v in set {
            if v != 0 && v != d + 1 {
                ans.push((v, i));
            }
        }
    }
    ans.sort();
    for a in ans {
        println!("{}", a.1 + 1);
    }
}

fn main() {
    run();
}


Measured memory_bytes: 2404
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &&x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int A, B, C;
    cin >> A >> B >> C;
    if (A + B > C - 1) cout << B + C << endl;
    else {
        int t = (C - 1) - (A + B);
        cout << B + C - t << endl;
    }
    return (0^_^0);
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
#define ll long long
using namespace std;
const int N=555;
map <ll,ll> mp;
ll n,inf=1e18;
ll a,b,c,d;
ll dfs(ll now)
{   if(mp[now])
     {  return mp[now];
	 }
	 ll ans=inf;
	  if(now>ans/d)
	     ans=inf;
	  else
	    ans=now*d;
  for(int i=0;i<5;i++)
   {   ll val=now-i;
      if(val==0)
       {    ans=min(d*i,ans);
            return mp[now]=ans;
	   }
      if(val%2==0)
         ans=min(ans,dfs(val/2)+d*i+a);
      if(val%3==0)
       ans=min(ans,dfs(val/3)+d*i+b);
       if(val%5==0)
       ans=min(ans,dfs(val/5)+d*i+c);
   }
   for(int i=0;i<5;i++)
    {   ll val= now+i;
      if(val%2==0)
         ans=min(ans,dfs(val/2)+d*i+a);
      if(val%3==0)
       ans=min(ans,dfs(val/3)+d*i+b);
       if(val%5==0)
       ans=min(ans,dfs(val/5)+d*i+c);
	}
	  mp[now]=ans;
	  return ans;
}
int main()
{
    int t;
    scanf("%d",&t);
    inf=1e18;
    while(t--){
        scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
        mp.clear();
        printf("%lld\n",dfs(n));
    }
    return 0;
}

Measured memory_bytes: 6628
#include <bits/stdc++.h>
#include<queue>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;

int main(){
    int h,a;
    cin >> h >> a;
    int count = 0;
    while(h >0){
        h -= a;
        count++;
    }
    cout << count << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_set>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long

int n[2];

int main(void)
{
    rep(i,3)
    {
        cin >> n[i];
    }

    int result = 0;
    while(n[0] != n[1] || n[1] != n[2])
    {
        result++;
        sort(n, n+3);

        if(n[1] == n[2])
        {
            n[0] += 2;
            continue;
        }

        n[0]++;
        n[1]++;
    }

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;
int n, m, dp[200]; pair<int, int> a[200];
int main() {
	while(true) {
		scanf("%d", &n);
		if(n == 0) break;
		for(int i = 0; i < n; i++) scanf("%d%d", &a[i].first, &a[i].second);
		scanf("%d", &m);
		for(int i = 0; i < m; i++) scanf("%d%d", &a[n + i].first, &a[n + i].second);
		sort(a, a + n + m);
		int ret = 0;
		for(int i = 0; i < n + m; i++) dp[i] = -1;
		for(int i = 0; i < n + m; i++) {
			bool flag = false;
			for(int j = 0; j < ret; j++) {
				if(dp[j] >= a[i].second) {
					dp[j] = a[i].second; flag = true; break;
				}
			}
			if(!flag) {
				dp[ret] = a[i].second, ret++;
				int ptr = i;
				while(a[ptr].first == a[i].first) i++; i--;
			}
		}
		printf("%d\n", ret);
	}
}

Measured memory_bytes: 2608
#include <iostream> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main() {
	int h, a,ans;
	cin >> h >> a;
	ans = h / a;
	if (h % a != 0) {
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define int long long
#define ll long long
#define P pair<int,int>
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define all(V) V.begin(),V.end()
#ifdef int
constexpr int INF = LLONG_MAX / 10;
#else
constexpr int INF = INT_MAX / 10;
#endif
constexpr double eps = 1e-9;
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
using namespace std;
inline ll gcd(ll a, ll b) {
	while (b) {
		ll c = a;
		a = b; b = c % b;
	}
	return a;
}
inline ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
bool isprime(ll n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
ll mypow(ll a, ll b) {
	if (!b)return 1;
	if (b & 1)return mypow(a, b - 1) * a;
	ll memo = mypow(a, b >> 1);
	return memo * memo;
}
int n, a[200010], b[200010];
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		b[a[i]]++;
	}
	int ans = 0;
	REP(i, n)ans += b[i] * (b[i] - 1) / 2;
	rep(i, n) {
		if (b[a[i]])cout << ans - b[a[i]] * (b[a[i]] - 1) / 2 + (b[a[i]] - 1) * (b[a[i]] - 2) / 2 << endl;
		else cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 5112
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

int main() {
    int R,G,B,N;

    cin >>R>>G>>B>>N;
    Int ans =0;
    int r = N/R +1;
    int g = N/G +1;

    rep(i,r){
        rep(j,g){

            if( (N-(i*R+j*G))%B == 0 && i*R+j*G <= N ){
                ans++;
            }
        }
    }


    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(s: str):
    ret = ''
    for c in s:
        if c == ',':
            ret += ' '
        else:
            ret += c
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define Test ll t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define loopS(i,a,b,step) for(ll i=a;i<b;i+=step)
#define loopRS(i,a,b,step) for(ll i=a;i>=b;i-=step)
#define ull unsigned long long int
#define pll pair<ll,ll>
#define puu pair<ull, ull>
#define V vector
#define M map
#define UM unordered_map
#define mp(x,y) make_pair(x,y)
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define inf INT_MAX
#define S3(a,b,c) cin >> a >> b >> c
#define S2(a,b) cin >> a >> b
#define debug(x) cout << #x << " = " << x << endl;
using namespace std;

void input(ll n, ll arr[]) {
	rep(i, 1, n + 1)cin >> arr[i];
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cout.tie(NULL);
		ll n; cin >> n;
		ll h[n + 1];
		input(n, h);
		ll dp[n + 1];
		dp[1] = 0; dp[2] = abs(h[2] - h[1]);
		rep(i, 3, n + 1) {
			dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]),
			dp[i - 2] + abs(h[i - 2] - h[i]) );
		}
		cout << dp[n] << endl;
}


Measured memory_bytes: 1792
fn main() {
    /* 標準入力を開いて */
    let mut scan = std::io::stdin();

    let mut line = String::new();

    /* 読み込んで  */
    let _ = scan.read_line(&mut line);
    /* 空白で分割してからベクタにまとめる */
    let vec: Vec<&str> = line.split_whitespace().collect();

    /* それぞれを変換 */
    let n: u32 = vec[0].parse().unwrap_or(0);
    let m: u32 = vec[1].parse().unwrap_or(0);
    println!("{}", n+m/2);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    ll n,z,w;cin>>n>>z>>w;
    if(n==1){
        ll x;cin>>x;
        cout<<abs(x-w)<<endl;
        return 0;
    }
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
    }   
    cout<<(max(abs(a[n-1]-a[n-2]),abs(w-a[n-1])))<<endl;
    return 0;
}


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

int main(){
    int n,m;
    cin>>n>>m;
    int a[n][m],b[m],c[n]={0};
    for(int i=0; i<n; ++i){
        for(int j=0; j<m; ++j){
            cin>>a[i][j];
        }
    }
    for(int i=0; i<m; ++i)cin>>b[i];
    for(int i=0; i<n; ++i){
        for(int j=0; j<m; ++j){
            c[i]+=a[i][j]*b[j];
        }
    }
    for(int i=0; i<n; ++i)cout<<c[i]<<endl;
    return 0;
}


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

using namespace std;

int main()
{
  int N, K, Q;
  cin >> N >> K >> Q;
  int *point = new int[N];

  for (int i = 0; i < N; i++)
    point[i] = 0;

  for (int i = 0; i < Q; i++){
    int A;
    cin >> A;
    point[A - 1]++;
  }

  for (int i = 0; i < N; i++){
    if (K > (Q - point[i])) cout << "Yes" << endl;
    else cout << "No" << endl;
  }

  delete[] point;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

ll N;
vector<pair<ll, ll>> vec;

void solve() {

	vector<ll> ans;
	ans.reserve(N);

	for (ll i = N - 1; i >= 0; i--) {
		if (vec[i].second == -1) continue;
		if (vec[i].first == vec[i].second) {
			ans.emplace_back(vec[i].first);
			vec[i].second = -1;
			i = N;
		}
		else {
			vec[i].second--;
		}
	}

	if (ans.size() == N) {
		for (ll i = N - 1; i >= 0; i--) cout << ans[i] << endl;
	}
	else {
		cout << -1;
	}

	return;
}

int main() {

	cin >> N;
	vec.resize(N);
	rep(i, N) {
		ll inp;
		cin >> inp;
		vec[i] = make_pair(inp, i + 1);
	}

	solve();
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
cards = []
suits = ['S', 'H', 'C', 'D']

n = int(input())

for i in range(n):
    s, r = input().split()
    r = int(r)
    if s == 'S':
        cards.append(0 + r)
    elif s == 'H':
        cards.append(13 + r)
    elif s == 'C':
        cards.append(26 + r)
    elif s == 'D':
        cards.append(39 + r)

for j in range(1, 53):
    if not j in cards:
        print(suits[(j-1)//13], (j-1)%13+1)


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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  if (B - A + 1 > 2 * K) {
    for (int i = A; i < A + K; ++i)
      cout << i << endl;
    for (int i = B - K + 1; i <= B; ++i)
      cout << i << endl;
  }
  else {
    for (int i = A; i <= B; ++i)
      cout << i << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
	int n,m,v[100];
	string s[100],str;
	long long ans;
	while(cin>>n>>m,n){
		ans=0;
		for(int i=0;i<n;i++)cin>>s[i]>>v[i];
		for(int i=0;i<m;i++){
			cin>>str;
			for(int j=0;j<n;j++){
				for(int k=7;k>=0;k--){
					if(s[j][k]!=str[k] && s[j][k]!='*')k-=20;
					if(k==0)ans+=v[j],j+=200;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


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

int main()
{
    int i,j;
    char a[4][4];
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            scanf("%c",&a[i][j]);
        }
        getchar();
    }
    for(i=0;i<3;i++)
    {
        printf("%c",a[i][i]);
    }
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int main()
{
    int n,mod;
    scanf("%d",&n);
    for(int i=1;i<=100;i*=10)
    {
        mod=(n/i)%10;
        if(mod==7)
        break;
    }
    if(mod==7)
    printf("Yes");
    else
    printf("No");
}


Measured memory_bytes: 1708
# -*- coding utf-8 -*-
import sys
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
D = [A[i] - B[i] for i in range(N)]
D.sort()

if D[0] >= 0:
    print(0)
    sys.exit()

sum = 0
count = 0
nsum = 0
for i in range(N):
    sum += D[i]
    if D[i] < 0:
        count += 1
        nsum += D[i]
if sum < 0:
    print(-1)
    sys.exit()

j = N - 1
while nsum < 0:
    nsum += D[j]
    count += 1
    j += -1

print(count)


Measured memory_bytes: 19188