akhauriyash/Code-Regression huggingface dataset:
/*---------------------------------- NEVER GIVE UP --------------------------------------------*/

/*

Some people think that if their opponent plays a beautiful game, it’s OK to lose. I don’t. You have to be merciless
-- MAGNUS CARLSEN

*/

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

typedef long long ll;
typedef double ld;
typedef pair<ll,ll> pii;
typedef tree<ll, null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define num dp
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define debug1(x) cerr<<#x<<" : "<<x<<endl
#define debug2(x,y) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define debug3(x,y,z) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define fastt ios_base::sync_with_stdio(false); cin.tie(NULL) ; cout.tie(NULL)

const ll modd=1e9+7;
const ll inf=1e18;

ll poww(ll a,ll b){
  ll ans=1;
  while(b){
    if(b&1LL) ans=(ans*a);
    a=(a*a);
    b=b>>1LL;
  }
  return ans;
}

/*    
         -> mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
         -> cout<<"Case #"<<casee<<": "<<ans<<endl; 

*/

/*-----------------------------------------------------------------------------------------------*/

vector <vector<ll>> dp[11][11];
vector <string> ans;

int main(){
   fastt;
   
   ll n;
   
   cin >> n;
   
   for(ll i = 1; i <= n; i++)
      for(ll j = 1; j <= n; j++){
		  if(i == 1 && j == 1){
			  vector <ll> vec;
			  vec.pb((1ll << (n-i)));
			  dp[i][j].pb(vec);
		  }
		  for(auto k : dp[i-1][j-1]){
			  k.pb((1ll << (n-i)));
			  dp[i][j].pb(k);
		  }
		  for(auto k : dp[i-1][j]){
			  for(ll l = 0; l < j; l++){
				  ll cpy = k[l];
				  k[l] |= (1LL << (n-i));
				  dp[i][j].pb(k);
				  k[l] = cpy; 
			  }
		  }
	  }
	  
   string ss = "";
   
   for(ll i = 1; i <= n; i++){
	   ss += "a";
   }  
	  
   for(ll i = 1; i <= n; i++){
	   for(ll j = 0; j < (ll)dp[n][i].size(); j++){
		   sort(num[n][i][j].begin() , num[n][i][j].end() , greater <ll>());
		   ll ind = 0;
		   for(auto k : num[n][i][j]){
			   for(ll l = 0; l < n; l++){
				   if(k & (1LL << l)) ss[n-1-l] = ('a'+ind);
			   }
			   ind++;
		   }
		   ans.pb(ss);
	   }
   }

   sort(ans.begin(),ans.end());
   
   for(auto j : ans) cout << j << '\n';
 
   return 0;
}





Measured memory_bytes: 18228
N = int(input())
A = list(map(int, input().split()))
INF = float('inf')

dp = [[-INF for _ in range(2)] for _ in range(N+1)]
dp[0][0] = dp[0][1] = sum(A)
# print(dp)
for i in range(N-1):
    dp[i+1][0] = max(dp[i+1][0], dp[i][0])
    dp[i+1][0] = max(dp[i+1][0], dp[i][1])

    dp[i+1][1] = max(dp[i+1][1], dp[i][0] - (A[i] + A[i+1]) + (-A[i]-A[i+1]))
    if i > 0:
        dp[i+1][1] = max(dp[i+1][1], dp[i][1] - (-A[i] + A[i+1]) + (A[i]-A[i+1]))

print(max(dp[N-1]))



Measured memory_bytes: 25892
#include <stdio.h>          // printf(), scanf()
#include <string.h>         // memset()
#include <stdbool.h>

// #define PROFILE 1
#define MAX_N 20
#define MAX_V 2000

static const int INF = 100000000;
int a[MAX_N];
int dp[MAX_N + 1][MAX_V + 1];
int n;
int m;
int O;

int
solve(int i, int m)
{
	if (m < 0)
		return 0;

	if (dp[i][m] != INF)
		return dp[i][m];

	O++;
	if (m == 0)
		dp[i][m] = 1;

	else if (i >= n)
		dp[i][m] = 0;

	else if (solve(i + 1, m))
		dp[i][m] = 1;

	else if (solve(i + 1, m - a[i]))
		dp[i][m] = 1;

	else
		dp[i][m] = 0;

	return dp[i][m];
}

int
main(int argc, char** argv)
{
	int q;
	int i, j, k;

	O = 0;
	scanf("%d", &n);
	for (i = 0; i < n; ++i)
		scanf("%d", &a[i]);

	scanf("%d", &q);
	for (i = 0; i < q; ++i)
	{
		for (j = 0; j <= n; ++j)
		{
			for (k = 0; k <= MAX_V; ++k)
				dp[j][k] = INF;
		}

		scanf("%d", &m);
		printf("%s\n", solve(0, m) == 1 ? "yes" : "no");
	}

#ifdef PROFILE
	fprintf(stderr, "O:%d\n", O);
#endif
	return 0;
}

Measured memory_bytes: 744
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

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

int main() {
	int n;

	while(cin >> n && n) {
		string s;
		cin >> s;

		rep(k, n) {
			stringstream ss;
			int len = 0;
			rep(i, s.size()) {
				len = 1;
				REP(j, i + 1, s.size()) {
					if(s[i] == s[j]) {
						len++;
						i++;
						continue;
					} else break;
				}
				ss << len;
				ss << s[i];
			}
			s = ss.str();
		}

		cout << s << endl;

	}

	return 0;
}

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

int Gcd(int a, int b) {
  if (b == 0) return a;
  return Gcd(b, a % b);
}

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> x(N);
  for (int i = 0; i < N; i++) cin >> x[i];
  vector<int> N_line(N + 1);
  for (int i = 0; i < N; i++) N_line[i] = x[i];
  N_line[N] = X;
  sort(N_line.begin(), N_line.end());
  vector<int> dif(N);
  for (int i = 0; i < N; i++) dif[i] = N_line[i + 1] - N_line[i];
  int ans = dif[0];
  for (int i = 0; i < N - 1; i++) ans = Gcd(ans, dif[i + 1]);
  cout << ans << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> sum(N, 0);
    for(int i = 0; i < Q; i++){
        int A;
        cin >> A;
        A--;
        sum[A]++;
    }
    for(int i = 0; i < N; i++){
        Yes(Q - sum[i] < K);
    }
}

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];

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

    vector<int> ans(N);

    int kind = 0;
    int left = 0, right = 0;
    while(left != N){
        while(A[left] == A[right] && right < N){
            ans[kind]++;
            right++;
        }
        left = right;
        kind++;
    }

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

    int res = 0;
    for(int i = 0; i < ans.size()-K; i++){
        res += ans[i];
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};


struct UnionFind{
    vector<ll> par;
    UnionFind(ll n) : par(n, -1){}
    

    int root(int x){
        if(par[x]<0) return x;
        return par[x] = root(par[x]);
    }

    bool same(int a, int b){
        return root(a)==root(b);
    }
    void unite(int a, int b){
        int x=root(a), y=root(b);
        if(same(x, y)) return;
        if(y<x) swap(x, y);
        par[x] += par[y];
        par[y] = x;
    }
    int size(int x){
        return -par[root(x)];
    }

};


int main(){
    ll n, m;   cin >> n >> m;
    vector<pair<ll, ll>> g(m);
    REP(i, m){
        ll a, b;    cin >> a >> b;
        a--, b--;
        g[i] = {a, b};
    }
    UnionFind bridge = UnionFind(n);
    ll res=n*(n-1)/2;
    priority_queue<ll, vector<ll>, greater<ll>> que;
    REPD(i, m){
        ll a=g[i].first, b=g[i].second;
        que.push(res);
        if(!bridge.same(a, b)){
            res -= bridge.size(a)*bridge.size(b);
            bridge.unite(a, b);
        }
    }
    while(!que.empty()){
        cout << que.top() << endl;
        que.pop();
    }

}


Measured memory_bytes: 6628
n = int(input())
p = [None] * (n+1)# i番目の列数 = i+1番目の行数
for i in range(n):
  p[i], p[i+1] = map(int, input().split())

INF = 10**18
m = [[None] * n for _ in range(n)]
for i in range(n):
  m[i][i] = 0
  
for l in range(2,n+1):# 行列の連鎖数
  for i in range(n-l+1):
    j = i + l - 1# [i, j]の範囲の計算の最小コストを考える
    m[i][j] = INF
    for k in range(i,j):
      m[i][j] = min(m[i][j], m[i][k]+m[k+1][j] + p[i-1]*p[k]*p[j])

print(m[0][n-1])


Measured memory_bytes: 5656
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 2e5;

int n;
int a[N],b[N],c[N];

void nhap()
{
    long long S = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        S += a[i];
    }
    for (int i = 1; i <= n; i++) {
        cin >> b[i];
        S -= b[i];
    }
    if (S < 0) {
        cout << -1;
        exit(0);
    }
    for (int i = 1; i <= n; i++) c[i] = a[i] - b[i];
    sort(c + 1,c + 1 + n,greater<int>());
}

void solve()
{
    int Res = 0;
    long long S = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] < b[i]) {
            S += b[i] - a[i];
            Res++;
        }
    }
    long long T = 0;
    for (int i = 1; T < S && i <= n; i++) {
        T += c[i];
        Res++;
    }
    cout << Res;
}
int main()
{
    nhap();
    solve();
}


Measured memory_bytes: 1408
#include<iostream>
#include<utility>
#include<algorithm>
using namespace std;

typedef long long ll;

int main(){
   int n;
   cin >> n;
   int w[n];
   for(int i = 0;i < n;i++){
       cin >> w[i];
   }
   int ans = 10000000;

   for(int i = 0;i < n;i++){
       int  t1 = 0,t2 = 0;
       for(int j = 0;j < i;j++){
           t1+=w[j];
       }
       for(int j = i;j<n;j++){
           t2+=w[j];
       }
       
       ans = min(ans,abs(t1-t2));
   }
   cout << ans << endl;
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define Very_fast std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N=2e5+5;
int n;ll ans=0;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		ans+=(ll)i*(i+1)/2;
	for(int i=2;i<=n;i++)
	{
		int x,y;
		cin>>x>>y;
		if(x>y)swap(x,y);
		ans-=(ll)x*(n-y+1);
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3584
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 count = 0;
		int ans = 0;
		for (int i = 0; i < M; i++) {
			count += sc.nextInt();
		}
		if (count <= N) {
			ans = N - count;
		} else {
			ans = -1;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 46648
using System;
using System.Linq;

namespace CDiceAndCoin
{
    class Program
    {
        static void Main(string[] args)
        {
            // 入力の取得
            var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = inputs[0];
            var k = inputs[1];

            // 各数字の小さい方から加算
            double probSum = 0;
            for (var i = 1; i <= n; i++)
            {
                var shiftCount = 0;
                while (i << shiftCount < k) shiftCount++;

                probSum += 1 / (n * Math.Pow(2, shiftCount));
            }

            // 解答の出力
            Console.WriteLine(probSum);
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define long long long int
using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> x(n), y(n);
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i];

    vector<int> p(n);
    for (int i = 0; i < n; i++) p[i] = i;
    double slen = 0;
    int nlen = 0;
    do {
        nlen++;
        for (int i = 0; i < n - 1; i++) {
            int a = p[i];
            int b = p[i + 1];
            slen += hypot(x[a] - x[b], y[a] - y[b]);
        }
    } while(next_permutation(p.begin(), p.end()));

    cout << setprecision(20) << slen / nlen;

    return 0;
}

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

#define ll long long
#define ar array

const int mxN=5e5, M=1e9+7;
int n, m;
ll iv[mxN+1], f1[mxN+1], f2[mxN+1];

ll nck(int n, int k) {
	return f1[n]*f2[k]%M*f2[n-k]%M;
}

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

	iv[1]=1;
	for(int i=2; i<=mxN; ++i)
		iv[i]=M-M/i*iv[M%i]%M;
	f1[0]=f2[0]=1;
	for(int i=1; i<=mxN; ++i) {
		f1[i]=f1[i-1]*i%M;
		f2[i]=f2[i-1]*iv[i]%M;
	}

	cin >> n >> m;
	ll ans=0;
	for(int i=0; i<=n; ++i) {
		ll c=i&1?M-1:1;
		c=c*nck(n, i)%M*nck(m, i)%M*f1[i]%M*nck(m-i, n-i)%M*nck(m-i, n-i)%M*f1[n-i]%M*f1[n-i]%M;
		ans=(ans+c)%M;
	}
	cout << ans;
}


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

using namespace std;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  vector<ll> vec(n);
  for (auto &v : vec)
    cin >> v;

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

  ll ans = vec[n-1] - vec[0];
  ll a = 1;
  ll b = n - 2;
  while (a <= b) {
    if (a < b)
      ans += vec[b] - vec[a-1] + vec[b + 1] - vec[a];
    else
      ans += max(vec[a] - vec[a-1], vec[a+1] - vec[a]);
    ++a;
    --b;
  }

  cout << ans << endl;
}

Measured memory_bytes: 4048
def altars(n, a, b, c):
    up = sorted(a)
    mid = sorted(b)
    down = sorted(c, reverse=True)
    i = j = 0
    up_count = []
    down_count = []
    for midpart in mid:
        while i < n and up[i] < midpart:
            i += 1
        up_count.append(i)
    for midpart in mid[::-1]:
        while j < n and midpart < down[j]:
            j += 1
        down_count.append(j)
    down_count.reverse()
    return sum(map(lambda x, y: x * y, up_count, down_count))


if __name__ == '__main__':
    n = int(input())
    a = map(int, input().split())
    b = map(int, input().split())
    c = map(int, input().split())
    print(altars(n, a, b, c))

Measured memory_bytes: 29708
using System;
using System.Collections.Generic;
using System.Linq;
class Ho{
  static void Main(){
    var aho = Console.ReadLine().Split();
    var s = aho[0];
    var t = aho[1];
    var baka = Console.ReadLine().Split();
    var a = int.Parse(baka[0]);
    var b = int.Parse(baka[1]);
    var j = Console.ReadLine();
    if(j == s){
      a = a-1;
    }
    else if(j == t){
     b = b-1;
    }
    Console.WriteLine(a+" "+b);
  }
}

Measured memory_bytes: 11220
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun bsCondOpCl(A: IntArray, L: Int, R: Int, K: Int): Int {
    val N = A.size

    fun isCondition(A: IntArray, m: Int): Boolean {
        var cnt = 0
        for (i in 0 until N) {
            cnt += (A[i]+m-1)/m - 1
        }

        return cnt <= K
    }

    var l = L; var r = R

    while (l+1 < r) {
        val m = (l + r) / 2
        if (isCondition(A, m)) {
            r = m
        } else {
            l = m
        }
    }
    return r
}


fun solve() {
    val (N, K) = rd.readIntArray()
    val A = rd.readIntArray().sorted()
    assert(A.size == N) {"A.size == N"}

    if (K==0) {
        println(A.last())
        return
    }

    val ans = bsCondOpCl(A.toIntArray(), 0, A.last(), K)

    print(ans)
}


//val rd = debug.Reader("abc", "174", "e", "sample-3")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!!
    } catch (e: Exception) { throw e }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
const val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


Measured memory_bytes: 69328
program b176
 
implicit none
character(len=200000) :: a 
integer :: n, i, t

read *, a

n = 0

do i = 1, 200000
 if (a(i:i) == ' ') then
  exit
 else
  read(a(i:i),*) t
  n = n + t
 end if
end do

!print *, n
 
if(mod(n, 9) == 0) then
 print *, 'Yes'
else
 print *, 'No'
end if


end program b176

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

template <class Iit>
void vout(const Iit &begin,const Iit &end,ostream &out) {
    for(auto it = begin; it != end; it++) {
        auto tmp = it;
        if (++tmp == end) out << *it << '\n';
        else out << *it << " ";
    }
}

int main(void)
{
    IOS
    const ll LINF = 1LL << 60;
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<ll> a(A+2,LINF), b(B+2,LINF);
    a[0] = -LINF; b[0] = -LINF;
    REP(i,A) cin >> a[i+1];
    REP(i,B) cin >> b[i+1];
    

    vector<ll> ab(a.size(),LINF), ba(b.size(),LINF);
    FOR(i,1,A+1) {
        auto it = lower_bound(ALL(b),a[i]);
        ab[i] = min(ab[i],abs(*it-a[i]));
        it--;
        ab[i] = min(ab[i],abs(a[i]-*it));
    }
    FOR(i,1,B+1) {
        auto it = lower_bound(ALL(a),b[i]);
        ba[i] = min(ba[i],abs(*it-b[i]));
        it--;
        ba[i] = min(ba[i],abs(b[i]-*it));
    }

    //vout(ALL(ab),cerr);
    //vout(ALL(ba),cerr);

    REP(i,Q) {
        ll X; cin >> X;
        ll ans = LINF;

        auto ita = lower_bound(ALL(a),X);
        int aidx = distance(a.begin(),ita);
        ans = min(ans,abs(a[aidx]-X) + ab[aidx]);
        ans = min(ans,abs(a[aidx-1]-X) + ab[aidx-1]);

        auto itb = lower_bound(ALL(b),X);
        int bidx = distance(b.begin(),itb);
        ans = min(ans,abs(b[bidx]-X) + ba[bidx]);
        ans = min(ans,abs(b[bidx-1]-X) + ba[bidx-1]);

        cout << ans << '\n';
    }


    return 0;
}

Measured memory_bytes: 4480
import heapq
n, m = map(int, input().split())
a_b = []

for i in range(n):
    ab = list(map(int, input().split()))
    a_b.append(ab)

heapq.heapify(a_b)

res = 0
for i in range(m):
    tmp_a, tmp_b = heapq.heappop(a_b)
    res += tmp_a 
    tmp_b -= 1
    if tmp_b > 0:
        heapq.heappush(a_b, [tmp_a, tmp_b])

print(res)

Measured memory_bytes: 27072
S=list(input())
L=len(S)
Key="keyence"

for i in range(8):
    if i==0:
        temp="".join(S[L-7:L+1])
    elif 1<=i<=6:
        temp="".join(S[0:i])+"".join(S[L+i-7:L+1])
    else:
        temp="".join(S)
    if temp == Key:
        print("YES")
        exit()
print("NO")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long int 
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define from(i,n)       for(int i=0;i<(int)n;i++)
#define from_j(i,j,n)   for(int i=j;i<(int)n;i++)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


int dp[100005]={0};

int dfs(int node,vector<vi> &adj_list){
    if(dp[node])return dp[node];
    int temp = 0;
    for(auto it :adj_list[node]){
        temp = max(temp,dfs(it,adj_list));
    }
    dp[node]=temp+1;
    return temp+1;
}
 
 
void c_p_c(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int32_t main()
{
    c_p_c();
    int n,edges; cin>>n>>edges;
    vector<vi> adj_list(n+1);
    vi parents(n+1);
    from(i,edges){
        int a,b; cin>>a>>b;
        adj_list[a].pb(b);
        parents[b]++;
    }
    int ans = 0;
    for(int i=1;i<=n;i++){
        if(!parents[i]){
            ans = max(ans,dfs(i,adj_list));
        }
    }
    cout<<ans-1;
    
    
    
    return 0;
}

Measured memory_bytes: 12032
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		char[] ch = scn.nextLine().toCharArray();
		boolean how = (ch[0]==ch[1] && ch[2]==ch[3]&&ch[0]!=ch[2])||(ch[0] == ch[2]&&ch[1]==ch[3]&&ch[0]!=ch[1])||(ch[0]==ch[3]&&ch[1]==ch[2]&&ch[0]!=ch[1]);
		System.out.println(how?"Yes":"No");
	}

}

Measured memory_bytes: 21844
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds

def main():
    mod = 10**9+7
    s=input()
    l=s.split(",")
    print(*l)
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列






if __name__ == "__main__":
    main()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string S;
  cin >> N >> S;
  int count=0,ans=0;
  for (int i=0;i<N;i++){
    if (S[i]=='I'){
      count++;
    }
    else {
      count--;
    }
    ans=max(count,ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = {False: 'No', True: 'Yes'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    S, T = MS()
    A, B = MI()
    U = input()

    if U == S:
        print(A - 1, B)
    elif U == T:
        print(A, B - 1)
    else:
        print(A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38640
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int n,s=0;
cin>>n;
long long int a[n],b[100002]={0};
for(int i=0;i<n;i++)
{
cin>>a[i];
s+=a[i];
b[a[i]]++;
}
long long int q;
cin>>q;
for(int i=1;i<=q;i++)
{
	int c,d;
	cin>>c>>d;
	s-=(b[c]*c);
	s+=(b[c]*d);
	b[d]+=b[c];
	b[c]=0;
cout<<s<<endl;	
}
	return 0;
}

Measured memory_bytes: 5176
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cctype>

#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <map>
#include <algorithm>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i,l,n) for(int (i)=(int)(l);(i)<(int)(n);(i)++)
#define d_arr(arr, h, w) rep(i,(h) ){ cout << "["; rep(j,(w) ) { cout << (arr)[i][j] << ", "; } cout << "]" << endl;}

typedef pair<int ,int> P;

class car
{
    int id;
    int num;
    public:
        car(int x, int y){ id=x; num=y; }
};

int H,W;
char grid[20][20];
int is_visit[20][20];
int start_h;
int start_w;


void rec(int h, int w);


int main()
{
    //各データセットに対して
    while( cin >> W >> H )
    {
        if ( W == 0 && H == 0 ) break;
        //入力
        rep(i, H)
        {
            rep(j, W)
            {
                char tmp;
                cin >> tmp;
                grid[i][j] = tmp;
                if( tmp == '@') { start_h = i; start_w = j; }
                is_visit[i][j] = 0;
            }
        }

        rec(start_h,start_w);

        int count=0;
        rep(i,H)
        {
            rep(j,W)
            {
                count += is_visit[i][j];
            }
        }

        cout << count << endl;
    }
}

void rec(int h, int w)
{
    //枠外
    if( h < 0 || H <= h || w < 0 || W <= w  ) { return ; }
    //障害物
    if( grid[h][w] == '#' ) { return ; }
    //訪れたか
    if( is_visit[h][w] == 1 ) { return ; }
    is_visit[h][w] = 1;

    vector<int> v(4);
    rec(h,w+1);
    rec(h,w-1);
    rec(h+1,w);
    rec(h-1,w);

    //int a = max( v[0] , v[1] );
    //int b = max( v[2] , v[3] );
    //return max(a, b) + 1;
    return;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long



bool dp[100001];

int main(){
	IOS;
	int n,k;
	cin >> n >> k;
	int a[n+1];
	for(int i=1;i<=n ; ++i){
		cin >> a[i];
	}

	for(int i=1;i<=k ; ++i){
		for(int j = 1;j<= n ; ++j){
			if(i-a[j]>=0 && !dp[i-a[j]]){
				dp[i] = true;
			}
		}
	}
	if(dp[k])cout << "First" << endl;
	else cout << "Second" << endl;

}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <cassert>

#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>
#include <queue>
#include <unordered_map>
#include <list>
#include <set>
#include <numeric>
using namespace std;

using ll = long long;

#define rep_init(i, init, n) for(int i = (init); i < (n); ++i)
#define rep(i, n) rep_init(i, 0, n)

template<typename T>
constexpr T gcd(T a, T b)
{
	if (a < b) swap(a, b);

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

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

	vector<int> A(N);
	rep(i, N)
	{
		cin >> A[i];
	}

	vector<int> L(N);
	vector<int> R(N);

	L[0] = A[0];
	rep_init(i, 1, N)
	{
		L[i] = gcd(L[i-1], A[i-1]);
	}

	R[N-1] = A[N-1];
	for (int i = N-2; i >= 0; --i)
	{
		R[i] = gcd(R[i+1], A[i+1]);
	}

	int ans = 0;
	rep(i, N)
	{
		if (i == 0)
		{
			ans = max(ans, R[0]);
		}
		else if (i == N-1)
		{
			ans = max(ans, L[N-1]);
		}
		else
		{
			ans = max(ans, gcd(R[i], L[i]));
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 4576
x,k,d=map(int,input().split())
if abs(x)//d>k:
    e=d*k
    print(abs(min(x-e,x+e,key=abs)))
else:
    r=abs(x)//d
    t=abs(x)%d
    if (k-r)%2==1:
        print(abs(t-d))
    else:
        print(t)

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

using namespace std;

int N, M, P;
int X[110], sum;

void solve() {
	if (X[M] == 0) {
		cout << 0 << endl;
		return;
	}
	
	int sub = sum;
	sub *= P;
	sub /= 100;
	sum -= sub;
	
	cout << sum / X[M] << endl;
}

int main() {
	while (1) {
		cin >> N >> M >> P; if (N == 0 && M == 0 && P == 0) break;
		M--;
		
		sum = 0;
		for (int i = 0; i < N; i++) {
			cin >> X[i];
			sum += 100 * X[i];
		}
		
		solve();
	}
	
	return 0;
}

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

using namespace std;

typedef long long ll;

ll ceil(ll a , ll b){
  return ( a + b - 1) / b;}

int main(){
 int N; cin >> N;
  vector<ll > A(N); vector<ll> B(N);
  for(ll i = 0; i < N; i++){
    cin >> A[i] >> B[i];}
  
  
   ll res = ceil( A[N-1], B[N-1]) * B[N-1] - A[N-1];
     
     
     
  for(ll i = N - 1; i >= 0; i--){
    if ( i == N - 1){ continue;}
   
   ll j = ceil( res + A[i], B[i]) - ceil( A[i],B[i]);
    
    res = (ceil( A[i] , B[i]) + j) * B[i] - A[i];}
   
  
  cout << res << endl; return 0;}

Measured memory_bytes: 1792
H, W, D = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]
x = [0]*(H*W+D+1)
y = [0]*(H*W+D+1)
for k in range(W):
    for l in range(H):
        x[A[l][k]] = k+1
        y[A[l][k]] = l+1

d = [0]*(H*W+D+1)
for k in range(H*W,0,-1):
    d[k] = d[k+D] + abs(x[k]-x[k+D]) + abs(y[k]-y[k+D])

for _ in range(int(input())):
    L, R = map(int,input().split())
    print(d[L]-d[R])


Measured memory_bytes: 55132
#define __mode_debug__
/*   ξ
     ll
   ＿ll＿
 ／  ∞  ＼
│*  Ａ  *│
│*  Ｃ  *│
│*  祈  *│
│*  願  *│
│*      *│
 ￣￣￣￣￣    */
//C++14 (GCC 5.4.1)
#include <bits/stdc++.h>
using namespace std;
#ifdef __mode_debug__
    #define DBG
#else
    #define DBG if(false)
#endif

#define LLINF (1LL<<60)
using ll = long long;
#define mod  1000000007

#define whole(a) (a).begin(),(a).end()
#define rwhole(a) (a).rbegin(),(a).rend()

#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(ll i=(a);i>=(b);i--)
#define each(itr,ds) for(auto itr=(ds).begin();itr!=(ds).end();itr++)

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

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

//DUMP
//  ostream vector<T> , vector<vector<T>> , set<T> ,queue<T> , priority_queue<T> , pair<T,U> , map<T,U>
template<class T> ostream& operator<<(ostream&os,vector<T>&vec){os<<"{ ";rep(i,vec.size()) os<<((i==0)?"":", ")<<i<<":"<<vec[i];os<<" }";return os;}
template<class T> ostream& operator<<(ostream&os,vector<vector<T>>&vec){os<<"{"<<endl;rep(i,vec.size())os<<"\t   "<<i<<":"<<vec[i]<<((i==vec.size()-1)? "":",")<<endl;os<<"\t }";return os;}
template<class T> ostream& operator<<(ostream&os,set<T>&p){os<<"{ ";each(itr,p)  os<<((itr==p.begin())?"":", ")<<*itr;os<<" }";return os;}
template<class T> ostream& operator<<(ostream&os,queue<T>&p){queue<T> q(p);os<<"[< "<<(q.empty()?" <]":"");while(!q.empty()){os<<q.front();q.pop();os<< (q.empty() ? " <]" : ", ");}return os;}
template<class T> ostream& operator<<(ostream&os,priority_queue<T>&p){priority_queue<T> q(p);os<<"[< "<<(q.empty()?" <]":"");while(!q.empty()){os<<q.top();q.pop();os<< (q.empty() ? " <]" : ", ");}return os;}
template<class T,class U> ostream& operator<<(ostream&os,pair<T,U>&p){os<<"("<<p.first<<","<<p.second<<")";return os;}
template<class T,class U> ostream& operator<<(ostream&os,map<T,U>&p){os<<"{ ";each(itr,p)os<<((itr==p.begin())?"":", ")<<itr->first<<":"<<itr->second;os<<" }";return os;}
void dump_f(string &nm,char t){cerr<<endl;}
template<class T,class... Ts> void dump_f(string &nm,char t,T &&x,Ts&&... ts){int l=nm.find_first_of(',');string name(nm,0,l),nx(nm,l+1,-1);if(t=='\n') cerr<<"  "<<name<<"\t: "<<x<<t;else cerr << name<<": "<<x<<","<<t;dump_f(nx,t,forward<Ts>(ts)...);}
template<class... Ts> void dump_m(int &&ln,string &&nm,char t,Ts&&... ts){cerr<<"[ln: "<<ln<<"]"<<t;dump_f(nm,t,forward<Ts>(ts)...);}
#define dump(...) DBG dump_m(__LINE__,#__VA_ARGS__,'\n',__VA_ARGS__)
#define dl(...) DBG dump_m(__LINE__,#__VA_ARGS__,'\t',__VA_ARGS__)

#define lower_bound_idx(V,c) distance(V.begin(),lower_bound(whole(V),c))

int main() {
    ios::sync_with_stdio(false);//stdout<=>cout
    cin.tie(nullptr);//cin<=>cout


    ll A,B,N;
    cin >>A>>B>>N;

    //-----------------------------------
    ll x = min(N,B-1);

    cout << A*x/B - A*(x/B) <<endl;
    

    return (0);
}

Measured memory_bytes: 3608
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		List<Integer> list = new ArrayList<Integer>();
		for(int i = 0; i < N - 1; i++) {
			list.add(Integer.parseInt(sc.next()));
		}
		sc.close();

		int ans = list.get(0);
		for(int i = 1; i < list.size(); i++) {
			ans += Math.min(list.get(i - 1), list.get(i));
		}
		ans += list.get(N - 2);

		System.out.println(ans);
	}

}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,ans=0,last;
int rt[200005],b[200005];

struct node
{
	int rt;
	int num;
}a[200005];

bool cmp(node a,node b)
{
	return a.num<b.num;
}

int Binary_search2(int l,int r,int k)//找到最后一个等于k的b序列中的数 
{
	if (l>r)  return last;
	if (l==r||l+1==r)
	{
		if (b[l]==k)  return min(l,last);
		if (b[r]==k)  return min(r,last);
		else return last;
	}
	int mid=(l+r)>>1;
	if (b[mid]>=k)
	{
		if (b[mid]==k)  last=mid;
		return Binary_search2(l,mid,k);
	}
	if (b[mid]<k)  return Binary_search2(mid,r,k);
}

int Binary_search(int l,int r,int k)//找到最后一个等于k的b序列中的数 
{
	if (l>r)  return last;
	if (l==r||l+1==r)
	{
		if (b[r]==k)  return max(r,last);
		if (b[l]==k)  return max(l,last);
		else return last;
	}
	int mid=(l+r)>>1;
	if (b[mid]<=k)
	{
		if (b[mid]==k)  last=mid;
		return Binary_search(mid,r,k);
	}
	else if (b[mid]>k)  return Binary_search(l,mid,k);
} 

signed main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i].num;
		a[i].rt=i;
		a[i].num-=(i-1);
	}
	sort(a+1,a+n+1,cmp);
	
	for (int i=1;i<=n;i++)  rt[a[i].rt]=i;
	for (int i=1;i<=n;i++)  b[i]=a[i].num;
	for (int i=1;i<=n;i++)
	{
		int now=rt[i],sum=2-i*2;
		last=1e9+7;
		int p1=Binary_search2(1,now,sum-b[now]);
		last=-1;
		int p2=Binary_search(1,now-1,sum-b[now]);
		last=1e9+7;
		int p3=Binary_search2(now+1,n,sum-b[now]);
		last=-1;
		int p4=Binary_search(now+1,n,sum-b[now]);
		
		if (p1!=1e9+7&&b[p1]+b[now]==sum)  ans+=(p2-p1)+1;
		if (p3!=1e9+7&&b[p3]+b[now]==sum)  ans+=(p4-p3)+1;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 9720
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int a, b;
  cin >> a >> b;
  a--; b--;
  vector<string> ans(100);
  rep(i, 100)rep(j, 100){
    if(i < 50) ans.at(i).push_back('#');
    else ans.at(i).push_back('.');
  }
  rep(i, 40){
    int j = 0;
    if(i % 2 == 0) j = 1;
    for(; j < 100; j += 2){
      if(a == 0) break;
      ans.at(i*2).at(j) = '.';
      a--;
    }
  }
  rep(i, 40){
    int j = 0;
    if(i % 2 == 0) j = 1;
    for(; j < 100; j += 2){
      if(b == 0) break;
      ans.at(i*2+51).at(j) = '#';
      b--;
    }
  }
  cout << "100 100" << endl;
  rep(i, 100){
    cout << ans.at(i) << endl;
  }
  return 0;
}

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

using namespace std;
int main(int argc, char const *argv[]) {
        int cnt = 0;
        string a;
        getline(cin, a);
        for(int i = 0; i < a.size(); i++) {

                if(!isalpha(a[i])) cout << a[i];
                else {
                        if(islower(a[i])) cout << char(toupper(a[i]));
                        else cout << char(tolower(a[i]));
                }
        }
        cout << endl;
        return 0;
}



Measured memory_bytes: 3164
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  if((a*b*c)%2==0)cout << 0 << endl;
  else cout << min(a*b,min(b*c,c*a)) << endl;
return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;
template <typename T> using vvec = vector<vector<T>>;

constexpr int64_t mpow(int64_t a, int64_t b, int64_t mod = 1000000007) {
    if (b <= 0) { return 1; } if (b == 1) { return a % mod; } if (b == 2) { return (a * a) % mod; }
    return (max(a * (b & 1), (int64_t)1) * mpow(mpow(a, b / 2, mod), 2, mod)) % mod;
}
constexpr int64_t mdiv(int64_t a, int64_t b, int64_t mod = 1000000007) {
    return (a * mpow(b, mod - 2, mod)) % mod;
}

int main() {
    int n; cin >> n;
    int cnt = 0;
    while (n--) {
        int d1, d2; cin >> d1 >> d2;
        if (d1 == d2) {
            ++cnt;
        }
        else {
            cnt = 0;
        }
        if (cnt == 3) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}



Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    string s;
    cin>>s;
    int n=s.size();
    if(s[n-1]=='s') cout<<s<<"es";
    else cout<<s<<'s';
}

Measured memory_bytes: 3624
from heapq import heappush, heappop
N, M = map(int, input().split())
X = []
for _ in range(N):
    a, b = map(int, input().split())
    X.append((a, b))
X = sorted(X)

i = 0
j = 1
H = []
hpush = lambda x: heappush(H, -x)
hpop = lambda: -heappop(H)

ans = 0
for j in range(M+1):
    while i < len(X) and X[i][0] <= j:
        hpush(X[i][1])
        i += 1
    if H: ans += hpop()

print(ans)


Measured memory_bytes: 20396
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq as hq
import itertools as its
import operator as op


# globals
inf = float('inf')
N = 0


def set_inputs():
    global N
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    n = get_int()
    u, v, w = get_data(n - 1, [int, int, int])
    d = defaultdict(list)
    for ui, vi, wi in zip(u, v, w):
        d[ui].append((vi, wi))
        d[vi].append((ui, wi))
    color = [-1] * n
    q = deque()
    color[1-1] = 0
    q.append(1)
    while len(q) > 0:
        ui = q.popleft()
        for vi, wi in d[ui]:
            if color[vi-1] >= 0:
                continue
            color[vi-1] = (color[ui-1] + wi) % 2
            q.append(vi)
    for c in color:
        print(c)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()


Measured memory_bytes: 125268
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}
// 素因数分解
/*
 * [2]-> 5, [3] -> 5のとき N = 2^5 * 3^5
 */
template<typename T>
map<T, long long> factorize(T x) {
  map<T, long long> res;
  for (long long i = 2; i * i <= x; ++i) {
    while (x % i == 0) {
      x /= i;
      res[i] += 1;
    }
  }
  if (x != 1) res[x]++;
  return res;
}


#define MAX 200010

class Combination {
  using _Tp = long long;
public:
  
  _Tp fac[MAX], finv[MAX], inv[MAX];

  Combination() {
    init();
  }

  void init() {
    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;
    }
  }

  // n!! * k!^(-1) * ((n - k)!)^(-1)
  _Tp comb(_Tp n, _Tp k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k]* finv[n - k] % MOD) % MOD;
  }
};

/* END END */

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

  Combination co;

  auto vec = factorize(m);
  ll res = 1;
  for (auto&& itr : vec) {
    auto num = itr.second;
    ll tmp = co.comb(num + n - 1, n - 1);
    res = (res * tmp) % MOD;
  }

  cout << res << endl;
}


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

int main()
{
	int a,b,x;
	int ans = 0;
	cin >> a >> b >> x;
	if (a < 2 * b) {
		ans += (x / 1000) * a;
		if (x % 1000 > 500)ans += a;
		else if (x % 1000 > 0)ans += min(a, b);
	}
	else {
		ans += (x / 500) * b;
		if (x % 500 > 0)ans += b;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3116
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#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 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;
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() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> v(N); rep(i, 0, N) { cin >> v[i]; }
	int K(0);
	while (true) {
		sort(all(v));
		if (v.back() < N)break;

		int x = v[v.size() - 1] / N;
		K += x;

		v[v.size() - 1] %= N;

		rep(i, 0, v.size() - 1)v[i] += x;
	}
	cout << K << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    long long n, a, b;
    // scanf("%d", &n);
    // scanf("%d", &a);
    // scanf("%d", &b);
    scanf("%lld %lld %lld", &n, &a, &b);
    // printf("%lld %lld %lld\n", n, a, b);
    long long amari = n%(a+b);
    if(amari > a) amari = a;
    // printf("%lld\n", amari);
    long long ans = (n-n%(a+b))/(a+b)*a + amari;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long l = sc.nextLong();
    long r = sc.nextLong();
    if(r-l>=2019){
      System.out.println(0);
      return;
    }
    long min = 2020l;
    for(int i = (int)l;i<(int)r;i++){
      for(int j = i + 1;j<=(int)r;j++){
        long ii = i % 2019;
        long jj = j % 2019;
        min = Math.min(min,(ii*jj)%2019);
      }
    }
    System.out.println(min);
  }
}


Measured memory_bytes: 35372