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

typedef long long ll;


void solve(std::string S, std::string T){
  ll Ss = (ll) S.size();
  ll Ts = (ll) T.size();
  ll rv = Ts;
  for (ll i = 0; i < Ss; ++i) {
    if (i + Ts > Ss) {
      break;
    }
    ll trv = 0;
    for (ll j = 0; j < Ts; ++j) {
      trv += (S[i+j] != T[j]);
    }
    rv = min(trv, rv);
  }
  cout << rv << endl;
}

int main() {
  std::string S;
  std::cin >> S;
  std::string T;
  std::cin >> T;
  solve(S, T);
  return 0;
}


Measured memory_bytes: 3628
package main

import (
	"fmt"
)

const mod = 1000000007

func main() {
	var l string
	fmt.Scan(&l)

	count := make([][]int,len(l)+1)
	for i := 0; i < len(l)+1; i++ {
		count[i] = append(make([]int,2))
	}
	count[0][1] = 0
	count[0][0] = 1
	for i, e := range l {
		if string(e) == "1" {
			count[i+1][0] = count[i][0]*2%mod
			count[i+1][1] = (count[i][1]*3+count[i][0])%mod
		} else {
			count[i+1][0] = count[i][0]
			count[i+1][1] = count[i][1]*3%mod
		}
	}

	ans := (count[len(l)][0]+count[len(l)][1])%mod

	fmt.Println(ans)
}


Measured memory_bytes: 4736
n=int(input())
L=[[0,0,0] for _ in range(n)]
for i in range(n-1):
    c,s,f=map(int,input().split())
    L[i]=[c,s,f]
for j in range(n):
    ans=0
    if j==n:
        print(0)
    else:
        for k in range(len(L)-1):
            if k==0:
                ans+=L[k][1]
                ans+=L[k][0]
            else:
                ans=max(-(-ans//L[k][2])*L[k][2],L[k][1])
                ans+=L[k][0]
        print(ans)
        L.pop(0)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
char s[4];
int main(void) {
    scanf("%s", s);
    int a = s[0] & 15;
    int b = s[1] & 15;
    int c = s[2] & 15;
    int d = s[3] & 15;
    int ans = 0;
    ans = a + b + c;
    if(ans + d == 7) {
        printf("%d+%d+%d+%d=7\n", a, b, c, d);
        return 0;
    } else if(ans - d == 7) {
        printf("%d+%d+%d-%d=7\n", a, b, c, d);
        return 0;
    }
    ans = a + b - c;
    if(ans + d == 7) {
        printf("%d+%d-%d+%d=7\n", a, b, c, d);
        return 0;
    } else if(ans - d == 7) {
        printf("%d+%d-%d-%d=7\n", a, b, c, d);
        return 0;
    }
    ans = a - b + c;
    if(ans + d == 7) {
        printf("%d-%d+%d+%d=7\n", a, b, c, d);
        return 0;
    } else if(ans - d == 7) {
        printf("%d-%d+%d-%d=7\n", a, b, c, d);
        return 0;
    }
    ans = a - b - c;
    if(ans + d == 7) {
        printf("%d-%d-%d+%d=7\n", a, b, c, d);
        return 0;
    } else if(ans - d == 7) {
        printf("%d-%d-%d-%d=7\n", a, b, c, d);
        return 0;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("03")
#define ll long long
#define ld long double
#define fi first
#define se second

using namespace std;

int sz[500100], n, sol[1000][1000], nr[4000100], vf;
vector <int> v;
bool ok[500100];

int main() {
//	ifstream cin("tst.in");
	ofstream out("tst.out");
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int p = 1;
	int rat = 2;
	while (p <= 200000) {
		ok[p] = 1;
		sz[p] = rat;
		p += rat;
		rat++;
	}
	cin >> n;
	if (!ok[n]) {
		cout << "No";
		return 0;
	}
	int col = sz[n];
	int row = 2 * n / col;
	int pos = 0;
	for (int i = 1; i <= 400000; i++) {
		nr[++pos] = i;
		nr[++pos] = i;
	}
	int l = 2;
	int h = 1;
	while (l <= 1000) {
		int p1, p2;
		p1 = p2 = 1;
		for (int i = 1; i <= h; i++) {
			int it = nr[++vf];
			sol[h][p1++] = it;
			int it2 = nr[++vf];
			sol[p2++][l] = it2;
		}
		l++;
		h++;
	}	
	cout << "Yes\n" << col << '\n';
	for (int i = 1; i <= col; i++) {
		cout << row << ' ';
		for (int j = 1; j <= row; j++)
			cout << sol[j][i] << ' ';
		cout << '\n';
	} 
	for (int i = 1; i <= 30; i++, out << '\n')
		for (int j = 1; j <= 31; j++)
			out << sol[i][j] << ' ';
	return 0;
}

Measured memory_bytes: 11648
n=int(input())
l=[[None for i in range(3) ] for i in range(n)]
for i in range(n):
    a,b,c=list(map(int,input().split()))
    l[i][0]=a
    l[i][1]=b
    l[i][2]=c
l1=[[None for i in range(3) ] for i in range(n)]
a=l1[0][0]=l[0][0]
b=l1[0][1]=l[0][1]
c=l1[0][2]=l[0][2]
q=max(a,b,c)
for i in range(1,n):
    a=l1[i][0]=l[i][0]+max(l1[i-1][1],l1[i-1][2])
    b=l1[i][1]=l[i][1]+max(l1[i-1][0],l1[i-1][2])
    c=l1[i][2]=l[i][2]+max(l1[i-1][1],l1[i-1][0])
    if q<max(a,b,c):
        q=max(a,b,c)
print(q)


Measured memory_bytes: 45612
#!/usr/bin/env python3
#ABC142 F

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m = LI()
edge = [[] for _ in range(n)]
for _ in range(m):
    a,b = LI()
    edge[a-1].append(b-1)

visited = [False]*n
def dfs(s):
    if visited[s]:
        return True
    visited[s] = True
    for i in edge[s]:
        if dfs(i):
            return True
    visited[s] = False
    return False

for i in range(n):
    if dfs(i):
        print(0)
        break
else:
    print(-1)


Measured memory_bytes: 46428
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
  int x=0,y=0,z=INF,n=0,w=0;
  std::cin >> x;
  std::vector<int> v(x);
  rep(i,x){
    std::cin >> v[i];
  }
  sort(all(v));
  repo(i,v[0],v[x-1]+1){
    Rep(j,x){
      y+=(v[j]-i)*(v[j]-i);
    }
    if(z>y)z=y;
    y=0;
  }
  std::cout << z << '\n';
}


Measured memory_bytes: 256
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B = il()
    for n in range(1100):
        if int(n*0.08) == A and int(n*0.1) == B:
            print(n)
            exit()
    else:
        print(-1)



if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	t := nextInt()
	x := nextInt()
	fmt.Println(float64(t) / float64(x))
}

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

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

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int f=0,p,k,t,a[10002],i;
int main()
{
    cin>>k>>t;
    for(i=0;i<t;i++) 
		cin>>a[i],f+=a[i];
    for(i=0;i<t;i++)
	{
        p=a[i]*2-f-1;        
        if(p>=0)
		{
            cout<<p<<endl;
            return 0;
        }
    }
    cout<<"0"<<endl;
    return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

char** alloc_masu(int H, int W){
	int i;
	char** A;
	A = malloc(sizeof(char*)*H);
	for(i=0;i<H;i++){
		A[i] = malloc(sizeof(char)*(H+1));
	}
	return A;
}
int evaluate_masu(char** A, int H, int W){
	int i=0, j=0;
	int bottomtrack,righttrack;
	int toptrack, lefttrack;
	while((i<H&&j<W)){
		bottomtrack = (i==H-1?0:A[i+1][j] == '#');
		righttrack = (j==W?0:A[i][j+1] == '#');
		toptrack = (i==0?0:A[i-1][j] == '#');
		lefttrack = (j==0?0:A[i][j-1] == '#');
		if(righttrack&&bottomtrack)return 0;
		if(lefttrack&&toptrack)return 0;
		if(i==H-1&&j==W-1)return 1;
		if(righttrack)j++;
		if(bottomtrack)i++;
	}
	return 0;
}

int main(){
	int H, W;
	char **A;
	int i,result;
	scanf("%d", &H);
	scanf("%d", &W);
	A = alloc_masu(H, W);
	for(i=0;i<H;i++){
		scanf("%s", A[i]);
	}
	result = evaluate_masu(A,H,W);
	printf("%s", (result?"Possible":"Impossible"));
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

struct Node{
    long long x, y, p;
};

const long long INF = (1LL << 60);

int main(){

    int N;
    cin >> N;
    vector<long long> x(N);
    vector<long long> y(N);
    vector<Node> node(N);

    for(int i = 0; i < N; i++){
        int p;
        cin >> x[i] >> y[i] >> p;
        node[i] = (Node){x[i], y[i], p};
    }

    vector<vector<int>> minDistX((1 << N), vector<int>(N));
    for(int i = 0; i < (1 << N); i++){
        vector<long long> xLine(1, 0);
        xLine.push_back(-INF);
        xLine.push_back(INF);

        for(int k = 0; k < N; k++){
            if(i & (1 << k)){
                xLine.push_back(x[k]);
            }
        }

        sort(xLine.begin(), xLine.end());
        for(int k = 0; k < N; k++){
            Node tempNode = node[k];

            auto temp1 = lower_bound(xLine.begin(), xLine.end(), tempNode.x);
            long long rightX = *temp1;
            temp1--;
            long long leftX = *temp1;
            minDistX[i][k] = min(rightX - tempNode.x, tempNode.x - leftX);
        }
    }

    vector<vector<int>> minDistY((1 << N), vector<int>(N));
    for(int i = 0; i < (1 << N); i++){
        vector<long long> yLine(1, 0);
        yLine.push_back(-INF);
        yLine.push_back(INF);

        for(int k = 0; k < N; k++){
            if(i & (1 << k)){
                yLine.push_back(y[k]);
            }
        }

        sort(yLine.begin(), yLine.end());
        for(int k = 0; k < N; k++){
            Node tempNode = node[k];
            
            auto temp1 = lower_bound(yLine.begin(), yLine.end(), tempNode.y);
            long long upperY = *temp1;
            temp1--;
            long long lowerY = *temp1;
            minDistY[i][k] = min(upperY - tempNode.y, tempNode.y - lowerY);
        }
    }

    vector<long long> ans(N + 1, INF);
    int upper = 1;
    for(int i = 0; i < N; i++){
        upper *= 3;
    }
    for(int i = 0; i < upper; i++){
        int xLines = 0;
        int yLines = 0;
        int temp = i;
        int lineCnt = 0;

        for(int j = 0; j < N; j++){
            int r = temp % 3;
            if(r == 0){
                
            }
            else if(r == 1){
                xLines += (1 << j);
                lineCnt++;
            }
            else{ // r == 2
                yLines += (1 << j);
                lineCnt++;
            }
            temp /= 3;
        }

        long long tempSum = 0;

        for(int j = 0; j < N; j++){
            int tempDist = min(minDistX[xLines][j], minDistY[yLines][j]);
            tempSum += tempDist * node[j].p;
        }

        ans[lineCnt] = min(ans[lineCnt], tempSum);
    }

    for(int i = 0; i <= N; i++){
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 9864
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
char c[55][55];
bool visited[55][55];
int d[55][55];
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
queue<P> Q;

int main()
{
	int H,W;
	cin >> H >> W;
	int cntW = 0;
	rep(i,H)
	{
		rep(j,W)
		{
			cin >> c[i][j];
			if (c[i][j] == '.') cntW++;
		}
	}
	rep(i,55)
	{
		rep(j,55)
		{
			d[i][j] = 1e8;
		}
	}
	d[0][0] = 0;
	Q.push(P(0,0));
	while(!Q.empty())
	{
		P q = Q.front();
		int f = q.first, s = q.second;
		Q.pop();
		if (visited[f][s]) continue;
		visited[f][s] = true;
		rep(i,4)
		{
			int xx = f+dx[i], yy = s+dy[i];
			if (xx >= 0 && xx < H && yy >= 0 && yy < W && c[xx][yy] == '.')
			{
				d[xx][yy] = min(d[xx][yy],d[f][s]+1);
				Q.push(P(xx,yy));
			}
		}
	}
	/*
	rep(i,H)
	{
		rep(j,W)
		{
			cout << d[i][j] << " ";
		}
		cout << endl;
	}
	*/
	if (d[H-1][W-1] == 1e8) cout << -1 << endl;
	else cout << cntW - d[H-1][W-1] - 1 << endl;
	return 0;
}

Measured memory_bytes: 3648
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def gcd(m, n):
    # 入力を m, n (m ≧ n) とする。
    tmp = max(m,n)
    n = min(m,n)
    m = tmp
    # n = 0 なら、 m を出力してアルゴリズムを終了する。
    if n == 0:
        return m
    # m を n で割った余りを新たに n とし、更に 元のnを新たにm とし 2. に戻る。
    return gcd(n, m % n)

def lcm(m, n):
    return m*n//gcd(m,n)


a,b = get_nums_l()
print(lcm(a,b))

Measured memory_bytes: 38512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}


int main() {
    int n,k,r,s,p;
    string t;
    ll ans = 0;
    cin >> n >> k >> r >> s >> p;
    cin >> t;
    for (int i = 0; i < n; ++i) {
        if(i < k){
            if(t[i] == 'r') ans += p;
            if(t[i] == 's') ans += r;
            if(t[i] == 'p') ans += s;
        }else{
            if(t[i-k] == t[i]) t[i] = '#';
            else{
                if(t[i] == 'r') ans += p;
                if(t[i] == 's') ans += r;
                if(t[i] == 'p') ans += s;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
F =->{_1.split.map &:to_i}
D = gets.to_i
C,*S = (0..D).map{F[gets]}
T,L = F[$<.read], [0]*26
i=s = 0
T.each {|t|
  s += S[i][t-=1]
  L[t] = i+=1
  p s -= 26.times.sum {C[_1]*(i-L[_1])}
}

Measured memory_bytes: 14392
def available(start, end, S, step=None):
    if step is not None:    #   追い越し処理
        S = S[:step] + "#" + S[step+1:]
    for i in range(start, end):
        if S[i] == "#" and S[i+1] == "#":
            return False, S
    return True, S
    
def overtake(start, end, S):
    for i in range(start, end+1):
        if S[i-1] == "." and S[i] == "." and S[i+1] == ".":
            step = i
            return True, step
    return False, None

N, A, B, C, D = map(int, input().split())
S = "." + input() + "."

if D > C:   #   追い越しが不要な時
    judge1, S = available(A, C, S)
    judge2, S = available(B, D, S)
    if judge1 and judge2:
        print("Yes")
    else:
        print("No")
else:   #   追い越しが必要な時
    overtakable, step = overtake(B, D, S)
    if overtakable:   #   追い越しが可能な時
        judge1, S = available(B, D, S)
        judge2, S = available(A, C, S, step=step)
        if judge1 and judge2:
            print("Yes")
        else:
            print("No")
    else:   #   追い越しができない時
        print("No")
        

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)

int tree[4*500005];
int n;
string s;

void update(int s,int e,int indx,int S,int E,char val){
    if(s>E || e<S)return;
    if(s==e){
        tree[indx]=(1LL<<(val-'a'));
        return;
    }
    int mid=(s+e)/2;
    update(s,mid,indx*2+1,S,E,val);
    update(mid+1,e,indx*2+2,S,E,val);
    tree[indx]=tree[indx*2+1]|tree[indx*2+2];
}

int que(int s,int e,int indx,int S,int E){
    if(s>E || e<S)return 0;
    if(s>=S && e<=E){
        return tree[indx];
    }
    int mid=(s+e)/2;
    return que(s,mid,indx*2+1,S,E)|que(mid+1,e,indx*2+2,S,E);
}

signed main(){
    FASTER;
    cin>>n>>s;
    for(int i=0;i<n;i++){
        update(0,n-1,0,i,i,s[i]);
    }
    int q;cin>>q;
    while(q--){
        int a;cin>>a;
        if(a==1){
            int a;cin>>a;
            a--;
            char c;cin>>c;
            update(0,n-1,0,a,a,c);
        }else{
            int x,y;cin>>x>>y;x--,y--;
            int k = que(0,n-1,0,x,y);
            int ans=0;
            while(k){ans+=k&1;
                k/=2;
                
            }
            cout<<ans<<"\n";
        }
    }
}

Measured memory_bytes: 11164
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define ld          long double
#define endl        "\n"

const int mod = 1e9+7;

inline int add(int a, int b) { int res = a + b; if(res >= mod) res -= mod;  return res; }
inline int sub(int a, int b) { int res = a - b; if(res < 0) res += mod; return res;}
inline int mul(int a, int b) { return (a * b)%mod; }

void solve() {
    int p, n;
    cin >> p >> n;
    int a[n];
    for(int i=0; i<n; i++) cin >> a[i];
    int mx = 0;
    for(int i=0; i+1<n; i++) mx = max(mx, a[i+1] - a[i]);
    mx = max(mx, a[0] + p - a[n-1]);
    int ans = p - mx;
    cout << ans << endl;
}

signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(12);

    int T = 1;
    //cin >> T;
    for(int tt=1; tt<=T; tt++) {
    	solve();
    }
    return 0;
}

Measured memory_bytes: 1792
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

n = int(input())

print(a[n-1])

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

n = int(input())
a = [int(x) for x in input().split()]
a.sort()

ans = [-1, 0, 0]

import bisect

i = a[-1]
idx = [bisect.bisect_left(a, i / 2), bisect.bisect_left(a, i / 2) - 1]

if abs(i / 2 - a[idx[0]]) < abs(i // 2 - a[idx[1]]):
    print(i, a[idx[0]])    
else:
    print(i, a[idx[1]])


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

struct Graph
{
    int N;
    struct Edge { int source, target, weight; };
    vector<vector<Edge>> adjacency_list;

    Graph(int N) : N(N), adjacency_list(N) {}

    int add_vertex()
    {
        adjacency_list.push_back({});
        return N++;
    }

    void add_edge(int a, int b, int w) { adjacency_list[a].push_back({a, b, w}); }

    int distance(const int start, const int finish) const
    {
        auto seen = vector<bool>(N);
        auto distances = vector<int>(N, -1);

        struct State { int v, distance; };
        const auto compare = [](const State a, const State b) { return a.distance > b.distance; };
        auto queue = std::priority_queue<State, vector<State>, decltype(compare)>(compare, {{start, 0}});
        queue.push({start, 0});

        while (!queue.empty())
        {
            auto s = queue.top(); queue.pop();
            if (seen[s.v]) continue;
            seen[s.v] = true;
            distances[s.v] = s.distance;

            for (const auto e : adjacency_list[s.v])
                queue.push({e.target, s.distance+e.weight});
        }

        return distances[finish];
    }
};

struct Subway { int source, target, company; };

int solve(const int N, const vector<Subway>& subways)
{
    auto graph = Graph(N);

    auto ids = map<pair<int, int>, int>();
    const auto id = [&](int station, int company)
    {
        if (ids.count({station, company})) return ids[{station, company}];
        else
        {
            const auto substation = ids[{station, company}] = graph.add_vertex();
            graph.add_edge(station, substation, 1);
            graph.add_edge(substation, station, 0);
            return substation;
        }
    };

    for (const auto s : subways)
    {
        const auto v = id(s.source, s.company), w = id(s.target, s.company);
        graph.add_edge(v, w, 0);
        graph.add_edge(w, v, 0);
    }

    return graph.distance(0, N-1);
}

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

    auto subways = vector<Subway>();
    for (auto i = 0; i < M; i++)
    {
        int a, b, c; cin >> a >> b >> c;
        a--; b--;
        subways.push_back({a, b, c});
    }

    cout << solve(N, subways) << endl;
}


Measured memory_bytes: 64600
#include <iostream>

using namespace std;

const int NMAX = 2000 + 5;
const int MOD = 1000000000 + 7;

int raise(int a, int b) {
    if (!b)
        return 1;
    else if (b & 1)
        return (1LL * a * raise(a, b - 1)) % MOD;
    else {
        int aux = raise(a, b >> 1);
        return (1LL * aux * aux) % MOD;
    }
}

int inv(int nr) {
    return raise(nr, MOD - 2);
}

int facts[NMAX * NMAX];
int invFacts[NMAX * NMAX];

void precalcFacts() {
    facts[0] = 1;
    for (int i = 1; i < NMAX * NMAX; ++ i)
        facts[i] = (1LL * i * facts[i - 1]) % MOD;

    invFacts[NMAX * NMAX - 1] = inv(facts[NMAX * NMAX - 1]);
    for (int i = NMAX * NMAX - 2; i >= 0; -- i)
        invFacts[i] = ((i + 1LL) * invFacts[i + 1]) % MOD;
}

inline int choose(int n, int k) {
    return ((1LL * facts[n] * invFacts[k]) % MOD * invFacts[n - k]) % MOD;
}

int dp[NMAX][NMAX];

int main()
{
    precalcFacts();

    int N, K;
    cin >> N >> K;

    K --;
    if (K == 0) {
        cout << "1\n";
        return 0;
    }

    dp[0][0] = 1;
    for (int i = 0; i <= N; ++ i)
        for (int j = i; j <= N; ++ j)
            if (i + j) {
                //We have i 0s left to place and j firsts to place
                if (i) //Place a 0
                    dp[i][j] = dp[i - 1][j];
                //Place a first
                dp[i][j] = (dp[i][j] + (1LL * dp[i][j - 1] * j) % MOD * choose(i + K * j - 1, K - 1)) % MOD;
            }

    cout << dp[N][N] << '\n';
    return 0;
}


Measured memory_bytes: 45440
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
//using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	string s ; cin >> s ;
	int k ; cin >> k ;
	set<string> ok ;
	vector<string> vec ;
	int n = s.size() ;
	for(int i=0;i<n;i++){
		string t ;
		for(int j=i;j<n;j++){
			t += s.at(j) ;
			if(vec.size()<5&&!ok.count(t)){
				vec.push_back(t) ;
				ok.insert(t) ;
				sort(vec.begin(),vec.end()) ;
			}
			if(!ok.count(t)&&t<vec.at(vec.size()-1)){
				ok.insert(t) ;
				vec.push_back(t) ;
				sort(vec.begin(),vec.end()) ;
				vec.pop_back() ;
			}
		}
	}
	sort(vec.begin(),vec.end()) ;
	cout << vec.at(k-1) << endl ;
}


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

int main(int argc, char const *argv[])
{
	string s;
	cin>>s;
	long long cnt=0,ans=0;
	for (int i = 0; i < s.size(); ++i)
	{
		if (s[i]=='B')
		{
			++cnt;
		}
		else
		{
			ans+=cnt;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

// Optimization

//#pragma GCC optimize("O3")
#define endl '\n'

// Shortcut

#define int long long
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)

// I/O & Debug

#define PrintV(a) Fora(iiii, a) cout << iiii << ' '; cout << endl;
#define PrintVl(a) Fora(iiii, a) cout << iiii << endl;
#define PrintA(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << ' '; cout << endl;
#define PrintAl(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
/*
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << endl;
    DEB(++it, args...);
}
*/

// Functions

//#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define bend(a) a.begin(), a.end()
#define rbend(a) a.rbegin(), a.rend()
#define mset(a) memset(a, 0, sizeof(a))
#define mset1(a) memset(a, 1, sizeof(a))
#define msetn1(a) memset(a, -1, sizeof(a))
#define msetinf(a) memset(a, 0x3f, sizeof(a))
#define gcd __gcd
#define __builtin_popcount __builtin_popcountll
//mt19937 rando(chrono::steady_clock::now().time_since_epoch().count());

// Data Structure

#define pque priority_queue
#define mts multiset
#define y0 _y0_
#define y1 _y1_
#define div divi
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;

const int N = 3e5 + 5, mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9, inf = 1e18 + 7;
const ll infll = 1e18 + 7;

int n, m, k;
int x, y, z;
int ans, tmp, cnt, idx, mx = -inf, mn = inf;
string s, t;
int a[N], b[N];
vi adj[N];

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
int q = 1;
// cin >> q;
while (q--){
    cin >> n;
    ForE(i, 1, n){
        cin >> a[i];
        if (a[i] % 2 == 0){
            if (a[i] % 3 != 0 && a[i] % 5 != 0) Ptest("DENIED");
        }
    }
    cout << "APPROVED";
}
}

/*
==================================+
INPUT:                            |
------------------------------    |

------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |

------------------------------    |
==================================+
*/

Measured memory_bytes: 10624
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<algorithm>
using namespace std;
const long long MAXN=100005,MAXP=21000;

long long prime[MAXP],pcnt;
bool npr[MAXP];

void LinerSieve()
{
	npr[1]=true;
	for(long long i=2;i<MAXP;i++)
	{
		if(!npr[i])
			prime[++pcnt]=i;
		for(long long j=1;j<=pcnt&&prime[j]*i<MAXP;j++)
		{
			npr[prime[j]*i]=true;
			if(i%prime[j]==0)
				break;
		}
	}
}
long long ans;
map<long long,long long> cnt;
long long n,A[MAXN];
long long F(long long x)
{
	long long res=1;
	for(long long j=1;j<=pcnt&&prime[j]*prime[j]*prime[j]<=x;j++)
		if(x%prime[j]==0)
		{
			long long cnt=0;
			while(x%prime[j]==0)
				x/=prime[j],cnt++;
			cnt%=3;
			for(long long k=1;k<=cnt;k++)
				res*=prime[j];
		}
	if(x!=1)
		res*=x;
	return res;
}

int main()
{

	LinerSieve();
    scanf("%lld",&n);
    for(long long i=1;i<=n;i++)
        scanf("%lld",&A[i]);
	for(long long i=1;i<=n;i++)
	{
		A[i]=F(A[i]);
		cnt[A[i]]++;
		//printf("(%lld)\n",A[i]);
	}
	
	bool flag=false;
	for(long long i=1;i<=n;i++)
	{
		if(A[i]==1)
			flag=true;
		else if(cnt[A[i]])
		{
			long long tmp=floor(sqrt(A[i])+0.5);
			long long y;
			if(tmp*tmp==A[i])
				y=tmp;
			else
				y=A[i]*A[i];
			y=F(y);
			//printf("[%lld][%lld]\n",A[i],y);
			if(cnt.count(y))
			{
				//puts("1");
				ans+=max(cnt[y],cnt[A[i]]);
				cnt[y]=cnt[A[i]]=0;
			}
			else
			{
				ans+=cnt[A[i]];
				cnt[A[i]]=0;
			}
		}
	}
	if(flag)
		ans++;
	printf("%d\n",ans);

    fclose(stdin);
    fclose(stdout);
    return 0;
}


Measured memory_bytes: 9344
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 998244353
#define N 200005

int main()
{
    ll x;
    cin>>x;
    ll ans=1000*(x/500);
    x%=500;
    ans+=(x/5)*5;
    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define ESP (1e-10)
using namespace std;

typedef struct Point {
	double x; 
	double y;

	Point() { }

	Point(double x, double y) :x(x), y(y) { }

	Point operator+(Point& p) {
		return Point(x + p.x, y + p.y);
	}

	Point operator-(Point& p) {
		return Point(x - p.x, y - p.y);
	}
};

typedef Point Vector;

 struct Line {
	Point p1, p2;
	Line() {}
	Line(const Point& a,const Point& b) : p1(a),p2(b) { }
};

 typedef Line Segment;

double abs(Point p1, Point p2) {
	double norm = (p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y);
	return sqrt(norm);
}

double product(Vector v1, Vector v2) {
	return v1.x*v2.x + v1.y*v2.y;
}

double cross(Vector p1, Vector p2) {
	return p1.x*p2.y - p1.y*p2.x;
}

int ccw(Point p0, Point p1, Point p2) {
	Vector v0 = p1 - p0;
	Vector v1 = p2 - p0;
	if (cross(v0, v1) > ESP) return 1;   //p0,p1,p2??????????¨???????
	if (cross(v0, v1) < -ESP) return -1;   //p0,p1,p2???????¨???????
	if (product(v0, v1) < -ESP) return 2;  //p2,p0,p1????????§????????´??????
	if (abs(p0, p1) < abs(p0, p2)) return -2;  //p0,p1,p2????????§????????´??????
	return 0;   //p2?????????(p0,p1)???
}

bool intersect(Point p0, Point p1, Point p2, Point p3) {
	return (ccw(p0, p1, p2)*ccw(p0, p1, p3) <= 0&&ccw(p2,p3,p0)*ccw(p2,p3,p1)<=0);
	//?????????????????????????????¶
}

bool intersect(Segment s1, Segment s2) {
	return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}

double DistanceLP(Line l, Point p) {
	return abs(cross(l.p2 - l.p1, p - l.p1)/abs(l.p1,l.p2));
}

double DistanceSP(Segment s, Point p) {
	if (product(s.p2 - s.p1, p - s.p1) < 0.0) return abs(p, s.p1);
	if (product(s.p1 - s.p2, p - s.p2) < 0.0) return abs(p, s.p2);
	return DistanceLP(s, p);
}

double DistanceSS(Segment s1, Segment s2) {
	if (intersect(s1, s2)) return 0.0;
	return min(min(DistanceSP(s1, s2.p1), DistanceSP(s1,s2.p2)), min(DistanceSP(s2, s1.p1), DistanceSP(s2, s1.p2)));
}

int main() {
	Segment s0,s1;
	int q; 
	cin >> q;
	for (int i = 0;i < q;i++) {
		cin >> s0.p1.x; cin >> s0.p1.y;
		cin >> s0.p2.x; cin >> s0.p2.y;
		cin >> s1.p1.x; cin >> s1.p1.y;
		cin >> s1.p2.x; cin >> s1.p2.y;
		cout <<setprecision(20)<< DistanceSS(s0, s1) << endl;
	}
}

Measured memory_bytes: 3256
#include<iostream>
#include<queue>
#include<vector>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int>* adj = new vector<int>[n];
	int* dist = new int[n];
	int t1, t2 ,t3;
	for (int i = 0;i < n;i++) {
		cin >> t1;
		t1--;
		cin >> t2;
		for (int i = 0;i < t2;i++) {
			cin >> t3;
			adj[t1].push_back(t3 - 1);
		}
		dist[i] = -1;
	}
	queue<pair<int, int> > q;
	q.push(make_pair(0, 0));
	dist[0] = 0;
	while (!q.empty()) {
		pair<int, int> p = q.front();
		q.pop();
		for (int i = 0;i < adj[p.second].size();i++) {
			t1 = adj[p.second][i];
			if (dist[t1] == -1){
				q.push(make_pair(p.first + 1, t1));
				dist[t1] = p.first + 1;
			}
		}
	}
	for (int i = 0;i < n;i++) {
		cout << i + 1 << " " << dist[i] << endl;
	}

}


Measured memory_bytes: 3152
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def patition(a, p, r):
    x = a[r]
    i = p-1
    for j in range(p, r):
        if a[j] <= x:
            i += 1
            a[i], a[j] = a[j], a[i]
    a[i+1], a[r] = a[r], a[i+1]
    return i+1


n = int(stdin.readline())
data = [int(s) for s in stdin.readline().split()]
pat = patition(data, 0, len(data)-1)
print(*data[:pat], end=' ')
print('[{}]'.format(data[pat]), *data[pat+1:])

Measured memory_bytes: 12712
#include <iostream>
using namespace std;
using ll = long long;

#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=(n);i>=0;--i)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"
const int MOD = 1e9+7;

int H, W, K;
ll dp2[8];
ll left(int k) {
  if (k <= 0)
    return 1;
  if (k == 1)
    return 2;
  if (dp2[k] != -1)
    return dp2[k];
  int ans = 0;
  rep(bit, 1<<k) {
    bool ok = true;
    rep(i, k-1) {
      if ((bit >> i) & 1 == 1 && (bit >> (i+1)) & 1 == 1)
        ok = false;
    }
    if (ok)
      ++ans;
  }
  return dp2[k] = ans;
}
ll right(int k) {
  return left(W-1-k);
}
int main() {
  fill(dp2, dp2+8, -1);

  cin.tie(0); ios::sync_with_stdio(false);
  in(H); in(W); in(K);
  --K;

  ll dp[H+1][W]; // dp[h][k] = 高さhのときk番目にいるパターン数
  rep(i, H+1) rep(j, W) dp[i][j] = 0;
  // fill((int*)dp, (int*)dp+H, 0);
  dp[H][K] = 1;
  rrep(h, H) {
    if (h == 0)
      break;
    rep(k, W) {
      dp[h-1][k] = (left(k-1) * right(k+1) * dp[h][k]) % MOD;
      if (k > 0) {
        dp[h-1][k] += (left(k-2) * right(k+1) * dp[h][k-1]) % MOD;
        dp[h-1][k] %= MOD;
      }
      if (k+1 < W) {
        dp[h-1][k] += (left(k-1) * right(k+2) * dp[h][k+1]) % MOD;
        dp[h-1][k] %= MOD;
      }
    }
  }
  out(dp[0][0]);

  return 0;
}


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

string str;

int main(){
    while(getline(cin,str)){
        for(int i=0;i<26;i++){
            if(str.find("the")!=string::npos)break;
            if(str.find("this")!=string::npos)break;
            if(str.find("that")!=string::npos)break;

            for(int j=0;j<str.size();j++){
                if(!isalpha(str[j]))continue;
                str[j]=(str[j]-'a'+1)%26+'a';
            }
        }
        cout<<str<<endl;
    }
    return 0;
}

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

int main() {
  int a, b, x;
  cin >> a >> b;
  
  x = a * b;
  
  if (x % 2 == 0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc166/tasks/abc166_d

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

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

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

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

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

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

const ll INF = 1e18;

void solve();

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

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

  return 0;
}
#endif

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

  ll LIMIT = 1000;
  ll mi = -LIMIT;
  ll ma = LIMIT;

  for (ll a = mi; a <= ma; ++a)
    for (ll b = mi; b <= ma; ++b) {
      if (pow(a, 5) - pow(b, 5) == X) {
        cout << a << " " << b << "\n";
        throw exit_exception();
      }
    }
}


Measured memory_bytes: 4084
#include <cstdio>

int main() {
    int d, t, s;
    std::scanf("%d %d %d", &d, &t, &s);
    
    d -= t * s;
    if (d <= 0) {
        std::printf("Yes\n");
    } else {
        std::printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
long long a,b,c;
int main()
{
	cin>>a>>b>>c;
	if(a>b)swap(a,b);
	if(a>c)swap(a,c);
	if(b>c)swap(b,c);
	cout<<a+b<<endl;
	return 0;
}

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

#define pb push_back
using namespace std;
 
int main()
{
 
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

 	
    unsigned long long n,k;
    cin>>n>>k;
    n=n%k;
    if((k-n)>n){
        cout<<n;
    }
    else{
        cout<<k-n;
    }

	return 0;
}

Measured memory_bytes: 256
import fileinput

def main(str_list):
    str_list.sort()
    result = ""
    for s in str_list:
        result += s
    print(result)

if __name__ == '__main__':
    str_list = []
    for line in fileinput.input():
        str_list.append(line.rstrip())
    main(str_list[1:])


Measured memory_bytes: 3060
// Working program using Reader Class 
import java.io.*; 
import java.io.FileInputStream; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.*; 

public class Main 
{ 
	static class Reader 
	{ 
		final private int BUFFER_SIZE = 1 << 16; 
		private DataInputStream din; 
		private byte[] buffer; 
		private int bufferPointer, bytesRead; 

		public Reader() 
		{ 
			din = new DataInputStream(System.in); 
			buffer = new byte[BUFFER_SIZE]; 
			bufferPointer = bytesRead = 0; 
		} 

		public Reader(String file_name) throws IOException 
		{ 
			din = new DataInputStream(new FileInputStream(file_name)); 
			buffer = new byte[BUFFER_SIZE]; 
			bufferPointer = bytesRead = 0; 
		} 

		public String readLine() throws IOException 
		{ 
			byte[] buf = new byte[64]; // line length 
			int cnt = 0, c; 
			while ((c = read()) != -1) 
			{ 
				if (c == '\n') 
					break; 
				buf[cnt++] = (byte) c; 
			} 
			return new String(buf, 0, cnt); 
		} 

		public int nextInt() throws IOException 
		{ 
			int ret = 0; 
			byte c = read(); 
			while (c <= ' ') 
				c = read(); 
			boolean neg = (c == '-'); 
			if (neg) 
				c = read(); 
			do
			{ 
				ret = ret * 10 + c - '0'; 
			} while ((c = read()) >= '0' && c <= '9'); 

			if (neg) 
				return -ret; 
			return ret; 
		} 

		public long nextLong() throws IOException 
		{ 
			long ret = 0; 
			byte c = read(); 
			while (c <= ' ') 
				c = read(); 
			boolean neg = (c == '-'); 
			if (neg) 
				c = read(); 
			do { 
				ret = ret * 10 + c - '0'; 
			} 
			while ((c = read()) >= '0' && c <= '9'); 
			if (neg) 
				return -ret; 
			return ret; 
		} 

		public double nextDouble() throws IOException 
		{ 
			double ret = 0, div = 1; 
			byte c = read(); 
			while (c <= ' ') 
				c = read(); 
			boolean neg = (c == '-'); 
			if (neg) 
				c = read(); 

			do { 
				ret = ret * 10 + c - '0'; 
			} 
			while ((c = read()) >= '0' && c <= '9'); 

			if (c == '.') 
			{ 
				while ((c = read()) >= '0' && c <= '9') 
				{ 
					ret += (c - '0') / (div *= 10); 
				} 
			} 

			if (neg) 
				return -ret; 
			return ret; 
		} 

		private void fillBuffer() throws IOException 
		{ 
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); 
			if (bytesRead == -1) 
				buffer[0] = -1; 
		} 

		private byte read() throws IOException 
		{ 
			if (bufferPointer == bytesRead) 
				fillBuffer(); 
			return buffer[bufferPointer++]; 
		} 

		public void close() throws IOException 
		{ 
			if (din == null) 
				return; 
			din.close(); 
		} 
	} 
	 
	public static int gcd(int a, int b) 
    { 
        // Everything divides 0  
        if (a == 0 || b == 0) 
           return 0; 
       
        // base case 
        if (a == b) 
            return a; 
       
        // a is greater 
        if (a > b) 
            return gcd(a-b, b); 
        return gcd(a, b-a); 
    } 

	public static void main(String[] args) throws IOException 
	{ 
		//Reader scan=new Reader(); 
		Reader scan=new Reader();
		PrintWriter out=new PrintWriter(System.out);
		int n=scan.nextInt();
		out.print((n-2)*180);
		out.close();
	} 
} 

Measured memory_bytes: 19540
#include <iostream>

int main()
{
    while (true)
    {
        int h, w;
        std::cin >> h >> w;
        
        if (h == 0 && w == 0)
            break;
        else
        {
            for (int h_ = 0; h_ < h; ++h_)
            {
                for (int w_ = 0; w_ < w; ++w_)
                {
                    std::cout << '#';
                }
                
                std::cout << std::endl;
            }
            
            std::cout << std::endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3112
import itertools as it
N=int(input())
ans=0
K=list(map(int,input().split()))
for i in it.combinations_with_replacement(K,3):
  a=i[0]
  b=i[1]
  c=i[2]
  if a!=b and b!=c and c!=a:
    if a+b>c and b+c>a and c+a>b:
      ans+=1
print(ans)

Measured memory_bytes: 9112
use std::cmp::min;
use std::fs::File;
use std::io::{stdout, BufWriter, Read, Write};
use std::thread;

fn main() {
    thread::Builder::new()
        .stack_size(32 * 1024 * 1024) // 32MB
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

/// ローカル環境なら _in.txt から入力を受ける
fn read_input() -> String {
    let stdin = std::io::stdin();
    let mut s = String::new();
    match option_env!("LOCAL") {
        Some(_) => File::open("src/_in.txt")
            .expect("File not found")
            .read_to_string(&mut s)
            .unwrap(),
        None => stdin.lock().read_to_string(&mut s).unwrap(),
    };
    s
}

fn run() {
    let out = stdout();
    let mut out = BufWriter::new(out.lock());
    let input = read_input();
    let mut input = input.split_whitespace();

    let in_n: usize = input.next().unwrap().parse().unwrap();
    let in_x: i64 = input.next().unwrap().parse().unwrap();
    let mut in_a: Vec<i64> = input.map(|s| s.parse().unwrap()).collect();

    let mut ans: i64 = in_a.iter().sum();
    // k 回色を変える
    for k in 1..in_n {
        in_a = (0..in_n)
            .map(|i| min(in_a[(i + in_n - 1) % in_n], in_a[i]))
            .collect();
        ans = min(ans, in_a.iter().sum::<i64>() + k as i64 * in_x);
    }
    writeln!(out, "{}", ans).ok();
}


Measured memory_bytes: 8572
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

template <class T>
inline bool chmin(T &a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b){
    if (a < b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll LNF = __LONG_LONG_MAX__;

constexpr int INF = 1e9+7;

const double PI=3.14159265358979323846;


vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<double> p(n);
    rep(i,0,n) cin >> p[i];
    double ans = 0;
    vector<vector<double>> dp(n+1,vector<double>(n+1,0));
    dp[0][0] = 1.0;
    rep(i,0,n){
        rep(j,0,n){
            dp[i+1][j+1] += dp[i][j]*p[i];
            dp[i+1][j] += dp[i][j]*(1-p[i]);
        }
        debug(dp[i+1]);
    }
    rep(i,(n+1)/2,n+1){
        ans += dp[n][i];
    }
    cout << fixed << setprecision(15) << ans << endl;
}

Measured memory_bytes: 70784
H,W = map(int,input().split())
ds = [list(map(int,input().split())) for i in range(10)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            ds[i][j] = min(ds[i][k] + ds[k][j], ds[i][j])

ans = 0
for i in range(H):
    row = list(map(int,input().split()))
    for a in row:
        if a < 0: continue
        ans += ds[a][1]
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>

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

using namespace std;

long long kanashimi(vector<long long> a, long long b) {
    long long ret = 0;
    for(long long ai : a) {
        ret += abs(ai - b);
    }
    return ret;
}

int main(){
    int n; cin >> n;
    vector<long long> a(n);
    rep(i, n) {
        cin >> a[i];
        a[i] -= (i+1);
    }
    sort(a.begin(), a.end());
    long long b = a[0];
    if(n%2 == 0){
        long long b =a[n/2];
        cout << kanashimi(a,b) << endl;
    } else {
        long long b =a[(n-1)/2];
        cout << kanashimi(a,b) << endl;
    }
}



Measured memory_bytes: 3328
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	for(int n; cin >> n && n;) {
		vector<char> vote(n);
		for(auto &e : vote) cin >> e;

		vector<int> cnt(128, 0);
		for(int i = 0; i < n; ++i) {
			++cnt[vote[i]];
			char candidate = -1;
			int top = 0;
			int second = 0;

			for(char c = 'A'; c <= 'Z'; ++c) {
				int tmp = cnt[c];
				if(top < tmp) {
					swap(top, tmp);
					candidate = c;
				}
				if(second < tmp) swap(second, tmp);
			}

			if(top > second + (n - i - 1)) {
				cout << static_cast<char>(candidate) << ' ' << i + 1 << endl;
				goto next;
			}
		}
		cout << "TIE" << endl;
	next:;
	}
	return EXIT_SUCCESS;
}

Measured memory_bytes: 3172