akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
//#include <tuple>
//#include <array>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) begin(v), end(v)
#define REV(v) rbegin(v), rend(v)
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

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

const ll MOD = 1e9 + 7;

map<string, int> weight;

int i;
string s;

int to_int(string s){
	int x = 0;
	rep(i, s.size()) x = x * 10 + s[i] - '0';
	return x;
}

int number(){
	if ('0' <= s[i] && s[i] <= '9'){
		int len = 1;
		if ('0' <= s[i + 1] && s[i + 1] <= '9') ++len;
		i += len;
		return to_int(s.substr(i - len, len));
	}
	return 1;
}

int atom(){
	int len = 1;
	if ('a' <= s[i + 1] && s[i + 1] <= 'z') ++len;
	i += len;
	string tmp = s.substr(i - len, len);
	if (weight.count(tmp)) return weight[tmp];
	return -1;
}

int molecule(){
	int res = 0;
	while (s[i] != '$' && s[i] != ')'){
		int x = -1;
		if (s[i] == '('){
			++i;
			x = molecule() * number();
		}
		else {
			x = atom() * number();
		}
		if (x < 0) return -1;
		res += x;
	}
	++i;
	return res;
}


int main(){
	int w;
	while (cin >> s, s != "END_OF_FIRST_PART"){
		cin >> w;
		weight[s] = w;
	}

	while (cin >> s, s != "0"){
		i = 0;
		s += "$$$";
		int ans = molecule();
		if (ans == -1) cout << "UNKNOWN" << endl;
		else cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#define PI 3.14159265359
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pai;
typedef pair<ll, ll> pal;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

ll modpow(ll a, ll n){
	ll res = 1;
	while(n > 0){
		if (n & 1) res = res * a %MOD;
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}

int main(){
	int n;
	cin >> n;
	if (n == 1){
		cout << 0 << endl;
	}else{
		ll ans = modpow(10, n) - modpow(9, n) - modpow(9, n) + modpow(8, n);
		ans %= MOD;
		if (ans < 0) cout << ans + MOD << endl;
		else cout << ans << endl;
	}
	return 0;
}



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

using namespace std;

int main()
{
    int x, a, dig, sum=0;
    cin>>a;
    x=a;
    while(x>0)
    {
      dig=x%10;
      sum+=dig;
      x/=10;
    }
    if(a%sum==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a+b>c+d)
	   cout<<"Left";
	else if(a+b==c+d)
	   cout<<"Balanced";
	else
	   cout<<"Right";
	return 0;
}

Measured memory_bytes: 256
// AOJ DPL_4_A Coin Combination Problem
// 2018.5.9 bal4u
 
#include <stdio.h>
#include <string.h>
 
// 数値のハッシュ関数
#define HASHSIZ 3456781
typedef struct { long long v; int f; } HASH;
HASH hash[HASHSIZ+3], *hashend = hash+HASHSIZ;

int lookup(long long n)
{
	HASH *p = hash + (int)(n % HASHSIZ);
	while (p->v) {
		if (p->v == n) return p->f;
		if (++p == hashend) p = hash;
	}
	return 0;
}

void insert(long long n)
{
	HASH *p = hash + (int)(n % HASHSIZ);
	while (p->v) {
		if (p->v == n) { p->f++; return; }
		if (++p == hashend) p = hash;
	}
	p->v = n, p->f = 1;
}

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
 
int in()
{
    int n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}

long long inLL()
{
    long long n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}

long long a[1002], b[1002], c[1002], d[1002];

int main()
{
	int N, i, j;
	long long V, t, ans;

	N = in(), V = inLL();
	for (i = 0; i < N; i++) a[i] = inLL();
	for (i = 0; i < N; i++) b[i] = inLL();
	for (i = 0; i < N; i++) c[i] = inLL();
	for (i = 0; i < N; i++) d[i] = inLL();

	for (i = 0; i < N; i++) {
		if (a[i]+3 > V) continue;
		for (j = 0; j < N; j++) {
			t = a[i] + b[j];
			if (t+2 <= V) insert(t);
		}
	}

	ans = 0;
	for (i = 0; i < N; i++) {
		if (c[i]+3 > V) continue;
		for (j = 0; j < N; j++) {
			t = c[i] + d[j];
			if (t+2 <= V) ans += lookup(V-t);
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 55720
#include <stdio.h>
#include <algorithm>

int main() {
  int L; scanf("%d", &L);
  long long dp[5] = {0, 0, 0, 0, 0};
  for(int i = 0; i < L; ++i) {
    int A; scanf("%d", &A);
    int diff2 = A == 0 ? 2 : A % 2;
    int diff1 = (A + 1) % 2;
    dp[0] += A;
    dp[1] += diff2;
    dp[2] += diff1;
    dp[3] += diff2;
    dp[4] += A;

    dp[1] = std::min(dp[0], dp[1]);
    dp[2] = std::min(dp[1], dp[2]);
    dp[3] = std::min(dp[2], dp[3]);
    dp[4] = std::min(dp[3], dp[4]);
  }
  printf("%lld\n", dp[4]);
  return 0;
}


Measured memory_bytes: 128
h, w, k = map(int, input().split(' '))
c = [input() for x in range(h)]
cnt = 0
 
for maskR in range(2**h):
    for maskC in range(2**w):
        black = 0
        for i in range(h):
            for j in range(w):
                if (((maskR >> i) &1) == 0
                    and ((maskC >> j) &1) == 0 and c[i][j] == '#'):
                    black += 1
        if black == k:
            cnt += 1
print(cnt)

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

int main()
{

   long d, a, b;

   cin >> d;
   cin >> a;
   cin >> b;

   if (a >= b)
   {
       cout << "delicious";
   }
   else
   {
        if (b - a <= d)
        {
            cout << "safe";
        }
        else
        {
            cout << "dangerous";
        }
   }

}

Measured memory_bytes: 500
n = int(input())
a = [int(i) for i in input().split()]
b = a[::]
ans1 = ans2 = 0
sign = 1
total = 0
for i in range(n):
    total += a[i]
    if total * sign <= 0:
        k = abs(total - sign)
        ans1 += k
        total = sign
    sign *= -1

sign = -1
total = 0
for i in range(n):
    total += b[i]
    if total * sign <= 0:
        k = abs(total - sign)
        ans2 += k
        total = sign
    sign *= -1
print(min(ans1, ans2))    

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

#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
using ll = long long;

const int maxn = 1e5 + 10; 
const int INF = 0x3f3f3f3f;

int a[maxn],b[maxn];
int A,B,M;

int main()
{
	fastIO;
	cin >> A >> B >> M;
	for(int i = 0; i < A; ++i) cin >> a[i];
	for(int i = 0; i < B; ++i) cin >> b[i];
	int ans = 2e5 + 10;
	for(int i = 0; i < M; ++i){
		int x,y,c; cin >> x >> y >> c;
		ans = min(ans,a[x - 1] + b[y - 1] - c);
	}	
	sort(a,a + A);
	sort(b,b + B);
	ans = min(ans,a[0] + b[0]);
	cout << ans << endl;
	return 0;
}

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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

void LOG(const int& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

i64 ceil(i64 a, i64 b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }
i64 pow(i64 x, i64 y, i64 z) { i64 a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
i64 inv(i64 x, i64 m) { return pow(x, m - 2, m); }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

const i64 M = 1000000007;
signed main() {
  i64 N;
  cin >> N;
  string S;
  cin >> S;
  i64 a = 1;
  i64 f = 0;
  i64 h = 0;
  REP(i, N * 2) {
    if ((f == 0) == (S[i] == 'B')) {
      h += 1;
    } else {
      a *= h;
      a %= M;
      h -= 1;
    }
    f ^= 1;
    if (h < 0) {
      break;
    }
  }
  if (h != 0) {
    cout << 0 << endl;
  } else {
    REP(i, N) {
      a *= i + 1;
      a %= M;
    }
    cout << a << endl;
  }
}


Measured memory_bytes: 720
def fac(n):
    result = 1
    for i in range(n):
        result = result * (i + 1)
    return result

def cmb(n, r):
    return fac(n) // (fac(r) * fac(n - r))

data = input().split()
n = int(data[0])
m = int(data[1])

print(cmb(n, 2) + cmb(m, 2))


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

int main() {

  int N, M, C;
  cin >> N >> M >> C;

  vector<int> B(M);
  for (int i = 0; i < M; i++) {
    cin >> B[i];
  }

  int answer = 0;

  for (int i = 0; i < N; i++) {
    int A = 0;
    for (int j = 0; j < M; j++) {
      int a_;
      cin >> a_;
      A += a_ * B[j];
    }
    if (0 < A + C) {
      answer++;
    }
  }

  cout << answer << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){

  int n;
  int a[200000];
  long long sum = 0, x = 0;
  long long ans[200000];

  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%d", &a[i]);
    sum += a[i];
  }
  
  x += a[0]; sum -= a[0];
  long long min_t = abs(x - sum);
  for(int i = 1; i < n - 1; i++){
    x += a[i];
    sum -= a[i];
    ans[i] = abs(sum - x);
  }

  for(int i = 1; i < n - 1; i++){
    if(ans[i] < min_t)
    min_t = ans[i];
  }
  printf("%lld\n", min_t);

  return 0;
}


Measured memory_bytes: 2560
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
from itertools import combinations, product
#import bisect# lower_bound etc
import numpy as np
def run():
    N,M,X = map(int, sysread().split())
    C = []
    A = []
    for _ in range(N):
        c, *a = map(int, sysread().split())
        C.append(c)
        A.append(a)
    A = np.array(A)
    C = np.array(C)
    val = float('inf')
    for buy in product((0,1), repeat=N):
        buy = np.array(list(buy))
        cost = (C * buy).sum()
        prog = (A.T * buy).sum(axis=1)
        if np.all(prog >= X):
            val = min(val, cost)
    if val == float('inf'):
        print(-1)
        return None
    print(val)


if __name__ == "__main__":
    run()

Measured memory_bytes: 27248
S = input()
a = 97
for i in range(26):
    if not chr(a + i) in S:
        S += chr(a + i)
        ans = S
        break
else:
    memo = [-1] * 200 #使える文字を記録
    flag = 0
    while True:
        i = 0
        while ord(S[-1]) + i < a + 26:
            #print(chr(ord(S[-1]) + i))
            if memo[ord(S[-1]) + i] == 1: #使える文字が見つかった
                s = chr(ord(S[-1]) + i)
                S = S[:-1] + s
                ans = S
                flag = 1
                break
            i += 1
        if flag == 1:
            break
        memo[ord(S[-1])] = 1
        S = S[:-1]
        if len(S) <= 0:
            ans = -1
            break
print(ans)

Measured memory_bytes: 62032
N=int(input())
for i in range(1,3501):
  for j in range(i,3501):
    if (4*i*j-N*(i+j))>0 and N*i*j%(4*i*j-N*(i+j))==0:
      k=N*i*j//(4*i*j-N*(i+j))
      print(i,j,k)
      break
  else:
    continue
  break

Measured memory_bytes: 2940
import java.io.*;
import java.util.*;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();

        int[][] happiness = new int[3][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 3; j++) {
                happiness[j][i] = in.nextInt();
            }
        }

        int[][] table = new int[3][n + 1];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 3; j++) {
                int nextMax = 0;
                for (int k = 0; k < 3; k++) {
                    if (j == k) continue;
                    nextMax = Math.max(nextMax, table[k][i] + happiness[j][i]);
                }
                table[j][i + 1] = nextMax;
            }
        }

        int ans = 0;
        for (int i = 0; i < 3; i++) {
            ans = Math.max(table[i][n], ans);
        }
        out.println(ans);
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 46896
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long

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

int H, W;
vector<string> S;
vector<vector<int>> kuro(1010, vector<int> (1010, -1));
queue<pair<int, int>> Q;
int main(){
  cin >> H >> W;
  S.resize(H);
  for(int i=0; i<H; i++){
    cin >> S[i];
  }
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(S[i][j] == '#'){
        kuro[i][j] = 0;
        pair<int, int> P;
        P = make_pair(i, j);
        Q.push(P);
      }
    }
  }
  while(!Q.empty()){
    pair<int, int> p;
    p = Q.front();
    Q.pop();
    for(int i=0; i<4; i++){
      int ny = p.first + dy[i];
      int nx = p.second + dx[i];
      if(ny<0 || ny>=H || nx<0 || nx>=W){
        continue;
      }
      if(kuro[ny][nx] != -1){
        continue;
      }
      kuro[ny][nx] = kuro[p.first][p.second] + 1;
      pair<int, int> P;
      P = make_pair(ny, nx);
      Q.push(P);
    }
  }
  int ans=0;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      ans = max(ans, kuro[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 13456
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <map>
#include <cmath>

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;

unsigned nChoosek( unsigned n, unsigned k )
{
    if (k > n) return 0;
    if (k * 2 > n) k = n-k;
    if (k == 0) return 1;

    int result = n;
    for( int i = 2; i <= k; ++i ) {
        result *= (n-i+1);
        result /= i;
    }
    return result;
}

double distance2(int* a, int* b, int d)
{
    double sum = 0;
    rep(i, d)
    {
        sum = sum + (b[i] - a[i]) * (b[i] - a[i]);
    }
    sum = sqrt(sum);
    return sum;
}

int main()
{
    ll l, r;
    cin >> l >> r;
    if (r -l > 2019)
    {
        cout << 0;
    }
    else
    {
        int mini = 2020;
        for (ll i = l; i <= r; i++)
        {
            for (ll j = l + 1; j <= r; j++)
            {
                if (i != j)
                {
                    int prod1 = (i % 2019);
                    int prod2 = (j % 2019);
                    if (mini > (prod1 * prod2) % 2019)
                    {
                        mini = (prod1 * prod2) % 2019;
                    }
                }
            }
        }
        cout << mini;
    }

    return 0;
}


Measured memory_bytes: 256
N=int(input())
A=[]
B=[]
#for i in range(2):
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=0
for j in range(N):
    a=sum(A[0:j+1])+sum(B[j:N])
    if ans<a:
        ans=a
print(ans)




Measured memory_bytes: 3060
// https://atcoder.jp/contests/abc148/tasks/abc148_d

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N;
  cin >> N;

  VL as(N);
  rep(i, N) cin >> as[i];

  ll cur = 0;

  rep(i, N) {
    if (as[i] == cur + 1) cur++;
  }

  if (cur == 0) drop(-1);

  ll res = N - cur;
  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

ll calc(ll x){
    ll res = 1;
    while(x%2 == 0){
        x /= 2;
        res *= 2;
    }
    while(x%5 == 0){
        x /= 5;
        res *= 5;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<P, ll> mp;
    rep(i,n){
        string s;
        cin >> s;
        ll a = 0, b = 1;
        bool f = false;
        for(char c : s){
            if(c == '.'){
                f = true;
                continue;
            }
            a = a * 10 + (c - '0');
            if(f) b *= 10;
        }
        ll g = gcd(a, b);
        a /= g;
        a = calc(a);
        b /= g;
        b = calc(b);
        ++mp[P(a, b)];
    }
    vector<P> v;
    v.reserve(mp.size());
    for(auto& p : mp){
        v.push_back(p.first);
    }
    int sz = v.size();
    ll ans = 0;
    rep(i,sz){
        P p1 = v[i];
        rep(j,i+1){
            P p2 = v[j];
            if(p2.first % p1.second == 0 && p1.first % p2.second == 0){
                ll tmp = mp[p1] * mp[p2];
                if(i == j){
                    tmp -= mp[p1];
                    tmp /= 2;
                }
                ans += tmp;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3648
// A.

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <stdio.h>

typedef long long LL;

char buffer[3072000];
LL cnt[20][20];
LL sum[20][20];
LL n;
LL ans;

int main(int argc, char* argv[]) {
	char c, *bufptr = buffer;
	fread(buffer, 1, 3072000, stdin);
	while ((c = *bufptr++) >= '0') {
		n = (n * 10) + (c - '0');
	}
	for (LL i = 0; i < n; ++i) {
		LL x = 0, two = 0, five = 9, df = 0;
		while ((c = *bufptr++) >= ' ') {
			if (c == '.') {
				df = -1;
			} else {
				x = (x * 10) + c - '0';
				five += df;
			}
		}
		two = __builtin_ctzll(x);
		x >>= two;
		two += five;
		while (x % 5 == 0) {
			++five;
			x /= 5;
		}
		cnt[two > 18 ? 18 : two][five] += 1;
	}
	for (int i = 0; i <= 18; ++i) {
		sum[i][0] = cnt[18 - i][18];
		for (int j = 1; j <= 18; ++j) {
			sum[i][j] += sum[i][j - 1] + cnt[18 - i][18 - j];
		}
	}
	for (int i = 1; i <= 18; ++i) {
		for (int j = 0; j <= 18; ++j) {
			sum[i][j] += sum[i - 1][j];
		}
	}
	for (int i = 0; i <= 18; ++i) {
		for (int j = 0; j <= 18; ++j) {
			ans += sum[i][j] * cnt[i][j];
			if (i >= 9 && j >= 9) {
				ans -= cnt[i][j];
			}
		}
	}
	printf("%lld\n", ans >> 1);
	return 0;
}


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

int check(int n, const vector<int>& a) {
    int d = -1;
    int c = 0;
    int r;
    while (n > 0) {
        r = n % 10;
        for (const int x : a) {
            if (r == x) {
                d = c;
                break;
            }
        }
        n /= 10;
        c++;
    }
    return d;
}

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

    int d;
    int s;
    while ((d = check(n, a)) >= 0) {
        s = (int)pow(10, d);
        n += s - (n % s);
    }

    cout << n << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_set>
#include <set>
#include <cstring>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;

using ll = long long;
const ll INF = 1e18 + 1;




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

    ll n;
    cin >> n;
    vector<ll> vec(n);

    for (int i = 0; i < n; ++i) {
        cin >> vec[i];
    }
    sort(vec.begin(), vec.end(), greater<ll>());

    ll ans = 0;

    priority_queue <ll > pq;
    pq.push(vec[0]);

    for (int i = 1; i < n; ++i) {
        ans += pq.top();
        pq.push(vec[i]);
        pq.push(vec[i]);

        pq.pop();
    }

    cout << ans << endl;







}

Measured memory_bytes: 6520
import java.util.*;
public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		long X = sc.nextLong(), Y = sc.nextLong();
		
		int count = 0;
		
		while(X <= Y) {
			count++;
			X *= 2;
		}
		
		System.out.println(count);
	}

}


Measured memory_bytes: 21844
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
    int a,b;
    cin>>a>>b;
    if(a>8||b>8)cout<<":("<<endl;
    else cout<<"Yay!"<<endl;  
    return 0;
}

Measured memory_bytes: 384
using System.Linq;
using System.Collections.Generic;
using System;

public class hello
{
    public static void Main()
    {
        var dict = new Dictionary<int, int>();
        var n = int.Parse(Console.ReadLine().Trim());
        var game = n * (n - 1) / 2;
        for (int i = 0; i < n; i++) dict[i + 1] = 0;
        for (int i = 0; i < game; i++)
        {
            string[] s = Console.ReadLine().Trim().Split(' ');
            var t = Array.ConvertAll(s, int.Parse);
            if (t[2] > t[3]) dict[t[0]] += 3;
            else if (t[2] < t[3]) dict[t[1]] += 3;
            else { dict[t[0]] += 1; dict[t[1]] += 1; }
        }
        foreach (var x in dict)
        {
            var a = dict.Count(y => y.Value > x.Value);
            Console.WriteLine(a + 1);
        }
    }
}

Measured memory_bytes: 10184
n = int(input())
a = list(map(int,input().split()))
dp = [0 for i in range(3)]
for i in range(1,n+1):
  ai = a[i-1]
  if i%2:
    dp[1] = max(dp[0],dp[1])
    dp[0] += ai
  if i%2 == 0:
    dp[2] = max(dp[1],dp[2])
    dp[1] += ai
  if i >= 3 and i%2:
    dp[2] += ai
if n%2 == 0:
  print(max(dp[0],dp[1]))
else:
  print(max(dp[1],dp[2]))

Measured memory_bytes: 105392
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------
    n = int(input())
    p = list(map(int,input().split()))
    if n==1:
        print(1)
        exit()
    a = gcd(p[0],p[1])
    lcm = p[0]*p[1]//a
    for i in range(1,n):
        a = gcd(lcm,p[i])
        lcm *= p[i]//a%Mod
    anslist = []
    for i in p:
        anslist.append(lcm//i)
    print(sum(anslist)%Mod)

if __name__ == "__main__":
    main() #endline===============================================
    

Measured memory_bytes: 264624
#include <iostream>
#include <fstream>
#include <vector>
#include <limits>
#include <cmath>
#include <queue>
using  namespace std;

int main(){

    string s;

    cin >> s;

    if (s[2] == s[3] && s[4] == s[5]){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }



    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n, t;
int level[100010];
const ll MOD = 1e+9 + 7;

int main() {
  while (scanf("%d %d", &n, &t) > 0) {
    REP(i, n) { scanf("%d", &level[i]); }
    sort(level, level + n);
    ll ans = 1;
    deque<int> prev;
    REP(i, n) {
      while (!prev.empty() && prev.front() < level[i] - t) { prev.pop_front(); }
      ans = (ans * (prev.size() + 1)) % MOD;
      prev.push_back(level[i]);
    }
    printf("%lld\n", ans);
  }
}

Measured memory_bytes: 1300
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
#include <utility>
typedef long long ll;
using namespace std;

vector<ll> div(ll n){
  vector<ll> ret;
  ret.clear();
  ll i;
  for(i=2;i*i<n;i++){
    if(n%i==0){
      ret.push_back(i);
      ret.push_back(n/i);
    }
  }
  if(i*i==n){
    ret.push_back(i);
  }

  return ret;
}

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

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

  ll cnt = 0;
  auto d = div(n);
  
  ll tmp;
  for(int i=0;i<d.size();i++){
    tmp = n;
    while(tmp%d[i]==0){
      tmp /= d[i];
    }
    if((tmp-1)%d[i]==0){
      ++cnt;
    }
  }

  auto p = div(n-1);

  cnt += p.size();

  cnt += 2;

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 384
n, k = map(int, input().split())
p = list(map(int, input().split()))
now = sum(p[:k])
ans = (now + k) / 2
for i in range(k, n):
    now += p[i] - p[i - k]
    ans = max(ans, (now + k) / 2)
print(ans)

Measured memory_bytes: 25060
#include <cstdio>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#define min(a,b)    (((a) < (b)) ? (a) : (b))
#define max(a,b)    (((a) > (b)) ? (a) : (b))
#define abs(x)    ((x) < 0 ? -(x) : (x))
#define INF 0x3f3f3f3f
#define delta 0.85
#define eps 1e-3
#define PI 3.14159265358979323846
#define MAX_N 105
using namespace std;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
int H, W;
char mp[MAX_N][MAX_N];

bool judge(int x, int y, char f){
	return x >= 0 && x < H && y >= 0 && y < W && mp[x][y] == f;
}

void dfs(int x, int y){
	char tmp = 'u';
	swap(tmp, mp[x][y]);
	for(int i = 0; i < 4; i++){
		int nx = x + dx[i], ny = y + dy[i];
		if(judge(nx, ny, tmp)) dfs(nx, ny);
	}
	return;
}

int main(){
	while(~scanf("%d%d", &H, &W) && H){
		for(int i = 0; i < H; i++) scanf("%s", mp + i);
		int res = 0;
		for(int x = 0; x < H; x++){
			for(int y = 0; y < W; y++){
				if(mp[x][y] != 'u'){
					dfs(x, y);
					++res;
				}
			}
		}
		printf("%d\n", res);
	}
	return 0;
}


Measured memory_bytes: 3580
INPUT = input()

if INPUT[0] == INPUT[1] and INPUT[1] != INPUT[2] and INPUT[2] == INPUT[3]:
	print('Yes')
	
elif INPUT[0] == INPUT[2] and INPUT[2] != INPUT[1] and INPUT[1] == INPUT[3]:
	print('Yes')
	
elif INPUT[0] == INPUT[3] and INPUT[3] != INPUT[1] and INPUT[1] == INPUT[2]:
	print('Yes')
	
else:
	print('No')

Measured memory_bytes: 3064
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashMap<Integer, ArrayList<Edge>> map = new HashMap<>();
		for (int i = 0; i < n; i++) {
			map.put(i, new ArrayList<>());
		}
		for (int i = 0; i < n - 1; i++) {
			int from = sc.nextInt() - 1;
			int to = sc.nextInt() - 1;
			int dis = sc.nextInt();
			Edge e = new Edge(from, to, dis);
			map.get(from).add(e);
			map.get(to).add(e);
		}
		TreeMap<Integer, Integer> color = new TreeMap<>();
		dfs(map, color, 0, 0);
		for (int i = 0; i < n; i++) {
			System.out.println(color.get(i));
		}
	}
	static void dfs(HashMap<Integer, ArrayList<Edge>> map, TreeMap<Integer, Integer> color, int index, int col) {
		for (int i = 0; i < map.get(index).size(); i++) {
			Edge e = map.get(index).get(i);
			if (!color.containsKey(e.from)) {
				color.put(e.from, (col + e.distance) % 2);
				dfs(map, color, e.from, (col + e.distance) % 2);
			} else if (!color.containsKey(e.to)) {
				color.put(e.to, (col + e.distance) % 2);
				dfs(map, color, e.to, (col + e.distance) % 2);
			}
		}
	}
}

class Edge {
	int from;
	int to;
	int distance;
	Edge(int from, int to, int distance) {
		this.from = from;
		this.to = to;
		this.distance = distance;
	}
}



Measured memory_bytes: 127868
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
#pragma warning (disable: 4996)

class RMQ {
public:
	vector<int>dat; int size_, packsz_;

	void init(int size_) {
		for (int i = 1; i <= 20; i++) {
			if (size_ < (1 << i)) { packsz_ = (1 << i) * 2; break; }
		}
		dat.resize(packsz_, -1000000007);
	}
	void upd(int pos, int x) {
		if (pos == 0)return;
		dat[pos] = max(dat[pos << 1], dat[(pos << 1) + 1]);
		upd(pos / 2, x);
	}
	int query_(int l, int r, int c, int pl, int pr) {
		if (r <= pl || pr <= l)return -1000000007;
		if (l <= pl && pr <= r)return dat[c];
		return max(query_(l, r, c * 2, pl, (pl + pr) / 2), query_(l, r, c * 2 + 1, (pl + pr) / 2, pr));
	}
	void update(int pos, int x) {
		dat[pos + (packsz_ / 2)] = x;
		upd((pos + (packsz_ / 2)) / 2, x);
	}
	int query(int l, int r) {
		return query_(l, r, 1, 0, packsz_ / 2);
	}
};

int N, M, a[1000009], cnt1, cnt2; vector<pair<int, int>>U1[1000009], U2[1000009], V1, V2;

int main() {
	scanf("%d%d", &N, &M);
	for (int i = 1; i <= N; i++)scanf("%d", &a[i]);
	for (int i = 1; i <= N; i += 2) {
		U1[a[i]].push_back(make_pair(a[i], a[i + 1]));
		U1[a[i + 1]].push_back(make_pair(a[i], a[i + 1]));
		V1.push_back(make_pair(a[i], a[i + 1])); cnt1 += 2;
	}
	for (int i = 0; i <= N; i += 2) {
		U2[a[i]].push_back(make_pair(a[i], a[i + 1]));
		U2[a[i + 1]].push_back(make_pair(a[i], a[i + 1]));
		V2.push_back(make_pair(a[i], a[i + 1])); cnt2 += 2;
	}
	RMQ X1, X2; X1.init(M + 2); X2.init(M + 2);
	for (int i = 1; i <= M; i++) {
		X1.update(i, (int)U1[i].size());
		X2.update(i, (int)U2[i].size());
	}
	for (int i = 1; i <= M; i++) {
		// --------------------------------- Pattern 1 --------------------------------------
		int ret = U1[0].size() + U1[i].size(); int V1 = X1.query(i, i + 1);
		for (int j = 0; j < U1[i].size(); j++) {
			int a1 = U1[i][j].first; if (U1[i][j].first == i)a1 = U1[i][j].second;
			X1.update(a1, X1.query(a1, a1 + 1) - 1);
		}
		X1.update(i, 0);
		ret += X1.query(1, M + 1);

		// -------------------------------- Pattern 2 ---------------------------------------
		int ret2 = U2[0].size() + U2[i].size(); int V2 = X2.query(i, i + 1);
		for (int j = 0; j < U2[i].size(); j++) {
			int a1 = U2[i][j].first; if (U2[i][j].first == i)a1 = U2[i][j].second;
			X2.update(a1, X2.query(a1, a1 + 1) - 1);
		}
		X2.update(i, 0);
		ret2 += X2.query(1, M + 1);
		printf("%d\n", min(cnt1 - ret, cnt2 - ret2));

		// -------------------------------- Restoring ---------------------------------------
		for (int j = 0; j < U1[i].size(); j++) {
			int a1 = U1[i][j].first; if (U1[i][j].first == i)a1 = U1[i][j].second;
			X1.update(a1, X1.query(a1, a1 + 1) + 1);
		}
		X1.update(i, V1);
		for (int j = 0; j < U2[i].size(); j++) {
			int a1 = U2[i][j].first; if (U2[i][j].first == i)a1 = U2[i][j].second;
			X2.update(a1, X2.query(a1, a1 + 1) + 1);
		}
		X2.update(i, V2);
	}
	return 0;
}

Measured memory_bytes: 140208
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

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

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    char a[h][w];
    int table[h][w];
    queue<pii> check;

    rep(i, h) rep(j, w) {
        cin >> a[i][j];
        if (a[i][j] == '#') {
            table[i][j] = 0;
            check.push(MP(i, j));
        } else {
            table[i][j] = INF;
        }
    }

    while (!check.empty()) {
        int i = check.front().first;
        int j = check.front().second;
        check.pop();

        rep(iii, 4) {
            int ii = i + Dx[iii];
            int jj = j + Dy[iii];
            if (ii < 0 || ii >= h || jj < 0 || jj >= w) continue;
            if (table[ii][jj] == INF) {
                check.push(MP(ii, jj));
                table[ii][jj] = table[i][j] + 1;
            } else if (table[ii][jj] > table[i][j] + 1) {
                table[ii][jj] = table[i][j] + 1;
            }
        }

    }
    int Max = 0;
    rep(i, h) rep(j, w) Max = max(Max, table[i][j]);
    cout << Max << endl;
    return 0;
}



Measured memory_bytes: 13328
from collections import deque

K = int(input())

ans = []

queue = deque(range(1, 10))

while len(ans) < K:
    n = queue.popleft()
    ans.append(n)
    n_str = str(n)
    p = int(n_str[-1])
    if p - 1 >= 0:
        queue.append(int(n_str+str(p-1)))
    queue.append(int(n_str+str(p)))
    if p + 1 <= 9:
        queue.append(int(n_str+str(p+1)))

print(ans[-1])



Measured memory_bytes: 83848
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
	int a,b,ab_half;
	int x,y;
	int res = 1;

	cin >> a >> b >> ab_half >> x >> y;

	int block = min(x,y);

	//half is high
	if(ab_half*2 > a+b) res = (a+b) * block;
	//hals is cheap
	else res = (ab_half*2) * block;

	if (x>y)
	{
		int comp = x - block;
		if (comp*a < comp*(ab_half*2)) res += comp*a;
		else res += comp*(ab_half*2);

		cout << res << "\n";
	}

	else if (x<y)
	{
		int comp = y - block;
		if (comp*b < comp*(ab_half*2)) res += comp*b;
		else res += comp*(ab_half*2);
		
		cout << res << "\n";
	}

	else
	{
		cout << res << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
d = LI()

ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        ans += d[i]*d[j]

print(ans)

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

int main(int argc, char const *argv[])
{
	int n;
	while(cin>>n,n)
	{
		int x[n],y[n],minx=0,maxx=0,miny=0,maxy=0;
		x[0]=0,y[0]=0;
		int a,b;
		for (int i = 1; i < n; ++i)
		{
			cin>>a>>b;
			int nx=x[a],ny=y[a];
			if(b==0) --nx,minx=min(minx,nx);
			else if(b==1) --ny,miny=min(miny,ny);
			else if(b==2) ++nx,maxx=max(maxx,nx);
			else ++ny,maxy=max(maxy,ny);
			x[i]=nx,y[i]=ny;
		}
		cout<<maxx-minx+1<<" "<<maxy-miny+1<<endl;
	}
	return 0;
}


Measured memory_bytes: 3016
N, K, *A = $<.read.split
# = gets.chomp.split.map(&:to_i)
# A = gets.chomp.split.map(&:to_i)
posi = []
nega = []
zeros = 0
# p N
# p K.class
N, K = N.to_i, K.to_i

A.each do |a|
  a = a.to_i
  if a < 0
    nega << a
  elsif a > 0
    posi << a
  else
    zeros += 1
  end
end

posi.sort!
nega.sort!.reverse!

posi_size = posi.size
nega_size = nega.size

zero_pairs = zeros * (zeros - 1) / 2 + zeros * (N - zeros)

ng = -(10**18 + 1)
ok = 10**18 + 1

while ok - ng > 1
  mid = (ok + ng) / 2
  cnt = 0
  
  cnt += zero_pairs if mid >= 0

  if mid > 0
    cnt += nega_size * posi_size
    [posi, nega].each do |a|
      l = 0
      r = a.size - 1
      while l < r
        r -= 1 while l < r && a[l] * a[r] > mid
        cnt += r - l
        l += 1
      end
    end
  else
    r = nega_size - 1
    posi.size.times do |l|
      r -= 1 while(r >= 0 && posi[l] * nega[r] <= mid)
      cnt += nega_size - r - 1
    end
  end

  cnt >= K ? (ok = mid) : (ng = mid)
end

puts ok

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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int a, b;
    cin >> a >> b;
    int d = b - a;
    int total = 0;
    for (int i = 1; i < d; i++) {
        total += i;
    }
    print(total - a);
}

signed main() {
    solve();
}


Measured memory_bytes: 256
# aising2019C - Alternating Path
import sys

sys.setrecursionlimit(10 ** 9)


def dfs(x: int, y: int) -> None:
    global blk, wht
    seen[x][y] = 1
    cur = S[x][y]
    if cur:
        blk += 1
    else:
        wht += 1
    for dx, dy in dxy:
        nx, ny = x + dx, y + dy
        if 0 <= nx < H and 0 <= ny < W and S[nx][ny] != cur and not seen[nx][ny]:
            dfs(nx, ny)


def main():
    # separate S to connected components
    global H, W, S, seen, dxy, blk, wht
    H, W, *S = open(0).read().split()
    H, W = int(H), int(W)
    S = [[1 if i == "#" else 0 for i in s] for s in S]
    seen = [[0] * W for _ in range(H)]
    dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    ans = 0
    for i in range(H):
        for j in range(W):
            if not seen[i][j]:
                blk, wht = 0, 0
                dfs(i, j)
                ans += blk * wht
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 150580
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
	int a;
	cin >> a;
	cout << a + a * a + a * a * a << endl;
}

Measured memory_bytes: 3560
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

int sum(int N) {
  return N * (N + 1) / 2;
}

signed main() {
  int X;
  cin >> X;

  int ok = X + 1;
  int ng = 0;

  while (ok - ng > 1) {
    int mid = (ok + ng) / 2;
    (sum(mid) >= X ? ok : ng) = mid;
  }
  cout << ok << endl;
}

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

int main(){
  string N;
  cin >> N;
  int fx = 0;
  int t;
  t = stoi(N);
  for(int i = 0; i < N.size(); i++){
    fx += (t % 10);
    t /= 10;
  }
  if(stoi(N) % fx == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#include <math.h>
#include <iostream>
#include <bitset>
#include <map>

#define db double
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define mod 998244353
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv(z,a,b) vector<vector<int>>z(a,vector<int>(b))
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) begin(c),end(c)
#define pp pair<int,int>
#define fix(n) fixed << setprecision(n)
#define gmax(a,b) __gcd(a,b)
#define gmin(a,b) a/__gcd(a,b)*b
using namespace std;
//obj;
class binary{
public:
    bool isOK(int index, int key,vi a) {
    if (a[index] >= key) return true;
    else return false;
}
int binary_search(int key,vi a) {
   
    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key,a)) ok = mid;
        else ng = mid;
    }
    return ok;
}
}obj;

int main(){
int n,k;cin>>n>>k;
vi a(n);
rep(i,n)cin>>a.at(i);
for(int i=k;i<n;i++){
if(a.at(i-k)>=a.at(i))cout<<"No"<<endl;
else cout<<"Yes"<<endl;
}


return 0;
 }


Measured memory_bytes: 4044
#include<iostream>
using namespace std;
int n,a[150],maxn=0,ans=0;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]>=maxn)
        {
            ans++;
            maxn=a[i];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if (a <= b * c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 35724
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

H, W = map(int, input().split())
if H > W:
    H, W = W, H

S = H * W

ans = INF
for i in range(1, H + 1):
    a = i * W
    h = H - i
    w = W
    remain = S - a
    b = h * (w // 2)
    c = remain - b
    ans = min(ans, max(a, b, c) - min(a, b, c))
    b = w * (h // 2)
    c = remain - b
    ans = min(ans, max(a, b, c) - min(a, b, c))
for i in range(1, W + 1):
    a = i * H
    h = H
    w = W - i
    remain = S - a
    b = h * (w // 2)
    c = remain - b
    ans = min(ans, max(a, b, c) - min(a, b, c))
    b = w * (h // 2)
    c = remain - b
    ans = min(ans, max(a, b, c) - min(a, b, c))
print(ans)



Measured memory_bytes: 9488