akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
# Your code here!
class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n))#親ノード
        self.size = [1]*n #グループの要素数

    def root(self, x): #root(x): xの根ノードを返す．
        if self.parent[x] == x:
            return x
        elif self.parent[self.parent[x]] == x:
            return self.parent[x]
        else:
            self.parent[x] = self.root(self.parent[x]) #xをxの根に直接つなぐ
            return self.parent[x]

    def merge(self, x, y): #merge(x,y): xのいるグループと$y$のいるグループをまとめる
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.size[x] < self.size[y]: #xの要素数がyの要素数より「小さい」とき入れ替える
            x,y=y,x
        self.size[x] += self.size[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        return True

    def issame(self, x, y): #same(x,y): xとyが同じグループにあるならTrue
        return self.root(x) == self.root(y)
        
    def size(self,x): #size(x): xのいるグループの要素数を返す
        return self.size[self.root(x)]


n,m = [int(i) for i in input().split()]
 
T=UnionFind(n)
c=0
for _ in [0]*m:
    x,y,z=[int(i) for i in input().split()]
    if not T.issame(x-1,y-1):
        T.merge(x-1,y-1)
        c+=1
 
print(n-c)

Measured memory_bytes: 8564
#!/usr/bin/env python3

#import
#import math
#import numpy as np

s = input()
q = int(input())

inv = False

fro = ""
end = ""

for _ in range(q):
    query = list(map(str, input().split()))

    if query[0] == "1":
        inv = not inv

    else:
        t = int(query[1])
        instr = query[2]
        if not inv:
            if t == 1:
                fro = instr + fro
            else:
                end = end + instr

        else:
            if t == 1:
                end = end + instr[::-1]
            else:
                fro = instr[::-1] + fro

ans = fro + s + end

if not inv:
    print(ans)

else:
    print(ans[::-1])

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define int long long
const int inf = 100100100100100;
const int mod = 1000000007;

int mod_pow(int x, int n, int m){
    if(n== 0) return 1;
    int res = mod_pow(x*x%m,n/2,m);
    if(n&1) res = res*x%m;
    return res;
}

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

    string s;
    cin >> s;
    int len = s.size();

    vector<int> acs;
    acs.push_back(0);
    vector<int> lcs;
    lcs.push_back(0);

    vector<int> ccs;
    ccs.push_back(0);
    vector<int> rcs;
    rcs.push_back(0);

    rep(i,0,len){
        if(s[i] == 'A'){
            acs.push_back(acs.back()+1);
            lcs.push_back(lcs.back());
        }
        else if(s[i] == '?'){
            lcs.push_back(lcs.back()+1);
            acs.push_back(acs.back());
        }
        else{
            acs.push_back(acs.back());
            lcs.push_back(lcs.back());
        }
    }

    for(int i = len-1; i > -1; i--){
        if(s[i] == 'C'){
            ccs.push_back(ccs.back()+1);
            rcs.push_back(rcs.back());
        }
        else if(s[i] == '?'){
            rcs.push_back(rcs.back()+1);
            ccs.push_back(ccs.back());
        }
        else{
            ccs.push_back(ccs.back());
            rcs.push_back(rcs.back());
        }
    }

    reverse(ccs.begin(),ccs.end());
    reverse(rcs.begin(),rcs.end());

    int ans = 0;
    rep(i,0,len){
        if(s[i] == 'B' || s[i] == '?'){
            ans += acs[i]%mod * ccs[i+1]%mod * mod_pow(3, lcs[i] + rcs[i+1],mod);
            ans += lcs[i]%mod * ccs[i+1]%mod * mod_pow(3, lcs[i] + rcs[i+1] - 1,mod);
            ans += acs[i]%mod * rcs[i+1]%mod * mod_pow(3, lcs[i] + rcs[i+1] - 1,mod);
            ans += lcs[i]%mod * rcs[i+1]%mod * mod_pow(3, lcs[i] + rcs[i+1] - 2,mod);
            ans %= mod;
        }
    }
    cout << ans % mod << endl;
}

Measured memory_bytes: 4476
#include <stdio.h>

int main(void)
{
	int x1,x2,a;
	scanf("%d %d",&x1,&x2);
	if(x1>x2){
		a=x1-x2;
	}
	else if(x2>x1){
		a=x2-x1;
	}
	else{
		a=x1-x2;
	}
	printf("%d\n",a);
	return 0;
}


Measured memory_bytes: 2064
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds; 
typedef long long int ll;
#define ull unsigned long long int
#define all(a) a.begin(),a.end()s
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define hell 1000000007
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define pb push_back
#define MAX 10000001
double maxvolume(double s) 
{ 
    // finding length 
    double length = s / 3; 
   //cout<<length<<endl;
    s -= length; 
  //cout<<s<<endl;
    // finding breadth 
    double breadth = s / 2; 
  
    // finding height 
    double height = s - breadth; 
  //cout<<breadth<<endl<<height<<endl;
    return length * breadth * height; 
} 
int main()
{
    double n;
    cin>>n;
    /*double len = n/3;
    double vol = (double)len*len*len;
    cout<<setprecision(6)<<vol;*/
    cout<<setprecision(8)<<maxvolume(n);
}

Measured memory_bytes: 256
# 一点更新区間取得
class segmentTree:
    def __init__(self, init_val, operator, identity):
        """
        :param init_val: 操作したい配列
        :param operator: 演算子(minはそのままでok。sumはlistを引数にとるからエラー->add関数を自作)
        :param identity: 演算子に対応する単位元(minならinf,sumなら0)
        """
        self.identity = identity
        self.operator = operator

        n = len(init_val)
        n_bin = bin(n)[2:]
        bc = sum([int(digit) for digit in n_bin])
        if bc == 1:  # 2のべき乗ならすっぽり入る
            self.num_end_leaves = 2**(len(n_bin)-1)
        else:  # 2のべき乗でないなら、はみ出すからー１しない
            self.num_end_leaves = 2**len(n_bin)

        self.tree = [identity for _ in range(self.num_end_leaves * 2)]
        # 葉に要素をセット
        for i in range(n):
            self.tree[i + self.num_end_leaves] = init_val[i]
        # segtree構築
        for i in range(1, self.num_end_leaves)[::-1]:
            self.tree[i] = self.operator(self.tree[2*i], self.tree[2*i+1])


    def update(self, x, val):
        """
        :param x: 更新するidx(0-indexed)
        :param val: 更新する値
        """
        leaf_x = x + self.num_end_leaves
        self.tree[leaf_x] = val
        while leaf_x > 0:
            leaf_x //= 2
            self.tree[leaf_x] = self.operator(self.tree[leaf_x*2], self.tree[leaf_x*2+1])
            # operaterがminだったりする

    def query(self, left, right):
        """
        :param left: queryの左idx(1-indexed)
        :param right: queryの右idx(1-indexed)
        大体queryは1-indexedなので、0-indexedにして
        left_0 = left - 1
        right_0 = right - 1
        半閉半開を考えるので、[left_0, right_0+1)
        つまり、[left_0, right)
        leftだけ-1する
        """
        left += self.num_end_leaves
        left -= 1
        right += self.num_end_leaves
        val_l = val_r = self.identity
        while right - left > 0:
            if left & 1:
                val_l = self.operator(val_l, self.tree[left])
                left += 1
            if right & 1:
                right -= 1
                val_r = self.operator(self.tree[right], val_r)
            left >>= 1
            right >>= 1
        return self.operator(val_l, val_r)


n, q = map(int, input().split())
a = list(map(int, input().split()))
st = segmentTree(a, max, 0)
res = list()

for _ in range(q):
    t, x, y = map(int, input().split())
    if t == 1:
        st.update(x - 1, y)
    elif t == 2:
        print(st.query(x, y))
    else:
        hi = n + 1
        lo = x - 1
        while hi - lo > 1:
            mid = (hi + lo) // 2
            if st.query(x, mid) >= y:
                hi = mid
            else:
                lo = mid
        print(lo + 1)


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

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

	ll ans = 1e18;
	for(ll i = 1; i*i <= n; i++){
		if(n%i == 0){
			ll j = n/i;
			ans = min(ans, i+j-2);
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int n, m, k, ans;

int main() {
    cin >> n >> m >> k;
    if (n + m >= k)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3592
N = gets.to_i
Hs = gets.split.map(&:to_i)
ans = "Yes"

Hs.reverse!

if N > 1
    pre = Hs[0]
    for i in 1...N do
        if pre == Hs[i]
            next
        elsif pre < Hs[i]
            if pre == Hs[i] - 1
                pre = Hs[i] - 1
                next
            else
                ans = "No"
                break
            end
        else
            pre = Hs[i]
            next
        end
    end
end

puts ans

Measured memory_bytes: 8588
N, Y = map(int, input().split())

def calc(N, Y):
    for i in range(N + 1):
        for j in range(N + 1 - i):
            if Y == i * 10000 + j * 5000 + (N - i -j) * 1000 == Y:
                return (i, j, (N - i - j))
    return (-1, -1, -1)

a, b ,c = calc(N, Y)
print(str(a) + " " + str(b) + " " + str(c))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;

int S;
int dp[2020];
int main()
{
	cin >> S;
	dp[0] = 1;
	for(int i=0;i<=S;i++)
	{
		for(int j=3;j<=S-i;j++)
		{
			dp[i+j] = (dp[i+j] + dp[i])%MOD;
		}
	}
	cout << dp[S] << endl;
	return 0;
}

Measured memory_bytes: 3592
from bisect import *
from heapq import *
import math
mod = 10**9+7
N, K = map(int, input().split())
A = list(map(int, input().split()))
l = 0
r = 10**9+1
while l+1 < r:
    x = (l+r)//2
    k = 0
    for a in A:
        k += math.ceil(a/x)-1
        if k > K:
            break
    if K < k:
        l = x
    else:
        r = x
print(r)

Measured memory_bytes: 105252
import sys
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def MAP(): return map(int, input().split())
inf = sys.maxsize

h, w, k = MAP()
s = [[int(i) for i in STR()] for _ in range(h)]

ans = inf
for i in range(2 ** (h - 1)): #縦方向の割り方を全探索 O(500)
    hdiv = [1 for _ in range(h)]
    for j in range(h - 1):
        tmp = 2 ** j
        hdiv[j] = 1 if i & tmp else 0
    sh = sum(hdiv)
    tmpans = sh - 1
    wdiv = [0 for _ in range(w - 1)]
    partsum = [0 for _ in range(sh + 1)]
    j = 0
    cnt = 0
    while j < w: #O(2 * 10 ** 4)
        tmp = 0
        idx = 0
        for kk in range(h): #O(10)
            tmp += s[kk][j]
            if hdiv[kk]:
                partsum[idx] += tmp
                tmp = 0
                idx += 1
        flag = True
        for kk in range(sh + 1):
            if partsum[kk] > k:
                tmpans += 1
                partsum = [0 for _ in range(sh + 1)]
                flag = False
        if flag:
            j += 1
            cnt = 0
        else:
            cnt += 1
        if cnt > 2:
            tmpans = inf
            break
    ans = min(ans, tmpans)
print(ans)


Measured memory_bytes: 47580
#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>;

const int MAX_N = 100005;

int MOD = 10;
struct ModInt {
    unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const {
        long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u);
    }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : MOD - x; return t; }
};
typedef ModInt mint;

vector<int> to[MAX_N];

struct DP {
  mint dp;
  DP(mint dp=1):dp(dp) {}
  DP operator+(const DP& a) const {
    return DP(dp*a.dp);
  }
  DP addRoot() const {
    return DP(dp+1);
  }
};

vector<DP> dp[MAX_N];
DP ans[MAX_N];

DP dfs(int v, int p=-1) {
  DP dpSum;
  dp[v] = vector<DP>(to[v].size());
  rep(i,to[v].size()) {
    int u = to[v][i];
    if (u == p) continue;
    dp[v][i] = dfs(u,v);
    dpSum = dpSum + dp[v][i];
  }
  return dpSum.addRoot();
}
void bfs(int v, const DP& dpP=DP(), int p=-1) {
  int deg = to[v].size();
  rep(i,deg) if (to[v][i] == p) dp[v][i] = dpP;

  vector<DP> dpLeft(deg+1);
  rep(i,deg) dpLeft[i+1] = dpLeft[i] + dp[v][i];
  
  vector<DP> dpRight(deg+1);
  for (int i = deg-1; i >= 0; --i)
    dpRight[i] = dpRight[i+1] + dp[v][i];
  
  ans[v] = dpLeft[deg].addRoot();

  rep(i,deg) {
    int u = to[v][i];
    if (u == p) continue;
    DP d = dpLeft[i] + dpRight[i+1];
    bfs(u, d.addRoot(), v);
  }
}

int main() {
  int n;
  cin >> n >> MOD;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  dfs(0);
  bfs(0);
  rep(i,n){
    cout << (ans[i].dp.x+MOD-1)%MOD << endl;
  }
  return 0;
}


Measured memory_bytes: 27236
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int[] A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        Array.Sort(A);
      
        int x = 0;
        int y = 0;
        int i = N - 1;
        for(;i > 0;i--)
        {
          if(A[i] == A[i - 1])
          {
            x = A[i];
            i -= 2;
            break;
          }
        }
        for(; i > 0;i--)
        {
          if(A[i] == A[i - 1])
          {
            y = A[i];
            break;
          }
        }
      
      Console.WriteLine((long)x*y);
    }
}


Measured memory_bytes: 20832
#include <iostream>
#include <vector>
#include <stdio.h>
#include <string>
#include <cctype>

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

typedef long long ll;

using namespace std;

const int INF = 1e9;
const double PI=3.14159265358979323846;

int main(){
  string s;
  int alphabet[26] = {};    
  while(getline(cin,s)){
    rep(i,s.size()){
      if(!isalpha(s[i])) continue;
      alphabet[tolower(s[i])-'a'] += 1;
    }
  }
  rep(i,26){
    cout << char('a'+i) << " : " << alphabet[i] << endl;
  }  
}



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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> a(M);
  vector<int> b(M);
  for(int i=0; i<M; i++) cin >> a[i] >> b[i];
  vector<int> ans(N);
  for(int i=0; i<M; i++){
    ans[a[i]-1]++;
    ans[b[i]-1]++;
  }
  for(int i=0; i<N; i++){
    cout << ans[i] <<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if (a < b) {
		printf("a < b\n");
	} else if (a > b) {
		printf("a > b\n");
	} else {
		printf("a == b\n",a,b);
	}
	return 0;
}


Measured memory_bytes: 2080
#include <bits/stdc++.h>
using namespace std;
int main(){
    long n,a,b,t;
    long e=0;
    scanf("%ld %ld %ld",&n,&a,&b);
    if(a>=n){
        printf("%ld",n);
        return 0;
    }if(a==0){
        printf("0");
        return 0;
    }
    t=a+b;
    //a+b
    if(n%t!=0){
        e=a*(n/t);
        if((n%t)<=a){
            e+=n%t;
        }else{
            e+=a;
        }
    }else{
        e=a*(n/t);
    }
    printf("%ld",e);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
long long a[400005];
long long aabs(long long x) {
    return max(x, -x);
}
int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        a[i] -= i;
    }
    sort(a + 1, a + 1 + n);
    long long res = 0;
    for (int i = 1; i <= n; ++i) {
        res += aabs(a[i] - a[n / 2 + 1]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e9
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(b<a) { a=b; return 1; } return 0; }

int main(){
  string s; cin >> s;
  int n = s.size();
  int k; cin >> k;
  ll ans = 0;
  bool same = true;

  rep(i,n-1){
    if(s[i] == s[i+1]){
      ans++;
      i++;
    }
    if(s[0] != s[i+1]) same = false;
  }

  if(same){
    ans = (ll)n*k/2;
  }else{
    ans *= k;
    if(s[0] == s[n-1]){
      int a = 0, b = n-1;
      while(s[0] == s[a]) a++;
      while(s[n-1] == s[b]) b--;
      b = n-1 - b;
      ans -= (a/2 + b/2 - (a+b)/2)*(k-1);
    }
  }

  cout << ans;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

struct PrimeList
{
	PrimeList()
	{
		prime.clear();
	};
	~PrimeList() {};

	void init(int n)
	{
		std::vector<bool> isComposite(n + 1);
		for (int i = 2; i <= n; ++i)
		{
			if (isComposite[i])continue;
			prime.push_back(i);
			for (int j = i; j <= n; j += i)
			{
				isComposite[j] = true;
			}
		}
	}

	std::vector<int> prime;
};

int A[10005];

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

	int max = 0;
	REP(i, N)
	{
		cin >> A[i];
		max = std::max(max, A[i]);
	}
	p.init(10001);
	sort(A, A + N);
	int sum = 0;
	int pi = 0;
	REP(i, N)
	{
		bool isP = true;
		REP(j, p.prime.size())
		{
			if (A[i] <= p.prime[j])break;
			if (A[i] % p.prime[j] == 0)
			{
				isP = false;
				break;
			}
		}
		if (isP)
		{
			sum++;
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3132
# -*- coding: utf-8 -*-
from collections import Counter
def inpl(): return map(int, input().split())
N, M = inpl()
A = list(inpl())
S = []
t = 0
for a in A:
    t = (t+a)%M
    S.append(t)
C = Counter(S)
ans = C[0]

for k in C.keys():
    ans += C[k]*(C[k]-1)//2
print(ans)

Measured memory_bytes: 17488
from sys import stdin
N = int(stdin.readline().rstrip())
T, A = [int(x) for x in stdin.readline().rstrip().split()]
H = [int(x) for x in stdin.readline().rstrip().split()]
temperature = [abs(T - x * 0.006 - A) for x in H]
ST = sorted(temperature)
print(temperature.index(ST[0]) + 1)

Measured memory_bytes: 3060
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()

def main():
    n = int(input())
    D = [defaultdict(int) for _ in range(n)]
    for i in range(n):
        s = input()
        for c in s:
            D[i][c] += 1
    ans = ""
    for i in range(26):
        c = chr(i + 97)
        minimum = 10**18
        for d in D:
            if c not in d:
                minimum = 0
                break
            minimum = min(minimum, d[c])
        if minimum == 0: continue
        ans += c * minimum
    print(ans)
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 69800
#include<iostream>
#define MOD 1000000007
#define N 300000
using namespace std;
typedef long long LL;
LL mod_pow(LL base, LL exp)
{
	if(exp==0) return 1;
	if(exp&1) return (mod_pow(base,exp-1)*base)%MOD;
	else return mod_pow((base*base)%MOD,exp/2);
}
LL fac[3*N+1];
LL fac_inv[3*N+1];
LL C(LL n, LL k)
{
	if(k < 0 || n < k) return 0;
	LL num = fac[n];
	LL den = (fac_inv[n-k]*fac_inv[k])%MOD;
	return (num*den)%MOD;
}
int main()
{
	fac[0] = 1;
	for(LL n = 1; n <= 3*N; n++)
		fac[n] = (fac[n-1]*n)%MOD;
	fac_inv[3*N] = mod_pow(fac[3*N],MOD-2);
	for(LL n = 3*N-1; n >= 0; n--)
		fac_inv[n] = (fac_inv[n+1]*(n+1))%MOD;

	LL a, b, c; cin >> a >> b >> c;
	a++;
	//WLOG, b > c
	if(!(b>c))
	{
		b = b^c;
		c = b^c;
		b = b^c;
	}

	LL ans = 0;
	LL sum = 1;
	LL pull = 0;
	for(LL n = a; n <= a+b+c; n++)
	{
		LL sub = 0;
		
		sub = (sub+sum-pull)%MOD;
		sub = (sub*C(n-2,a-2))%MOD;
		sub = (sub*mod_pow(3,a+b+c-n))%MOD;
		ans = (ans+sub)%MOD;

		sum  = (2*sum-C(n-a,c))%MOD;
		pull = (2*pull+C(n-a,n-a-b))%MOD;
	}
	cout<<(ans+MOD)%MOD<<endl;

	return 0;
}

Measured memory_bytes: 14968
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <regex>
#include <string>
#include <stack>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

int main()
{
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if (a == 5 && b == 5 && c == 7 || a == 5 && b == 7 && c == 5 || a == 7 && b == 5 && c == 5)
		puts("YES");
	else
		puts("NO");

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
using namespace std;

int main() {
	int a, b, c, d; cin >> a >> b >> c >> d;
	if (a + b > c + d) cout << "Left" << endl;
	else if (a + b < c + d)cout << "Right" << endl;
	else cout << "Balanced" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int main(){
    int N;
    cin>>N;
    vector<int> P(N),Q(N);
    rep(i,N){
        cin>>P[i];
        P[i]--;
    }
    rep(i,N) Q[P[i]]=i;
    rep(i,N){
        cout<<Q[i]+1<<" ";
    }
}

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

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

  long long cnt = 0;
  for(long long A = 1; A < N; A++) {
    cnt += (N-1)/A;
  }

  cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
 
ostream& operator<<(ostream &out, string str) {
	for(char c : str) out << c;
	return out;
}
 
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
	return out << "(" << p.first << ", " << p.second << ")";
}
 
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
	out << "{";
	for(auto it = a.begin(); it != a.end(); it = next(it))
		out << (it != a.begin() ? ", " : "") << *it;
	return out << "}";
}
 
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
	cerr << a << ", ";
	dump(x...);
}
 
#ifdef DEBUG
#  define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#  define debug(...) false
#endif
 
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
 
template<class T> int size(T && a) { return a.size(); }
 
using LL = long long;
using PII = pair<int, int>;
 
mt19937 _gen(chrono::system_clock::now().time_since_epoch().count());
int rd(int a, int b) {
	return uniform_int_distribution<int>(a, b)(_gen);
}
 
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n, m;
	cin >> n >> m;

	multiset<int> S;
	REP(i, n) {
		int a;
		cin >> a;
		S.emplace(a);
	}

	REP(i, m) {
		auto it = prev(S.end());
		int val = *it;
		S.erase(it);
		S.emplace(val / 2);
	}

	LL ans = 0;
	for(int x : S)
		ans += x;

	cout << ans << "\n";
}


Measured memory_bytes: 4992
#include<stdio.h>
int main()
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(a<b)
{
 if(b<c)
 {
 printf("Yes\n");
 }
 else
 {
 printf("No\n");
 }
}
else
{
 printf("No\n");
}
return 0;
}

Measured memory_bytes: 2648
N = int(input())

# 文字列の出現回数を格納
S = {}
for _ in range(N):
    s = input()
    if s in S:
        S[s] += 1
    else:
        S[s] = 1

# 出現回数が最大の文字列をansに格納し、昇順にソートする
# ans = [k for k, v in S.items() if v == max(S.values())]
# ans.sort()
max_value = max(S.values())
ans = sorted([k for k, v in S.items() if v == max_value])

# 出力
for a in ans:
    print(a)

Measured memory_bytes: 32988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define SZ(i) int(i.size())
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#endif

const int MAXN = 3003;
const ll MOD = 1000000007;

int n, t, pre[MAXN], dp[MAXN][MAXN];
vector<pair<int,int> > food;
/*********************GoodLuck***********************/
int main () {
    IOS();
    cin >> n >> t;

    food.emplace_back(-1, 0);
    REP1 (i, n) {
        int a, b;
        cin >> a >> b;
        food.emplace_back(a, b);
    }
    sort(food.begin(), food.end());


    for (int i=n; i>=1; i--) {
        pre[i] = max(pre[i+1], food[i].second);
    }

    int ans = 0;
    REP1 (i, n) {
        debug(food[i].first, food[i].second);
        for (int k=0; k<t; k++) {
            dp[i][k] = dp[i-1][k];
            if (k >= food[i].first) {
                dp[i][k] = max(dp[i-1][k-food[i].first]+food[i].second, dp[i][k]);
            }
            ans = max(ans, dp[i][k] + pre[i+1]);
        }
    }
    debug(dp[1][10]);
    debug(dp[2][20]);
    debug(dp[3][30]);

    cout << ans << endl;
}


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

#define is_uruu main
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(a);i>(b);--i)
    
int is_uruu() {
	long int N,K;
	long long count=0;
	cin >> N >> K;
	
	if(K!=0){
		FOR(b,K+1,N+1){
			if((N%b)-K >= 0){
				count += (b-K)*(N/b)+N%b+1-K;
			}
			if((N%b)-K < 0){
				count += (b-K)*(N/b);
			}
		}
	}
	if(K==0){
		count = N*1ll*N;
	}
	cout << count << endl;
    return 0;
}

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

int main() {
  int N;
  int count=0;
  std::cin >> N;
  std::vector<int> data(N);
  for (int i=0; i<N; i++) {
    std::cin >> data.at(i);
  }
  std::sort(data.rbegin(),data.rend());
  for (int i=0; i<N-2; i++) {
    for (int j=i+1; j<N-1; j++) {
      for (int k=j+1; k<N; k++) {
        if (data.at(i) < data.at(j)+data.at(k)) {
          count++;
        }
        else {
          break;
        }
      }
    }
  }
  std::cout << count << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cmath>
#include<string>
using namespace std;
#define f first
#define s second
#define MOD 1000000007
#define fast ios::sync_with_stdio(0),cout.tie(0),cin.tie(0)
#define pb push_back
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define mkt make_tuple
typedef long long ll;
typedef unsigned long long ull;
class solution{
public:
	ll pow;
	
	void solve(){
		ll n;
		cin>>n;
		ll ans =1;
		n = n /2;
		ll current =1;
		while(n>=1){
			n = n/2;
			current = current *2;
			ans += current;
		}
		cout<<ans;
	}

};

int main()
{
    fast;
	ll i=0;
	solution s;
	s.solve();

 return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int matrixChainOrder(int,int[]);
int min(int,int);

int main(int argc, char** argv) {
    int matDim;
    scanf("%d",&matDim);
    int dimArray[matDim+1];
    for(int i = 0; i < matDim; i++)
        scanf("%d %d", &dimArray[i], &dimArray[i+1]);
    printf("%d\n",matrixChainOrder(matDim,dimArray));    
    
    return (EXIT_SUCCESS);
}

int matrixChainOrder(int size, int p[size]){
    int cost[size][size];
    int j, temp;
    for(int i = 0; i < size; i++)
        for(int j = 0; j < size; j++)
            cost[i][j] = 0;
    for(int l = 2; l <= size; l++)
        for(int i = 0; i < size-l+1; i++){
            j = i+l-1;
            cost[i][j] = INT_MAX;
            for(int k = i; k < j; k++){
                temp = cost[i][k] + cost[k+1][j] + p[i]*p[k+1]*p[j+1];
                cost[i][j] = min(cost[i][j],temp);
            }
        }
    return cost[0][size-1];
}

int min(int a, int b){
    if(a < b)
        return a;
    return b;
}



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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  int number;
  cin >> number;
  int count = 0;
  for(int i=0; i < a + 1; i++) {
    for(int j=0; j< b + 1; j++) {
    	for(int k=0; k< c+1; k++) {
          if(500 * i + 100 * j + 50 * k == number){
          	count++;
          }
        }
    }
  }
  cout << count <<endl;
}


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

int main() {
  int n;
  cin >> n;
  int a[n];
  for ( int i = 0; i < n; i++ ) { cin >> a[i]; }
  sort(a, a+n, greater<int>());
  
  int ans = 0;
  for ( int i = 0; i < n; i++ ) {
    ans += ( i%2 == 0 ) ? a[i] : -a[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3544
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 2 * 105000;

int n;
long long k;
int a[MAXN];
vector<int> pos, neg;
int z;
long long zn;
long long total;

long long getCnt(long long x) {
  long long cnt = 0;
  if (0 >= x) {
    cnt += zn;
  }

  int p = sz(pos) - 1;
  for (int i = 0; i < sz(pos); i++) {
    if (p < i) {
      p = i;
    }
    while (p > i && 1ll * pos[i] * pos[p - 1] >= x) {
      p--;
    }
    if (1ll * pos[i] * pos[p] >= x) {
      int add = sz(pos) - p;
      if (p == i) {
        add--;
      }
      cnt += add;
    }
  }

  p = sz(neg) - 1;
  for (int i = 0; i < sz(neg); i++) {
    if (p < i) {
      p = i;
    }
    while (p > i && 1ll * neg[i] * neg[p - 1] >= x) {
      p--;
    }
    if (1ll * neg[i] * neg[p] >= x) {
      int add = sz(neg) - p;
      if (p == i) {
        add--;
      }
      cnt += add;
    }
  }

  p = sz(pos) - 1;
  for (int i = 0; i < sz(neg); i++) {
    while (p > 0 && 1ll * neg[i] * pos[p] < x) {
      p--;
    }
    if (p >= 0 && 1ll * neg[i] * pos[p] >= x) {
      cnt += p + 1;
    }
  }

  return cnt;
}

int main() {

  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);  
    if (a[i] < 0) {
      neg.push_back(a[i]);
    } else if (a[i] == 0) {
      z++; 
    } else {
      pos.push_back(a[i]);
    }
  }

  sort(all(pos));
  sort(all(neg));
  reverse(all(neg));

  total = 1ll * n * (n - 1) / 2;

  if (z > 0) {
    zn = 1ll * z * sz(pos);
    zn += 1ll * z * sz(neg);
    zn += 1ll * z * (z - 1) / 2;
  }

  long long l = -1e18, r = 1e18;
  while (l < r) {
    long long mid = l + (r - l + 1) / 2;
    if (getCnt(mid) >= total - k + 1) {
      l = mid;
    } else {
      r = mid - 1;
    }
  }

  cout << l << endl;

  return 0;
}


Measured memory_bytes: 1912
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust, fromMaybe )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.IO as IOA
import qualified Data.Array.MArray as MA
import Control.Monad.ST
import System.IO (stdin)
import Control.Arrow
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Generic as GV
import qualified Data.Vector.Mutable as MV
import Data.Ix
import Data.Ord (Down(Down))
import qualified Data.Sequence as Seq
import Data.Foldable (toList)
-- import Control.Lens

debug = False

ts :: Show a => a -> a
ts a = if debug then traceShowId a else a


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)

readTuple4 :: IO (Int, Int, Int, Int)
readTuple4 = do
    [a, b, c, d] <- readInts
    return (a, b, c, d)

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

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

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

solve :: Int -> Int -> [Int] -> Double
solve n k ps = maximum $ (\start -> sumss GV.! (start + k) - sumss GV.! start) <$> [0..n-k] where
  sums :: [Double]
  sums = (\a ->(/(fromIntegral a)) . fromIntegral $ (1 + a) * a `div` 2)  <$> ps
  sumss = UV.fromList $ scanl' (+) 0 sums


main :: IO ()
main = do
  (n, k) <- readTuple2
  ps <- readInts
  print $ solve n k ps




Measured memory_bytes: 9596
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target ("sse4")
#pragma comment(linker, "/stack:200000000")

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

#define deb(x) cout << #x << " is " << x << "\n";

using namespace std;
using namespace __gnu_pbds;

const double PI = 2 * acos(0.0);
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long a, b;
    cin >>a >>b;
    cout <<(a * b) / __gcd(a, b);
    return 0;
}

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

const ll INF = 1LL << 60;

struct edge { ll cost, to; };
vector<edge> g[200100]; // 辺
ll dist[100100]; // 距離
vector<ll> prever; // どこから来たか
ll N; // 頂点の数

void dijkstra(ll s) {
    dist[s] = 0;
    prever = vector<ll>(N, -1);

    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top(); que.pop();
        ll v = p.second;

        if (p.first > dist[v]) continue;
        // 次の頂点へ潜る
        for (int i = 0; i < g[v].size(); i++) {
            edge e = g[v][i];
            if (e.cost + dist[v] < dist[e.to]) {
                dist[e.to] = e.cost + dist[v];
                prever[e.to] = v;
                que.push(P(dist[e.to], e.to));
            }
        }
    }
}

int main() {
    cin >> N;

    rep(i, N - 1) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        g[a].push_back((edge){c, b});
        g[b].push_back((edge){c, a});

    }

    rep(i, N) dist[i] = INF;

    ll Q, K;
    cin >> Q >> K;
    K--;
    dijkstra(K);
    rep(i, Q) {
        ll x, y;
        cin >> x >> y;
        x--;
        y--;

        ll ans = 0;
        ans += dist[x];
        ans += dist[y];
        cout << ans << endl;
    }
}

Measured memory_bytes: 15732
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
#include <tuple>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int,int> T;
const int inf=20000000;

int now;
int main(){
  int n;
  int a=0,b=0;
  string s;
  cin>>n;
  cin>>s;
  int south[300001],east[300001];
  south[0]=0;
  east[0]=0;
  for(int i=0;i<s.size();i++){
    south[i+1]=south[i];
    east[i+1]=east[i];
    if(s[i]=='E')east[i+1]++;
    else south[i+1]++;
  }
  int ans=3000000;
  for(int i=0;i<s.size();i++){
    ans=min(ans,south[i]+east[s.size()]-east[i+1]);
  }
  cout<<ans<<endl;


}


Measured memory_bytes: 3076
import java.util.Scanner;

/**
 * Frog 2
 */
public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int K = sc.nextInt();
            int[] H = new int[N + 1];
            for (int i = 1; i <= N; i++) {
                H[i] = sc.nextInt();
            }

            long[] dp = new long[N + 1];

            for (int i = 2; i <= N; i++) {
                dp[i] = Long.MAX_VALUE;

                for (int j = 1; j <= K; j++) {
                    if (i - j >= 1) {
                        dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(H[i] - H[i - j]));
                    }
                }
            }

            System.out.println(dp[N]);
        }
    }

}


Measured memory_bytes: 52624
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

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

	Int N, M, C;
	cin >> N >> M >> C;

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

	Int a;
	Int ans = 0;
	Int temp;
	for (Int i = 0; i < N; i++) {
		temp = 0;
		for (Int j = 0; j < M; j++) {
			cin >> a;
			temp += b[j] * a;
		}
		temp += C;
		if (temp>0) {
			ans++;
		}
	}
	cout << ans << "\n";
}


Measured memory_bytes: 384
#include <stdio.h>

int F[44] = {0};

int fibo(int x){
  if(x == 1 || x == 0)   return F[x] = 1;
  if(F[x] != 0)          return F[x];
  return F[x] = fibo(x - 2) + fibo(x - 1);
}


int main(){
  int x;
  int fib;

  scanf("%d", &x);
  fib = fibo(x);
  printf("%d\n",fib);
  return 0;
}



Measured memory_bytes: 2112
from numba import jit
from math import gcd

k = int(input())

@jit
def main(k):
    point = 0
    for i in range(1,k+1):
        for j in range(1,k+1):
            for k in range(1,k+1):
                point += gcd(gcd(i,j),k)
    return point

print(main(k))

Measured memory_bytes: 110160
import java.util.HashSet;
import java.util.Scanner;

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

        int N = scanner.nextInt();
        int D = scanner.nextInt();

        HashSet<Long> hashSet = new HashSet<>();

        for(long i=0; i<1000; i++){
            hashSet.add(i*i);
        }


        int[][] vectors = new int[N][D];

        for(int i=0; i<N; i++){
            for(int j=0; j<D; j++){
                vectors[i][j] = scanner.nextInt();
            }
        }

        long ans = 0;

        for(int i=0; i<N-1; i++){
            for(int j=i+1; j<N; j++){
                long tmp = 0;
                for(int k=0; k<D; k++){
                    tmp += (vectors[i][k] - vectors[j][k]) * (vectors[i][k] - vectors[j][k]) ;
                }

                if(hashSet.contains(tmp)){
                    ans++;
                }
            }
        }

        System.out.println(ans);

    }
}


Measured memory_bytes: 21844
using System;

namespace A___Traveling_Budget
{
    class Program
    {
        static void Main(string[] args)
        {
            var A = int.Parse(Console.ReadLine());
            var B = int.Parse(Console.ReadLine());
            var C = int.Parse(Console.ReadLine());
            var D = int.Parse(Console.ReadLine());

            var res = Math.Min(A, B) + Math.Min(C, D);

            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 13140
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Sun Dec 23 23:09:07 2018
//
package main

import "fmt"

func main() {
	var N, M, Q int
	fmt.Scan(&N, &M, &Q)

	cities := make([][]int, N)
	for i := range cities {
		cities[i] = make([]int, N)
	}

	for i := 0; i < M; i++ {
		var l, r int
		fmt.Scan(&l, &r)
		cities[l-1][r-1]++
	}

	for i := range cities {
		for j := range cities[i] {
			if j+1 < len(cities[i]) {
				cities[i][j+1] += cities[i][j]
			}
		}
	}

	for i := 0; i < Q; i++ {
		var p, q int
		fmt.Scan(&p, &q)
		p--
		q--

		ans := 0
		for j := p; j <= q; j++ {
			if j < 0 {
				continue
			}

			var from int
			if p-1 > 0 {
				from = cities[j][p-1]
			}
			ans += cities[j][q] - from
		}
		fmt.Println(ans)
	}
}


Measured memory_bytes: 7692
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 62);
ll p[] = {2,3,5};
int main() {
  int t;
  cin >> t;

  while (t--) {
    ll n;
    vector<ll> cost(4);
    cin >> n;
    rep(i,4) cin >> cost[i];

    map<ll,ll> mp;
    mp[0] = 0;
    mp[1] = cost[3];
    auto dfs = [&](auto&& f, ll now)->ll{
      if (mp.count(now)) return mp[now];
      ll res = INF;
      for (int i = 0; i < 3; i++) {
        ll d = now / p[i];
        ll e = (now + p[i] - 1) / p[i];
        res = min(res, f(f, d) + cost[i] + now % p[i] * cost[3]);
        res = min(res, f(f, e) + cost[i] + (e * p[i] - now) * cost[3]);
      }
      if (INF / cost[3] > now) res = min(res, now * cost[3]);
      return mp[now] = res;
    };
    //cout << "ans ";
    cout << dfs(dfs, n) << endl;
  }
  return 0;
} 

Measured memory_bytes: 4376
#include <iostream>

using namespace std;

int main() {
  int a[10] = {111, 222, 333, 444, 555, 666, 777, 888, 999};
  int n;
  cin >> n;
  for (int i = 0; i < 10; i++) {
    if(n <= a[i]) {
      cout << a[i] << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
const ll MOD = 998244353;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0}, dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	vector<ll> a(n + 5);
	rep(i, n) cin >> a[i];
	if (n == 2) {
		cout << max(a[0], a[1]) << endl;
		return 0;
	}
	vvl dp(n + 7, vl(3, -INF));
	rep(i, 3) dp[i][i] = 0;
	rep(i, n) {
		rep(j, 3) {
			if (dp[i][j] == -INF) continue;
			dp[i + 2][j] = max(dp[i + 2][j], dp[i][j] + a[i]);
			if (j < 2) dp[i + 3][j + 1] = max(dp[i + 3][j + 1], dp[i][j] + a[i]);
			if (j < 1) dp[i + 4][j + 2] = max(dp[i + 4][j + 2], dp[i][j] + a[i]);
		}
	}
	ll ans = -INF;
	if (n % 2)
		rep(i, 3) ans = max(ans, dp[n - 1 + i][i]);
	else
		rep(i, 2) ans = max(ans, dp[n + i][i]);
	cout << ans << endl;
	return 0;
}


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

struct Benri {
    Benri() {
        std::cin.tie(0); ios::sync_with_stdio(false);
        cout << fixed << setprecision(12);
    }
} benri;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MOD 1000000007
#define MOD2 998244353

//0-indexedのBIT
template<class V, int ME> class BIT {
public:
    V bit[1 << ME];
    V sum(int e) {if (e < 0) return 0; V s = 0; e++; while (e) s += bit[e - 1], e -= e & -e; return s;}
    void add(int e, V v) { e++; while (e <= 1 << ME) bit[e - 1] += v, e += e & -e;}
};


ll POW[200020];

int main() {
    POW[0] = 1;
    rep(i, 200005) POW[i + 1] = (POW[i] * 2) % MOD2;

    ll N; cin >> N;
    vll X(N), Y(N);
    vector<pll> P(N);
    rep(i, N) {
        cin >> X[i] >> Y[i];
        P[i].F = X[i];
        P[i].S = Y[i];
    }

    //座標圧縮
    sort(all(X));
    sort(all(Y));
    rep(i, N) {
        P[i].F = lower_bound(all(X), P[i].F) - X.begin();
        P[i].S = lower_bound(all(Y), P[i].S) - Y.begin();
    }
    sort(all(P), greater<pll>());

    //各点pを左から見てそれを含む長方形、をつくる部分集合の数をカウントする
    ll ans = (N * POW[N - 1]) % MOD2; // pを含む部分集合からの寄与

    BIT<ll, 20> Left; //点pの左にある点のy座標を入れていくBIT
    ll LU, LD, RU, RD; // 点pの左上、左下、右上、右下にある点の数
    ll a, b, c;

    rep(i, N) { 
        LD = Left.sum(P[i].S);
        LU = i - LD;
        RD = P[i].S - LD;
        RU = (N - 1) - LD - LU - RD;
        a = ((((POW[RU] - 1) * (POW[LD] - 1)) % MOD2) * (((POW[RD]) * (POW[LU])) % MOD2) ) % MOD2;
        b = ((((POW[RU]) * (POW[LD])) % MOD2) * (((POW[RD] - 1) * (POW[LU] - 1)) % MOD2) ) % MOD2;
        c = ((((POW[RU] - 1) * (POW[LD] - 1)) % MOD2) * (((POW[RD]-1) * (POW[LU]-1)) % MOD2) ) % MOD2;
        ans = (ans + a + b - c + MOD2) % MOD2;
        Left.add(P[i].S, 1);
    }

    cout << ans << endl;


}




Measured memory_bytes: 13568