akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, R;
    cin >> N >> R;
    if (N >= 10) {
        cout << R << endl;
    }
    else {
        cout << R + 100 * (10 - N) << endl;
    }
    return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int main () {
  int n,m;
  cin>>n>>m;
  vector<vector<int>>data;
  for(int i=0;i<100010;i++){
    vector<int>x;
    data.push_back(x);
  }
  int input_order[m][2];
  for(int i=0;i<m;i++){
    int perfecture,year;
    cin>>perfecture>>year;
    input_order[i][0]=perfecture;
    input_order[i][1]=year;
    data[perfecture].push_back(year);
  }
  for(int i=0;i<100010;i++){
    sort(data[i].begin(),data[i].end());
  }
  for(int i=0;i<m;i++){
    int perfecturee=input_order[i][0];
    int pos = upper_bound(data[perfecturee].begin(),data[perfecturee].end(),input_order[i][1])-data[perfecturee].begin();
    string a = to_string(perfecturee);
    string b = to_string(pos);
    for(int j=0;j<6-a.length();j++){
        cout<<"0";
    }
    cout<<a;
    for(int j=0;j<6-b.length();j++){
        cout<<"0";
    }
    cout<<b<<endl;
  }
  return 0;
}



Measured memory_bytes: 7792
import sys
input = sys.stdin.readline

N, C, K = map(int, input().split())
T = [int(input()) for i in range(N)]
T.sort()
answer = 1
limit = T[0] + K
n = 0

for i in T:
    if i <= limit and n < C:
        n += 1
    else:
        answer += 1
        n = 1
        limit = i + K

print(answer)

Measured memory_bytes: 7484
#include <stdio.h>
#define abs(a) ((a>=0)? (a):(-a))

int initialize(int a[],int num){
	int i;
	for(i=0;i<num;i++){
		a[i]=0;
	}
	
	return 0;
}

int scan(int a[],int num){
	int i,index=0;
	int temp;
	int minusMax=-100001;
	for(i=0;i<num;i++){
		scanf("%d",&temp);
		
		if(index==0 && a[index]==0 && temp<=0){
			if(minusMax<temp){
				minusMax=temp;
			}
			continue;
		}
		
		if(((a[index]<0)!=(temp<0))){
			index++;
		}
		a[index]+=temp;
	}
	if(index==0 && a[index]==0){
		a[index]=minusMax;
	}else if(a[index]<0){
		index--;
	}
	return index+1;
}

int doubleShift(int a[],int num,int length){
	for(;num+2<length;num++){
		a[num]=a[num+2];
	}
	
	return 0;
}

int optimize(int a[],int num){
	int index;
	int i;
	index=num;
	for(i=num-2;i>=1;i-=2){
/*		printf("(%d>%d && %d<%d)\n",a[i-1],abs(a[i]),abs(a[i]),a[i+1]);
*/		if(a[i-1]>abs(a[i]) && abs(a[i])<a[i+1]){
/*			printf("yes!\n");
*/			a[i-1]+=a[i]+a[i+1];
			doubleShift(a,i,index);
			index-=2;
		}
	}
	return index;
}

int sumf(int a[],int x,int y){
	int i;
	int sum=0;
	for(i=x;i<=y;i++){
		sum+=a[i];
	}
	
	return sum;
}

int serchMax(int a[],int num){
	int i,j;
	int max=-100001,temp;
	for(i=0;i<=num;i+=2){
		for(j=i;j<=num;j+=2){
			temp=sumf(a,i,j);
			if(max<temp){
				max=temp;
			}
		}
	}
	
	return max;
}

int main(){
	int data[5000]={0,};
	int num,dataLength;
	int i,temp;
	while(1){
		scanf("%d",&num);
		if(num==0){
			break;
		}
/*		printf("-[%d]----------\n",num);
*/		initialize(data,num);
		dataLength=scan(data,num);

/*		for(i=0;i<dataLength;i++){
			printf("%d\n",data[i]);
		}
*/		
		while(1){
			temp=optimize(data,dataLength);
			if(dataLength==temp){
				break;
			}
			dataLength=temp;
		}
		
		
		printf("%d\n",serchMax(data,dataLength));
		
	}
	
	return 0;
}

Measured memory_bytes: 432
def cc081():
    import sys
    from collections import Counter

    n,k = list(map(int, input().split()))
    an = list(map(int, input().split()))

    dan = Counter(an)

    l = len(dan)
    if l <= k:
        print(0)
        sys.exit()

    l -= k
    cnt = 0
    for ke,va in dan.most_common()[::-1]:
        cnt += va
        l -= 1
        if l <= 0:
            break

    print(cnt)

cc081()



Measured memory_bytes: 39344
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace std;
using namespace __gnu_pbds; 
#define     mod             1e9+7
#define     MOD             998244353
#define     ll              long long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     t()             int test;cin>>test;while(test--)
#define     setbits(x)      __builtin_popcountll(x)
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif



int32_t main()
 
{  
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS;
   //t()
   {
      int a[5];
      int i, ans=0;

      for(int i=0; i<5; i++)
      {
        cin>>a[i];
        if(!a[i])ans=i+1;
      }
      cout<<ans<<endl;
   }
    
}

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

#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

ll n, m, r;
ll dist[222][222];
ll town[10];

ll ans = LINF;
bool used[222] = {};

void dfs(ll pos, ll path_dist, ll depth){
    if(depth == r){
        ans = min(ans, path_dist);
    }

    rep(i, r)if(!used[town[i]]){
        used[town[i]] = true;
        dfs(town[i], path_dist+dist[pos][town[i]], depth+1);
        used[town[i]] = false;
    }
}

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

    rep(i, r){
        cin >> town[i];
        town[i]--;
    }

    //最短距離テーブルの初期化
    rep(i, n)rep(j, n)dist[i][j] = LINF;

    rep(i, m){
        ll a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        dist[a][b] = dist[b][a] = min(dist[a][b], c);
    }

    //ワーシャルフロイド法で各組の最短距離を更新
    rep(k, n){//中間点
        rep(i, n){//始点
            rep(j, n){//終点
                dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
            }
        }
    }

    rep(i, r){
        used[town[i]] = true;
        dfs(town[i], 0, 1);
        used[town[i]] = false;
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
N = int(input())
T = list(map(int,input().split()))
A = list(map(int,input().split()))
A.append(1)
count = 0
Tmax = 1
Amax = 1
T2 = [0] * N
A2 = [0] * N
ans = 1

for i in range(N):
    if T[i] > Tmax and A[i] > A[i+1] and T[i] != A[i]:
        ans = 0
        break
    elif T[i] > Tmax and A[i] == A[i+1] and T[i] > A[i]:
        ans = 0
        break
    elif A[i] > A[i+1] and T[i] == Tmax and A[i] > T[i]:
        ans = 0
        break
    elif T[i] > Tmax and A[i] > A[i+1] and T[i] == A[i]:
        count = 1
        Tmax = T[i]
        Amax = A[i+1]
    elif T[i] > Tmax and A[i] == A[i+1] and T[i] <= A[i]:
        count = 1
        Tmax = T[i]
    elif A[i] > A[i+1] and T[i] == Tmax and A[i] <= Tmax:
        count = 1
        Amax = A[i+1]
    else:
        count = min(A[i],T[i])
    ans *= count
    ans = ans % (10**9+7)
print(ans)


Measured memory_bytes: 19136
import collections
S = list(input())
T = list(input())
 
cntS = collections.Counter(S)
cntT = collections.Counter(T)
 
if len(cntS) != len(cntT):
    print('No')
    exit()
else:
    valS = list(cntS.values())
    valT = list(cntT.values())

    if valS != valT:
            print('No')
            exit()
print('Yes')

Measured memory_bytes: 12544
#include<iostream>
using namespace std;
int main()
{
    int a;
    int b;
    cin >> a >> b;
    if(a==b)
    {
        cout << "Yes" << endl;
        return 0;
    }
    if(a%500 == 0)
    {
        cout << "Yes" << endl;
        return 0;
    }
    if(a<500 && a > b)
    {
        cout << "No" << endl;
        return 0;
    }
    for(int i=0; i<10000; i++)
    {
        a = a-500;
        if(a < 500)
        {
            break;
        }
    }
    if(a <= b)
    {
        cout << "Yes" << endl;
        return 0;
    }
    if(a >= b)
    {
        cout << "No" << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define rand rng
using namespace std; void solve();
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;

struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
  int main(){solve_dbg();}
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif

using P = pair<int,int>; using vp = vector<P>;
constexpr int MOD = 998244853;
mt19937_64 rng(58);
/////////
#define PI 3.1415926535897932384626
double dotp(double x,double y,double xx,double yy){
  return x * xx + y * yy;
}
void solve(){
  ini(N);
  vp v(N); in(v);
  double ans = 0;
  for(double theta = 0.0; theta < 2.0*PI; theta += 2.0*PI/5e5){
    const double x = cos(theta) , y = sin(theta);
    double cx = 0 , cy = 0;
    rep(i , N){
      if(dotp(v[i].fi,v[i].se,x,y) > 0) cx+=v[i].fi, cy+=v[i].se;
    }  
    ans = max(ans , sqrt(cx * cx + cy * cy));
  }
  out(ans);
}

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


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int N = S.size();
  vector<string> split;
  int endIndex = 0;
  pair<int, int> RL;

  vector<int> ans(N);

  for( int i = 0; i < N-1; ++i){
    if( S[i] == 'R' && S[i+1] == 'L'){
      RL.first = i;
      RL.second = i+1;
    }
    if(S[i] == 'L' && S[i+1] == 'R'){
      int subSize = i + 1 - endIndex;
      if( subSize%2 == 0){
        ans[RL.first] = ans[RL.second] = subSize/2;
      }else{
        ans[RL.first] = ans[RL.second] = subSize/2;
        if( (RL.first - endIndex)%2 == 0){
          ++ans[RL.first]; 
        }else{
          ++ans[RL.second];
        }
      }
      endIndex = i+1;
    }
  }
  
  int subSize = N - endIndex;
  if( subSize%2 == 0){
    ans[RL.first] = ans[RL.second] = subSize/2;
  }else{
    ans[RL.first] = ans[RL.second] = subSize/2;
    if( (RL.first - endIndex)%2 == 0){
      ++ans[RL.first]; 
    }else{
      ++ans[RL.second];
    }
  }
  
  for( int i = 0; i < N; ++i){
    cout << ans[i] << " ";
  }
  cout << "\n";
}

Measured memory_bytes: 1104
#include <bits/stdc++.h>
// https://www.irohabook.com/exp-2
// 1e9（10桁） は 2^26乗～2^27乗 であり、int(正負の2^16乗まで)では不可

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

string S, T;

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

	int minCnt = 100000; //  変更回数が最小のもの

	// 3文字ならば 6-3+1=4で0,1,2,3の４回必要になる
	// cab aba bac acc
	for (int i = 0; i < S.length() - T.length() + 1;i++) {
		
		int cnt = 0;

		for (int j = 0; j < T.length();j++) {
			// 対象の文字が違う場合変化用のカウントを追加
			if (S[i+j] != T[j] ) {
				cnt++;
			}
		}

		minCnt = min(minCnt,cnt);
	}

	cout << minCnt << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define maxn 100005
int x[maxn];
int flg[maxn];
long long int tot[maxn];
int main(){
    int n , a, b;
    long long int k;
    memset(flg,0,sizeof(flg));
    memset(tot, 0, sizeof(tot));
    cin >> n>> k;
    for(int i = 0; i<n; i++)
    {
        scanf("%d %d", &a, &b);
        tot[a]+=b;
        if(!flg[a]) x[i] = a;
        else x[i] = 0;
        flg[a] = 1;
    }
    sort(x, x+n);
    long long int sum = 0;
    for(int i = 0; i<n; i++){
        sum += tot[x[i]];
        if(sum >= k)
            return !printf("%d\n", x[i]);
    }
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int ll;
ll gcd(ll a, ll b){
    if(a==0) return b;
    if(b==0) return a;
    if(a < b){
        return gcd(b, a);
    }else{
        if(a%b == 0){
            return b;
        }else{
            return gcd(b, a%b);
        }
    }
}

int main() {
    ll b, c, d, n, m, p, i, j;
    ll ans = 0;
    cin >> n;
    ll a[n+1];
    a[0] = 0;
    ll l1[n+1];
    ll l2[n+1];
    l1[0] = 0;
    l2[0] = 0;
    l1[n+1] = 0;
    l2[n+1] = 0;
    for(i=1;i<n+1;i++) {
        cin >> b;
        a[i] = b;
    }
    for(i=1;i<n+1;i++) {
        l1[i] = gcd(l1[i-1], a[i]);
    }
    for(i=n;i>0;i--) {
        l2[i] = gcd(l2[i+1], a[i]);
    }
    for(i=1;i<n+1;i++) {
        m = gcd(l1[i-1], l2[i+1]);
        if (ans < m) ans = m;
    }
    //for(j=0;j<n+2;j++) {
    //    cout << l2[j] << ' ';
    //}
    //cout << endl;
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
using namespace std;
int n;
double p[3000];
double dp[3000][3000];


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

    dp[0][0] = 1.0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            dp[i+1][j+1] += dp[i][j] * p[i];
            dp[i+1][j] += dp[i][j] * (1.0-p[i]);
        }
    }

    double ans = 0.0;
    for (int i = (n+1)/2; i <= n; i++) ans += dp[n][i];
    cout << setprecision(10) << ans << endl;
}

Measured memory_bytes: 68864
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

class Dice {
    int top;
    int bottom;
    int left;
    int right;
    int front;
    int back;

    static Dice of (int[] init) {
        Dice d = new Dice();
        d.top = init[0];
        d.bottom = init[5];
        d.left = init[3];
        d.right = init[2];
        d.front = init[1];
        d.back = init[4];
        return d;
    }

    static Dice of (Dice copy) {
        Dice d = new Dice();
        d.top = copy.top;
        d.bottom = copy.bottom;
        d.left = copy.left;
        d.right = copy.right;
        d.front = copy.front;
        d.back = copy.back;
        return d;
    }

    void E () {
        Dice copy = Dice.of(this);
        top = copy.left;
        bottom = copy.right;
        left = copy.bottom;
        right = copy.top;
    }

    void N () {
        Dice c = Dice.of(this);
        top = c.front;
        bottom = c.back;
        front = c.bottom;
        back = c.top;
    }

    void S () {
        Dice c = Dice.of(this);
        top = c.back;
        bottom = c.front;
        front = c.top;
        back = c.bottom;
    }

    void W () {
        Dice c = Dice.of(this);
        top = c.right;
        bottom = c.left;
        left = c.top;
        right = c.bottom;
    }
}

public class Main {
    public static void main(String[] args) {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))){
            int[] arr = Arrays.stream(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
            Dice dice = Dice.of(arr);

            String[] orders = in.readLine().split("");
            for (int i = 0; i < orders.length; i++) {
                switch (orders[i]) {
                    case "E":
                        dice.E();
                        break;
                    case "N":
                        dice.N();
                        break;
                    case "S":
                        dice.S();
                        break;
                    case "W":
                        dice.W();
                        break;
                }
            }

            System.out.println(dice.top);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}



Measured memory_bytes: 31084
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static int[][] map;
	static int[][] directions8= {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
	static int[][] directions4= {{-1,0},{1,0},{0,-1},{0,1}};
	static int ans;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		while(true) {

			int n = sc.nextInt();
			int m = sc.nextInt();

			if((n|m)==0) {
				break;
			}
			int[] taro = new int[n];
			int taroSum = 0;
			int[] hana = new int[m];
			int hanaSum =0;

			for(int i = 0; i < n; i++) {
				taro[i] = sc.nextInt();
				taroSum+=taro[i];
			}
			for(int i = 0; i < m; i++) {
				hana[i] = sc.nextInt();
				hanaSum +=hana[i];
			}

			int k = hanaSum - taroSum;
			boolean ok = false;

			int tAns =0;
			int hAns=0;

			if(k%2 == 0) {

				Arrays.sort(taro);

				for(int i = 0; i < n && ! ok; i++) {
					for(int j = 0; j < m && !ok; j++) {
						if(taro[i] + k/2 == hana[j]) {
							tAns =taro[i];
							hAns = hana[j];
							ok = true;
						}
					}
				}
			}
			if(ok) {
				System.out.println(tAns+" "+hAns);
			}else {
				System.out.println(-1);
			}
		}
	}

	//BFS用に二つの配列を足し算する
	static int[] addArrayElms(int[] a, int[] b) {
		int[] c = new int[a.length];
		for(int i = 0; i < a.length; i++) {
			c[i] = a[i] + b[i];
		}
		return c;
	}

	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray){
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedArray[mid]<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList){
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedList.get(mid)<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
		return b == 0 ? a: gcd(b, a % b);
	}
	public static long gcd(long a, long b) {
		return b == 0 ? a: gcd(b, a % b);
	}
}



Measured memory_bytes: 29112
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <set>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef long long LL;
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IFOR(v,it) for(VI::iterator it=(v).begin();it!=(v).end();++it)
#define IN(v) cin>>(v)


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

  int before1, before2;
  IN(before1);
  IN(before2);
  int count = 0;
  REP(i, N-2) {
    int p;
    cin >> p;
    if (before1 > before2 && before2 > p || before1 < before2 && before2 < p)
      ++count;
    before1 = before2;
    before2 = p;
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

static int plus(int a, int b);
static int minus(int a, int b);
static int multiply(int a, int b);
static void disp_max(int a, int b);
int main(void){
  int a = 0, b = 0;
  scanf("%d", &a);
  scanf("%d", &b);
  disp_max(a, b);

  return 0;
}

static int plus(int a, int b){
  return a+b;
}
static int minus(int a, int b){
  return a-b;
}
static int multiply(int a, int b){
  return a*b;
}
static void disp_max(int a, int b){
  int x, y, z;
  int result = 0;
  x = plus(a, b);
  y = minus(a, b);
  z = multiply(a, b);
  if(x > y){
    result = x;
  } else {
    result = y;
  }
  if(z > result){
    result = z;
  } else {}

  printf("%d", result);
}

Measured memory_bytes: 128
#include <stdio.h>

int main () {

    int i, j, n, num, c, p;
    int a[100][100];

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            a[i][j] = 0;
        }
    }

    for (i = 0; i < n; i++) {
        scanf("%d", &num); scanf("%d", &c);
        for (j = 0; j < c; j++) {
            scanf("%d", &p);
            a[num - 1][p - 1] = 1;
        }
    }

    for (i = 0; i < n; i++) {
        for (j = 0; j < n - 1; j++) {
            printf("%d ", a[i][j]);
        }
        printf("%d", a[i][n - 1]);
        puts("");
    }

    return 0;

}


Measured memory_bytes: 2140
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector< vector<int> >
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

const double EPS = 1e-10;
#define equals(a, b) (fabs((a) - (b)) < EPS)

struct Point{
    double x, y;
    Point(){}
    Point(double x0, double y0){
        x = x0; y = y0;
    }

    Point operator +(const Point &p){
        return Point(x + p.x, y + p.y);
    }
    Point operator -(const Point &p){
        return Point(x - p.x, y - p.y);
    }
    Point operator *(const double &a){
        return Point(a * x, a * y);
    }
    Point operator /(const double &a){
        return Point(x / a, y / a);
    }

    bool operator == (const Point &p){
        return equals(x, p.x) && equals(y, p.y);
    }

    bool operator < (const Point &p){
        return x != p.x ? x < p.x : y < p.y ;
    }

};

double norm(Point p){
    return p.x * p.x + p.y * p.y;
}

double v_abs(Point p){
    return sqrt(norm(p));
}

typedef Point Vector;

double dot(Vector a, Vector b){
    return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b){
    return a.x * b.y - a.y * b.x;
}

struct Circle{
    Point c;
    double r;
    Circle(){}
    Circle(Point c0, double r0){
        c.x = c0.x;
        c.y = c0.y;
        r = r0;
    }
    Circle(double x0, double y0, double r0){
        c.x = x0;
        c.y = y0;
        r = r0;
    }
};


int main(){
    int Q;
    cin >> Q;
    rep(i, Q){
        Point p0, p1, p2, p3;
        cin >> p0.x >> p0.y;
        cin >> p1.x >> p1.y;
        cin >> p2.x >> p2.y;
        cin >> p3.x >> p3.y;

        Vector base = p1 - p0, a = p2 - p0, b = p3 - p0;
        // double s = abs(cross(base, a))/v_abs(base) , t = abs(cross(base, b))/v_abs(base);
        double s = abs(cross(base, a)), t = abs(cross(base, b));
        Point ans = p2 * (t / (s + t)) + p3 * (s / (s + t));
        printf("%.10lf %.10lf\n", ans.x, ans.y);
    }
}


Measured memory_bytes: 3288
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < (n); ++i)

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

using namespace std;

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

    char temp = s[0];
    for (int i = 1; i < s.size(); ++i) {
        if (temp != s[i]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define llong long long
#define pb(a) push_back(a)
#define INF 9999999

using namespace std;

typedef pair<int,int> P;

int dy[4]={0,0,1,-1};
int dx[4]={1,-1,0,0};
int main(){
	char x[100];
	int n;
	string ans="Three";
	cin>>n;
	REP(i,n)cin>>x[i];
	REP(i,n)if(x[i]=='Y')ans="Four";
	cout<<ans<<endl;
}


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

#define MAX(p,q) ((p>q)?(p):(q))
#define MIN(p,q) ((p<q)?(p):(q))

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

int main(void)
{
  int k;
  scanf("%d",&k);
  if(k%2==0) printf("%d",k*k/4);
  else printf("%d",(k-1)/2*((k-1)/2+1));
  return 0;
}


Measured memory_bytes: 128
member = int(input())
day,remainder = map(int,input().split())
eatrate = []
for i in range(member):
    eatrate.append(int(input()))
l = []
temp = list(range(day))
for r in eatrate:
    l.append(temp[::r])
print(sum([len(i) for i in l]) + remainder)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define MAX 1e18
#define MIN -1e18
#define MOD 1000000007
//#define mod2 20071027
//#define MOD 998244353
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a) for(int i=1;i<=a;i++)
#define base 139
//#define mod 1000074259
#define base2 31
#define memz(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define in1(a) scanf("%lld", &a)
#define in2(a, b) scanf("%lld%lld", &a, &b)
#define TC(c) printf("Case #%lld: ", ++c)
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
const ll N=300010,M=1000010;
string s;

int main()
{
    cin>>s;
    for(auto u:s)
        if(u=='7')
    {
        printf("Yes\n"); return 0;
    }
    printf("No\n");
    return 0;
}

/*

*/


Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    vector<string> a;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        a.push_back(s);
    }
    sort(a.begin(),a.end());
    long long int ans=1;
    for(int i=1;i<n;i++)
    {
        if(a[i]!=a[i-1])
        ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 9160
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  string s;
  cin>>s;
  int ret = 0;
  string nova = "";
  int last_ind=0;
  vector<string>names(202020);
  names[0]="aa";
  for(int i=0;i<s.length();i++){
  	nova+=s[i];
  	if(nova!=names[last_ind]){
  		last_ind++;
  		names[last_ind]=nova;
  		nova="";
  		ret++;
  	}
  }
  cout<<ret<<endl;
}








Measured memory_bytes: 11028
fun main(args: Array<String>) {
    val (h, w, k) = readLine()!!.split(' ').map(String::toInt)
    val map = Array(h) { CharArray(w) { '.' } }
    (0 until h).forEach { map[it] = readLine()!!.toCharArray() }
    val ansMap = Array(h) { IntArray(w) { 0 } }
    val sList = mutableListOf<Pair<Int, Int>>()
    for (th in 0 until h) {
        for (tw in 0 until w) {
            if (map[th][tw] == '#') sList.add(Pair(th, tw))
        }
    }
    var ansNum = 1
    for (s in sList) {
        val (sh, sw) = s
        ansMap[sh][sw] = ansNum
        var tw = sw
        while (true) {
            tw--
            if (tw < 0 || map[sh][tw] == '#') break
            ansMap[sh][tw] = ansNum
        }
        tw = sw
        while (true) {
            tw++
            if (tw >= w || map[sh][tw] == '#' ||ansMap[sh][tw]!=0) break
            ansMap[sh][tw] = ansNum
        }
        ansNum++
    }

    for (th in 1 until h) {
        for (tw in 0 until w) {
            if (ansMap[th][tw] == 0) ansMap[th][tw] = ansMap[th - 1][tw]
        }
    }

    for (th in (h-2) downTo 0) {
        for (tw in 0 until w) {
            if (ansMap[th][tw] == 0) ansMap[th][tw] = ansMap[th + 1][tw]
        }
    }
    ansMap.forEach {
        println(it.joinToString(" "))
    }
}

Measured memory_bytes: 52512
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[][] b = new int[N][2];
		for (int i=0;i<N;i++) {
			b[i][0]=sc.nextInt();
		}

		for (int i=0;i<N;i++) {
			if (b[i][0]>i+1) {
				System.out.println(-1);
				break;
			}
			b[i][1]=b[i][0];
			for (int j=0;j<i;j++) {
				if (b[j][1]>=b[i][0]) {
					b[j][1]++;
				}
			}
			if (i==N-1) {
				Arrays.sort(b, (A, B) -> Long.compare(A[1], B[1]));
				for (int k=0;k<N;k++) {
					System.out.println(b[k][0]);
				}
			}
		}
	}
}

Measured memory_bytes: 27988
#include <iostream>
#include <vector>
#include <string>
#include <bits/stdc++.h>
#include <ctime>

#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL)
#define TT int test_cases; cin >> test_cases; while(test_cases--)
#define TT1 int test_cases=1; while(test_cases--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
using namespace std;
typedef long long int ll;

 
int main() {
    
    FAST;
    TT1{
        
        ll n;cin>>n;
        string ans;
        while(n>0)
        {
            int d=n%26;
            if(d==0)
            {
                ans.pb('z');n=n/26;n=n-1;
            }
            else
            {
                char ch1=char('a'+d-1);
                ans.pb(ch1);
                n=n/26;
            }
        }
        
        reverse(ans.begin(),ans.end());
        cout<<ans<<"\n";
    }
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(void){
  double x,y,a,b,c,d,e,f;
  while((scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f))!=EOF){
    x=(f-c*e/b)/(d-a*e/b);
    y=(f-c*d/a)/(e-b*d/a);
    if(x==-0.0000)
      x=0.000;
    if(y==-0.000)
      y=0.000;
    printf("%.3f %.3f\n",x,y);
  }
  return 0;
}

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

Measured memory_bytes: 35736
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >> K;
  int X,Y;
  bool marker = 0;
  int counter;
  counter=0;
  vector<int> dictionary(N);
  
  for(int i = 0; i < K; i++){
    cin >> X;
    for(int j = 0; j < X; j++){
      cin >> Y;
      Y=Y-1;
      marker=0;
      for(int a = 0; a < N; a++){
        if(a==Y){
          dictionary.at(Y)=1;
         
        }
      }
    }
  }
  
  for(int b = 0; b < N; b++){
    if(dictionary.at(b)==1){
    counter=counter+1;
    }
  }
  
  cout << N-counter;
}

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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define long long long
#define db double
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
template <class T> inline void chmin(T &a, const T& val) { if (a > val) a = val; }
template <class T> inline void chmax(T &a, const T& val) { if (a < val) a = val; }
template <class T> long sqr(T a) { return 1ll * a * a; }
template <class T> void compress(T &a){
  sort(all(a)); a.resize(unique(all(a)) - a.begin());  
}

const db pi = acos(-1.00);
const db eps = 1e-6;
const int INF = 1e9;
const int MOD = 1e9+7;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};

const int N = 2e5+1;
int n, k, a[N];

int main()
{
  fastio;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  if ((a[n] <= 0) && (k % 2)){
    long ans = 1;
    for (int i = 1; i <= k; i++){
      ans *= a[n - i + 1];
      ans %= MOD;
    }
    cout << (ans + MOD) % MOD;
    return 0;
  }  
  int cur = 0; int l = 1; int r = n;
  long ans = 1;
  while (cur < k){
    if (cur == k - 1 || 1ll * a[l] * a[l + 1] < 1ll * a[r] * a[r - 1]){
      ans *= a[r]; ans %= MOD;
      r--; cur++;
    }
    else {
      ans *= a[l]; ans %= MOD;
      ans *= a[l + 1]; ans %= MOD;
      l += 2; cur += 2;
    }
  }
  cout << (ans + MOD) % MOD;
  return 0;
}

Measured memory_bytes: 4384
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
N, M = MAP()
AB = [LIST() for _ in range(N)]
 
AB.sort(key = lambda x: (x[0], x[1]))
 
cnt = 0
ans = 0
for i in range(N):
	if cnt+AB[i][1] >= M:
		ans += (M-cnt)*AB[i][0]
		print(ans)
		break
	else:
		cnt += AB[i][1]
		ans += AB[i][0] * AB[i][1]

Measured memory_bytes: 37508
def solve():
    if k==n: return P + M
    if len(M) == n: return sorted(M, reverse=k%2)[:k]

    P.sort(reverse=True)
    M.sort()
    P.append(-1)
    M.append(1) # add endpoint
    pa, ma = [], []
    while len(pa) + len(ma) < k:
        if P[len(pa)] < -M[len(ma)]:
            ma.append(M[len(ma)])
        else:
            pa.append(P[len(pa)])

    if len(ma)%2 == 0: return pa + ma

    exist_pa = len(pa) > 0
    exist_ma = len(ma) > 0
    remain_p = len(P) - 1 > len(pa)
    remain_m = len(M) - 1 > len(ma)
    if exist_pa & exist_ma & remain_p & remain_m:
        if abs(pa[-1] * P[len(pa)]) < abs(ma[-1] * M[len(ma)]):
            pa.pop()
            ma.append(M[len(ma)])
        else:
            ma.pop()
            pa.append(P[len(pa)])
    elif exist_ma & remain_p:
        ma.pop()
        pa.append(P[len(pa)])
    elif exist_pa & remain_m:
        pa.pop()
        ma.append(M[len(ma)])
    return pa + ma

n, k = map(int, input().split())
P, M = [], [] # plus, minus
for a in map(int, input().split()):
    if a < 0: M.append(a)
    else: P.append(a)
ans, MOD = 1, 10**9 + 7
for a in solve(): ans *= a; ans %= MOD
ans += MOD; ans %= MOD
print(ans)


Measured memory_bytes: 32132
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <bitset>
#define ll long long
#define rep(x,n) for(ll (x)=0;(x)<n;(x)++)
#define rep1(x,n) for(ll (x)=1;(x)<=n;(x)++)
using namespace std;

const ll N=200002;

struct node
{
    int id,pa1,pa2;
    node(int _id=0,int _pa1=0,int _pa2=0)
    {
        id=_id;pa1=_pa1;pa2=_pa2;
    }
    bool operator < (const node b) const
    {
        return pa1<b.pa1;
    }
};

int n,pa1[N],pa2[N],ans[N]={0};
vector<node> S[N];

int fpa1(int x)
{
    return pa1[x]==x?x:pa1[x]=fpa1(pa1[x]);
}

int fpa2(int x)
{
    return pa2[x]==x?x:pa2[x]=fpa2(pa2[x]);
}

int main()
{
    #ifdef LOCAL
        freopen("C_data","r",stdin);
    #endif
    int k,l,a,b;
    scanf("%d%d%d",&n,&k,&l);
    rep1(i,n) pa1[i]=i,pa2[i]=i;
    while(k--)
    {
        scanf("%d%d",&a,&b);
        if(fpa1(b)!=fpa1(a))
            pa1[fpa1(b)]=fpa1(a);
    }
    while(l--)
    {
        scanf("%d%d",&a,&b);
        if(fpa2(b)!=fpa2(a))
            pa2[fpa2(b)]=fpa2(a);
    }
    rep1(i,n)
    {
        S[fpa2(i)].push_back(node(i,fpa1(i),fpa2(i)));
    }
    rep1(i,n)
    {
        sort(S[i].begin(),S[i].end());
        int st=0;
        while(st<S[i].size())
        {
            int t=st,cnt=1;
            while(t+1<S[i].size() && S[i][t+1].pa1==S[i][t].pa1) t++,cnt++;
            for(int j=st;j<=t;j++)
            {
                ans[S[i][j].id]=cnt;
            }
            st=t+1;
        }
    }
    rep1(i,n) cout<<ans[i]<<' ';
    cout<<endl;
    return 0;
}


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

int main() {
    ll x,y;
    std::cin >> x>>y;
    
    for (int i = 0; i <= x; i++) {
        int j = x-i;
        if(i*2+j*4==y){
            std::cout << "Yes" << std::endl;
            return 0;
        }
    }
    std::cout << "No" << std::endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<pair<string, long>> data(N);
  for(int i = 0; i < N; i++){
    cin >> data.at(i).first >> data.at(i).second;
  }
  string X;
  cin >> X;
  long ans = 0, flag = 0;
  for(int i = 0; i < N; i++){
    if(flag == 1)ans += data.at(i).second;
    if(data.at(i).first == X)flag = 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
// D - Coloring Edges on Tree
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	vector<vector<int>> tree(N);
	int C[N-1];
	rp(i, 0, N-1){
		int p; scanf("%d%d", &p, C+i); p--,C[i]--;
		tree[p].push_back(C[i]);
		tree[C[i]].push_back(p);
	}

	int K = 0;
	int colors[N], visited[N]; rp(i, 0, N) colors[i] = visited[i] = 0;

	queue<int> q;
	q.push(0);
	visited[0] = true;
	while(!q.empty()){
		int p = q.front(); q.pop();
		int color = 1;
		for(auto c:tree[p]){
			if(visited[c]) continue;
			q.push(c);
			visited[c] = true;
			colors[c] = color==colors[p]? ++color: color;
			K = max(K, color++);
		}
	}

	printf("%d\n", K);
	for(int c:C) printf("%d\n", colors[c]);
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    long long sum=0;
    cin>>n;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            for(int k=1; k<=n; k++){
                sum+=gcd(gcd(i,j),k);
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll x = 0;
  vector<ll> a(5);
  for (ll i = 0; i < 5; ++i) {
    cin >> a[i];
  }
  ll k;
  cin >> k;

  if (a[4]-a[0] > k) cout << ":(" << endl;
  else cout << "Yay!" << endl;

  return 0;
}

Measured memory_bytes: 256
def dfs(i,sumnum,sums):
    global ans
    if i == 4:
        if sumnum == 7:
            ans = sums + "=7"
    else:
        dfs(i+1,sumnum + int(s[i]),sums + "+" + s[i])
        dfs(i+1,sumnum - int(s[i]),sums + "-" + s[i])
s = input()
ans = ""
dfs(1,int(s[0]),s[0])
print(ans)

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



int coins(int A, int B, int C, int X){
	
	if(X == 0)
		return 1;
	int use_500 = 0, use_100 = 0, use_50 = 0;
	for(int i = 1; X - 500*i >=0 && i<=A; i++){
		use_500 += coins(0,B,C,X-500*i); 
	}
	for(int i = 1; X - 100*i >=0 && i<=B; i++){
		use_100 += coins(0,0,C,X-100*i); 
	}
	for(int i = 1; X - 50*i >=0 && i<=C; i++){
		use_50 += coins(0,0,0,X-50*i); 
	}
	
	return use_500+use_100+use_50;
}



int main(){
	int A, B, C, X;
	
	cin>> A >> B >> C >> X;
	
	
	
	cout<< coins(A,B,C,X) <<"\n";
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n,m;
  while(1){
    cin>>n;
    if(n==0)break;
    cin>>m;
    string s;
    cin>>s;
    string tmp="I";
    rep(i,n)
      tmp+="OI";
    n=2*n+1;
    int ans=0;
    rep(i,s.size()-n)
      if(s.substr(i,n)==tmp)ans++;
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3900
#include<bits/stdc++.h>
#define myp pair<int,int>
#define myq queue<myp>
#define ll long long
using namespace std;
const int N=5010,M=210;
int n,m,maxp,pow2[16];
int d[N][M];
ll dis[N],a[N][N],ans=0;
myp st[N<<1][16];
myp que(int l,int r){
	int p=log2(r-l+1);
	return st[l][p].first>st[r-pow2[p]+1][p].first?st[l][p]:st[r-pow2[p]+1][p];
}
//void fill(int l,int r,int k){
//	if(l>r||l<=0||r>n) return;
//	myp temp=que(l,r,k);
//	int tempk=temp.second;
//	a[l][tempk]+=temp.first,a[tempk+1][tempk]-=temp.first,a[l][r+1]-=temp.first,a[tempk+1][r+1]+=temp.first;
//	fill(l,tempk-1,k);fill(tempk+1,r,k);
//	return;
//}
void fill(){
	myq q;
	q.push(myp(1,n));
	myp x,temp;
	int tempk,l,r;
	while(!q.empty()){
		x=q.front();q.pop();
		l=x.first,r=x.second;
		if(l>r||l<=0||r>n) continue;
		temp=que(l,r);
		tempk=temp.second;
		a[l][tempk]+=temp.first,a[tempk+1][tempk]-=temp.first,a[l][r+1]-=temp.first,a[tempk+1][r+1]+=temp.first;
		q.push(myp(l,tempk-1));q.push(myp(tempk+1,r));
	}
	return;
}
int main(){
//	freopen("in.txt","r",stdin);
	scanf("%d%d",&n,&m);
	maxp=log2(n)+1;
	pow2[0]=1;
	for(int i=1;i<=maxp;i++) pow2[i]=2*pow2[i-1];
	for(int i=2;i<=n;i++) scanf("%lld",&dis[i]);
	for(int i=2;i<=n;i++) dis[i]+=dis[i-1];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++) scanf("%d",&d[i][j]);
	for(int i=1;i<=m;i++){
		for(int k=1;k<=n;k++) st[k][0]=make_pair(d[k][i],k);
		for(int j=1;j<=maxp;j++)
			for(int k=1;k<=n;k++){
				if(st[k][j-1].first>=st[k+pow2[j-1]][j-1].first)st[k][j]=st[k][j-1];
				else st[k][j]=st[k+pow2[j-1]][j-1];
			}
		fill();
	}
//	for(int i=1;i<=n;i++){
//		for(int j=1;j<=n;j++) cout<<a[i][j]<<" ";
//		cout<<endl;
//	}
//	cout<<endl;
	for(int i=1;i<=n;i++)
		for(int j=2;j<=n;j++) a[i][j]+=a[i][j-1];
	for(int j=1;j<=n;j++)
		for(int i=2;i<=n;i++) a[i][j]+=a[i-1][j];
//	for(int i=1;i<=n;i++){
//		for(int j=1;j<=n;j++) cout<<a[i][j]<<" ";
//		cout<<endl;
//	}
	for(int i=1;i<=n;i++)
		for(int j=i;j<=n;j++)
			ans=max(ans,a[i][j]-dis[j]+dis[i]); // !
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 201088
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
using ll = long long;
const ll M = 1000000007;
const ll infi = 1000000000000000;
const ll md = 998244353;
using namespace std;
using vl = vector<ll>;
using pll =  pair<ll,ll>;

ll power(ll x,ll y){
    if(y==0)
    return 1;
    ll res=power(x,y/2);
    res=(res*res)%M;
    if(y&(ll)1)
    res=(res*x)%M;
    return res;
}
//ll temp[100001];
void solve(){
    int n;cin>>n;int a,f=1;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        if(a%2==0&&a%3!=0&&a%5!=0)
        {
            f=0;
        }
    }
    if(f==1)
    cout<<"APPROVED";
    else
    cout<<"DENIED";
    cout<<endl;
}
 
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // temp[0]=0;
    // for(int i=1;i<100001;i++)
    // {
    //     temp[i]=i/2+i%2;
    //     temp[i]=(temp[i]+temp[i-1])%M;
    // }
    // int t;
    // cin>>t;
    // while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 256
k, n = map(int, input().split())
a = list(map(int, input().split()))

dis = 0
for i in range(len(a)-1):
    if dis < a[i+1]-a[i]:
        dis = a[i+1]-a[i]

if dis < a[0]+k-a[len(a)-1]:
    dis = a[0] + k-a[len(a)-1]

print(k-dis)


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n;
	cin >> n;
	long long h, mx = 0;
	cin >> h;
	vector<int> b(n);
	for(int i = 0; i < n; i++) {
		int a;
		cin >> a >> b[i];
		mx = max(1LL * a, mx);
	}
	sort(b.rbegin(), b.rend());
	long long sum = 0;
	int cnt = 0;
	for(int i = 0; i < n; i++) {
		if(b[i] < mx) {
			break;
		}
		sum += b[i];
		cnt++;
		if(sum >= h) {
			cout << cnt << endl;
			return 0;
		}
	}
	cout << cnt + (h - sum + mx - 1) / mx << endl;
	return 0;	
}


Measured memory_bytes: 640
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int k = Integer.parseInt(sc.next());
    k = Math.min(n,k);
    int x = Integer.parseInt(sc.next());
    int y = Integer.parseInt(sc.next());
    System.out.println(k * x + (n-k) * y);
  }
}

Measured memory_bytes: 22996
N, A, B = map(int,input().split())
 
def sum_digit(num):
    sum = 0
    while num > 0:
        sum += num % 10
        num //= 10
    return sum
 
answer = 0
for i in range(1,N+1):
    if A <= sum_digit(i) <= B:
        answer += i
print(answer)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
vector<string> a(100);
vector<int> alp(26, 0);

void fun_1(int d, int m, bool& ff){
    if(m == 0)  return;
    int id = 0;
    for(int i = 0;i < 26;i++){
        while(alp[i] >= d){
            alp[i] -= d;
            if(++id == m) return;
        }
        if(i == 25) ff = false;
    }
}
int main(){
    int H, W;
    cin >> H >> W;
    for(int i = 0;i < H;i++){
        cin >> a[i];
        for(int j = 0;j < W;j++){
            alp[a[i][j]-'a']++;
        }
    }
    bool f = true;
    fun_1(4, (H/2)*(W/2), f);
    if(H&1) fun_1(2, W/2, f);
    if(W&1) fun_1(2, H/2, f);
    if(H&1 && W&1)  fun_1(1, 1, f);
    if(f)   cout << "Yes" << endl;
    else    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int a[100002],m,n;
  long long b[100002], mx=-1;
  a[0]=0;
  a[100001]=0;
  cin>>n>>m;
  for(i=1;i<n+1;i++)
    cin>>a[i];
  for(i=1;i<n+1;i=j){
    for(;i<n+1&&(a[i-1]>a[i]||a[i+1]>a[i]);i++);
    if(i!=n+1){
      b[i]=m-a[i];
      for(j=i-1;j>0;j--){
	if(a[j-1]>a[j]){
	  b[j]=m-a[j]+(b[j-1]>b[j+1]?b[j-1]:b[j+1]);
	  break;
	}else
	  b[j]=m-a[j]+b[j+1];
      }
      for(j=i+1;j<n+1&&a[j-1]>a[j];j++)
	b[j]=m-a[j]+b[j-1];
    }else
      j=i;
  }
  for(i=1;i<n+1;i++){
    if(mx<b[i])
      mx=b[i];
  }
  cout<<mx<<endl;
  return 0;
}

Measured memory_bytes: 1212