akhauriyash/Code-Regression huggingface dataset:
from sys import exit, setrecursionlimit, stderr, stdin
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect
import functools

def input():
  return stdin.readline().strip()

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

MM = 2 * 10**5
MOD = 10**9 + 7

fact = [1] * MM
for i in range(1, MM): fact[i] = (fact[i-1] * i) % MOD
invfact = [0] * MM; invfact[-1] = pow(fact[-1], MOD-2, MOD)
for i in range(MM-2, -1, -1): invfact[i] = invfact[i+1] * (i+1) % MOD

def comb(n, k):
  return fact[n] * invfact[n-k] * invfact[k] % MOD if 0 <= k <= n else 0

def inv(n):
  return pow(n, MOD-2, MOD)

N, A, B, C = reads()

invh = inv(100)

pA = A * inv(A + B) % MOD
pB = B * inv(A + B) % MOD

powpA = [1] * (N+1)
for i in range(1, N+1):
  powpA[i] = (powpA[i-1] * pA) % MOD

powpB = [1] * (N+1)
for i in range(1, N+1):
  powpB[i] = (powpB[i-1] * pB) % MOD

expc = 100 * inv(A + B) % MOD

expect = 0
for i in range(N):
  cb = comb(N-1  + i, i)
  expect += (N + i) * expc % MOD * cb % MOD * powpA[N] * powpB[i] % MOD
  expect %= MOD
  expect += (N + i) * expc % MOD * cb % MOD * powpA[i] * powpB[N] % MOD
  expect %= MOD

print(expect)

Measured memory_bytes: 47212
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
typedef long long ll;

using namespace std;

int main() {
  while(true) {
    int h, w;
    cin >> h >> w;

    if (h == 0 && w == 0) break;

    REP(i, h) {
      REP(j, w) {
        if (i == 0 || i == h-1 || j == 0 || j == w-1) {
          cout << "#";
        } else {
          cout << ".";
        }
      }
      cout << "\n";
    }
    cout << "\n";
  }
}


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

using graph = vector<vector<int>>;

int dfs(graph& g, vector<bool>& visited, vector<vector<int>>& cap, int v, int t) {
    if(v == t) {
        return 1;
    }
    visited[v] = true;
    for(auto to : g[v]) {
        if(visited[to] || cap[v][to] == 0) {
            continue;
        }
        if(dfs(g, visited, cap, to, t) == 1) {
            cap[to][v]++;
            cap[v][to]--;
            return 1;
        }
    }
    return 0;
}

int max_flow(graph& g, vector<vector<int>>& cap, int s, int t, int cnt = 100000) {
    vector<bool> visited(g.size());
    int f = 0;
    while(cnt--) {
        fill(visited.begin(), visited.end(), false);
        if(dfs(g, visited, cap, s, t) == 1) {
            f++;
        } else {
            break;
        }
    }
    return f;
}

int main() {
    int N, E, Q;
    cin >> N >> E >> Q;
    graph g(N);
    vector<vector<int>> cap(N, vector<int>(N));
    auto add_edge = [&](int from, int to) {
        g[from].push_back(to);
        g[to].push_back(from);
        cap[from][to] = cap[to][from] = 1;
    };
    for(int i = 0; i < E; ++i) {
        int f, t;
        cin >> f >> t;
        f--; t--;
        add_edge(f, t);
    }

    int res = max_flow(g, cap, 0, N - 1);
    while(Q--) {
        int m, a, b;
        cin >> m >> a >> b;
        a--; b--;
        if(m == 1) {
            add_edge(a, b);
        } else {
            // used b -> a
            if(cap[a][b] == 2) {
                // doesn't exist circuit b -> a on residual graph
                if(max_flow(g, cap, b, a, 1) == 0) {
                    max_flow(g, cap, N - 1, 0, 1);
                    max_flow(g, cap, b, a, 1);
                    res--;
                }
            } else if(cap[b][a] == 2) {
                if(max_flow(g, cap, a, b, 1) == 0) {
                    max_flow(g, cap, N - 1, 0, 1);
                    max_flow(g, cap, a, b, 1);
                    res--;
                }
            }

            cap[a][b] = cap[b][a] = 0;
            g[a].erase(find(g[a].begin(), g[a].end(), b));
            g[b].erase(find(g[b].begin(), g[b].end(), a));
        }

        res += max_flow(g, cap, 0, N - 1);
        cout << res << endl;
    }
}


Measured memory_bytes: 4212
def main(n: int, l: list):
    ans = 0

    l.sort(reverse=True)

    for _ in range(n):
        a, b = l.pop(), l.pop()
        ans += a

    print(ans)


if __name__ == "__main__":
    n = int(input())
    l = list(map(int, input().split()))

    main(n, l)


Measured memory_bytes: 2940
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>

long long GCD(long long n, long long m){
  long long maxval = std::max(n, m);
  long long minval = std::min(n, m);
  if (maxval%minval==0){
    return minval;
  } else {
    return GCD(minval, maxval%minval);
  }
}

int main(){
  int N, K;
  scanf("%d", &N);
  scanf("%d", &K);
  std::vector<long long > A(N);
  long long max = -1;
  for (int i=0; i<N; i++){
    scanf("%lld", &A[i]);
    max = std::max(max, A[i]);
  }
  
  long long gcd = A[0];
  for (int i=1; i<N; i++){
    gcd = GCD(gcd, A[i]);
  }
  //printf("max=%lld, gcd=%lld\n", max, gcd);
  if (K>max || K%gcd!=0){
    printf("IMPOSSIBLE\n");
  } else {
    printf("POSSIBLE\n");
  }
  return 0;
}


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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;



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

    vii award(m);
    for(int i=0; i<n; i++){
        if(a[i] > m) continue;
        award[m-a[i]].push_back(b[i]);
    }
    priority_queue<int, vi, less<int>> pque;
    ll ans=0;
    for(int i=m-1; i>=0; i--){
        for(auto x: award[i]) pque.push(x);
        if(pque.empty()) continue;
        ans+=pque.top();
        pque.pop();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9236
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define all(x) x.begin(),x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for(int x=0; x<n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;

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

int n, k, d, t, arr[110], ans;

int main() {
	cin >> n >> k;
	for (int i = 0; i < k; i++) {
		cin >> d;
		FOR(j, d) {
			cin >> t;
			arr[t] = 1;
		}
	}
	for (int i = 1; i <= n; i++) {
		if (arr[i] == 0) ans++;
	}
	cout << ans;
}

Measured memory_bytes: 3496
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
#define vcin(a)                          \
    for (int i = 0; i < (a).size(); i++) \
        cin >> (a)[i];

int main()
{
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    rep(y, H)
    {
        rep(x, W)
        {
            if ((x < A and y < B) or (x >= A and y >= B))
                cout << 0;
            else
                cout << 1;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
import * as fs from "fs"

const NUMBER_MAX = Math.floor(Number.MAX_SAFE_INTEGER / 2)
const NUMBER_MIN = Math.ceil(Number.MIN_SAFE_INTEGER / 2)

// ############################################################ //

const process = (n: number, h: number[]): string => {
  let now = NUMBER_MIN

  for (let i = 0; i < n; i++) {
    if (now === h[i]) {
      now = h[i]
      continue
    }
    if (now < h[i]) {
      now = h[i] - 1
      continue
    }
    return "No"
  }
  return "Yes"
}

const Main = (input: string): string => {
  const aa: string[][] = input.split("\n").map((e) => e.split(" "))
  const na0: number[] = aa[0].map((e) => parseInt(e))
  const na1: number[] = aa[1].map((e) => parseInt(e))
  const res = process(na0[0], na1) + ""
  console.log(res)
  return res
}
Main(fs.readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 17804
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int a[200005];
LL sum[200005];
map<LL, int> dp;
int main(){
	int n;
	scanf("%d", &n);
	for(int i=1;i<=n;i++) scanf("%d", &a[i]), sum[i] = sum[i-1] + a[i];
	dp[0] = 1;
	LL ans = 0;
	for(int i=1;i<=n;i++){
		ans += dp[sum[i]];
		dp[sum[i]]++;
	}
	printf("%lld\n", ans);
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;

int main() {
        ios_base::sync_with_stdio( false );
        cin.tie( nullptr );
        int S, W;
        cin >> S >> W;
        if ( W >= S ) {
                cout << "unsafe\n";
        } else {
                cout << "safe\n";
        }
        return 0;
}


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

int main(){
  int R,C,K;
  cin>>R>>C>>K;
  vector<vector<int64_t>> p(R,vector<int64_t>(C));
  for(int i=0;i<K;i++){
    int a,b;
    int64_t c;
    cin>>a>>b>>c;
    a--,b--;
    p[a][b]=c;
  }
  vector<vector<vector<int64_t>>> dp(R,vector<vector<int64_t>>(C,vector<int64_t>(4)));
  dp[0][0][1]=p[0][0];
  for(int a=0;a<R+C-2;a++){
    for(int b=max(0,a-R+1);b<min(C,a+1);b++){
      int i=a-b,j=b;
      for(int k=0;k<4;k++){
        if(j+1<C){
          dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k]);
          if(k<3){
            dp[i][j+1][k+1]=max(dp[i][j+1][k+1],dp[i][j][k]+p[i][j+1]);
          }
        }
        if(i+1<R){
          dp[i+1][j][1]=max(dp[i+1][j][1],dp[i][j][k]+p[i+1][j]);
          dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k]);
        }
      }
    }
  }
  int64_t Z=0;
  for(int k=0;k<4;k++){
    Z=max(Z,dp[R-1][C-1][k]);
  }
  cout<<Z<<endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  for(int i=0; i<n; i++)
    cin >> l.at(i);
  
  sort(l.begin(), l.end());
  
  int sum = 0;
  
  for(int i=0; i<n-1; i++)
    sum += l.at(i);
  
  if(sum > l.at(n-1))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

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

    int q;
    cin >> q;
    vector<int> A(n, 0);
    while(q--){
        int t, x, d;
        cin >> t >> x >> d;
        x--;
        if(t == 1){
            A[x] += d;
            if(A[x] > C[x]){
                cout << x + 1 << endl;
                return 0;
            }
        }else{
            A[x] -= d;
            if(A[x] < 0){
                cout << x + 1 << endl;
                return 0;
            }
        }
    }

    cout << 0 << endl;

    return 0;
}


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

int solve_number(
  vector<bool> comp, vector<int> p, vector<int> c, int g){
  
  int point = 0;
  int num   = 0;
  
  for(int i=0; i<p.size(); i++){
    if(comp.at(i)){
      point += 100*(i+1)*p.at(i) + c.at(i);
      num   += p.at(i);
    }
  }
  
  if(point>g)return num;
  
  for(int i=p.size()-1; i>=0; i--){
    if(comp.at(i))continue;
    if(p.at(i)==0)continue;
    
    if(point + 100*(i+1)*(p.at(i)-1) >=g){
      num += (g- point + 100*(i+1) - 1)/(100*(i+1));
      return num;
    }else{
      point += 100*(i+1)*(p.at(i)-1);
      num   += p.at(i)-1;
    }
  }
  
  return 1000;
}

void combi(
  vector<bool> comp,
  vector<int> &p, vector<int> c, int d, int g, int &nmin){
  
  if(d==0){
    nmin = min( nmin, solve_number(comp, p, c, g));
    return;
  }
  
  combi(comp, p, c, d-1, g, nmin);
  
  comp.at(d-1) = true;
  combi(comp, p, c, d-1, g, nmin);
  comp.at(d-1) = false;
  
  return;
}

int main(){
  
  int d,g;
  cin >> d >> g;
  
  vector<int> p(d), c(d);
  
  for(int i=0; i<d ; i++){
    cin >> p.at(i) >> c.at(i);
  }
  
  //コンプリートボーナスを取る点の組み合わせを決める
  //コンプ取らない問題はGに達しない限り上からp_i - 1問解く
  
  vector<bool> comp(d, false);
  int nmin=1000;
  
  combi(comp, p, c, d, g, nmin);
  cout << nmin << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb emplace_back
#define inf (int)1e9
#define ff first
#define ss second
#define ll long long
#define sp(n) cout << setprecision(n) << fixed
#define hellcat ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define give(x) cout << #x << " " << x << endl
#define debug cout << "dddd" << '\n'
#define debarr(a, n) for (int i = 0; i < n; ++i) cout << a[i] << ' '; cout << endl
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

template <class S, class T>
inline S smax(S &l, T r) {
  return l = max(l, (S)r);
}
template <class S, class T>
inline bool smin(S &l, T r) {
  return l = min(l, (S)r);
}

int32_t main () {
  hellcat;

	int k, a, b;
	cin >> k >> a >> b;

	bool is = false;
	for (int i = a; i <= b; ++i) {
		if (k > i)
			continue;
		if (i % k == 0) {
			is = true;
			break;
		}
	}

	cout << ((is) ? "OK\n" : "NG\n");

	return 0;
}


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

template<typename T> struct WG{
  using P = pair<int, T>;
  using Q = pair<T, int>;
  int n, k;
  vector<vector<P>> graph;
  vector<T> ans;
  WG(int n_, int k_){
    n = n_, k = k_;
    graph.resize(n); ans.resize(n, 2000000000000000000);
  }
  void add_edge1(int from, int to, T cost){
    P edge;
    edge.first = to; edge.second = cost;
    graph[from].push_back(edge);
  }
  void add_edge2(int from, int to, T cost){
    P edge1, edge2;
    edge1.first = to; edge1.second = cost;
    edge2.first = from; edge2.second = cost;
    graph[from].push_back(edge1);
    graph[to].push_back(edge2);
  }
  void dijkstra(int start){
    int a = n / 4;
    ans[start] = 0; Q s; s.first = 0; s.second = start;
    priority_queue<Q, vector<Q>, greater<Q>> pque;
    pque.push(s);
    vector<bool> seen(n, 0);
    while(!pque.empty()){
      Q tmp = pque.top(); pque.pop();
      int x = tmp.second;
      seen[x] = 1;
      for(auto edge: graph[x]){
        if(seen[edge.first]) continue;
        if(edge.first % a == x % a) edge.second = (k - ans[x] % k) % k;
        if(ans[edge.first] > ans[x] + edge.second){
          ans[edge.first] = ans[x] + edge.second;
          Q next; next.first = ans[edge.first]; next.second = edge.first;
          pque.push(next);
        }
      }
    }
  }
};

int main(){
  int h, w, k, sx, sy, gx, gy, a, a2, a3, b, c; cin >> h >> w >> k >> sx >> sy >> gx >> gy; --sx; --sy; --gx; --gy;
  a = h*w; a2 = a*2; a3 = a*3; b = sx*w+sy; c = gx*w+gy; WG<long> g(4*a, k);
  vector<string> v(h); rep(i, h) cin >> v[i];
  rep(i, h){
    rep(j, w){
      if(v[i][j] == '@') continue;
      int tmp = i*w+j;
      if(j < w-1 && v[i][j+1] == '.'){
        g.add_edge1(tmp, tmp+1, 1);
        g.add_edge1(a2+tmp+1, a2+tmp, 1);
      }
      if(j > 0 && v[i][j-1] == '.'){
        g.add_edge1(tmp-1, tmp, 1);
        g.add_edge1(a2+tmp, a2+tmp-1, 1);
      }
      if(i < h-1 && v[i+1][j] == '.'){
        g.add_edge1(tmp+a, tmp+a+w, 1);
        g.add_edge1(a3+tmp+w, a3+tmp, 1);
      }
      if(i > 0 && v[i-1][j] == '.'){
        g.add_edge1(tmp+a-w, tmp+a, 1);
        g.add_edge1(a3+tmp, a3+tmp-w, 1);
      }
      g.add_edge2(tmp, tmp+a, 0);
      g.add_edge2(tmp, tmp+a2, 0);
      g.add_edge2(tmp, tmp+a3, 0);
      g.add_edge2(tmp+a, tmp+a2, 0);
      g.add_edge2(tmp+a, tmp+a3, 0);
      g.add_edge2(tmp+a2, tmp+a3, 0);
    }
  }
  g.dijkstra(b);
  long ans = min(g.ans[c], min(g.ans[c+a], min(g.ans[c+a2], g.ans[c+a3])));
  if(ans == 2000000000000000000) ans = -1;
  else ans = (ans-1) / k + 1;
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 564540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	int n;
	cin >> n;
	vector<int> p(n);
	forn(i, n) cin >> p[i];
	vector<int> q(n);
	forn(i, n) cin >> q[i];

	vector<int> a(n);
	forn(i, n) a[i] = i+1;
	int i = 1, ra = 0, rb = 0;
	while(next_permutation(all(a))) {
		if(p == a) ra = i;
		if(q == a) rb = i;
		i++;	
	}
	cout << abs(ra-rb) << endl;
	return 0;
}



Measured memory_bytes: 3620
O = input()
E = input()
n = len(O)
m = len(E)
if n - m == 1:
	l = ""
	for i in range(m):
		l += O[i] + E[i]
	l += O[n -1]
	print(l)
else:
	l = ""
	for i in range(m):
		l += O[i] + E[i]
	print(l)

Measured memory_bytes: 3064
main = do
  s <- getLine
  if possible s then putStrLn "YES" else putStrLn "NO"

possible [] = True
possible s = dream s || dreamer s || erase s || eraser s

dream ('d':'r':'e':'a':'m':s) = possible s
dream _ = False
dreamer ('d':'r':'e':'a':'m':'e':'r':s) = possible s
dreamer _ = False
erase ('e':'r':'a':'s':'e':s) = possible s
erase _ = False
eraser ('e':'r':'a':'s':'e':'r':s) = possible s
eraser _ = False

Measured memory_bytes: 7548
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	sum := 0
	min := 1000000000
	msum := 0
	for i := 0; i < n; i++ {
		var v int
		fmt.Scan(&v)
		rv := abs(v)
		sum += rv
		if rv < min {
			min = rv
		}
		if v < 0 {
			msum++
		}
	}
	if msum%2 == 0 {
		fmt.Println(sum)
	} else {
		fmt.Println(sum - min*2)
	}
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 7552
#include <iostream>
using namespace std;
int main(void){
    int N,K;
    cin >> N >> K;
    int x[N];
    int i,j;
    int max = 0;
    int sum =0;
    int x1,x2=0;
    for(i=0;i<N;i++)
    {
        cin >> x[i];
    }
    max = 2*(x[N-1] - x[0]);
    
    for(i=0;i<=N-K;i++)
    {
        sum =0;
        x1 = abs(x[i]);
        x2 = abs(x[i+K-1]);
        sum += min(x1,x2);
        if(K>=2){
        for(j=i;j<=i+K-2;j++)
        {
            sum += x[j+1]-x[j];
        }
        }
        /*
        //sum += max(x[i],x[i+N]);
        x1 = abs(x[i]);
        x2 = abs(x[i+K-1]);
        sum += min(x1,x2);
        */
        if(sum < max)
        {
            max = sum;
        }
        
    }
    cout << max << endl;
    
    
}

Measured memory_bytes: 768
#include <iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    double ans = 0.0;
    for(int i=0;i<n;i++){
        double x;
        string u;
        cin >> x >> u;
        if(u == "JPY")
            ans += x;
        else
            ans += x * 380000.0;
    }
    printf("%lf\n", ans);
    return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left
import random
import time
import math



#入力
D = int(input())
C = [int(c) for c in input().split()]
S = []
for _ in range(D):
    s = [int(x) for x in input().split()]
    S.append(s)
#初期解
T = []
for _ in range(D):
    t = random.randrange(26)
    T.append(t)


last_day = [[-1] for _ in range(26)]
for d in range(D):
    test = T[d]
    last_day[test].append(d)
for i in range(26):
    last_day[i].append(D)


T0 = 4000
time_start = time.perf_counter()
while True:
    time_now = time.perf_counter()
    if time_now - time_start > 1.8:
        break
    #時間を正規化して温度を設定
    time_n = (time_now - time_start) / 1.8
    T1 = T0 ** (1 - time_n)
    #ランダムな日のテストをランダムに入れ替え
    d = random.randrange(365)
    q = random.randrange(26)
    old = T[d]
    T[d] = q
    #日程dでの元のテストold
    l = last_day[old]
    ind_old = l.index(d)
    dd_left = l[ind_old] - l[ind_old-1] - 1
    dd_right = l[ind_old+1] - l[ind_old] - 1
    dd = l[ind_old+1] - l[ind_old-1] - 1
    dif_old = C[old] * (((dd_left * (dd_left + 1)) // 2) + ((dd_right * (dd_right + 1)) // 2) - ((dd * (dd + 1)) // 2))
    #日程dでのテストq
    l = last_day[q]
    ind_q = bisect_left(last_day[q],d)
    dd_left = d - l[ind_q-1] - 1
    dd_right = l[ind_q] - d - 1
    dd = l[ind_q] - l[ind_q-1] - 1
    dif_q = C[q] * (((dd * (dd + 1)) // 2) - ((dd_left * (dd_left + 1)) // 2) - ((dd_right * (dd_right + 1)) // 2))
    #変更による差
    dif_s = (dif_old + dif_q - S[d][old] + S[d][q])
    if (dif_s > 0) or (math.exp(dif_s / T1) > random.random()):
        del last_day[old][ind_old]
        last_day[q].insert(ind_q,d)
    else:
        T[d] = old
for d in range(365):
    print(T[d] + 1)



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

#define ll long long int

int main(){
    ll n;
    cin >> n;
    ll ar[n];
    for(ll i = 0;i < n;i++) cin >> ar[i];
    ll dp[n][n];
    memset(dp,0,sizeof dp);
    for(ll i = 0;i < n;i++){
        for(ll j = 0;j + i < n;j++){
            if(i==0){
                dp[j][j] = ar[j];
                continue;
            }
            dp[j][j+i] = max(ar[j]-dp[j+1][j+i],ar[j+i]-dp[j][j+i-1]);
        }
    }
    cout<<dp[0][n-1];
}

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

int main() {
    int n; scanf("%d",&n);
    map<string, int> mp;
    while(n--){
        string s; cin >> s;
        mp[s]++;
    }  
    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d", mp["AC"], mp["WA"], mp["TLE"], mp["RE"]);
    return 0;
}

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

int main(void){
    long n;
    cin >> n;
    deque<long> v(n), w(n), x(n);
    for(long i=0; i<n; i++){
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    long left=v[0], right=v[0];
    //cout << v[0] << endl;
    v.pop_front();
    long sum = 0;
    while(v.size()>0){
        array<long,4> d;
        d[0] = abs(v.front() - left);
        d[1] = abs(v.front() - right);
        d[2] = abs(v.back() - left);
        d[3] = abs(v.back() - right);
        const auto it = max_element(d.begin(), d.end());
        //cout << v.front() << "," << v.back() << endl;
        //cout << left << "," << right << endl;
        const long pos = it-d.begin();
        //cout << *it << endl;
        sum += d[pos];
        if(pos%2==0){
            left = pos<2 ? v.front() : v.back();
        }else{
            right =  pos<2 ? v.front() : v.back();
        }
        if(pos<2){
            v.pop_front();
        }else{
            v.pop_back();
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define MOD           1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define endl "\n"
#define PI 3.14159265358979323846264338327950L
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int fc[100001], in[100001];
/*int pwmd(int a, int n)
{
	if (!n)
		return 1;
	int pt = pwmd(a, n / 2);
	pt *= pt, pt %= mod;
	if (n & 1)
		pt *= a, pt %= mod;
	return pt;
}*/

/*void dfs(int i,int par)
{
	for(int x:adj[i])
	{
		if(x!=par)
		{
			dfs(x,i);
		    sub[i]+=sub[x];
		}
	}
}*/
int pow(int a,int b,int m)
{
	int ans=1; 
	while(b>0)
	{ 
		if(b%2==1) 
			ans=(ans*a)%m; 
		 b/=2; 
		 a=(a*a)%m; 
	}
		return ans%m; 
}


int c1,c2,c3;
int dp[3005][3];
int32_t main()
{
	FIO;
	int a,b,h,m;
	cin>>a>>b>>h>>m;

	long double h_arg = (2*PI*(double(h) / 12)) + (2*PI*(double(m)/720));
	long double m_arg = 2*PI *(double(m) / 60);
	
	long double center_arg = abs(h_arg - m_arg);
 
	long double c_2 = a * a + b * b - 2 * a * b * cos(center_arg);
	cout << fixed << setprecision(16);
	cout << sqrt(c_2) << endl;

}

Measured memory_bytes: 4144
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n;
    cin>>n;
    map<int,int> a;
    int x;
    rep(i,n-1){
        cin>>x;
        a[x] ++;
    }
    for(int i=1;i<=n;i++) cout<<a[i]<<endl;
}/*
./problem.exe
*/

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

int main(void){
  int n;
  int dp[31];
  dp[0] = 1;
  dp[1] = 2;
  dp[2] = 4;
  for(int i = 3 ; i < 31 ;  i ++){
    dp[i] = dp[i-1] + dp[i-2] + dp[i-3];
  }
  while(cin>>n,n){
    cout<<1+dp[n-1]/3650<<endl;
  }
}

Measured memory_bytes: 1160
import math

a = list(map(int, [input() for i in range(5)]))
b = [math.ceil(b/10)*10 for b in a]

c1 = b[0] + b[1] + b[2] + b[3] + a[4]
c2 = b[0] + b[1] + b[2] + a[3] + b[4]
c3 = b[0] + b[1] + a[2] + b[3] + b[4]
c4 = b[0] + a[1] + b[2] + b[3] + b[4]
c5 = a[0] + b[1] + b[2] + b[3] + b[4]

print(min([c1,c2,c3,c4,c5]))

Measured memory_bytes: 3064
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())

A=a % 10
B=b % 10
C=c % 10
D=d % 10
E=e % 10
s=a // 10
t=b // 10
u=c // 10
v=d // 10
w=e // 10

if A == 0:
	A = A + 10
else:
	a = (s + 1) * 10

if B == 0:
	B = B + 10
else:
	b = (t + 1) * 10

if C == 0:
	C = C + 10
else:
	c = (u + 1) * 10

if D == 0:
	D = D + 10
else:
	d = (v + 1) * 10

if E == 0:
	E = E + 10
else:
	e = (w + 1) * 10

m = min([A,B,C,D,E])

if m == 10:
	X = a+b+c+d+e
elif m == A:
	X = b+c+d+e+(s*10+A)
elif m == B:
	X = a+c+d+e+(t*10+B)
elif m == C:
	X = a+b+d+e+(u*10+C)
elif m == D:
	X = a+b+c+e+(v*10+D)
else:
	X = a+b+c+d+(w*10+E)

print(X)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007

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

int main(){
    int n;
    cin >> n;
    vector<int> c(n);
    rep(i,n) cin >> c[i];
    vector<int> a(200010,-1);
    vector<int> next(200010,-1);
    rep(i,n){
        if(a[c[i]]==-1){
            a[c[i]]= i;
        }else{
            next[a[c[i]]] = i;
            a[c[i]] = i;
        }
    }
    vector<ll>dp(n);
    for(int i = n-1;i>=0;i--){
        if(i==n-1){
            dp[i] = 1;
        }else{
            if(next[i]==-1||next[i]==i+1){
                dp[i] = dp[i+1];
            }else{
                dp[i] = dp[i+1] + dp[next[i]];
                dp[i] %= mod;
            }
        }
    }
    cout << dp[0] << endl;
    return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
#define pi pair<int,int>
using namespace std;
int main(){
   int n ; 
   cin>> n ;
   int a[n][3] ,dp[n][3] ; 
   for(int i = 0 ;i < n ; ++i)
   cin>>a[i][0] >> a[i][1] >> a[i][2] ;
   
   dp[0][0] = a[0][0] ; 
   dp[0][1] = a[0][1] ; 
   dp[0][2] = a[0][2] ; 
   for(int i = 1 ;i < n ; ++i){
	  
	  for(int j = 0 ; j < 3 ; ++j){
		   if(j == 0)
			   dp[i][0] = max(dp[i-1][1]  , dp[i-1][2]) + a[i][0] ; 
	       else if(j ==1 )
	            dp[i][j] = max(dp[i-1][0]  , dp[i-1][2]) + a[i][1] ;
             else 
                 dp[i][j] = max(dp[i-1][0]  , dp[i-1][1]) + a[i][2] ;
			 }
		 }
		 cout<<max(dp[n-1][0] , max(dp[n-1][1] , dp[n-1][2]))<<endl;
  
}


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

int t = 0;

int main(){
    int n, q;
    cin >> n >> q;
    queue<pair<string, int> > qu;
    for(int i = 0; i < n; i++){
        pair<string, int> p;
        cin >> p.first >> p.second;
        //cout << p.first << ' ' << p.second << endl;
        qu.push(p);
    }
    while(!qu.empty()){
        if(qu.front().second <= q){
            t += qu.front().second;
            cout << qu.front().first << ' ' << t << endl;
            qu.pop();
        }
        else{
            t += q;
            pair<string, int> p;
            p = make_pair(qu.front().first, qu.front().second - q);
            qu.push(p);
            qu.pop();
        }
    }
    return 0;
}



Measured memory_bytes: 6388
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>
#include <cassert>
#include <bitset>
#include <list>
#include <iomanip>
#include <cctype>

#define for0(i, N)    for (long long i = 0  ; i <  (N); ++i)
#define for1n(i, N)   for (long long i = 1  ; i <= (N); ++i)
#define for1(i, N)    for (long long i = 1  ; i <  (N); ++i)
#define forn(i, N)    for (long long i = 0  ; i <= (N); ++i)
#define forx(i, N, x) for (long long i = (x); i <  (N); ++i)
#define forl(i, N, x, a) for (long long i = (x), a = 0; a < (N);    \
                              i = (i + 1) % (N), ++a)
#define int long long

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b, signed){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b + 1;
}

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b++;
    return temp;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b, signed){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b - 1;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b--;
    return temp;
}

long long constexpr inf = std::numeric_limits<long long>::max();

using namespace std;

typedef long long ll;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<vector<ll>> vvll;


signed main(void){
    cin.tie(0); ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);

    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    deque<ll> p(a, 0), q(b, 0), r(c, 0);

    for0(i, a){
        cin >> p[i];
    }
    for0(i, b){
        cin >> q[i];
    }
    for0(i, c){
        cin >> r[i];
    }

    sort(p.begin(), p.end(), greater<ll>());
    sort(q.begin(), q.end(), greater<ll>());
    sort(r.begin(), r.end(), greater<ll>());

    while(!r.empty()){
        ll rm = p[x - 1];
        ll gm = q[y - 1];
        ll mM = r[0];
        if (rm < gm) {
            if (rm > mM) {
                break;
            }
            p.push_front(mM);
            r.pop_front();
        } else {
            if (gm > mM) {
                break;
            }
            q.push_front(mM);
            r.pop_front();
        }
    }

    ll result = 0;

    for0(i, x){
        result += p[i];
    }
    for0(i, y){
        result += q[i];
    }

    cout << result;

    return 0;
}


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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<29)
#define INFLL (1LL<<62)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int Cost;
struct Edge {
  int src, dst; Cost cost;
  Edge(int s, int d, Cost c) : src(s), dst(d), cost(c) {}
};
typedef vector<Edge>  Edges;
typedef vector<Edges> Graph;
typedef vector<Cost>  Array;
typedef vector<Array> Matrix;

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

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n, mod = 1e9+7;
  cin >> n;
  ll p = 1;
  for (int i = 1; i <= n; i++) {
    p = (p * i) % mod;
  }

  cout << p << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;
//const int MOD=998244353;

ll a[200001];
ll b[200001];
int c[200001];
int main(){
	int n; cin>>n;
	map<int,int> m;
	FOR(i,0,n){
		cin>>a[i];
		b[i]=a[i]*2;
	}

	int ans=0;
	sort(a,a+n); sort(b,b+n);
	ROF(i,0,n){
		int k=0;
		b[i]++;
		if(c[i]) continue;
		while((1<<k)<=a[i]) k++;
		int t=(1<<k)-a[i];
		int ti=upper_bound(b,b+n,t*2)-b;
		if(b[ti-1]==t*2){
			b[ti-1]++;
			c[ti-1]=1;
			ans++;
		}
		//printf("%d %d %d %d\n",i,t,ti,ans);
		//FOR(i,0,n) cout<<b[i]<<" "; cout<<endl;
	}
	co(ans);
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
int A[3][3] = {};
int B[3][3] = {};

int main() {
    for(int i=0; i<3; ++i) {
        for(int j=0; j<3; ++j) cin >> A[i][j];
    }

    int N; cin >> N;
    for(int i=0; i<N; ++i) {
        int b; cin >> b;
        for(int i=0; i<3; ++i) {
            for(int j=0; j<3; ++j) {
                if(A[i][j] == b) B[i][j] = true;
            }
        }
    }

    for(int i=0; i<3; ++i) {
        if(B[i][0] && B[i][1] && B[i][2]) {
            cout << "Yes\n";
            return 0;
        }
    }
    for(int i=0; i<3; ++i) {
        if(B[0][i] && B[1][i] && B[2][i]) {
            cout << "Yes\n";
            return 0;
        }
    }
    if(B[0][0] && B[1][1] && B[2][2]) {
        cout << "Yes\n";
        return 0;
    }
    if(B[0][2] && B[1][1] && B[2][0]) {
        cout << "Yes\n";
        return 0;
    }
    cout << "No\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<queue>
#include<string>
#include<stack>
#include<algorithm>
#include<memory.h>
#include<set>
#include<map>
#include<cmath>
#include<time.h>
#include<iomanip>
#include<time.h>
using namespace std;
typedef long long ll;
#define se second
#define fi first
#define pb push_back
const int N = 5002, M = 1e9 + 7;
const double PI = acos(-1);
int a, b, c, x, y;

int main() {
	scanf("%d%d%d%d%d", &a, &b, &c, &x, &y);

	ll ans = 1e18;
	for (int i = 0;i <= max(2 * x, 2 * y);i+=2) {
		ll t = i * 1LL * c;
		int remx = x - (i/2);
		int remy = y - (i / 2);
		if (remx>0)t += remx*1LL*a;
		if (remy>0)t += remy * 1LL * b;
		ans = min(ans, t);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
    int x,y;
    for(;;){
        scanf("%d %d",&x,&y);
        if(x != 0 || y != 0){
            if(x <= y){
                printf("%d %d\n",x,y);
            }else{
                printf("%d %d\n",y,x);
            }
        }else{
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 2556
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  char S;
  cin>>S;

  if(S>='a'&&S<='z') cout<<'a'<<endl;
  else cout<<'A'<<endl;

  return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
char s[100010];
int main() {
    scanf("%s",s+1);
    int n=strlen(s+1);
    puts((n+(s[1]==s[n]))%2?"First":"Second");
    return 0;
}

Measured memory_bytes: 384
(* O(1) *)
let get_next_time cook_time current waits =
  let time = cook_time + current in
  let m = time mod 10 in
  if m = 0 || not waits then time else time + 10 - m

(* O(n) *)
let rec fold_btw f a i n = if i >= n then a else fold_btw f (f a i) (i + 1) n
let fold_int f a n = fold_btw f a 0 n

(* O(|dishes|!) *)
let solve dishes =
  let n = Array.length dishes in
  let used = Array.make n false in
  let perm = Array.make n (-1) in
  let rec loop min_time i =
    if i >= n then
      min
        min_time
        (fold_int
          (fun acc i -> get_next_time dishes.(perm.(i)) acc (i <> n - 1))
          0 n)
    else
      fold_int
        (fun acc j ->
          if used.(j) then
            acc
          else
            (used.(j) <- true;
            perm.(i) <- j;
            let mi = loop acc (i + 1) in
            used.(j) <- false;
            mi))
        min_time
        n
    in
      loop max_int 0

let read_int_array n = Array.init n (fun _ -> read_int ())

let _ = read_int_array 5 |> solve |> string_of_int |> print_endline

Measured memory_bytes: 384
#include<stdio.h>
#define N 2

int matrix(double **x);
 
int main(void){
	double x[N][N+1];
	double *y[N];
	double su1=0,su2=0;
	int i,j,k;
	char str[100];
    
	for( ;fgets(str,sizeof(str),stdin)!=NULL; ){
		sscanf(str,"%lf %lf %lf %lf %lf %lf",&x[0][0],&x[0][1],&x[0][2],&x[1][0],&x[1][1],&x[1][2]);
		for(i=0;i<N;i++)
			y[i]=x[i];
		matrix(y);
		for(i=0;i<N;i++){
			if(i) printf(" ");
			printf("%3.3f",x[i][N]);
		}
		printf("\n");
	}
	return 0;
}

int matrix(double **x){
	int i,j,k;
	double su1=0,su2=0;

	for(k=0;k<=N-2;k++){
		for(j=k+1;j<=N-1;j++){
			su1=x[k][k];
			su2=x[j][k];
			for(i=0;i<=2;i++){
				x[j][i]=x[j][i]-x[k][i]*su2/su1;
			}
		}
	}	
	for(k=0;k<=N-2;k++){
		for(j=k+1;j<=N-1;j++){
			su1=x[1-k][1-k];
			su2=x[1-j][1-k];
			for(i=0;i<=2;i++){
				x[1-j][i]=x[1-j][i]-x[1-k][i]*su2/su1;
			}
		}
	}
	su1=0;
	for(j=0;j<=N-1;j++){
	su1=x[j][j];
		for(i=0;i<=N;i++){
		x[j][i]=x[j][i]/su1;
		}	
	}
	return 0;
}

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

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

	int main() {
        int a;
        cin >> a;
        string s;
        cin >> s;

        if (a >= 3200) {
            cout << s << endl;
        } else {
            s = "red";
            cout << s << endl;
        }

	    return 0;
	}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define rep(i, o) for (int i = 0; i < (o);i++)
#define rep_s(i, o) for (int i = 1; i < (o);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }


template<class T>
bool chmax(T &a, const T &b) {
    if (a < b)
    {
        return b;
    }
    return a; 
}

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

int main() {
    ull x, y;
    cin >> x >> y;

    ll max_array_size = 1;
    while (1) {
        x *= 2;
        if (x > y) break;
        max_array_size++;
    }
    cout << max_array_size << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};

const int MAX=510000;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n;
  cin >> n;
  vector<pair<string,P>>vec;
  rep(i,n){
    string s;
    int p;
    cin >> s >> p;
    vec.emplace_back(s,P(-p,i+1));
  }
  sort(vec.begin(),vec.end());
  rep(i,n) cout << vec[i].second.second << endl;
  return 0;
}

Measured memory_bytes: 3672
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN2(n,m);
  Vi A(m);
  Vi B(m);
  VIN(A)
  VIN(B)
  Vi ANS(n);
  REP(i,m){
      ANS[A[i]-1]++;
      ANS[B[i]-1]++;
  }
  VOUT(ANS)
}


Measured memory_bytes: 256
// template version 1.6
// {{{ define basic macro
using namespace std;
#include <iostream>
#include <bits/stdc++.h>
// varibable settings
#define int long long
#define INF 1000000000000000000LL
// #define INF 2147483647
#define MOD 1000000007LL
// #define MOD 998244353LL
#define infile "../test/sample-1.in"

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)
template<class T, size_t N> size_t sza(const T (&array)[N]) { return N; }
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
template<class T=int> T in() {T x; cin>>x; return (x);}
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

int solve(){
  int d;cin>>d;

  if (d==25) {
    cout << "Christmas" << endl;
  }
  else if(d==24){
    cout << "Christmas Eve" << endl;
  }
  else if(d==23){
    cout << "Christmas Eve Eve" << endl;
  }
  else{
    cout << "Christmas Eve Eve Eve" << endl;
  }

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


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

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int K = in.nextInt();
		long[] h = new long[N];
		for (int i = 0; i < h.length; i++) {
			h[i] = in.nextLong();
		}
		Arrays.sort(h);
		long ans = Long.MAX_VALUE;
		for (int i = 0; i < h.length - K + 1; i++) {
			ans = Math.min(ans, h[i + K - 1] - h[i]);
		}
		System.out.println(ans);
		in.close();
	}
}

Measured memory_bytes: 48444
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int N, ans = 0;
		String[] S;

		Scanner in = new Scanner(System.in);
		List<String> ph1 = new ArrayList<String>();
		List<String> ph2 = new ArrayList<String>();
		List<String> ph3 = new ArrayList<String>();
		N = Integer.parseInt(in.next());
		S = in.next().split("");

		for (int i = 0; i < N - 2; i++) {
			if (ph1.contains(S[i])) {
				continue;
			}
			ph1.add(S[i]);
			for (int j = i + 1; j < N - 1; j++) {
				if (ph2.contains(S[j])) {
					continue;
				}
				ph2.add(S[j]);
				for (int k = j + 1; k < N; k++) {
					if (ph3.contains(S[k])) {
						continue;
					}
					ph3.add(S[k]);
					ans++;
				}
				ph3.clear();
			}
			ph2.clear();
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 27376
n, y = map(int, input().split())

y=y/1000
c=y-n

if c<0 or 10*n<y: # 例外処理
    print(-1, -1, -1)
else:
    X=-1
    Y=-1
    Z=-1
    for x in range(n+1):
        for y in range(n+1):
            if x+y>n:
                break
            if 9*x+4*y==c:
                X=x
                Y=y
                Z=n-x-y
                break
        if X>=0: break
    print(X, Y, Z)

Measured memory_bytes: 40556