akhauriyash/Code-Regression huggingface dataset:
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# rstrip().decode('utf-8')
# INF=float("inf")
#MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
#import numpy as np
# import operator
# import bisect
# from heapq import heapify,heappop,heappush
#from math import gcd
# from fractions import gcd
# from collections import deque
# from collections import defaultdict
# from collections import Counter
# from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())


def main():
	L,R=map(int,input().split())
	ans=0
	LL, RR = L % 2019, R % 2019
	if R-L<2019 and LL<RR:
		ans=2018
		L,R=L%2019,R%2019
		for i in range(LL,RR):
			j=1
			while i+j<=RR:
				ans=min(ans,(i*(i+j))%2019)
				j+=1
	print(ans)
	





if __name__ == '__main__':
	main()


Measured memory_bytes: 3064
#!/usr/bin/env python

class UnionFind():
    def __init__(self, n): 
        self.n = n 
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.sizes = [1 for _ in range(n)]

    def root(self, x): 
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.root(self.par[x]) # 圧縮経路
            return self.par[x]
            # return root(par[x]) # 圧縮しない場合

    def same(self, x, y): 
        return self.root(x) == self.root(y)

    def unite(self, x, y): 
        rx = self.root(x)
        ry = self.root(y)
        if rx == ry: 
            return

        # par[rx] = ry # naiveな連結

        # 低い木を高い方にくっつける。
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.sizes[ry] += self.sizes[rx]
        else:
            self.par[ry] = rx
            self.sizes[rx] += self.sizes[ry]

        # rx木とry木の高さが同じならば、rx木を深くする。
        if self.rank[rx] == self.rank[ry]:
            self.rank[rx] += 1

    def size(self, x): 
        '''
        xが属するグループのサイズを返す
        (連結成分の大きさ)
        '''
        return self.sizes[self.root(x)]


n, m = map(int, input().split())
uf = UnionFind(n)
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    uf.unite(a, b)

ans = 0
for i in range(n):
    tmp = uf.size(i)
    if ans <= tmp:
        ans = tmp

print(ans)
    

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

typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 100005;

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

#define mp make_pair
#define fi first
#define se second

int n, num;
pii p[maxn];
ll S, sum[maxn], nowx, nowy, ansx, ansy;

ll calc(int x) {return sum[x] - (x >= num ? p[num].fi : 0);}

int main()
{
	n = gi();
	for (int i = 1; i <= n; ++i) p[i].fi = gi(), p[i].se = gi(), S += p[i].fi, p[i].fi = max(p[i].fi, p[i].se);;
	sort(p + 1, p + n + 1, greater<pii>());
	for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + p[i].fi;

	ansx = 0; ansy = 1;
	for (int i = 1; i <= n; ++i) {
		num = i;
		int l = 0, r = n + 1, mid;
		while (l < r) {
			mid = (l + r) >> 1;
			if (calc(mid) >= S - p[i].se) r = mid;
			else l = mid + 1;
		}
		if (l > n || calc(l) >= S) continue;
		ll nowx = (ll)(n - (l - (i <= l))) * p[i].se - S + calc(l), nowy = (ll)n * p[i].se;
		if (1. * nowx * ansy > 1. * nowy * ansx) ansx = nowx, ansy = nowy;
	}
	ll g = __gcd(ansx, ansy);
	printf("%lld %lld\n", ansx / g, ansy / g);
	
	return 0;
}



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

int main(){
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int ans = 0;
    for(int i = 0; i <= A; i++){
        for(int j = 0; j <= B; j++){
            for(int k = 0; k <= C; k++){
                if(i * 500 + j * 100 + k * 50 == X){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,m = inm()
a = []
b = []
for i in range(m):
    aa,bb = inm()
    cc = inl()
    a.append(aa)
    x = 0
    for j in range(bb):
        x += 2**(cc[j]-1)
    b.append(x)

ddprint(a)
ddprint(b)

t = [BIG]*(2**n)
t[0] = 0
for i in range(m):
    for j in range(2**n-1):
        if t[j]<BIG:
            t[j|b[i]] = min(t[j|b[i]], t[j]+a[i])
if t[2**n-1]==BIG:
    print(-1)
else:
    print(t[2**n-1])


Measured memory_bytes: 50136
import copy
from typing import List, Tuple


def _generate_goal() -> List[List[int]]:
    goal = [[0] * 3 for _ in range(3)]
    for row in range(3):
        for col in range(3):
            if 9 == 3 * row + col + 1:
                goal[row][col] = 0
            else:
                goal[row][col] = 3 * row + col + 1
    return goal


def _find_zero_pos(board: List[List[int]]) -> Tuple[int, int]:
    for row in range(3):
        for col in range(3):
            if 0 == board[row][col]:
                return (row, col)
    # Never reaches here.
    return (-1, -1)


def _swappable_cand(zero_pos: Tuple[int, int]) -> List[Tuple[int, int]]:
    row, col = zero_pos[0], zero_pos[1]
    cand_pos_list: List[Tuple[int, int]] = []
    if 0 != row:
        cand_pos_list.append((row - 1, col))
    if 2 != row:
        cand_pos_list.append((row + 1, col))
    if 0 != col:
        cand_pos_list.append((row, col - 1))
    if 2 != col:
        cand_pos_list.append((row, col + 1))

    return cand_pos_list


def solve_8puzzle(board: List[List[int]]) -> int:
    goal = _generate_goal()
    if board == goal:
        return 0
    generated_boards = {tuple(sum(board, [])): 0, tuple(sum(goal, [])): 1}
    steps = {tuple(sum(board, [])): 0, tuple(sum(goal, [])): 0}
    step = 0
    state = [(board, 0), (goal, 1)]
    while state:
        state_copied = copy.deepcopy(state)
        state = []
        step += 1
        for s2, d in state_copied:
            zero_row, zero_col = _find_zero_pos(s2)
            cand_pos_list = _swappable_cand((zero_row, zero_col))
            for (row, col) in cand_pos_list:
                s1 = copy.deepcopy(s2)
                s1[zero_row][zero_col], s1[row][col] = s1[row][col], 0
                key = tuple(sum(s1, []))
                if key in generated_boards:
                    if generated_boards[key] != d:
                        return step + steps[key]
                    continue
                state.append((s1, d))
                generated_boards[key] = d
                steps[key] = step
    # Never reaches here.
    return -1


if __name__ == "__main__":
    board = [[0] * 3 for _ in range(3)]

    for row in range(3):
        input_nums = list(map(lambda x: int(x), input().split()))
        for col in range(3):
            # if 0 == input_nums[col]:
            #     zero_pos = (row, col)
            board[row][col] = input_nums[col]

    print(f"{solve_8puzzle(board)}")



Measured memory_bytes: 20400
from collections import defaultdict
import bisect

S = input()
T = input()
d = defaultdict(list)
for i, s in enumerate(S):
    d[s].append(i)

x = -1
cnt = 0

for t in T:
    if len(d[t]) == 0:
        print(-1)
        exit()
    y = bisect.bisect_right(d[t], x)
    if y == len(d[t]):
        cnt += 1
        x = d[t][0]
    else:
        x = d[t][y]

ans = len(S) * cnt + x + 1
print(ans)

Measured memory_bytes: 45808
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String N  = sc.next();
		
		String[] Array =  N.split("");
		int k = 0;
		for (String string : Array) {
			if(string.equals("2")) {
			++k;
			}
		}
		
		System.out.println(k);
		
	}

}


Measured memory_bytes: 22996
def main():
    n,k=map(int,input().split())
    P=list(map(int,input().split()))
    ave=[(p+1)/2 for p in P]
    s=sum(ave[:k])
    ans=s
    for left in range(n-k):
        s -= ave[left]
        s += ave[left+k]
        if s>ans:
            ans = s
    print(ans)
main()

Measured memory_bytes: 25060
#include<stdio.h>

int N;
char s[100001];
int right[100002],left[100002];

void solve(int first,int Nth){
    int i,m;
    right[1] = right[N + 1] = first;right[N] = right[0] = Nth;left[1] = left[N + 1] = first;left[N] = left[0] = Nth;

    for(i = 1;i < N;i++){
        m = 1;
        if(s[i] == 'x')
            m = -1;
        m *= right[i];
        right[i + 1] = right[i - 1] * m;
    }
    for(i = N;i > 1;i--){
        m = 1;
        if(s[i] == 'x')
            m = -1;
        m *= left[i];
        left[i - 1] = left[i + 1] * m;
    }
}

int main(void){
    int i,j,k,f;
    scanf("%d",&N);
    scanf("%s",&s[1]);

    for(i = -1;i <= 1;i+=2)
        for(j = -1;j <= 1;j+=2){
            solve(i,j);
            f = 1;
            for(k = 1;k <= N;k++)
                if(right[k] != left[k]){
                    f = 0;
                    break;
                }
            if(f == 1){
                for(k = 1;k <= N;k++){
                    if(right[k] == 1)
                        printf("S");
                    else
                        printf("W");
                }
                printf("\n");
                return 0;
            }
        }

    printf("-1\n");

    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
using namespace std;
int p, q, x, y;
string s;
int main() {
	cin>>p>>q>>x>>y;
	x-=p, y-=q, p=q=0;
	while(q++<y) s+='U';
	while(p++<x) s+='R';
	while(--q) s+='D';
	while(--p) s+='L';
	s+="LU";
	while(q++<y) s+='U';
	while(p++<x) s+='R';
	s+="RDRD";
	while(--q) s+='D';
	while(--p) s+='L';
	s+="LU";
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#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 fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int n;
    cin>>n;
    vpi x;
    forn(i,n){
        int a,b;
        cin>>a>>b;
        x.pb(mp(b,a));
    }
    //forn(i,n)   cout<<x[i].fi<<" "<<x[i].se<<endl;
    sort(all(x));
    //forn(i,n)   cout<<x[i].fi<<" "<<x[i].se<<endl;
    int sum = 0;
    forn(i,n)
    {
        int f = x[i].fi;
        int s = x[i].se;
        if((sum+s) <= f){
            sum += s;
     //       cout<<sum<<endl;
        }
        else{
            cout<<"No\n";
            return 0;
        }
    }
    cout<<"Yes\n";
    return 0;
}



Measured memory_bytes: 2420
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		int result = 0;
		for (int i=0; i<6; i++){
			if (S.substring(i, i+1).equals("1")){
				result++;
			}
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define wi(t) int t;cin>>t;while(t--)
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int mpow(int base, int exp); 
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

int tc=1;

void solve()
    { 
     
     
     ll int n,d;
     cin>>n>>d;
     ll int c=0;
     while(n--)
     {
       ll int x,y;
       cin>>x>>y;
       if(sqrt(x*x+y*y)<=d)
       c++;
     }
     cout<<c<<endl;
     
     
     
     
    
   


    }
     
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
   // wi(t)
    {
    solve();
    }
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
    u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}







Measured memory_bytes: 10732
import collections

n = int(input())
s_count = list()
for i in range(n):
    s = input()
    s_list = ""
    for j in range(26):
        s_list += str(s.count(chr(j + 97)))
    s_count.append(s_list)
s = collections.Counter(s_count)
res = 0
for i in s.values():
    if i >= 2:
        res += i * (i - 1) // 2
print(res)


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    int2(n, x);
    vector<int> data(n);
    for (int i = 0; i < n; i++) {
        cin >> data[i];
    }
    sort(all(data));

    int cnt = 0;
    rep(i, data.size()) {
        x -= data[i];
        if (x < 0) break;
        cnt++;
    }
    if (x > 0)
        cout << cnt-1 << endl;
    else 
        cout << cnt << endl;


    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int s;
	int f[1000001];
	int i,j,k;
	for(i=0;i<1000001;i++)f[i]=0;
	scanf("%d",&s);
	f[1]=s;
	for(i=2;i<1000001;i++){
		k=f[i-1]%2;
		if( k==0 )f[i]=f[i-1]/2;
		else f[i]=3*f[i-1]+1;
		for(j=i-1;j>0;j--){
			if(f[i]==f[j]){
				printf("%d ",i);
				goto out;
			}
		}
	}
	out:
	return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int L;
	cin >> L;
	cout << setprecision(12) << fixed;
	cout << pow((double)L / 3, 3) << "\n";
}

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;
  cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  double x = a[0];
  REP(i, n - 1){
    x = (x + a[i + 1]) / 2;
  }
  printf("%.10f\n", x);
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int n,x;
vector <int> a,s,idx;
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&x),a.push_back(x);

	s=a;
	sort(s.begin(),s.end());
	if(s==a) cout<<"YES";
	else
	{
		for(int i=0;i<n;i++)
			if(a[i]!=s[i])
				idx.push_back(i);
		if(idx.size()==2) cout<<"YES";
		else cout<<"NO";
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
const int N = 1300;
int main(){
	char str[N];
	while(fgets(str, 1300, stdin))
	{
		int sum = 0;
		if(str[0] == '0')
		{
			break;
		}
		for(int i = 0; i < strlen(str)-1; i++)
		{
			sum += str[i] - '0';
		}
		printf("%d\n", sum);
}
	return 0;
}


Measured memory_bytes: 2696
#include <bits/stdc++.h>
 
using namespace std;
 
typedef pair<int, int> P;
 
vector<int> Point(string s)
{
    stringstream ss(s);
    int num;
    vector<int> v;
 
    while (ss >> num) {
	v.push_back(num);
    }
    return v;
}
 
int getScore(string s)
{
    vector<int> a;
    a = Point(s);
    int len = (int)a.size();
    int score = 0 , sum = 0;
    int p = 0, n = 0;
 
    for (int i = 0; i < len; i++) {
	if (p >= 9) {
	    p++;
	    score += a[i];
	} else {
	    if (a[i] == 10 && n == 0) {
		score += a[i] + a[i+1] + a[i+2];
		p++;
	    } else {
		n++;
		sum += a[i];
		if (n == 2) {
		    n = 0;
		    score += sum;
		    if (sum == 10) {
			score += a[i+1];
		    }
		    p++;
		    sum = 0;
		}
	    }
	}
    }
 
    return -score;
}
 
int main()
{
    int m;
    while (cin >> m, m) {
	vector<P> v;
	string pin;
	for (int i = 0; i < m; i++) {
	    int score, num;
	    cin >> num;
 
	    getline(cin, pin);
	    score = getScore(pin);
   
	    v.push_back(P(score, num));
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < m; i++) {
	    cout << v[i].second << " " << -v[i].first << endl;
	}
    }
    return 0;
}

Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main() {
    int n;
    cin >> n;
    vector<ll> fib(1000);
    fib[0] = fib[1] = 1;
    rep(i, 50) fib[i + 2] = fib[i + 1] + fib[i];
    cout << fib[n] << endl;
}


Measured memory_bytes: 3120
#include<iostream>
#include<string>
using namespace std;
int main ()
{
    string s;
    string t;
    int a,b;
    string u;
    cin>>s>>t;
    cin>>a>>b;
    cin>>u;
    if(u==s)
        cout<<a-1<<" "<<b<<endl;
    else if (u==t)
        cout<<a<<" "<<b-1<<endl;
    return 0;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

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

const int sz = 5005;
ll dp[sz][sz];
bool used[5555];

int main(){

	ll n, a, b;cin >> n >> a >> b;
	vector<ll> v(n);
	REP(i, n)cin >> v[i],v[i]--;

	REP(i, sz)REP(j, sz)dp[i][j] = LLINF;
	dp[0][0] = 0;

	REP(i, n+1){
		if(i > 0)used[v[i-1]] = true;
		REP(j, n+1){
			if(used[j])dp[i][j+1] = min(dp[i][j+1], dp[i][j]);
			else dp[i][j+1] = min(dp[i][j+1], dp[i][j] + b);
			if(v[i] == j)dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]);
			if(v[i] < j)dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
			else dp[i+1][j] = min(dp[i+1][j], dp[i][j] + a);
		}
	}

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

	return 0;
}


Measured memory_bytes: 195968
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    vector< int > v(5);
    for(int i = 0 ; i < 5 ; i++){
        cin >> v[i]; 
    }
    sort(v.begin() , v.end());
    int ans = 9999999;
    do{
      //  cout << "hello" << endl;
        int cnt = 0;
        for(int i = 0 ; i < 5 ; i++){
            if(i != 4)
            cnt += (((v[i]+9)/10)*10);
            else
            {
                cnt += v[i];
            }
        }
        ans = min(ans,cnt);
    }while(next_permutation(v.begin(),v.end()));
    cout << ans << endl;
 	return 0; 
}

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

using LL = long long;

int main() {
    LL a, b;
    cin >> a >> b;
    LL ans = 1;
    for (LL i = 2; i <= min(1000000ll, min(a, b)); i++) {
        if (a % i == 0 && b % i == 0) {
            ans++;
            while (a % i == 0 && b % i == 0) {
                a /= i;
                b /= i;
            }
        }
    }
    if (gcd(a, b) != 1) {
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p) {
    return out << "(" << p.first << ", " << p.second << ")";
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
template<class T> inline void YES(T condition) { 
    if(condition) cout << "YES" << endl;
    else cout << "NO" << endl;
}
template<class T> inline void Yes(T condition) {
    if(condition) cout << "Yes" << endl;
    else cout << "No" << endl;
}
template<class T> T gcd(T a, T b) {
    if(a && b) { return gcd(min(a, b), max(a, b) % min(a, b)); }
    else { return a; }
}
template<class T> T lcm(T a, T b){
    return a / gcd(a, b) * b;
}
long long qpow(long long a, long long b, int MOD) {
    if (b == 0) return 1;
    long long res = 1;
    while (b) {
        if (b & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return res;
}

const int MOD = 1e9 + 7;
const int maxn = 2e6;
int fac[maxn + 5];
int invfac[maxn + 5];
void init() {
    fac[0] = 1;
    for (int i = 1; i <= maxn; i++) fac[i] = 1LL * fac[i - 1] * i % MOD;
    invfac[maxn] = (int)(qpow(fac[maxn], MOD - 2, MOD));
    for (int i = maxn - 1; i >= 0; i--) invfac[i] = 1LL * invfac[i + 1] * (i + 1) % MOD;
}
int C(int n, int k) {
    assert(0 <= k && n >= k);
    int tmp = (int)(1LL * invfac[k] * invfac[n - k] % MOD);
    return (int)(1LL * fac[n] * tmp % MOD);
}

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

    string s, t;
    cin >> s;
    cin >> t;
    int n = s.size();
    int n2 = t.size();
    bool ok = (n2 - n == 1);
    if (!ok) {
        cout << "No" << '\n';
        return 0;
    }
    for (int i = 0; i < n; i++) {
        ok &= (s[i] == t[i]);
    }
    Yes(ok);

    return 0;
}


Measured memory_bytes: 3592
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;
const ll INF_ = 1000000000000000000;


int main() {
    ll n, a,cnt=1;
    bool zero = false;
    cin >> n;
    cin >> cnt;
    rep(i, n-1) {
        cin >> a;
        if (zero && a != 0)continue;
        if (zero && a == 0) { cnt = 0; break; }
        if(cnt <= (INF_/a))
            cnt *= a;
        else {
            cnt = -1;
            zero = true;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3648
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 2005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n,s,a[MAXN];
bitset<2000*1001> bs[MAXN];
int main()
{
    scanf("%d",&n);
    s=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        s+=a[i];
    }
    bs[0].set(0);
    for(int i=1;i<=n;i++) bs[i]=bs[i-1]|(bs[i-1]<<a[i]);
    for(int i=(s+1)/2;i<=s;i++)
    {
        if(bs[n][i])
        {
            printf("%d\n",i);
            return 0;
        }
    }
    return 0;
}



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

#define M_PI 3.14159265358979323846

using namespace std;

//typedef
//-------------------------#include <bits/stdc++.h>

#define M_PI 3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s)
{
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}
template <class T>
inline string toString(T x)
{
    ostringstream sout;
    sout << x;
    return sout.str();
}
inline int readInt()
{
    int x;
    scanf("%d", &x);
    return x;
}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a) * (a))
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

//repetition
//------------------------------------------
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-8;

#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const int INF = 2147483647;

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

    ll N, Y;
    cin >> N >> Y;

    for (ll i = 0; i <= N; i++)
    {
        for (ll j = 0; j + i <= N; j++)
        {
            ll k = N - (i + j);
            if (i * 10000 + j * 5000 + k * 1000 == Y)
            {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}


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

typedef long long ll;
ll n, s, a[300005];
int main()
{
	ll i, j;
	cin >> n;
	n *= 3;
	for (i = 0; i < n; i++) {
		scanf ("%lld", &a[i]);
	}
	sort(a, a + n);
	for (i = n - 2, j = 0; i >= 0 && j < n / 3; i -= 2, j++) {
		s += a[i];
	}
	cout << s;
    return 0;
}


Measured memory_bytes: 2560
N = int(input())
H = list(map(int,input().split()))

cnt = 0
cnt_list = []
for n in range(N-1):
    if H[n] >= H[n+1]:
        cnt += 1
    else:
        cnt_list.append(cnt)
        #if中で出たcntの合計だけリストに入れるにはこの位置
        cnt = 0
        #0に戻してループを再開
cnt_list.append(cnt)
#print(cnt_list)
print(max(cnt_list))

Measured memory_bytes: 15020
#include <stdio.h>
#include <string.h>

int main(void)
{
char str[256];
char rev[256];

scanf("%s", str);

for (int i = 0; str[i] != '\0'; i++){
rev[i] = str[strlen(str) - 1 - i];
}
rev[strlen(str)] = '\0';

printf("%s\n", rev);

return (0);
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = n;
        for (int i=0;i<=n;i++){
            int num = 0;
            int a = i;
            while (a>0){
                num+=a%6;
                a/=6;
            }
            a = n-i;
            while (a>0){
                num+=a%9;
                a/=9;
            }
            if (ans>num)ans=num;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 35520
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n,a,b,k;
vector<pair<ll,ll>> v;
int main()
{
			// #ifndef ONLINE_JUDGE
  	// 		// for getting input from input.txt
  	// 		freopen("input.txt", "r", stdin);
  	// 		// for writing output to output.txt
  	// 		freopen("output.txt", "w", stdout);
  	// 	#endif
  			cin>>n>>k;
  			for (int i = 0; i < n; ++i)
  			{
  				cin>>a>>b;
  				v.push_back(make_pair(a,b));
  			}
  			sort(v.begin(), v.end());
  			
  			for (int i = 0; i < v.size(); ++i)
  			{
  				k = k - v[i].second;
  				if(k<=0) { cout<<v[i].first<<endl; break; }
  			}
	return 0;
}

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

class modint {
  public:
    using ll = long long;
    ll num;
    static const ll MOD = 998244353;
    static vector<modint> factorial;

    modint(): num(0) {};
    modint(ll n_): num((n_ + MOD) % MOD) {}
    modint(const modint &r): num(r.num) {}
    operator ll() const { return (num+MOD)%MOD; }
    friend istream& operator>>(istream& is, modint &r){
        ll num_;
        is >> num_;
        r = num_;
        return is;
    }

    template <typename T>
    modint operator+(const T &r) const { return modint(num + (ll)r); }
    template <typename T>
    modint operator-(const T &r) const { return modint(num - (ll)r); }
    template <typename T>
    modint operator*(const T &r) const { return modint(num * (ll)r); }
    template <typename T>
    modint operator/(const T &r) const { return num * pow(r, MOD-2); }

    template <typename T>
    modint operator+=(const T &r) { return *this = *this + r; }
    template <typename T>
    modint operator-=(const T &r) { return *this = *this - r; }
    template <typename T>
    modint operator*=(const T &r) { return *this = *this * r; }
    template <typename T>
    modint operator/=(const T &r) { return *this = *this / r; }

    static modint pow(const modint &x, const ll &r) {
        if(r == 0) return 1;
        return pow(x*x, r/2) * modint(r&1 ? x : modint(1));
    }

    static modint fact(int n){
        if((int)factorial.size() <= n) {
            int size = factorial.size();
            factorial.resize(n+1);
            for (int k = size; k <= n; k++) {
                factorial[k] = factorial[k-1] * k;
            }
        }
        return factorial[n];
    }

    static modint C(int n, int r){
        return n >= r ? fact(n)/(fact(n-r)*fact(r)) : modint(0);
    }
};
vector<modint> modint::factorial = {1};
#define fact(n) modint::fact(n)
#define C(n,r) modint::C(n,r)
#define H(a,b) C(a+b, a)


int main(void){
    int n;
    cin >> n;
    modint sum = 0;
    for (int i = n/2+1; i <= n; i++) {
        sum += C(n,i) * modint::pow(2,n-i) * 2;
    }
    cout << modint::pow(3,n) - sum << endl;
    return 0;
}


Measured memory_bytes: 117376
# coding: utf-8

N, M = list(map(int, input().split(' ')))
A = [int(input()) for _ in range(N)]
B = [int(input()) for _ in range(M)]
scores = [0 for _ in range(N)]

for j in range(M):
    for i in range(N):
        if A[i] <= B[j]:
            scores[i] += 1
            break

max_i, max_val = 0, 0
for i in range(N):
    if scores[i] > max_val:
        max_val = scores[i]
        max_i = i
print(max_i + 1)


Measured memory_bytes: 5632
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
ll dp[2][4];
int now = 0;
int t[3];
ll p2[32];
bool use[100010];
int arr[256];
void Sequence() {
	ll x;
	cin >> x;
	int i = 1;
	ll v = 0;

	while (v < x)
	{
		v += i;
		i++;
	}
	cout << (i - 1) << endl;
}
int main() {
	Sequence();
	return 0;
}



Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-6;
const long INF = 1e10;


int main(){
	int n;
	vector<long>prime;
	for(long i=2;i<=1299709;i++){
		bool flag=true;
		for(long j=2;j*j<=i;j++)if(i%j==0){
			flag=false;break;
		}
		if(flag)prime.PB(i);
	}
	while(cin>>n){
		if(n==0)break;
		vector<long>::iterator itr=lower_bound(ALL(prime),n);
		if(*itr==n){
			cout<<0<<endl;
		}else{
			long ma=*itr;
			itr--;
			cout<<ma-*itr<<endl;
		}
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
const ll M=1e9+7;

ll per(int n,int m)
{
    ll ans=1;
    for(int i=0;i<m;i++)
    {
        ans=ans*(n-i)%M;
    }
    return ans;
}

int main()
{
    int n,k;

    while(cin>>n>>k)
    {
        cout<<per(k,n)<<endl;
    }

    return 0;
}



Measured memory_bytes: 3104
import bisect
import sys

input = sys.stdin.readline


def read_i():
    return list(map(int, input().split()))


n = int(input())
ls = sorted(read_i())
res = 0
for i in range(n - 2):
    x = ls[i]
    for j in range(i + 1, n - 1):
        y = ls[j]
        res += bisect.bisect_left(ls, x + y) - j - 1
print(res)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,ans = 0;
  	cin >> N;
    vector<int> A(N),B(N),sA(N+1,0),sB(N+1,0);
    for(int i = 0;i < N;i ++){
        cin >> A[i];
    }
    for(int i = 0;i < N;i ++){
        cin >> B[i];
    }
    for(int i = 0;i < N;i ++){
        sA[i+1] = A[i] + sA[i];
        sB[i+1] = B[N-i-1] + sB[i];
    }
    for(int i = 1;i <= N;i ++){
        if(sA[i]+sB[N-i+1]>ans) ans = sA[i]+sB[N-i+1]; 
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;

int main() {
  vector<int> arr(10);
  for(int i=0;i<10;++i){
    cin>>arr[i];
  }
  sort(arr.begin(), arr.end(), greater<int>());
  for(int i=0;i<3;++i){
    cout<<arr[i]<<endl;
  }
}




Measured memory_bytes: 3128
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

 const int N=2e5+5;

 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;
	}
	 return res;	
   }



int a,b,n;

int cal(int x) {	   
	   int yo=(a*x)/b;
	   yo-=(a*(x/b));
	   return yo;
	}
	
void solve() {
    
    cin>>a>>b>>n;
    
    int x=min(b-1,n);
    
    int ans=(a*x)/b-(a*(x/b));    
    cout<<ans<<endl;
 }

    
int32_t main() {
	cool;
	int t=1;	

	//cin>>t;
	while(t--)
	  solve();

return 0;	   
}


Measured memory_bytes: 3612
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main(void){
    while(1){
        string x;
        cin >> x;
        
        if(x=="0")break;
        
        int v;
        v=0;
        for(int i=0;i<(int)x.size();i++){
            char ch = x[i];
            
            int n = (int)ch - (int)'0';
            v+=n;
        }
        cout << v << endl;;
    }
}

Measured memory_bytes: 1192
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int h, w; cin >> h >> w;
    char a[100][100];
    REP(i, h) {
        REP(j, w) {
            cin >> a[i][j];
        }
    }
    vector<int> di = {-1, 1, 0, 0};
    vector<int> dj = {0, 0, -1, 1};
    REP(i, h) {
        REP(j, w) {
            if (a[i][j] != '#') {
                continue;
            }

            bool ok = false;
            REP(k, 4) {
                if ((0 <= i+di[k]) && (i+di[k] < h) && (0 <= j+dj[k]) && (j+dj[k] < w)) {
                    if (a[i+di[k]][j+dj[k]] == '#') {
                        ok = true;
                    }
                }
            }
            if (!ok) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main() {
    int N; cin >> N;
    vector<int> V(N);
    for (int i=0; i<N; i++) cin >> V[i];
    sort(V.begin(), V.end());
    float ans = 0;
    ans = (V[0] + V[1]) / 2.0;
    for (int i=2; i<N; i++) {
        ans = (ans + V[i]) / 2.0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3820
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
  int N,K;
  cin >> N >> K;
  vector<long long> H(N,0); 
  for(int i=0;i<N;i++){
    cin >> H[i];
  }
  sort(H.begin(),H.end());
  long long ans=0;
  for(int i=0;i<N-K;i++)ans+=H[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
n = gets.to_i

edges = []
g = Array.new(n){ [] }
(n-1).times do |i|
  a,b = gets.split
  a,b = a.to_i-1, b.to_i-1
  a, b = b, a if a > b # 辺は頂点 i < j の形で入れる。
  g[a] << b # 隣接リストに
  g[b] << a # 反対向きにも隣接リストに.無向グラフなので
  edges << [a,b] # 辺リストにいれる。辺が識別されてて、最後に辺リストから辺を回して色をとりだす。
end

colors = Hash.new() # Esge => color # 辺についてO(1)で使った色を見れる。O(1)はホントに?
colors_used = Array.new(n){Hash.new} # 頂点と色についてO(1)で使ったか確かめられる。
used = Array.new(n){false} # 頂点について探索済みかどうかO(1)でわかる。
que = [0] # 頂点0から見ていくので0が入っている # 探索待ちの未探索の頂点リスト

k = 0 # 答えとなる色の数
while !que.empty? do
  v = que.shift # queにある頂点を取り出す. 破壊的メソッドなので先頭は削除される。
  cur = 1 # 使ってない色がわからないので、とりあず色1から見ていく。
  g[v].each do |w| # vの隣接頂点wを見ていく。
    next if used[w] == true # 探索済みの頂点なら見ない。
    k = g[v].size if k < g[v].size  # 隣接する頂点数より色数が小さければ色数を更新
    v<w ? (i,j = v,w) : (i,j = w,v) # i < jの並びで頂点を捉える。
    # next if colors[[i,j]] != nil # nilでなければi-jの辺に色がついてて頂点jは探索済みで,次に。
    cur += 1 while colors_used[v][cur] == true # v周りの頂点で色をつかっていれば次の色に更新していく。塗る前に使ってない色にする。
    colors_used[v][cur] = true # vに色を使ったので記録する。
    colors_used[w][cur] = true # wに色を使ったので記録する。
    colors[[i,j]] = cur # 辺に使った色をいれる。
    que.push(w) #探索待ちの未探索頂点リストに頂点wを入れる。
  end
  used[v] = true # 頂点vを探索済みにする。
end

puts k
edges.each{ |e| puts colors[e] }

Measured memory_bytes: 58620
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define rep(i,a,b) for(int i = (a) ; i <= (b) ; i++)
#define per(i,a,b) for(int i = (a) ; i >= (b) ; i--)
#define mem(a) memset(a,0,sizeof(a))
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define fast_io ios::sync_with_stdio(false)

const int INF = 1e9;
const LL mod = 1e9 + 7;
const int maxn = 2e5 + 7;

int a[maxn];

int main() {
    int n,m;
    sd(n),sd(m);
    int sum = 0;
    rep(i,1,m) sd(a[i]), sum += a[i];
    n -= sum;
    if(n < 0) pd(-1);
    else pd(n);
    return 0;
}


Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
const ll mod = 1e9 + 7;
ll powmod(ll a, ll b) { ll res=1; a%=mod; assert(b>=0); for(;b;b>>=1) { if(b&1) res=res*a%mod; a=a*a%mod; } return res; }
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }

int main() {
	int t;
	// cin >> t;
    t = 1;

	while(t--) {
		int n;
		cin >> n;
        
        vector<int> arr(n+1, 0);
        
        for (int i = 1; i*i <= n; i++) {
            for (int j = 1; j*j <= n; j++) {
                for (int k = 1; k*k <= n; k++) {
                    ll res = (((i+j) * (i+j)) + ((j+k) * (j+k)) + ((k+i) * (k+i)));
                    if (res <= 2*n)
                        ++arr[res/2];
                }
            }
        }
        
        for (int i = 1; i <= n; i++)
            cout << arr[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a;
    cin>>n;
    std::deque<int> deq;
    deq.emplace_back(0);
    int sum=0;
    for (int i=0;i<=n;i++) {
        if (i!=n) {
            cin>>a;
            deq.emplace_back(a);
            sum+=abs(deq[i]-deq[i+1]);
        } else {
            deq.emplace_back(0);
            sum+=abs(deq[i]-0);
        }
    }
    for (int j=1;j<=n;j++) {
        int tmp=sum;
        tmp-=abs(deq[j-1]-deq[j]);
        tmp-=abs(deq[j]-deq[j+1]);
        tmp+=abs(deq[j-1]-deq[j+1]);
        cout<<tmp<<endl;
    }
}

Measured memory_bytes: 1664
#include<iostream> 
#include<algorithm> 
#include<cassert> 
#include<vector> 
#include<fstream> 
#include<string> 
#include<stdio.h> 
#include<stdlib.h> 
#include<time.h> 
#include<queue> 
#include<map> 
#include<set> 
#include<bitset> 
#include<cmath> 

using namespace std; 
#define REP(i,m,n) for(int i=m;i<n;++i) 
#define REPll(i,m,n) for(long long i=m;i<n;++i) 
#define INF 10000000000000000 
#define MOD 1000000007 
#define ll long long 
#define mp make_pair 
#define all(v) v.begin(),v.end() 

bool check(int a){
    for(int i=2;i*i<=a;i++){
        if(a%i==0){
            return false;
        }
    }
    return true;
}    

int main() {
    int n;
    cin>>n;
    cout<<"2 5"<<flush;
    int hoge=2;
    REP(i,1,1850){
        if(check(i*30+1)==true){
            hoge++;
            cout<<" "<<i*30+1<<flush;
        }
        if(hoge==n){
            cout<<endl;
            return 0;
        }
    }
    return 0; 
}


Measured memory_bytes: 256