akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define fi first
#define se second

#define INF 2147483600

bool   dp[6][1000001];
bool dp2[38][1000001];

int main(){
  int n=1;
  vector<int> vec, vec2;
  int tmp=0;
  while(tmp<=1000000){
    tmp+=n*(n+1)/2;
    vec.pb(tmp);
    if(tmp%2==1) vec2.pb(tmp);
    n++;
  }
  // dp[i][j] : i???????????£???j?????°????????????
  dp[0][0]=true;
  repl(i,1,5+1){
    for(int upd : vec){
      rep(j, 1000001){
        dp[i][j] = dp[i][j] | dp[i-1][j];
        if(j-upd>=0 && dp[i-1][j-upd]) dp[i][j] = true;
      }
    }
  }
  dp2[0][0]=true;
  repl(i,1,38){
    for(int upd : vec2){
      rep(j, 1000001){
        dp2[i][j] = dp2[i][j] | dp2[i-1][j];
        if(j-upd>=0 && dp2[i-1][j-upd]) dp2[i][j] = true;
      }
    }
  }

  while(cin>>n, n){
    int res=1;
    while(dp[res][n]==false) res++;
    cout<<res<<" ";
    res=1;
    while(dp2[res][n]==false) res++;
    cout<<res<<endl;
  }
  return 0;
}

Measured memory_bytes: 44168
def solve(X, Y):
    T = Y - 2 * X
    if T < 0 or T % 2 != 0:
        return False
    T //= 2
    C = X - T
    if C < 0:
        return False
    return True


if __name__ == "__main__":
    X, Y = map(int, input().split())
    print("Yes" if solve(X, Y) else "No")


Measured memory_bytes: 9176
// Back and Forth
#include <iostream>
using namespace std;

int sx,sy,tx,ty;

int main(){
    cin>>sx>>sy>>tx>>ty;
    for(int i=sx;i<tx;i++){
        cout<<"R";
    }for(int i=sy;i<ty;i++){
        cout<<"U";
    }for(int i=sx;i<tx;i++){
        cout<<"L";
    }for(int i=sy;i<ty;i++){
        cout<<"D";
    }cout<<"L";
    for(int i=sy;i<ty+1;i++){
        cout<<"U";
    }for(int i=sx-1;i<tx;i++){
        cout<<"R";
    }cout<<"DR";
    for(int i=sy-1;i<ty;i++){
        cout<<"D";
    }for(int i=sx;i<tx+1;i++){
        cout<<"L";
    }cout<<"U\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  if (N % 2 == 0) {
    cout << N << endl;
  }else {
    cout << 2 * N << endl;
  }

  return 0;
}



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

int main() {
  
  int A, B, C; cin >> A >> B >> C; int ans = 0;
  
  for (int i = 0; i < 10000; i++) {
    
    if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1) {
      cout << ans << endl;
      return 0;
    }
    
    int tmpA = A; int tmpB = B; int tmpC = C;
    
    A = tmpB / 2 + tmpC / 2;
    B = tmpA / 2 + tmpC / 2;
    C = tmpA / 2 + tmpB / 2;
    
    ans++;
    
  }
  
  cout << -1 << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N >> M;
    if (N <= M) {
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }
}

Measured memory_bytes: 3636
/// Bismillahir Rahmanir Rahim

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define PI acos(-1)
#define IOS ios::sync_with_stdio(false);
using namespace std;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
int main()
{
    IOS
    int n;
    cin>>n;
    cout << (double)2*PI*n << endl;
    return 0;
}
///Alhamdulillah


Measured memory_bytes: 3808
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define pb push_back
 
#define limit (int) (2e5 +5)
#define mod (int) 1000000007

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
using ld = long double;

int a[limit];
int main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    
    int n;
    cin >> n;

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

    sort(a,a+n);

    lli ans = a[n-1];
    int ci = n-2;
 
    for (int i = n-3; i >= 0; i -= 2)
    {
        if (i == 0)
        {
            ans += a[ci];
            break;
        }
        ans += 2*a[ci];
        ci--;
    }

    cout << ans;
    return 0;
}
















Measured memory_bytes: 4408
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int A[] = new int[N];
		for (int i=0;i<M;i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			A[a-1]++;
			A[b-1]++;
		}
		for (int i =0;i<N;i++) {
			System.out.println(A[i]);
		}
	}
}

Measured memory_bytes: 36020
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false);
    ll n ; cin >> n;
    ll a = 1 , b = 1 , c = 1 , d = 1;
    for (int i = 1 ; i <= n ; i++) a = a * 10 % mod;
    for (int i = 1 ; i <= n ; i++) b = b * 8 % mod;
    for (int i = 1 ; i <= n ; i++) c = c * 9 % mod;
    c = (c - b + mod) % mod;
    cout << (a - ((2 * c) %mod) - (b%mod) + 2ll * mod) % mod << endl;
    return 0;
}


Measured memory_bytes: 3628
import java.util.*;
import java.lang.reflect.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int ans = 0;
        int a,b,c;
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        ans = a + b + c - Math.max(a,Math.max(b,c));
        System.out.print(ans);
    }
}

Measured memory_bytes: 21076
#include <iostream>
#include <fstream>
#include <random>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <map>
#include <algorithm>

using namespace std;

#define int int64_t

int binpow(int a, int pw, int mod) {
    if (pw <= 0) {
        return a;
    }
    if (pw % 2 == 0) {
        return binpow(a*a%mod, pw/2, mod);
    } else {
        return (binpow(a, pw-1,mod) * a)%mod;
    }
}


signed main() {

    //freopen("../input.txt", "r", stdin);

    ios::sync_with_stdio(false);
    cin.tie();
    cout.tie();

    int n, p;
    string s;
    cin >> n >> p >> s;

    int ans = 0;

    if (p == 2 || p == 5) {
        for (int i = 0; i < n; ++i) {
            if ((s[i] - '0') % p == 0) {
                ans += i + 1;
            }
        }
    } else {
        map<int, int> cnt;
        int tenPower = 1;
        int currRem = 0;

        cnt[0]++;

        for (int i = n - 1; i >= 0; --i) {
            currRem = (currRem + tenPower * (s[i] - '0')) % p;
            tenPower *= 10;
            tenPower %= p;

            ans += cnt[currRem];
            cnt[currRem]++;
        }

    }



    cout << ans;
    return 0;
}

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

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> numx(w + 1);
  vector<int> numy(h + 1);
  set<P> s;
  rep(i, m) {
    int hi, wi;
    cin >> hi >> wi;
    numx[wi]++;
    numy[hi]++;
    s.insert(make_pair(wi, hi));
  }
  int maxx = 0;
  int maxy = 0;
  for (int x : numx) maxx = max(x, maxx);
  for (int y : numy) maxy = max(y, maxy);
  vector<int> maxx_v;
  vector<int> maxy_v;
  rep(i, w + 1) {
    if (numx[i] == maxx) maxx_v.push_back(i);
  }
  rep(i, h + 1) {
    if (numy[i] == maxy) maxy_v.push_back(i);
  }
  for (int x : maxx_v) {
    for (int y : maxy_v) {
      if (s.count(make_pair(x, y)) == 0) {
        cout << maxx + maxy << endl;
        return 0;
      }
    }
  }

  cout << maxx + maxy - 1 << endl;
  return 0;
}

Measured memory_bytes: 23876
#include <iostream>
using namespace std;
int main() {
  int M,N;
  cin >> N >> M;
  int sum=0;
  if(N>=2){
    sum+=N*(N-1)/2;
  }
  if(M>=2){
    sum+=M*(M-1)/2;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use proconio::*;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    input! {
        c:[[isize;3];3],
    }

    let mut b = true;

    b = b && c[0][0] - c[0][1] == c[1][0] - c[1][1] && c[1][0] - c[1][1] == c[2][0] - c[2][1];
    b = b && c[0][1] - c[0][2] == c[1][1] - c[1][2] && c[1][1] - c[1][2] == c[2][1] - c[2][2];
    b = b && c[0][0] - c[1][0] == c[0][1] - c[1][1] && c[0][1] - c[1][1] == c[0][2] - c[1][2];
    b = b && c[1][0] - c[2][0] == c[1][1] - c[2][1] && c[1][1] - c[2][1] == c[1][2] - c[2][2];

    println!("{}", if b { "Yes" } else { "No" });
}


Measured memory_bytes: 2192
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

typedef long long ll;

int main(){
 ll L,R; cin >> L >> R;
  if( R - L >= 2019){ cout << 0 << endl; return 0;}
  else{
    for(ll i = L; i<= R; i++){
      if( i % 2019 == 0){ cout << 0 << endl; return 0;}}
    int ans = 1e8;
    for(ll i = L; i <= R - 1; i++){
      for(ll j = i + 1; j <= R; j++){
        int c = ( i * j ) % 2019;
        ans = min( ans , c) ;}}
    
    cout << ans << endl; return 0;} 
} 
      
      


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
 <url:https://github.com/kei1107/algorithm/blob/master/template/template_for_problems.cpp>
 ?????????============================================================
 n????????´??°a1, a2, ???, an??¨n????????´??°p1, p2, ???, pn?????´??°m?????????????????????
 k???????????´??°ak???pk[%]????¢??????§?????¶?????¨??????????????????k(1 ??? k ??? n)?????????????????????
 0?????\???n?????\????????´??°??????????????????1??\???m??\????????´??°????????§???
 ?????°????????´??°????°?????????¨???1?????§?????????????????????????????°????????????????±??????????
 =================================================================
 ?§£??¬=============================================================
 ????????????( := ????????????????????????)
 ================================================================
 
 
 <reference:http://d.hatena.ne.jp/simezi_tan/20130522/1369203086>
 
 ???????????????????????????????????? < rep(j, 0, n) if(j & (1 << i)) f[j] -= f[j ^ (1 << i)]; >
 ????????????????????????????????? <rep(j, 0, n) if(j & (1 << i)) f[j] += f[j ^ (1 << i)];>
 */

inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll n;
    long double m;
    cin >> n >> m;
    vector<ll> a(n);
    vector<long double> p(n);
    for(auto &x:a) cin >> x;
    for(auto &x:p) {
        cin >> x;
        x/=100;
    }
    
    // Preprocessing
    // probability
    // ??????????±???????????????????????????£??????????????????
    vector<long double> dp1((1<<n),1.0);
    for(int i = 0; i < n;i ++){
        for(int j = 0; j < (1<<n);j++){
            if((j>>i)&1){
                dp1[j] *= p[i];
            }else{
                dp1[j] *= (1-p[i]);
            }
        }
    }
    
    // ????????????????????????
    /* ?????????????????? +=??¨?????? -=???????????°??????*/
    vector<ll> dp2((1<<n),0);
    for(int i = 0; i <(1<<n);i++){
        ll LCM = 1;
        for(int j = 0; j < n;j++){
            if(LCM > m) break;
            if((i>>j)&1){
                ll tmp = a[j] / gcd(LCM,a[j]);
                if(1.0 * tmp * LCM < m + 1) LCM*=tmp;
                else LCM = m+1;
            }
        }
        dp2[i] = m/LCM;
    }
    for(int i = 0; i < n;i++){
        for(int j = 0;j < (1<<n);j++){
            if((j>>i)&1){
                dp2[j] -= dp2[j^1 << i];
            }
        }
    }
    
    long double res = 0;
    for(int i = 0; i < (1<<n);i++){
        res += dp1[i] * (m - abs(dp2[i])); // ??¶???????????¨???
    }
    cout << fixed << setprecision(10) << res << endl;
    return 0;
}

Measured memory_bytes: 27508
/** Author: Nicklaus **/
 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
typedef long double ld;

int main(){
	int n;
	cin>>n;
	int m=n/100;
	int y=n%100;
	if(m>0 && m<=12){
		if(y<=12 && y>0){
			cout<<"AMBIGUOUS";
		}else{
			cout<<"MMYY";
		}
	}else if(y>0 && y<=12){
		cout<<"YYMM";
	}else{
		cout<<"NA";
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
C = input()
cnt = 0
left = 0
right = N-1
while(left < right and left<=N-1):
  if(C[left] == 'W'):
    flag = 0
    while(left < right):
      if(C[right] == 'R'):
        cnt += 1
        right -= 1
        break
      right -= 1
  left += 1
print(cnt)

Measured memory_bytes: 67656
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890123456789LL
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

typedef long long cat;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

bool test(vector<int> &A, vector<int> &B, cat ans) {
	int N = A.size();
	for(int i = 0; i < N; i++) {
		vector<bool> reach(A[i]+1, 0);
		reach[A[i]] = 1;
		for(int j = A[i]; j >= 0; j--) if(reach[j]) {
			if(j == B[i]) break;
			for(int k = 0; k < 50; k++)
				if((ans>>k)&1) reach[j%(k+1)] = 1;
		}
		if(!reach[B[i]]) return false;
	}
	return true;
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	vector<int> A(N), B(N);
	for(int i = 0; i < N; i++) cin >> A[i];
	for(int i = 0; i < N; i++) cin >> B[i];
	for(int i = 0; i < N; i++) if(A[i] < B[i]) {
		cout << "-1\n";
		return 0;
	}
	cat ans = 0;
	int mxk = 50;
	while(true) {
		// sufficient as is?
		if(test(A, B, ans)) break;
		int k = 0;
		for(int nxtk = 1; nxtk <= mxk; nxtk++) {
			if(!test(A, B, ans+(1LL<<nxtk)-1)) continue;
			k = nxtk;
			break;
		}
		if(k == 0) {
			cout << "-1\n";
			return 0;
		}
		ans += 1LL<<(k-1);
		mxk = k-1;
	}
	cout << 2*ans << "\n";
	return 0;}

// look at my code
// my code is amazing


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

vector<int> to[200005];
vector<int> ans;

void dfs(int v, int p = -1){
  for(int u : to[v]){
    if(u == p)continue;
    ans[u] += ans[v];
    dfs(u, v);
  }
}

int main()
{
  int n, m; cin >> n >> m;
  rep(i, n-1){
    int a, b; cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(n);
  rep(i, m){
    int a, b; cin >> a >> b;
    a--;
    ans[a] += b;
  }
  dfs(0);
  rep(i, n){
    cout << ans[i] << endl;
  }
  system("pause");
}

Measured memory_bytes: 23680
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
     long long int a,b,c,d;
    cin>>a>>b>>c>>d;
    long long int x,y;
     long long int prod;
    x=max(a,b);
     long long int t=min(a,b);
    y=max(c,d);
     long long int m=min(c,d);
    long long int p=x*y;
    long long int o=x*m;
     long long int u=max(p,o);
    long long int h=t*y;
     long long  int j=t*m;
     long long int e=max(h,j);
    prod=max(u,e);
    cout<<prod<<endl;
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

/* #define MULTI_INPUT 0 */

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef MULTI_INPUT
    int T;
    cin >> T;
    for (int t = 0; t < T; ++t) {
        solve();
    }
#else
    solve();
#endif
    return 0;
}


Measured memory_bytes: 3636
#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;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


vector<LL> b(1<<17),l(1<<17),u(1<<17);
LL n,x;

bool f(LL m){
    LL e = m%x;
    LL k = m/x;
    vector<P> a;
    for (int i = 0; i < n; i++) {
        a.pb(mp((x-b[i])*u[i]+l[i]*b[i],i));
    }
    sort(RALL(a));
    LL sum = 0;
    for (int i = 0; i < k; i++) {
        sum += a[i].fs;
    }
    for (int i = 0; i < n; i++) {
        sum -= b[a[i].sc]*l[a[i].sc];
    }
    if(e==0) return sum>=0;
    for (int i = 0; i < n; i++) {
        int nx = a[i].sc;
        if(i<k){
            sum-=a[i].fs-b[nx]*l[nx];
            sum+=a[k].fs;
            if(e>=b[nx]){
                sum+=(e-b[nx])*u[nx];
                if(sum>=0) return true;
                sum-=(e-b[nx])*u[nx];
            }
            else{
                sum+=(e-b[nx])*l[nx];
                if(sum>=0) return true;
                sum-=(e-b[nx])*l[nx];
            }
            sum+=a[i].fs-b[nx]*l[nx];
            sum-=a[k].fs;
        }
        else{
            sum+=l[nx]*b[nx];
            if(e>=b[nx]){
                sum+=(e-b[nx])*u[nx];
                if(sum>=0) return true;
                sum-=(e-b[nx])*u[nx];
            }
            else{
                sum+=(e-b[nx])*l[nx];
                if(sum>=0) return true;
                sum-=(e-b[nx])*l[nx];
            }
            sum-=l[nx]*b[nx];
        }
    }
    return false;
}


int main(){
    cin >> n >> x;
    LL sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> b[i] >> l[i] >> u[i];
        sum+=b[i];
    }
    LL ll=-1,rr=sum;
    while(abs(rr-ll)>1){
        LL mm = ll+(rr-ll)/2;
        if(f(mm)) rr = mm;
        else ll = mm;
    }
    cout << rr << endl;
    return 0;
}


Measured memory_bytes: 7508
#include<iostream>
#include<string>
#include<array>
#include<algorithm>
#include<deque>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<list>

int main(void) {
	using namespace std;
	int a;
	bool res = true;
	vector<int>vec;
	for (int i = 0; i < 4;i++) {
		cin >> a;
		vec.push_back(a);
	}
	sort(vec.begin(), vec.end());
		
			if (vec[0] != 1) {
				res = false;
			}
			if (vec[1] != 4) {
				res = false;
			}
			if (vec[2] != 7) {
				res = false;
			}
			if (vec[3] != 9) {
				res = false;
			}

			if (res == true) {
				cout << "YES" << endl;
			}
			else {
				cout << "NO" << endl;
			}
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        boolean[][] having = new boolean[4][13];
        String[] nameOfSuit = {"S", "H", "C", "D"};
        int num = sc.nextInt();
        int i;
        String suit;
        int rank;
        for (i = 0; i < num; i++) {
            suit = sc.next();
            rank = sc.nextInt();
            if (suit.equals(nameOfSuit[0])) having[0][rank - 1] = true;
            else if (suit.equals(nameOfSuit[1])) having[1][rank - 1] = true;
            else if (suit.equals(nameOfSuit[2])) having[2][rank - 1] = true;
            else if (suit.equals(nameOfSuit[3])) having[3][rank - 1] = true;
        }
        int s, r;
        for (s = 0; s < 4; s++) {
            for (r = 1; r <= 13; r++) {
                if (having[s][r - 1] == false) {
                    System.out.println(nameOfSuit[s] + " " + r);
                }
            }
        }
    }
}


Measured memory_bytes: 26120
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    vector<ll> dp(N + 1);
    // dp[i]:=i日目終了時の最大のお金
    dp[0] = 1000;
    for(int i = 1; i <= N; i++) {
        for(int j = 0; j < i; j++) {
            dp[i] = max(dp[i], dp[j]);
            for(int k = j + 1; k <= i; k++) {
                ll kabu = dp[j] / A[k - 1];
                ll rest = dp[j] % A[k - 1];
                for(int l = k + 1; l <= i; l++) {
                    dp[i] = max(dp[i], kabu * A[l - 1] + rest);
                }
            }
        }
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 3620
from pprint import pprint
from collections import deque

def bfs(sy,sx):
    que = deque()
    que.append([sy,sx])
    checked_map = [[-1]*w for _ in range(h)]
    checked_map[sy][sx] = 0

    dyx = [[1,0],[-1,0],[0,1],[0,-1]]

    while que:
        y,x = que.popleft()
        if y == gy and x == gx:
            return checked_map[gy][gx]
        for d in dyx:
            ny = y + d[0]
            nx = x + d[1]
            #正常に進むパターン
            if 0 <= ny <= h-1 and 0 <= nx <= w-1 and s[ny][nx] == "." and (checked_map[ny][nx] == -1 or checked_map[ny][nx] -1 > checked_map[y][x]):
                checked_map[ny][nx] = checked_map[y][x] + 1
                que.append([ny,nx])
            else:
                continue
    #gy,gxにたどり着けない場合は、queが空になってwhile queが終了する。
    else:
        return -1





h,w = map(int,input ().split())

s = [list(input()) for _ in range(h)]


sy = 0
sx = 0
gy = h-1
gx = w-1

flg = bfs(sy,sx)

if flg == -1:
    print(-1)
    exit()
else:
    counter = 0
    for line in s:
        counter += line.count(".")
    #全部の白の数から最短経路を引いた値が黒に変更できる数である。ただしスタート地点の分もカウントするためマイナス１する。
    result = counter - flg - 1
    #print(counter)
    #print(flg)
    print(result)
    


Measured memory_bytes: 40304
import java.io.*;
import java.util.*;
class Main{
    public static void main(String[] args)throws IOException{
	String a;
	int b;
	InputStreamReader isr=new InputStreamReader(System.in);
	BufferedReader br =new BufferedReader(isr);
	a= br.readLine();
	while(a!=null){
	    StringTokenizer st = new StringTokenizer(a);
	    b=Integer.parseInt(st.nextToken())+Integer.parseInt(st.nextToken());
	    b=(int)Math.log10(b)+1;
	    System.out.println(b);
	    a=br.readLine();
	    }
}
}

Measured memory_bytes: 17040
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

long long solve(int n, int m, priority_queue<long long> que){
    long long tmp;
    for(int i=0; i<m; ++i){
        tmp = que.top(); que.pop();
        que.push(tmp/2);
    }

    long long res=0;
    while(!que.empty()){
        res += que.top(); que.pop();
    }

    return res;
}

int main(){
    int N, M; cin >> N >> M;
    long long A;
    priority_queue<long long> que;

    for(int i=0; i<N; ++i){
        cin >> A; que.push(A);
    }

    long long res = solve(N, M, que);

    cout << res << endl;
}

Measured memory_bytes: 1908
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;

    if (b % a == 0)
    {
        cout << a+b << endl;
    } else {
        cout << b-a << endl;
    }

    return 0;
}

Measured memory_bytes: 256
public class Main {
	public static void main(String[] args) {
		for (int i = 1; i <= 9; i++) {
			for (int j = 1; j <= 9; j++) {
				int ans = i * j;
				System.out.println(i + "x" + j + "=" + ans);
			}
		}
	}
}

Measured memory_bytes: 16852
#include <iostream>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

int main(){
  while(1){
    int N;
    cin >> N;
    if(N==0) break;
    int x,y,map[100][100]={};
    rep(i,N){
      cin >> x >> y;
      map[y][x] = 1;
    }
    int Rx = 10,Ry = 10,tr = 0;
    int M;
    cin >> M;
    rep(i,M){
      string v;
      int d;
      cin >> v >> d;
      if(v == "N"){
	rep(j,d){ 
	  Ry++;
	  if( map[Ry][Rx] == 1){
	    tr += map[Ry][Rx];
	    map[Ry][Rx]--;
	  }
	}
      }
      else if(v == "E"){
	rep(j,d){ 
	  Rx++;
	  if( map[Ry][Rx] == 1){
	    tr += map[Ry][Rx];
	    map[Ry][Rx]--;
	  }
	}
      }
      else if(v == "S"){
	rep(j,d){ 
	  Ry--;
	  if( map[Ry][Rx] == 1){
	    tr += map[Ry][Rx];
	    map[Ry][Rx]--;
	  }

	}
      }
      else if(v == "W"){
	rep(j,d){ 
	  Rx--;
	  if( map[Ry][Rx] == 1){
	    tr += map[Ry][Rx];
	    map[Ry][Rx]--;
	  }

	}
      }
    }
    if(tr == N) cout << "Yes\n";
    else cout << "No\n";
  }
  return 0;
}

Measured memory_bytes: 1216
d = int(input())
c = [int(i) for i in input().split()]
s = [[int(i) for i in input().split()] for j in range(d)]

#t = [int(input()) for i in range(d)]

for i in range(d):
    print(1)
    
exit()

ans = []
last = [[0 for i in range(26)] for j in range(27)]
tmp_ans = [0]*26

for i in range(1,d+1):
    tmp_num = 0
    for j in range(26):
        tmp_ans[j] += s[i-1][j]
        last[j+1][j] = i
        for k in range(26):
            tmp_ans[j] -= (i-last[j+1][k])*c[k]
    idx = tmp_ans.index(max(tmp_ans))
    for j in range(26):
        for k in range(26):
            if k == idx:
                continue
            last[k][j] = last[idx][j]
    print(idx+1)
    #print(tmp_ans)
#print(ans)
    """
            
    ans += s[i-1][t[i-1]-1]
    last[t[i-1]-1] = i
    for j in range(26):
        ans -= (i-last[j])*c[j]
    print(ans)
    """
    


Measured memory_bytes: 9388
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int n;
int ans = 0;
vector<vector<int>> G;
vector<bool> seen;
map<P, int> mp;

void dfs(int v, int used) {
    debug(v, used);
    int color = 0;
    seen[v] = true;
    for(const auto& nv: G[v]) {
        if (seen[nv]) continue;
        if (color == used) color++;
        if (v<nv) mp[{v,nv}] = color;
        else mp[{nv, v}] = color;
        debug(v, nv, used, color);
        dfs(nv, color);
        color++;
    }
    chmax(ans, color);
}

int main() {
    cin >> n;
    G.resize(n);
    seen.assign(n, false);
    vector<P> edges(n-1);
    rep(i, n-1) {
        int x, y; cin >> x >> y;
        x--; y--;
        G[x].push_back(y);
        G[y].push_back(x);
        edges[i] = {x, y};
    }
    // print(G);
    dfs(0, -1);
    cout << ans << endl;
    for(const auto& p: edges) {
        cout << mp[{p.fi, p.se}]+1 << endl;
    }
}

Measured memory_bytes: 14080
n,m,x,y=map(int,input().split())
lx=list(map(int,input().split()))
ly=list(map(int,input().split()))
z=max(lx)+1 if max(lx)>=x else x+1

if min(ly)<z or y<z:
  print("War")
  
else:
  print("No War")

Measured memory_bytes: 9080
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    string s;
    int ans = 0;
    cin >> s;
    rep(i, 6)if(s[i] == '1')++ans;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
<?php
$w = trim(fgets(STDIN));

$counts = [];
for ($i = 0; $i < strlen($w); $i++) {
  $c = $w[$i];
  if (isset($counts[$c])) {
    $counts[$c]++;
  } else {
    $counts[$c] = 1;
  }
}

$beauty = array_reduce($counts, function($carry, $v) {
  return $carry & ($v % 2 === 0);
}, true );

echo $beauty ? "Yes\n" : "No\n";

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

using namespace std;
using ll = long long;


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

	int cnt = 0;
	for(int i = 1; i < 200; i++) {
		for(int j = 0; j < n; j++) {

			if(a[j] >= i && a[j + 1] < i)cnt++;

		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
ll C,D,E,F,N,M;
string S,T;
ll num=0,ans=0,cnt=0;
ll i,j,z;
bool f=false;
int main()
{
  cin>>N>>M>>C;
  ll A[100][100];
  ll B[100];
  for(i=0;i<M;i++) cin>>B[i];
  for(i=0;i<N;i++){
    for(j=0;j<M;j++){
      cin>>num;
      ans+=num*B[j];
    }
    //cout<<ans+C<<endl;
    if(ans+C>0) cnt++;
    ans=0; 	
  }
  cout<<cnt<<endl;
}


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

typedef pair<int,int> P;
int M,N;

struct state{
  int k;
  int maxi[101],mini[101];
  void init(){
    for(int j=1;j<=N;j++){
      maxi[j] = 100;
      mini[j] = 0;
    }
  }
  bool check(){
    for(int i=1;i<=N;i++){
      if( maxi[i] < mini[i] ) return false;
    }
    return true;
  }
};

state S[101];

bool check(const state &s1, const state &s2){
  for(int i=1;i<=N;i++){
    if( s1.mini[i] > s2.maxi[i] ) return false;
  }
  return true;
}

vector<int> G[101];
int nG[101];



int main(){
  cin >> M >> N;
  bool f = true;
  for(int i=0;i<M;i++){
    S[i].init();
    cin >> S[i].k;
    for(int j=0;j<S[i].k;j++){
      int s,t;string c;
      cin >> s >> c >> t;
      if( c == "<=" ){
        S[i].maxi[s] = min(S[i].maxi[s],t);
      } else {
        S[i].mini[s] = max(S[i].mini[s],t);
      }
    }
    if( !S[i].check() ) f = false;
  }

  if( !f ) {
    cout << "No" << endl;
    return 0;
  }

  for(int i=0;i<M;i++){
    for(int j=0;j<M;j++){
      if( i == j ) continue;
      if( check(S[i],S[j]) )
        G[i].push_back( j );
    }
  }

  //kokomade_

  for(int i=0;i<M;i++) nG[i] = G[i].size();
  int T = M-1;
  bool used[111]={};
  while( T ){
    vector<P> pr;
    for(int i=0;i<M;i++){
      if(!used[i]) pr.push_back( P(nG[i],i) );    
    }
    sort(pr.begin(),pr.end());

    if( pr.back().first >= T ){
      used[pr.back().second] = true;
      for(int i=0;i<M;i++){
        for(int j=0;j<(int)G[i].size();j++){
          int to = G[i][j];
          if( to == pr.back().second ) {
            nG[i]--;
          }
        }
      }
    } else {
      f = false;
      break;
    }
    --T;
  }
  if( f ) cout << "Yes" << endl;
  else cout << "No" << endl;

  

}

Measured memory_bytes: 1368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef string str;
static const long long INF = 1LL<<59;
static const long long MOD = (ll)1e9+7;

#define endl "\n"
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define REP(i, n) for(ll i=0;i<n;i++)
#define SZ(v) (ll)((v).size())
#define WHOLE(v) (v).begin(), (v).end()
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse((v).begin(), (v).end())
#define FOLDL(src, dst, lambda) partial_sum((src).begin(), (src).end(), (dst).begin(), lambda)
#define FOLDR(src, dst, lambda) INV(src);partial_sum((src).begin(), (src).end(), (dst).begin(), lambda);INV(dst)
#define CUMSUML(src, dst) FOLDL(src, dst, [](auto a, auto b) {return a+b;})
#define CUMSUMR(src, dst) FOLDR(src, dst, [](auto a, auto b) {return a+b;})
#define ACCUM(v, d0, lambda) accumulate((v).begin(), (v).end(), d0, lambda)
#define SUM(v, d0) ACCUM(v, d0, [](auto a, auto b) {return a+b;})
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) ASC(v);v.erase(unique(v.begin(), v.end()), v.end())

template <typename T>void debug(T t) {cerr << t << endl;}
template <typename T, typename ...Args>void debug(T t, Args ...args) {cerr << t << " ";debug(args...);}
template <typename T>void out(T t) {cout << t << endl;}
template <typename T, typename ...Args>void out(T t, Args ...args) {cout << t << " ";out(args...);}

void solve() {
    ll N, K;
    cin >> N >> K;
    vll A(N), B(N);
    REP(i, N) cin >> A[i] >> B[i];
    vll Ks;
    Ks.push_back(K);
    ll bit = 0;
    ll tmp = K;
    while(tmp >= 1) {
        tmp >>= 1;
        bit++;
    }
    for(ll k = bit; k >= 0; k--) {
        ll mask = ~(1 << k);
        ll p = 0;
        for(ll q = k - 1; q >= 0; q--) {
            p |= (1 << q);
        }
        if (((K&mask)|p) <= K)
            Ks.push_back((K&mask)|p);
    }
    UNIQ(Ks);
    ll ans = -INF;
    for(auto &k:Ks) {
        ll tmp = 0;
        REP(i, N) {
            if((k|A[i])==k) {
                tmp+=B[i];
            }
        }
        ans = max(ans, tmp);
    }
    out(ans);
}

int main() {
    fast_io;
    solve();
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

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

  int ans = 1;
  string prev = s.substr(0, 1);
  string cur;
  for (int i = 1; i < s.size(); ++i) {
    cur += s[i];
    if (prev == cur) continue;
    prev = cur;
    cur = "";
    ans++;
  }

  cout << ans << endl;
  
  return 0;
}

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

signed main() {
    int n, d, ans;
    map<int, int> mochi;

    cin >> n;
    ans = 0;
    for ( int i = 0; i < n; i++ ) {
        cin >> d;
        if (mochi[d] < 1) {
            ans++;
        }
        mochi[d] = 1;
    }

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

Measured memory_bytes: 3596
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    ll n, m;
    cin >> n >> m;
    if (n > m) swap(n, m);
    if (n == 1) {
        cout << 1;
        return 0;
    }
    ll sum = n * m;
    cout << sum / 2 + sum % 2;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = str(input())

r = S.count("R")
g = S.count("G")
b = S.count("B")
ans = r*g*b

for aida in range(1, (N//2)+5):
  for i in range(N):
    if i + 2*aida >= N:
      break
    if S[i]!=S[i+aida] and S[i+aida]!=S[i+2*aida] and S[i]!=S[i+2*aida]:
      ans += -1
print(ans)

Measured memory_bytes: 9212
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int a, b, n;
	cin >> a >> b  >> n;
	int val = min(b - 1,  n);
	cout << (a * val) / b;
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    ll n,k,sum=0;
    cin >> n >> k;
    vll x(n);
    rep(i,n){
        cin >> x[i];
        sum += 2*(min(x[i],abs(x[i]-k)));
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 636
import scala.io.{StdIn => in}
import scala.collection.{mutable => mu}

object Main extends App {
  val Array(d, n) = in.readLine.split(" ").map(_.toInt)
  val n2 = math.pow(100,d).toInt
  def rec(acc:Int, cnt:Int, num:Int):Int = {
    if(cnt == n) acc
    else if((acc/n2)%n2 != 0) rec(acc+num, cnt+1, num)
    else rec(acc+num, cnt, num)
  }
  val ans = (if(d == 0) n else rec(0,1,n2)) + (if(n==100) n2 else 0)
  println(ans)
}

Measured memory_bytes: 27332
#include<stdio.h>
#include<string.h>
#define LEN 1001
void print(char[],int,int);
void reverse(char[],int,int);
void replace(char[],int,int,char[]);
int main(void)
{
  int i,n;
  int a,b;
  char str[LEN];
  char op[10];
  char rep[LEN];
  scanf("%s",str);
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%s",op);
      scanf("%d%d",&a,&b);
      if(strcmp(op,"print")==0) print(str,a,b);
      if(strcmp(op,"reverse")==0) reverse(str,a,b);
      if(strcmp(op,"replace")==0)
        {
          scanf("%s",rep);
          replace(str,a,b,rep);
        }
    }
  return 0;

}
void print(char str[],int a,int b)
{
  char temp=str[b+1];
  str[b+1]='\0';
  printf("%s\n",str+a);
  str[b+1]=temp;
}
void reverse(char str[],int a,int b)
{
  int i;
  int n=b-a+1;
  char temp;
  char tempStr[LEN];
  for(i=0;i<n;i++) tempStr[i]=str[b-i];
  tempStr[n]='\0';
  temp=str[b+1];
  strcpy(str+a,tempStr);
  str[b+1]=temp;
}
void replace(char str[],int a,int b,char rep[])
{
  char temp=str[b+1];
  strcpy(str+a,rep);
  str[b+1]=temp;
}


Measured memory_bytes: 2088
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	int n; cin >> n;
	bool ok = true;
	int ans = 0;
	rep (i, n ){
		char p; int x; cin >> p >> x;
		ans += (p == '(' ? x : -x );
		if (ans < 0 ){
			ok = false;
			break;
		} // end if
	} // end rep

	if (ans != 0 ) ok = false;

	if (ok ){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	} // end if		
	return 0;
}

Measured memory_bytes: 1192
N, M = gets.split.map(&:to_i)
A = gets.split.map{|x| x.to_i % M}

B = Hash.new(0)
B[0] = 1
ans = 0
tot = 0
A.each do |a|
  tot = (tot + a) % M 
  ans += B[tot]  
  B[tot] += 1
end

puts ans

Measured memory_bytes: 12164
/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

clock_t time_p=clock();
void aryanc403()
{
#ifdef ARYANC403
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
#endif
}

#ifdef ARYANC403
#include "/home/aryan/codes/PastCodes/header.h"
#else
    #define dbg(args...)
#endif

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    string s;
    vi a;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>n;
    a.clear();a.reserve(n);

    fo(i,n)
    {
        cin>>in;
        a.pb(in);
    }

    sort(all(a));
    lli ans=0;

    if(n==1)
        ans+=a[0];
    else if(n==2)
    {
        ans+=3*a[0];
        ans+=2*a[1];
        ans%=mod;
    }
    else if(n>2)
    {
        reverse(all(a));
        fo(i,n)
        {
            ans+=(i+2)*a[i]%mod;
            ans%=mod;
        }

        fo(i,n-2)
            ans=(ans*2)%mod;
    }

    fo(i,n)
        ans=(ans*2)%mod;
    ans%=mod;ans+=mod;ans%=mod;
    cout<<ans<<endl;
}   aryanc403();
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<deque>
using namespace std;

int main() {

     
    double a, b, c, d, e, f;

    while ( cin >> a >> b >> c >> d >> e >> f ) {
        double det = a * e - b * d;
        double x = (c * e - b * f) / det + 0.0;
        double y = (a * f - c * d) / det + 0.0;
        printf("%.3f %.3f", x, y);
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main() {
	long long int N, a[5], sum, min = 1000000000000000, i;

	scanf("%lld", &N);
	for (i = 0; i < 5; i++) {
		scanf("%lld", &a[i]);
		if (a[i] <= min) {
			min = a[i];
		}
	}

	sum = 4;
	sum = sum + N / min;
	if (N % min != 0) sum++;

	printf("%lld", sum);

	return 0;
}

Measured memory_bytes: 128
N = int(input())
s = [input() for _ in range(N)]
bucket = {}

for i in range(N):
  if s[i] in bucket:
    bucket[s[i]].append(s[i])
  else:
    bucket[s[i]] = []

Max = 0
Max_key = []
for i in bucket:
  if Max < len(bucket[i]):
    Max = len(bucket[i])

for i in bucket:
  if Max == len(bucket[i]):
    Max_key.append(i)

Max_key.sort()
for i in Max_key:
  print(i)

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

int main()
{
    int a, b;
    for (int i = 1;;)
    {
        cin >> a >> b;
        if(a == 0 && b==0) break;
        if(a>b) swap(a,b);
        cout << a << " "<<b << endl;
    }
    return 0;
}


Measured memory_bytes: 3064