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

int main() {
	int n;
	cin >> n;
	unordered_map<int, int> mp;
	for(int i = 0; i < n; i++) {
		int _;
		cin >> _;
		mp[_]++;
	}
	int ans = 0;
	for(auto m: mp) {
		int num = m.first;
		int freq = m.second;
		if(num > freq) ans += freq;
		else ans += freq-num;
	}
	printf("%d", ans);
}


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

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {


		int N = nextInt();

		int[] p = nextInts();

		long ans =0;
		if(p[0]==1){
			int tmp =p[0];
			p[0]=p[1];
			p[1]=tmp;
			ans++;
		}
		if(p[N-1]==N){
			int tmp =p[N-1];
			p[N-1]=p[N-2];
			p[N-2]=tmp;
			ans++;
		}

		for(int i=0;i<N;i++){
			if(p[i]==i+1){
				int tmp =p[i];
				p[i]=p[i+1];
				p[i+1]=tmp;
				ans++;
			}
		}
		System.out.println(ans);
	}



	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


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

using namespace std;

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

    int a, b, c;
    std::cin >> a >> b >> c;
    std::swap(a, b);
    std::swap(a, c);
    std::cout << a << " " << b << " " << c << "\n";
    return 0;
}

Measured memory_bytes: 256
from heapq import heapify,heappop,heappush
from math import ceil

def solve(A,N,K):
    ans_max,ans_min = max(A),1

    while True:
        if cutable(A,N,K,(ans_max+ans_min)//2):
            if ans_max > (ans_max+ans_min)//2:
                ans_max = (ans_max+ans_min)//2
            else:
                return ans_max
        else:
            if ans_min < (ans_max+ans_min)//2:
                ans_min = (ans_max+ans_min)//2
            else:
                return ans_max

def cutable(A,N,K,div):
    #K回までの切断で全部を長さdiv以下にできるかどうか
    cnt = 0
    for i in range(N):
        cnt += A[i]//div
        if A[i] % div == 0:
            cnt -= 1
        if cnt > K:
            return False

    return True

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))

    ans = solve(A,N,K)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 31024
#include <iostream>
#include <string>

using namespace std;

void A_Station_and_Bus(void) {

	string S;

	cin >> S;

	cout << ((S[0] == S[1] && S[0] == S[2]) ? "No" : "Yes");

	return;
}

void B_Count_Balls(void) {

	long n;
	int a, b;
	long count = 0;

	cin >> n >> a >> b;

	count = (n - (n % (a + b))) / (a + b);

	if (n % (a + b) <= a) {

		cout << n % (a + b) + count * a;
	}
	else {

		cout << a + count * a;
	}

	return;
}

void C_Tax_Increase(void) {

	int a, b;

	int pa[1000] = { -1 };
	int pb[1000] = { -1 };

	int flag = 0;

	int re = 0;

	cin >> a >> b;

	for (int loop = 1; loop < 1400; loop++) {

		if ((int)(loop * 0.08) == a && flag < 1000) {
			pa[flag] = loop;
			flag++;
		}
	}

	flag = 0;
	for (int loop = 1; loop < 1400; loop++) {

		if ((int)(loop * 0.1) == b && flag < 1000) {
			pb[flag] = loop;
			flag++;
		}
	}

	for (int xloop = 0; xloop < 1000; xloop++) {

		for (int yloop = 0; yloop < 1000; yloop++) {

			if (pa[xloop] != -1 && pa[xloop] == pb[yloop]) {

				re = pa[xloop];
			}
		}
	}

	for (int xloop = 0; xloop < 1000; xloop++) {

		for (int yloop = 0; yloop < 1000; yloop++) {

			if (pa[yloop] != -1 && pa[yloop] == pb[xloop]) {

				if (re > pa[yloop]) re = pa[yloop];
			}
		}
	}

	if (re > 0) {

		cout << re << flush;
	}
	else {

		cout << -1 << flush;
	}

	return;
}

void D_String_Formation(void) {

	string S;
	int Q;

	cin >> S;
	cin >> Q;

	int T;
	int F;
	char C;

	int max = 0;
	char sBuff;

	int loop1 = 0;
	int loop2 = 0;

	for (loop1 = 0; loop1 < Q; loop1++) {

		cin >> T;

		if (T == 1) {

			max = (int)(S.size() * 0.5);

			for (loop2 = 0; loop2 < max; loop2++) {

				sBuff = S[loop2];
				S[loop2] = S[S.size() - loop2 - 1];
				S[S.size() - loop2 - 1] = sBuff;
			}
		}
		else {

			cin >> F >> C;

			if (F == 1) {

				S = C + S;
			}
			else {

				S = S + C;
			}
		}
	}

	cout << S;

	return;
}

int main(void) {

	A_Station_and_Bus();
	//B_Count_Balls();
	//C_Tax_Increase();
	//D_String_Formation();

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static Scanner sc;
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        if (a > b) {
            System.out.println("a > b");
        } else if (a < b) {
            System.out.println("a < b");
        } else {
            System.out.println("a == b");
        }
    }
}

Measured memory_bytes: 26156
'use strict'

function main(input) {
  input = input.split('\n').map(v => v.split(' ').map(v => ~~v))
  const n = input[0][0]
  // const M = input[0][1]
  const ships = input.slice(1, input.length)

  let setA = new Set()
  let setB = new Set()
  for (let i = 0; i < ships.length; i++) {
    if (ships[i][0] == 1) {
      setA.add(ships[i][1])
    }
    if (ships[i][1] == n) {
      setB.add(ships[i][0])
    }
  }
  // console.log(shipsA, shipsB)

  for (let i = 1; i < n; i++) {
    if (setA.has(i) && setB.has(i)) {

      console.log('POSSIBLE')
      return
    }
  }
  let ans = 'IMPOSSIBLE'
  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

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

using namespace std;

int a[100];

long long  dp[100][21];

int main()
{
	int n; cin >> n;

	for (int i = 0; i < n; ++i) cin >> a[i];

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

	for (int i = 1; i < n - 1; ++i) {
		for (int j = 0; j <= 20; ++j) {
			if (j + a[i] <= 20) dp[i][j] += dp[i - 1][j + a[i]];
			if (j - a[i] >= 0) dp[i][j] += dp[i - 1][j - a[i]];
		}
	}

	printf("%lld\n", dp[n - 2][a[n - 1]]);
}

Measured memory_bytes: 1164
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
int n;
cin>>n;
V<ll> a(n),l(n,1),r(n,1);
for(int i=0;i<n;i++){
	cin>>a[i];
	l[i]=a[i];
	r[i]=a[i];
}
for(int i=0;i<n-1;i++)l[i+1]=gcd(l[i],l[i+1]);
for(int i=n-1;i>=1;i--)r[i-1]=gcd(r[i],r[i-1]);
ll ans=max(l[n-2],r[1]);
for(int i=0;i<n-2;i++){
    ll d=gcd(l[i],r[i+2]);
	chmax(ans,d);
}
cout<<ans<<endl;
}



Measured memory_bytes: 2560
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<fstream>
using namespace std;
const int mod=1000000007;
int n,m;
int f[3003][3003][2];
int dp(int tur,int num,int sta){
	int &ret=f[tur][num][sta];
	if(ret!=-1){
		return ret;
	}
	if(tur==m){
		if(sta==1){
			return ret=1;
		}
		return ret=0;
	}
	ret=0;
	if(num){
		ret=(ret+dp(tur+1,num-1,sta|(num==1)))%mod;//-1 red,+1 red,+1 blue,-1 red
	}
	if(num){
		ret=(ret+dp(tur+1,num,sta|(num==1)))%mod;//-1 red,+1 red,+1 blue,-1 blue
	}
	if(n-num){
		ret=(ret+dp(tur+1,num,sta))%mod;//-1 blue,+1 red,+1 blue,-1 red
	}
	if(n-num){
		ret=(ret+dp(tur+1,num+1,sta))%mod;//-1 blue,+1 red,+1 blue,-1 blue
	}
	return ret;
}
int main(){
	memset(f,-1,sizeof(f));
	cin>>n>>m;
	long long ans=0;
	ans=(ans+dp(0,0,1))%mod;
	for(int i=1;i<=n;i++){
		ans=(ans+dp(0,i,0))%mod;
	}
	cout<<ans<<endl;
	return 0;
}
/*

in:
2 3

out:
56

in:
1000 10

out:
1048576

*/

Measured memory_bytes: 71040
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  using ll = long long;
  using P = pair<ll, ll>;
  constexpr int MOD = 1000000007;
  auto normalize = [](const P& p){
  	auto [A, B] = p;
  	if (A == 0) B = abs(B);
  	else if (B == 0) A = abs(A);
  	else if (B < 0) A *= -1, B *= -1;
  	return make_pair(A, B);
  };
  auto modpow = [&](ll a, int n) -> int {
  	ll res{1};
  	while (n > 0) {
  		if (n % 2 == 1) res = res * a % MOD;
  		a = a * a % MOD;
  		n /= 2;
  	}
  	return res;
  };
  int N;
  cin >> N;
  vector<P> AB(N);
  for (auto& [A, B] : AB) {
  	cin >> A >> B;
  	ll g = gcd(A, B);
  	if(g == 0) continue;
  	A /= g, B /= g;
  	if (A == 0) B = abs(B);
  	else if (B == 0) A = abs(A);
  	else if (B < 0) A *= -1, B *= -1;
  }
  map<pair<ll, ll>, int> m;
  for (const auto& p : AB) ++m[p];
  ll ans = 1;
  int zeros = m[make_pair(0ll, 0ll)];
  m.erase(make_pair(0ll, 0ll));
  while (!m.empty()) {
  	auto[p, c] = *begin(m);
  	const auto& [A, B] = p;
  	auto iter = m.find(normalize(make_pair(-B, A)));
  	ll op = 
  		iter == m.end() ? modpow(2, c) :
  		(modpow(2, c) + modpow(2, iter->second) - 1) % MOD;
  	ans = ans * op % MOD;
  	if (iter != begin(m) && iter != end(m)) m.erase(iter);
  	m.erase(begin(m));
  }
  ans = (ans + zeros - 1 + MOD) % MOD;
  cout << ans << endl;
}


Measured memory_bytes: 18716
x = int(input())

# パフォーマンスのため、10000回の操作が何回必要かを記録
block_of_10000, remaining = divmod(x, 5 * 5000 + 6 * 5000)

count = 0
while remaining > 0:
    if count % 2 == 0:
        remaining -= 6
    else:
        remaining -= 5
    count += 1

print(block_of_10000 * 10000 + count)


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
void isTriangle()
{
	int j;
	cin >> j;
	for (int i = 0; i < j; i++)
	{
		int a, b, c;
		cin >> a;
		cin >> b;
		cin >> c;
		bool flag = false;
		if (a * a + b*b == c * c)flag = true;
		if (b * b + c * c == a * a)flag = true;
		if (c * c + a *a == b * b)flag = true;

		if (flag)cout << "YES" << endl;
		if (!flag)cout << "NO" << endl;
	}
}

int main()
{
	isTriangle();
	return 0;
}

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

int main() {
    int myhp, myattack, yourhp, yourattack;
    cin >> myhp;
    cin >> myattack;
    cin >> yourhp;
    cin >> yourattack;
    
    if(ceil((double)yourhp/myattack) <= ceil((double)myhp/yourattack)){
        cout << "Yes"<< endl;
    }else{
        cout << "No"<< endl;
    }
	return 0;
}

Measured memory_bytes: 3172
n = int(input())
A = list(map(int, input().split()))
qN = int(input())
Q = list(map(int, input().split()))

memo = {}
def solve(A, index, currS):
    key = str(index)+' '+str(currS)
    global memo
    if key in memo:
        return memo[key]
    else:
        if currS == 0:
            memo[key] = True
            return True
        elif currS < 0 or index >= len(A):
            memo[key] = False
            return False
        else:
            result1 = solve(A, index+1, currS)
            result2 = solve(A, index+1, currS-A[index])
            memo[key] = result1 or result2
            return memo[key]
for q in Q:
    if solve(A, 0, q):
        print('yes')
    else:
        print('no')    



Measured memory_bytes: 8784
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctype.h>
#include <math.h>
using namespace std;

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin>>h.at(i);
    }
    int count=0;
    for(int i=0;i<n;i++){
        if(h.at(i)>=k){
            count++;
        }
    }
    cout<<count<<endl;
}


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

int main() {
  int n;
  cin >> n;

  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }

  for (int i = n - 1; i >= 0; i--) {
    cout << a.at(i);
    if (i != 0) {
      cout << " ";
    }
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 3088
import sys
n = int(input())
w = list(map(int,input().split()))
a = 0
b  = sum(w)
for i in range(n):
    a += w[i]
    b -= w[i]
    if a > b:
        print(min(a-b,2*w[i]-a+b))
        sys.exit()



Measured memory_bytes: 2940
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val n = sc.nextInt()
    val m = sc.nextInt()


    val t = (m * 1900 + (n - m) * 100)


    var p = 1
    var c = 0
    while (c < m) {
        p *= 2
        c += 1
    }

    println(t * p)


}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 31016
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

sys.setrecursionlimit(10**9)


n = int(input())
G = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    G[a].append(b)
    G[b].append(a)

flag = [0]*n
def dfs(cur, par,f):
    flag[cur] = f
    for to in G[cur]:
        if to != par:
            dfs(to, cur, f^1)

dfs(0, -1, 0)

a = sum(flag)
b = n-a

one = []
two = []
three = []
for i in range(1, n+1):
    if i%3 == 0:
        three.append(i)
    elif i%3 == 1:
        one.append(i)
    else:
        two.append(i)
k = n//3
ans = [0]*n
if k<a and k<b:
    for i in range(n):
        if flag[i]:
            if one:
                ans[i] = one.pop()
            else:
                ans[i] = three.pop()
        else:
            if two:
                ans[i] = two.pop()
            else:
                ans[i] = three.pop()
else:
    #1
    if k >= a:
        for i in range(n):
            if flag[i]:
                ans[i] = three.pop()
        res = one + two + three
        for i in range(n):
            if not flag[i]:
                ans[i] = res.pop()
    # 0
    else:
        for i in range(n):
            if not flag[i]:
                ans[i] = three.pop()
        res = one + two + three
        for i in range(n):
            if flag[i]:
                ans[i] = res.pop()
print(*ans)

Measured memory_bytes: 167108
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		ULL H, W; cin >> H >> W;
		if (H == 1 || W == 1) cout << 1 << endl;
		else cout << (H * W + 1) / 2 << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed up
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed up
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed down
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed down
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
//    cout << fixed << setprecision(15);

    i32 n,a,b; cin >> n >> a >> b;
    string s; cin >> s;

    i32 aa = 0, bb = 0;
    for(auto ch : s) {
        if(ch == 'a') {
            if(aa < a) {
                ++aa;
                cout << "Yes" << '\n';
            }
            else if(bb < b) {
                ++bb;
                cout << "Yes" << '\n';
            }
            else cout << "No" << '\n';
        }
        else if(ch == 'b') {
            if(bb < b) {
                ++bb;
                cout << "Yes" << '\n';
            }
            else {
                cout << "No" << '\n';
            }
        }
        else cout << "No" << '\n';
    }



    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


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

void solve(long long N, long long A, long long B)
{
    long long a = N / (A + B);
    long long b = N % (A + B);

    long long ans = a * A;

    if (b > A)
        ans += A;
    else
        ans += b;

    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    solve(N, A, B);
    return 0;
}


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

using namespace std;


int main() {

  int N;
  cin >> N;

  int num[4] = {0, 3, 5, 7};
  vector<long> vec;

  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      if (j == 0 && i != 0) continue;
      for (int k = 0; k < 4; k++) {
        if (k == 0 && j != 0) continue;
        for (int l = 0; l < 4; l++) {
          if (l == 0 && k != 0) continue;
          for (int m = 0; m < 4; m++) {
            if (m == 0 && l != 0) continue;
            for (int n = 0; n < 4; n++) {
              if (n == 0 && m != 0) continue;
              for (int o = 0; o < 4; o++) {
                if (o == 0 && n != 0) continue;
                for (int p = 0; p < 4; p++) {
                  if (p == 0 && o != 0) continue;
                  for (int d = 3; d <= 7; d+=2) {
                    vec.push_back(d + num[p]*pow(10,1)
                                    + num[o]*pow(10,2)
                                    + num[n]*pow(10,3)
                                    + num[m]*pow(10,4)
                                    + num[l]*pow(10,5)
                                    + num[k]*pow(10,6)
                                    + num[j]*pow(10,7)
                                    + num[i]*pow(10,8));
                  }
                }
              }
            }
          }
        }
      }
    }
  }

  int ans = 0;
  bool flag[10];

  for (int i = 0; i < vec.size(); i++) {
    for (int j = 0; j < 10; j++) flag[j] = false;
    if (vec[i] > N) break;
    else {
      int x = vec[i];
      while(x) {
        flag[x%10] = true;
        x/= 10;
      }
      if (flag[7] && flag[5] && flag[3]) ans++;
    }
  }
  cout << ans << endl;

  return 0;
}

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

#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 unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll big = 1000000007;
const ll mod = 998244353;
ll n,k,m;
ll T;

vl A;

vl sol;

bool mark[1001] = {0};


int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,d,e;

    cin >> n;
    for(int c1 = 0; c1 < n; c1++){
        cin >> a;
        A.push_back(a);
    }

    ll ans1 = 0;
    ll ans2 = 0;

    for(int c1 = 0; c1 < n; c1++){
        if(c1%2 == 0){
            if(A[c1] > 0){
                ans1+=A[c1];
                mark[c1] = 1;
            }
        }
        else{
            if(A[c1] > 0){
                ans2+=A[c1];
                mark[c1] = 1;
            }
        }
    }

    if(ans1 == 0){

        ll ma = -big*big;
        ll ima = 0;
        for(int c1 = 0; c1 < n; c1++){
            if(c1%2 == 0){
                if(A[c1] > ma){
                    ma = A[c1];
                    ima = c1;
                }
            }
        }
        mark[ima] = 1;
        ans1 = ma;

    }

    if(ans2 == 0){

        ll ma = -big*big;
        ll ima = 0;
        for(int c1 = 0; c1 < n; c1++){
            if(c1%2 == 1){
                if(A[c1] > ma){
                    ma = A[c1];
                    ima = c1;
                }
            }
        }
        mark[ima] = 1;
        ans2 = ma;

    }



    if(ans1 > ans2){
        for(int c1 = 0; c1 < n; c1++){
            if(c1%2 == 1)mark[c1] = 0;
        }
    }
    else{
        for(int c1 = 0; c1 < n; c1++){
            if(c1%2 == 0)mark[c1] = 0;
        }
    }

    ll i = 0;
    ll n2 = n;
    while(mark[i] == 0){
        sol.push_back(1);
        i++;
        n2--;
    }

    i += 2;
    while(i < n){
        if(mark[i]){
            sol.push_back(2);
        }
        else{
            if(n2 == 3)break;
            sol.push_back(3);
        }
        i += 2;
        n2 -= 2;
    }
    while(n2 > 1){sol.push_back(n2);n2--;}


    cout << max(ans1,ans2) << "\n";
    cout << sz(sol) << "\n";
    for(int c1 = 0; c1 < sz(sol); c1++){
        cout << sol[c1] << "\n";
    }
    return 0;
}


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

using namespace std;

int main()
{
    int n,m,i,j,k,l,ck=1,p,q,check=0;
    char ch[200][200],ch1[200][200];

    memset(ch,0,sizeof(ch));
    memset(ch1,0,sizeof(ch1));

    cin>>n>>m;

    for(i=0; i<n; i++)
    {
        scanf("%s",ch[i]);
    }
    for(i=0; i<m; i++)
    {
        scanf("%s",ch1[i]);
    }
    for(i=0; i<n; i++)
    {
        for(j=0; j<n; j++)
        {
            if(ch[i][j]==ch1[i-i][j-j])
            {
                 ck=0;
                 for(k=0; k<m; k++)
                 {
                     for(l=0; l<m; l++)
                     {
                         if(ch[i+k][j+l]!=ch1[k][l])
                         {
                             ck=1;
                             break;
                         }
                     }
                 }
            }
             if(ck==0)
             {
                 cout<<"Yes"<<endl;
                 check=1;
                 break;
             }
         }
         if(check==1)
            break;
     }
     if(check==0)
        cout<<"No"<<endl;

     return 0;
}


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

int main(){

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

    sort(ref,ref+n);

    int cnt=0;
    for(int i=0;i<n;i++){
        if(ref[i]!=p[i]){
            cnt+=1;
        }
    }

   // cout<<"cnt="<<cnt<<endl;
    if(cnt<=2) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

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

        int N = scanner.nextInt();

        List<Integer> list = new ArrayList(N);

        for (int i = 0; i < N; i++) {
            list.add(scanner.nextInt());
        }

        Collections.sort(list, Collections.reverseOrder());

        int aTotal = 0;
        int bTotal = 0;

        for (int i = 0; i < N; i++) {
            if ((i & 1) == 0) {
                aTotal += list.get(i);
            } else {
                bTotal += list.get(i);
            }
        }

        System.out.println(aTotal - bTotal);
    }
}

Measured memory_bytes: 21844
public class Hello{
    public static void Main(){
        int n;
        int i, j, k;
        string numstr;
        string[] numsstr;
        double max = -1;
        System.Collections.Generic.List<int> list;
        list = new System.Collections.Generic.List<int>();
        n = int.Parse(System.Console.ReadLine()); //?¨??????\???
        numstr = System.Console.ReadLine();
        numsstr = numstr.Split(' ');
        for(i = 0; i < n; i++)
        {
            list.Add(int.Parse(numsstr[i]));
        }
        list.Sort();
        for(j = 0; j < n; j++)
        {
            for(k = j + 1; k < n; k++)
            {
                int a, b, c, d;
                double value;
                a = -1;
                b = -1;
                c = list[k];
                d = list[j];
                int i2;
                for(i2 = n -1; i2 >= 0; i2--)
                {
                    if(i2 != j && i2 != k)
                    {
                        if(a < 0)
                        {
                            a = list[i2];
                        } else 
                        {
                            b = list[i2]; 
                            break;
                        }
                    }
                }
                value = (double)(a + b) / (c - d);
                if(max < value)
                {
                    max = value;
                }
            }
        }
        
        System.Console.WriteLine(max.ToString());
    }
}

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

const int mod = 1e9 + 7;

template<typename T0, typename T1, typename T2>
inline void update(T0 &x, const T1 &y, const T2 &mod) {
	x += y;
	if (x >= mod) x -= mod;
}

int n, m;
int a[33][3][3], b[3][3], ans[3][3];

namespace Matrix {
	void times3x3(int a[3][3], int b[3][3], int c[3][3]) {
		static int t[3][3];
		memset(t, 0, sizeof t);
		for (int i = 0; i < 3; ++i)
			for (int j = 0; j < 3; ++j)
				for (int k = 0; k < 3; ++k)
					update(t[i][j], 1LL * a[i][k] * b[k][j] % mod, mod);
		for (int i = 0; i < 3; ++i)
			for (int j = 0; j < 3; ++j)
				c[i][j] = t[i][j];
	}

	void times3x1(int a[3][3], int b[3][3], int c[3][3]) {
		static int t[3][3];
		memset(t, 0, sizeof t);
		for (int i = 0; i < 3; ++i)
			for (int j = 0; j < 3; ++j)
				update(t[i][0], 1LL * a[i][j] * b[j][0] % mod, mod);
		for (int i = 0; i < 3; ++i)
			c[i][0] = t[i][0];
	}

	void power(const int &p, int x[3][3]) {
		for (int i = 0; i < 30; ++i) {
			if (p >> i & 1)
				times3x1(a[i], x, x);
		}
	}
}
using namespace Matrix;

int main() {
	a[0][0][0] = 1, a[0][0][1] = 0, a[0][0][2] = 1;
	a[0][1][0] = 2, a[0][1][1] = 1, a[0][1][2] = 2;
	a[0][2][0] = 1, a[0][2][1] = 1, a[0][2][2] = 2;
	b[0][0] = 1, b[0][1] = 0, b[0][2] = 0;
	b[1][0] = 2, b[1][1] = 1, b[1][2] = 0;
	b[2][0] = 1, b[2][1] = 1, b[2][2] = 1;
	for (int i = 1; i <= 30; ++i)
		times3x3(a[i - 1], a[i - 1], a[i]);
	ans[0][0] = 1;
	scanf("%d%d", &n, &m);
	int lst = -1;
	for (int i = 1; i <= m; ++i) {
		int x;
		scanf("%d", &x);
		power(x - lst - 1, ans);
		times3x1(b, ans, ans);
		lst = x;
	}
	power(n - lst - 1, ans);
	printf("%d\n", ans[2][0]);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
#define N 1002
int h[N];
int main(){
	int n;
	cin>>n;
	double T,A;
	cin>>T>>A;
	int i;
	for( i=0;i<n;i++ )
		cin>>h[i];
	double cl = 1000000;
	int index;
	for( i=0;i<n;i++ )
	{
		double tmp = T-h[i]*0.006;
		double t =fabs(A-tmp);  
		if( t<cl )
		{
			cl = t;
			index = i+1;
		}
	}
	cout<<index<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 500

int main(){
  int n,i,j,u,k,ver;
  int G[N][N];
  
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      G[i][j] = 0;
    }
  }

  for(i=1;i<=n;i++){
    scanf("%d%d",&u,&k);
    for(j=1;j<=k;j++){
      scanf("%d",&ver);
      G[u][ver] = 1;
    }
  }

  for(i=1;i<=n;i++){
    for(j=1;j<n;j++){
      printf("%d ",G[i][j]);
    }
    printf("%d",G[i][j]);
    printf("\n");
  }
  
  return 0;
}



Measured memory_bytes: 2076
#include <bits/stdc++.h>
using namespace std;
#define LL long long 
#define LLU long long unsigned
#define rarr(arr, n) for(int aab = 0; aab < n; aab++){cin >> arr[aab];}
#define parr(arr, n) for(int aab = 0; aab < n; aab++){cout << arr[aab] << " ";}
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n";

#define freopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);ios_base::sync_with_stdio(0);cin.tie(0);

int main(){
	long long int a, b = 0;
	char arr[4];
	cin >> a >> arr;
	b += (arr[0] - '0') * 100 + (arr[2] - '0') * 10 + (arr[3] - '0');
	a = a * b;
	cout << a / 100;
} 

Measured memory_bytes: 3636
num = input().split()
nums = []
for i in num:
  nums.append(int(i))
#print(nums)
price = [300000, 200000, 100000]
result = []
 
#2 3 4 5 6
for i in nums:
  if int(i) > 3:
    result.append(0)
  else:
    result.append(price[i-1])
value = result[0] + result[1]
if value == 600000:
  print("1000000")
else:
  print(value)

Measured memory_bytes: 38256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn solve_max(a: isize, b: isize) -> isize {
    if a < b {
        a
    } else {
        b
    }
}

fn solve_min(n: isize, a: isize, b: isize) -> isize {
    let ans = a + b - n;
    if ans > 0 {
        ans
    } else {
        0
    }
}

fn main() {
    input!{
        nab: [isize; 3]
    }
    let n = nab[0];
    let a = nab[1];
    let b = nab[2];

    println!("{} {}", solve_max(a,b), solve_min(n,a,b));
}

#[test]
fn test() {
    assert_eq!(solve_max(3,5), 3);
    assert_eq!(solve_min(10,3,5), 0);
    assert_eq!(solve_max(7,5), 5);
    assert_eq!(solve_min(10,7,5), 2);
    assert_eq!(solve_max(100,100), 100);
    assert_eq!(solve_min(100,100,100), 100);
}


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

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef map<int, int> mi;

#define rep(i,a,b) for (int i = a; i < b; i++)

int gcd(int a, int b){
	if (a == 0) return b;
	return gcd(b % a, a);
}



int main(){
	int n;
	cin >> n;
	
	
	long long res = 0;
	
	rep(i,1,n+1){
		rep(j,1,n+1){
			rep(k,1,n+1){
				if (i == 1 || j == 1 || k == 1){
					res += 1;
					continue;
				}
				
				int temp1 = gcd(i,j);
				int g = gcd(temp1, k);
				
				
				res += g;			
			}
		}
	}
	
	cout << res;




	return 0;
}


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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll N;
    char S;
    cin >> S;

    if(S=='A'){
        cout << "T" << endl;
    }
    else if (S == 'T')
    {
        cout << "A" << endl;
    }
    else if (S == 'G')
    {
        cout << "C" << endl;
    }
    else{
        cout << "G" << endl;
    }
}

Measured memory_bytes: 3632
from math import atan2, hypot

n = int(input())
xy = []
for i in range(n):
    x,y = map(int, input().split())
    theta = atan2(y,x)
    xy.append((theta, y, x))
xy.sort()
xy += xy
cs = [(0,0)]
for _, x, y in xy:
    cs.append((cs[-1][0]+x, cs[-1][1]+y))

ans = 0
for i in range(n):
    for j in range(i+1, i+n+1):
        x1, y1 = cs[i]
        x2, y2 = cs[j]
        ans = max(ans, hypot(x1-x2, y1-y2))
print(ans)


Measured memory_bytes: 38896
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define forn(i,n) for(int i = 0; i < (int) n; i++)
#define ios ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
typedef long long ll;

int main() {
  ios;
  int n;
  cin >> n;

  vector<ll> v(n + 1);
  forn(i, n + 1) cin >> v[i];

  if (v[0] == 1) {
    if (n == 0)
      cout << "1\n";
    else
      cout << "-1\n";

    return 0;
  }

  vector<ll> suf(n + 1);
  suf[n] = v[n];
  for(int i = n - 1; i >= 0; i--) suf[i] = suf[i + 1] + v[i];

  ll work = 1, nodes = 1;
  for(int i = 1; i <= n; i++) {
    work = min(2*work, suf[i]);
    nodes += work;
    if (v[i] > work) {
      cout << "-1\n";
      return 0;
    }
    work -= v[i];
  }

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

  cout << nodes << "\n";
}


Measured memory_bytes: 4752
#include<bits/stdc++.h>
using namespace std;
#define BeatMeScanf ios_base::sync_with_stdio(false)
#define ll long long
#define sz 100505

int main(){
    BeatMeScanf;
    int n,k;
    while(cin>>n>>k){
        int r,s,p;
        ll points=0;
        string str,win;
        cin>>r>>s>>p>>str;

        win=str;

        for(int i=0;i<str.size();i++){
            if(str[i]=='r') win[i]='p';
            else if(str[i]=='p') win[i]='s';
            else if(str[i]=='s') win[i]='r';
        }
        for(int i=k;i<str.size();i++){
            if(win[i]=='r' && win[i-k]=='r') win[i]='#';
            else if(win[i]=='p' && win[i-k]=='p') win[i]='#';
            else if(win[i]=='s' && win[i-k]=='s') win[i]='#';
        }
        for(int i=0;i<win.size();i++){
            if(win[i]=='#') continue;
            else if(i-k<0){
                if(win[i]=='r') points+=r;
                else if(win[i]=='p') points+=p;
                else points+=s;
            }
            else if(win[i]!=win[i-k]){
                if(win[i]=='r') points+=r;
                else if(win[i]=='p') points+=p;
                else points+=s;
            }
        }
        cout<<points<<endl;
    }
    return 0;
}


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

struct union_find {
    private:
        vector<int> parents;
        vector<int> ranks;

    public:
        union_find(int n) : parents(n, -1), ranks(n, 0) {}

        void unite(int a, int b) {
            int pa = find(a);
            int pb = find(b);
            if (pa == pb) return;
            assert(pa != pb);

            int np, nc;
            if (ranks[pa] == ranks[pb]) {
                np = pa; nc = pb;
                ranks[np]++;
            } else if (ranks[pa] < ranks[pb]) {
                np = pb; nc = pa;
            } else {
                np = pa; nc = pb;
            }

            parents[nc] = np;
        }

        int find(int a) {
            while (parents[a] != -1) { a = parents[a]; }
            return a;
        }
};

int main() {
    int N, K, L;
    cin >> N >> K >> L;

    union_find road(N);
    for (int i = 0; i < K; i++) {
        int p, q;
        cin >> p >> q;
        p--; q--;
        road.unite(p, q);
    }

    union_find rail(N);
    for (int i = 0; i < L; i++) {
        int p, q;
        cin >> p >> q;
        p--; q--;
        rail.unite(p, q);
    }

    map<pair<int, int>, int> gs;
    for (int i = 0; i < N; i++) {
        gs[pair<int, int>(road.find(i), rail.find(i))]++;
    }

    bool first = true;
    for (int i = 0; i < N; i++) {
        if (first) {
            first = false;
        } else {
            cout << ' ';
        }
        cout << gs[pair<int, int>(road.find(i), rail.find(i))];
    }
    cout << endl;

    return 0;
}


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



int main(){
	ll ans;
	ll n,a,b;
	cin>>n>>a>>b;
	ans=n/(a+b)*a;
	n-=n/(a+b)*(a+b);
	ans+=min(n,a);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
from operator import itemgetter

n = int(input())

list = []
for i in range(n):
    a, b = input().split()
    list.append((a, int(b), i))

all = sorted(list, key=itemgetter(1), reverse=True)
all2 = sorted(all, key=itemgetter(0))
# all = sorted(list, key=lambda x: (x[0], x[1]))

# print(all2)

for i in range(n):
    print(int(all2[i][2]) + 1)


Measured memory_bytes: 3060
N,K = map(int,input().split())

amari_0 = [] 
amari_Kw2 = []

for i in range(1,N+1,1):
    if i%K == 0:
        amari_0.append(i)
    if i%K == K//2:
        amari_Kw2.append(i)

if K%2 == 0:
    ans = pow(len(amari_0),3)
    ans += pow(len(amari_Kw2),3)
else:
    ans = pow(len(amari_0),3)

print(ans)

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

int main() {
    int n, k;
    int h[101000];
    int ans = INT_MAX;
    
    cin >> n >> k;
    
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    
    sort(h, h + n);
    
    for (int i = 0; i <= (n - k); i++) {
        ans = min(ans, (h[i + k - 1] - h[i]));
    }
    
    cout << ans << endl;
    return 0;
}

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  int n,k; cin>>n>>k;
  if (k==1) cout << 0 << endl;
  else cout << n-k << endl;
}

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


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

int main(){
  int N;
  cin >> N;
  int A[N];
  int B[N];
  int C[N];
  C[N-1]=0;
  int sum=0;
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  for(int i=0;i<N;i++){
    cin >> B[i];
    sum+=B[i];
  }
  for(int i=0;i<N-1;i++){
    cin >> C[i];
  }
  for(int i=0;i<N-1;i++){
    if (A[i+1]==A[i]+1){
      sum+=C[A[i]-1];
    }
  }
  cout << sum;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;
 
#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
 
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }
 
ll h,w;
ll gy,gx;
 
ll d[30][30][4];
 
vector<vector<ll>> G;
ll c[4];
 
ll dx[] = {1,0,-1,0};
ll dy[] = {0,1,0,-1};
 
bool in(int y,int x){
    return y >= 0 && y < h && x >= 0 && x < w;
}
 
void dijkstra(ll sy,ll sx,ll dir){
    rep(i,30)rep(j,30)rep(k,4)d[i][j][k] = INF;
    d[sy][sx][dir] = 0;
 
    typedef pair<P,P> PP;
    priority_queue<PP, vector<PP>, greater<PP>> que;
    que.push(PP(P(0,dir),P(sy,sx)));
 
    while (!que.empty()){
        PP p = que.top();
        que.pop();
        ll cdir = p.first.second;
        ll cost = p.first.first;
        ll cy = p.second.first;
        ll cx = p.second.second;
        if(cost > d[cy][cx][cdir])continue;
        if(cy == gy && cx == gx)continue;
        rep(i,4){
            ll ny = cy + dy[(i + cdir)%4];
            ll nx = cx + dx[(i + cdir)%4];
            ll ndir = (cdir + i)%4;
            if(!in(ny,nx))continue;
            ll ncost = cost;
            if(i != G[cy][cx])ncost += c[i];
            if(d[ny][nx][ndir] > ncost){
                d[ny][nx][ndir] = ncost;
                que.push(PP(P(ncost,ndir),P(ny,nx)));
            }
        }
    }
}
 
int main(){
    while(cin >> w >> h && w){
        gy = h - 1; gx = w - 1;
        G.clear();
        G.resize(h);
        rep(i,h)G[i].resize(w);
        rep(i,h){
            rep(j,w){
                cin >> G[i][j];
            }
        }
        cin >> c[0] >> c[1] >> c[2] >> c[3];
        dijkstra(0,0,0);
        ll ans = INF;
        rep(i,4)ans = min(ans,d[h-1][w-1][i]);
        cout << ans << endl;
    }
 
}


Measured memory_bytes: 3192
@list = []
@d = []
@f = []
@time = 0


def d_search(i)
  @time += 1
  @d[i] = @time

  @list[i].sort.each do |j|
    d_search(j-1) unless @d[j-1]
  end

  @time += 1
  @f[i] = @time
end

n = gets.to_i
n.times do
  u, k, *v = gets.split.map {|i| i.to_i}
  @list[u-1] = v
end

(0..n-1).each do |i|
  d_search(i) unless @d[i]
end

(0..n-1).each do |i|
  puts "#{i+1} #{@d[i]} #{@f[i]}"
end



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

int main() {
	int x, y, t;
	vector<int> X, Y, T;
	while (cin >> x >> y) {
		if (x == 0)break;
		X.push_back(x);
		Y.push_back(y);
	}
	for (int i = 0; i < X.size(); i++) {
		if (X[i] == 1)t = (Y[i] - 1) % 7;
		else if (X[i] == 2)t = (30 + Y[i]) % 7;
		else if (X[i] % 2 == 0) {
			if (X[i] >= 8)t = (((X[i] - 8) / 2) * 61 + Y[i] + 212) % 7;
			else t = (((X[i] - 4) / 2) * 61 + 90 + Y[i]) % 7;
		}
		else {
			if(X[i]>=8)t = (((X[i] - 9) / 2) * 61 + 243 + Y[i]) % 7;
			else t= (((X[i] - 3) / 2) * 61 + 59 + Y[i]) % 7;
		}
		T.push_back(t);
	}
	for (int i = 0; i < T.size(); i++) {
		if (T[i] == 0)cout << "Thursday" << endl;
		else if (T[i] == 1)cout << "Friday" << endl;
		else if (T[i] == 2)cout << "Saturday" << endl;
		else if (T[i] == 3)cout << "Sunday" << endl;
		else if (T[i] == 4)cout << "Monday" << endl;
		else if (T[i] == 5)cout << "Tuesday" << endl;
		else cout << "Wednesday" << endl;
	}
	return 0;
}

Measured memory_bytes: 3120
import bisect

n, k = map(int, input().split())
vs = list(map(int, input().split()))
res = 0
for i in range(k + 1):
    for j in range(k + 1):
        if i + j > min(k, n):
            continue
        ls = vs[:i]
        if j > 0:
            ls += vs[-j:]
        ls.sort()
        index = bisect.bisect(ls, 0)
        l = min(index, k - i - j)
        res = max(res, sum(ls[l:]))
print(res)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
using Graph = vector<vector<int>>;

int main(){
	int n, m; cin >> n >> m;
	cout << 6 - n - m << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=sc.nextInt();
    if (a==b&&b==c) {
      System.out.println("No");
    }else{
      if(a==b||a==c||b==c){
         System.out.println("Yes");
      }else{
         System.out.println("No");
      }

    }
  }
}


Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int main(void) {
	int num,N;
	cin >> N;
	int res = 1;
	int nmin;
	cin >> nmin;
	for (int i = 1; i < N; ++i) {
		cin >> num;
		if (num < nmin) {
			++res;
			nmin = num;
		}
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 256