akhauriyash/Code-Regression huggingface dataset:
package main

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

// 最大積載量がpの時、k台のトラックで何個詰めるかを返します
func check(n int, k int, ws []int, p int64) int {
	i := 0
	for j := 0; j < k; j++ {
		s := 0
		for int64(s+ws[i]) <= p {
			s = s + ws[i]
			i++
			if i == n {
				return n
			}
		}
	}
	return i
}

func resolve(n int, k int, ws []int) int64 {
	var left int64
	left = 0
	var right int64
	right = 10000 * 100000
	var mid int64
	for (right - left) > 1 {
		mid = int64((right + left) / 2)
		v := check(n, k, ws, mid)
		if v >= n {
			// 積載量midで十分に詰める
			right = mid
		} else {
			// 積載量midでは足りない
			left = mid
		}
	}
	return right
}

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	k := nextInt(sc)
	var ws []int
	for i := 0; i < n; i++ {
		ws = append(ws, nextInt(sc))
	}
	p := resolve(n, k, ws)
	fmt.Println(p)
}



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

int n;
int q, k;

struct LowestCommonAncestor {
  const int MAX_LOG_V = 50;

  int V, root = 0;
  vector<vector<pair<int, long long>>> G;
  vector<long long> depth, length;
  vector<vector<int> > parent;

  LowestCommonAncestor() {}
  LowestCommonAncestor(int V) : V(V) { init(); }
  LowestCommonAncestor(int V, int root) : V(V), root(root) { init(); }

  void init() {
    G.resize(V);
    depth.resize(V);
    length.resize(V);
    parent.resize(MAX_LOG_V, vector<int>(V));
  }

  void add_edge(int u, int v, long long c) {
    G[u].push_back(make_pair(v, c));
    G[v].push_back(make_pair(u, c));
  }

  void add_edge(int u, int v) {
    add_edge(u, v, 1ll);
  }

  void dfs(int v, int u, int d, long long l){
    depth[v] = d;
    length[v] = l;
    parent[0][v] = u;
    for (int i = 0; i < G[v].size(); ++i) {
      pair<int, long long> p = G[v][i];
      if (p.first != u) {
        dfs(p.first, v, d + 1, l + p.second);
      }
    }
  }

  void build() {
    dfs(root, -1, 0, 0ll);
    for (int k = 0; k + 1 < MAX_LOG_V; k++) {
      for (int v = 0; v < V; v++) {
        if (parent[k][v] < 0) parent[k + 1][v] = -1;
        else parent[k + 1][v] = parent[k][parent[k][v]];
      }
    }
  }

  int lca(int u, int v) {
    if (depth[u] > depth[v]) swap(u, v);
    for (int k = 0; k < MAX_LOG_V; k++) {
      if ((depth[v] - depth[u]) >> k & 1) {
        v = parent[k][v];
      }
    }

    if (u == v) return u;

    for (int k = MAX_LOG_V - 1; k >= 0; k--) {
      if (parent[k][u] != parent[k][v]) {
        u = parent[k][u];
        v = parent[k][v];
      }
    }

    return parent[0][u];
  }

  long long dist(int u, int v) {
    int z = lca(u, v);
    return length[u] + length[v] - 2 * length[z];
  }
};

signed main() {
  cin >> n;

  LowestCommonAncestor LCA(n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v, c;
    cin >> u >> v >> c;
    u--; v--;

    LCA.add_edge(u, v, c);
  }

  LCA.build();

  cin >> q >> k;
  while (q--) {
    int x, y;
    cin >> x >> y;

    cout << LCA.dist(x - 1, k - 1) + LCA.dist(k - 1, y - 1) << endl;;
  }
}


Measured memory_bytes: 34040
def divisible(n):
    ans = 0
    while n % 2 == 0:
        n /= 2
        ans +=1
    return ans
# 整数の入力
N = int(input())
# スペース区切りの整数の入力 リスト
A = list(map(int, input().split()))

ans = min(map(divisible,A))
print(ans)


Measured memory_bytes: 2940
N = int(input())
data = list(map(int,input().split()))
res = 0
exist_odd = False
while exist_odd == False:
    for i in range(N):
        if data[i]%2 == 1:
            exist_odd = True
    
    if exist_odd == True:
            break
        
    for i in range(N):
        data[i] = data[i]//2
    
    res += 1
    
print(res)

Measured memory_bytes: 3060
An = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(An[int(input())-1])


Measured memory_bytes: 38408
# -*- coding: utf-8 -*-
from itertools import permutations
def inpl(): return tuple(map(int, input().split()))
 
INF = float("inf")
 
N, M, _ = inpl()
R = inpl()
G = [[INF]*(N+1) for _ in range(N+1)]

for _ in range(M):
    s, t, d = inpl()
    G[s][t] = d
    G[t][s] = d

for v in range(N):
    G[v][v] = 0 

def WarshallFloyd(G):
    V = len(G)
    for k in range(V):
        for i in range(V):
            if G[i][k] == INF:
                continue
            for j in range(V):
                G[i][j] = min(G[i][j], G[i][k] + G[k][j])
    return G

G = WarshallFloyd(G)

res = INF
for r in permutations(R, len(R)):
    tmp = 0
    for i in range(len(R)-1):
        tmp += G[r[i]][r[i+1]]
    res = min(res, tmp)
 
print(res)

Measured memory_bytes: 58200
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

const int MOD = 1000000007;

using namespace std;

int main(){

    int i,j,d,n,u=1,y,z,count=0;
    cin >> n >> d;
    double x[n][d];
    double v=0.0;

    for(i=0;i<n;i++){
        for(j=0;j<d;j++){
            cin >> x[i][j];
        }
    }

    for(i=0;i<n-1;i++){
        while(u<n){
            for(j=0;j<d;j++){
                v += (x[i][j]-x[u][j])*(x[i][j]-x[u][j]);
            }
            if(ceil(sqrt(v)) == floor(sqrt(v))){
                count++;
            }
            v=0;
            u++;
        }
        u=i+2;
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
import sys


# \n
def input():
    return sys.stdin.readline().rstrip()


def main():
    N, T = map(int, input().split())
    dp = [0] * (T + 1)
    AB = []
    for k in range(N):
        a, b = map(int, input().split())
        AB.append((a, b))

    AB.sort()
    maxdp = 0
    temp =0
    for i in range(N):
        a, b = AB[i]  # a:time  b:value
        temp +=a
        dp[T] = max(maxdp + b, dp[T])
        for j in range(min(T - 1,temp+1), a - 1, -1):
            dp[j] = max(dp[j], dp[j - a] + b)
            maxdp = max(dp[j], maxdp)
    print(dp[T])


if __name__ == "__main__":
    main()


Measured memory_bytes: 73568
def getlist():
	return list(map(int, input().split()))

n = int(input())
a = getlist()
a = sorted(a)
x = a[-1]
xx = x / 2
y = 0
s = float("inf")
for i in range(n - 1):
	if abs(xx - a[i]) < s:
		s = abs(xx - a[i])
		y = a[i]

print(x, y)

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

using namespace std;

#define int long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0);

signed main () {
  cin.tie(0);
  cout << setprecision(10);

  string s; cin >> s;
  int count = 1;
  FOR(i, 1, s.size()) {
    if(s[i] != s[i-1]) count++;
  }
  cout << count-1 << endl;
}


Measured memory_bytes: 512
N, K = map(int, input().split())
X = list(map(int, input().split()))

a = 10**10
for left,x in enumerate(X):
  right = left + K - 1
  if right == N:
    break
  left_to_right = abs(X[left])+abs(X[right]-X[left])
  right_to_left = abs(X[right])+abs(X[right]-X[left])
  m = min(left_to_right, right_to_left)
  if a > m:
    a = m
    
print(a)
  


Measured memory_bytes: 14224
#include <stdio.h>
#include <string>
#include <stack>
#include <cstdlib>

int calc(int a, int b, std::string ope)
{
  int ans = 0;
  if (ope == "+") ans = a + b;
  else if (ope == "-") ans = a - b;
  else if (ope == "*") ans = a * b;
  return ans;
}

int main()
{
  char temp[10] = {0};
  std::string ope[3] = { "+", "-", "*" };
  std::stack<int> st;

  while (scanf("%s", temp) != EOF) {
    bool is_operator = false;
    std::string symbol(temp);
    for (int i = 0; i < 3; i++) {
      if (ope[i] == symbol) {
        int b = st.top();
        st.pop();
        int a = st.top();
        st.pop();
        st.push(calc(a, b, ope[i]));
        is_operator = true;
        break;
      }
    }
    if (is_operator) continue;
    st.push(std::atoi(symbol.c_str()));
  }

  printf("%d\n", st.top());

  return 0;
}



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


int main(){
	int h,w;
	string s;
	cin >> h >> w;
	for(int i=1;i<=h;i++){
		for(int j=0;j<w;j++){
			cin >> s;
			if(s=="snuke"){
				cout << char('A'+j) << i << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc148/tasks/abc148_e

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

const ll INF = 1e18;

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

  if (N <= 2) drop(0);
  if (N % 2 == 1) drop(0);

  ll res = 0;

  ll div = 10;  // 5 * 2

  while (N / div > 0) {
    res += N / div;
    div *= 5;
  }

  cout << res << endl;
}

// while (N / div > 0) {
//   res += N / div;
//   div *= 10;
// }

// ll div50 = 50;
// while (N / div50 > 0) {
//   res += N / div50;
//   res -= N / (2 * div50);
//   div50 *= 10;
// }

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

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

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

  return 0;
}
#endif

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

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

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

    cout << v[i];
  }

  cout << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#define int long long
#define all(c) (c).begin(),(c).end()
#define pii pair<long long,long long>
#define endl '\n'

using namespace std;

signed main(){
    //std::ios::sync_with_stdio(false);
    //cout << numeric_limits<double>::digits12 << endl;
    double l;
    cin >> l;
    l=l/double(3);
    double ans=l*l*l;
    //cout << numeric_limits<double>::digits10 << endl;
    //cout << setprecision(12); 
    cout << fixed <<setprecision(12) <<  ans <<endl;
}

Measured memory_bytes: 256
let () =
  let n = Scanf.scanf " %d\n" (fun x -> x) in
  let rec read = function
      0 -> ()
    | i ->
       let (x,y) = Scanf.scanf " %d %d\n" (fun x y-> (x,y)) in
       let r = x mod y in
       Printf.printf "%d\n" (if r = 0 then y else r)
       ;read (i-1)
  in read n
;;

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a=0;
  cin>>n;
  vector<int> x(n),y(n);
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i];
  }
  for(int i=0;i<n;i++){
    a=a+y[i]-x[i]+1;
  }
  cout<<a<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long long n,i,j,k;
  map<long long, long long> key;
  for(i=1;i<=105;i++)
    for(j=1;j<=105;j++)
      for(k=1;k<=105;k++)
        key[i*i+j*j+k*k+i*j+j*k+k*i]++;
  cin>>n;
  for(i=1;i<=n;i++)
  {
  	cout<<key[i]<<'\n';
  }
  return 0;
}

Measured memory_bytes: 6308
#include <stdio.h>

int main()
{
     int a, b, c;

     scanf("%d %d", &a, &b);

     c = a + b;

     if(c >= 10)
     {
          printf("error\n");
     }
     else
     {
          printf("%d\n", c);
     }

     return 0;
}

Measured memory_bytes: 128
from itertools import accumulate
from bisect import bisect_right

n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A_accumulate = list(accumulate([0] + A))
B_accumulate = list(accumulate([0] + B))

ans = 0

for i in range(n+1):
    remain = k - A_accumulate[i]

    if remain < 0:
        continue

    j = bisect_right(B_accumulate, remain)

    ans = max(ans, i+j-1)

print(ans)

Measured memory_bytes: 49300
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
int lcm(int x, int y){
    return x / __gcd(x , y) * y ;
}
signed main(){
    fastio
    int x ;
    cin >> x ;
    cout << lcm(x, 360) / x << endl;
    return 0; 
}

Measured memory_bytes: 3608
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    for (m in 1 until 10000) {
        if (m * (m + 1) / 2 != n) continue
        println("Yes")
        println(m + 1)
        val ans = Array(m + 1) { mutableListOf(m) }
        var num = 1
        for (i in 0..m) {
            for (j in i + 1..m) {
                ans[i].add(num)
                ans[j].add(num)
                num++
            }
        }
        for (lst in ans) {
            println(lst.joinToString(" "))
        }
        return
    }
    println("No")
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 57448
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f,s;
	scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
	s=a*1+b*5+c*10+d*50+e*100+f*500;
		if(1000<=s){
			printf("1\n");
		}
		else{
			printf("0\n");
		}
	return 0;
}

Measured memory_bytes: 1012
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define mod 1005
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int ll;
ll powmod(ll a, ll b) {
    ll res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
int nxt() {
    int x;
    scanf("%d", &x);
    return x;
}

const int nax = 405;
const ll INF = 1e18L + 5;
ll dp[nax][nax];

int main() {
    int n = nxt();
    VI a(n);
    generate(all(a), nxt);
    auto sum = [&](int L, int R) {
        ll s = 0;
        for (int i = L; i <= R; i++) s += a[i];
        return s;
    };
    for (int L = n - 1; L >= 0; L--) {
        for (int R = L; R < n; R++) {
            if (L == R)
                dp[L][R] = 0;
            else {
                dp[L][R] = INF;
                ll s = sum(L, R);
                for (int i = L; i < R; i++) {
                    dp[L][R] = min(dp[L][R], s + dp[L][i] + dp[i + 1][R]);
                }
            }
        }
    }
    printf("%lld\n", dp[0][n - 1]);
    return 0;
}


Measured memory_bytes: 1536
#include<cstdio>
#include<algorithm>
using namespace std;

struct Node_tag{
	int key;
	Node_tag *parent, *left, *right;
};

typedef struct Node_tag Node;

Node *root;
Node *nil = (Node *)malloc(sizeof(Node));

void init(){
	nil->parent = nil->left = nil->right = nil;
	root = nil;
}


void inParse(Node *u){
	if(u == nil)
		return;
	inParse(u->left);
	printf(" %d", u->key);
	inParse(u->right);
}

void preParse(Node *u){
	if(u == nil)
		return;
	printf(" %d", u->key);
	preParse(u->left);
	preParse(u->right);
}

void insert(Node *z){
	Node *x = root, *y = nil;
	while(x != nil){
		y = x;
		if(z->key < x->key)
			x = x->left;
		else
			x = x->right;
	}
	z->parent = y;

    if (y == nil)
        root = z;
    else if(z->key < y->key)
        y->left = z;
    else
        y->right = z;
}

int main(void){
	int m, i, key;
	char S[10];
	init();
	scanf("%d", &m);
	for(i = 0;i < m;i++){
		scanf("%s", S);
		if(S[0] == 'i'){
			scanf("%d", &key);
			Node *z = (Node *)malloc(sizeof(Node));
			z->key = key;
			z->left = z->right = nil;
			insert(z);
		} else {
			inParse(root);
			printf("\n");
			preParse(root);
			printf("\n");
		}
	}
	return 0;
}

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

int main()
{
	string s;
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> s;

	int n = s.length();
	unsigned long long res = 0;
	char last = -1;
	int pos;
	for (int i = 1; i < n; i++)
	{
		if (s[i] < s[i - 1])
		{
			if (i > 1 && s[i - 1] == s[i - 2])
				s[pos++] = '0';
			else
				s[i-1] = '0';
			--i;

			int j = n - 1;
			while (++s[j] > '9')
				s[j--] = '0';

			++res;
		}
		else if (s[i] == s[i - 1] && s[i] != last)
		{
			last = s[i];
			pos = i - 1;
		}
		else if(s[i] > s[i - 1])
			last = -1;
	}

	if (s[n - 1] > '0')
		res++;

	cout << res;
	return 0;
}

Measured memory_bytes: 1172
import java.util.Scanner;

public class Main {
	static boolean[] isPrime;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long P = sc.nextLong();
		sc.close();
		if(N == 1) {
			System.out.println(P);
			System.exit(0);
		}
		long ans = 1;
		long t = (long)Math.pow(P, (double)1 / N) + 1;
		for(long k = 2; k <= t; k++) {
			long s = (long)Math.pow(k, N);
			if(P % s == 0) {
				ans = k;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n;
int pre[200005];

int main()
{
	scanf("%d", &n);
	for(int i=1;i<=n;i++) scanf("%d", &pre[i]);
	bool flag = true;
	pre[1]--;
	for(int i=2;i<=n;i++){
		if(pre[i] > pre[i-1]){
			pre[i]--;
		}
		if(pre[i] < pre[i-1] || pre[i-2] > pre[i-1]){
			flag = false;
			break;
		}
	}
	if(flag){
		puts("Yes");
	}
	else puts("No");
	return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
char a, b;
int main(void) {
    cin >> a >> b;
    (a != b ? cout << "D" << endl : cout << "H" << endl);
    return 0;
}

Measured memory_bytes: 3528
n,m = map(int, input().split())
pairs = []
for _ in range(n):
    l = list(map(int,input().split()))
    pairs.append(l)
pairs.sort()
count = 0
ans = 0
for i in pairs:
    ans += i[0]*i[1]
    count += i[1]
    if count >= m:
        ans -= i[0]*(count - m)
        break
print(ans)

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

int main()
{
    int64_t a, b, x;
    cin >> a >> b >> x;
    if (a == 0)
    {
        cout << b / x + 1 << endl;
    }
    else
    {
        cout << b / x - (a - 1) / x << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<cmath>
using namespace std;
#define int long long int
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define endl '\n'
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define inf 1e18
#define pf push_front
#define pob pop_back
#define pof pop_front
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);

typedef pair<int,int> pi;
typedef pair<int,pair<int,int>> piii;
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;

int32_t main()
{
   // boost
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        if(n<3)
        {
            cout<<"0"<<endl;
            continue;
        }
        if(n<6)
        {
            cout<<"1"<<endl;
            continue;
        }
        int dp[n+1]={0};
        dp[0]=dp[1]=dp[2]=0;
        dp[3]=dp[4]=dp[5]=1;
        dp[6]=2;

        for(int i=7;i<=n;i++)
        {
            dp[i]=1;
            for(int j=3;j<=i-3;j++)
            {
                dp[i]+=dp[j];
                dp[i]%=mod;
            }
        }

        cout<<dp[n]<<endl;
    }


    

}

Measured memory_bytes: 3604
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
flag = [[False for _ in range(3)] for _ in range(3)]
B = [int(input()) for _ in range(N)]

for b in B:
    for i, line in enumerate(A):
        for j, a in enumerate(line):
            if a == b:
                flag[i][j] = True

# yoko
for line in flag:
    if line[0] and line[1] and line[2]:
        print("Yes")
        exit()
for i in range(3):
    if flag[0][i] and flag[1][i] and flag[2][i]:
        print("Yes")
        exit()

if (flag[0][0] and flag[1][1] and flag[2][2]) or(flag[0][2] and flag[1][1] and flag[2][0]):
    print("Yes")
    exit()
print("No")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


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

    int odds=0, fob=0, eve=0;
    rep(i, N) {
        int a;
        cin >> a;
        if(a%2) odds++;
        else if(a%4==0) fob++;
        else eve++;
    }

    if(eve) {
        if(fob >= odds) cout << "Yes" << endl;
        else cout << "No" << endl;
    } else {
        if(fob >= odds-1) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define INF 1e9
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int dp[100001][13];
int main() {
    string s; cin >> s;
    int mod = 1000000007;
    dp[0][0] = 1;

    rep(i,s.size()) {
        rep(j,13) {
            if(s[i]=='?') {
                rep(b,10) {
                    dp[i+1][(10*j+b)%13] += dp[i][j];
                    dp[i+1][(10*j+b)%13] %= mod;
                }
            }
            else {
                dp[i+1][(10*j+(s[i]-'0'))%13] += dp[i][j];
                dp[i+1][(10*j+(s[i]-'0'))%13] %= mod;
            }
        }
    }
    cout << dp[s.size()][5] << endl;
    

    return 0;
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
#define ull unsigned long long int 
#define pb push_back
#define F first
#define S second
#define ll long long 
#define ld long double 

#define int long long int

const int mod = 1e9+7;
const ll inf = 1e18; 
 
int power(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int ncr(int n, int r){ int C[r+1]; memset(C, 0, sizeof(C)); C[0] = 1; for(int i = 1; i <= n; i++) {int t=i;if(r<t)t=r; for (int j = t; j > 0; j--) C[j] = C[j] + C[j-1]; }return C[r];} 
int gcd(int a,int b){if (a==0)return b;return gcd(b%a,a);}
int lcm(int a,int b){return (a/gcd(a,b)*b);}

int min(int a , int b){return a < b ? a : b;}
int max(int a , int b){return a > b ? a : b;}

using namespace std;


signed main(){

	 ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;
	int a[n][n];
	for(int i = 0 ; i < n ; i++)
		for(int j = 0 ; j < n ; j++)
			cin >> a[i][j];
			
	vector<int> dp(1<<n , 0);
	dp[0] = 1;
	
	for(int mask = 0 ; mask < (1<<n)-1 ; mask++){
		int men_married = __builtin_popcount(mask); // gives the number of set bits in mask
		for(int women = 0 ; women < n ; women++){
			if(a[men_married][women] && !(mask & (1 << women))){
				int temp = (mask|(1<<women));
				dp[temp] = (dp[temp] + dp[mask])%mod;
			}
		}
	}
	cout << dp[(1<<n)-1];
	
}










Measured memory_bytes: 19572
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <cassert>
 
typedef long long ll;
using namespace std;
 
#define mod 1000000007
#define INF 1000000000
#define LLINF 2000000000000000000LL
 
#define SIZE 200010
 
struct SW_ROOM{
    int x;
    int y;
    int num;
    
    SW_ROOM(int a=0,int b=0,int c=0)
    :x(a),y(b),num(c){}
};
 
bool comp_xy(SW_ROOM a,SW_ROOM b){
    return a.x==b.x ? a.y < b.y : a.x < b.x;
}
bool comp_yx(SW_ROOM a,SW_ROOM b){
    return a.y==b.y ? a.x < b.x : a.y < b.y;
}
 
//(1,1) -> (M,N)
 
int m,n,k,x,y;
vector<pair<int,int> > way[SIZE*2];
priority_queue<pair<ll,int> > pq;
bool visit[SIZE*2] = {0};
 
int main(){
    
    vector<SW_ROOM> sw;
    
    scanf("%d%d%d",&m,&n,&k);
    
    bool flag = false;
    
    for(int i=1;i<=k;i++){
        scanf("%d%d",&x,&y);
        if(x==1 && y==1){
            flag = true;
            continue;
        }
        if(x==m && y==n){
            continue;
        }
        
        sw.push_back(SW_ROOM(x,y,i));
        way[i*2].push_back({i*2+1,1}); //SN
        way[i*2+1].push_back({i*2,1}); //WE
    }
    
    sw.push_back(SW_ROOM(1,1,0));
    
    if(flag){
        way[0].push_back({1,1}); //SN
        way[1].push_back({0,1}); //WE
    }
    
    sw.push_back(SW_ROOM(m,n,k+1));
    
    
    sort(sw.begin(),sw.end(),comp_xy);
    
    for(int i=0;i<sw.size();i++){
        
        while(i<sw.size()-1 && sw[i].x == sw[i+1].x){
            int room1 = sw[i].num * 2;
            int room2 = sw[i+1].num * 2;
            int dis = sw[i+1].y - sw[i].y;
            
            way[room1].push_back({room2,dis}); //SN
            way[room2].push_back({room1,dis}); //WE
            
            i++;
        }
        
    }
    
    sort(sw.begin(),sw.end(),comp_yx);
    
    for(int i=0;i<sw.size();i++){
        
        while(i<sw.size()-1 && sw[i].y == sw[i+1].y){
            int room1 = sw[i].num * 2 +1;
            int room2 = sw[i+1].num * 2 +1;
            int dis = sw[i+1].x - sw[i].x;
            
            way[room1].push_back({room2,dis}); //SN
            way[room2].push_back({room1,dis}); //WE
            
            i++;
        }
    }
    
    //dijkstra
    
    
    
    pq.push({0,0});
    
    while(pq.size()){
        pair<ll,int> p = pq.top();
        pq.pop();
        
        int room = p.second;
        ll cost = p.first;
        
        if(visit[room]) continue;
        visit[room] = true;
        
        if(room == (k+1)*2 || room == (k+1)*2+1){
            printf("%lld\n",-cost);
            return 0;
        }
        
        for(int i=0;i<way[room].size();i++){
            pq.push({cost-way[room][i].second,way[room][i].first});
        }
        
    }
    
    puts("-1");
    
    return 0;
}

Measured memory_bytes: 38756
#include <cstdio>
#include <set>
#include <iterator>

int main() {
    std::multiset<int> ms;
    int d;
    for (int i = 0; i < 10; ++i) {
        scanf("%d", &d);
        ms.insert(d);
    }
    for (auto i = ms.rbegin(); i != std::next(ms.rbegin(), 3); ++i) {
        printf("%d\n", *i);
    }
}

Measured memory_bytes: 1016
from collections import Counter

mod = 1000000007
ng3 = ("AGC", "ACG", "GAC")
ng4 = ("AAGC", "ACGC", "AGGC", "ATGC", "AGAC", "AGCC", "AGGC", "AGTC")


def isok(s):
    if s[-3:] in ng3:
        return False
    if s[-4:] in ng4:
        return False
    return True


N = int(input())
dp = [Counter() for _ in range(N + 1)]
dp[0] = {"": 1}
for n in range(1, N + 1):
    for s, v in dp[n-1].items():
        for c in "ACGT":
            if isok(s + c):
                dp[n][s[-3:] + c] += v
print(sum(dp[N].values()) % mod)


Measured memory_bytes: 6736
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#define rep(i,a,b) for(int i=a;i<=b;i++)
typedef long long ll;
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=1e5+10;
void io(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
int c[N];
int main()
{
	io();
	int n,a;cin>>n;
	cin>>a;
	int s=a;
	for(int i=1;i<n;i++){
		cin>>a;
		s=__gcd(s,a);
	}
	cout<<s<<endl;
	return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    string s, t;
    cin >> s >> t;
    vector<int> pos;
    rep (i, s.size()) {
        if (s[i] == '?' || s[i] == t[0]) {
            bool check = true;
            rep (j, t.size()) {
                if (s[i + j] == '?' || s[i + j] == t[j]) continue;
                check = false;
            }
            if (check) {
                pos.push_back(i);
            } else {
                if (s[i] == '?') s[i] = 'a';
            }
        }
    }
    int p = -1;
    rep (i, pos.size()) p = max(p, pos[i]);
    if (p != -1) {
        int j = 0;
        rep (i, s.size()) {
            if (i >= p && i < p + t.size()) s[i] = t[j++];
            else if (s[i] == '?') s[i] = 'a';
        }
    }
    if (pos.size()) cout << s << endl;
    else cout << "UNRESTORABLE" << endl;
    
    return 0;
}



Measured memory_bytes: 256
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int n,a[100005];
ll s;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i)scanf("%d",a+i),s+=a[i];
    if(s%(n*(n+1ll)/2ll)){
        puts("NO");
        return 0;
    }
    s/=n*(n+1ll)/2ll;
    a[n+1]=a[1];
    for(int i=1;i<=n;++i){
        ll o=s-a[i+1]+a[i];
        if(o<0||o%n){
            puts("NO");
            return 0;
        }
    }
    puts("YES");
    //system("pause");
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int res=n%10;
    if(res==2||res==4||res==5||res==7||res==9){
        cout<<"hon"<<endl;
    }
    else if(res==0||res==1||res==6||res==8){
        cout<<"pon"<<endl;
    }
    else if(res==3){
        cout<<"bon"<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>

using namespace std;

int main(void) {
	string in;
	char tmp;
	int pos, count, dir, tmppos;

	while(true) {
		getline(cin, in);
		if(in == ".") { break; }
		pos = 0;
		count = 0;
		dir = 1;
		while(true) {
			if(dir == 1 && (in[pos] == '(' || in[pos] == '[')) {
				count++;
			} else if(dir == 1 && (in[pos] == ')' || in[pos] == ']')) {
				tmp = in[pos];
				tmppos = pos;
				dir = -1;
			} else if(dir == -1 && ((in[pos] == '(' && tmp == ')') || (in[pos] == '[' && tmp == ']'))) {
				count--;
				in[pos] = '*';
				in[tmppos] = '*';
				dir = 1;
			} else if(dir == -1 && ((in[pos] == '(' && tmp == ']') || (in[pos] == '[' && tmp == ')'))) {
				break;
			}
			pos += 1*dir;
			if(pos < 0) { count++; break; }
			if((int)in.length() < pos) { break; }
		}
		if(count == 0) { cout << "yes" << endl; }
		else { cout << "no" << endl; }
	}

	return 0;
}

Measured memory_bytes: 900
/*
?¨???????
???????????´??° a, b ??¨?????????????????? op ?????????????????§???a op b ????¨??????????????????°?????????????????????????????????
????????????????????? op ??????"+"(???)???"-"(???)???"*"(???)???"/"(???)???????????¨?????????????????§????????????????????´?????????
?°???°?????\??????????????¨????????????????¨????????????¨????????????

Input
??\???????????°????????????????????????????§???????????????????????????????????????????????????¢????????\????????¨????????§??????

a op b

op ??? '?' ?????¨??? ??\?????????????????????????????????????????±???????????????????????£????????????????????????

Output
?????????????????????????????????????¨??????????????????????????????????????????????

Constraints
0 ??? a, b ??? 20000
0 ?????????????????????????????????????????¨?????????????????????

*/

#include <iostream>
#include <string>
int main() {
	int a, b;
	std::string op;
	while (1) {
		std::cin >> a >> op >> b;
		//std::cout << a << op << b << std::endl;

		if (op == "+") std::cout << a + b << std::endl;
		else if (op == "-") std::cout << a - b << std::endl;
		else if (op == "*") std::cout << a * b << std::endl;
		else if (op == "/") std::cout << (int)(a / b) << std::endl;
		else { return 0; }
	}
}

Measured memory_bytes: 3148
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    var t = (1..3).map { sc.nextInt() }.sorted()
    val set = HashSet<String>()
    var ans = 0
    while (true) {
        if (t[0] % 2 != 0 || t[1] % 2 != 0 || t[2] % 2 != 0) {
            println(ans)
            return
        }
        if (set.contains(t.joinToString(","))) {
            println(-1)
            return
        }
        set.add(t.joinToString(","))
        val next = listOf(t[0] / 2 + t[1] / 2, t[0] / 2 + t[2] / 2, t[1] / 2 + t[2] / 2).sorted()
        t = next
        ans++
    }
}

Measured memory_bytes: 35916
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> x(N);
  for (int i = 0; i < N; i++){
    cin >> x[i];
    if (x[i] - i > N * (N - 1) + 1 || x[i] < i){
      cout << "No" << endl;
      return 0;
    }
  }
  priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> pq;
  for (int i = 0; i < N; i++){
    if (i > 0){
      pq.push(make_tuple(x[i] - 1, i, i + 1));
    }
  }
  /*
  priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> pq2 = pq;
  while (!pq2.empty()){
    int pos, cnt, num;
    tie(pos, cnt, num) = pq2.top();
    pq2.pop();
    cout << "pos = " << pos << ", cnt = " << cnt << ", num = " << num << endl;
  }
  */
  vector<int> ans(N * N, 0);
  for (int i = 0; i < N; i++){
    ans[x[i] - 1] = i + 1;
  }
  bool ok = true;
  vector<int> c(N, 0);
  vector<bool> done(N, false);
  for (int i = 0; i < N * N; i++){
    if (ans[i] != 0){
      c[ans[i] - 1]++;
      done[ans[i] - 1] = true;
      continue;
    }
    if (!pq.empty()){
      int pos, cnt, num;
      tie(pos, cnt, num) = pq.top();
      pq.pop();
      //cout << "pos = " << pos << ", cnt = " << cnt << ", num = " << num << endl;
      if (i > pos){
        ok = false;
        break;
      }
      ans[i] = num;
      c[num - 1]++;
      if (cnt > 1){
        pq.push(make_tuple(pos, cnt - 1, num));
      }
    } else {
      bool exist = false;
      for (int j = 0; j < N; j++){
        if (done[j] && c[j] < N){
          ans[i] = j + 1;
          c[j]++;
          exist = true;
          break;
        }
      }
      if (!exist){
        ok = false;
        break;
      }
    }
  }
  if (ok){
    cout << "Yes" << endl;
    for (int i = 0; i < N * N; i++){
      cout << ans[i];
      if (i < N * N - 1){
        cout << ' ';
      }
    }
    cout << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 2176
import java.util.*;
 
class Main{
 
    void solve(){
        Scanner sc = new Scanner(System.in);
 
        double INF = Double.MAX_VALUE;
 
        while(true){
            int n = sc.nextInt();
            if(n==0) break;
 
            int[] a = new int[n+1];
            for(int i=1; i<=n; i++) a[i] = sc.nextInt();
            double b = sc.nextDouble();
            int r = sc.nextInt();
            double v = sc.nextDouble(), e = sc.nextDouble(), f = sc.nextDouble();
 
            double[][] times = new double[n+1][n+1];
            for(int i=0; i<=n; i++){
                for(int j=0; j<=n; j++){
                    double time = 0.0;
                    for(int k=0; k+a[i]<a[j]; k++){
                        if(k>=r) time += 1.0/(v - e * (k-r));
                        else time += 1.0/(v - f * (r-k));
                    }
                    times[i][j] = time;
                }
            }
 
            double[][] dp = new double[n+1][n+1];
            for(int i=0; i<=n; i++) Arrays.fill(dp[i], INF);
 
            for(int i=0; i<=n; i++){
                dp[0][i] = times[0][i];
                if(i!=n) dp[1][i] = dp[0][i] + b;
                else dp[1][i] = dp[0][i];
                dp[1][n] = Math.min(dp[1][n], dp[1][i] + times[i][n]);
            }
 
            for(int i=2; i<=n; i++){
                for(int j=0; j<n; j++){
                    dp[i][j] = Math.min(dp[i][j], dp[i-1][j]);
                    for(int l=0; l<=j; l++){
                        if(dp[i-1][l]==INF) continue;
                        dp[i][j] = Math.min(dp[i][j], dp[i-1][l] + times[l][j] + b);
                        dp[i][n] = Math.min(dp[i][n], dp[i-1][n]);
                        dp[i][n] = Math.min(dp[i][n], dp[i][j] + times[j][n]);
                    }
                }
            }
 
            System.out.printf("%.4f\n",dp[n][n]);
        }
    }
 
    public static void main(String[] args){
        new Main().solve();
    }
} 

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

int main(){
    int H, W;

    while(1){

        cin >> H >> W;

        if (H == 0 && W ==0) break;
        else{
            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;
        }
    }

}



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


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Set<Integer> set = new HashSet<Integer>();
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            if (set.contains(a)) {
                set.remove(a);
            } else {
                set.add(a);
            }
        }
        System.out.println(set.size());
    }
}


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

using namespace std;


#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define REP(i,a) FOR(i,0,a)
#define ROF(i,a,b) for(int i = (b)-1; i >=(a); i--)
#define RREP(i,a) ROF(i,0,a)
#define MOD 1000000007
#define pb push_back
#define um unordered_map
#define us unordered_set
#define rs resize
#define LSB(x) ((x)&(-x))
typedef long long ll;
typedef vector<int> vi; typedef vector<vi> vvi;
typedef vector<bool> vb; typedef vector<vb> vvb;
typedef vector<ll> vll; typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef priority_queue<pii, vector<pii>, greater<pii>> djki;
typedef priority_queue<pll, vector<pll>, greater<pll>> djkll;
typedef unordered_map<int, int> umii;
typedef unordered_map<ll, ll> umll;
typedef unordered_set<int> usi;
typedef unordered_set<ll> usll;

vvi pts;
vvi dp;

int solve(int d, int curr) {
    if(d == 1) return dp[d][curr] = pts[1][curr];
    else if(dp[d][min(curr, 2)] != -1) return dp[d][min(curr, 2)];
    else {
        int best = 0;
        for(int i = 0; i < 3; i++) {
            if(i != curr) best = max(best, pts[d][min(curr, 2)] + solve(d - 1, i));
        }
        return dp[d][min(2, curr)] = best;
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    pts.resize(n + 2, vi(3, 0));
    dp.resize(n + 2, vi(3, -1));
    REP(i, n) {
        cin >> pts[i + 1][0] >> pts[i + 1][1] >> pts[i + 1][2];
    }
    solve(n + 1, 3);
    cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
    return 0;
}

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

int main() {
    ll H, W;
    cin >> H >> W;

    ll ans;
    if (H == 1 || W == 1) ans = 1;
    else if ((H * W) % 2 == 0 ) ans = H * W / 2;
    else ans = H * (W / 2) + (H - 1) / 2 + 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def gcd(a, b):
    if b==0:
        return a
    else:
        return gcd(b, a % b)

N, X = map(int, input().split())
x = list(map(int, input().split()))

dx = [abs(X - v) for v in x]
ans = dx[0]
for b in dx[1:]:
    ans = gcd(ans, b)
print(ans)


Measured memory_bytes: 14252
import os
import sys

import numpy as np


def solve(inp):
    r, c, k = inp[:3]
    items = np.zeros((r + 1, c + 1), dtype=np.int64)
    rrr = inp[3::3]
    ccc = inp[4::3]
    vvv = inp[5::3]
    for r_, c_, v in zip(rrr, ccc, vvv):
        items[r_, c_] = v

    dp = np.zeros((r + 1, c + 1, 4), dtype=np.int64)

    for i in range(1, r + 1):
        for j in range(1, c + 1):
            for w in range(4):
                dp[i, j, w] = max(dp[i, j - 1, w], dp[i - 1, j, 3])
            if items[i, j] > 0:
                for w in range(2, -1, -1):
                    dp[i, j, w + 1] = max(dp[i, j, w + 1], dp[i, j, w] + items[i, j])

    return dp[-1, -1, -1]


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()
    exit()

if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(i8[:],)', cache=True)(solve)
    print('compiled', file=sys.stderr)

inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print(ans)


Measured memory_bytes: 386284
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <list>
#include <deque>

using namespace std;

int main(){
    int n;
    string s;
    cin >> n >> s;
    int co=0;
    for(int i=0;i<n;i++){
        if(s[i]=='E'){
            co++;
        }
    }
    int ans=co;
    for(int i=0;i<n;i++){
        if(s[i]=='W'){
            co++;
        }
        else{
            co--;
        }
        ans=min(ans,co);
    }
    cout << ans << endl;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
 
 
int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	 long double t,k,z;
	cin>>t>>k>>z;
    if(2*sqrt(t)*sqrt(k)+t+k<z)
      cout<<"Yes"<<endl;
    else 
    cout<<"No"<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int[] a = new int[100];
		
		int n = sc.nextInt();
		
		for(int i = 0; i < n; i++)
			a[i] = sc.nextInt();
		
		for(int i = 0; i < n; i++){
			System.out.print(a[n - 1 - i]);
			
			if(i < n - 1)
				System.out.print(" ");
			else
				System.out.println("");
		}
	}
}

Measured memory_bytes: 26112