akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    var(int, N, M);

    vector<i64> a(N);
    read(a);
    sort(all(a));

    vector<pii> ps(M);
    rep(i, 0, M) {
        var(int, b, c);
        ps[i] = { c, b };
    }
    sort(all(ps), greater<>());

    int i = 0;
    for (const auto &e : ps) {
        const int C = e.first;
        const int B = e.second;
        rep(_, 0, B) {
            if (i >= N) break;
            if (a[i] > C) break;
            a[i] = C;
            ++i;
        }
    }

    print(accumulate(all(a), 0LL));

    return 0;
}


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

using namespace std;

int main(int argc, char** argv) {
  int diff = -1e9-1;

  int minv;
  cin >> minv; // drop 1st line
  cin >> minv;

  int n;
  while (cin >> n) {
    if (diff < n - minv) {
      diff = n - minv;
    }
    if (n < minv) {
      minv = n;
    }
  }
  cout << diff << endl;
  return 0;
}



Measured memory_bytes: 3108
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
struct Combination{
private:
    ll N;
    vector<ll> fac, facinv;

public:
    Combination(ll n){
        N = n;
        fac.push_back(1); fac.push_back(1);
        rep(i,2,N+1) fac.push_back(fac[i-1] * i % MOD);
        rep(i,0,N+1) facinv.push_back(power(fac[i], MOD-2));
    }
    ll power(ll x, ll n){
        if(n == 0) return 1LL;
        ll res = power(x * x % MOD, n/2);
        if(n % 2 == 1) res = res * x % MOD;
        return res;
    }
    ll nck(ll n, ll k){
        if(k == 0 || n == k) return 1LL;
        return fac[n] * facinv[k] % MOD * facinv[n-k] % MOD;
    }
    ll npk(ll n, ll k){
        if(k == 0 || n == k) return 1LL;
        return fac[n] * facinv[n-k] % MOD;
    }
    ll get(ll x){return fac[x];};
    ll getinv(ll x){return facinv[x];};
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll x[100010];
    rep(i,0,N) cin >> x[i];
    Combination cb(100010);
    ll inv_val[100010] = {};
    rep(i,1,N+1){
        inv_val[i] = cb.power(i, MOD-2);
    }
    ll diff[100010] = {};
    ll v = cb.get(N-1);
    rep(i,0,N-2){
        ll nn = i+2;
        v *= inv_val[nn];
        v %= MOD;
        diff[i] = v;
        v *= nn;
        v %= MOD;
    }
    ll ans = 0;
    ll tt = cb.get(N-1);
    rep(i,0,N-1){
        ans += (x[i+1] - x[i]) * tt % MOD;
        ans %= MOD;
        if(i != N-2) tt = (tt + diff[i]) % MOD;
    }
    print(ans);



    

}

Measured memory_bytes: 4852
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lb long double
#define pb push_back
#define qwerty1 first
#define qwerty2 second
#define qwerty3 -> first
#define qwerty4 -> second
#define umap unordered_map
#define uset unordered_set
#define pii pair < int , int >

using namespace std;

const int N = 100005;
const int M = 1000000007;
const lb PI = acos(-1);

int t , n;
char s[N] , s1[N] , s2[N];

void Test()
{
    cin >> s;

    int i , ans = 0;

    s1[0] = '1';
    s2[0] = '0';

    n = strlen(s);

    for(i = 1 ; i < n ; i++)
    {
        s1[i] = 1 - (s1[i - 1] - '0') + '0';
        s2[i] = 1 - (s2[i - 1] - '0') + '0';
    }

    int p1 = 0 , p2 = 0;

    for(i = 0 ; i < n ; i++)
        if(s1[i] != s[i])
            ++p1;

    for(i = 0 ; i < n ; i++)
        if(s2[i] != s[i])
            ++p2;

    cout << min(p1 , p2);
}

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

    t = 1;

	while(t--)
		Test();

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int seven_count(int, int);

bool check_753(int);

int main(){
    int N;
    cin >> N;
    int ans = seven_count(0, N);
    cout << ans << endl;
}

int seven_count(int a, int N){
    if(a > N or a < 0) return 0;
    else if(check_753(a)) return 1 + seven_count(a*10 + 3, N) + seven_count(a*10 + 5, N)
+ seven_count(a*10 + 7, N);
    else return seven_count(a*10 + 3, N) + seven_count(a*10 + 5, N)
+ seven_count(a*10 + 7, N);
}

bool check_753(int a){
    bool check7, check5, check3;
    check7 = check5 = check3 = false;
    while(a != 0){
        if(a%10 == 7) check7 = true;
        else if(a%10 == 5) check5 = true;
        else if(a%10 == 3) check3 = true;
        a /= 10;
    }
    return check7 and check5 and check3;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#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 Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if  (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    ll n;
    cin >> n;
    vll v(n+1);
    v[0]=0;
    for(int i=1;i<=n;i++){
        v[i]=v[i-1]+1;
        for(int j=1;i-pow(6,j)>=0;j++){
            v[i]=min(v[i],v[i-pow(6,j)]+1);
        }
        for(int j=1;i-pow(9,j)>=0;j++){
            v[i]=min(v[i],v[i-pow(9,j)]+1);
        }
    }
    cout << v[n] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int x;
int y;
int s;


int cal_tax(int value, int rate) {
  return value * (100 + rate) / 100;
}

int cal_max() {
  int result = 0;
  for (int a = 1; a < s; a++) {
    for (int b = 1; b < s; b++) {
      if (cal_tax(a, x) + cal_tax(b, x) == s) {
	if (cal_tax(a, y) + cal_tax(b, y) > result) {
	  result = cal_tax(a, y) + cal_tax(b, y);
	}
      }
    }
  }
  return result;
}

int main() {
  while (cin >> x >> y >> s && x != 0) {
    cout << cal_max() << endl;
  }
}


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

int N; string s,t;

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

    int i,j;
    for (i=0; i<N; i++){
        for (j=0; j<N-i; j++)
            if (s[i+j]!=t[j]) break;

        if (j==N-i){
            cout << N+i << "\n";
            return 0;
        }
    }

    cout << 2*N << "\n";

    return 0;
}


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

int main() {
	int N, L;
	cin >> N >> L;
	vector<int> vec(N);

	for (int i = 0; i < N; i++)
		vec.at(i) = L + i;

	int j;

	if (L >= 0)
		j = vec.at(0);
	else if (N + L - 1 <= 0)
		j = vec.at(N - 1);
	else
		j = 0;

	int sum = (2 * L + N - 1) * N / 2;
	cout << sum - j << endl;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, ns, ne) for (int i = ns; i < ne; ++i)
using namespace std;
using ULL = unsigned long long;
int main() {
  ULL N, a, b, west, east, chk, ans = 0;
  cin >> N >> a >> b >> west;
  rep(i, 1, N) {
    cin >> east;
    chk = (east - west) * a;
    if (chk > b) {
      ans += b;
    } else {
      ans += chk;
    }
    west = east;
  }
  cout << ans << endl;
  getchar();
}

Measured memory_bytes: 3532
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {

	public static void main(String[] args)throws java.lang.Exception
    {		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n =Integer.parseInt(br.readLine());
		System.out.println(n%1000==0?0:1000-n%1000);
	}

}


Measured memory_bytes: 32648
n=int(input())
from collections import Counter
a=Counter(list(map(int,input().split())))
l=[]
ll=[]
ans=0
for i in a:
    if a[i]>=2:
        l.append(i)
    if a[i]>=4:
        ans=max(ans,i*i)
l.sort(reverse=True)
if len(l)<2:
    print(0)
else:
    print(max(l[0]*l[1],ans))


Measured memory_bytes: 18600
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let n = input::<i64>();
    let xu = (0..n)
        .map(|_| {
            let x = input();
            let u = input();
            (x, u)
        })
        .collect::<Vec<(f64, String)>>();

    let ans = xu
        .iter()
        .map(|&(x, ref u)| if u == "JPY" { x } else { x * 380000.0 })
        .sum::<f64>();
    println!("{}", ans);
}


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


#define M_MAX 20
#define N_MAX 50000
#define INFTY 1 << 29

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

}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  string S;
  cin >> S;
  int Q;
  cin >> Q;
  vector<int> k(Q);
  rep(i, 0, Q) { cin >> k[i]; }

  for (auto kk : k) {
    int ans = 0, d = 0, m = 0, dm = 0;
    rep(i,0,N){
      if(S[i]=='D'){
        d++;
      }
      else if(S[i]=='M'){
        m++;
        dm+=d;
      }
      else if(S[i]=='C'){
        ans+=dm;
      }

      int a=i-kk+1;
      if(a>=0){
        if(S[a]=='D'){
          d--;
          dm-=m;
        }
        else if(S[a]=='M'){
          m--;
        }
      }
    }
    cout<<ans<<endl;
  }

  return 0;
}


Measured memory_bytes: 1948
#include<bits/stdc++.h>
using namespace std;
#define mx 100000
#define md 1000000007ll
int main(){

    int n;
    cin>>n;
    pair<pair<string,int>,int >ar[n+3];

    for(int i=1;i<=n;i++){
        cin>>ar[i].first.first>>ar[i].first.second;
        ar[i].first.second*=-1;
        ar[i].second=i;
    }

    sort(ar+1,ar+n+1);

    for(int i=1;i<=n;i++)cout<<ar[i].second<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main()
    {
        int count = int.Parse(Console.ReadLine());
        string[] raw = Console.ReadLine().Split(' ');
        for (int i = count - 1; i > 0; i--) Console.Write(raw[i] + " ");
        Console.WriteLine(raw[0]);
    }
}

Measured memory_bytes: 5304
N=int(input())
graphs = [['' for x in range(2*N)] for x in range(2*N)]
for i in range(N):
  x,y=map(int,input().split())
  graphs[x][y] = 'r'
for j in range(N):
  x,y=map(int,input().split())
  graphs[x][y] = 'b'
rqueue = []
count = 0
for k in range(2*N):
  for l in range(2*N):
    if graphs[k][l] == 'r':
      rqueue.append(tuple([k,l]))
      rqueue.sort(key=lambda x:x[1],reverse=True)
    elif graphs[k][l] == 'b':
      for m in range(len(rqueue)):
        if rqueue[m][0] < k and rqueue[m][1] < l:
          rqueue.pop(m)
          count += 1
          break
print(count)

Measured memory_bytes: 3316
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

f("ABC", X) :- X =< 999, !.
f("ABD", X).

main :-
	get_number(N),
    f(X, N),
    writeln(X).


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

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

    int ans = 0;
    int n = s.length();
    char t = '.';
    for(int i=0; i<n; i++){
        ans += 1;

        if(t == s[i]){ t = '.'; i += 1; if(i >= n) ans -= 1; }
        else t = s[i];
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int N, L;
    cin >> N >> L;
    int sum = (L-1) * N + N * (1 + N) / 2;
    if(L > 0){
        cout << sum - L << endl;
    }else if(L + N - 1 < 0){
        cout << sum - L - N + 1 << endl;
    }else{
        cout << sum << endl;
    }
    return 0;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second

//int dxy[5] = {0, 1, 0, -1, 0};
// assign avl ncm dijkstra geo2 kruskal graph uf lca BIT
// matrix dinic next_combination topcoder lcm

signed main()
{
    string st;
    cin >> st;
    if (st[0] == st[2]) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
int main(){
	string a;
  int n;
  cin>>n;
	cin>>a;
	if(a.substr ( 0 , a.length()/2 )==a.substr ( a.length()/2 ,a.length()  ))cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
return 0;
} 

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()

int K, X;

int main() {
    cin >> K >> X;
    cout << ((500 * K >= X) ? "Yes" : "No") << endl;
}

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

template <class T> using V = vector<T>;
template <class S, class T> using P = pair<S, T>;
template <class... T> using TP = tuple<T...>;

using ll = long long;
using db = double;
using ldb = long db;
using str = string;
using ch = char;
using vll = V<ll>;
using vvll = V<V<ll>>;
using vvvll = V<V<V<ll>>>;
using pll = P<ll,ll>;
using tpll = TP<ll,ll,ll>;
using vpll =V<pll>;
using vvpll = V<vpll>;
using vtpll = V<tpll>;
using vst = V<str>;
using vch = V<ch>;
using vvch = V<vch>;
using qll = queue<ll>;
using vqll = V<qll>;

#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin() 
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl
#define pb(a) push_back(a)
#define pob pop_back()
#define mp make_pair
#define mt make_tuple
#define pbmp(a,b) push_back(mp(a,b))
#define subs(a,b) substr(a,b)
#define cfs(a) cout<<fixed<<setprecision(a) //
/*vvll v(n,vll(m)) n行m列  continue
A.erase(A.begin()+i); 配列Aのi番目を消せる
std::binary_search(v.bgn,v.en,a); 二分探索
abs(a,b)   pow(a,n)  to_string  stoll
auto Iter=lower_bound(v.bgn,v.en,a); v[i]>=aとなる初のv[i]
v.insert(lower_bound(v.bgn,v.en,a),b); bを入れられる
lower upper  co(*Iter) co(Iter-v.bgn) v[i]>=aとなる初のi
vvll v(100001,vll(0)); v[a].pb(b); v[b].pb(a);
priority_queue<ll> pque; pque.push(ai); pque.top(); pque.pop();
priority_queue<ll,vll,greater<ll>> pque; 昇順
vqll q(3);  q[0].push(0); q[0].push(2); q[0].push(1);
q[0].front()→0 q[0].back()→1 q[0].pop(); q[0].front()→2
que.pop() que.sz while(!que.empty())
ll a=1,b=2,c=4,xo; xo=a^b^c; if(a^b^c==0)co(xo)→7 if(xo==0)co(xo)→なし
*/

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
#define comuse Comuse()
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll pow_mod(ll a,ll n,ll mod){
  ll res=1;
  for(;n>0;n/=2){
    if(n%2==1)res=(res*a)%mod;
    a=(a*a)%mod;
  }
  return res;
}
ll digit_sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0)break;
  }
  return m;
}
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}

int main(){
  str s,t;
  cin>>s>>t;
  ll c=0;
  FOR(i,0,3){
    if(s[i]==t[i]){
      c++;
    }
  }
  co(c);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n, m;
    cin >> n >> m;

    if(n == 1 && m == 1){
        cout << 1 << endl;
        return 0;
    }

    if(n == 1){
        cout << m - 2 << endl;
        return 0;
    }
    if(m == 1){
        cout << n - 2 << endl;
        return 0;
    }

    ll res = n * m - (2 * (n + m) - 4);

    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 256
#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_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
const double eps = 1e-6;

/////////////////////////////////////////////

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

////////////////////////////////

#define int long long

void solve(){

	int n , k;
	cin>>n>>k;

	int ans = min(n , abs(n - k));

	n%=k;

	ans = min(ans , n);

	ans = min(ans , abs(n-k));

	cout<<ans<<endl;
}


signed main(){

    fast;
    int t = 1;
    //cin>>t;
    for(int i = 1 ; i <= t; ++i){

    	solve();
    }
}


Measured memory_bytes: 256
N,X = map(int,input().split(" "))
L = input().split(" ")
L = [int(i) for i in L]
cd = 0
list = [0]
for i in range(N):
    cd += L[i]
    list.append(cd)
#print(list)
count = 0
for i in range(N+1):
    if list[i] <= X:
        count += 1
print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n,num[20],to[20][20],zt[20][20];
inline bool check(int state){
	bool flag=0;
	for(int i=1;i<=n;i++){
		flag=0;
		for(int j=1;j<=num[i];j++){
			if(zt[i][j]^((state&(1<<(to[i][j]-1)))>>(to[i][j]-1))) flag=1;
		}
		if(!(state&(1<<(i-1)))){
			if(!flag) return 0;
		}
		else if(flag) return 0;
	}
	return 1;
}

inline int query(int state){
	int sum=0;
	for(int i=state;i;i-=(i&-i)) sum++;
	return sum;
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&num[i]);
		for(int j=1;j<=num[i];j++){
			scanf("%d%d",&to[i][j],&zt[i][j]);
		}
	}
	int ans=0;
	for(int state=0;state<(1<<n);state++){
		if(check(state)) ans=max(ans,query(state));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
//#define int long long
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

vector<vector<int>> graph(100010, vector<int>());

int dfs(int n, int p) {
	int res = 0;
	for (int i : graph[n]) {
		if (i == p) continue;
		res ^= (dfs(i, n) + 1);
	}
	return res;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	rep(_, n - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		graph[a].pb(b);
		graph[b].pb(a);
	}
	cout << (dfs(0, -1) ? "Alice" : "Bob") << '\n';
}

Measured memory_bytes: 10368
#pragma GCC optimize(3)
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<bitset>
#include<deque>
using namespace std;
#define ll long long
// #define inf 0x3f3f3f3f
#define ri register int
#define il inline
#define fi first
#define se second
#define mp make_pair
#define pi pair<int,int>
#define mem0(x) memset((x),0,sizeof (x))
#define mem1(x) memset((x),0x3f,sizeof (x))
il char gc()
{
	static const int BS = 1 << 22;
	static unsigned char buf[BS], *st, *ed;
	if (st == ed) ed = buf + fread(st = buf, 1, BS, stdin);
	return st == ed ? EOF : *st++;
}
#define gc getchar
template<class T>void in(T &x)
{
	x = 0;
	bool f = 0;
	char c = gc();
	while (c < '0' || c > '9')
	{
		if (c == '-') f = 1;
		c = gc();
	}
	while ('0' <= c && c <= '9')
	{
		x = (x << 3) + (x << 1) + (c ^ 48);
		c = gc();
	}
	if (f) x = -x;
}
#undef gc
#define pb push_back
ll n;
int s[500], hd = 250, tl = 249;
int dfs(ll x)
{
	if (x == 0) return 0;
	if (x == 1)
	{
		s[++tl] = 1;
		return 1;
	}
	if (x & 1)
	{
		int t = dfs(x >> 1);
		s[++tl] = t + 1;
		return t + 1;
	}
	else
	{
		int t = dfs(x - 1);
		s[--hd] = t + 1;
		return t + 1;
	}
}
signed main()
{
#ifndef ONLINE_JUDGE
	//freopen("in.in", "r", stdin);
#endif
	in(n);
	dfs(n);
	printf("%d\n", (tl - hd + 1) << 1);
	for (ri i = 1; i <= (tl - hd + 1); ++i) printf("%d ", i);
	for (ri i = hd; i <= tl; ++i) printf("%d ", s[i]);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int k = sc.nextInt();
    int q = sc.nextInt();

    int[] a = new int[q];
    int[] p = new int[n+1];

    for (int i = 1; i < n+1; i++) {
      p[i] = 0;
    }

    for (int i = 0; i < q; i++) {
      a[i] = sc.nextInt();
      p[a[i]]++;
    }

    for (int i = 1; i < n+1; i++) {
      if(k - (q - p[i]) > 0) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
    }

  }
}


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

using namespace std;

#define ll long long

int bin_pow(int a, int pow) {
    if (pow == 0) return 1;
    if (pow == 1) return a;
    if (pow % 2 == 0) {
        int tmp = bin_pow(a, pow / 2);
        return tmp * tmp;
    }
    return a * bin_pow(a, pow - 1);
}

int fact(int x) {
    int ans = 1;

    for (int i = 1; i <= x; i++) ans *= i;
    return ans;
}

int count(vector<int> a) {
    int ans = 0;
    unordered_set<int> was;
    for (int i = 0; i < a.size(); i++) {
        int count = a[i] - 1;
        for (int j = 1; j < a[i]; j++) {
            count -= was.count(j);
        }
        ans += count * fact(a.size() - i - 1);
        was.insert(a[i]);
    }

    return ans;
}

ll m = 1000000007;

bool isPrime(int x) {
    for (int i = 2; i * i <= x; i++) {
        if (x % i == 0) return false;
    }
    return true;
}

int main() {
    cin.tie();
    ios_base::sync_with_stdio(false);
    
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    
    for (int i = 0; i < n; i++) {
        cout << s[i] << t[i];
    }
    return 0;
}

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

n, m = [int(x) for x in input().split()]
g = [[] for _ in range(n)]

for _ in range(m):
    l, r, d = [int(x) for x in input().split()]
    g[l - 1].append((r - 1, d))
    g[r - 1].append((l - 1, -d))

d = [None] * n
visited = [0] * n

for i in range(n):
    if visited[i] != 0:
        continue
    stack = [i]
    d[i] = 1
    while stack:
        u = stack.pop()
        visited[u] = 1
        for v, d_ in g[u] :
            if d[v] is None:
                d[v] = d[u] + d_
                stack.append(v)
            else:
                if d[v] != d[u] + d_ :
                    print("No")
                    sys.exit()
print("Yes")


Measured memory_bytes: 66680
#include<bits/stdc++.h>
/*	#include <boost/math/common_factor.hpp>  boost::math::lcm(10,20) ---> use it to find lcm.*/
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//typedef long long ll;
#define int long long 
#define PI pair<int , int >
#define mpr make_pair
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define debug() cout << "Hi" << endl	// write debug(); in main()
const int MOD = 1e9+7;
const int MAXN = 1e5+3;
const int inf = 2e9;
int max(int a,int b){	if(a > b)return a; else return b; }
int min(int a, int b){	if(a < b)return a; else return b; }
/*		0. Go to main function first.
		1. Take all the inputs................................................
		2. Check Once whether the graph given is directed or undirected.......
		3. Tree can also be undirected.
		4. Whenever you do multiplication and division in the same line, beware.
*/
void solve(){
	//debug();
	// int main  or  int32_t main ...
	int n,a,b;
	cin >> n >> a >> b;
	int c = a+b;
	int r = n%c;
	int q = n/c;
	q *= a;
	if(r>a)q += a;
	else q += r;
	
	cout << q << endl;
}
/*	memset() can be used to set all values as 0 or -1 for integer data types.*/

int32_t main(){
	IO;
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#endif // ONLINE_JUDGE
	// std::cout << std::setprecision(12); std::cout << std::fixed;
	int t;
	// cin >> t;
	t = 1;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int a[10010];

int main() {
	int n;
	while(n=in()){
		int i;
		for(i=0;i<n;i++)a[i]=in();
		sort(a,a+n);
		Int res=0;
		for(i=0;i<n;i++){
			res+=a[i]*(n-i-1);
		}
		cout<<res<<endl;
	}
	return 0;
}

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

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

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main (String[] args) {
		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		int C = scanner.nextInt();
		int K = scanner.nextInt();

		//A,B,Cを昇順に並び替える
		int[] array = {A, B, C};
		Arrays.sort(array);

		/*
		for (int i : array) {
		    System.out.println(i);
		}
		*/

		//最大値をK回2倍し、他の2つの数を足す
		int add = array[2];
		for (int i = 0; i < K; i++) {
		    add *= 2;
		}
		System.out.println(add + array[0] + array[1]);
	}
}

Measured memory_bytes: 21844
#include<stdio.h>

#define N 10000
#define M 500



int main(){
  int i,j,n,m,S[N],T[M],c=0,key;

  scanf("%d",&n);

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

  scanf("%d",&m);

  for(i=0;i<n;i++){
    scanf("%d",&T[i]);
  }
  
  for(j=0;j<m;j++){
    S[n]=T[j];
    key=T[j];
    i=0;
    while(S[i]!=key){
      i++;
    }
    if(i!=n){
      c++;
    }
  }

  printf("%d\n",c);
  
  return 0;
}



Measured memory_bytes: 2128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1000000000100000000;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    char a, b; cin >> a >> b;
    if(a==b)cout<< "H" << ln;
    else cout << "D" << ln;
}

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

#define LINE_BUF_SIZE 512

int main(){

    int i=0,j=0,k=0;
    int N,v,max=0;
    char line[LINE_BUF_SIZE];

    fgets(line,sizeof(line),stdin);
    sscanf(line,"%d",&N);

     int *A = malloc(sizeof(int)*(int)(1e5));

    for(i=0;i<N;i++){
        A[i]=0;
    }

    for(i=0;i<N;i++){
        scanf("%d",&v);
        A[v]+=1;
        if(v > max)max = v;
    }

    int count = 0;
    int count_three = 0;
    int sum = 0;

    for(i=0;i<=max;i++){

        if(A[i] > 0){
            if(A[i] % 2 != 0){
                A[i] = 1;
                count_three += 1;   /*奇数の数*/
            }
            else{
                A[i] = 2;
                count += 1;         /*偶数の数*/
            }
            sum += 1;   /*1以上のますの数*/
        }

    }

    int ans = 0;

    if(count % 2 == 0){     /*偶数*/
        ans = 0;
    }

    else{        /*奇数*/
        ans = -1;
    }

    printf("%d",sum+ans);

    return 0;

}

Measured memory_bytes: 512
foo :: Int -> Int -> Int
foo n d =
  let
    r = 2 * d + 1
    k = n `mod` r
    a = n `div` r
  in if k == 0 then a else a + 1


main = do
  ints <- map read .words <$> getLine :: IO [Int]
  print $ foo (head ints) (last ints)


Measured memory_bytes: 508
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        int swapCount = 0;
        for (int i = 0; i < n; i++) {
            int minj = i;
            for (int j = i; j < n; j++) {
                if (a[j] < a[minj]) {
                    minj = j;
                }
            }
            if (i != minj) {
                swap(a, i, minj);
                swapCount++;
            }
        }
        printlnArray(a);
        System.out.println(swapCount);
    }

    static void swap(int[] a, int i, int j) {
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }

    private static void printlnArray(int[] a) {
        for (int i = 0; i < a.length - 1; i++) {
            System.out.print(a[i] + " ");
        }
        System.out.println(a[a.length - 1]);
    }
}


Measured memory_bytes: 26360
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0;i < (int)(n);i++)
int main() {
  int n, m, M = 0, x;
  cin >> n;
  string s;
  map<string, int> v;
  rep(i, n) {
    cin >> s;
    v[s]++;
  }
  cin >> m;
  rep(i, m) {
    cin >> s;
    v[s]--;
  }
  for(auto p : v) {
    x = p.second;
    if(x > M) M = x;
  }
  cout << M << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  string color = "Three";
    
  for (int i = 0;i < N; i ++) {
    string x;
    cin >> x;
    
    if (x == "Y") {
      color = "Four";
    }
  }
  
  cout << color << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
using namespace std;
int mod = 1e9+7;

int main() {
  int x, y;
  cin >> x >> y;
  cout << (x%y == 0 ? -1 : x) << endl;

  return 0;
}




//


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    int count = 0;
    Scanner sc = new java.util.Scanner(System.in);
    int leng = Integer.parseInt(sc.nextLine());
    String [] nums = sc.nextLine().split(" ");
    int evenCount = 0;
    for (String num: nums) {
      if (Integer.parseInt(num) % 2 == 0) {
        evenCount++;
      }
    }
    while (evenCount == nums.length) {
      evenCount = 0;
      count++;
      for (int i = 0; i < nums.length; i++) {
        nums[i] = String.valueOf(Integer.parseInt(nums[i]) / 2);
      }
      for (String num: nums) {
        if (Integer.parseInt(num) % 2 == 0) {
          evenCount++;
        }
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 23508
h1,m1,h2,m2,k=list(map(int,input().split()))
if m1==m2:
    m=0
    h=h2-h1
elif m2-m1>0:
    m=m2-m1
    h=h2-h1
else:
    m=60-m1+m2
    h=h2-h1-1
ans=(k-(m+h*60))*(-1)
if ans<=0:
    print(0)
else:
    print(ans)



Measured memory_bytes: 9192
N = int(input())
s = raw_input().split()
A = [0]*N

for i in range(N):
    A[i] = int(s[i])

#print N, A

h = 0
t = N-1
lh = 0
lt = 0

for i in range(N):
    if (lh > lt):
        lt += A[t]
        t -= 1
    else:
        lh += A[h]
        h += 1
    #print h, t, lh, lt, A[h+1:t-1]

print abs(lh-lt)


Measured memory_bytes: 26392
n,k=list(map(int,input().split()))
a=sorted(list(map(int,input().split())))
f=sorted(list(map(int,input().split())),reverse=True)

left = -1
right = 10**18+1
 
 
while right - left > 1:
    mid = left + (right - left) // 2
 
 
    train = k
    for i in range(n):
        req = mid // f[i]
        if req < a[i]:
            train -= a[i] - req
 
 
    if train >= 0:
        right = mid
    else:
        left = mid
 
 
 
print(right)

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

int main() {
int N;
cin>>N;
vector<vector<int>> D(N, vector<int>(2));
for (int i = 0; i < N; i++) {
    for (int j = 0; j < 2; j++) {
        cin >> D.at(i).at(j);
    }
}
int cnt=0;
for(int i=0;i<N;i++){
    if(D.at(i).at(0)==D.at(i).at(1)){
        cnt++;
    }else if(cnt!=0){
        cnt=0;
    }
    if(cnt==3){
        cout<<"Yes"<<endl;
        return 0;
    }
}
cout<<"No"<<endl;
}

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int n = fs.nextInt();
		int m = fs.nextInt();
		System.out.println(conv2(n) + conv2(m));
	}

	int conv2(int n) {
		if(n < 2) {
			return 0;
		}
		return (n)*(n-1)/2;
	}
	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 21076
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

main(){
	char buf[20];
	scanf("%s",buf);
	int l=strlen(buf);
	long long p10[16];
	p10[0]=1;for(int i=1;i<=15;i++)p10[i]=p10[i-1]*10;
	
	long long ans=0;
	
	for(int i=0;i<l;i++){
		for(int j=i+1;j<=l;j++){
			ans+=(buf[i]-'0')*(1LL<<(max(0,l-j-1)+i))*p10[j-i-1];
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>

#define M 16777216
#define FOUND 1
char H[M];


int getChar( char ch )
{
	if( ch == 'A') {
		return 1;
	} else if( ch == 'C') {
		return 2;
	} else if( ch == 'G') {
		return 3;
	} else if( ch == 'T') {
		return 4;
	}
	return 0;
}

int getKey( char str[] )
{
	int i;
	int key = 0, base = 1;
	for ( i=0; i<strlen( str ); i++ ) {
		key += base*( getChar( str[i] ) );
		base *= 4;
	}
	return key;
}

int find( char str[] )
{
	if( FOUND == H[ getKey( str ) ] ) {
		return FOUND;
	} else {
		return 0;
	}
}

void insert( char str[] )
{
	H[ getKey( str ) ] = FOUND;
	return;
}
int main() 
{
	int i, n;
	char str[14], com[9];	
	
	for ( i=0; i<M; i++ ) {	H[i] = '\0'; }
	
	scanf( "%d", &n );
	int j;
	for ( j=0; j<n; j++ ) {
		scanf( "%s %s", com, str );
		if ( com[0] == 'i' ){
			insert( str );
		} else {
			if( find( str ) ){
				printf("yes\n");
			} else {
				printf("no\n");
			}
		}
	}

    return 0;
}

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

#define task ""
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DEBUG(X) { cerr << #X << " = " << (X) << '\n'; }
#define PR(A, n) { cerr << #A << " = "; FOR(_, 1, n) cerr << A[_] << ' '; cerr << '\n'; }
#define sz(x) ((int)(x).size())
#define pb push_back
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define left lajcljascjljl
#define right aucouasocjolkjl
#define y0 u9cqu3jioajc

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
int a, b, c;
int main()
{
	//freopen(task".in","r",stdin);
	//freopen(task".out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	cin >> a >> b >> c;
	if (a + b + c >= 22) cout << "bust";
	else cout << "win";
}


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

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
 

using ll = long long int;
using ld = long double;
using pii = pair<int,int>;

#define REP(i,m,n) for(ll i = m; i < (ll)(n);++i)
#define rep(i,n) REP(i,0,n)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
 
using vi=vc<int>;

const ll mod=1e9+7;
const ll INF = 1e18;

int main(){
  int n,W;cin >> n>>W;
  ll w[110],v[110];
  rep(i,n) cin >> w[i] >>v[i];
  ll dp[110][100010];
  rep(i,100009)dp[0][i]=0;
  rep(i,109) dp[i][0]=0;
  REP(i,0,n+1){
    rep(j,W+1){
      dp[i+1][j]=dp[i][j];
      if(w[i]<=j){
      chmax(dp[i+1][j],dp[i][j-w[i]]+v[i]);
      }
    }
  }
  cout << dp[n][W] << endl;}


Measured memory_bytes: 86016
#include <iostream>
#include <map>
using namespace std;
int N;
char S[40], S2[40];
const int MOD = 1000000007;
map <pair <int, int>, int > M;
void Read()
{
    cin >> N;
    cin.get();
    cin.getline(S, 40);
}

void precalcDP()
{
    for(int conf = 0; conf < (1 << N); conf++)
    {
        int valr = 0, valb = 0;
        for(int j = 0; j < N; j++)
        {
            if((conf & (1 << j)) != 0)
            {
                valr = (1LL * valr * 73 + S[j] - 'a' + 1) % MOD;
            }
            else
                valb = (1LL * valb * 73 + S[j] - 'a' + 1) % MOD;
        }
        M[make_pair(valr, valb)]++;
    }
}

void Solve()
{
    int cnt = -1;
    for(int i = 2 * N - 1; 2 * N - i <= N; i--)
    {
        S2[++cnt] = S[i];
    }
    long long ans = 0;
    for(int conf = 0; conf < (1 << N); conf++)
    {
        int valr = 0, valb = 0;
        for(int j = 0; j < N; j++)
        {
            if((conf & (1 << j)) != 0)
            {
                valr = (1LL * valr * 73 + S2[j] - 'a' + 1) % MOD;
            }
            else
                valb = (1LL * valb * 73 + S2[j] - 'a' + 1) % MOD;
        }
        if(M.count(make_pair(valr, valb)) > 0)
            ans += M[make_pair(valr, valb)];
    }
    cout << ans << "\n";
}
int main()
{
    Read();
    precalcDP();
    Solve();
    return 0;
}


Measured memory_bytes: 16640
#include<bits/stdc++.h>
#define INF 1e9
using namespace std;

int main () {
	int n; int m;
	cin >> n;
	int t=INF;
	for (int i=0;i<n;i++){
		cin >> m;
		t = min(t,(-m&m));
	}
	cout << log2(t) << endl;
}

Measured memory_bytes: 256