akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define minit(a,b) memset(a,b,sizeof(a))

typedef long long lint;
int W, H, N;
const int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
const lint INF = 1LL << 60;
lint over[555][555][4], cst[555][555];

struct State {
	int x, y;
	lint cst;
	State(int x_, int y_, lint cst_ = 0) : x(x_), y(y_), cst(cst_) {}
	bool operator > (const State& a) const { return cst > a.cst; }
};

int dir(char c) {
	if (c == 'D') return 0;
	if (c == 'R') return 1;
	if (c == 'U') return 2;
	return 3;
}

int main() {
	cin >> W >> H >> N;
	
	int sx, sy, ex, ey;
	cin >> sx >> sy >> ex >> ey;
	
	minit(over, 0);
	
	for_(i,0,N) {
		int x, y, T;
		string pat;
		
		cin >> x >> y;
		cin >> T >> pat;
		int len = pat.size();
		
		for_(j,0,T) for_(k,0,len) {
			int nx = x + dx[dir(pat[k])], ny = y + dy[dir(pat[k])];
			if (nx < 0 || W <= nx || ny < 0 || H <= ny) continue;
			if (nx == x) ++over[max(y, ny)][x][dir('R')], ++over[max(y, ny)][x+1][dir('L')];
			else ++over[y][max(x, nx)][dir('D')], ++over[y + 1][max(x, nx)][dir('U')];
			x = nx; y = ny;
		}
	}
	
	for_(y,0,H+1) for_(x,0,W+1) cst[y][x] = INF;
	
	priority_queue< State, vector< State >, greater< State > > que;
	que.push(State(sx, sy));
	cst[sy][sx] = 0;
	
	while (!que.empty()) {
		State s = que.top(); que.pop();
		
		if (cst[s.y][s.x] < s.cst) continue;
		
		for_(d,0,4) {
			int nx = s.x + dx[d], ny = s.y + dy[d];
			if (nx < 0 || W < nx || ny < 0 || H < ny) continue;
			
			lint cc = s.cst + over[s.y][s.x][d];
			
			if (cst[ny][nx] > cc) {
				cst[ny][nx] = cc;
				que.push(State(nx, ny, cc));
			}
		}
	}
	
	cout << cst[ey][ex] << endl;
}

Measured memory_bytes: 17984
def use_fast_io():
    global input
    import io
    import sys
    f = io.BytesIO(sys.stdin.buffer.read())
    input = f.readline
use_fast_io()


from scipy.sparse.csgraph import floyd_warshall
import numpy as np

N, M, L = map(int, input().split())
graph = np.full((N, N), np.inf)
for _ in range(M):
    s, t, w = map(int, input().split())
    if w <= L:
        graph[s-1][t-1] = graph[t-1][s-1] = w
graph = floyd_warshall(graph, directed=False)
graph = floyd_warshall(graph <= L, directed=False)
graph[np.isinf(graph)] = 0

Q = int(input())
ans = []
for _ in range(Q):
    s, t = map(int, input().split())
    ans.append(int(graph[s-1][t-1]) - 1)
print(*ans, sep='\n')


Measured memory_bytes: 18860
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nk[0];
        var k = nk[1];
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        //var a = Enumerable.Repeat(0, n).ToArray();
        //nが小さい時注意
        for (int count = 0; count < k; count++)
        {
            SegmentTree<int> next = new SegmentTree<int>(n, 0, (x, y) => x + y);
            for (int i = 0; i < n; i++)
                next.Operate(Max(i - a[i], 0), Min(i + a[i], n - 1), 1);
            var isAllN = true;
            for (int i = 0; i < n; i++)
            {
                a[i] = next[i];
                if (a[i] != n) isAllN = false;
            }
            if (isAllN) break;
            //Console.WriteLine(string.Join(" ", a));
        }

        Console.WriteLine(string.Join(" ", a));
    }
}


class SegmentTree<T>
{
    public readonly int Size;
    T[] Operators;
    Func<T, T, T> Merge;
    int LeafCount;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public SegmentTree(int size, T identity, Func<T, T, T> merge)
    {
        Size = size;
        Merge = merge;
        LeafCount = 1;
        while (LeafCount < size) LeafCount <<= 1;
        Operators = new T[LeafCount << 1];
        for (int i = 0; i < Operators.Length; i++)
            Operators[i] = identity;
    }
    public T this[int index]
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get { return Query(index); }
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Operate(int i, T x) { i += LeafCount; Operators[i] = Merge(Operators[i], x); }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Operate(int l, int r, T x)
    {
        for (l += LeafCount, r += LeafCount; l <= r; l = (l + 1) >> 1, r = (r - 1) >> 1)
        {
            if ((l & 1) == 1) Operators[l] = Merge(Operators[l], x);
            if ((r & 1) == 0) Operators[r] = Merge(Operators[r], x);
        }
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Query(int i)
    {
        i += LeafCount;
        T res = Operators[i];
        while (0 < (i >>= 1)) res = Merge(res, Operators[i]);
        return res;
    }
}

Measured memory_bytes: 61120
#include <iostream>
using namespace std;
int w,h;
int mp[31][31];
int memo[4][31][31];
int memo2[31][31];
int c[4];
int ans;
int cnt;
string str = ">v<^";
 
void saiki(int x,int y,int dir,int cost) {
  int dx[] = {1,0,-1,0};
  int dy[] = {0,1,0,-1};
 
   
  if(x == w-1 && y == h-1 && ans > cost) ans = cost;
  else if(memo[dir%4][y][x]>cost && ans > cost){
    memo[dir%4][y][x] = cost;
    cnt++;
     
    //    cout << str[dir%4];
    //  cout <<" "<< x <<" " << y <<" cost="<<cost<<endl
     
    for(int i=0;i<4;i++){
      int ii = (i+dir%4)%4;
      int nx = x + dx[ii];
      int ny = y + dy[ii]; 
      if(nx < 0 || nx >= w || ny < 0 || ny >= h ) continue;
      if(i == mp[y][x]) {
	saiki(nx,ny,(dir+i),cost);
      }
      else
	saiki(nx,ny,(dir+i),cost+c[i]);
       
    }
  }
}
 
int main() {
   
  while(1) {
    cin >> w >> h;
    if(w == 0 && h == 0) break;
 
 
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	cin >> mp[i][j];
 
 
    for(int i=0;i<4;i++)cin >> c[i];
 
 
 
    for(int i=0;i<4;i++)
      for(int j=0;j<31;j++)
	for(int k=0;k<31;k++)
	  memo[i][j][k] = 1000000000;
 
    ans = 1000000000;
    cnt = 0;
    saiki(0,0,0,0);
 
    cout << ans<< endl;
    //  cout << cnt <<endl;
  }
 
  return 0;
}

Measured memory_bytes: 1392
import * as fs from "fs";

const split = (str: string): string[] =>
  str.split(" ").map((v: string) => v.trim());
const split_number = (str: string): number[] =>
  split(str).map((v: string) => +v);

export function main(input: string) {
  const lines = input.split("\n");
  const [n] = split_number(lines[0]);
  const A = split_number(lines[1]);

  const before = A.filter(n => n % 2 === 0);
  const after = before.filter(n => n % 3 === 0 || n % 5 === 0);

  return before.length === after.length ? "APPROVED" : "DENIED";
}

if (!process.env.LOCAL_DEBUG) {
  console.log(main(fs.readFileSync("/dev/stdin", "utf8")));
}


Measured memory_bytes: 7372
#include<iostream>
using namespace std;
int main(){
	bool ok=false;
	int a,b,c;
	cin>>a>>b>>c;
	for(int i=1;i<=b;i++){
		if(i*a%b==c)ok=true;
	}
	cout<<(ok?"YES":"NO")<<endl;
	return 0;
}


Measured memory_bytes: 256
n,m = list(map(int, input().split()))

ac = 0
wa = 0
ans = [{'AC': False, 'cnt': 0} for _ in range(n)]

if m == 0:
    print('0 0')
else:

    for _ in range(m):
        p,s = list(input().split())
        p = int(p)
        if s == 'AC':
            ans[p-1]['AC'] = True
        elif ans[p-1]['AC'] == False:
            ans[p-1]['cnt'] += 1

    for a in ans:

        if a['AC']:
            ac += 1
            wa += a['cnt']
    print('{} {}'.format(ac, wa))


Measured memory_bytes: 33524
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;

int main() {

    int N;
    cin >> N;
    ll ans = 0;

    for (ll k = 1; k <= N; k++) ans += k * (N - k + 1);

    for (ll i = 0; i < N - 1; i++) {
        ll u, v;
        cin >> u >> v;
        if (u > v) swap(u, v);
        ans -= u * (N - v + 1);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3592
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
	}

	public boolean hasNext() {
		return cnt < 1;
		// return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		String[] strArr = str.split(" ");
		HashSet<Integer> cols = new HashSet<Integer>();
		int master = 0;
		for (int i = 0; i < N; i++) {
			int a = Integer.parseInt(strArr[i]);
			int c = -1;
			// •レート 1-399：灰色
			if (a >= 1 && a <= 399)
				c = 1;
			// •レート 400-799：茶色
			if (a >= 400 && a <= 799)
				c = 2;
			// •レート 800-1199：緑色
			if (a >= 800 && a <= 1199)
				c = 3;
			// •レート 1200-1599：水色
			if (a >= 1200 && a <= 1599)
				c = 4;
			// •レート 1600-1999：青色
			if (a >= 1600 && a <= 1999)
				c = 5;
			// •レート 2000-2399：黄色
			if (a >= 2000 && a <= 2399)
				c = 6;
			// •レート 2400-2799：橙色
			if (a >= 2400 && a <= 2799)
				c = 7;
			// •レート 2800-3199：赤色
			if (a >= 2800 && a <= 3199)
				c = 8;
			if (a >= 3200)
				master++;
			if (c >= 1 && c <= 8)
				cols.add(c);
		}
		int min = cols.size();
		int max = cols.size();
		if (master > 0) {
			if (min == 0)
				min = 1;
			max += master;
			// if (max > 8)
			// max = 8;
		}
		System.out.println(min + " " + max);
		cnt++;
	}
}


Measured memory_bytes: 23252
n,x,y = map(int,input().split())
 
root = [[] for i in range(n)]
for i in range(1,n):
    root[i-1].append(i)
    root[i].append(i-1)
root[x-1].append(y-1)
root[y-1].append(x-1)
memo = [0]*(n-1)
for j in range(n):
    stack=[j]
    check = [-1]*n
    check[j] = 0
    while len(stack):
        v = stack.pop(0)
        for i in root[v]:
            if check[i] == -1:
                check[i]=check[v]+1
                memo[check[i]-1]+=1
                stack.append(i)
for i in memo:
    print(i//2)

Measured memory_bytes: 46668
import heapq
inf = float('inf')

def main():
    n = input()
    A = []
    for i in xrange(n):
        A.append(map(int,raw_input().split()))

    d = dijkstra(0,A,n)
    for i in xrange(n):
        print i, d[i]
    
def dijkstra(s,A,n):
    c = [-1]*n
    d = [inf]*n
    d[s] = 0
    H = zip(d,range(n))
    heapq.heapify(H)
    
    while (len(H) >= 1):
        di,u = heapq.heappop(H)
        c[u] = 1
        for i in xrange(A[u][1]):
            v = A[u][2+2*i]
            l = A[u][3+2*i]
            if (c[v] != 1):
                if (d[u]+l < d[v]):
                    d[v] = d[u] + l
                    c[v] = 0
                    heapq.heappush(H,(d[v],v))
    return d

if __name__ == "__main__":
    main()

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

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

signed main(){

  ll n,k,r,s,p;
  cin>>n>>k>>r>>s>>p;
  string t;
  cin>>t;

  vector<string> x(k);
  rep(i,n){
    x[i%k] += t[i];
  }

  auto solve = [&](string const& str)->ll{
    int m = size(str);
    vector dp(3,vector(m+1,0ll));
    rep(i,m){
      dp[0][i+1]=max(dp[1][i],dp[2][i]);
      dp[1][i+1]=max(dp[0][i],dp[2][i]);
      dp[2][i+1]=max(dp[0][i],dp[1][i]);
      if(str[i]=='r')dp[0][i+1] += p;
      if(str[i]=='s')dp[1][i+1] += r;
      if(str[i]=='p')dp[2][i+1] += s;
    }
    return max({dp[0][m],dp[1][m],dp[2][m]});
  };

  ll ans = 0;
  rep(i,k)ans+=solve(x[i]);

  cout<<(ans)<<endl;

}

Measured memory_bytes: 6688
from heapq import heappush, heappop
n, m = map(int, input().split())

in_dict = {}
for _ in range(n):
    a, b = map(int, input().split())
    in_dict[a] = in_dict.get(a, [])
    in_dict[a].append(b)

heap = []
res = 0
for m_i in range(1, m + 1):
    for i in in_dict.get(m_i, []):
        heappush(heap, -i)
    if heap:
        res += -heappop(heap)

print(res)


Measured memory_bytes: 27344
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,0,-1,1,-1,-1,1,2,0,-2,0};
const int dy[]={0,1,-1,0,1,1,-1,-1,0,2,0,-2};
const int INF = 1<<30;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
int main(){
	int x,y,s;
	while(scanf("%d%d%d",&x,&y,&s),(x|y|s)){
		int ma = -INF;
		reps(i,1,s){
			int a = i;
			int b = s-i;
			double m = a * 100.0 / (100.0+x);
			double n = b * 100.0 / (100.0+x);
			if((int)(ceil(m)*(100.0+x)/100) != a)continue;
			if((int)(ceil(n)*(100.0+x)/100) != b)continue;
			int p = (int)(double)(ceil(m)*(100.0+y)/100.0);
			int q = (int)(double)(ceil(n)*(100.0+y)/100.0);	
			ma = max(ma,p+q);
		}
		printf("%d\n",ma);
	}
	return 0;
}

Measured memory_bytes: 1192
def main():
    N = int(input())
    p = list(map(int, input().split()))
    c = {}
    f = []
    for i in range(N):
        if p[i] != i+1:
            c[p[i]] = i+1
            f.append(p[i])
    if len(c) > 2:
        print('NO')
    elif len(f) == 0 or (c[f[0]] == f[1] and c[f[1]] == f[0]):
        print('YES')
    else:
        print('NO')

main()  

Measured memory_bytes: 9188
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  cin >> str;
  while(str[0]!='0'){
    int i,o=0;
    for(i=0;i<str.size();i++){
      o+=str[i]-'0';
    }
    cout << o << endl;
    cin >> str;
  }
  return 0;
}

Measured memory_bytes: 1184
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))


"""
全体のxor=S
赤のxor=xとすれば
求値は x+(S^x)の最大値
きつい

上の桁から見て，
Sのi桁目が0の時，その桁が1のものを奇数ずつ割り振りたい．
Sのi桁目が1の時，どんな分け方しても関係ない

上の桁から埋めたいというのはxを最大化したいというのと似ている．
Sのi桁目が1のぶんは先に計算しておく,かつ，各A[i]のその桁を0にしておけば，xを最大化したいという問題に帰着するか

xorの最大化，難しい．基底ベクトルに分解して，上の桁から足していく？
"""
def main():
    mod=10**9+7
    
    N=I()
    A=LI()
    
    S=0
    for i in range(N):
        S=S^A[i]
    
    M=61
    delete=[0]*M#消す桁
    
    ans=0
    for i in range(M):
        if (S>>i) & 1:
            delete[i]=1
            ans+=1<<i
            for j in range(N):
                if (A[j]>>i)&1:
                    A[j]-=1<<i
    
    #基底ベクトルを入れていく                
    vec=[]
    
    #二進数の桁数
    def dig_b(x):
        cnt=0
        while x!=0:
            x=x//2
            cnt+=1
        return cnt
    
    for i in range(N):
        now=A[i]
        d=dig_b(now)
        
        if vec==[]:
            vec.append((now,d))
        else:
            for v in vec:#各基底ベクトルと比較
                if v[1]==d:#今見てる数字と，基底ベクトルの最上位の桁数が同じなら潰せる
                    now=now^v[0]
                    d=dig_b(now)
            if now!=0:#0以外なら基底になる
                vec.append((now,d))
                vec.sort(reverse=True) #基底は大きい順に走査したいので
                
    temp=0
    for v in vec:
        temp2=temp^v[0]
        temp=max(temp,temp2)
        
    ans+=temp*2
    print(ans)
                    
                
        
    
                    
    
                    

        


main()


Measured memory_bytes: 92220
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7;

template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (int i = 0; i < v.size(); ++i)
    {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    for (int i = 0; i < v.size() - 1; ++i)
    {
        os << v[i] << " ";
    }
    if (v.size() > 0)
    {
        os << v[v.size() - 1] << endl;
    }
    return os;
}


int main()
{
    ll n, m, l, q;
    cin >> n >> m >> l;
    vector<vector<ll>> G(n, vector<ll>(n, INF));
    REP(i, m)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        --a;
        --b;
        G[a][b] = c;
        G[b][a] = c;
    }
    vector<vector<ll>> d(n, vector<ll>(n, INF));
    REP(i,n){
        REP(j,n){
            d[i][j] = G[i][j];
        }
    }
    REP(k, n)
    {
        REP(i,n){
            REP(j,n){
                if (d[i][j] > d[i][k] + d[k][j]){
                    d[i][j] = d[i][k] + d[k][j];
                }
            }
        }
    }
    vector<vector<ll>> d2(n, vector<ll>(n, INF));
    REP(i,n){
        REP(j,n){
            if (d[i][j] <= l){
                d2[i][j] = 1;
            }
        }
    }
    REP(k, n)
    {
        REP(i, n)
        {
            REP(j, n)
            {
                if (d2[i][j] > d2[i][k] + d2[k][j])
                {
                    d2[i][j] = d2[i][k] + d2[k][j];
                }
            }
        }
    }
    cin >> q;
    REP(i,q){
        int s,t;
        cin >> s >> t;
        --s;
        --t;
        if (d2[s][t] >= INF){
            cout << -1 << endl;
        }else{
            cout << d2[s][t]-1 << endl;
        }
    }
}

Measured memory_bytes: 2688
#include<iostream>
using namespace std;
int main()
{
	int N, flag, i, j, cnt;
	while (cin >> N)
	{
		for (i = 1, cnt = 0; i <= N; i += 2)
		{
			for (flag = 0, j = 2; j*j < i; j++)
				if (!(i%j))
					flag++;
			if (2 * flag == 6)
				cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner ipt = new Scanner(System.in);
		//1
		String n = ipt.next();
		String[] alpha = null;
		String[] alpha2 = null;
		int ans = 0;
		alpha = n.split("");
		//2
		n = ipt.next();
		alpha2 = n.split("");
		for (int i = 0; i < alpha.length; i++) {
			if (alpha[i].equals(alpha2[i])) {
				ans++;
			}
		}
		System.out.println(ans);
		ipt.close();
	}
}

Measured memory_bytes: 23124
import sys
sys.setrecursionlimit(10 ** 7)

# 反転 (ライツアウト)
# 2回やったら元に戻る

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

ans = 0

if A[0] > X:
    x = X
    ans += A[0] - X
else:
    x = A[0]

for i in range(1, N):
    a = A[i]
    b = max(a - X + x, 0)
    ans += b
    x = A[i] - b

print(ans)


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N, K;
std::vector<int> v, w;

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    std::cin >> N >> K;

    for(int i=0;i<N;++i){
        int x;
        std::cin >> x;

        if(x > 0){
            v.emplace_back(x);
        }else if(x < 0){
            w.emplace_back(-x);
        }else{
            K -= 1;
        }
    }

    if(K == 0){
        std::cout << 0 << std::endl;
        return 0;
    }

    std::reverse(w.begin(), w.end());

    int mn = 1001001001;

    if(v.size() >= K){
        mn = v[K - 1];
    }

    if(w.size() >= K){
        mn = std::min(mn, w[K - 1]);
    }

    for(int i=1;i<=std::min<int>(K - 1, v.size());++i){
        if(i + w.size() < K){
            continue;
        }

        mn = std::min({mn, v[i - 1] * 2 + w[K - i - 1], w[K - i - 1] * 2 + v[i - 1]});
    }

    std::cout << mn << std::endl;
}


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

using namespace std;

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

int INF = 1000000000;

int min(int i, int j)
{
    if (i > j) return j;
    else return i;
}

int main(void)
{
    int n, m;
    cin >> n >> m;
    vec<int> c(m);
    rep(i, m) cin >> c[i];

    vec<int> dp(n + 1, INF);

    dp[0] = 0;
    rep(i, n) {
        rep(j, m) {
            if (i + c[j] <= n) dp[i + c[j]] = min(dp[i + c[j]], dp[i] + 1);
        }
    }

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

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

#define LL long int


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

    int sz = s.size();

    vector<int> num(sz);

    for(int i = 0; i < sz; ++i) num[i] = s[i] - '0';

    vector<vector<vector<LL> > > dp(sz + 1, vector<vector<LL> >(2, vector<LL>(k + 2, 0 ) ) );

    dp[0][0][0] = 1;

    for(int i = 0; i < sz; ++i){
        for(int smaller = 0; smaller < 2; ++smaller){
            for(int j = 0; j <= k; ++j){
                for(int x = 0; x <= (smaller ? 9 : num[i]); ++x){
                    dp[i + 1][smaller || x < num[i]][j + (x != 0)] += dp[i][smaller][j];
                }
            }
        }
    }

    cout << dp[sz][0][k] + dp[sz][1][k] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	string a,b;
	cin>>a;
	cin>>b;
	ll count = 0;
	for(ll i=0;i<a.size();i++){
		if(a[i]!=b[i])	count++;
	}
	cout<<count<<endl;



	return 0;
}


Measured memory_bytes: 3860
#include <stdio.h>
int main(void) {
    int num,count,i,j,inst,card[202],shuffle[202];
    scanf("%d%d",&num,&count);
    for (i=1; i<=2*num; i++) card[i]=i;
    for (i=0; i<count; i++) {
        scanf("%d",&inst);
        if (inst==0) {
            for (j=1; j<=2*num; j++) shuffle[j]=card[j];
            for (j=1; j<=num; j++) {
                card[2*j-1]=shuffle[j];
                card[2*j]=shuffle[j+num];
            }
        } else {
            for (j=1; j<=inst; j++) shuffle[j]=card[j];
            for (j=1; j<=2*num-inst; j++) card[j]=card[j+inst];
            for (j=2*num-inst+1; j<=2*num; j++) card[j]=shuffle[j-2*num+inst];
        }
    }
    for (i=1; i<=2*num; i++) printf("%d\n",card[i]);
    return 0;
}

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

using namespace std;

void to_permutation(vector<int>& xs) {
    int n = (int)xs.size();
    vector<pair<int, int>> ys(n);
    for (int i = 0; i < n; ++i) {
        ys[i] = make_pair(xs[i], -i);
    }
    sort(ys.begin(), ys.end());
    for (int i = 0; i < n; ++i) {
        xs[-ys[i].second] = i;
    }
}

struct Fenwick {
    int n;
    vector<int> xs;
    Fenwick(int n): n(n), xs(n+1) {}
    void set(int p, int c) { // a[p] = max(a[p], c)
        while (p <= n) {
            xs[p] = max(xs[p], c);
            p += p&(-p);
        }
    }
    int get_max(int p) { // return max(a[1], a[2], ..., a[p])
        int hi = 0;
        while (p > 0) {
            hi = max(xs[p], hi);
            p -= p&(-p);
        }
        return hi;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> xs(n);
    for (int& x : xs) {
        cin >> x;
    }
    to_permutation(xs);
    Fenwick f(n);
    for (int i = n-1; i >= 0; --i) {
        int length = 1 + f.get_max(xs[i]);
        f.set(xs[i]+1, length);
    }
    cout << f.get_max(n) << endl;
    return 0;
}


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

using namespace std;

int main(){
	int ans = 0;
	string s;
	cin >> s;

	for(int i=1;i<s.size();++i){
		if(s[i] == s[i-1]){
			ans++;
			if(s[i-1] == '0') s[i] = '1';
			else s[i] = '0';
		}
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 512
a,b,c=map(int,input().split())
count=0
if a==b==c and a%2==0:
    print(-1)
    exit()
while a%2==0 and b%2==0 and c%2==0:
    A=a//2
    B=b//2
    C=c//2
    a=B+C
    b=C+A
    c=A+B
    count+=1
print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
 
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define pow10(n) stoll("1"+string(n,'0'))
//fill(all(arr),1)
//if(map.count(key)){}
//bitset<20>(n);
//int mini=min({a,b,c,d,e});
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;

int main(){
  FIO
  
  int n,m;
  cin>>n>>m;
  int a[m];
  int s=0;
  forn(i,m){cin>>a[i];s+=a[i];}
  //cout<<s;
  if(s>n)cout<<-1;
  else cout<<n-s;
  return 0;
}

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

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
  	vector<vector<int>> dp(n+1, vector<int>(3));
  	for (int i = 1; i <= n; ++i) {
  		vector<int> activities(3);
  		for (int a = 0; a < 3; ++a) cin >> activities[a];
  		for (int j = 0; j < 3; ++j)
  			for (int k = 0; k < 3; ++k) if (j != k)
  				dp[i][j] = max(dp[i][j], dp[i-1][k] + activities[j]);
  	}
  	cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << '\n';
}

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

#define MorsheD ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
typedef long long ll;

int main() {
	// ===================
	MorsheD;
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	// ===================

	ll d, t, s;
	cin >> d >> t >> s;

	if (t * s >= d) {
		cout << "Yes" << '\n';
	} else {
		cout << "No" << '\n';
	}

	return 0;
}

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


int main()
{
	int a,b;
	a=b=0;
	string s;
	getline(cin,s);
	for(int i=0;i<3;i++)
	{
		if(s[i]=='A')
		a++;
		else
		b++;
	}
	if(a!=3 && b!=3)
	cout<<"Yes"<<'\n';
	else
	cout<<"No"<<"\n";
	return 0;
} 


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#define _USE_MATH_DEFINES
#include<math.h>

using namespace std;

int main(){
    double x = 0, y = 0, direction = 90;
    int distance, degree;

    while (true)
    {
        scanf("%d,%d", &distance, &degree);

        if (distance == 0 && degree == 0){
            break;
        }

        x += distance*cos(direction / 180 * M_PI);
        y += distance*sin(direction / 180 * M_PI);

        direction -= degree;

    }

    cout << (int)x<<endl << (int)y << endl;

    scanf("%d,%d", &distance, &degree);


    return 0;
}

Measured memory_bytes: 1208
import java.io.*;
import java.util.*;

public class Main{
  public static void main(String[] args){
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String s;
    while(true){
      try{
        s = reader.readLine();
        if(s.equals(".")) break;
         Deque<Integer> ka = new ArrayDeque<>();//0 = [ 1 = (
         //Deque<Integer> ka2 = new ArrayDeque<>();//2 = ] 3 = )
        char[] c = s.toCharArray();
        int i = 0;
        for(char cs: c){
          if(cs == '(') ka.offerFirst(1);
          if(cs == '[') ka.offerFirst(0);
          if(cs == ')'){
            //ka2.offerFirst(3);
            if(ka.peek() == 1){
              ka.pollFirst();
              //ka2.pollFirst();
            }
            else{
              System.out.printf("no\n");
              break;
            }
          }
          if(cs == ']'){
            //ka2.offerFirst(2);
            if(ka.peek() == 0){
              ka.pollFirst();
              //ka2.pollFirst();
            }
            else{
              System.out.printf("no\n");
              break;
            }
          }
          if(i == s.length() - 1){
            if(ka.peek() == null /*&& ka2.peekFirst() == null*/){
              System.out.printf("yes\n");
              break;
            }
            else{
              System.out.printf("no\n");
              break;
            }
          }
          i++;
        }
      }catch(Exception e){
        System.out.printf("no\n");
      }
    }
  }
}


Measured memory_bytes: 33548
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int secs = sc.nextInt();
            int hh = secs / (60 * 60);
            int hs = secs % (60 * 60);
            int mm = hs / 60;
            int ss = hs % 60;
            System.out.println(String.format("%d:%d:%d", hh, mm, ss));
        }
    }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main(){
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int sq[n];
  for(int i=0; i<n; i++)
    cin >> sq[i];

  bool flag = true;
  for(int i=n-2; i>=0; i--){
    if(sq[i] == sq[i+1]+1)
      sq[i]--;
    else if(sq[i] > sq[i+1]+1){
      flag = false;
      break;
    }
  }

  if(flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 640
rank = []
p = []


def makeSet(x):
    p.append(x)
    rank.append(0)


def union(x, y):
    link(findSet(x), findSet(y))


def link(x, y):
    if rank[x] > rank[y]:
        p[y] = x
    else:
        p[x] = y
        if rank[x] == rank[y]:
            rank[y] = rank[y] + 1


def findSet(x):
    if x != p[x]:
        p[x] = findSet(p[x])
    return p[x]


def same(x, y):
    return findSet(x) == findSet(y)

def kruskal(g):
    MST = 0
    edges = g

    for e in edges:
        u = e[0]
        v = e[1]


        if findSet(u) != findSet(v):
            union(u, v)
            MST += e[2]

    return MST


V, E = map(int, input().split())
G = [list(map(int, input().split())) for i in range(E)]
G.sort(key=lambda x: x[2])

for i in range(V):
    makeSet(i)

print(kruskal(G))



Measured memory_bytes: 28200
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from functools import lru_cache
def resolve():
    for _ in range(int(input())):
        n, a, b, c, d = map(int, input().split())

        @lru_cache(None)
        def dfs(k):
            # base case
            if k == 0:
                return 0
            if k == 1:
                return d
            # recursion
            res = k * d
            for p, cost in zip([2, 3, 5], [a, b, c]):
                q, r = divmod(k, p)
                if r == 0:
                    res = min(res, dfs(q) + cost)
                else:
                    res = min(res, dfs(q) + cost + d * r, dfs(q + 1) + cost + d * (p - r))
            return res

        print(dfs(n))
resolve()

Measured memory_bytes: 101208
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

type Task struct {
	A, B int
}

type SortBy []Task

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	if a[i].B != a[j].B {
		return a[i].B < a[j].B
	}
	return a[i].A < a[j].A
}

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	N := nextInt()
	tasks := make([]Task, N)
	for i := 0; i < N; i++ {
		tasks[i].A = nextInt()
		tasks[i].B = nextInt()
	}
	sort.Sort(SortBy(tasks))
	// fmt.Println(tasks)
	t := 0
	for i := 0; i < N; i++ {
		t += tasks[i].A
		if t > tasks[i].B {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// Genericsがないので筋肉で...
// interfaceでの取扱がようわからんし
func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// mapからkeysとvaluesを返す感じのやつ
// なんかしらんけどmap[interface{}]interface{}しか受け付けない。なんのためのinterface{}やねん
// なので呼ぶときのmapはmap[int]stringとかじゃダメ
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
	return
}


Measured memory_bytes: 6272
#include <stdio.h>

long long W[101];
long long V[101];

long long dp[101][100001];

long long max(long long a, long long b) {
    if (a >= b) return a;
    else return b;
}

long long q (long long k, long long w) {
    if (dp[k][w] != -1) return dp[k][w];
    if (k == 0 || w == 0) dp[k][w] = 0;
    else if (w < W[k]) dp[k][w] = q(k-1, w);
    else {
        dp[k][w] = max(V[k] + q(k-1, max(0, w - W[k])), q(k-1, w));
    } 
    return dp[k][w];
}

int main(void) {

    long long N, M;
    scanf("%lld%lld", &N, &M);

    for (int i = 1; i <= N; i++) {
        scanf("%lld%lld", &W[i], &V[i]);
    }


    for (int i = 0; i <= N; i++) {
        for (long long j = 0; j <= M; j++) {
            dp[i][j] = -1;
        }
    }

    printf("%lld\n", q(N, M));


    return 0;
}

Measured memory_bytes: 79104
/*
 
*/ 
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define LSOne(S) (S & (-S))
#define EPS 1e-9
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pd;
typedef tree<pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0); // FOR QUERY PROBLEM DON'T FORGET TO UNCOMMENT THIS
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    int ans = 1e9;
    for(int i = 0; i+m-1 < n; ++i)
    {
        int curr = 0;
        for(int j = 0; j < m; ++j)
        {
            curr += (s[i+j] != t[j]);
        }
        ans = min(ans, curr);
    }
    cout << ans << "\n";
    return 0;
}
 
/*
 
*/  

Measured memory_bytes: 3640
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

const ll mod=998244353;

ll n,k,l[maxn],r[maxn],dp[maxn],pre[maxn];

int main()
{
	n=read(); k=read(); dp[1]=1; pre[1]=1;
	rep(i,1,k) l[i]=read(),r[i]=read();
	for(ll i=2;i<=n;i++)
	{
		rep(j,1,k)
		{
			if(i>=l[j])
			{
				dp[i]=(dp[i]+pre[i-l[j]]-pre[max(0ll,i-r[j]-1)]+mod)%mod;
			}
		}
		pre[i]=(pre[i-1]+dp[i])%mod;
	}
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 6768
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define log(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}



// TODO: write
int main() {
  int a,b;cin>>a>>b;
  print(a*b);
  
  return 0;
}


Measured memory_bytes: 3604
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

ll N;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> N;
    solve();
}

// 1 ≤ N ≤ 9
// N は整数である。

// ll N
// 設定できるパスワードが何種類であるかを出力せよ。
void solve(){
    cout<<N*N*N<<endl;    
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		int w = sc.nextInt();

		sc.close();
		String ans = "safe";
		if (w >= s ) {
			ans = "unsafe";
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 27036
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=105;
int n,m,K,mo;
int C[N][N],f[N][N],g[N][N];
int P[N][N*N],IP[N][N*N];
int power(int x,int y){
	int s=1;
	for (;y;y/=2,x=1ll*x*x%mo)
		if (y&1) s=1ll*s*x%mo;
	return s; 
}
int main(){
	scanf("%d%d%d%d",&n,&m,&K,&mo);
	For(i,0,N-1) C[i][0]=1;
	For(i,0,K) P[i][0]=IP[i][0]=1;
	For(i,0,K) IP[i][1]=power(i,mo-2);
	For(i,0,K) For(j,1,n*m) P[i][j]=1ll*P[i][j-1]*i%mo;
	For(i,0,K) For(j,1,n*m) IP[i][j]=1ll*IP[i][j-1]*IP[i][1]%mo;
	For(i,1,N-1) For(j,1,i)
		C[i][j]=(C[i-1][j-1]+C[i-1][j])%mo;
	f[0][0]=1;
	For(i,1,K){
		For(j,0,n) For(k,0,m) f[j][k]=1ll*f[j][k]*P[i][(n-j)*(m-k)]%mo*IP[K-i+1][j*k]%mo;
		memset(g,0,sizeof(g));
		For(j,0,n) For(k,0,m) For(jj,0,n-j)
			g[j+jj][k]=(g[j+jj][k]+1ll*f[j][k]*C[jj+j][j])%mo;
		memset(f,0,sizeof(f));
		For(j,0,n) For(k,0,m) For(kk,0,m-k)
			f[j][k+kk]=(f[j][k+kk]+1ll*g[j][k]*C[kk+k][k])%mo;
		For(j,0,n) For(k,0,m) f[j][k]=1ll*f[j][k]*P[K-i+1][j*k]%mo;
		if (K!=i){
			For(j,0,n) For(k,0,m) f[j][k]=1ll*f[j][k]*IP[K-i][j*k]%mo;
			memset(g,0,sizeof(g));
			For(j,0,n) For(k,0,m) For(jj,0,n-j)
				g[j+jj][k]=(g[j+jj][k]+1ll*f[j][k]*(jj&1?mo-C[jj+j][j]:C[jj+j][j]))%mo;
			memset(f,0,sizeof(f));
			For(j,0,n) For(k,0,m) For(kk,0,m-k)
				f[j][k+kk]=(f[j][k+kk]+1ll*g[j][k]*(kk&1?mo-C[kk+k][k]:C[kk+k][k]))%mo;
			For(j,0,n) For(k,0,m) f[j][k]=1ll*f[j][k]*IP[i][(n-j)*(m-k)]%mo*P[K-i][j*k]%mo;
		}
	}
	printf("%d",f[n][m]);
}

Measured memory_bytes: 9216
from collections import Counter, deque

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

now_cnt = len(list(set(A)))

if (now_cnt <= k):
    print(0)
    exit()

c = Counter(A)
c_sorted = sorted(c.items(), key=lambda x: x[1])
dec = now_cnt - k
cnt = 0
L = deque()

for (i, v) in c_sorted:
    L.append([i, v])

while True:
    if (dec != 0):
        L[0][1] -= 1
        L[-1][1] += 1
        cnt += 1
    else:
        print(cnt)
        exit()

    if (L[0][1] == 0):
        L.popleft()
        dec -= 1

print(cnt)


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

#define ln '\n'
#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 FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t, x;
    cin >> t >> x;
    cout << fixed << setprecision(4) << (double)t / x << ln;
    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++)

int main(){
  int N, K, Q; cin >> N >> K >> Q;
  vector<int> A(N); rep(i, N) cin >> A[i];
  vector<int> As(A);

  sort(As.begin(), As.end());
  const int INF = 1e9 + 10;
  int ans = INF;

  rep(minnum, N) {
    int minA = As[minnum];
    vector<vector<int>> vv(1);
    int v = 0;
    rep(i, N) {
      if (A[i] < minA) {
        vv.push_back(vector<int>());
        v++;
      } else {
        vv[v].push_back(A[i]);
      }
    }
    vector<int> vec;
    for (auto& x : vv) {
      sort(x.begin(), x.end());
      rep(k, x.size() - K + 1) vec.push_back(x[k]);
    }
    sort(vec.begin(), vec.end());
    if(vec.size() < Q) continue;
    ans = min(ans, vec[Q - 1] - vec[0]);
  }
  cout << ans << endl;
}


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

void solve()
{
    int n;cin>>n;
    pair<double,double>xy[n];
    REP(i,n){
        double x,y;cin>>x>>y;
        xy[i]={x,y};
    }
    double d[n][n];
    REP(i,n)REP(j,n){
        d[i][j]=sqrt((xy[i].first-xy[j].first)*(xy[i].first-xy[j].first)+(xy[i].second-xy[j].second)*(xy[i].second-xy[j].second));
        d[j][i]=d[i][j];
    }
    int p[n];REP(i,n)p[i]=i;
    double sum=0,cnt=0;
    do{
        REP(i,n-1)sum+=d[p[i]][p[i+1]];
        cnt++;
    }while(next_permutation(p,p+n));
    cout<<setprecision(20)<<sum/cnt<<endl;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


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

public class Main {

    private static int[] number;
    private static char[] color;
    private static int[] combination;
    private static int[][] box;

    public static void main(String[] args){

        Scanner scn = new Scanner(System.in);
        int count = scn.nextInt();

        for(int i = 0; i < count; i++){
            number = new int[9];
            color = new char[9];
            combination = new int[3];

            for(int j = 0; j < 9; j++) number[j] = scn.nextInt();
            for(int j = 0; j < 9; j++) color[j] = scn.next().charAt(0);
            box = new int[3][3];


            if(solve(0)){
                System.out.println("1");
            }
            else{
                System.out.println("0");
            }
        }
    }

    public static boolean solve(int n){

        if(n == 9){
            for(int i = 0; i < 3; i++){
                //三色同じか判定
                if( color[box[i][0]]!= color[box[i][1]] || color[box[i][1]] != color[box[i][2]] ) {
                    return false;
                }
            }

            for(int i = 0; i < 3; i++){
                int[] tmp = new int[3];

                for(int j = 0; j < 3; j++) {
                    tmp[j] = number[box[i][j]];
                }
                Arrays.sort(tmp);
                if( !( tmp[0] == tmp[1] && tmp[1] == tmp[2] || tmp[0] + 1 == tmp[1] && tmp[1] + 1 == tmp[2] ) ){
                    return false;
                }
            }
            return true;
        }

        for(int i = 0; i < 3; i++){
            if(combination[i] == 3) continue;
            box[i][combination[i]] = n;
            combination[i]++;
            if( solve(n + 1) ) return true;
            combination[i]--;
        }
        return false;
    }
}



Measured memory_bytes: 31980