akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(H):
    ans = 0
    c = 1
    h = H
    while h > 0:
        h //= 2
        ans += c
        c *= 2
    return ans


def main():
    H = read_int()
    print(slv(H))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6852
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
bool find(int a[], int l, int r, int x) {
	if (l <= r) {
		int m = (l + r) / 2;
		if (a[m] == x)
			return true;
		else if (a[m] < x)
			return find(a, m + 1, r, x);
		else
			return find(a, l, m - 1, x);
	}
	return false;
}
int main() {
	//freopen("input.txt", "r", stdin);
	int n, x;
	int a[100];
	cin >> x >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	int res1 = x - 1, res2 = x + 1;
	bool f = find(a, 0, n - 1, x);
	if (f) {
		while (f) {
			bool f1 = find(a, 0, n - 1, res1);
			if (f1) res1 -= 1;
			bool f2 = find(a, 0, n - 1, res2);
			if (f2) res2 += 1;
			f = f1 && f2;
		}
		res1 = x - res1;
		res2 = res2 - x;
		cout << x + ((res1 > res2) ? res2 : -res1);
	}
	else
		cout << x;
	return 0;
}

Measured memory_bytes: 3636
#[warn(unused_imports)]
use proconio::{
   fastout, input,
   marker::{Bytes, Chars, Isize1, Usize1},
};

const INF: usize = 1001001001;

#[fastout]
fn main() {
   input! {
      n: usize,
      a: [usize; n],
      uv: [(Usize1, Usize1); n-1]
   }
   let mut to = vec![Vec::new(); n];
   for (u, v) in uv.iter().copied() {
      to[u].push(v);
      to[v].push(u);
   }
   let mut dp = vec![INF; n+1];
   let mut ans = vec![INF; n];
   dfs(0, 0, &mut dp, &mut ans, &to, &a);
   for ans in ans {
      println!("{}", ans);
   }
}

fn dfs(
   v: usize,
   p: usize,
   dp: &mut Vec<usize>,
   ans: &mut Vec<usize>,
   to: &Vec<Vec<usize>>,
   a: &Vec<usize>,
) {
   let pos = dp.lower_bound(&a[v]);
   let res = dp[pos];
   dp[pos] = a[v];
   ans[v] = dp.lower_bound(&INF);
   for u in to[v].iter() {
      if *u == p {
         continue;
      }
      dfs(*u, v, dp, ans, to, a);
   }
   dp[pos] = res;
}

use std::cmp::Ordering;
/// Equivalent to std::lowerbound and std::upperbound in c++
pub trait BinarySearch<T> {
   fn lower_bound(&self, x: &T) -> usize;
   fn upper_bound(&self, x: &T) -> usize;
}
impl<T: Ord> BinarySearch<T> for [T] {
   fn lower_bound(&self, x: &T) -> usize {
      let mut low = 0;
      let mut high = self.len();
      while low != high {
         let mid = (low + high) / 2;
         match self[mid].cmp(x) {
            Ordering::Less => {
               low = mid + 1;
            }
            Ordering::Equal | Ordering::Greater => {
               high = mid;
            }
         }
      }
      low
   }
   fn upper_bound(&self, x: &T) -> usize {
      let mut low = 0;
      let mut high = self.len();
      while low != high {
         let mid = (low + high) / 2;
         match self[mid].cmp(x) {
            Ordering::Less | Ordering::Equal => {
               low = mid + 1;
            }
            Ordering::Greater => {
               high = mid;
            }
         }
      }
      low
   }
}


Measured memory_bytes: 41032
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

// inf
constexpr ll infl = 10000000000000000LL;
constexpr int inf = 1000000000;

int main() {
    ll x, y;
    cin >> x >> y;
    int cnt = 1;
    while (x <= y) {
        x *= 2;
        if (x <= y) {
            ++cnt;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import Data.Char

main = do
    [a,b,c,d] <- map digitToInt <$> getLine :: IO [Int]
    let ans | a+b+c+d == 7 = show a ++ "+" ++ show b ++ "+" ++ show c ++ "+" ++ show d ++ "=7"
            | a+b+c-d == 7 = show a ++ "+" ++ show b ++ "+" ++ show c ++ "-" ++ show d ++ "=7"
            | a+b-c+d == 7 = show a ++ "+" ++ show b ++ "-" ++ show c ++ "+" ++ show d ++ "=7"
            | a+b-c-d == 7 = show a ++ "+" ++ show b ++ "-" ++ show c ++ "-" ++ show d ++ "=7"
            | a-b+c+d == 7 = show a ++ "-" ++ show b ++ "+" ++ show c ++ "+" ++ show d ++ "=7"
            | a-b+c-d == 7 = show a ++ "-" ++ show b ++ "+" ++ show c ++ "-" ++ show d ++ "=7"
            | a-b-c+d == 7 = show a ++ "-" ++ show b ++ "-" ++ show c ++ "+" ++ show d ++ "=7"
            | a-b-c-d == 7 = show a ++ "-" ++ show b ++ "-" ++ show c ++ "-" ++ show d ++ "=7"
            | otherwise = "Error"
    putStrLn ans

Measured memory_bytes: 3780
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>


using namespace std;

int main(){
	string S;
	cin >> S;

	bool exist = false;
	if (!(S.at(0) == S.at(1) && S.at(1) == S.at(2))) exist = true;
	if (exist) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(ll i=0;i<n;++i)
#define FOR(i,j,n) for(ll i=j;i<n;++i)
#define MOD (1e9 + 7)

int main(void){
    string S, T;
    cin >> S;
    cin >> T;
    ll n = S.size();
    bool check = true;
    REP(i,n){
        if(S[i]!=T[i]){
            check = false;
        }
    }
    string res;
    if(check){
        res = "Yes";
    }else{
        res = "No";
    }
    cout << res << endl;
}

Measured memory_bytes: 3632
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var M = one[1];
  var list = new Array(N);
  for(var i = 0; i < N; i++){
    list[i] = {
      child : [],
      no : i,
      access : false
    };
  }
  for(var i = 0; i < M; i++){
    var tmp = nextIntArray();
    list[tmp[0] - 1].child.push(tmp[1] - 1);
    list[tmp[1] - 1].child.push(tmp[0] - 1);
  }
  var output = [1];
  list[0].access = true;
  var stack = [0];
  while(stack.length > 0){
    var now = stack.pop();
    if(now != 0){
      output.push(now + 1);
    }
    var child = list[now].child;
    for(var i = 0; i < child.length; i++){
      if(!list[child[i]].access){
        list[child[i]].access = true;
        stack.push(child[i]);
        break;
      }
    }
  }
  var stack = [0];
  while(stack.length > 0){
    var now = stack.pop();
    if(now != 0){
      output.unshift(now + 1);
    }
    var child = list[now].child;
    for(var i = 0; i < child.length; i++){
      if(!list[child[i]].access){
        list[child[i]].access = true;
        stack.push(child[i]);
        break;
      }
    }
  }
  myout(output.length);
  myout(myconv(output, 8));
}


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

int main(){
  int64_t a, b, k;
  cin >> a >> b >> k;
  if (a+b < k){
    a = 0;
    b = 0;
  }
  else if(a < k){
    b = b - (k-a);
    a = 0;
  }
  else{
    a = a - k;
  }
  cout << a << " " << b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
const int MAX=2e5;
const ll MOD=1e9+7;
const int INF=1<<30;

const int MAX_N=2e5+10;//ここは適宜変更
int par1[MAX_N],Rank1[MAX_N];
int par2[MAX_N],Rank2[MAX_N];

void init1(int n){//初期設定として全部の頂点のrootをその頂点番号(0~),length(rankを指す)は0とする
  for (int i=0;i<n;i++){
    par1[i]=i;
    Rank1[i]=0;
  }
}
int root1(int x){//rootを返す関数
  return par1[x]==x?x:par1[x]=root1(par1[x]);
}
bool same1(int x,int y){//二つのrootは同じかを返す関数
  return root1(x)==root1(y);
}
void unite1(int x,int y){//二つを結合する関数
  x=root1(x);
  y=root1(y);
  if(x==y) return;//rootが同じなら何もしない
  if(Rank1[x]<Rank1[y]){
    par1[x]=y;
  }else{
    par1[y]=x;
    if(Rank1[x]==Rank1[y])
      Rank1[x]++;//rankが同じならyのrootをxにしてrankを1上げる
  }
}

void init2(int n){//初期設定として全部の頂点のrootをその頂点番号(0~),length(rankを指す)は0とする
  for (int i=0;i<n;i++){
    par2[i]=i;
    Rank2[i]=0;
  }
}
int root2(int x){//rootを返す関数
  return par2[x]==x?x:par2[x]=root2(par2[x]);
}
bool same2(int x,int y){//二つのrootは同じかを返す関数
  return root2(x)==root2(y);
}
void unite2(int x,int y){//二つを結合する関数
  x=root2(x);
  y=root2(y);
  if(x==y) return;//rootが同じなら何もしない
  if(Rank2[x]<Rank2[y]){
    par2[x]=y;
  }else{
    par2[y]=x;
    if(Rank2[x]==Rank2[y])
      Rank2[x]++;//rankが同じならyのrootをxにしてrankを1上げる
  }
}

int main(){
  int N,K,L;
  cin >> N >> K >> L; 
  init1(N);
  init2(N);
  rep(i,K){
    int a,b;
    cin >> a >> b;
    a--; b--;
    unite1(a,b);
  }
  rep(i,L){
    int a,b;
    cin >> a >> b;
    a--; b--;
    unite2(a,b);
  }
  map<pair<int,int>,int> mp;
  rep(i,N){
    mp[make_pair(root1(i),root2(i))]++;
  }
  rep(i,N){
    cout << mp[make_pair(root1(i),root2(i))];
    if(i==N-1) cout << endl;
    else cout << " ";
  }
  
}

Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define N 1000005
typedef long long int ll;
// int n,m;
// vector<int> adj[mx];

//---dfs--
// bool visited[mx];
// vector<int> val(n,0);

// void dfs(int s, int & cnt_vert, int & cnt_edge){
// 	assert(!visited[s]);
// 	visited[s]=true;
// 	++cnt_vert;
// 	cnt_edge+=adj[s].size();
// 	for(int b:adj[s]){
// 		if(!visited[b]){
// 			dfs(b,cnt_vert,cnt_edge);
// 		}
// 	}
// }
//---dfs---

//---primes---
// const int N = 1e7 + 10;
 
// bool prime[N];
 
// int spf[N];
 
// void calc(){
// 	for(int i = 2; i<1e4; i++){
// 		if(prime[i])
// 			continue;
// 		spf[i] = i;
// 		for(int j = i * i; j < N; j += i){
// 			prime[j] = 1;
// 			spf[j] = i;
// 		}
// 	}
// 	for(int i = 2; i < N; i++)
// 		if(!spf[i])
// 			spf[i] = i;
// }

// vector<pair<int,int>> getp(int x){
// 	int curr=x;
// 	vector<pair<int,int>> ans;
// 	while(curr>1){
// 		int a=spf[curr];
// 		int count=0;
// 		while(curr%a==0){ curr/=a; count++;}
// 		ans.push_back(make_pair(a,count));
// 	}
// 	return ans;
// }

// bool ispr(int n) {
//     for (int i=2;i*i<=n;++i){
//         if(n%i==0){
//             return false;
//         }
//     }
//     return true;
// }
//---primes---

//---segment_tree---
// int upd(int t,int val,int l,int r,int y, int z){
// 	if(y<l||y>r) return tr[val];
// 	if(l==r) return tr[val]=z;
// 	int s=(l+r)/2;
// 	upd(t^1,2*val+1,l,s,y,z);
// 	upd(t^1,2*val+2,s+1,r,y,z);
// 	if(t) tr[val]=tr[2*val+1]|tr[2*val+2];
// 	else tr[val]=tr[2*val+1]^tr[2*val+2];
// 	return tr[val];
// }
//int query(){}
//---segment_tree---


int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	int t=1;
	//cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int> a(n);
		ll sum=0;
		for(int i=0;i<n;i++){
			cin>>a[i];
			sum+=a[i];
		}
		sort(a.rbegin(),a.rend());
		ll ans=a[0];
		int count=n-2;
		int i=1;
		while(count>0){
			if(count==1) {ans+=a[i]; count--;}
			else {
				ans+=2ll*a[i]; count-=2;
			}
			i++;
		}
		cout<<ans<<"\n";
	}
}


Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) xmax = x; return true;
    return false;
}
void solve() {
    ll n, m; cin >> n >> m;
    ll dp[100010];
    FOR(i, 0, 100010) dp[i] = 0;
    dp[0] = 1;
    dp[1] = 1;
    FOR(i, 0, m) {
        ll tmp;
        cin >> tmp;
        dp[tmp] = -1;
    }

    FOR(i, 2, n+1) {
        if (dp[i] < 0) { continue; }
        if (dp[i-1] < 0 && dp[i-2] < 0) {
            cout << 0 << endl;
            return;
        }
        if (dp[i-1] < 0) {
            dp[i] = dp[i-2] % MOD;
        } else if (dp[i-2] < 0) {
            dp[i] = dp[i-1] % MOD;
        } else {
            dp[i] = dp[i-1] % MOD + dp[i-2] % MOD;
        }
        dp[i] %= MOD;
    }
    cout << dp[n] % MOD << endl;
}

signed main() {
    solve();
    return 0;
}

Measured memory_bytes: 1024
/* Volume0-0001(山の高さ) */

import java.io.*;
import java.util.*;

public class Main {
  public static void main (String[] args) throws java.lang.Exception {
    // 入力された値をゲット
   Scanner sc = new Scanner(System.in);

   Integer[] yama = { sc.nextInt(),
                 sc.nextInt(),
                 sc.nextInt(),
                 sc.nextInt(),
                 sc.nextInt(),
                 sc.nextInt(),
                 sc.nextInt(),
                 sc.nextInt(),
                 sc.nextInt(),
                 sc.nextInt()};
   Arrays.sort(yama, Collections.reverseOrder());
   System.out.println(yama[0]);
   System.out.println(yama[1]);
   System.out.println(yama[2]);
 }
}


Measured memory_bytes: 26144
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = in.nextInt();
        while (n > 0) {
            long[] a = new long[n];
            long sum = 0;
            for (int i = 0; i < n; i++) {
                sum += a[i] = in.nextInt();
            }
            int cnt = 0;
            for (int i = 0; i < n; i++) {
                if (a[i] * n <= sum) cnt++;
            }
            out.println(cnt);


            n = in.nextInt();

        }
        out.flush();
    }

}



Measured memory_bytes: 58920
#include<stdio.h>
int main(){
int n,i,f;
char s[50];
scanf("%d", &n);
scanf("%s", s);
for(i=0;i<n;i++){
if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
f++;
}
}
printf("%d\n", f);
return 0;
}

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


int N, M;
vector<int> A;


void input() {
    cin >> N >> M;
    A = vector<int>(N);
    rep(i, N) cin >> A[i];
}


// 最大公約数
ll gcd(ll a, ll b) {
    while (b) {
        ll tmp = a % b;
        a = b;
        b = tmp;
    }
    return a;
}

// 最小公倍数
ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}


int main() {
    input();
    vector<int> B(N);
    rep(i, N) B[i] = A[i] / 2;
    if (N == 1) {
        cout << (M / B[0] + 1) / 2 << endl;
        return 0;
    }
    int x = B[0] % 2;
    rep(i, N) {
        if (B[i] % 2 != x) {
            cout << 0 << endl;
            return 0;
        }
    }
    ll g = lcm(B[0], B[1]);
    for (int i = 2; i < N; i++) g = lcm(g, B[i]);
    rep(i, N) {
        if ((g / B[i]) % 2 == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    cout << (M / g + 1) / 2 << endl;
}


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

import static java.lang.System.in;

public final class Main {
	static Scanner sc = new Scanner(in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		Pair[] pairs = new Pair[N];
		for (int i = 0; i < N; i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();
			pairs[i] = new Pair(L, R);
		}
		Arrays.sort(pairs);
		int[] f = new int[N];
		int[] b = new int[N];
		int min = 0;
		int max = 1000000000;
		for (int i = 0; i < N; i++) {
			min = Math.max(min, pairs[i].l);
			max = Math.min(max, pairs[i].r);
			f[i] = Math.max(0, max - min + 1);
		}
		min = 0;
		max = 1000000000;
		for (int i = N - 1; i >= 0; i--) {
			min = Math.max(min, pairs[i].l);
			max = Math.min(max, pairs[i].r);
			b[i] = Math.max(0, max - min + 1);
		}
		int ans = 0;
		for (int i = 0; i < N - 1; i++) {
			ans = Math.max(ans, f[i] + b[i + 1]);
		}
		int[] rs = new int[N];
		for (int i = 0; i < N; i++) {
			rs[i] = pairs[i].r;
		}
		Arrays.sort(rs);
		for (int i = 0; i < N; i++) {
			int v = pairs[i].r - pairs[i].l + 1;
			int ml = i == N - 1 ? pairs[N - 2].l : pairs[N - 1].l;
			int mr = pairs[i].r == rs[0] ? rs[1] : rs[0];
			v += Math.max(0, mr - ml + 1);
			ans = Math.max(ans, v);
		}
		System.out.println(ans);
	}

	static class Pair implements Comparable<Pair> {
		int l, r;

		public Pair(int l, int r) {
			this.l = l;
			this.r = r;
		}

		@Override
		public int compareTo(Pair o) {
			if (this.l != o.l) return Integer.compare(this.l, o.l);
			return Integer.compare(this.r, o.r);
		}
	}
}


Measured memory_bytes: 95692
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define SZ(v)       (ll)(v).size()
#define ALL(v)      (v).begin(), (v).end()
#define UNIQ(v)     sort(ALL(v)); (v).erase(unique(ALL(v)), (v).end())
#define IN(x,l,r)   ((l)<=(x) && (x)<=(r))
#define BIT(n)      (1LL<<(n))
#define PQ(T)       priority_queue<T, vector<T>, greater<T>>
#define SHOW(x)     cout << #x << " = " << x << endl

template<typename T>string join(const vector<T>& v, string d=" ")
{stringstream s;REP(i,SZ(v))s<<d<<v[i];return s.str().substr(d.length());}

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v)
{if(SZ(v))s<<join(v,", ");return s;}

const ll inf = 1e15;
const ll mod = 1e9+7;
const double eps = 1e-10;

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

int main() {
    ll H, W, N; cin >> H >> W >> N;
    
    set<pair<ll, ll>> S1, S2;
    REP(i, N) {
        ll x, y; cin >> x >> y;
        S1.insert(make_pair(x, y));
        REP(j, 3) REP(k, 3) S2.insert(make_pair(x-j, y-k));
    }
    
    vector<ll> ans(10);
    ans[0] = (H-2)*(W-2);
    for (auto p: S2) {
        ll x = p.first;
        ll y = p.second;
        
        if (not IN(x, 1, H-2)) continue;
        if (not IN(y, 1, W-2)) continue;
        
        ll sum = 0;
        REP(j, 3) REP(k, 3) sum += S1.count(make_pair(x+j, y+k));
        
        ans[sum]++;
        ans[0]--;
    }
    
    for (auto x: ans) {
        cout << x << endl;
    }
    
    return 0;
}


Measured memory_bytes: 62720
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
 
/*** Template Begins ***/
 
typedef long long    ll;
typedef pair<ll,ll>  pll;
typedef pair<ll, pair<int, int> > plll;
typedef vector<long long>  vll;
typedef vector<pll>  vp;
typedef long double ld;
#define pb           push_back
#define INF          INT_MAX/10
#define F            first
#define S            second
#define mp           make_pair
// #define ios          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define hell         1000000007
// #define h 998244353
#define all(a)       (a).begin(),(a).end()
ll power(ll x, ll y, ll p)
{
  ll res = 1;
  x = x % p;
  while (y > 0)
  { 
    if (y & 1) 
      res = (res*x) % p;
    y = y>>1;
    x = (x*x) % p;
  } 
  return res; 
} 
const int MAXN = 1e5+7;

// Debug //
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
// #define trace6(a, n,i;b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

// Constants //
 
/*** Template Ends ***/

void solve()
{
  ll n;
  cin>>n;
  if(n%2)
    cout<<n/2+1;
  else
    cout<<n/2;

}
int main()
{ 
  // ios;
  // fxreopen("inputt.txt", "w", stdout);
  ll t;
  // cin >> t;
  t=1;
  while(t--)
    solve();
  return 0;
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
	cin.tie(0);
    
    int s, w;
    cin >> s >> w;
    
    cout << (w >= s ? "unsafe" : "safe") << endl;
    
    return 0;
}


Measured memory_bytes: 3640
/*
	Powered by C++11.
	Author : Alex_Wei.
*/

#include <bits/stdc++.h>
using namespace std;

//#pragma GCC optimize(3)
//#define int long long

#define ll long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb emplace_back
#define all(x) x.begin(),x.end()
#define sor(x) sort(all(x))
#define rev(x) reverse(all(x))
#define mem(x,v) memset(x,v,sizeof(x))

// Templates start.

namespace IO{
	char buf[1<<21],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;
	#ifdef __WIN32
		#define gc getchar()
	#else
		#define gc (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
	#endif
	#define pc(x) (*O++=x)
	#define flush() fwrite(obuf,O-obuf,1,stdout)

	inline int read(){
		int x=0,sign=0; char s=gc;
		while(!isdigit(s))sign|=s=='-',s=gc;
		while(isdigit(s))x=(x<<1)+(x<<3)+(s-'0'),s=gc;
		return sign?-x:x;
	}
	void print(int x) {if(x>9)print(x/10); pc(x%10+'0');}
}

namespace math{
	const int mod=998244353;
	const int maxn=1e6+5;

	ll ksm(ll a,ll b){ll s=1,m=a; while(b){if(b&1)s=s*m%mod; m=m*m%mod,b>>=1;} return s;}
	ll inv(ll x){return ksm(x,mod-2);}

	ll fc[maxn],ifc[maxn];
	void init_m(int n){
		fc[0]=1; for(int i=1;i<=n;i++)fc[i]=fc[i-1]*i%mod;
		ifc[n]=inv(fc[n]); for(int i=n-1;i>=0;i--)ifc[i]=ifc[i+1]*(i+1)%mod;
	}
	ll C(ll n,ll m){return fc[n]*ifc[m]%mod*ifc[n-m]%mod;}
}

// Templates end. Please give me more points.

using namespace IO;
//using namespace math;

const int N=5e5+5;


int main(){
	int x;
	cin>>x;
	cout<<360/__gcd(x,360); 
	
	return 0;
}









Measured memory_bytes: 3560
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::iter::Iterator;
use std::collections::HashSet;
use std::cmp::*;
use itertools::Itertools;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }
  
  #[allow(unused_macros)]
  macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        a: u128,
        b: f64,
    }

    let b = (b * 100.0).round() as u128;

     println!("{}", a * b / 100);
}


Measured memory_bytes: 2640
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define REP(i, l, r) for (int i=(l); i<(r); ++i)
#define RREP(i, r, l) for (int i=(r); i>(l); --i)
#define CASET int _T; cin >> _T; REP(caset, 0, _T)
#define print(x) cout << to_string(x) << '\n'
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vvi vector<vi>
#define vvb vector<vb>
#define pii pair<int,int>
#define t3i tuple<int,int,int>
#define mii map<int,int>
#define vpii vector<pii>
#define vt3i vector<t3i>
#define sq(x) (x)*(x)
#define inv(x) powa(x, MOD-2)
 
long long INF = 1LL<<60;
long long MOD = 998244353;

string to_string(char &c) {string x(1, c); return x;}
string to_string(const char s[]) {return (string)s;}
string to_string(string &s) {return s;}
string to_string(vb &v) {string res; for (const bool &x : v) res += to_string(x) + ' '; return res;}
template <class C> string to_string(C &v) {string res; for (auto &x : v) res += to_string(x) + ' '; return res;}
template <typename A, typename B> istream &operator>>(istream &is, pair<A, B> &pr) {is >> pr.first >> pr.second; return is;}
template <typename A> istream &operator>>(istream &is, vector<A> &v) {for (auto &x : v) is >> x; return is;}
ostream &operator<<(ostream &os, char &c) {os << (char)c; return os;}
ostream &operator<<(ostream &os, const char s[]) {os << (string)s; return os;}
ostream &operator<<(ostream &os, string &s) {for (char &c : s) os << (char)c; return os;}
template <typename A, typename B> ostream &operator<<(ostream &os, pair<A, B> pr) {os << '(' << pr.first << ", " << pr.second << ')'; return os;}
ostream &operator<<(ostream &os, vb &v) {
    bool first = true;
    os << '[';
    for (const bool &x : v) {
        if (!first) os << ", ";
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
template <class C> ostream &operator<<(ostream &os, C &v) {
    bool first = true;
    os << '[';
    for (auto &x : v) {
        if (!first) os << ", ";
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
string bin_string(int x) {
    const int d = 32;
    string res(d, ' ');
    REP(i, 0, d) res[d-1-i] = '0'+(x>>i & 1LL);
    return res;
}
int powa(int base, int exp) {
    int res = 1;
    while (exp) {
        if (exp&1) res = res*base % MOD;
        base = base*base % MOD;
        exp >>= 1;
    }
    return res;
}

main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    int k, x;
    cin >> k >> x;
    k *= 500;
    if (k >= x) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
N, K, *V = $<.read.split.map(&:to_i)

p [*-K..0].product([*0..K]).select{|l,r| r-l <= [N,K].min }.map{|l,r|
	v = V.values_at(*l...0) + V[0...r]
	v.inject(0,:+) - v.min(K-v.size).select{|_|_<0}.inject(0,:+)
}.max


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

#define scanf abacaba
#define printf abacaba

 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
using namespace std;
 
 
/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/
 
multiset<pair<int, int>> sl;
multiset<pair<int, int>> sr;
 
ll solve(int x) {
	ll ans = 0;
	ll cur = 0;
	int fl = 0;
	for (int i = x; !sl.empty() && fl < 1; ++i) {
		pair<int, int> p;
		if (i % 2 == 0) {
			p = *sl.rbegin();
			if (p.first <= cur && p.second >= cur) {
				fl += 1;
				continue;
			}
			sl.erase(sl.find(p));
			sr.erase(sr.find(make_pair(p.second, p.first)));
		}
		else {
			p = *sr.begin();
			swap(p.first, p.second);
			if (p.first <= cur && p.second >= cur) {
				fl += 1;
				continue;
			}
			sl.erase(sl.find(p));
			sr.erase(sr.find(make_pair(p.second, p.first)));
		}
		fl = 0;
		if (cur < p.first) {
			ans += abs(p.first - cur);
			cur = p.first;
		}
		else {
			ans += abs(p.second - cur);
			cur = p.second;
		}
	}
	ans += abs(cur);
	return ans;
}
 
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int l, r;
		cin >> l >> r;
		sl.insert(make_pair(l, r));
		sr.insert(make_pair(r, l));
	}
	auto tmpl = sl;
	auto tmpr = sr;
	ll ans = solve(0);
	sl = tmpl;
	sr = tmpr;
	ans = max(ans, solve(1));
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 18944
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

struct query{
  ll type;//0=empty, 1=add-sum ,2=set-min
  ll value;
  query(ll a=0,ll b=0):type(a),value(b) {}
};

ll INF=(1LL<<60);

struct segtree{
  ll SIZE;
  vector<query> s;
  vector<ll> t;// sum-add
  vector<ll> u;// min-set

  segtree(ll n=1){
    SIZE=1;
    while(SIZE<n)SIZE*=2;
    s.clear();
    t.clear();
    u.clear();
    s.resize(SIZE*2, query());
    t.resize(SIZE*2, 0);
    u.resize(SIZE*2, 0);
  }
  
  void func(ll k,ll l,ll r,query q){
    if(q.type==1){
      if(s[k].type==0)s[k]=q;
      else s[k].value+=q.value;
      t[k]+=q.value*(r-l);
      u[k]+=q.value;
    }
    if(q.type==2){
      s[k]=q;
      t[k]=q.value*(r-l);
      u[k]=q.value;
    }
  }

  void compute(ll k,ll l,ll r){
    query q=s[k];
    s[k]=query();
    if(q.type==0||r-l==1)return;
    ll m=(l+r)/2;
    func(k*2+1,l,m,q);
    func(k*2+2,m,r,q);
  }

  void Update(ll a,ll b,query x,ll k,ll l,ll r){
    if(b<=l || r<=a)return;
    compute(k,l,r);
    if(a<=l && r<=b){
      func(k,l,r,x);
    }else{
      ll m=(l+r)/2;
      Update(a,b,x,k*2+1,l,m);
      Update(a,b,x,k*2+2,m,r);
      t[k]=t[k*2+1]+t[k*2+2];
      u[k]=min(u[k*2+1],u[k*2+2]);
    }
  }

  ll Dfs(ll type,ll a,ll b,ll k,ll l,ll r){
    if(b<=l || r<=a){
      if(type==1)return 0; //add
      if(type==2)return INF; // min
    }
    compute(k,l,r);
    if(a<=l && r<=b){
      if(type==1)return t[k];
      if(type==2)return u[k];
    }else{
      ll m=(l+r)/2;
      ll lv=Dfs(type,a,b,k*2+1,l,m);
      ll rv=Dfs(type,a,b,k*2+2,m,r);
      if(type==1)return lv+rv; // add
      if(type==2)return min(lv,rv); // min
    }
  }

  void Add(ll a,ll b,ll x){
    Update(a,b,query(1,x), 0,0,SIZE);
  }
  void Set(ll a,ll b,ll x){
    Update(a,b,query(2,x), 0,0,SIZE);
  }
  ll Getsum(ll a,ll b){
    return Dfs(1,a,b, 0,0,SIZE);
  }

  ll Getmin(ll a,ll b){
    return Dfs(2,a,b, 0,0,SIZE);
  }
  
};



int main(){
  ll n,q;
  cin >> n >> q;
  segtree T(n);
  T.Set(0,n,2147483647);
  
  for(ll i=0;i<q;i++){
    ll type,a,b,c;
    cin >> type >> a >> b;
    if(type==0){
      cin >> c;
      T.Set(a,b+1,c);
    }
    else {
      cout << T.Getmin(a,b+1) << endl;
    }
  }
  return 0;
}


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

int main() {
    int64_t n, m;
    cin >> n >> m;
    int64_t lcm = 1;

    int64_t d = -1;
    for (int64_t i = 0; i < n; i++) {
        int64_t a;
        cin >> a, a /= 2;

        int64_t t = 0;
        for (int64_t b = a; b % 2 == 0; b /= 2) t++;
        if (d != -1 && d != t) {
            cout << 0 << endl;
            return 0;
        }
        d = t;
        
        lcm = lcm * a / __gcd(lcm, a);
        if (lcm > m) {
            cout << 0 << endl;
            return 0;
        }
    }
    cout << (m / lcm + 1) / 2 << endl;
}


Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
#include<cmath>
using namespace std;
void read(int &x){
	char ch;bool ok;
	for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
	for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok)x=-x;
}
#define rg register
const int maxn=210;bool vis[maxn];
int f[maxn],n,ans,a[maxn],mp[maxn][maxn],b[maxn],tot1,tot2,x[maxn];
bool check(int x){
	if((!(x&1))||x==1)return 0;
	int n=sqrt(x);
	for(rg int i=2;i<=n;i++)
		if(!(x%i))return 0;
	return 1;
}
bool dfs(int x){
	for(rg int i=1;i<=tot2;i++)
		if(!vis[i]&&mp[x][i]){
			vis[i]=1;
			if(!f[i]||dfs(f[i]))return f[i]=x,1;
		}
	return 0;
}
int main(){
	read(n);
	for(rg int i=1;i<=n;i++)read(x[i]);
	if(n==1){printf("3\n");return 0;}
	for(rg int i=1;i<=n;i++){
		if(x[i+1]-x[i]!=1||i==n){
			if((x[i]+1)%2==0)a[++tot1]=x[i]+1;
			else b[++tot2]=x[i]+1;
		}
		if(x[i]-x[i-1]!=1||i==1){
			if(x[i]&1)b[++tot2]=x[i];
			else a[++tot1]=x[i];
		}
	}
	for(rg int i=1;i<=tot1;i++)
		for(rg int j=1;j<=tot2;j++)
			if(check(abs(a[i]-b[j])))mp[i][j]=1;
	for(rg int i=1;i<=tot1;i++){
		memset(vis,0,sizeof vis);
		if(dfs(i))ans++;
	}
	//	printf("%d\n",ans);
	printf("%d\n",ans+(tot1-ans)/2*2+(tot2-ans)/2*2+(tot1-ans)%2*3);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#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 Rep(j,n) for(int j=i+1;j<(int)(n);++j)

#define int long long

using namespace std;

signed main()
{
    bool maxtrue=true;
int j,i,a[5],maxnumber;
rep(i,5){
a[i]=0;
cin>>a[i];
}
cin>>maxnumber;
rep(i,5){
Rep(j,5){
if(abs(a[i]-a[j])>maxnumber){
maxtrue=false;
}
}
}
cout<<((maxtrue)?"Yay!":":(");
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
using namespace std;
int n,d;
int main ()
{
	scanf("%d%d",&n,&d);
	if(n%((d*2)+1)==0)
		printf("%d",n/((d*2)+1));
	else
		printf("%d",n/((d*2)+1)+1);
	return 0;
}

Measured memory_bytes: 128
//#pragma GCC diagnostic error "-std=c++11"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5e5 + 5;
const ll inf = 0x3f3f3f3f3f;
bool dislike[100];
ll n,k;

bool judge(int n)
{
	while(n)
	{
		if(dislike[n%10]) return false;
		n/=10;
	}
	return true;
}

int main(){
	cin>>n>>k;
	for(int i=1;i<=k;i++)
	{
		ll q;
		cin>>q;
		dislike[q]=1;
	}
	for(int i=n;;i++)
	{
		if(judge(i))
		{
			cout<<i;
			return 0;
		}
	}
	return 0;
}

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

vector<ll> f(const vector<ll> &a) {
	const int n = (int) a.size();
	vector<ll> dp(n + 1, 0);
	ll sum = 0;
	for (int i = 1; i <= n; ++i) {
		const ll x = a[i - 1];
		sum += x;
		dp[i] = min(sum, dp[i - 1] + (x - 2 < 0 ? 2 - x : x & 1));
	}
	return dp;
}

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

	int n;
	cin >> n;
	vector<ll> a(n);
	for (ll &x : a)
		cin >> x;

	vector<ll> dp = f(a);

	for (int i = 1; i <= n; ++i) {
		const ll x = a[i - 1];
		dp[i] = min(dp[i], dp[i - 1] + (x == 0 ? 1 : (x - 1) & 1));
	}

	reverse(a.begin(), a.end());
	vector<ll> dp2 = f(a);

	ll ans = 1LL << 60;
	for (int i = 0; i <= n; ++i) {
		ans = min(ans, dp[i] + dp2[n - i]);
	}
	cout << ans;
	return 0;
}


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

using namespace std;

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

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	int n=s.size();
	REP(i, n){
		REP(j, n-i+1){
			string tmp="";
			if(j>0){
				tmp+=s.substr(0, j);
			}
			tmp+=s.substr(j+i, n);
			if(tmp=="keyence"){
				cout<<"YES"<<'\n';
				return 0;
			}
		}
	}
	cout<<"NO"<<'\n';
	return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        d: usize,
        t: usize,
        s: usize
    };

    let res = if s * t >= d { "Yes" } else { "No" };
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2236
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#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>
#define INF 100000000
using namespace std;


int main(){
  int N,M,R;

  // N = 街の数 , M = 道の数, R = 訪れるべき街の数
  cin >> N >> M >> R;
  int dist[N][N];

  // 自己ループは0 その他の道はINFに設定
  for(int i = 0; i < N; i++) for(int j = 0; j < N; j++){
    if(i == j) dist[i][j] = 0;
    else dist[i][j] = INF;
  }

  //訪れるべき街リストの作成(0index)
  vector<int> r(R);
  for(int i = 0; i < R; i++){
    cin >> r[i];
    r[i]--;
  }

  //道のコストをdist[][]に格納 (双方向)
  for(int i = 0; i < M; i++){
    int to,from,cost;
    cin >> to >> from >> cost;
    to --; from--;
    dist[to][from] = cost;
    dist[from][to] = cost;
  }

  //ワーシャルフロイド
  for(int k = 0; k < N; k++){
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        if (dist[i][k] != INF && dist[k][j] != INF) {
          dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
        }
      }
    }
  }

  //順列用の配列を作成
  vector<int> perm(R);
  for(int i = 0; i < R; i++) perm[i] = i;

  int ans = INF;

  /*cout << endl;
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      cout << dist[i][j] << " ";
    }
    cout << endl;
  }//*/

  //next permutation で順列を回す
  do{
    int d = 0;
    for(int i = 0; i < R-1; i++){
      d += dist[r[perm[i]]][r[perm[i+1]]];
    }
    ans = min(ans,d);
  }while(next_permutation(perm.begin(), perm.end()));

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(void){
  int n,k,s[100],b;

  while(cin >> n >> k,n|k){
    for(int i=0;i<k;i++)cin >> s[i];
    
    for(int i=0;i<n;i++){
      for(int j=0;j<k;j++){
	cin >> b;
	s[j]-=b;
      }
    }
    
    bool fg=false;
    for(int i=0;i<k;i++){
      if(s[i]<0){
	cout << "No" << endl;
	fg=true;
	break;
      }
    }
    if(!fg)cout << "Yes" << endl;
  }

  return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {
	  public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);

		   String a = scanner.next();
		   String b = scanner.next();
		   int A = Integer.parseInt(a);
		   int B = Integer.parseInt(b);
		   
		   if(A <= 8 && B <= 8)
		   {
			   System.out.println("Yay!");
		   }
		   else 
		   {
			   System.out.println(":(");
		   }
        	scanner.close();}
		  }

Measured memory_bytes: 23764
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 400000000;
	int r;
	Scanner sc;

	void run() {
		sc = new Scanner(System.in);
		for(;;) {
			r = sc.nextInt();
			if( r == 0) break;
			Pair[] a = scan();
			Pair[] b = scan();
//			for(Pair p: a) debug(p.f, p.s);
//			for(Pair p: b) debug(p.f, p.s);

			int min = INF;
			int i=0,j=b.length-1;
			for(;;) {
				if(i == a.length || j == -1) break;
				if(a[i].s+b[j].s >= r) {
					min = min(a[i].f + b[j].f, min);
					j--;
				}
				else {
					i++;
				}
			}

			System.out.println(min);
		}
	}

	int w, h;
	int[][] map;
	boolean[][] visited;
	int sx, sy;

	Pair[] scan() {
		w = sc.nextInt();
		h = sc.nextInt();
		map = new int[h+2][w+2];
		visited = new boolean[h+2][w+2];

		for(int[] a: map) fill(a, INF);

		sx = sc.nextInt();
		sy = sc.nextInt();

		for(int i=1;i<=h;i++) for(int j=1;j<=w;j++)
			map[i][j] = Integer.parseInt(sc.next());
//		for(int[] a: map) debug(a);
		PriorityQueue<P> que = new PriorityQueue<P>(1, new Comp());
		que.add(new P(sx, sy));
		LinkedList<Pair> pairs = new LinkedList<Pair>();
		visited[sy][sx] = true;
		for(;;) {
			P p = que.remove();
//			debug(p.x, p.y, map[p.y][p.x]);
			if( map[p.y][p.x]== INF ) break;

			for(int i=0;i<4;i++) if( !visited[p.y+dy[i]][p.x+dx[i]] ) {
				que.add(new P(p.x+dx[i], p.y+dy[i]));
				visited[p.y+dy[i]][p.x+dx[i]] = true;
			}

			pairs.add( new Pair( map[p.y][p.x], bfs(que, map[p.y][p.x]) ) );


		}

		Pair[] pp = new Pair[pairs.size()+1];
		pp[0] = new Pair(0, 0);
		int size = pairs.size();
		for(int i=1;i<=size;i++) {
			Pair pair = pairs.remove();
			pp[i] = new Pair( pair.f, pair.s + pp[i-1].s );
		}

		return pp;
	}

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

	int bfs(PriorityQueue<P> que, int lev) {
		int cnt = 1;
		if(que.isEmpty()) return cnt;
		for(;;) {
			P p = que.remove();
			if( map[p.y][p.x] > lev  ) {
				que.add(p);
				break;
			}
			cnt++;
			for(int i=0;i<4;i++) if( !visited[p.y+dy[i]][p.x+dx[i]] ) {
				que.add(new P(p.x+dx[i], p.y+dy[i]));
				visited[p.y+dy[i]][p.x+dx[i]] = true;
			}
		}

		return cnt;
	}

	class Pair {
		int f,s;
		Pair(int f, int s ) {
			this.f = f;
			this.s = s;
		}
	}

	class Comp implements Comparator<P> {

		@Override
		public int compare(P o1, P o2) {
			// TODO 自動生成されたメソッド・スタブ
			return map[o1.y][o1.x] - map[o2.y][o2.x];
		}

	}

	class P {
		int x, y;
		P (int x, int y) {
			this.x = x;
			this.y = y;
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 25000
import java.util.*;

public class Main {
	static int dp[][];

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int k = scn.nextInt();
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = scn.nextInt();
		}
		Boolean dp[] = new Boolean[k + 1];
		dp[0] = false;

		for (int i = 1; i <= k; i++) {
			boolean res = false;
			for (int j = 0; j < a.length; j++) {
				if (i - a[j] >= 0 && dp[i - a[j]] != null) {
					res = res | !dp[i - a[j]];
				}
			}
			dp[i] = res;
		}
		System.out.println(dp[k]?"First":"Second");
	}

	
	private static boolean solve(int k, int p, int[] a, Boolean[][] dp) {
		if (k == 0) {
			return true;
		}

		if (dp[k][p] != null) {
			return dp[k][p];
		}
		boolean res = false;
		for (int i = 0; i < a.length; i++) {
			if (k - a[i] >= 0) {
				res = res || !solve(k - a[i], (p + 1) % 2, a, dp);
			}

		}
		dp[k][p] = res;
		return res;

	}

}

Measured memory_bytes: 24020
#include <iostream>
#include <algorithm>
 
using namespace std;
 
const int N = 30;
  
int h, w, n;
char data[N][N];
char tmp[N][N];
 
void copy(){
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      tmp[i][j] = data[i][j];
    }
  }
}
 
int erase(){
  int res = 0;
  bool f[N][N];
  fill(f[0], f[N], false);
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(tmp[i][j] == '.') continue;
      int k;
      for(k=j;k<w&&tmp[i][j]==tmp[i][k];k++);
      if(k - j >= n) for(int l=j;l<k;l++) f[i][l] = true;
    }
  }
  for(int j=0;j<w;j++){
    for(int i=0;i<h;i++){
      if(tmp[i][j] == '.') continue;
      int k;
      for(k=i;k<h&&tmp[i][j]==tmp[k][j];k++);
      if(k - i >= n) for(int l=i;l<k;l++) f[l][j] = true;
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(f[i][j]){
        tmp[i][j] = '.';
        res++;
      }
    }
  }
  return res;
}
 
void fall(){
  for(int i=h-1;i>=0;i--){
    for(int j=0;j<w;j++){
      if(tmp[i][j] == '.') continue;
      int k;
      for(k=i+1;k<h&&tmp[k][j]=='.';k++);
      swap(tmp[i][j], tmp[k-1][j]);
    }
  }
}
 
bool check(){
  int cnt = 0;
  for(int i=0;i<h;i++) for(int j=0;j<w;j++) if(data[i][j] != '.') cnt++;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(data[i][j] == '.') continue;
      for(int k=-1;k<=1;k++){
        if(!k) continue;
        int ny = i;
        int nx = j + k;
        if(nx < 0 || nx >= w) continue;
        swap(data[i][j], data[ny][nx]);
        copy();
        int rem = cnt;
        fall();
        while(1){
          int tmp = erase();
          rem -= tmp;
          if(!tmp) break;
          fall();
        }
        if(!rem) return true;
        swap(data[i][j], data[ny][nx]);
      }
    }
  }
  return false;
}
 
main(){
  cin >> h >> w >> n;
  for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin >> data[i][j];
  cout << (check() ? "YES" : "NO") << endl;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main(){
  int N; cin>>N;
  vector<P>job(N);
  for(int i=0;i<N;i++) 
    cin>>job.at(i).second>>job.at(i).first;
  sort(job.begin(),job.end());
  
  long long time=0;
  bool OK=true;
  
  for(int i=0;i<N;i++){
    time+=job.at(i).second;
    if(time>job.at(i).first){
      OK=false;
      break;
    }
  }
  
  if(OK)
    cout<<"Yes";
  else
    cout<<"No";
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int ans = a[a.length - 1] - a[0];
        int dis1 = 0;
        int dis2 = 0;
        int dis = 0;
        for (int i = 1; i < n-1; i++) {
            dis1 = k - a[i] + a[i - 1];
            dis2 = a[i] + k - a[i+1];
            dis = Math.min(dis1, dis2);
            ans = Math.min(ans, dis);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 79184
#include<stdio.h>
#include<math.h>
#include<string.h>

int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    int c;
    if(a>=b){
        c=b;
    }
    else{
        c=a;
    }
    int d=0;
    for(int i=1;i<=pow(10,(a+b-c-1));i*=10){
        d+=i*c;
    }
    printf("%d\n",d);
}    

Measured memory_bytes: 128