akhauriyash/Code-Regression huggingface dataset:
///A drunk man will find his way home, but a drunk bird may get lost forever...
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair <int, int> pii;
#define pb push_back
#define f first
#define s second
#define sz(x) (int)x.size()
const int mx = 1000 * 100 + 5, M = 1e9 + 7;
int n, m, s, t, dis[2][mx], cnt[2][mx];
set < pii > ms;
vector < pii > ad[mx];
vector < pair < pii , int > > ed;
void dij(int a, int ind){
	memset(dis[ind], 127, sizeof dis[ind]);
	dis[ind][a] = 0;
	cnt[ind][a] = 1;
	for(int i = 0; i < n; i++)
		ms.insert({dis[ind][i], i});
	while(sz(ms)){
		auto v = ms.begin() -> s;
		ms.erase(ms.begin());
		for(auto u : ad[v]){
			if(dis[ind][v] + u.s < dis[ind][u.f]){
				ms.erase({dis[ind][u.f] , u.f});
				dis[ind][u.f] = dis[ind][v] + u.s;
				cnt[ind][u.f] = cnt[ind][v];
				ms.insert({dis[ind][u.f] , u.f});
			}
			else if(dis[ind][v] + u.s == dis[ind][u.f]){
				cnt[ind][u.f] += cnt[ind][v];
				cnt[ind][u.f] %= M;
			}
		}
	}
	return;
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
 	cout.tie(0);
	cin >> n >> m >> s >> t;
	s--, t--;
	int u, v, w;
	for(int i = 0; i < m; i++){
		cin >> u >> v >> w;
		u--, v--;
		ad[u].pb({v , w});
		ad[v].pb({u , w});
		ed.pb({{u , v} , w});
	}
	dij(s , 0);
	dij(t , 1);
	int sum = cnt[0][t] * cnt[1][s] % M;
	for(int i = 0; i < n; i++){
		if(dis[0][i] == dis[1][i] && dis[0][i] + dis[1][i] == dis[0][t]){
			sum -= cnt[0][i] * cnt[0][i] % M * cnt[1][i] % M * cnt[1][i] % M;
			sum = ((sum % M) + M) % M;
		}
	}
	for(auto u : ed){
		if (dis[0][u.f.f] > dis[0][u.f.s]) 
			swap(u.f.f , u.f.s);
		if(dis[0][u.f.f] + dis[1][u.f.s] + u.s == dis[1][s] && dis[0][u.f.f] < dis[1][s] / 2 && dis[1][u.f.s] < dis[1][s] / 2){
			sum -= cnt[0][u.f.f] * cnt[0][u.f.f] % M * cnt[1][u.f.s] % M * cnt[1][u.f.s] % M;
			sum = ((sum % M) + M) % M;

		}
	}
	cout << sum << endl;
	return 0;
}



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

int main(){
  int n;
  cin >> n;
  map<char, int> mpl, mpr;
  string s;
  cin >> s;
  rep(i, n){
    mpr[s.at(i)]++;
  }
  int ans = 0;
  rep(i, n){
    mpr[s.at(i)]--;
    mpl[s.at(i)]++;
    int add = 0;
    for(auto p : mpl){
      if(mpr[p.first] > 0) add++;
    }
    ans = max(ans, add);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
A,B,C,D,E,F = map(int,input().split())

a_limit = int(-(-F//(100*A)))
b_limit = int(-(-F//(100*B)))
c_limit = int(-(-F*E//(100*C)))
d_limit = int(-(-F*E//(100*D)))

water_cand = []
for i in range(a_limit):
  for j in range(b_limit):
    water_cand.append(100*A*i+100*B*j)

water_cand = [x for x in list(set(water_cand)) if 0<x<F]

sugar_cand = []
for i in range(c_limit):
  for j in range(d_limit):
    sugar_cand.append(C*i + D*j)

sugar_cand = list(set(sugar_cand))

max_dens = 0
ans_total = 100*A
ans_sugar = 0
for i in water_cand:
  for j in sugar_cand:
    total = i + j
    dens = float(j)/total
    if total <= F and float(j)/i <= (E/100) and max_dens<dens:
      max_dens = dens
      ans_total = total
      ans_sugar = j
            
print(ans_total, ans_sugar)

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

using namespace std;

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

    if(N%2)
        cout<<setprecision(7)<<(N+1.0)/(2.0*N);

    else
        cout<<setprecision(7)<<0.5;

    return 0;
}


Measured memory_bytes: 256
(function main() {
  const n = Number(require('fs').readFileSync('/dev/stdin', 'utf8'));
  const cache = [1, 1];
  const fib = (n) => cache[n|0] || (cache[n|0] = fib(n - 1) + fib(n - 2));
  console.log(fib(n));
})();



Measured memory_bytes: 15392
#include <bits/stdc++.h>
#define IO                       \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
#define mem(a, x) memset(a, x, sizeof(a))
#define per(x, a, b) for (int x = a; x <= b; x++)
#define rep(x, a, b) for (int x = a; x >= b; x--)

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-8;

LL n, m;
P p[maxn];

void solve() {
    LL ans = 0;
    for (int i = 0; i < n; i++) {
        if (m >= p[i].second) {
            m -= p[i].second;
            ans += p[i].first * 1LL * p[i].second;
        } else {
            ans += 1LL * m * p[i].first;
            break;
        }
    }
    cout << ans << endl;
}
int main() {
#ifdef LOCAL_IM0QIANQIAN
    freopen("test.in", "r", stdin);
//    freopen("test.out", "w", stdout);
#else
    IO;
#endif // LOCAL_IM0QIANQIAN

    while (cin >> n >> m) {
        for (int i = 0; i < n; i++) {
            cin >> p[i].first >> p[i].second;
        }
        sort(p, p + n);
        solve();
    }
    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
const int maxn = 200200;
vector<int> g[maxn];
int M(){
    int n, m;
    if(!~scanf("%d %d", &n, &m)) return 0;
    for(int e = 0; e < n; e++) g[e].clear();
    for(int e = 0; e < m; e++){
        int u, v; cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(int e = 0; e < n; e++)
        sort(g[e].begin(), g[e].end());
    for(int v : g[0]){
        if(!g[v].empty() && g[v].back() == n-1)
            return printf("POSSIBLE\n"), 1;
    }
    return printf("IMPOSSIBLE\n"), 1;
}
int main(){
    while(M());
    return 0;
}


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

using namespace std;

int main(){
    string S;
    cin >> S;
    if (S.length() % 2 == 1){
        puts("No");
        return 0;
    }
    for (int i = 0; i < S.length(); i++){
        if (i % 2 == 0 and S[i] != 'h'){
            puts("No");
            return 0;
        }
        if (i % 2 == 1 and S[i] != 'i'){
            puts("No");
            return 0;
        }
    }

    puts("Yes");
}

Measured memory_bytes: 256
class Dice
  V={N:0,E:1,S:2,W:3}
  def initialize(label)
    @label=label
    @top=1
    @around=[5,3,2,4] # U R D L
    # 右に転がす場合
    # 対角値(レフト,idx3)が上面(top)になる
    # 右(idx1)にもともと上面だった値（top）が入る
    # その対角面(右,idx1)には対角値（合計7になる値）が入る
    # 1 => [5,3,2,4]
    # 4 => [5,1,2,6]
    # 下に転がす場合
    # 1 => [5,3,2,4]
    # 5 => [6,3,1,4]
  end
  def set_position(top,front)
    # 与えられた値（ラベル値）になるようにダイスを回転させる
    # 縦横の回転数を計算して実際に動かす
    top_num=@label.index(top)+1
    front_num=@label.index(front)+1
    # TOP面をあわせる
    if top_num==@top then
    elsif idx=@around.index(top_num)
      rn=self.reverse_vector(idx)
      v=V.key(rn)
      self.move(v)
    elsif
      2.times{self.move("S")}
    end
    # FRONT面を合わせる
    if idx=@around.index(front_num)
      n = case idx
          when 3; 1
          when 2; 0
          when 1; 3
          when 0; 2
          end
      self.turn(n)
    else
      puts "i can not"
    end
  end
  def turn(n)
    # n回右に回転する（TOPは変わらず）
    # n = turn_right * n
    @around.push(@around.shift(n)).flatten!
  end
  def move(v)
    # v = U,R,D,L
    #     N,E,S,W
    #     0,1,2,3
    vn=V[v.to_sym] # 移動方向のインデックス数値
    rn=reverse_vector(vn) # 対角のインデックス数値（2を足す。4を超えていた場合は剰余）
    @top,@around[vn]=@around[rn],@top
    @around[rn]=7-@around[vn]
  end
  def puts_top
    puts @label[@top-1]
  end
  def puts_right
    idx=@around[1]
    puts @label[idx-1]
  end
  def reverse_vector(vn)
    return (vn+2)%4
  end
end
def code_run
  #iS,iL=$stdin.gets.split.map(&:to_i)
  #until ( iN,iX=$stdin.gets.split.map(&:to_i) ) == [0,0] do
  label=$stdin.gets.split.map(&:to_i)
  d=Dice.new(label)
  ($stdin.gets.to_i).times do
    t,f=$stdin.gets.split.map(&:to_i)
    d.set_position(t,f)
    d.puts_right
  end
end

code_run


Measured memory_bytes: 6876
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func vi(n int, args ...int) []int {
	res := make([]int, n)
	if len(args) == 0 {
		return res
	}
	v := args[0]
	if v == 0 {
		return res
	}
	for i := 0; i < n; i++ {
		res[i] = v
	}
	return res
}

func vvi(n int, args ...int) [][]int {
	res := make([][]int, n)
	m := n
	if len(args) > 0 {
		m = args[0]
	}
	v := 0
	if len(args) > 1 {
		v = args[1]
	}
	for i := 0; i < n; i++ {
		res[i] = vi(m, v)
	}
	return res
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func dist(x1, y1, x2, y2 int) int {
	return abs(x2-x1) + abs(y2-y1)
}

func main() {
	defer stdout.Flush()
	n := readInt()
	t := 0
	x := 0
	y := 0
	for i := 0; i < n; i++ {
		nt := readInt()
		nx := readInt()
		ny := readInt()

		d := dist(x, y, nx, ny)
		dt := nt - t
		if d > dt || d%2 != dt%2 {
			println("No")
			return
		}
		t = nt
		x = nx
		y = ny
	}
	println("Yes")
}


Measured memory_bytes: 1792
import Control.Arrow

main :: IO ()
main = readParams >>= putStrLn . format . uncurry solve

readParams :: IO (Int, [Int])
readParams = (last &&& init) . map read . words <$> getLine

format :: Show a => [a] -> String
format = unwords . map show

solve :: Int -> [Int] -> [Int]
solve k = map fst . tail . scanl f (0, k)

f :: (Int, Int) -> Int -> (Int, Int)
f (_, x) y = (max (y - x) 0, max (x - y) 0)


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

using namespace std;using f64 = double;using i64=long long;using u64=unsigned long long;
template<typename T> using Arr=vector<T>;
#define hfor(v, s, e) for(int v=(s);(s)<=v&&v<(e);++v)//half-opened range
#define hfori(v, s, e) for(int v=(e)-1;(s)<=v&&v<(e);--v)//inversion
#define hforo(v, s, e) int v=(s);for(;(s)<=v&&v<(e);++v)//out declaration
#define hforoi(v, s, e) int v=(e)-1; for(;(s)<=v&&v<(e);--v)
#define cfor(v, s, e) hfor(v,(s),(e)+1)//closed range
#define cfori(v, s, e) hfori(v,(s),(e)+1)
#define cforo(v, s, e) hforo(v,(s),(e)+1)
#define cforoi(v, s, e) hforoi(v,(s),(e)+1)
#define rep(v,x) hfor(v,0,(x))
#define repi(v,x) hfori(v,0,(x))
#define repo(v,x) hforo(v,0,(x))
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pushb push_back
#define pushf push_front
#define popb pop_back
#define popf pop_front
#define empl emplace
#define emplb emplace_back
#define emplf emplace_front
#define fi first
#define se second
#define cxp constexpr
#define PQ std::priority_queue

#ifndef DEBUG
	#pragma GCC optimize ("Ofast")
	auto __PRE_RUN__=(ios::sync_with_stdio(0), cin.tie(0), cout.tie(0),(cout<<fixed<<setprecision(11)), 0);
#endif

template<typename T> cxp T inf() { return numeric_limits<T>::max() / 2; }
auto mapf(auto a, auto f){for(auto& x:a)x=f(x); return a;}
int rd(int lb, int ub){static mt19937 rng(time(0)^i64(new int)); return uniform_int_distribution<int>(lb, ub-1)(rng);}
int rd(int ub=inf<int>()){return rd(0,ub);}
const f64 pi=acosl(-1);
#define endl '\n'//not interactive?
#define int i64//MLE?
using pint = pair<int,int>;
using tint = tuple<int,int,int>;

signed main(){
	int n,k; cin>>n>>k;
	cout<<(n*500>=k?"Yes":"No")<<endl;
	return 0;
}



Measured memory_bytes: 384
n, k = map(int, input().split()) 

res = 0
for m in range(k,n+2):
    sum_min = m*(m-1)//2
    sum_max = m*(2*n-m+1)//2
    cnt = sum_max - sum_min + 1
    res += cnt
    res %= 10**9+7
print(res)

Measured memory_bytes: 9044
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    N = int(readline())
    m = map(int, read().split())
    UVW = zip(m, m, m)

    # 木が保証されているので、必ず実現できる

    graph = [[] for _ in range(N + 1)]
    for u, v, w in UVW:
        graph[u].append((v, w))
        graph[v].append((u, w))

    color = [0] * (N + 1)
    stack = [1]
    parent = [0] * (N + 1)
    while stack:
        x = stack.pop()
        for y, w in graph[x]:
            if y == parent[x]:
                continue
            parent[y] = x
            color[y] = color[x] ^ (w & 1)
            stack.append(y)

    print('\n'.join(map(str, color[1:])))
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 52080
MOD = 10**9 + 7
def solve(n, m):
    if n < m:
        n, m = m, n
    if n - m >= 2:
        return 0
    res = 1
    for i in range(n):
        res = (res * (i+1)) % MOD
    for i in range(m):
        res = (res * (i+1)) % MOD
    if n - m == 0:
        res = (res * 2) % MOD
    return res
assert solve(2,2) == 8
assert solve(3,2) == 12
assert solve(1,8) == 0
n, m = map(int, raw_input().split())
print solve(n, m)

Measured memory_bytes: 5764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const ll MOD = 1000000007;
int N;
string s[2];
ll dp[55];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> s[0] >> s[1];

  if (s[0][0] == s[1][0]) {
    dp[0] = 3;
  } else {
    dp[0] = dp[1] = 6;
  }
  for (int i = 0; i < N;) {
    if (s[0][i] == s[1][i]) {
      if (s[0][i+1] == s[1][i+1]) {
        dp[i+1] = dp[i] * 2;
        dp[i+1] %= MOD;
        i++;
      } else {
        dp[i+1] = dp[i] * 2;
        dp[i+1] %= MOD;
        dp[i+2] = dp[i] * 2;
        dp[i+2] %= MOD;
        i++;
      }
    } else {
      if (s[0][i+2] == s[1][i+2]) {
        dp[i+2] = dp[i];
        dp[i+2] %= MOD;
        i += 2;
      } else {
        dp[i+2] = dp[i] * 3;
        dp[i+2] %= MOD;
        dp[i+3] = dp[i] * 3;
        dp[i+3] %= MOD;
        i += 2;
      }
    }
  }
  cout << dp[N-1] << endl;

  return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
import bisect
a.sort()
b.sort()
c.sort()
ans=0
for i in range(n):
    ans+=bisect.bisect_left(a,b[i])*(n-bisect.bisect_right(c,b[i]))
print(ans)


Measured memory_bytes: 22720
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#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 <cctype>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

typedef pair<int, int> pint;
typedef pair<pint, pint> ppint;

int main() {

	int H, W; cin >> H >> W;
	vector<vector<int>> a(H, vector<int>(W, 0));

	int odd = 0;

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> a[i][j];
			if (a[i][j] & 1)++odd;
		}
	}

	vector<ppint> res;
	int num = 0;
	int x = 0, y = 0;

	for (int iter = 0; iter < W*H; ++iter) {
		if (a[x][y] & 1)++num;
		int nx = x, ny = y;

		if (x % 2 == 0) {
			if (ny == W - 1)++nx;
			else  ++ny ;
		}
		else {
			if (ny == 0)++nx;
			else --ny;
		}

		if (num & 1)if (num < odd)res.push_back(ppint(pint(x, y), pint(nx, ny)));
		x = nx, y = ny;

	}

	cout << res.size() << endl;
	for (auto p : res) {
		cout << p.first.first + 1 << " " << p.first.second + 1 << " " << p.second.first + 1 << " " << p.second.second + 1 << endl;
	}

	
	return 0;
}

Measured memory_bytes: 5232
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();
               if(a<=9 && b<=9){
               System.out.println(a*b);
               }else{
               System.out.println(-1);
               }
	 }
}
     

Measured memory_bytes: 22868
def D():
    N, K = map(int, input().split())
    MOD = 10**9+7
    ans = 0
    for i in range(K, N+2):
        lower = i*(i-1)//2
        higher = N*(N+1)//2 - (N-i)*(N-i+1)//2 + 1
        # print(lower, higher)
        ans += (higher - lower)%MOD
        ans %= MOD
    print(ans)
D()

Measured memory_bytes: 9192
#include <stdio.h>
int main()
{
	int a,b,h,s=0;
	//1<=a<=100,1<=b<=100,1<=h<=100
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&h);
	//h为偶数
	s=(a+b)*h/2;
	printf("%d",s);
	return 0; 
}

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

struct mint{
    static const long long MOD = 1000000007;

    long long v;

    mint() : v(0) {}
    mint(long long x){
        x = x % MOD;
        if(x < 0){ x += MOD; }
        v = x;
    }
    mint& operator+=(mint a){
        v += a.v;
        if(v >= MOD){ v -= MOD; }
        return *this;
    }
    mint& operator*=(mint a){
        v *= a.v;
        v %= MOD;
        return *this;
    }
    mint& operator-=(mint a){
        v -= a.v;
        if(v < 0){ v += MOD; }
        return *this;
    }
    mint& operator/=(mint a){
        return (*this) *= a.inv();
    }

    mint operator*(mint a) const{
        return mint(v) *= a;
    }

    mint operator+(mint a) const {
        return mint(v) += a;
    }

    mint operator-(mint a) const {
        return mint(v) -= a;
    }

    mint operator/(mint a) const {
        return mint(v) /= a;
    }

    mint pow(long long k) const {
        mint res(1),tmp(v);
        while(k){
            if(k&1) res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    mint inv(){return pow(MOD - 2); }

    static mint comb(long long n, int k){
        mint res(1);
        for(int i = 0; i < k; ++i){
            res *= mint(n - i);
            res /= mint(i + 1);
        }
        return res;
    }

    static mint factorial(long long n){
        mint res(1);
        for(int i = n; i > 1; --i){
            res *= mint(i);
        }
        return res;
    }

    bool operator<(const mint &a) const {
        return v < a.v;
    };
};

mint operator*(long long l, mint r){ return r * l; }

std::ostream& operator<<(std::ostream& stream, const mint& m){
    stream << m.v;
    return stream;
}

void solve(long long N, std::vector<long long> A){
    const ll max_a = *max_element(A.begin(), A.end());
    vector<ll> count(max_a + 2, 0);
    count.at(0) = 3;
    mint ans = 1;
    for(auto x : A){
        x++;
        count.at(x)++;
        ans *= count.at(x - 1);
        count.at(x - 1)--;
    }
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] arg)throws IOException{
		 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		 //br.readline(); = 入力された１行分を日本語変換して返してくれる。
		 String str = br.readLine();

		 /*配列の型(intとかStringとか) [] 配列名 = 配列を用意
		  *今回はstrAryって配列にstrを入れてる。
		  *str.split = splitってのはString内に用意されてるメソッド
		  *文字列を分割するときに使用。今回は空白で区切ってって仕様なので
		  *split(" ")としてます。*/
		 String[] strAry = str.split(" ");

		 /*おなじみの文字列から数値への変換。
		  *ただし今回は指定先が配列の何番って風になってる。*/
		 int a = Integer.parseInt(strAry[0]);
		 int b = Integer.parseInt(strAry[1]);
		 int c = Integer.parseInt(strAry[2]);

		 //前準備 for文の変数iと約数の数を数える変数count
		 int i = 0;
		 int count = 0;

		 /*Constraintsを実験的にセット
		  *1?a,b,c?10000
		  *a?b
		  *この条件の場合エラーメッセージを出力している。
		  *が、本来求められていない機能のようなのでコメントアウトしておく。
		  */

		 //if(!(a < 1 || a > 10000 || b < 1 || b > 10000 || c < 1 || c > 10000 || a < b )){

			 for(i=a; i<=b; i++){
				 if( c % i == 0){count = count +1;}
			 }

		 System.out.println(count);
		 /*} else {
		  *	 System.out.println("エラー");
		 }*/
    }
}

Measured memory_bytes: 17056
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	int a[100001];
	map<int, int> cnt;
	vector<pair<int, int> > tmp;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		if(cnt.find(a[i]) == cnt.end()){
			cnt[a[i]] = 1;
				tmp.push_back(make_pair(a[i], i));
			}else{
				cnt[a[i]]++;
			}
	}
	sort(tmp.begin(), tmp.end());
	reverse(tmp.begin(), tmp.end());
	long long int checkednum = 0;
	long long int ans[100001] = {};
	tmp.push_back(make_pair(0, 0));
	int minindex = n;
	for(int i = 0; i < tmp.size() - 1; i++){
		long long int now = tmp[i].first;
		long long int next = tmp[i + 1].first;
		minindex = min(minindex, tmp[i].second);
		checkednum += cnt[now];
		ans[minindex] += (now - next) * checkednum;
	}
	for(int i = 1; i <= n; i++){
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 7668
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
	int a[3];
	for (int i = 0; i < 3; i++) scanf("%d", &a[i]);
	sort(a, a + 3);
	int k = a[2] - a[1], l = a[2] - a[0];
	int ans;
	if (k % 2 == l % 2)
		ans = (k + l) / 2;
	else
		ans = (k + l + 1) / 2 + 1;
	printf("%d\n", ans);
	return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int intLoop = scan.nextInt();
		ArrayList<Double> list = new ArrayList<Double>();
		ArrayList<Integer> listX = new ArrayList<Integer>();
		ArrayList<Integer> listY = new ArrayList<Integer>();
		for(int i = 0; i < intLoop; i++){
			listX.add(scan.nextInt());
		}
		for(int i = 0; i < intLoop; i++){
			listY.add(scan.nextInt());
		}
		// P = 1
		double dbP1 = 0;
		for(int i = 0; i < intLoop; i++){
			dbP1 += Math.abs((listX.get(i) - listY.get(i)));
		}
		list.add(dbP1);

		// P = 2
		double dbP2 = 0;
		for(int i = 0; i < intLoop; i++){
			dbP2 += Math.pow(Math.abs((listX.get(i) - listY.get(i))), 2);
		}
		list.add(Math.sqrt(dbP2));

		// P = 3
		double dbP3 = 0;
		for(int i = 0; i < intLoop; i++){
			dbP3 += Math.pow(Math.abs((listX.get(i) - listY.get(i))), 3);
		}
		list.add(Math.cbrt(dbP3));

		// P = ???
		double dbInf = 0;
		double dbTemp = 0;
		for(int i = 0; i < intLoop; i++){
			dbTemp = Math.abs(listX.get(i) - listY.get(i));
			if(dbInf <= dbTemp){
				dbInf = dbTemp;
			}
		}
		list.add(dbInf);

		for(int i = 0; i < list.size(); i++){
			System.out.println(list.get(i));
		}
	}
}

Measured memory_bytes: 20352
#include <bits/stdc++.h>
using namespace std;
constexpr int pDec[]={1,10,100,1000,10000,100000,1000000,10000000,100000000};
constexpr int fct[]={40320,5040,720,120,24,6,2,1};
constexpr int dif[]={-1,1,-3,3};
int makeHash(int num){
    int ans=0;
    int f=0;
    for(int i=0;i<8;i++){
        int tmp=num%10;
        // auto index=lower_bound(vDigit.begin(),vDigit.end(),tmp);
        // ans+=(index-vDigit.begin())*fct[i];
        //vDigit.erase(index);
        
        ans+=(tmp-__builtin_popcount(f&(1<<tmp)-1))*fct[i];
        f|=(1<<tmp);
        num/=10;
    }
    return ans;
}

int main(void){
    // cout<<makeHash(305147826)<<endl;
    // return 0;
    vector<int> vDigit{0,1,2,3,4,5,6,7,8};
    
    // int count=0;
    // do{
    //     int num=0;
    //     for(int i=9;i>0;i--){
    //         num+=pDec[i-1]*vDigit[9-i];
    //     }
    //     mp.emplace(num,count++);
    // }while(next_permutation(vDigit.begin(),vDigit.end()));
    // Your code here!
    int h,v;
    while(cin>>h>>v,h||v){
        int hv[]={h,h,v,v};
        int st=0;
        int end=0;
        int a;
        vector<bool> visited(362880,false);
        cin>>st;
        for(int i=0;i<8;i++){
            st*=10;
            cin>>a;
            st+=a;
        }
        cin>>end;
        for(int i=0;i<8;i++){
            end*=10;
            cin>>a;
            end+=a;
        }
        priority_queue<pair<int,int>> q;
        q.emplace(0,st);
        while(1){
            int pos=q.top().second;
            int cost=q.top().first;
            if(pos==end){
                cout<<-cost<<endl;
                break;
            }
            q.pop();
            int hash=makeHash(pos);
            if(visited[hash]){
                continue;
            }
            visited[hash]=true;
            int zero=to_string(pos+1000000000).find('0')-1;
            for(int i=0;i<4;i++){
                int s=pos,t=8-((zero+dif[i]+9)%9);
                int tmp=(pos/pDec[t])%10;
                s+=(pDec[8-zero]*tmp-pDec[t]*tmp);
                //cout<<tmp<<" "<<pos<<" "<<s<<endl;
                q.emplace(cost-hv[i],s);
            }
        }
    }
    return 0;
}



Measured memory_bytes: 10132
import std.stdio;
import std.ascii;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

const INF = int.max / 2;

void main() {
    int N;
    int[] P, T;
    bool input() {
        scanf("%d\n", &N);
        if (N == 0) return false;
        P = new int[N + 1];
        T = new int[N + 1];
        P[0] = T[0] = 0;
        for (int i = 1; i <= N; i++) {
            scanf("%d %d\n", &P[i], &T[i]);
        }
        return true;
    }
    int dist(int a, int b) {
        return abs(P[a] - P[b]);
    }
    void solve() {
        auto dp = new int[][](4, N + 1);
        foreach (ref L; dp) L[] = INF;
        dp[0][0] = 0; // ばんぺーさん
        dp[1][1] = T[1] < P[1] ? INF : P[1];
        for (int j = 1; j <= N; j++) {
            for (int i = 1; i <= 3; i++) {
                int ntime = T[j - 1] + dist(0, j - 1) * (i + 1) + dist(0, j) * 1;
                if (ntime <= T[j]) {
                    dp[1][j] = min(dp[1][j], dp[i][j - 1] + dist(0, j - 1) + dist(0, j));
                }
            }
            for (int i = 2; i <= 3; i++) {
                int ntime = T[j - 1] + dist(j - 1, j) * i;
                if (ntime <= T[j]) {
                    dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + dist(j, j - 1));
                }
            }
        }
        //foreach (L; dp) L.map!"a == INF ? -1 : a".writeln;
        //writeln;
        for (int j = N; j >= 0; j--) {
            int X = INF;
            for (int i = 0; i <= 3; i++) {
                X = min(X, dp[i][j]);
            }
            if (X < INF) {
                if (j == N) {
                    writeln("OK ", X + P[N]);
                } else {
                    writeln("NG ", j + 1);
                }
                break;
            }
        }
    }
    while (input) solve;
}

Measured memory_bytes: 1060
#include <iostream>
#include <vector>

const int INF = 2147483647;

std::vector<int> value;
int N;

void update(int i, int x) {
  i += N - 1;
  value[i] = x;
  while (i > 0) {
    i = (i - 1) / 2;
    value[i] = std::min(value[2 * i + 1], value[2 * i + 2]);
  }
}

int query(int a, int b, int k, int l, int r) {
  // [l r)                [l r)
  //       [a b) or [a b)
  if (r <= a or b <= l)
    return INF;

  //      [l r)
  //   [a       b)
  else if (a <= l and r <= b)
    return value[k];

  else
    return std::min(query(a, b, 2 * k + 1, l, (l + r) / 2),
                    query(a, b, 2 * k + 2, (l + r) / 2, r));
}

int main() {
  int n, q;
  std::cin >> n >> q;
  N = 1;
  while (N < n)
    N *= 2;

  value = std::vector<int>(2 * N - 1, INF);

  for (int j = 0; j < q; ++j) {
    int c;
    std::cin >> c;

    // update
    if (c == 0) {
      int i, x;
      std::cin >> i >> x;
      update(i, x);
    }
    // query
    else {
      int s, t;
      std::cin >> s >> t;
      std::cout << query(s, t + 1, 0, 0, N) << std::endl;
    }
  }
}



Measured memory_bytes: 3884
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] a = new int[n][3];
        for(int i=0; i<n; i++) for(int j=0; j<3; j++) a[i][j] = sc.nextInt();
        sc.close();
        long[][] dp = new long[n][3];
        for(int i=0; i<3; i++) dp[0][i] = a[0][i];
        for(int i=1; i<n; i++){
            dp[i][0] = Math.max(dp[i-1][1], dp[i-1][2]) + a[i][0];
            dp[i][1] = Math.max(dp[i-1][2], dp[i-1][0]) + a[i][1];
            dp[i][2] = Math.max(dp[i-1][0], dp[i-1][1]) + a[i][2];
        }

        System.out.println(Arrays.stream(dp[n-1]).max().getAsLong());
    }
}

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

int main(){
	string s;
	cin>>s;
	int a=0;
	rep(i,s.size())a+=(s[i]=='2');
	cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,D,X;
  cin >> N >> D >> X;
  vector<int> A(N);
  for (int i=0;i<N;i++) {
    cin >> A.at(i);
  }
  
  int k,eaten=0;
  for (int i=0;i<N;i++) {
    k=0;
    while (k*A.at(i)+1 <= D) {
      k++;
    }
    eaten += k;
  }
  
  cout << eaten+X << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

struct DSU{
	int S;
	struct node{
		int parent; ll sum;
	};
	vector<node> dsu;
	DSU(int n){
		S = n;
		rep(i, n){
			node tmp;
			tmp.parent = i; tmp.sum = 1;
			dsu.pb(tmp);
		}
	}
	void reset(int n){
		dsu.clear();
		S = n;
		rep(i, n){
			node tmp;
			tmp.parent = i; tmp.sum = 1;
			dsu.pb(tmp);
		}
	}
	int root(int u){
		if(dsu[u].parent == u) return u;
		dsu[u].parent = root(dsu[u].parent);
		return dsu[u].parent;
	}
	void merge(int u, int v){
		u = root(u); v = root(v);
		if(u == v) return;
		if(getsum(u) < getsum(v)) swap(u, v);
		dsu[v].parent = u;
		dsu[u].sum += dsu[v].sum;
	}
	bool sameset(int u, int v){
		if(root(u) == root(v)) return true;
		return false;
	}	
	ll getsum(int u){
		return dsu[root(u)].sum;
	}
};

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, m;
	cin >> n >> m;
	vi x(m), y(m), z(m);
	DSU dsu(n + 1);
	rep(i, m){
		cin >> x[i] >> y[i] >> z[i];
		dsu.merge(x[i], y[i]);
	}
	int ans = 0;
	repn(i, 1, n + 1) if(dsu.root(i) == i) ans++;
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

typedef long long ll;
const int MAX_N = 100000;

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

  std::vector<int> ans(N + 1, -1);
  int u, v;
  ll w;
  std::queue<std::tuple<int, int, ll>> que;
  for(int i = 0; i < N - 1; ++i) {
    std::cin >> u >> v >> w;
    que.push(std::make_tuple(u, v, w));
  }
  auto t = que.front(); que.pop();
  u = std::get<0>(t);
  v = std::get<1>(t);
  w = std::get<2>(t);
  ans[u] = 0;
  if(w % 2 == 0) ans[v] = 0;
  else ans[v] = 1;

  while(not que.empty()) {
    auto t = que.front(); que.pop();
    u = std::get<0>(t);
    v = std::get<1>(t);
    w = std::get<2>(t);
    if(ans[u] == -1 and ans[v] == -1) {
      que.push(std::make_tuple(u, v, w));
    } else {
      if(w % 2 == 0) {
        ans[u] = std::max(ans[u], ans[v]);
        ans[v] = ans[u];
      } else {
        if(ans[u] == -1) ans[u] = 1 ^ ans[v];
        else ans[v] = 1 ^ ans[u];
      }
    }
  }

  for(int i = 1; i <= N; ++i) {
    std::cout << ans[i] << "\n";
  } std::cout << std::endl;

}

Measured memory_bytes: 2560
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e18;
using vi = vector <int>;
using vvi = vector <vi>;
//g++ -std==c++14
const int MAX_E = 2000, MAX_V = 1000;

struct edge{int from, to, cost;};
edge es[MAX_E];
int d[MAX_V];
bool nega[MAX_V];
int V, E;

bool bellmanFord(int s){
    for(int i = 0; i < V; i++)
        d[i] = INF;
    d[s] = 0;

    for(int cnt = 0; cnt < V; cnt++){
        for(int i = 0; i < E; i++){
            edge e = es[i];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                if(cnt == V - 1)
                    nega[e.to] = true;
            }
        }
    }
    return false;
}

signed main(){
	cin >> V >> E;
	int a, b, c;
	rep(i, E){
		cin >> a >> b >> c;
		es[i] = {a - 1, b - 1, -c};
	}

	bellmanFord(0);
	if(nega[V - 1])
		cout << "inf" << endl;
	else
		cout << -d[V - 1] << endl;
}


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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

u64 lcm(u64 a, u64 b) { return (a / gcd(a, b)) * b; }

int main() {
  u32 N;
  cin >> N;
  vector<string> S(N);
  ArrayInput(S);
  sort(S.begin(), S.end());
  map<string, u32> res;
  for (auto itr = S.begin(); itr != S.end(); ++itr) {
    res[*itr]++;
  }
  string prev = S[0];
  u32 m = 0;
  for (u32 i = 0; i < N; ++i) {
    if (m < res[S[i]]) {
      m = res[S[i]];
    }
  }

  for (u32 i = 0; i < N; ++i) {
    if (S[i] != prev) {
      if (res[prev] == m) {
        cout << prev << endl;
      }
      prev = S[i];
    }
  }
  if (res[prev] == m) {
    cout << prev << endl;
  }

  return 0;
}

Measured memory_bytes: 26880
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    for(int i=0;i<n;i++){
    	if(i+1==k){
    		if(s.at(i)=='A'){
    			s[i]='a';
			}
			else if(s.at(i)=='B'){
    			s[i]='b';
			}
			else if(s.at(i)=='C'){
    			s[i]='c';
			}	
		}
		cout<<s[i];
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int n, k, s, ans, a[5005];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int i;
	cin>>n>>k;
	for(i=0; i<n; i++) cin>>a[i];
	sort(a, a+n);
	for(i=n-1; i>=0; i--) {
		if(s+a[i]>=k) ans = 0;
		else ans++, s += a[i];
        //dump(ans);
	}
	cout<<ans;
	return 0;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  vector<char>pic(W+2,'#');
  for(int i=0; i<pic.size(); i++){
    cout << pic.at(i);
  }
  cout << endl;
  vector<char>pic2(W);
  for(int i=0; i<H; i++){
    cout << '#';
    for(int j=0; j<W;j++){
      cin >> pic2.at(j);
      cout << pic2.at(j);
    }
    cout << '#' <<  endl;
  }
  vector<char>frame(W+2,'#');
  for(int i=0; i<frame.size(); i++){
    cout << frame.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 10000000000
#define FOR(i,a,n) for(i=a;i<n;i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
int n,a,b;
ll h[100000];
int check(ll t){
	int i,d=a-b;
	ll k=b*t;
	FOR(i,0,n){
		if(h[i]>k){
			t-=((h[i]-k+d-1)/d);
		}
	}
	return t>=0;
}
int main(void)
{
	int i;
	ll l=0,r=INF,mid;
	scanf("%d%d%d",&n,&a,&b);
	FOR(i,0,n) scanf("%lld",&h[i]);
	while(r>l){
		mid=(l+r)/2;
		if(check(mid)) r=mid;
		else l=mid+1;
	}
	printf("%lld\n",r);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n; cin >> n;
	ll tmp = 0;
	int l;
	FOR(i, 1, 1000000)
	{
		tmp += i;
		if (n <= tmp)
		{
			l = i;
			break;
		}
	}
	string ans = string(l, ')') + string(l, '(');
	int k = tmp - n;
	swap(ans[l], ans[l - k]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3360
def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    
    table.sort()
    return table

N, M = map(int, input().split())

div = divisor(M)

for i in range(len(div)):
    if div[i] <= M // N:
        res = div[i]
            
print(res)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
inline void fastIO(){
    ios_base::sync_with_stdio(0);cin.tie(0);
}

int main(){
   int a,b,c;
   cin>>a>>b>>c;
   if((a==b)&&(a!=c)){
        cout<<"Yes"<<endl;
   }else if((a==c)&&(a!=b)){
        cout<<"Yes"<<endl;
   }else if((c==b)&&(b!=a)){
        cout<<"Yes"<<endl;
   }else{
     cout<<"No"<<endl;
   }
}
// - VERIFICAR LONG VS INT -


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

using namespace std;

typedef tuple<int, int, int> tup;
#define rep(i, n) REP(i, 0, n)
#define REP(i, a, n) for(int i=(a); i<(n); i++)


int adj[110][110];
int dis[110][110];
bool f[110];

int main() {
	int N, M, L, K, A, H;
	while(cin>>N>>M>>L>>K>>A>>H, N+M+L+K+A+H) {
	    fill_n(f, N, false);
	    rep(v, N) fill_n(adj[v], N, INT_MAX);
	    rep(_, L) { int v; cin>>v; f[v] = true; }
	    rep(_, K) { int x, y, t; cin>>x>>y>>t; adj[x][y] = adj[y][x] = t; }
	    
	    rep(v, N) fill_n(dis[v], sizeof(dis[v]), INT_MAX);
	    priority_queue<tup, vector<tup>, greater<tup>> que;
	    que.push(make_tuple(dis[A][M]=0, A, M));
	    while(!que.empty()) {
	        int d_u, u, m;
	        tie(d_u, u, m) = que.top(), que.pop();
	        if(dis[u][m] < d_u) continue;
	        rep(v, N) {
	            if(adj[u][v]==INT_MAX) continue;
	            if(f[u]) {
	                for(int w=0; m+w<=M; w++) {
	                    if(m+w<adj[u][v]) continue;
	                    if(dis[v][m+w-adj[u][v]]>d_u+w+adj[u][v]) {
	                        dis[v][m+w-adj[u][v]] = d_u+w+adj[u][v];
	                        que.push(make_tuple(dis[v][m+w-adj[u][v]], v, m+w-adj[u][v]));
	                    }
	                }
	            } else {
	                if(m < adj[u][v]) continue;
	                if(dis[v][m-adj[u][v]]>d_u+adj[u][v]) {
	                    dis[v][m-adj[u][v]] = d_u+adj[u][v];
	                    que.push(make_tuple(dis[v][m-adj[u][v]], v, m-adj[u][v]));
	                }
	            }
	        }
	    }
	    
	    int ans = INT_MAX;
	    rep(i, M) ans = min(ans, dis[H][i]);
	    if(ans == INT_MAX) cout << "Help!" << endl;
	    else cout << ans << endl;
	}
}



Measured memory_bytes: 3324
module ABC135

  ! <module>s to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none

  ! accessibility of <subroutine>s and <function>s in this <module>
  public :: task_B

  ! contained <subroutine>s and <function>s are below
  contains
  
  subroutine task_B

    ! variables for this <subroutine>
    integer(INT32) :: len_sequence
    integer(INT32) :: num_descending
    integer(INT32) :: position_1st
    integer(INT32) :: position_2nd
    integer(INT8 ) :: val_sequence_buf
    logical        :: stat_valid

    ! arrays for this <subroutine>
    integer(INT8), dimension(:), allocatable :: val_sequence

    ! support variables for this <subroutine>
    integer(INT32) :: itr
    
    ! STEP.01
    ! read out the given data
    ! (length of the given sequence)
    read(unit=INPUT_UNIT, fmt=*) len_sequence

    ! STEP.02
    ! allocate the array to store the given data
    allocate( val_sequence(1:len_sequence) )

    ! STEP.03
    ! read out the given data
    ! (values of the given sequence)
    read(unit=INPUT_UNIT, fmt=*) val_sequence(:)

    ! STEP.04
    ! initialization of the variables
    num_descending = 0_INT32
    position_1st   = 0_INT32
    position_2nd   = 0_INT32
    stat_valid     = .true.

    do itr = 2_INT32, len_sequence, 1_INT32
      if ( val_sequence(itr-1) .gt. val_sequence(itr) ) then

        num_descending = num_descending + 1_INT32
        
        if ( num_descending .gt. 3_INT32 ) then
          stat_valid = .false.
          exit
        else if (position_1st .eq. 0_INT32) then
          position_1st = itr - 1
        else if (position_2nd .eq. 0_INT32) then
          position_2nd = itr
        end if

      end if
    end do
    
    ! STEP.05
    ! swap the element of the given sequence
    if ( num_descending .eq. 2_INT32 .and. stat_valid ) then
      val_sequence_buf             = val_sequence( position_1st )
      val_sequence( position_1st ) = val_sequence( position_2nd )
      val_sequence( position_2nd ) = val_sequence_buf
    end if
    
    ! STEP.06
    ! check the order of edited given sequence
    if ( stat_valid ) then
      do itr = 2_INT32, len_sequence, 1_INT32
        if ( val_sequence(itr-1) .gt. val_sequence(itr) ) then
          stat_valid = .false.
          exit
        end if
      end do
    end if

    ! STEP.07
    ! output the answer of this task
    if ( stat_valid ) then
      write(unit=OUTPUT_UNIT, fmt='(A)', advance='yes') 'YES'
    else
      write(unit=OUTPUT_UNIT, fmt='(A)', advance='yes') 'NO'
    end if

    ! STEP.08
    ! deallocate the array to store the given data
    deallocate( val_sequence )
    
    ! STEP.END
    return

  end subroutine task_B

end module ABC135

program main

  ! <module>s to import
  use, non_intrinsic :: ABC135
  
  call task_B

end program main

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

vector<vector<int> > mp;

int dir[4][2]={{-1,0}, {0,1}, {1,0}, {0,-1}};

vector<int> mv(string s){
  vector<int> tmp;
  for(int i=0; i<s.length(); i++){
    tmp.push_back(s[i]);
  }
  return tmp;
}

void solve(int i, int j){
  if(i<0 || 12<=i || j<0 || 12<=j)return;
  if(mp[i][j]=='0')return;
  mp[i][j]='0';
  for(int k=0; k<4; k++)
    solve(i+dir[k][0], j+dir[k][1]);
}

int main(){
  string s;
  while(cin>>s){
    mp.clear();
    if(s==""){continue;}
    mp.push_back(mv(s));
    for(int i=0; i<11; i++){
      cin>>s;
      mp.push_back(mv(s));
    }

    int ans=0;
    for(int i=0; i<12; i++){
      for(int j=0; j<12; j++){
        if(mp[i][j]=='1'){
          ans++;
          solve(i, j);
        }
      }
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1216
var fs = require('fs')
    length = fs.fstatSync(process.stdin.fd).size,
    buffer = new Buffer(length),
    bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
    input = buffer.toString('utf8', 0, bytesRead).split('\n');

function main(){
	a=input[0].split(' ').map(Number);
	console.log(a[0]>a[1]?'a > b':a[0]<a[1]?'a < b':'a == b');
}

main();


Measured memory_bytes: 15136
N = int(input())
H = list(map(int, input().split()))

# memo = [0] + [abs(H[i] - H[i-1]) for i in range(1, N)]
# memo = [H[i] - H[i-1] for i in range(1, N)]
memo = [sum(H)] * (N+2)
memo[0] = 0
for i in range(N):
    memo[i+1] = min(memo[i+1], memo[i] + abs(H[i+1] - H[i]))
    if i > N-3:
        break
    memo[i+2] = min(memo[i+2], memo[i] + abs(H[i+2] - H[i]))

print((memo[N-1]))

Measured memory_bytes: 52592
A,B,C,X,Y=list(map(int, input().split()))

extra_pizza=max(X,Y)
surplus=max(X,Y)-min(X,Y)

number_of_pair=(X+Y-surplus)/2
money_sum=0

if number_of_pair*(A+B) > number_of_pair*2*C:
    money_sum+=number_of_pair*2*C
else:
    money_sum+=number_of_pair*(A+B)

if extra_pizza==X:
    if surplus*A > surplus*2*C:
        money_sum+=surplus*2*C
    else:
        money_sum+=surplus*A
else:
    if surplus*B > surplus*2*C:
        money_sum+=surplus*2*C
    else:
        money_sum+=surplus*B

print(int(money_sum))


Measured memory_bytes: 3064