akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
    string S;
    getline(cin, S);

    vector<int> modcounts(2019, 0);
    int premod = 0;
    int tensmod = 1;  // 10^0 % 2019
    for (int i = S.length() - 1; i >= 0; i--) {
        int c = S.at(i) - '0';
        int m = (c * tensmod + premod) % 2019;
        modcounts[m]++;
        tensmod = (tensmod * 10) % 2019;
        premod = m;
    }
    int64_t result = 0;
    for (uint m = 0; m < modcounts.size(); m++) {
        if (m == 0 && modcounts[m] >= 1) {
            result += (int64_t)(modcounts[m] + 1) * modcounts[m] / 2;
        } else if (modcounts[m] >= 2) {
            result += (int64_t)modcounts[m] * (modcounts[m] - 1) / 2;
        }
    }
    cout << result << endl;
}


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

int main(){
  int p,q,r;
  cin >> p >> q >> r;
  
  //小さい順に並べ替え
  int tmp[4] = {p,q,r,0};
  for (int i = 0; i < 3; i++){
    if(tmp[i] > tmp[i+1]){
      int n = tmp[i];
      tmp[i] = tmp[i+1];
      tmp[i+1]= n;
    } 
  }
  
  cout << tmp[0] + tmp[1] << endl;
  return 0;
  
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int k = scan.nextInt();
        int x = scan.nextInt();
        scan.close();

        int lower = x - k + 1;
        int upper = x + k - 1;

        for (int i = lower; i <= upper; i++) {
            System.out.print(i);
            if (i != upper) {
                System.out.print(" ");
            }
        }
    }
}


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

int main(){
	string n;
	cin>>n;
	for(int i=0;i<3;i++){
		if(n.at(i)=='1'){
			n.at(i)='9';
		}
		else{
			n.at(i)='1';
		}
	}
	cout<<n;
}


Measured memory_bytes: 256
import math


N, M = map(int, input().split())
S = input()
T = input()

if N>M:
    N,M = M,N
    S,T = T,S
    
def gcd(a, b):
    while b:
	    a, b = b, a % b
    return a
    
L = int(M*N/gcd(N, M))

for i in range(N):
    if (M*i)%N == 0:
        j = int((M*i)/N)
        if S[i] != T[j]:
            print(-1)
            exit(0)

print(L)

        


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

signed main(){
	const double PI = acos(-1);
	double A, B;
	double H, M;
	scanf("%lf%lf", &A, &B);
	scanf("%lf%lf", &H, &M);
	double x = (H * 360 / 12 + M * 360 / 12 / 60) * PI / 180;
	double y = (M * 360 / 60) * PI / 180;
	printf("%.20lf\n", sqrt(A * A + B * B - 2 * A * B * cos(x - y)));
	return 0;
}

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


int F[1000][1000];

//?????????????????????
void r(int yy,int xx,int z){
 if(F[yy][xx]!=z){
	return ;
 }

F[yy][xx]=10;

r(yy-1,xx,z);
r(yy,xx+1,z);
r(yy+1,xx,z);
r(yy,xx-1,z);

}




int main(){
 int w,h,xs,ys,xg,yg,n;
 int c,d,x,y;

while(1){
 cin>>w>>h;

//?????????????????????0???????????????
 if(w==0&&h==0)break;
//???????????????????????????????????\?????°????±??????£???????????????
 cin>>xs>>ys>>xg>>yg>>n;

//n?????°???????????????????????????
for(int i=0;i<n;i++){
	cin>>c>>d>>x>>y;//?????????????????¨????????±????????????
	if(d==0){
		F[x  ][y]=c;
		F[x+1][y]=c;
 		F[x+2][y]=c;
 		F[x+3][y]=c;
 		F[x  ][y+1]=c;
 		F[x+1][y+1]=c;
 		F[x+2][y+1]=c;
 		F[x+3][y+1]=c;
	}
	if(d==1){
		F[x][y  ]=c;
 		F[x][y+1]=c;
		F[x][y+2]=c;
		F[x][y+3]=c;
 		F[x+1][y  ]=c;
		F[x+1][y+1]=c;
		F[x+1][y+2]=c;
 		F[x+1][y+3]=c;
	}
}

//??\????????????????????????


//??????????????????
r(xs,ys,F[xs][ys]);
//??´???????????????
if(F[xg][yg]==10){
	cout<<"OK"<<endl;
}else{
	cout<<"NG"<<endl;
}
//???????????????????????????
for(int i=1;i<=w;i++){
	for(int g=1;g<=w;g++){
		F[i][g]=6;
	}
}
//?????????????????????
}
return 0;
}





	

Measured memory_bytes: 3396
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

class Rank {
public:
  int I, U, A, P;
  Rank();
  Rank(int I, int U, int A, int P) : I(I), U(U), A(A), P(P) {}

};

bool comp(const Rank &r1, const Rank &r2) {
  if(r1.A != r2.A) return r1.A > r2.A;
  if(r1.P != r2.P) return r1.P < r2.P;
  return r1.I < r2.I;
}

int main() {
  
  int n;
  int ii, uu, aa, pp;
  while(cin >> n && n) {
    vector<Rank> vec;
    for(int i=0; i<n; i++) {
      cin >> ii >> uu >> aa >> pp;
      vec.push_back(Rank(ii, uu, aa, pp));
    }
    sort(vec.begin(), vec.end(), comp);
    
    vector<Rank> res;
    vector<int> UCnt(1001,0);
    
    for(int i=0; i<vec.size(); i++) {
      if(res.size() < 10 && UCnt[vec[i].U] < 3) {
	res.push_back(vec[i]);
      }
      else if(res.size() < 20 && UCnt[vec[i].U] < 2) res.push_back(vec[i]);
      else if(res.size() < 26 && UCnt[vec[i].U] == 0) res.push_back(vec[i]);
      UCnt[vec[i].U] ++;
    }
    
    for(int i=0; i<res.size(); i++) {
      cout << res[i].I << endl;
    }
  }
  
  return 0;
}

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

int main(){
    int A, B;
    cin >> A >> B;
    
    int count = 0;
    int socket = 1;

    if(A == 1){
        count = 0;
        cout << count;
    }

    while(socket < B){
        socket += A - 1;
        count++;
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    int n,k;
    vector<int> value;

    scanf("%d %d", &n, &k);
    for(auto i=0; i<n; ++i){
        int v;
        scanf("%d", &v);
        value.push_back(v);
    }

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

    int sum = 0;
    for(auto i=0; i<k; ++i){
        sum += value[i];
    }

    printf("%d", sum);
}

Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,cnt=0,min;
    scanf("%d",&n);
    int arr[n];
    for(int i=0;i<n;i++)
    scanf("%d",&arr[i]);
     for(int i=0;i<n-1;i++)
       {
         min=i;
         for(int j=i+1;j<n;j++)
         {
             if(arr[j]<arr[min])
             {

                 min=j;
                 //cnt++;
             }
         }
        if(i!=min)
        {swap(arr[min],arr[i]);
         cnt++;
}
         }
 for(int i=0;i<n-1;i++)
    printf("%d ",arr[i]);
printf("%d\n",arr[n-1]);
 printf("%d\n",cnt);
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> v(2*M);
  int count;
  for (int i=0;i<2*M;i++){
    cin >> v.at(i);
  }
  for (int j=0;j<N;j++){
    count =0;
    for (int k=0;k<2*M;k++){
      if(j+1==v.at(k))
        count++;
    }
    cout << count << endl;
  }
  
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int v[1<<10];
int dp[100001];

int main() {
  int n,m;
  while(cin>>n>>m,n||m) {
    int a[n];
    REP(i,n) cin >> a[i];
    REP(S,1<<n) {
      int s=0;
      REP(i,n) if (S>>i&1) s+=a[i];
      v[S]=s;
    }
    REP(i,m+1)dp[i]=INF;
    dp[0] = 0;
    for (int S=1; S<(1<<n); ++S) {
      for (int i=0; i+v[S]<=m; ++i)
        dp[i+v[S]] = min(dp[i+v[S]], dp[i]+1);
    }
    cout << dp[m] << endl;
  }
}

Measured memory_bytes: 0
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
#if DEBUG
            ReadLine();
#endif
        }

        void Solve(ConsoleInput cin)
        {
            int s = cin.ReadInt;

            List<int> mem = new List<int>();
            mem.Add(s);

            while (true)
            {
                int pre = mem[mem.Count() - 1];
                int next = -1;

                if (pre == (pre / 2) * 2)
                {
                    next = pre / 2;
                }
                else
                {
                    next = 3 * pre + 1;
                }

                if (mem.Contains(next))
                {
                    break;
                }
                else
                {
                    mem.Add(next);
                }
            }

            Console.WriteLine(mem.Count() + 1);
        }

        class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;

            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }

            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }

            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


Measured memory_bytes: 13396
#include<iostream>
#include<string>

using namespace std;

int main(){
    string str;
    while(cin >> str){
        if(str[0] == '0') break;

        int sum = 0;
        for(int i = 0; i < str.size(); i++){
            sum += str[i] - '0';
        }
        cout << sum << endl;
    }
    return 0;
}

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

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

#define INF 1000000

int main() {


    int n;
    scanf("%d", &n);

    int num;

    int max = -INF;
    int min = INF;
    long long int sum = 0;

    REP(i, n) {
        scanf("%d", &num);
        if(num > max) {
            max = num;
        }
        if(num < min) {
            min = num;
        }
        sum += num;
    }

    printf("%d %d %lld\n", min, max, sum);

    return 0;
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define IOS   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define mp    make_pair
#define pb    push_back
#define F     first
#define pi 	  3.14159265358979323846
#define S     second
#define ll    long long
#define ld    long double
#define sz(s) (ll)s.size() 
#define vl    vector < ll >
#define pll   pair < ll, ll >
#define ml    map < ll, ll >
#define mod   1000000007
#define qe	  998244353
#define MAXN  500005 
#define mx    10000005
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define inv(i,a,b)  for(i=a;i>=b;i--)
#define all(a)  (a).begin(),(a).end()
using namespace std;
ll dis,curr,farthest;
vector<ll>v[MAXN];
bool vis[MAXN];
void dfs(ll s,ll &j){
	vis[s]=true;
	rep(i,0,v[s].size()){
		if(vis[v[s][i]]==false)j++,dfs(v[s][i],j);
	}
}
int main(){
//	#ifndef ONLINE_JUDGE
//    if (fopen("input.txt", "r"))
//    {
//        freopen("input.txt", "r", stdin);
//        freopen("output.txt", "w", stdout);
//    }
//	#endif
	IOS;
	ll t,n,l;
	ll i,j,m,mn,q,d,x,y,ans=0,sum=0,r,p,k,c;
	string s,s1;
	cin>>n>>m;
	rep(i,0,m){
		cin>>x>>y;
		v[x].pb(y);v[y].pb(x);
	}
	farthest=1;
	ans=0;
	vis[MAXN]={false};
	rep(i,1,n+1){
		if(vis[i]==false){
			j=1;
			dfs(i,j);
			ans=max(ans,j);
		}
		
	}
//	cout<<farthest<<endl;
	cout<<ans;
}

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

const ll mod = 1e9+7;

int main() {

    int N;
    cin >> N;
    string s1, s2;
    cin >> s1 >> s2;

    ll ans = 0;

    bool s=false;
    int start=0;
    if (s1[0] == s2[0]) {
        ans = 3LL;
        s = false;
        start=1;
    }
    else {
        ans = 6LL;
        s = true;
        start = 2;
    }

    for (int i=start; i<N; ++i) {
        if (s1[i] == s2[i]) {
            if (!s) ans*=2LL%mod;
            else { s=!s; }
        }
        else {
            if (!s) { s=!s; ans*=2LL%mod; }
            else { ans*=3LL%mod; }
            ++i;
        }
    }

    cout << ans%mod << endl;


}


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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl

using namespace std;
using i64 = long long;

int main()
{
    int x, y, z;
    cin >> x >> y >> z;

    swap(x, y);
    swap(x, z);

    cout << x << " " << y << " " << z << endl;

    return 0;
}

Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
struct BIT { //1-indexed
private:
    int n,n2;
    vector<ll> bit;

public:
    BIT(ll N){
        n = N;
        bit.resize(n+1);
        rep(i,0,n) bit[i+1] = 0;
        n2 = 1;
        while(n2 * 2 <= n) n2 *= 2;
    }

    ll sum(ll i){ // [1, i]
        ll s = 0;
        while(i > 0){
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }

    void add(ll i, ll x){
        if(i == 0) return;
        while(i <= n){
            bit[i] += x;
            i += i & -i;
        }
    }
    ll lower_bound(ll w) {
        if (w <= 0) return 0;
        ll x = 0;
        for (ll k = n2; k > 0; k /= 2) {
            if (x + k <= n && bit[x + k] < w) {
                w -= bit[x + k];
                x += k;
            }
        }
        return x + 1;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll A[100010];
    rep(i,0,N) cin >> A[i];
    ll lv = 0, rv = 1e9+7;
    ll M = N * (N+1) / 2;
    while(rv - lv > 1){
        ll x = (rv + lv) / 2;
        ll B[100010];
        rep(i,0,N){
            if(A[i] >= x){
                B[i] = 1;
            }else{
                B[i] = -1;
            }
        }
        ll S[100010] = {};
        S[0] = 100000;
        rep(i,0,N) S[i+1] = S[i] + B[i];
        BIT bit(200010);
        ll val = 0;
        rep(i,0,N+1){
            val += bit.sum(S[i]);
            bit.add(S[i], 1);
        }
        if(val >= (M+1)/2) {
            lv = x;
        }else{
            rv = x;
        }
    }
    print(lv);
}

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

typedef long long ll;
const int N = 2e3;

int n;
int li[N+5];

ll cari(int l, int r, int tar){
	ll ret = l-1;
	while(l<=r){
		int mid = (l+r)/2;
		if(li[mid] < tar){
			ret = mid;
			l = mid+1;
		} else {
			r = mid-1;
		}
	}
	return ret;
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&li[i]);
	}
	sort(li+1,li+n+1);
	ll tot = 0;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			tot+=cari(j+1,n,li[i]+li[j]) - j;
		}
	}
	printf("%lld\n",tot);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<utility>
#include<iterator>
#include<regex>
#include<math.h>

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(lli i=0;i<j;i++)
#define rep1(i,j) for(lli i=1;i<=j;i++)
#define rep0d(i,j) for(lli i=j-1;i>=0;i--)
#define MAX 1000000007
typedef struct tree Tree;

using namespace std;

bool cmpf(pair<lli, lli> left, pair<lli, lli> right) {
	return left.first < right.first;
}
bool cmp(pair<lli, lli> left, pair<lli, lli> right) {
	if (left.first != right.first)return left.first < right.first;
	else return left.second < right.second;
}
int main() {
	string s, t;
	cin >> s >> t;
	t += t;
	rep0(i, s.size()) {
		if (t.compare(i, s.size(), s) == 0) {
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
}


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

const ll mod = ll(1e9) + 7;
const int INF = 1<<29;
const ll lINF = 1l<<40;

int main(){
    int D;
    cin >> D;
    vecInt c(26);
    rep(i,0,26) cin >> c[i];
    vector<vecInt> s(D,vecInt(26));
    rep(i,0,D) rep(j,0,26) cin >> s[i][j];
    vecInt last(26);
    vecInt ans(D,1);
    rep(i,0,D){
        ll score = -INF;
        rep(j,0,26){
            ll res = s[i][j];
            rep(k,0,26){
                if (k==j) continue;
                res -= c[k] * ((j + 1) - last[k]);
            }
            if (res>score){
                score = res;
                last[j] = i + 1;
                ans[i] = j + 1;
            }
        }
    }
    rep(i,0,D) cout << ans[i] << endl;
    /*
    rep(i,0,D){
        score += s[i][t[i]-1];
        last[t[i]-1] = i + 1;
        rep(j,0,26){
            if (j==t[i]-1) continue;
            score -= c[j] * ((i + 1) - last[j]);
        }
        cout << score << endl;
    }
    */

    return 0;
}

Measured memory_bytes: 3668
while True:
    n = input()
    if n == 0: break
    p = map(int, raw_input().strip().split(" "))
    j = map(int, raw_input().strip().split(" "))
    j.sort(); j.reverse();
    sum = 0; num = n;
    for m in p:
        sum += m
    for i in range(n-1):
        if (num-1)*(sum+j[i]) < num*sum: break
        num-=1; sum+=j[i]
    print num * sum

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

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, m;
    cin >> n >> m;

    int ans = n*(n-1)/2 + m*(m-1)/2;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
n, x, y = STDIN.gets.split.map(&:to_i)

kumi = {}

(1...n).each do |i|
  (i+1..n).each do |j|
    s = [
      (j - i).abs,
      (x - i).abs + 1 + (j - y).abs,
      (y - i).abs + 1 + (j - x).abs
    ].min
    kumi[s] ||= 0
    kumi[s] += 1
  end
end

(n-1).times do |i|
  puts kumi[i+1] || 0
end


Measured memory_bytes: 1916
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] pr = new int[103000];
		for (int i = 0; i < pr.length; i++)
			pr[i] = 1;
		pr[0] = 0;
		pr[1] = 0;
		for (int i = 2; i < Math.sqrt(pr.length); i++)
			if (pr[i] == 1)
				for (int j = i * 2; j < pr.length; j += i)
					pr[j] = 0;
		while (true) {
			int n = sc.nextInt();
			int p = sc.nextInt();
			if (n == -1 && p == -1)
				break;
			Vector<Integer> v = new Vector<Integer>(0);
			int a = n + 1;
			while (v.size() <= p) {
				if (pr[a] == 1)
					v.add(a);
				a++;
			}
			Vector<Integer> r = new Vector<Integer>(0);
			for (int i = 0; i < v.size(); i++)
				for (int j = i; j < v.size(); j++)
					r.add(v.get(i) + v.get(j));
			int[] result = new int[p * (p + 1) / 2];
			for (int i = 0; i < result.length; i++)
				result[i] = r.get(i);
			Arrays.sort(result);
			System.out.println(result[p - 1]);
		}
		sc.close();
	}
}

Measured memory_bytes: 58300
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using Graph = std::vector<std::vector<int>>;
using WGraph = std::vector<std::vector<std::pair<int, long long>>>;
using ll = long long;
using namespace std;
 
int main() {
    int n = 0;
  cin >> n;
  map<long long, int> mp;
  long long tmp = 0;
  for (int i=0; i<n; i++) {
    cin >> tmp;
    mp[tmp]++;
  }
  int m = 0;
  cin >> m;
  for (int i=0; i<m; i++) {
    cin >> tmp;
    mp[tmp]--;
  }
  for (auto iter=mp.begin(); iter!=mp.end(); iter++) {
    if (iter->second < 0) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 12800
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

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

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll n;
    cin >> n;
    vpll red(n), blue(n);
    for(ll i = 0; i < n; i++) {
        cin >> red[i].first >> red[i].second;   // (x, y)
    }
    for(ll i = 0; i < n; i++) {
        cin >> blue[i].second >> blue[i].first; // (y, x)
    }
    sort(red.begin(), red.end(), greater<pll>());
    sort(blue.begin(), blue.end());
    vb selected(n, false);
    ll ans = 0;
    for(ll i = 0; i < n; i++) {
        for(ll j = 0; j < n; j++) {
            if(selected[j]) continue;
            if(red[i].first >= blue[j].second) continue;
            if(red[i].second >= blue[j].first) continue;
            selected[j] = true;
            ans++;
            break;
        }
    }
    cout << ans << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 256
from collections import defaultdict


def main():
    N, x = map(int, input().split())
    a_list = list(map(int, input().split()))

    pre_total = sum(a_list)

    a_list = [min(a, x) for a in a_list]
    for i in range(1, len(a_list)):
        t = a_list[i - 1] + a_list[i]
        a_list[i] -= max(0, t - x)

    print(pre_total - sum(a_list))


if __name__ == '__main__':
    main()


Measured memory_bytes: 14508
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
#define N 100010
//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main(){
    ll x,k,d;
    scanf("%lld%lld%lld",&x,&k,&d);
    ll k1=0;
    if(x>0)
        k1=x/d;
    else if(x<0)
        k1=(-x)/d;
    else
        k1=0;
    if(k<=k1)
    {
        if(x>=0)
            printf("%lld\n",x-k*d);
        else
            printf("%lld\n",-x-k*d);
        return 0;
    }
    if(x>=0)
    {
        if((k-k1)%2==1)
            printf("%lld\n",-x+(k1+1)*d);
        else
            printf("%lld\n",x-k1*d);
    }
    else
    {
        if((k-k1)%2==1)
            printf("%lld\n",x+(k1+1)*d);
        else
            printf("%lld\n",-x-k1*d);
    }
	return 0;
}


Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
int main() {
     int n;
     cin >> n;
     vector<int> p(n);
     for(int i = 0; i < n; i++){
          cin >> p[i];
     }
     int k = 0;
     for(int j = 0; j < n; j++){
          if(p[j] != j+1) k++;
     }
     if(k <= 2) cout << "YES" << endl;
     else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<string>
#include<cctype>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
#define inf 0x3f3f3f3f
const int maxn = 200000 + 8;

int a[maxn];
int n;

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

    int minv = a[0];
    int maxv = -2000000000;
    for(int i = 1; i < n; ++i){
        maxv = max(maxv,a[i] - minv);
        minv = min(minv,a[i]);
    }
    printf("%d\n",maxv);
    return 0;
}

Measured memory_bytes: 3960
A, B, C = map(int,input().split())
c = 0

while (A % 2 == 0) and (B % 2 == 0) and (C % 2 == 0):
    A, B, C = B/2+C/2, C/2+A/2, A/2+B/2
    c += 1

    if A == B == C:
        c = -1
        break

print(c)

Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main(){
  int H, W;
  while(1){
  cin >> H >> W;
  if (H == 0 && W == 0)
   break;
    for(int j=1; j<=H; j++){
      for(int i=1; i<=W; i++){
        if(j%2 == 1 && i%2 == 0)
         cout << '.';
        else if(j%2 == 1 && i%2 == 1)
         cout << '#';
        else if(j%2 == 0 && i%2 == 1)
         cout << '.';
        else if(j%2 == 0 && i%2 == 0)
         cout << '#';
    }
    cout << endl;
  }
  cout << endl;
}
return 0;
}

Measured memory_bytes: 3048
#include<bits/stdc++.h>
using namespace std;
const int maxn=302,p=1e9+7;
int f[maxn][maxn][maxn],n,m;
vector<pair<int,int> >s[maxn];
void add(int &x,int y){x+=y;if(x>p) x-=p;}
int check(int r,int g,int b){
    int now=max(r,max(g,b));
    for(int i=0;i<s[now].size();++i){
        int l=s[now][i].first,x=s[now][i].second;
        int p=(r>=l)+(g>=l)+(b>=l);
        if(p!=x)return 1;
    }
	return 0;
}
int main(){
	cin>>n>>m;
    for(int i=1,l,r,x;i<=m;++i)cin>>l>>r>>x,s[r].push_back(make_pair(l,x));
    f[0][0][0]=1;int ans=0;
    for(int r=0;r<=n;++r)
        for(int g=0;g<=n;++g)
            for(int b=0;b<=n;++b){
                if((r==g||r==b||g==b)&&((!r)+(!g)+(!b))<2)continue;
                if(check(r,g,b))continue;
                int k=max(r,max(g,b))+1;
                add(f[k][g][b],f[r][g][b]);
                add(f[r][k][b],f[r][g][b]);
                add(f[r][g][k],f[r][g][b]);
                if(k==n+1)add(ans,f[r][g][b]);
		}
		cout<<ans;
}

Measured memory_bytes: 107904
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>   // popen, pclose, fgets
#include <cstdlib> 
using namespace std;
#define rep0(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>;
using ll = long long; //10e19までいける
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll =vector<vvll>;
const double PI=3.14159265358979323846;
//小数点以下を指定したい時　　→→→→  cout << fixed << setprecision()<<答え<<endl;
//int→string
//string→int   int num = atoi(numStr.c_str());

int main() {
    int n,m;cin>>n>>m;
    vi k(n),dish(m);
    rep0(i,n){
        cin>>k[i];
        vi A(k[i]);
        rep0(j,k[i]){
            cin>>A[j];
            dish[A[j]-1]++;
        }
    }
    int ans=0;
    rep0(i,m){
        if(dish[i]==n){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3616
#include<stdio.h>
#include<string.h>
int main(void)
{
	int i,b;
	char s[4],a[4];
	scanf("%s",s);
	scanf("%s",a);
	b=0;
	for(i=0;i<3;i++){
		if(s[i]==a[i]){
			b++;
		}
	}
	printf("%d",b);
	return 0;
}

Measured memory_bytes: 1712
package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

func main() {
	var s string
	fmt.Scan(&s)
	ls := list.New()
	for _, r := range s {
		ls.PushBack(string(r))
	}
	rv := false
	var q int
	fmt.Scan(&q)
	for i := 0; i < q; i++ {
		var t int
		fmt.Scan(&t)
		switch t {
		case 1:
			rv = !rv
		case 2:
			var (
				f int
				c string
			)
			fmt.Scan(&f, &c)
			if rv {
				f = 3 - f
			}
			if f == 1 {
				ls.PushFront(c)
			} else {
				ls.PushBack(c)
			}
		}
	}

	var wr = bufio.NewWriter(os.Stdout)
	if rv {
		for e := ls.Back(); e != nil; e = e.Prev() {
			wr.WriteString(e.Value.(string))
		}
	} else {

		for e := ls.Front(); e != nil; e = e.Next() {
			wr.WriteString(e.Value.(string))
		}
	}
	wr.WriteString("\n")
	wr.Flush()
}


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

using namespace std;


#define uniq(x)  x.erase(unique(x.begin(),x.end()), x.end()) //Unique value find from vector
#define upper(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Upper value search  >
#define lower(arr,n,fixed) lower_bound(arr,arr+n,fixed)-arr  //Lower value search  >=
#define FOR(i,a,n) for(int i=a; i<(int)n; i++)
#define FORI(i,a,n) for(int i=a; i>=(int)n; i--)
#define pii pair<int,int>
#define vpii vector<pii>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(a) int((a).size())
#define fastIO() ios_base::sync_with_stdio(0); cin.tie(0)
#define endl "\n"
#define all(a) a.begin(), a.end()
#define MEMSET(p,i) memset(p,i,sizeof(p))

typedef long long LL;
typedef unsigned long long ULL;


string a, b;
int n, m;

int memo[3010][3010] = {0};
string ans;
int dp(int i, int j)
{
	auto &dpm = memo[i][j];
	if(i >= n || j >= m)
		return dpm = 0;

	if(dpm != -1)
		return dpm;


	// match
	if(a[i] == b[j]){
		// avança os dois
		dpm = max(dpm, dp(i+1,j+1) + 1);
	}
	return dpm = max({dpm, dp(i+1,j), dp(i,j+1)});
}	

void construct(int i, int j)
{
	if(sz(ans) == memo[0][0]) return;
	auto &dpm = memo[i][j];
	if(i >= n || j >= m)
		return;

	// match
	if(a[i] == b[j] && memo[i+1][j+1] == memo[i][j]-1){
		ans += a[i];
		construct(i+1,j+1);
		return;
	}
	if(sz(ans) == memo[0][0]) return;
	if(memo[i+1][j] == memo[i][j])
		construct(i+1,j);
	else
		construct(i,j+1);
}

int main(void)
{
	fastIO();
	cin >> a >> b;
	n = sz(a);
	m = sz(b);

	MEMSET(memo,-1);
	dp(0,0);
	construct(0,0);
	cout << ans << endl;

}

Measured memory_bytes: 36096
import java.util.Scanner;

public class Main {

    public int countMultiple(int l, int r, int d) {
        int ans = (r / d) - (l / d);
        return l % d == 0 ? ans + 1 : ans;
    }

    public static void main(String args[]) {
        Main nm = new Main();
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        int r = sc.nextInt();
        int d = sc.nextInt();
        System.out.println(nm.countMultiple(l, r, d));
    }
}


Measured memory_bytes: 35648
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

int check(string s){
  pr(s);
  int N = s.size();
  for(int i=0;i<=N-i-1;i++){
    if(s[i] != s[N - 1 - i]) return 0;
  }
  return 1;
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string s;
  cin>>s;

  int N = s.size();
  int a = check(s);
  int b = check(s.substr(0, (N - 1)/2));
  int c = check(s.substr((N + 3)/2 - 1));
  int ans = a && b && c;
  cout<<(ans? "Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};



int main(){
    int n;cin >> n;
    bool f = true;
    for (int i = 0; i < n; i++) {
        int a;cin >> a;
        if(a%2==0){
            if(a%3&&a%5){
                f = false;
            }
        }
    }
    if(f) puts("APPROVED");
    else puts("DENIED");
    return 0;
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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; }

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; string s; cin>>n>>s;
  
  map<char,ll> m;
  rep(i,n){
    m[s[i]]++;
  }
  ll ans=1;
  for(auto e: m){
    (ans*=(e.second+1))%=MOD;
  }
  cout<<ans-1<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < n; i ++)
#define for1(i, n) for (int i = 1; i <= n; i ++)
#define repn(i, n) for (int i = n-1; i >= 0; i --)
#define rep1(i, n) for (int i = n; i >= 1; i --)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define f first
#define s second
using namespace std;
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
typedef long long ll;
const int INF = 1e9;
const ll INFl = 1e18;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<ll> vll;
typedef queue<int> qi;
typedef queue<pii> qpii;

void test_case() {
	char n; cin >> n;
	if (n >= 'a' && n <= 'z') cout << 'a';
	else cout << 'A';
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int q = 1; 
	//cin >> q;
	while (q--) {
		test_case();
	}
	return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <utility>
#include <algorithm>
#include <set>
#include <queue>
#include <climits>
#include <limits>
#define inf 1000000000000000000

#define ll long long
#define max(A, B) ((A) > (B) ? (A) : (B))
#define min(A, B) ((A) < (B) ? (A) : (B))
#define pair(A, B) make_pair(A, B)

using namespace std;

typedef pair<int, int> pi;
typedef pair<pair<int, int>, int> pii;

void perform() {
  int n; cin >> n;
  int pts = (n/500) * 1000;
  n %= 500;
  pts += (n/5) * 5;
  cout << pts << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t = 1; //cin >> t;
  while (t--) {perform();}
}

Measured memory_bytes: 256
#include<stdio.h>
signed main(){
    int x,y,a,b=0,c=0,A,B;
    scanf("%d %d",&x,&y);
    for(a=0;a<=x;a++){
        b=x-a;
        A=a*4;
        B=b*2;
        if(A+B==y){
            c++;
        }
    }
    if(c!=0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return(0);
}

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

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

	int h, n;
	long long int sum(0);

	cin >> h >> n;

	int temp;
	for (int i = 0; i < n; i++)
	{
		cin >> temp;
		sum += temp;
	}

	if (sum >= h) cout << "Yes";
	else cout << "No";

	return 0;
}

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

int main() {
	int N;
	std::cin >> N;
	std::vector<int> A(N);
	for(int i = 0; i < N; i++) {
		std::cin >> A[i];
		A[i] -= (i + 1);
	}

	std::sort(A.begin(), A.end());
	long long result = 0ll;
	if(N == 1) {
		result = 0ll;
	} else {
		const long long center = A[N / 2];
		for(int i = 0; i < N; i++) {
			result += std::abs((long long)A[i] - center);
		}
	}
	std::cout << result << std::endl;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
ll ar[1001][2],h,n; ll dp[10001];
ll findans(ll cur_h){
	if(cur_h<=0) return 0;
	if(dp[cur_h]!=-1){
		return dp[cur_h];
	}
	ll i,mn=1e18;
	for(i=1;i<=n;i++){
		mn=min(mn,findans(cur_h-ar[i][0])+ar[i][1]);
	}
	return dp[cur_h]=mn;
}
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l;
	cin>>h>>n;
	for(i=1;i<=n;i++){
		cin>>ar[i][0]>>ar[i][1];
	}
	memset(dp,-1,sizeof(dp));
	ll an=findans(h);
	cout<<an;
	return 0;
}

Measured memory_bytes: 768
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace dwacon
{
    class Program
    {
        struct data
        {
            public int[] num; 
        }

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            data[] d = new data[n];
            for (int i = 0; i < n; i++)
            {
                d[i].num = 文字列処理(Console.ReadLine());
            }
            string output = "";
            for (int i = 0; i < 26; i++)
            {
                int min = int.MaxValue;
                for (int j = 0; j < n; j++)
                {
                    if (d[j].num[i] < min) min = d[j].num[i];

                }
                char add = (char)((int)'a' + i);
                for (int j = 0; j < min; j++)
                {
                    output += add.ToString();
                }
            }
            Console.WriteLine(output);
        }

        static int[] 文字列処理(string x)
        {
            int[] output = new int[26];
            for (int i = 0; i < x.Length; i++)
            {
                output[x[i] - 'a'] = output[x[i] - 'a'] + 1;
            }
            return output;
        }


    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,p,x,y;
int main(){
	cin>>n>>p;
	for(int i=1;i<=n;i++){
		cin>>x;
		if(x&1)y=1;
	}
	if(y)cout<<(1LL<<(n-1));
	else if(p==0)cout<<(1LL<<n);
	else cout<<0;
}

Measured memory_bytes: 256
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

lia = [0]
lib = [0]
tmp = M
ans = 0

for i in range(N):
    lia.append(lia[i]+A[i])
for i in range(M):
    lib.append(lib[i]+B[i])

for i in range(N+1):
    kari = 0
    t = K - lia[i]
    kari += i

    if t<0:
        break
    elif t==0:
        ans = max(ans, i)
        break
    else:
        pass

    for j in range(tmp,-1,-1):
        if t<lib[j]:
            continue
        else:
            tmp = j
            kari += j
            ans = max(ans, kari)
            break

print(ans)

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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int a[3], k;

    cin>> a[0]>> a[1]>> a[2]>> k;

    int i=0, sum=0;
    while(k!=0)
    {
        if(i==2)
            sum-= min(k, a[i]);
        else if(i== 0)
            sum+= min(k, a[i]);

        k-=(min(k, a[i]));
           i++;
    }

    cout<< sum;
    nl;


    return 0;
}




Measured memory_bytes: 3612
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split(" ");
	const S = parseInt(input[0], 10);
	const W = parseInt(input[1], 10);
  //出力
  if (S <= W) {
    console.log('unsafe');
  } else {
    console.log('safe');
  }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 30532
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  vi x(n);
  rep(i,n){
    cin >> x[i];
  }

  ll cost = 1001001001LL;
  int ans = 0;
  rep(p,101){
    ll sum = 0;
    rep(i,n){
      sum+=(x[i]-p)*(x[i]-p);
    }
    if(sum < cost){
      ans=p;
      cost = sum;
    }
  }
  cout<<cost<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

int main() {
	int n;
	
	while (cin >> n, n){
		vector<pair<double, string>> veg(n);
		REP(i, n){
			double a, b, c, d, e, f, g, h, m;
				cin >> veg[i].second;
				cin >> a >> b >> c >> d >> e >> f >> g >> h >> m;
				veg[i].first = -(m*h*g-a)/((b+c+d)+(e+f)*m);
				
		}
		SORT(veg);
		REP(i, n){
			cout << veg[i].second << endl;
		}
		cout << '#' << endl;
	}
}

Measured memory_bytes: 3228