akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long   ll;
typedef unsigned long long   ull;
typedef long double ld;
typedef pair<ll, ll>    pll;
typedef pair<ull, ull>    pull;
typedef pair<ll, ll>  pii;
typedef pair<ld, ld>  pld;
ld n;
ld one, two, three;
ld dp[300][300][300];
ld f(ld i, ld j, ld k){
    if(i == 0 && j == 0 && k == 0)
        return 0;
    if(dp[(ll)i][(ll)j][(ll)k] != 0)
        return dp[(ll)i][(ll)j][(ll)k];
    ld tmp = 0;
    tmp += n/(i+j+k);
    if(i > 0)
        tmp += i/(i+j+k)*f(i-1, j, k);
    if(j > 0)
        tmp += j/(i+j+k)*f(i+1, j-1, k);
    if(k > 0)
        tmp += k/(i+j+k)*f(i, j+1, k-1);
    return dp[(ll)i][(ll)j][(ll)k] = tmp;
    
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    
    cin >> n;
    ll tmp;
    for(int i = 0; i < n; ++i){
        cin >> tmp;
        if(tmp == 1)
            ++one;
        else if(tmp == 2)
            ++two;
        else if(tmp == 3)
            ++three;
    }
    
    cout << fixed << setprecision(14) << f(one, two, three) << "\n";
        
}

Measured memory_bytes: 420224
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastIO;
    vector<int> in;
    rep(i, 3) {
        int t;
        cin >> t;
        in.push_back(t);
    }
    sort(in.begin(), in.end());
    cout << (in.at(2) * 10 + in.at(1) + in.at(0));
}

Measured memory_bytes: 3632
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()

mod = 10**9+7
def inv(x):
  y = 1
  while x != 1:
    y *= mod // x + 1
    x -= mod % x
    y %= mod
  return y

d = []
tmp = 1
for i in range(1,k):
  tmp *= n-i
  tmp %= mod
  tmp *= inv(k-i)
  tmp %= mod
d.append(tmp)
#print(tmp)
for i in range(1,n):
  tmp = d[-1]
  tmp *= inv(n-i)
  tmp %= mod
  tmp *= n-k+1-i
  tmp %= mod
  d.append(tmp)
#print(d)
ans = 0
for i in range(n):
  ans += d[i] * a[-i-1]
  ans -= d[i] * a[i]
  ans %= mod
print(ans)

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

using Graph = std::vector<std::vector<int>>;

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

  std::set<std::pair<int, int>> v_pair;

  Graph G(N);
  for (int i = 0; i < M; ++i) {
    int a, b;
    std::cin >> a >> b;
    --a, --b;

    std::pair<int,int> p1(a, b);
    std::pair<int,int> p2(b, a);

    if (v_pair.count(p1) || v_pair.count(p2)) continue;
    v_pair.insert(p1);


    G[a].push_back(b);
    G[b].push_back(a);

  }
  
  std::vector<int> dist(N, -1);
  std::queue<int> que;

  int ans = 0;
  
  for (int v = 0; v < N; ++v) {
    if (dist[v] != -1) continue; // vは探索済み
    dist[v] = 0;
    que.push(v);
    int count = 0;
    while (!que.empty()) {
      int v = que.front();
      que.pop();
      ++count;
      for (auto v_next : G[v]) {
        if (dist[v_next] != -1) continue;
        dist[v_next] = dist[v] + 1;
        que.push(v_next);
        // ++count;
      }
    }
    ans = std::max(ans, count);
  }

  if (M == 0) ans = 1;
  
  std::cout << ans << std::endl << std::flush;


  return 0;
}


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

void insertSort(string &s, bool des = false)
{
  //挿入ソート
  for(int i = 1; i < s.size(); i++)
  {
    for(int j = i; j > 0; j--)
    {
      char a = s[j];
      if(!des)
      {
        if(s[j - 1] > a)
        {
          s[j] = s[j - 1];
          s[j - 1] = a;
        }
      }
      else
      {
        if(s[j - 1] < a)
        {
          s[j] = s[j - 1];
          s[j - 1] = a;
        }
      }
    }
  }
}

int main()
{
  bool res = false, isEqual = true;
  string s, t;
  cin >> s >> t;
  insertSort(s);
  insertSort(t, true);
  int length = (s.size() > t.size())? t.size(): s.size();
  for(int i = 0; i < length; ++i)
  {
    if(s[i] < t[i])
    {
      res = true;
      break;
    }
  }
  
  //if(!res && isEqual && s.size() < t.size())
  if(!res && s.size() < t.size())
  {
    for(int i = 0; i < length; i++)
    {
      if(s[i] != t[i])
      {
        isEqual = false;
      }
    }
    
    if(isEqual)
      res = true;
  }
  
  if(res)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
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 (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    ll N; cin >> N;
    ll ans = 1;
    ll max = 0;
    FOR(i, 1, N+1) {
        ll c = 0;
        ll n = i;
        while (n/2 != 0) {
            n /= 2;
            c++;
        }
        if (max < c) {
            max = c;
            ans = i;
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000
const long long INF=1145141919,MOD=1e9+7;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const double EPS = 1e-9;    // 許容誤差。問題によって変える
//typedef complex<double> P;  // Point
//typedef vector<P> VP; //単純多角形
//#define X real()
//#define Y imag()
//#define LE(n,m) ((n) < (m) + EPS)
//#define GE(n,m) ((n) + EPS > (m))
//#define EQ(n,m) (abs((n)-(m)) < EPS)
//namespace std{
//    bool operator < (const P a, const P b){
//        return a.X != b.X ? a.X <b.X : a.Y < b.Y;
//    }
//}
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
//外積cross(a,b) = |a||b|sinθ
//double cross(const P& a, const P& b) {
 // return imag(conj(a)*b);
//}
//内積dot(a,b) = |a||b|cosθ
//double dot(const P& a, const P& b) {
  //return real(conj(a)*b);
//}
//Line
//struct L : public vector<P> {
  //L(const P &a, const P &b) {
    //push_back(a); push_back(b);
  //}
//};
//円
//struct C{
//  P p; double r;
//  C(const P &p, double r) : p(p), r(r) { }
//};
int main(){
    int a,p;
    cin>>a>>p;
    cout<<(a*3+p)/2<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int MAXN=100001;
int Q,L,R,primenum=0;
int prime[MAXN],ans[MAXN];
bool flag[MAXN];
inline void getready()
{
	memset(ans,0,sizeof(ans));
	memset(flag,0,sizeof(flag));
	flag[0]=flag[1]=true;
	for(int i=2;i<MAXN;++i)
	{
		if(flag[i]==false) prime[++primenum]=i;
		for(int j=1;j<=primenum&&i*prime[j]<MAXN;++j)
		{
			flag[i*prime[j]]=true;
			if(i%prime[j]==0) break;
		}
	}
	for(int i=1;i<MAXN;++i)
		if(flag[i]==false&&flag[(i+1)>>1]==false) ans[i]=1;
	for(int i=1;i<MAXN;++i)
		ans[i]+=ans[i-1];
}
inline int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
	return x*f;
}
int main()
{
	getready();
	Q=read();
	while(Q--)
	{
		L=read();R=read();
		printf("%d\n",ans[R]-ans[L-1]);
	}
	return 0;
}

Measured memory_bytes: 1152
import javax.print.DocFlavor;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.BiConsumer;

public class Main {

    //グローバル変数を定義

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        String input = sc.next();

        if(input.length() == 2){
            System.out.println(input);
        } else {
            for(int i=0; i<3; i++){
                System.out.print(input.charAt(2-i));
            }
            System.out.println();
        }
    }
}
//
//class Gauss {
//    //連立方程式の係数
//    //a[N][N](係数行列)とb[1](定数)を一緒にしたもの
//    double a[][];
//    int N;
//
//    Gauss(double[][] a, int N){
//        a = a;
//        N = N;
//    }
////    double a[][]={{1.0,1.0,1.0,1.0,10,0},
////            {2.0,1.0,3.0,2.0,21.0},
////            {1.0,3.0,2.0,1.0,17.0},
////            {3.0,2.0,1.0,1.0,14.0}};
////    int N=a.length;
//
//    //Gaussの消去法で連立方程式を解く
//    void gauss(){
//        //前進消去
//        double s;
//        for(int k=0; k<N-1; k++){
//            for(int i=k+1; i<N; i++){
//                s=a[i][k]/a[k][k];
//                for(int j=k+1; j<=N; j++){
//                    a[i][j] -= s * a[k][j];
//                }
//            }
//        }
//        //後退代入
//        for(int i=N-1; i>=0; i--){
//            s=a[i][N];
//            for(int j=i+1; j<N; j++){
//                s -= a[i][j] * a[j][N];
//            }
//            a[i][N] = s/a[i][i];
//        }
//    }
//    public static void run() {
//        Gauss gs= new Gauss();
//        gs.gauss();
//        //解の表示
//        System.out.println("ガウスの消去法による連立1次方程式の解");
//        for(int i=0; i<gs.N; i++){
//            System.out.println("x["+i+"] = "+gs.a[i][gs.N]);
//        }
//    }
//}


Measured memory_bytes: 21716
package main

import (
	"fmt"
	"strings"
)

func main() {
	var N, A, B int
	fmt.Scan(&N, &A, &B)

	var S string
	fmt.Scan(&S)

	s := strings.Split(S, "")

	var x, y int
	for _, v := range s {
		if v == "a" {
			if x < A+B {
				fmt.Println("Yes")
				x++
			} else {
				fmt.Println("No")
			}
		} else if v == "b" {
			y++
			if x < A+B && y <= B {
				fmt.Println("Yes")
				x++
		} else {
			fmt.Println("No")
		}
	} else {
			fmt.Println("No")
		}
	}
}


Measured memory_bytes: 4992
package main

import "fmt"

func main() {
	var n, p int
	fmt.Scan(&n, &p)

	m := make(map[int]int)
	t := p
	for i := 2; i*i <= p; i++ {
		for t%i == 0 {
			m[i]++
			t /= i
		}
	}
	if t != 1 {
		m[t] = 1
	}

	ans := 1
	for k, v := range m {
		for i := 0; i < v/n; i++ {
			ans *= k
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
package main

import (
	"fmt"
	"strconv"
)

type Card struct {
	Kind string
	Val  int
}

func main() {
	var N int
	fmt.Scan(&N)
	cards := make([]Card, N)
	for i := 0; i < N; i++ {
		var s string
		fmt.Scan(&s)
		cards[i] = Card{kind(s), val(s)}
	}
	cards1 := make([]Card, N)
	cards2 := make([]Card, N)
	copy(cards1, cards)
	copy(cards2, cards)
	bubbleSort(cards1)
	p(cards1)
	if isStable(cards, cards1) {
		fmt.Println("Stable")
	} else {
		fmt.Println("Not stable")
	}
	selectionSort(cards2)
	p(cards2)
	if isStable(cards, cards2) {
		fmt.Println("Stable")
	} else {
		fmt.Println("Not stable")
	}
}

func isStable(arr1, arr2 []Card) bool {
	map1 := make(map[int][]string)
	map2 := make(map[int][]string)
	for i := 0; i < len(arr1); i++ {
		card := arr1[i]
		map1[card.Val] = append(map1[card.Val], card.Kind)
	}
	for i := 0; i < len(arr2); i++ {
		card := arr2[i]
		map2[card.Val] = append(map2[card.Val], card.Kind)
	}
	for num, kinds := range map1 {
		for i, k := range kinds {
			if k != map2[num][i] {
				return false
			}
		}
	}
	return true
}

func bubbleSort(arr []Card) {
	for i := 0; i < len(arr); i++ {
		for j := len(arr) - 1; j >= i+1; j-- {
			if arr[j].Val < arr[j-1].Val {
				arr[j], arr[j-1] = arr[j-1], arr[j]
			}
		}
	}
}

func selectionSort(arr []Card) {
	for i := 0; i < len(arr); i++ {
		minj := i
		for j := i; j < len(arr); j++ {
			if arr[j].Val < arr[minj].Val {
				minj = j
			}
		}
		arr[i], arr[minj] = arr[minj], arr[i]
	}
}

func val(card string) int {
	i, _ := strconv.Atoi(string(card[1]))
	return i
}

func kind(card string) string {
	return string(card[0])
}

func p(arr []Card) {
	for i := 0; i < len(arr); i++ {
		if i != 0 {
			fmt.Print(" ")
		}
		fmt.Print(arr[i].Kind)
		fmt.Print(arr[i].Val)
	}
	fmt.Println()
}



Measured memory_bytes: 1148
#include<stdio.h>
#include<math.h>
int s[10005];
int main()
{
    int n,i,count=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&s[i]);
    }
    for(i=0;i<n;i++)
    {
        while(s[i]%2==0)
        {
            s[i]=s[i]/2;
            count++;
        }
    }
    printf("%d",count);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n;
  cin>>n;
  if(n==22) cout<<"Christmas Eve Eve Eve"<<endl;
  else if(n==23) cout<<"Christmas Eve Eve"<<endl;
  else if(n==24) cout<<"Christmas Eve"<<endl;
  else if(n==25) cout<<"Christmas"<<endl;

  return 0;
}


Measured memory_bytes: 256
# abc171_b.py
# https://atcoder.jp/contests/abc171/tasks/abc171_b

# B - Mix Juice /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# ある店で N種類の果物、果物 1,…,N が売られており、それぞれの価格は一個あたり p1,…,pN円です。
# この店で K種類の果物を一個ずつ買うとき、それらの合計価格として考えられる最小の金額を求めてください。

# 制約
#     1≤K≤N≤1000
#     1≤pi≤1000
#     入力中の値はすべて整数である。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N K
# p1 p2 … pN

# 出力
# 果物の最小の合計価格を表す整数を出力せよ。

# 入力例 1
# 5 3
# 50 100 80 120 80

# 出力例 1
# 210

# この店では、果物 1,2,3,4,5がそれぞれ 50 円、100 円、80 円、120 円、80円で売られています。
# これらから 3種類を買うときの最小合計価格は、果物 1,3,5 を買うときの 50+80+80=210円です。

# 入力例 2
# 1 1
# 1000

# 出力例 2
# 1000


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    # N = int(lines[0])
    N, K = list(map(int, lines[0].split()))
    values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    values.sort()
    tmps = values[:K]
    result = sum(tmps)

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['5 3', '50 100 80 120 80']
        lines_export = [210]
    if pattern == 2:
        lines_input = ['1 1', '1000']
        lines_export = [1000]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9268
from collections import deque
a=list(map(int,input().split()))
n,q=a[0],a[1]
data=deque()
for i in range(n):
    process=input().split()
    process[1]=int(process[1])
    data.append(process)
time=0

while len(data)!=0:
    task=data.popleft()
    if task[1]>q:
        task[1]-=q
        data.append(task)
        time+=q
    else:
        time+=task[1]
        print(task[0],time)



Measured memory_bytes: 17408
#include <bits/stdc++.h>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18 


int main () {
    int a, b ;
    cin >> a >> b ;
    int n = 1;
    int t = a;
    while(b > t){
        n++ ; 
        t = t + a - 1 ;
    }
    if(b == 1){
        n = 0 ;
    }
    cout << n << endl ;
}

Measured memory_bytes: 3592
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	num, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return num
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	// sc.Split(bufio.ScanWords)
	n := nextInt()
	dictionary := map[string]int{}
	for i := 0; i < n; i++ {
		str := nextString()
		dictionary[str] = 1
	}

	fmt.Println(len(dictionary))
}


Measured memory_bytes: 18304
from decimal import Decimal
import math
import sys
sys.setrecursionlimit(10**9)


t = int(input())
for i in range(t):
    n, a, b, c, d = map(int, input().split())

    memo = dict()
    memo[0] = 0
    memo[1] = d

    def solve(v):
        if v in memo:
            return memo[v]

        if v > 10**16:
            v = Decimal(v)

        memo[v] = min(solve(math.floor(v / 5)) + c + (v - math.floor(v / 5) * 5) * d,
                      solve(math.ceil(v / 5)) + c + (math.ceil(v / 5) * 5 - v) * d,
                      solve(math.floor(v / 3)) + b + (v - math.floor(v / 3) * 3) * d,
                      solve(math.ceil(v / 3)) + b + (math.ceil(v / 3) * 3 - v) * d,
                      solve(math.floor(v / 2)) + a + (v - math.floor(v / 2) * 2) * d,
                      solve(math.ceil(v / 2)) + a + (math.ceil(v / 2) * 2 - v) * d,
                      v * d)
        return memo[v]

    print(solve(n))


Measured memory_bytes: 11992
#include <iostream>
#include <unordered_set>

int main(void) {
	int N, M, K, Ans;
	std::cin >> N >> M;

	std::unordered_set<int> *A = new std::unordered_set<int>[N];

	for (int i = 0; i < N; i++) {
		std::cin >> K;
		for (int j = 0; j < K; j++) {
			std::cin >> Ans;
			A[i].insert(Ans);
		}
	}

	int num = 0;
	bool success;
	for (int i = 0; i <= M; i++) {
		success = 1;

		for (int j = 0; j < N; j++) {
			if (A[j].find(i) == A[j].end()) {
				success = 0;
			}
		}

		if (success) {
			num++;
		}
	}

	std::cout << num;

	delete[] A;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <numeric>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll MOD = 1000000007;
const ll INF = 1LL << 60;
#define PI (acos(-1))

ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}
vector<ll> divisor(ll n)
{
    vector<ll> ret;
    for (ll i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i * i != n)
                ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

const ll MAX = 510000;
// const ll MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll a[101];
ll solve()
{
    string s;
    cin >> s;
    map<char, ll> m;
    m[s[0]]++;
    m[s[1]]++;
    if(s.length() == 2){
        if(m[s[0]] == 2){
            cout << 1 << " " << 2 << endl;
            return 0;
        }
    }

    for(int i=2; i < s.length(); i++){
        m[s[i]]++;
        if(m[s[i]] >= 2){
            cout << i - 1 << " " << i + 1 << endl;
            return 0;
        }else if(m[s[i - 1]] >=2){
            cout << i - 1 << " " << i + 1 << endl;
            return 0;
        }
        m[s[i - 2]]--;
    }
    cout << -1 << " " << -1 << endl;

    return 0;
}

int main()
{
    //cout.precision(10);
    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();
}


Measured memory_bytes: 512
n, m, q = map(int, input().split())

x = [[0 for i in range(n)] for j in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    x[a-1][b-1] += 1

for j in range(1, n):
    for k in range(n-j):
        x[k][j+k] += x[k][j+k-1] + x[k+1][j+k] - x[k+1][j+k-1]

y = []
for i in range(q):
    a, b = map(int, input().split())
    y.append(x[a-1][b-1])
    
for i in range(q):
    print(y[i])

Measured memory_bytes: 10468
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int n, d;
    cin >> n >> d;
    int ans = n / (2 * d +1);

    if(n % (2 * d + 1) != 0) {
        cout << ans + 1 << endl;
    }else
    {
        cout << ans <<  endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    
    int S, h, m, s;
    int mod;
    
    scanf("%d", &S);
    
    h = S / 3600;
    mod = S % 3600;
    m = mod / 60;
    s = mod % 60;
    
    printf("%d:%d:%d\n",h, m, s);
    
    return 0;
}

Measured memory_bytes: 592
#include<iostream>
using namespace std;
#define ll long long
#define int long long

pair<int,int> ans[100010];
int ans2[100010];
int p;

signed main(){
    int n,k;cin>>n>>k;

    if(k>(n+1)/2){
        cout<<"-1"<<endl;
        return 0;
    }

    ll now=(3*n+1)/2;
    if(n%2){
        for(int i=1;i<=n;i++){
            int tmp=i%2==0?(n+1)/2+i/2:(i+1)/2;
            ans[p++]={tmp,now+i-tmp};
        }
    }
    else{
        for(int i=1;i<n;i++){
            int tmp=i%2==0?n/2+1+i/2:(i+1)/2;
            ans[p++]={tmp,(now+1+i/2*2)-tmp};
        }
        ans[p++]={n/2+1,2*n};
    }

    for(int i=0;i<n;i++)ans2[i]=k+n*2+i,ans[i].first+=k-1,ans[i].second+=k-1;
    for(int i=0;i<n;i++){
        if(ans[i].first+ans[i].second>ans2[i]){
            cout<<"-1"<<endl;
            return 0;
        }
    }
    for(int i=0;i<n;i++){
        cout<<ans[i].first<<" "<<ans[i].second<<" "<<ans2[i]<<endl;
    }
}


Measured memory_bytes: 4608
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
a=list(map(int,input().split()))
a.sort()
rui=list(accumulate(a))
# print(rui)

cnt=0
now=0
for now in range(n-1):
    if rui[now]*3>=rui[now+1]:
        cnt+=1
    else:
        cnt=0
print(cnt+1)

Measured memory_bytes: 86376
import sys
def main():
  input=sys.stdin.readline
  n,k=map(int,input().split())
  a=list(map(int,input().split()))
  accum=[0]*n
  accum[0]=a[0]
  d=dict()
  ans=0
  for i in range(1,n):
    accum[i]+=a[i]+accum[i-1]
  accum=[0]+accum
  for j in range(n+1):
    if j-k>=0:
      d[(accum[j-k]-(j-k))%k]-=1
    if (accum[j]-j)%k not in d:
      d[(accum[j]-j)%k]=1
    else:
      ans+=d[(accum[j]-j)%k]
      d[(accum[j]-j)%k]+=1
    #print(d)
  return print(ans)
if __name__=='__main__':
  main()

Measured memory_bytes: 48024
#include<bits/stdc++.h>
#define maxn 120000
using namespace std;
typedef long long LL;
LL h[maxn], f[maxn]; 
int main(){
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	for(int i = 1; i <= N; i += 1) cin >> h[i];
	for(int i = 2; i <= N; i += 1){
		f[i] = f[i - 1] + abs(h[i] - h[i - 1]);
		for(int j = 2; j <= K && j < i; j += 1)
			f[i] = min(f[i], f[i - j] + abs(h[i] - h[i - j]));
	}
	cout << f[N];
} 

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    string t;
    cin >> t;

    for ( size_t i = 0; i < t.size(); i++ ) {
        if ( t[i] == '?' ) cout << "D";
        else cout << t[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3720
#include<stdio.h>

int main() {
	int x,y,z;

	scanf("%d %d", &x,&y);

		while (x != 0||y!=0) {
		    if(x>y){
		        z=x;
		        x=y;
		        y=z;
		    }
			printf("%d %d\n", x,y);
			scanf("%d %d", &x,&y);
		}

	return 0;
}


Measured memory_bytes: 2044
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <sstream>
#include <map>
#include <cstring>
#include <vector>
#include <queue>
#include <iomanip>

using namespace std;
typedef long long ll;

ll ans, mx, sum, mn = 1e8, cnt;
int main(){
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0; i<n; i++){
		cin>>a[i];
	}
		
	mn=a[0];
	for(ll i=0; i<n; i++){
		if(a[i]<=mn) mn=a[i];
		if(a[i]<=mn) ans++; 
	}
	cout<<ans;

}

Measured memory_bytes: 5148
x,n=map(int,input().split())
p=list(map(int,input().split()))

dist=1000
ans=1000
for i in range(101,-1,-1):
  if i in p:
    continue
  t_dist=abs(x-i)
  if t_dist<=dist:
    ans=i
    dist=t_dist

print(ans)

Measured memory_bytes: 9116
import sys
import math
N, M = map(int, input().split())
INF = 10 ** 9 + 7

if abs(N - M) >= 2:
    print(0)
    sys.exit()

tmpN = math.factorial(N)
tmpM = math.factorial(M)
ans = tmpN * tmpM
if N == M:
    ans *= 2
print(ans % INF)

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

int n;
int dp[100100][4];
vector<int> arr[100100];

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        int k;
        for (int j = 0; j < 3; ++j) {
            cin >> k;
            arr[i].push_back(k);
        }
    }

    for (int i = 0; i < 3; ++i) dp[1][i] = arr[1][i];

    for (int pos = 2; pos <= n; ++pos) {
        for (int j = 0; j < 3; ++j) {

            if ( j == 0 ) 
                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][1], dp[pos - 1][2]);
            
            else if ( j == 1 )
                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][0], dp[pos - 1][2]);

            else
                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][0], dp[pos - 1][1]);
        }
    }

    cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;
    return 0;
}


Measured memory_bytes: 7296
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n, l;
	cin >> n >> l;
	
	vector<string> s(n);
	for(int i = 0; i < n; ++i) {
		cin >> s[i];
	}
	
	sort(s.begin(), s.end());
	
	string ans = "";
	for(int i = 0; i < n; ++i) {
		ans += s[i];
	}
	
	cout << ans << endl;
	
	return 0;
}


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

int main(){
    int ans = 0;
    int num1 = 0;
    vector <int> v1;
    int num2 = 0;
    vector <int> v2;
    cin >> num1;

    for(int i = 0; i < num1 ; i++ ){
        int tmp;
        cin >> tmp;
        v1.push_back(tmp);
    }

    cin >> num2;

    for(int i = 0; i < num2; i++){
        int tmp;
        cin >> tmp;
        v2.push_back(tmp);
    }

    for(int i = 0; i< num2; i++){
        auto it = lower_bound(v1.begin(), v1.end(), v2[i]);
        
        if(it != v1.end() && *it == v2[i]){
            ans++;
        }

    }

    cout << ans << endl;

    return 0;
}


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

int main() {

	string S,T;
	int change = 0;
	cin >> S >> T;

	for (int i = 0; i < S.length(); i++) {
		if (S[i] != T[i]) change++;
	}

	cout << change;

	return 0;
}

Measured memory_bytes: 3468
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    h = II()
    w = II()
    print((n-h+1)*(n-w+1))
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 38640
while True:
    n,x = list(map(int,input().split()))
    if n==0 and x==0:break
    way=0
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if i+k+j==x:
                    way+=1
    print(way)


Measured memory_bytes: 5592
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)

using namespace std;

string s;
char *p;

string solve(){
	string ret;
	int cnt=0;

	for(;;){
		if(*p == '+'){
			cnt++;
		}else if(*p == '-'){
			cnt--;
		}else if(*p == '['){
			p++;
			auto r=solve();
			rrep(i, r.size()) ret += r[i];
		}else if(*p == ']' || *p == 0){
			return ret;
		}else{
			ret += (char)((*p-'A'+cnt+260)%26+'A');
			cnt = 0;
		}
		p++;
	}
}



int main(){
	for(;;){
		string ss;
		cin >> ss;
		if(ss == ".") break;
		
		string ret= "z";

		rep(i,26) rep(j,26) rep(k,26){
			s = "";
			int a=0;
			for(auto c:ss){
				if(c=='?'){
					if(a==0) c=i+'A';
					if(a==1) c=j+'A';
					if(a==2) c=k+'A';
					a++;
				}
				s += c;
			}
			p = &s[0];
			auto r = solve();

			ret = min(ret, r);
		}
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 3124
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

char table[][2] = {{'i','i'},
		   {'w','w'},
		   {'(',')'},
		   {')','('},
		   {'{','}'},
		   {'}','{'},
		   {'[',']'},
		   {']','['}};

int memo[15][15];
string str;

char oppose(char c){
  for(int i=0; i<8; i++)
    if(c==table[i][0])
      return table[i][1];
  return 0;
}

int solve(int from,int to){
  if(memo[from][to]!=-1){
    return memo[from][to];
  }else{
    int ans=3;
    for(int f=from; str[f]!='i'; f++){
      char op=oppose(str[f]);
      for(int t=to; str[t]!='i'; t--)
	if(str[t]==op)
	  ans = max(ans,2+solve(f+1,t-1));
    }
    memo[from][to] = ans;
    return ans;
  }
}

int main(){
  for(int i=0; i<15; i++) for(int j=0; j<15; j++) memo[i][j] = -1;

  cin >> str;
  cout << solve(0,str.size()-1) << endl;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void)
{
    ll n, x, m;
    cin >> n >> x >> m;
    vb used(m*2);
    vll one_cycle;
 
    ll start = 0;
    ll now = x;
    
 	rep(i, n) {
        used[now] = true;
        one_cycle.pb(now);
        now = now * now % m;
        if (used[now]) {
            for(ll j = 0; j < (ll)one_cycle.size(); ++j) if (one_cycle[j] == now) {
                start = j;
                break;
            }
        break;
        }
    }
 
    ll s1 = 0, s2 = 0, loop = one_cycle.size() - start;
    
    rep(i, start) s1 += one_cycle[i];
    
    for(int i = start; i < one_cycle.size(); ++i) s2 += one_cycle[i];
    
    ll ans = s1 + (n - start) / loop * s2;
    
    for(int i = 0; i < (n - start) % loop; ++i) {
        ans += now;
        now = now * now % m;
    }
    
    mes(ans);
    
    return 0;
}

Measured memory_bytes: 3836
package main

import (
	"bufio"
	"fmt"
	"go/token"
	"go/types"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	n, _ := strconv.Atoi(stdin.Text())
	for i := 0; i < n; i++ {
		stdin.Scan()
		exp := strings.TrimRight(stdin.Text(), "=")
		res, _ := types.Eval(token.NewFileSet(), nil, token.NoPos, exp)
		fmt.Println(res.Value)
	}
}



Measured memory_bytes: 1836
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <array>

using namespace std;
int INF = 100000000;

struct Matrix { int row, col; };

int getMinMCM(const vector<Matrix>& matVec) {
	const size_t n = matVec.size();
	//table(i,num)は、与えられた行列積のindex=i(0始まり）の行列から、num個先の行列までの積についてのMCM最小値を記録する
	//（ table.at(0).at(n - 1) が求まると、与えられた行列積全体のMCMが求まる ）
	vector< vector<int> > table(n, vector<int>(n, 0));
	for (size_t num = 1; num != n; ++num) {
		const size_t end = n - num;
		for (size_t i = 0; i != end; ++i) {
			const Matrix& matI = matVec.at(i);
			const Matrix& matNum = matVec.at(i+num);
			int& target = table.at(i).at(num);
			target = INF;
			int end2 = i + num;
			for (int j = i; j != end2; ++j) {
				const Matrix& matJ = matVec.at(j);
				target = min(target, matI.row * matJ.col * matNum.col + table.at(i).at(j - i) + table.at(j + 1).at(num+i-j-1));
			}

		}
	}
	return table.at(0).at(n - 1);
}

template<typename T>
void execute(T& cin) {
	int n;
	cin >> n;
	vector<Matrix> m(n);
	for (auto& matrix : m)cin >> matrix.row >> matrix.col;
	cout << getMinMCM(m) << endl;

}

int main()
{
	execute(cin);

	return 0;
}


Measured memory_bytes: 3108
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

struct edge {
    ll to, cost;
};

int V;
vector<edge> G[1000000];
vector<ll> d1, d2;

void addedge(int st, int ed, ll co) {
    edge e;
    e.to = ed;
    e.cost = co;
    G[st].push_back(e);
}

void dijkstra(int s, vector<ll> &distance) {
    priority_queue<plglg, vector<plglg>, greater<plglg> > que;
    distance = vector<ll>(V, inf);
    distance[s] = 0;
    que.push(plglg(0, s));

    while (!que.empty()) {
        plglg p = que.top();
        que.pop();
        ll v = p.second;
        if (distance[v] < p.first) {
            continue;
        }
        int len = G[v].size();
        for (int i = 0; i < len; i++) {
            edge e = G[v][i];
            if (distance[e.to] > distance[v] + e.cost) {
                distance[e.to] = distance[v] + e.cost;
                que.push(plglg(distance[e.to], e.to));
            }
        }
    }
}

ll snum[200010];
ll tnum[200010];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M, s, t;
    cin >> N >> M >> s >> t;
    V = N;
    s--;
    t--;
    REP(i, 0, M) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        addedge(a, b, 1);
        addedge(b, a, 1);
    }
    dijkstra(s, d1);
    dijkstra(t, d2);
    REP(i, 0, N) {
        if (d1[i] != inf) {
            snum[d1[i]]++;
        }
        if (d2[i] != inf) {
            tnum[d2[i]]++;
        }
    }
    ll ans = 0;
    REP(i, 0, d1[t] - 1) {
        ans += snum[i] * tnum[d1[t] - i - 2];
    }
    cout << ans << endl;
}



Measured memory_bytes: 38120
def solve(string):
    import heapq
    x, y, z, k, *abc = map(int, string.split())
    a, b, c = map(lambda x: sorted(x, reverse=True), [abc[:x], abc[x:x + y], abc[x + y:]])
    hq = []
    heapq.heappush(hq, (-(a[0] + b[0] + c[0]), 0, 0, 0))
    ans = []
    check = set([(0, 0, 0)])
    for _ in range(k):
        m, i, j, k = heapq.heappop(hq)
        ans.append(str(-m))
        if i + 1 < x and (i + 1, j, k) not in check:
            heapq.heappush(hq, (-(a[i + 1] + b[j] + c[k]), i + 1, j, k))
            check.add((i + 1, j, k))
        if j + 1 < y and (i, j + 1, k) not in check:
            heapq.heappush(hq, (-(a[i] + b[j + 1] + c[k]), i, j + 1, k))
            check.add((i, j + 1, k))
        if k + 1 < z and (i, j, k + 1) not in check:
            heapq.heappush(hq, (-(a[i] + b[j] + c[k + 1]), i, j, k + 1))
            check.add((i, j, k + 1))
    return "\n".join(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input() for _ in range(4)])))


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

int main(){
    int h,w;
    while(cin >> h >> w && !(h==0 && w==0)){
        for(int i=0;i<h;++i){
            for(int j=0;j<w;++j){
                if(i==0 || i==h-1 || j==0 || j==w-1) cout << '#';
                else cout << '.';
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3080
a,b = [int(i) for i in input().split()]
if(a<0):
  if(b<0):
    if((b-a)%2 ==0):
      print('Negative')
    else:
      print('Positive')
  else:
    print('Zero')
elif(a == 0):
  print('Zero')
else:
  print('Positive')

Measured memory_bytes: 3060
k = list(map(int, input().split()))
a = list(map(int, input().split()))
sa = [a[i + 1] - a[i] for i in range(len(a) - 1)]
l = (k[0] - a[-1]) + a[0]
sa = sa + [l]
print(sum(sa) - max(sa))

Measured memory_bytes: 26436
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;

signed main() {
	int N;
	cin >> N;
	vector<double>p(N);
	rep(i, N)cin >> p[i];
	vector<vector<double>>dp(N, vector<double>(N + 1));
	dp[0][0] = 1 - p[0];
	dp[0][1] = p[0];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= N; j++) {
			if (i - 1 >= 0)dp[i][j] += dp[i - 1][j] * (1 - p[i]);
			if (i - 1 >= 0 && j - 1 >= 0)dp[i][j] += dp[i - 1][j - 1] * p[i];
		}
	}
	double ans = 0;
	for (int i = N / 2 + 1; i <= N; i++)ans += dp[N - 1][i];
	printf("%.10f", ans);
}

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

#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) for(int i=int(n-1);i>=0;i--)
#define forn(i,n) for(int i=0;i<int(n);i++)
#define D(a) cerr << #a << " = " << a << endl
#define all(a) a.begin(),a.end()
#define si(a) int((a).size())
typedef pair<int,int> pii;
typedef long long int ll;
typedef vector<int> vi;
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    
    int n; cin >> n;
    vi a[3],dp[3];
    forn(i,3) a[i] = vi(n), dp[i] = vi(n+1);
    forn(i,n) forn(j,3) cin >> a[j][i];
    dforn(i,n) forn(j,3){
        int x = dp[(j+1) % 3][i+1];
        int y = dp[(j+2) % 3][i+1];
        dp[j][i] = max(dp[j][i], a[j][i] + max(x,y));
    }
    int r = 0;
    forn(i,3) r = max(r, dp[i][0]);
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    string s;
    cin >> s;
    int ans = 0;
    vector<int> cnt(2);
    for (auto c : s) {
        cnt[c - '0']++;
    }
    cout << min(cnt[0], cnt[1]) * 2 << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
ll MOD = 1000000007;
ll INF = 2147483647;
double EPS = 1e-12;
double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

template <class T>
class SegmentTree{
  ll N;
  vector<T> data;
  T def;
  function<T(T,T)> operation;
  function<T(T,T)> update;

  T _query(ll a,ll b,ll k,ll l,ll r){
      if(b <= l || r <= a) return def;
      if(a <= l && r <= b){
          return data[k];
      }else{
          T c1 = _query(a,b,k*2+1,l,(l+r)/2);
          T c2 = _query(a,b,k*2+2,(l+r)/2,r);
          return operation(c1,c2);
      }
  }
  public:
  SegmentTree(size_t _N,T _def,function<T(T,T)> _operaition,function<T(T,T)> _update):def(_def),operation(_operaition),update(_update){
          N = 1;
          while(N < _N){
              N *= 2;
          }
          data = vector<T>(2*N-1,def);
  }

  void change(ll i,T x){
      i += N-1;
      data[i] = update(data[i],x);
      while(i > 0){
          i = (i-1)/2;
          data[i] = operation(data[i*2+1],data[i*2+2]);
      }
  }

  T query(ll a,ll b){
      return _query(a,b,0,0,N);
  }

  T operator[](ll i){
      return data[i+N-1];
  }
};

int main(){
    ll N,Q;cin >> N >> Q;
    auto f = [](ll a,ll b){return min(a,b);};
    auto g = [](ll a,ll b){return b;};
    SegmentTree<ll> ST(N,INF,f,g);
    rep(i,Q){
        ll t,x,y;cin >> t >> x >> y;
        if(t == 0){
            ST.change(x,y);
        }else{
            cout << ST.query(x,y+1) << endl;
        }
    }
}


Measured memory_bytes: 4976
#/*
    AUTHOR:shivam51
    IIESTS
*/
  #include<bits/stdc++.h>
  using namespace std;
  //
  #define add accumulate
  #define ll long long int
  #define ff first
  #define ss second
  #define pb push_back
  #define mp make_pair
  #define vll vector<ll>
  #define lb lower_bound
  #define ub upper_bound
  #define pll pair<ll,ll>
  #define vpll vector<pll>
  #define all(v) v.begin(), v.end()
  #define rep(i,k,n) for(int i=k;i<n;i++)
  #define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
  const int md=1e8;
  const int MAX=1e5+1;
  //
  //
  int main(){
  	ll n;
  	cin>>n;
  	cout<<(n-2)*180;
  	return 0;
  }

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

int num[101];
int main() {
  int N;
  cin >> N;
  for(int i=1; i<=N; i++) {
    cin >> num[i];
  }

  int sum = 0;
  int minj=1;
  for(int i=1; i<=N; i++) {
    minj = i;
    for(int j=i+1; j<=N; j++) {
      if(num[j]<num[minj]) {
        minj=j;
      }
    }
    swap(num[i], num[minj]);
    if(i!=minj) sum++;
  }


  cout << num[1];
  for(int i=2; i<=N; i++) {
    cout << " " << num[i];
  }
  cout << endl;
  cout << sum << endl;;
}



Measured memory_bytes: 3088
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

class Main {
	
	public static BigDecimal INTEREST_RATE = new BigDecimal("0.05");
	
	public static void main(String... args) {
		Scanner scanner = null;
		try {
			scanner = new Scanner(System.in);
			int n = scanner.nextInt();
			
			BigDecimal baseDebt = new BigDecimal(100000);
			BigDecimal debt = calc(baseDebt, n);
			System.out.println(debt.intValue());
		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
	
	public static BigDecimal calc(BigDecimal debt, int n) {
		if (n <= 0) {
			return debt;
		}
		BigDecimal interest = debt.multiply(INTEREST_RATE);
		BigDecimal afterDebt = debt.add(interest).setScale(-3, RoundingMode.UP);
		return calc(afterDebt, --n);
	}
}

Measured memory_bytes: 17280
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    int a,b,c,x; std::cin>>a>>b>>c>>x;

    int ans=0;
    for(int i=0; i<=a; i++){
        for(int j=0; j<=b; j++){
            for(int k=0; k<=c; k++){
                if(500*i+100*j+50*k==x) ans++;
            }
        }
    }
    std::cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256