akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int N;
long long A, B, C, D;

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

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A >> B >> C >> D;
        if (A < B || B > D) {
            cout << "No" << endl;
            continue;
        } else if (B <= C) {
            cout << "Yes" << endl;
            continue;
        }
        
        long long g = gcd(B, D);
        
//        A + k * D (mod B)で最大のものとCを比べる
        if ((A % g) + B - g > C) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
    }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;

public class Main {
	public static void main(String[] args) throws Exception {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	    String line = "";
	    HashMap<String, Integer> ans = new HashMap<String, Integer>();
	    while ((line = br.readLine()) != null) {
		    for (int i = 0; i < line.length(); i++) {
		    	String str = Character.toString(line.charAt(i)).toLowerCase();

		    	if (ans.containsKey(str)) {
		    		ans.put(str, ans.get(str) + 1);
		    	} else {
		    		ans.put(str, 1);
		    	}
		    }
	    }

	    // Display Answer
	    StringBuilder sb = new StringBuilder();
	    for (char c = 'a'; c <= 'z'; c++) {
	    	sb.append(c).append(" : ");
	    	String keyChar = Character.toString(c);
	    	if (ans.containsKey(keyChar)) {
	    		sb.append(ans.get(keyChar));
	    	} else {
	    		sb.append("0");
	    	}

    		sb.append("\n");
 	    }
	    System.out.print(sb.toString());
	}
}

Measured memory_bytes: 24504
n = int(input())
s = sorted([int(input()) for i in range(n)])
su = sum(s)
if su%10 != 0:
  print(su)
else:
 for j in range(n):
    if s[j]%10 != 0:
      print(su-s[j])
      break
    elif j+1 == n:
      print(0)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using lint = long long;


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

  cout << fixed << setprecision(12);

  double a, b, h, m;
  cin >> a >> b >> h >> m;

  const double pi = acos(-1);

  double radH = 2 * pi * (h * 60 + m);
  radH /= 720;

  double radM = 2 * pi * m;
  radM /= 60;

  double x1 = a * cos(radH);
  double y1 = a * sin(radH);

  double x2 = b * cos(radM);
  double yy = b * sin(radM);

  // cout << x1 << " " << y1 << ' ' << x2 << " " << yy << "\n";

  double ans = hypot(x1 - x2, y1 - yy);
  cout << ans << "\n";
}

Measured memory_bytes: 4168
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 300005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int MOD = 1000000007;
int K,N;
int dp[2005][2005],sum[2005];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
void Solve() {
    
    read(N);read(K);
    dp[0][N + 1] = 1;
    for(int i = 1 ; i <= K ; ++i) {
	sum[N + 2] = 0;
	for(int j = N + 1 ; j >= 1 ; --j)  sum[j] = inc(sum[j + 1],dp[i - 1][j]);
	for(int j = 1 ; j <= N ; ++j) {
	    if(i == K && j != 1) continue;
	    if(i < K && j == 1) continue;
	    dp[i][j] = sum[j + 1];
	    if((N - j + 1) > (i - 1)) dp[i][j] = inc(dp[i][j],dp[i - 1][j]);
	}
    }
    int t = 1;
    for(int i = 1 ; i < N - K ; ++i) {
	t = mul(t,2);
    }
    out(mul(dp[K][1],t));enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}


typedef struct
{
    ll w,val;
} node;

ll n,k,mx;

vector<node>v;

ll dp[110][100010];

ll call(ll i,ll val)
{
    if(val<=0)return 0;

    if(i==n)
        return 1e18;


    if(~dp[i][val]==0)
dp[i][val]=min(call(i+1,val),v[i].w+call(i+1,val-v[i].val));

    return dp[i][val];

}



int main()
{

    fastread();

    ll i,j,m,p,a,sum=0,t,b,c,d,cnt=0,q,l,r;


    string str;

    bool flag=true;

    cin>>n>>k;

    memset(dp,-1,sizeof(dp));



    for(i=0; i<n; i++)
    {
        cin>>a>>b;

        v.eb(node{a,b});

        sum+=b;
    }


    for(i=sum; i>=0; i--)
    {

        if(call(0,i)<=k)
        {
            cout<<i<<endl;

            return 0;
        }
    }





}


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

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

  ll ans = 0;
  rep_s(i, 1, N + 1) {
    if (i % 3 == 0 || i % 5 == 0) {
      continue;
    }
    ans += i;
  }

  cout << ans << endl;

}


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

using namespace std;
typedef long long ll;
const int N = 200010;
int _w;

int n, a[N], len[N];

int main() {
	_w = scanf( "%d", &n );
	for( int i = 1; i <= n; ++i )
		_w = scanf( "%d", a+i );
	for( int i = 1; i <= n; ++i ) {
		int x = a[i];
		if( len[x-1] ) len[x] = len[x-1] + 1;
		else len[x] = 1;
	}
	printf( "%d\n", n - *max_element(len+1, len+n+1) );
	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
int main()
{
	int A,B,X;
	scanf("%d %d %d",&A,&B,&X);
	if(X>=A){
		if(X<=A+B){
			printf("YES");
		}else{
			printf("NO");
		}
	}else{
		printf("NO");
	}
	return 0;
}


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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> red;
    vector<pair<int, int>> blue;
    int a, b;
    for (int i = 0; i < n; i++) {
        cin >> a >> b;
        red.emplace_back(a, b);
    }
    sort(ALL(red), [](auto r1, auto r2){return r1.second > r2.second;});
    for (int i = 0; i < n; i++) {
        cin >> a >> b;
        blue.emplace_back(a, b);
    }
    sort(ALL(blue));

    int t = 0;
    for (const auto p : blue) {
        for (int i = 0; i < red.size(); i++) {
            if (p.first > red[i].first && p.second > red[i].second) {
                t++;
                red.erase(red.begin() + i);
                break;
            }
        }
    }

    cout << t << endl;
}


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

int main() {
    int N,i,j,k,A,x,y,m=0;
    cin >> N;
    vector<vector<int>> t(N, vector<int>(N,-1));

    for(i=0; i<N; i++) {
        cin >> A;
        for(j=0; j<A; j++) {
            cin >> x >> y;
            t.at(i).at(x-1) = y;
        }
    }

    for(i=0; i<(1<<N); i++) {
        vector<int> l(N,-1);
        set<int> h;
        bool b=1;
        for(j=0; j<N; j++) {
            if(i & (1<<j)) {
                h.insert(j);
                for(k=0; k<N; k++) {
                    if(t.at(j).at(k) == -1)
                        continue;
                    if(l.at(k) == -1) {
                        l.at(k) = t.at(j).at(k);
                        continue;
                    }
                    if(l.at(k) != t.at(j).at(k))
                        break;
                }
                if(k != N)
                    break;
            }
        }
        if(j == N) {
            for(j=0; j<N; j++) {
                if(h.count(j) && l.at(j)==0)
                    b = 0;
                if(!h.count(j) && l.at(j)==1)
                    b = 0;
            }
            if(b)
                m = max(m,(int)h.size());
        }
    }

    cout << m << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
   int A;
   int sum = 0;
   for(int i=0; i<3; ++i) {
      std::cin >> A;
      sum += A;
   }
   if(sum<=21) std::cout << "win" << std::endl;
   else std::cout << "bust" << std::endl;
   return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u32 = read();
    println!(
        "{}", 
        (0..n)
            .map(|_| read::<u32>().trailing_zeros())
            .min()
            .unwrap()
    )
}


Measured memory_bytes: 4352
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	n,a,b = readline() |> split |> parseMap
	x = readline() |> split |> parseMap
	s = 0
	for i in 2:n
		if (x[i]-x[i-1])*a < b
			s += (x[i]-x[i-1])*a
		else
			s += b
		end
	end
	println(s)
end
main()


Measured memory_bytes: 116232
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
	int N, Q;
	String S;
	int[] l, r;
	List<Integer> acIndexes;
	int[] memo;
	PrintWriter out = new PrintWriter(System.out);

	Main() throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] tokens = in.readLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		Q = Integer.parseInt(tokens[1]);
		S = in.readLine();
		l = new int[Q];
		r = new int[Q];
		for (int i = 0; i < Q; ++i) {
			tokens = in.readLine().split(" ");
			l[i] = Integer.parseInt(tokens[0]);
			r[i] = Integer.parseInt(tokens[1]);
		}
		in.close();
	}

	void calc() {
		this.memo = new int[N];
		Arrays.fill(this.memo, 0);
		int count = 0;
		char[] c = S.toCharArray();
		for (int i = 0; i < c.length - 1; ++i) {
			if (c[i] == 'A' && c[i + 1] == 'C') {
				++count;
				this.memo[i] = count;
				this.memo[i + 1] = count;
				++i;
			} else {
				this.memo[i] = count;
			}
		}
		this.memo[this.memo.length - 1] = this.memo[this.memo.length - 2];
		/*
		 * for (int i = 0; i < this.memo.length; ++i) { System.out.println(" " +
		 * this.memo[i]); }
		 */

		for (int i = 0; i < Q; ++i) {
			int left = 0;
			if (l[i] == 1) {
				left = 0;
			} else {
				left = this.memo[l[i] - 2];
			}
			int right = this.memo[r[i] - 2];
			// int left = findRight(this.acIndexes, l[i] - 1);
			// int right = findRight(this.acIndexes, r[i] - 1);
			// System.out.println(left + ", " + right);
			int result = right - left;
			out.println(result);
		}

	}

	public static void main(String[] args) throws IOException {
		Main ins = new Main();
		ins.calc();
		ins.out.flush();
	}

}

Measured memory_bytes: 47472
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  string S;
  cin>>S;
  if(N%2==1) cout<<"No"<<endl;
  else{
    int n=N/2;
    bool A=true;
    for(int i=0;i<n;i++){
      if(S.at(i)!=S.at(i+n)){
        A=false;
        break;
      }
    }
    if(A==true){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }
}
        
  

Measured memory_bytes: 256
import string
n = int(input())
m = set(list(string.ascii_lowercase))
l = []
for _ in range(n):
  s = input()
  m &= set(list(s))
  l.append(s)
r = ""
for s in m:
  r += s * min(l, key=lambda x: x.count(s)).count(s)
print(''.join(sorted(r)))


Measured memory_bytes: 3772
#include<stdio.h>
#include<map>
#include<iostream>
using namespace std;
map<int,int> a;
int t[2],lt;
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0; i<n; i++){
		int x;
		scanf("%d",&x);
		a[x]++;
	}
	for(map<int,int>::reverse_iterator it = a.rbegin(); it != a.rend(); it++){
		int A = it->first, B = it->second;
		while(B >= 2 && lt < 2){
			t[lt++] = A;
			B -= 2;
		}
	}
	cout <<(lt < 2?0:(long long int)t[0] * t[1]) <<endl;
	return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    rep(i,0,26)rep(j,0,10)if(i * 4 + j * 7 == N){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(ll i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;

const long long TIME_LIMIT=10000;

ll scorecalc(vector<vector<ll>> a, vector<ll> los, ll d, vector<ll> an)
{
    ll ans = 0;
    
    vector<ll> last(los.size(), 0);
    for (int i = 0; i < an.size(); i++)
    {
        ll loss = 0;
        for (int j = 0; j < 26; j++)
        {
            if (j == an[i] - 1)
                continue;

            loss += los[j] * (i+1LL - last[j]);
        }
        ans += a[i][an[i] - 1] - loss;
        last[an[i] - 1] = i + 1LL;
    }

    return ans;
}

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

    ll d;
    cin >> d;
    vector<ll> c(26);
    rep(i, 26)
    {
        cin >> c[i];
    }
    vector<vector<ll>> s(d, vector<ll>(26));
    rep(i, d)
    {
        rep(j, 26)
            cin >> s[i][j];
    }

    vector<ll> ans(d);

    vector<ll> last(26, 0);

    for (ll i = 0; i < d; i++)
    {
        ll lost = 0;
        for (int j = 0;j < 26; j++)
        {
            lost += c[j] * (i + 1 - last[j]);
        }
        ll man = s[i][0]-lost+c[0]*(i+1-last[0]);
        ll manu = 1;
        for (int j = 0; j < 26; j++)
        {
            if (man <= s[i][j]-lost+c[j]*(i+1-last[j]))
            {
                man = s[i][j] - lost + c[j] * (i + 1 - last[j]);
                manu = j + 1LL;
                last[j] = i + 1;
            }
        }
        ans[i] = manu;
    }
    /*ll score = scorecalc(s, c, d, ans);
    ll times = 0;
    while (times < 10000)
    {
        vector<ll> tmpD(1000);
        rep(j, 1000)
        {
            tmpD[j] = (ll)rand() % d;
        }
        vector<ll> tmpN(1000);
        rep(j, 1000)
        {
            tmpN[j] = ans[tmpD[j]];
            ans[tmpD[j]] = (ll)rand() % 26 + 1;
        }

        if (score >= scorecalc(s, c, d, ans))
            rep(j, 1000)
            ans[tmpD[j]] = tmpN[j];
        else
            score = scorecalc(s, c, d, ans);

        times++;
    }*/

    rep(i, d)
    {
        cout << ans[i] << endl;
    }

	return 0;

}

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

using namespace std;
using ll = long long;

int main() {
  ll a[5];
  for (int i = 0; i < 5; ++i) {
    cin >> a[i];
  }
  ll b[5];
  ll mina = 10;
  int indexa = -1;
  for (int j = 0; j < 5; ++j) {
    ll b = a[j]%10;
    if(b==0)
      b=10;
    if(b<mina){
      mina = b;
      indexa = j;
    }
  }
  ll res = 0;
  for (int k = 0; k < 5; ++k) {
    if(k == indexa)
      continue;
    res += a[k];
    if(a[k]%10!=0)
      res += 10-a[k]%10;
  }
  if(indexa != -1)
    res += a[indexa];
  cout << res << endl;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
ac_d = {}
wa_d = {}
for i in range(m):
    p, s = input().split()
    if s == "WA":
        if p in wa_d:
            if wa_d[p] == 0:
                pass
            else:
                if p not in ac_d:
                    wa_d[p] += 1
        else:
            wa_d[p] = 1
    else:
        if p not in wa_d:
            wa_d[p] = 0
        ac_d[p] = 1

ac = len(ac_d.keys())

penalty = 0
for key in ac_d.keys():
    penalty += wa_d[key]
print(ac, penalty)

Measured memory_bytes: 27276
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#define bogo_sort   std::sort
#define bozo_sort   std::stable_sort
#define alles(obj)  obj.begin(), obj.end()
#define elif        else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo        std::cout <<
#define read        std::cin >>
#define endl        std::endl
#define fin         << '\n'
#define bash        push_back
#define makePair    std::make_pair
#define _           << ' ' <<
// type-define
#define Stack       std::stack
#define Queue       std::queue
#define Set         std::set
#define PQueue      std::priority_queue
#define Vector      std::vector
#define Pair        std::pair
#define Map         std::map
#define HashMap     std::unordered_map
#define Greater     std::greater
using String  =     std::string;
using llong   =     long long;
using boolean =     bool;
using Pii     =     Pair<int, int>;
using Vi      =     Vector<int>;
using Vii     =     Vector<Pii>;
// utils
constexpr int   dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int   dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int   INF  = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    template<class A, class B> A power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    template<class A, class B> A power ( A x, B n ) { return power( x, n, 1000000007 ); }
    template<class A> A gcd ( A x, A y ) { return x % y ? gcd( y, x % y ) : y; }
    template<class A, class B> A lcm   ( A x,  B y ) { return ( x / gcd(x, y) * y ); }
    template<class A> inline A abs ( A n ) { return ( n < 0 ) ? -n : n; }
    template<class A, class B> inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B> inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    Vi vi, bi;
    int left, right;

    signed call_of_Cthulhu( signed datum ) {

        int n;
        read n;
        for ( int i = 0; i < n; i++ ) {
            int a;
            read a;
            vi.bash(a);
            bi.bash(a);
        }

        bozo_sort(alles(bi));
        left = bi[n/2-1];
        right = bi[n/2];
        for ( int i = 0; i < n; i++ ) {
            if ( vi[i] < right ) {
                echo right fin;
            }
            else {
                echo left fin;
            }
        }


        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


Measured memory_bytes: 3944
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,w;
    cin>>n>>w;
    int a[n][2];
    for(int i=1;i<=n;i++){
        cin>>a[i][0]>>a[i][1];
    }
    long long int d[n+1][w+1];
    for(int i=0;i<=n;i++){
        for(int j=0;j<=w;j++){
            if(i==0||j==0){
                d[i][j]=0;
            }
            else if(j>=a[i][0]){
                d[i][j]=max(a[i][1]+d[i-1][j-a[i][0]],d[i-1][j]);
            }
            else{
                d[i][j]=d[i-1][j];
            }
        }
    }
    cout<<d[n][w];
}

Measured memory_bytes: 79104
#include <cstring>
#include <cstdint>
#include <iostream>
#include <string>
#include <memory>
#include <queue>
#include <limits>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <sstream>
#include <random>
#include <functional>
#include<algorithm>
using namespace std;

int main() {
	string str;
	cin >> str;
	size_t l = 0,r = str.size() - 1;
	int v = 0;
	while(l < r)
	{
		while ((str[l] == str[r]) && (l < r))
		{
			l++;r--;
		}
		if (l < r) {
			if (str[l] == 'x') {
				v++;
				l++;
			}
			else if (str[r] == 'x') {
				v++;
				r--;
			}
			else {
				v = -1;
				break;
			}
		}
	}
	cout << v;
	return 0;
}

Measured memory_bytes: 512
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import string
import sys

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

sys.setrecursionlimit(2147483647)
INF = float("inf")

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

plus = []
minus = []

for a in A:
    if a >= 0:
        plus.append(a)
    else:
        minus.append(a)
if not plus:
    mm = max(minus)
    plus.append(mm)
    minus.remove(mm)
if not minus:
    mp = min(plus)
    minus.append(mp)
    plus.remove(mp)

hist = []
x = minus.pop()
while len(plus) > 1:
    y = plus.pop()
    hist.append((x, y))
    x = x - y
minus.append(x)

x = plus.pop()
while len(minus) > 1:
    y = minus.pop()
    hist.append((x, y))
    x = x - y
y = minus.pop()
hist.append((x, y))

print(x - y)
for h in hist:
    print(*h)


Measured memory_bytes: 29800
n, c = map(int, input().split())

r = [[0 for i in range(c)] for j in range(100000)]  # テレビ局の番組表
for dummy in range(n):  # 入力
    s, t, c = map(int, input().split())
    for j in range(s - 1, t):
        r[j][c - 1] = 1  # 放送中なら1

ans = 0
for i in range(100000):
    if sum(r[i]) > ans:
        ans = sum(r[i])  # 同時に放送されている番組の最大数

print(ans)

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

int main() {
    int A,B;
  	cin >> A >> B;
  
  	int ans =0;
    int amount = 1;
  	while(amount < B) {
      amount--;
      amount += A;
      ans++;
    }
    cout << ans << endl;
  
	return 0;  
}


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

int a[105];

int cost(int l, int r, int curWatered){ ///[l, r]
    if(r < l){
        return 0;
    }
    if(l == r){
        return (a[l] >= curWatered ? a[l] - curWatered : 0);
    }

    int mn = *min_element(a + l, a + r + 1);
    int mc = mn - curWatered;

    curWatered = mn;

    int strt;
    for(int i = l; i <= r; ++i){
        if(a[i] == mn){
            if(i == l){
                strt = l;
                break;
            }
            mc += cost(l, i - 1, curWatered);
            strt = i;
            break;
        }
    }

    for(int i = strt + 1; i <= r; ++i){
        if(a[i] == mn){
            if(i == strt || strt + 1 == i){
                continue;
            }
            mc += cost(strt + 1, i - 1, curWatered);
            strt = i;
            continue;
        }
        if(i == r){
            mc += cost(strt + 1, i, curWatered);
        }
    }

    return mc;
}

int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    int res = cost(0, n - 1, 0);
    cout << res << "\n";
    return 0;
}


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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

static const double pi = 3.141592653589793;

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

    double A = (double)a, B = (double)b;

    double H,M;
    cin >> H >> M;

    double cosC = cos(pi/180 * min(abs(H*30 - M*5.5),360 - abs(H*30 - M*5.5)));

    double AABB2ABCOSC = A*A + B*B - 2.0 * A * B * cosC;

    double ans = sqrt(AABB2ABCOSC);

    if(ans >= 1000.0)
    printf("%13.9f\n",ans);
    else if(ans >= 100.0)
    printf("%12.9f\n",ans);
    else if(ans >= 10.0)
    printf("%11.9f\n",ans);
    else
    printf("%10.9f\n",ans);

    return 0;
}

Measured memory_bytes: 4132
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(int i=0;i<(n);i++)
#define fori(a,b,i) for(int i=(a);i<=(b);i++)
#define ford(a,b,i) for(int i=(a);i>=(b);i--)
#define fast_io ios_base::sync_with_stdio(false) , cin.tie(NULL);


#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef set<int> SI;
typedef long long int llint;


int main(){
	llint k;
	string s;
	cin>>k>>s;
	loop(i, min(k, (llint)s.length())) cout<<s[i];
	if(k < s.length()) cout<<"...";
	return 0;
}


Measured memory_bytes: 3620
A, B, K = map(int, input().split())
def h(x):
    if x%2==0:
        return int(x/2)
    else:
        return int((x-1)/2)
for i in range(K):
    if i%2 == 0:
        A = h(A)
        B = B + A
    else:
        B = h(B)
        A = A + B
print(A, B)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 1e9 + 7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

void solve()
{
	int n;
	cin >> n;
	string s;
	set<string> S;
	for (int i = 0; i < n; i++)
	{
		cin >> s;
		S.insert(s);
	}
	cout << sz(S) << ln;
	return;
}

int main()
{
	FASTIO;
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve();
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 19240
S = input()
while len(S) > 0:
    if 'dream' in S[-5:]:
        S = S[:-5]
        continue
    if 'dreamer' in S[-7:]:
        S = S[:-7]
        continue
    if 'erase' in S[-5:]:
        S = S[:-5]
        continue
    if 'eraser' in S[-6:]:
        S = S[:-6]
        continue
    break
if S == '':
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3316
//By : BebekJK
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//Declare -> ordered_set NAMA;
//Nth smallest integer -> find_by_order(N-1)
//Number of elements less than N -> order_of_key(N)
//Delete N from the set -> erase(N)

#define endl '\n'
#define MOD 1000000007
#define PI 3.141592653
#define fi first
#define sc second
#define pb push_back
#define pbb pop_back

//#pragma GCC optimize("Ofast")
//#pragma GCC target ("string"...)
//#pragma GCC push_options
//#pragma GCC pop_options
//#pragma GCC reset_options
//#pragma GCC optimize ("O3")

typedef long long ll;
typedef long long ld;
typedef pair<int , int> pii;
typedef pair<long long , long long> pll;

void BOOST(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
}
void fcin(int &x){
	bool neg = false;
	register int c;
	x = 0;
	c = getchar();
	if(c=='-'){
		neg = true;
		c = getchar();
	}
	for(;(c>47 && c<58);c=getchar())x = (x<<1)+(x<<3)+c-48;
	if(neg)x*=-1;
}
ll pmod(ll a , ll b){
	if(b==0)return 1;
	ll temp = pmod(a , b/2);
	if(b%2==0)return(temp*temp)%MOD;
	return (((temp*temp)%MOD)*a)%MOD;
}
int main(){
//	BOOST();
	ll N , K , T[200005];
	cin>>N>>K;
	for(int i=1;i<=N;i++)cin>>T[i];
	set<int>vis;
	vis.clear();
	vis.insert(1);
	ll now = 1 , cnt = 0 , sz = 1;
	for(int i=1;i<=N;i++){
		if(i==K+1){
			cout<<now<<endl;
			return 0;
		}
		
		if(vis.find(T[now])!=vis.end()){
			sz = vis.size();
			break;
		}
		now = T[now];
		cnt++;
		vis.insert(now);
	}
	K-=(cnt+1);
	ll temp = T[now];
	bool check = false;
	vector<int>cycle;
	cycle.empty();
	now = 1;
	for(int i=1;i<=N;i++){
		if(temp==now && !check)check = true;
		else if(temp==now && check)break;
		if(check){
			cycle.pb(now);
		}
		now = T[now];
	}
	ll x = cycle.size();
	K%=(x);
	cout<<cycle[K]<<endl;
	
}






Measured memory_bytes: 13308
#include <iostream>
#include <cmath>

using namespace std;

int main(void)
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define queint queue<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>//大きい順
#define pqg priority_queue<int,vec,greater<int>>//小さい順
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll lin(){ll x;scanf("%lld",&x);return x;}
int main(){
    int n=in();
    vec p(n);
    rep(i,n)p[i]=in();
    int ans=0;
    rep(i,n-2){
        if(p[i+1]<p[i]&p[i+1]>p[i+2])ans++;
        if(p[i+1]>p[i]&p[i+1]<p[i+2])ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE RankNTypes #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
-- import Data.List
-- import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace
-- trace _ = id

solve :: [(Int,Int)] -> String
solve [(a,b),(c,d),(e,z)] = if (f 1) + (f 2) + (f 3) + (f 4) == 2 then "YES" else "NO"
  where
    flat :: [Int]
    flat = [a,b,c,d,e,z]
    f :: Int -> Int
    f i = if length [x | x <- flat, x == i] == 1 then 1 else 0


readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> String
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      lstAB = map (\[x1,x2] -> (readBInt x1,readBInt x2)) remLines0
  in solve lstAB

outAnswer :: String -> IO ()
outAnswer = putStrLn

main :: IO ()
main = outAnswer . tmain =<< B.getContents


-------------------------------------------------------------------------------

inp1 = "4 2\n1 3\n2 3\n"
inp2 = "3 2\n2 4\n1 2\n"
inp3 = "2 1\n3 2\n4 3\n"
tv1 = tmain $ B.pack inp1
tv2 = tmain $ B.pack inp2
tv3 = tmain $ B.pack inp3
test1 = tv1 == "YES"
test2 = tv2 == "NO"
test3 = tv3 == "YES"
alltest = test1 && test2 && test3



Measured memory_bytes: 380
from sys import stdin, setrecursionlimit


def initialize_cmb(m, mod=10 ** 9 + 7):
    fac = [1]
    finv = [1]
    inv = [0] * (m + 1)
    if m >= 1:
        fac.append(1)
        finv.append(1)
        inv[1] = 1
        pre_fac = 1
        pre_finv = 1
        for i in range(2, m + 1):
            pre_fac = pre_fac * i % mod
            fac.append(pre_fac)
            inv[i] = mod - inv[mod % i] * (mod // i) % mod
            pre_finv = pre_finv * inv[i] % mod
            finv.append(pre_finv)
    return fac, finv


def cmb(n, k, fac, finv, mod=10 ** 9 + 7):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    mod = 10 ** 9 + 7
    input = stdin.buffer.readline
    x, y = map(int, input().split())

    if (x + y) % 3 != 0 or 2 * x < y or 2 * y < x:
        print(0)
    else:
        fac, finv = initialize_cmb((x + y) // 3, mod)

        x_min = (x + y) // 3

        print(cmb((x + y) // 3, x - x_min, fac, finv, mod))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


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

const double INF = 1e10;

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

	double min_h = INF, max_h = -INF;
	double h;
	while(cin >> h) {
		min_h = min(min_h, h);
		max_h = max(max_h, h);
	}
	cout << max_h - min_h << endl;
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in.txt", "r", stdin);
	freopen(".out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s, t; cin >> s >> t;
	int n = t.size(), cur = 0, ans = INF32;
	for(int i = 0; i <= s.size() - n; i++)
	{
		for(int j = 0, ii = i; j < n; j++, ii++) cur += s[ii] != t[j];
		ans = min(ans, cur);
		cur = 0;
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
#define int long long
#define rep(i,a,n) for (int (i)=(a);(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef long double ld;
signed  main() {
	ll n, a, b;
	cin >> n >> a >> b;
	if (n == 1 && a != b) {
		cout << 0 << endl;
		return 0;
	}
	if (a > b) {
		cout << 0 << endl;
		return 0;
	}
	cout << (a + (n - 1)*(b))-(a*(n - 1) + b)+1 << endl;
	getchar(); getchar();
}

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

using namespace std;

char board[1005][1005];
int dp[1005][1005];
int H,W;
const int mod = (int)1e9 + 7;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> H >> W;
	for (int i = 0 ; i < H ; i++)
	{
		for (int j = 0 ; j < W ; j++)
		{
			cin >> board[i][j];
		}
	}
	dp[0][0] = 1; // There only 1 way to go at 0,0(because it is starting point :))) )
	for (int i = 0 ; i <= H ; i++)
	{
		for (int j = 0 ; j <= W ; j++)
		{
			if (i + j > 0 && board[i][j] != '#')
			{                  
				dp[i][j] = (i > 0 ? dp[i-1][j] : 0) + (j > 0 ? dp[i][j-1] : 0);
				if (dp[i][j] >= mod) dp[i][j] -= mod;
			}
		}
	}
	cout << dp[H-1][W-1] << "\n";	
	return 0;
}

/*
	dp[i][j]: the maximum number of path from [0,0] to [i,j]
	The answer will be dp[H-1][W-1]

	i + j > 0 will be alternative to i != 0 || j != 0 
*/

Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<ll,ll>;
#define rep(i,n) for(ll i=0;i<(ll)n;++i)
const ll INF = 999999999999999;

int main(){
  ll a,b,c,k;
  cin >> a >> b >> c >> k;
  if( a >= k ){
    cout << k << endl;
  }else if( a+b >= k ){
    cout << a << endl;
  }else{
    cout << a - (k-a-b) << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
// Math = ♥️

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define sz(c) ((ll)c.size())
#define ordered_set                            \
    tree<ll, null_type, less<ll>, rb_tree_tag, \
         tree_order_statistics_node_update>

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

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

    ll MAX = (1 << n);
    ll sub[MAX];

    for (int i = 0; i < MAX; i++) {
        sub[i] = 0;
        vi ind;
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                ind.pb(j);
            }
        }

        for (int j = 0; j < ind.size(); j++) {
            for (int k = j + 1; k < ind.size(); k++) {
                sub[i] += arr[ind[j]][ind[k]];
            }
        }
    }

    ll dp[MAX];

    for (int mask = 0; mask < MAX; mask++) {
        dp[mask] = sub[mask];
        for (int s = mask; s; s = (s - 1) & mask) {
            dp[mask] = max(dp[mask], sub[mask ^ s] + dp[s]);
        }
    }

    cout << dp[MAX - 1] << "\n";
}



Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int N, K, a[102], mod=1e9+7; ll dp[101][100001]; 
int main(){
    scanf("%d %d", &N, &K);
    for(int i=1; i<=N; i++) scanf("%d", &a[i]);
    dp[0][0] = 1;
    for(int i=1; i<=N; i++){
        dp[i][0] = 1;
        for(int j=1; j<=K; j++){
            dp[i][j] = (dp[i-1][j] - (j>=a[i]+1? dp[i-1][j-a[i]-1]: 0) + mod) % mod;
            dp[i][j] = (dp[i][j] + dp[i][j-1]) % mod;
        }
    }
    printf("%lld\n", dp[N][K]);
}

Measured memory_bytes: 78336
#!/usr/bin/env pypy3

M = 64
P = 10 ** 9 + 7


def solve(n, xs):
    su = 0
    for i in range(M):
        zc = 0
        oc = 0
        idsu = 0
        for j in range(n):
            if xs[j] % 2 == 0:
                zc += 1
            else:
                oc += 1
            xs[j] //= 2
        idsu = oc * zc * (1 << i)
        su += idsu
        su %= P
    return su


def main():
    n = int(input())
    xs = [int(x) for x in input().split()]
    res = solve(n, xs)
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 125624
/// إِنَّ مَعَ الْعُسْرِ يُسْرًا
/// لَا أَبْرَحُ حَتَّىٰ أَبْلُغَ

#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_cxx;
using namespace __gnu_pbds;
using namespace std;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef pair<int, int> iPair;
#define LL unsigned long long
#define ll long long
#define LD double
#define HabdModeActive ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define S second
#define F first
#define PI acos(-1)
#define MAX 5000005
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);




int main() {
    HabdModeActive




     int n, m;
     cin >> n >> m;
     vector<LL> vec;
     for (int i = 0; i < n; i++) {
         LL x;
         cin >> x;
         vec.push_back(x);
     }
     sort(vec.rbegin(), vec.rend());

     priority_queue<int>Q;
     for(int i=0 ; i<n; i++)
         Q.push(vec[i]);

     while(m>0 && Q.top()!=0)
     {
         int x = Q.top();

         Q.pop();
         if(Q.size()>=1)
         {
             LL v = 2;
             while(x>=Q.top() && m>0)
             {
                 x/=2;
                 m--;
             }
             Q.push(x);
         }
         else
         {
             while(m>0 && x>0)
             {
                 x/=2;
                 m--;
             }
             Q.push(x);
         }
     }
     LL sum = 0 ;
     while(!Q.empty())
         sum+=Q.top(),Q.pop();

     cout<<sum;

    return 0;
}


Measured memory_bytes: 1908
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <string>
#include <map>
#include <list>
using namespace std;

// int main() {
//   long long N,K;
//   cin >> N >> K;
//   long long a[N],b[N];
//   for(int i = 0; i < N; ++i) cin >> a[i] >> b[i];
//   long long bsum = 0;
//   for(int i = 0; i < N; ++i){
//     bsum += b[i];
//   }
//   long long air[bsum];
//   for(int i = 0; i < N; i += b[i]){
//     for(int j=0; j<b[i]; ++j){
//       air[i+j]=a[i];
//     }
//   }
//   sort(air,air + bsum-1);
//   cout << air[K-1] << endl;
// }


using ll = long long;
const int AMAX = 100000;
ll cnt[AMAX + 1];

int main(void) {
  int N;
  ll K;
  cin >> N >> K;

  for (int i = 0; i < N; ++i) {
    int A, B;
    cin >> A >> B;
    cnt[A] += B;
  }

  for (int ans = 1; ans <= AMAX; ++ans){
    if (K <= cnt[ans]) {
      cout << ans << endl;
      break;
    }
    K -= cnt[ans];
  }
  return 0;
}

Measured memory_bytes: 4360
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

class Solver {
};

int main() {
	while (true) {
		int w, h;
		cin >> w >> h;
		if (w == 0)break;

		vector<vector<vector<bool>>> movable(
			h, vector<vector<bool>>(w, vector<bool>(4, false)));
		for (int i = 0; i < 2 * h - 1; i++) {
			if (i % 2 == 0) {
				for (int j = 0; j < w - 1; j++) {
					int v;
					cin >> v;
					if (v == 0) {
						movable[i / 2][j][0] = true;
						movable[i / 2][j + 1][2] = true;
					}
				}
			}
			else {
				for (int j = 0; j < w; j++) {
					int v;
					cin >> v;
					if (v == 0) {
						movable[i / 2][j][3] = true;
						movable[i / 2 + 1][j][1] = true;
					}
				}
			}
		}

		vector<vector<int>> distance(h, vector<int>(w, 1e9));
		queue<tuple<int,int,int>> que;
		que.emplace(make_tuple(0, 0, 1));
		while (!que.empty()) {
			auto val = que.front();
			int y = get<0>(val);
			int x = get<1>(val);
			int d = get<2>(val);
			que.pop();
			if (d >= distance[y][x])continue;
			distance[y][x] = d;

			if (movable[y][x][0])que.emplace(make_tuple(y, x + 1, d + 1));
			if (movable[y][x][1])que.emplace(make_tuple(y - 1, x, d + 1));
			if (movable[y][x][2])que.emplace(make_tuple(y, x - 1, d + 1));
			if (movable[y][x][3])que.emplace(make_tuple(y + 1, x, d + 1));
		}
		if (distance[h - 1][w - 1] == 1e9) cout << 0 << endl;
		else cout << distance[h - 1][w - 1] << endl;
	}
}


Measured memory_bytes: 3200
module Main where

import Data.List
import Control.Monad
import Debug.Trace
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as = let
    (fo, la) = span f as
    las = case la of
        [] -> []
        xs -> split f $ tail xs
    in
        case fo of
            [] -> las
            xs -> xs : las

solve :: [Int] -> Int
solve ns = let
    all = sum $ do
        a <- ns
        b <- ns
        return $ a * b
    mine = sum $ (\a -> a* a) <$> ns
    in
        (all - mine) `div` 2
    

main = do
    _ <- readInt
    ns <- readInts
    print $ solve ns


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

int main(){
    
    int data[4][3][10]; //build,floor,room,value
    int record;

    memset(data,0,sizeof(data));
    cin >> record;

    for (int i = 0; i < record ; i++)
    {
        int b,f,r,v;
        cin >> b >> f >> r >> v;
        data[b-1][f-1][r-1] += v;
    }
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 10; k++)
            {
                cout << " " << data[i][j][k];
            }
            cout << endl;
        }
        if(i < 4-1){
          cout << "####################" << endl;
        }
    }

    
    return(0);
}


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

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

    if (A == B && B == C)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}

Measured memory_bytes: 256
include Math

def fetch_prime_list(max)
  list = (2..max).to_a
  prime_list = []
  sqrt = Math.sqrt(max).floor

  while val = list.shift
    prime_list << val
    if val > sqrt
      break
    end
    list.delete_if{|num| num % val == 0}
  end
  return prime_list.concat(list)
end

prime = fetch_prime_list(105000)
while true do
    n = gets.to_i
    if n == 0
        break
    end
   
    sum = 0
    for a in 0..n - 1 do
        c = prime[a]
        sum += c.to_i
    end
    puts sum
end



Measured memory_bytes: 8148
program test

integer(8) :: i,j,k,l,r,ll,rr,ans=10**9,new,sa

read(*,*) l,r

ll = mod(l,2019)
rr = mod(r,2019)

sa = r - l 

if(ll == 0 .or. rr == 0 .or. ll >= rr .or. sa >= 2019)then
  ans = 0
else
  do i=ll,rr-1
    do j=i+1,rr
      new = mod(i*j,2019)
      ans = min(new,ans)
    enddo
  enddo
endif

write(*,*) ans

end program

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

using namespace std;

#define long long long
#define INF 2e18
#define MOD (long) (1e9 + 7)
#define umap unordered_map

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

    long t = 1;
    //cin >> t;

    while (t--) {
        long n, m;
        cin >> n >> m;

        string s;
        s.resize(n);

        while (m--) {
            long d;
            char c;
            cin >> d >> c;
            if (not s[d-1]) {
                s[d-1] = c;
                if (d == 1 and n > 1 and c == '0') {
                    puts("-1");
                    return 0;
                }
            } else {
                if ((s[d-1] and s[d-1] != c)) {
                    puts("-1");
                    return 0;
                }
            }
        }
        for (auto &c : s) {
            if (not c) c = '0';
        }
        if (s[0] == '0' and n > 1) s[0] = '1';
        cout << s << endl;
    }
}


Measured memory_bytes: 3660