akhauriyash/Code-Regression huggingface dataset:
N = int(input())
T, A = list(map(int, input().split()))
H = list(map(int, input().split()))

res, height = 0, 100001
for i in range(N) :
    tmp = T - H[i] * 0.006
    if height > abs(A - tmp) :
        height = abs(A - tmp)
        res = i + 1

print(res)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
	int a, b, i=0, n[100002], c=0;
	scanf("%d%d", &a, &b);
	for (i = 0; i < b; i++)
	{
		scanf("%d", &n[i]);
		c = c + n[i];
	}
	if (c < a)
	{
		printf("No");
	}
	else
	{
		printf("Yes");
	}
	return 0;
}

Measured memory_bytes: 512
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;
#[allow(dead_code)]
const MOD:i64 = 1e9 as i64 + 7;


#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


#[allow(unused_imports)]
use std::f64;


fn main() {
    input!{n:i64, m:i64};
    println!("{}", if n==m {"Yes"} else {"No"});

}

Measured memory_bytes: 4352
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
 
		String o = sc.next();
		String e = sc.next();
 
		for (int i = 0; i < o.length(); i++) {
			System.out.print("" + o.charAt(i) + (i < e.length() ? e.charAt(i) : ""));
		}
		System.out.println();
	}
 
}

Measured memory_bytes: 21716
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")

#include<bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

const ll inf = 1e18;
const ll mod1 = 1e9 + 7;
const ll mod2 = 228661337;
const ll N = (1 << 12) + 2;

#define int long long
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define F first
#define S second

void shift()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
}
void include_file(bool a)
{
    if (!a) return;
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}




int32_t main()
{
    shift();
    srand(time(0));
    include_file(false);
    int n;
    cin >> n;
    vector<int>a(n + 1);
    for(int i = 0; i < n + 1; ++i)
        cin >> a[i];
    vector<int>b(n);
    for(int i = 0; i < n; ++i)
        cin >> b[i];
    int res = 0;
    for(int i = 0; i < n; ++i)
    {
        int k = min(b[i], a[i]);
        a[i] -= k;
        b[i] -= k;
        res += k;
        k = min(b[i], a[i + 1]);
        a[i + 1] -= k;
        b[i] -= k;
        res += k;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 1792
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

int n;
char tmp[100];
string s;

int read() {
  if (scanf("%s", tmp) < 1) {
    return false;
  }
  s = tmp;
  n = sz(s);
  return true;
}

void solve() {
  for (int i = 0; i + 1 < n; i++) {
    if (s[i] == 'A' && s[i + 1] == 'C') {
      printf("Yes\n");
      return;
    }
  }
  printf("No\n");
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
N, K = map(int, input().split())
H = sorted(list(map(int, input().split())), reverse=True)
l = len(H)
if K != 0:
    if len(H) <= K:
        print(0)
    else:
        print(sum(H[K:]))
else:
    print(sum(H))

Measured memory_bytes: 26024
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define r_rep(i, n) for(int i = (int)n-1; i > 0; i--)
#define ll long long
#define pb push_back

int main() {
  ll x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;

  vector<ll> red(a);
  vector<ll> green(b);
  vector<ll> tp(c);

  rep(i, a){
    cin >> red[i];
  }

  rep(i, b){
    cin >> green[i];
  }

  rep(i, c){
    cin >> tp[i];
  }

  sort(red.begin(), red.end());
  sort(green.begin(), green.end());
  sort(tp.begin(), tp.end());

  // とりあえずの総和をだす
  ll ans = 0;
  vector<ll> tmp;
  for(ll i = a-1; i >= a - x; i--){
    ans += red[i];
    tmp.push_back(red[i]);
  }
  for(ll i = b-1; i >= b - y; i--){
    ans += green[i];
    tmp.push_back(green[i]);
  }
  sort(tmp.begin(), tmp.end());
  // 一番小さいものとtpの一番大きいものを入れ替えていく
  ll i = 0, j = c-1;
  while(tmp[i] < tp[j]){
    ans = ans - tmp[i] + tp[j];
    i++;
    j--;
    if(j == -1 || i == tmp.size()) break;
  }
  cout << ans << endl;

}


Measured memory_bytes: 4724
#include <iostream>

#include <string>

using namespace std;

string S;



int main()
{

	cin >> S;

	if (S == "Sunny") {
		cout << "Cloudy" << endl;
	}
	else if (S == "Cloudy") {
		cout << "Rainy" << endl;
	}
	else {
		cout << "Sunny" << endl;
	}


	return 0;
}


Measured memory_bytes: 256
N = int(input())
A=[list(map(int, input().split())) for i in range(2)]

for i in range(1, N):
    A[0][i]=A[0][i]+A[0][i-1]

for i in range(N-1, 0, -1):
    A[1][i-1]=A[1][i-1]+A[1][i]

max=0
for i in range(0, N):
    if max<A[0][i]+A[1][i]:
        max=A[0][i]+A[1][i]

print(max)

Measured memory_bytes: 3064
n=int(input())
a = [list(map(int,input().split())) for _ in range(2)]

amemax=0
for i in range(n):
    ame=sum(a[0][:i+1])+sum(a[1][i:])
    amemax = max(ame,amemax)
    
print(amemax)

Measured memory_bytes: 9188
#include<queue>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdint>
#include<iostream>
#include<algorithm>
using namespace std;
int xt[200001];
int main()
{
	long long x,y;
	cin>>x>>y;
/*	if(x>y)
	{
		long long t=x;
		x=y;
		y=t;
	}*/
	if(x%y==0)
		printf("-1\n");
	else if(y==2)
		printf("%lld\n",x*3ll);
	else
		printf("%lld\n",x*(y-1));
	return 0;
}

Measured memory_bytes: 256
LARGE = 10**9 + 7


def p_inv(k, p):
    return pow(k, p-2, p)


def nck_mod(n, k, m):
    res = 1
    for i in range(n, n-k, -1):
        res = res * i % m
    for i in range(1, k+1):
        res = res * p_inv(i, m) % m
    return res


def solve(n, m, k):
    res_1 = 0
    r = n * (n - 1) // 2
    res_1 += r
    for i in range(1, n):
        r += i
        r -= n - i
        res_1 += r
    res_2 = 0
    r = m * (m - 1) // 2
    res_2 += r
    for i in range(1, m):
        r += i
        r -= m - i
        res_2 += r
    res = (res_1 * m * m + res_2 * n * n) % LARGE

    weight = nck_mod(n * m - 1, k - 1, LARGE) * p_inv(n * m - 1, LARGE) * (k - 1) * p_inv(2, LARGE) % LARGE

    return res * weight % LARGE


if __name__ == "__main__":
    N, M, K = map(int, input().split())
    print(solve(N, M, K))
    # print(solve(2, 2, 2))
    # print(solve(4, 5, 4))
    # print(solve(100, 100, 5000))


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

int main(){
    int N,K;
    cin >> N >> K;
    vector<double> p(N);
    for(int i=0; i<N; i++) {
        int num;
        cin >> num;
        p[i] = (double)(num+1)/2;
    }
    double S=0,S_k;
    for(int i=0; i<N; i++){
        S+=p[i];
        if(i==N-1-K)S_k=S;
    }
    int i = N-1, j = i-K;
    double maxi = 0;
    while(1){
        maxi = max(maxi,S-S_k);
        if(j==-1) break;
        S -= p[i--];
        S_k -= p[j--];
    }
    printf("%f\n",maxi);
}

Measured memory_bytes: 4820
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
string s0, s1;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S, T;
  map< char, char > table[2];
  cin >> S >> T;
  int N = S.size();
  // cout << table['A'] << endl;
  // cout << (table['A'] == '\0') << endl;
  REP(k, 2) {
    REP(i, N) {
      if (table[k][S[i]] == '\0') {
        table[k][S[i]] = T[i];
      } else if (table[k][S[i]] != T[i]) {
        cout << "No"
             << "\n";
        return 0;
      }
    }
    swap(S, T);
  }

  cout << "Yes"
       << "\n";
}

Measured memory_bytes: 916
import collections
import copy

N = int(input().split()[0])
S = input()

counter = collections.Counter(S)
total = 0
done_list = []

for i, ch in enumerate(S[::-1]):  # 3 * 10 ** 4
    if ch in done_list:
        counter[ch] = counter[ch] - 1
        if counter[ch] < 1:
            del counter[ch]
        continue
    sub_done_list = []
    counter[ch] = counter[ch] - 1
    if counter[ch] < 1:
        del counter[ch]
    sub_counter = copy.copy(counter)

    for ch_2 in S[N - (i + 1) - 1 :: -1]:  # 3 * 10 ** 4
        if ch_2 in sub_done_list:
            sub_counter[ch_2] = sub_counter[ch_2] - 1
            if sub_counter[ch_2] < 1:
                del sub_counter[ch_2]
            continue
        sub_done_list.append(ch_2)
        sub_counter[ch_2] = sub_counter[ch_2] - 1
        if sub_counter[ch_2] < 1:
            del sub_counter[ch_2]
        total += len(sub_counter.keys())

    done_list.append(ch)

ans = total

print(ans)


Measured memory_bytes: 42220
n = int(input())
a = list(map(int, input().split()))
b = []
c = {}
ans = 0
for i in range(n):
  if a[i] in c:
    c[a[i]] += 1
  else:
    c[a[i]] = 1
    b.append(a[i])
  
for i in range(len(b)):
  temp=c[b[i]]
  temp2=b[i] 
  if temp > temp2:
    ans += temp-temp2
  elif temp < temp2:
    ans += temp
  
  
print(ans)


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

int main(void) {
    int K,N; cin >> K >> N;
    vector<int> A;
    for(int i=0; i<N; i++) {
        int x; cin >> x;
        A.push_back(x); 
    }
    int max_dis=0;
    //if(A[0]!=0) max_dis=A[N-1]-A[0];
    max_dis=A[0]+K-A[N-1];
    for(int i=1; i<N; i++) {
        int dis = A[i] - A[i-1];
        if(max_dis<dis) max_dis=dis;
    }
    cout << K-max_dis << endl;
    return 0;
}

Measured memory_bytes: 4304
import javax.management.monitor.CounterMonitor;
import java.math.BigDecimal;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        //
        //Euclid e1=new Euclid();//ユークリッドの互除法
        //Compute c1=new Compute();//累積和，
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax=Double.MIN_VALUE;
        double dMin=Double.MAX_VALUE;
        int answer=0;
        //StringBuilder answer=new StringBuilder();
        //List<Integer> list = new ArrayList<>();
        //int array[] = new int[];

        //入力
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int P =sc.nextInt();

        int piece=3*A+P;
        int pie=piece/2;
        answer=pie;
        //出力
        //System.err.println();//標準エラー出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        //System.out.println(String.format("%.0f",answer));
        System.out.println(answer);
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  string s, t;
  int count = 0;
  cin >> s >> t;

  if(s[0] == t[0]){
    count++;
  }
  if(s[1] == t[1]){
    count++;
  }
  if(s[2] == t[2]){
    count++;
  }

  cout << count << endl;

}

 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;

int main(){
    int N, M; cin >> N >> M;
    ll ans = 0;
    if(N >= 2)ans += (N*(N-1))/2;
    if(M>=2) ans+=(M*(M-1))/2;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)     for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = m; i <= (int)(n); i++)
#define MOD 1000000007
#define Graph vector<vector<int>>
typedef pair<int, int> PII;
typedef long long int ll;

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

  int pi[N];
  rep(i,N) cin >> pi[i];
  
  ll SUM[1002];
  SUM[0] = 0;
  rep(i,1002){
    if(i == 0) continue;
    SUM[i] = SUM[i-1] + i; 
  }

  double ans = 0.0;
  
  //初期値
  double tmp = 0.0;
  for(int j = 0;j < K;j++){
    tmp += (double)SUM[pi[j]] / pi[j];
  }
  ans = tmp;
  
  
  //ひとつづつ
  double tmpAns = ans;
  for(int i = 1;i <= N-K; i++){ 
    tmpAns += (double)SUM[pi[i+K-1]] / pi[i+K-1];
    tmpAns -= (double)SUM[pi[i-1]] / pi[i-1];
    if(tmpAns > ans) ans = tmpAns;
  }


  cout << fixed;
  cout << setprecision(10);
  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define ll long long
#define d1(x)  cerr << #x << "--> " << x << endl
#define d2(x, y)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<endl
#define d3(x, y,z)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z<< endl
#define vpll vector<pair<ll,ll>>
#define F first
#define S second
#define T ll tt; cin>>tt; while(tt--)
using namespace std;
ll mode=pow(10,9)+7;
bool cmp(pair<long double ,int > x, pair<long double , int> y){ return x.F<y.F && x.S<y.S; }
const ll maxn=1e4+10;
ll __lcm(ll a, ll b){ return (a*b)/__gcd(a,b); }
int main(){ 
    
//    #ifndef ONLINE_JUDGE
//  		freopen("input.txt", "r", stdin);
//    #endif
    
    ios::sync_with_stdio(0);
    cin.tie(0);
    
	ll n;
	cin>>n;
	map<ll, ll> mp;
	for (int i=0;i<n;i++){
		ll x;
		cin>>x;
		mp[x]++;
	}    
	bool ok=true;
	for (auto i:mp){
		if (i.S>1){
			ok=false;
			break;
		}
	}
	if (ok) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

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

int main(){
    int a,b;
    cin >> a >> b;
    if (a > b) {
		cout << a - 1;
	}
	else {
		cout << a;
	}
}

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

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second　//pairの二つ目の要素

int main(){
	int n,p;
    string s;
    cin>>n>>p>>s;
    ll ans=0;
    if(10%p==0){
        for(int i=0;i<n;i++){
            if((s[i]-'0')%p==0)ans+=i+1;
        }
        cout<<ans<<endl;
        return 0;
    }

    vector<int> d(n+1);
    int ten=1;
    for(int i=n-1;i>=0;i--){
        int a=(s[i]-'0')*ten%p;
        d[i]=(d[i+1]+a)%p;
        ten*=10;
        ten%=p;
    }
    vector<int> cnt(p);
    for(int i=n;i>=0;i--){
        ans+=cnt[d[i]];
        cnt[d[i]]++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1412
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iterator>
#include <typeinfo>
using namespace std;


// define list


namespace  math{
    const double PI = 3.14;
    const int INF = 1000000007;
    int GCM(int a,int b); //最大公約数
    int LCM(int a,int b); //最小公倍数
    int Pemu(int n,int r); //順列
    int Comb(int n,int m); //組み合わせ
    
    int GCM(int a,int b){
        if(a<b){
            swap(a,b);
        }
        int r = a%b;
        while (r!=0)
        {
            a=b;
            b=r;
            r=a%b;
        }
        return b;
    }

    int LCM(int a,int b){
        return a*(b/GCM(a,b));
    }

    int Pemu(int n,int r){
        int ans = n;
        for(int i=1;i<r;i++){
            ans*=(ans-i);
        }
        return ans;
    }

    int Comb(int n,int m){
        int a=n,b=m;
        for(int i=1;i<m;i++){
            a *= (a-i);
        }
        for(int i=1;i<m;i++){
            b *= (b-i);
        }
        
        return a/b;
    }
}

namespace SubLib{
    #define int long long
    #define double long double
    #define incin(n) int (n); cin >> (n);
    #define incin2(a,b) int a,b; cin >> a >> b; 
    #define rap(n,i) for(int (i) = 0;i<(n);(i)++)
    #define input(n,v) (v) = SubLib::Input((n),(v))
    #define all(v) (v).begin(),(v).end()
    using intv = vector<int>;
    using strv = vector<string>;
    using charv = vector<char>;
    template <class T1>
    using pvec = vector<pair<T1,T1>>;
    template <typename T> vector<T> Input(int n,vector<T> v){
        for(int i=0;i<n;i++){
            cin >> v.at(i);
        }
        return v;
    }
}

using namespace math;
using namespace SubLib;

signed main(){
    incin2(n,m);
    incin(x);
    intv a(m);
    intv mas(n+1,0);
    input(m,a);
    rap(m,i){
        mas[a[i]] = 1;
    }
    int r_cost = 0;
    int l_cost = 0;
    for(int i=x;i<=n;i++){
        r_cost+=mas[i];
    }
    for(int i=x;i>=0;i--){
        l_cost+=mas[i];
    }
    cout<<min(r_cost,l_cost)<<endl;
    return 0;
}

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

N=int(input())

E=[[] for i in range(N+1)]

for i in range(N-1):
    x,y=map(int,input().split())
    E[x].append(y)
    E[y].append(x)

mod=10**9+7

from collections import deque
Q=deque()

USE=[0]*(N+1)
Q.append(1)
H=[0]*(N+1)
H[1]=1
USE[1]=1

while Q:
    x=Q.pop()
    for to in E[x]:
        if USE[to]==0:
            USE[to]=1
            H[to]=H[x]+1
            Q.append(to)

EH=[(h,ind+1) for ind,h in enumerate(H[1:])]
EH.sort(reverse=True)

COME=[1]*(N+1)
USE=[0]*(N+1)

for h,ind in EH:
    USE[ind]=1
    for to in E[ind]:
        if USE[to]==0:
            COME[to]+=COME[ind]

ANS=0

POW2=[1]
for i in range(N+1):
    POW2.append(POW2[-1]*2%mod)

for i in range(1,N+1):
    SCORE=[]
    for j in E[i]:
        if COME[j]<COME[i]:
            SCORE.append(COME[j])

    if sum(SCORE)<N-1:
        SCORE.append(N-sum(SCORE)-1)

    AV=1

    for s in SCORE:
        AV+=POW2[s]-1

    ANS+=POW2[N-1]-AV
    #print(SCORE,AV)

print((ANS*pow(POW2[N],mod-2,mod))%mod)

Measured memory_bytes: 105780
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]
cnt = 0
for x in A:
  total = sum([x[i]*B[i] for i in range(M)])
  total += C
  if total > 0:
    cnt+= 1
    
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i!=n;i++)

using namespace std;


int main(void){
    long long a,b;
    cin >> a >> b;
    long long r;
    long long x=a*b;
    if(a<b){
        long long tmp=a;
        a=b;
        b=tmp;
    }
    r=a%b;
    while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  cout << x/b << endl;
}


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

int main() {
    int N;
    while (cin >> N, N) {
        vector<string> vstr(N);
        for (auto& i : vstr) cin >> i;

        vector<string> cstr;
        int max_len = 0;
        for (auto str : vstr) {
            string s = "";
            s += str[0];

            string alf = "aiueo";
            for (int i = 1; i < str.size(); i++) {
                if (alf.find(str[i-1]) != string::npos) {
                    s += str[i];
                }
            }

            cstr.push_back(s);

            max_len = max(max_len, (int)s.size());
        }

        int ans = -1;

        for (int i = 1; i <= max_len; i++) {
            set<string> ss;
            for (auto s : cstr) {
                ss.insert(string(s.begin(), s.begin() + min(i, (int)s.size())));
            }

            if (ss.size() == N) {
                ans = i;
                break;
            }
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3192
#include<iostream>
#include <bits/stdc++.h>
#include<string>
#include<algorithm>
#include<utility>
using namespace std;


int main(){
    int N,M,A[10010];
    cin >> N >> M;
    for(int i =0; i < M; ++i){
        cin >>A[i];
    }
    int sum =0;

    for(int i =0 ; i <M;++i){
        sum += A[i];
    }
    if(sum > N){
        cout << -1 << endl; 
    }else{
        cout << N-sum <<endl;
    }
    return 0;
}



Measured memory_bytes: 3716
// template version 1.12
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-2.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int dp1[31625][100];
int dp2[31625][100];
int n,k;

int f(int y){  // yまで
  int r = n/y     + 1;
  int l = n/(y+1) + 1;  // 7
  return r-l;
}

int solve(){
  cin>>n>>k;

  int x = sqrt(n);
  int z = n/(x+1);
  dump(x, z);

  dp1[x][0] = f(x);
  rrep(i, 1, x){
    dp1[i][0] += f(i);
    dp1[i][0] += dp1[i+1][0];
  }
  dump_2d(dp1, 11, 11);

  // rep(i, 1, z+1){
  rep(i, 1, max(z, x)+1){
    dp2[i][0] += i;
  }
  dump_2d(dp2, 11, 11);

  int res=0;

  rep(j, 1, k){
    // dp1の更新
    rrep(i, 1, x+1){
      dp1[i][j] += dp2[i][j-1] * f(i);
      if (i!=x) dp1[i][j] += dp1[i+1][j];
      dp1[i][j] %= MOD;
    }

    // dp2の更新
    rep(i, 1, x+1){
      dp2[i][j] += dp1[i][j-1];
      dp2[i][j] += dp2[z][j-1];
      if (i>=2) dp2[i][j] += dp2[i-1][j];  // acuumulate
      dp2[i][j] %= MOD;
    }
    dump_2d(dp1, 11, 11);
    dump_2d(dp2, 11, 11);
  }

  cout << (dp2[z][k-1]+dp1[1][k-1])%MOD << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 49664
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		int[][] path=new int[M][2];
		for(int i=0; i<M; i++) {
			for(int j=0; j<2; j++) {
				path[i][j]=sc.nextInt();
			}
		}
		int count=0;
		for(int i=0; i<M; i++) {
			UnionFind.init(N);
			for(int j=0; j<M; j++) {
				if(i!=j) {
					UnionFind.unite(path[j][0]-1, path[j][1]-1);
				}
			}
			for(int j=2; j<=N; j++) {
				if(!UnionFind.same(0,j-1)) {
					count++;
					break;
				}
			}
		}
		System.out.println(count);
	}

	static class UnionFind {
		static int N;			//頂点数
		static int par[];		//親ノード
		static int rank[];		//ランク　UnionFind木の高さがrankみたい
		public static void init(int n) {		//初期化
			N = n;
			par = new int[N];
			rank = new int[N];
			for(int i = 0; i < N; i++) {		//0処理
				par[i] = i;
				rank[i] = 0;
			}
		}

		public static int find(int x) {		//木の根を求める
			if(par[x] == x) {
				return x;
			} else {
				return par[x] = find(par[x]);	//経路圧縮
			}
		}

		public static void unite(int x, int y) {		//xとyの属する集合を併合	xにyをという意味合いが強そう		集合に含めるときに unite(114,514);のようにするみたい
			x = find(x);
			y = find(y);
			if(x == y) return;

			if(rank[x] < rank[y]) {
				par[x] = y;
			} else {
				par[y] = x;
				if(rank[x] == rank[y]) rank[x]++;
			}
		}

		public static boolean same(int x, int y) {		//x,yが同じ集合に属するか否か
			return find(x) == find(y);
		}
	}
}

Measured memory_bytes: 23252
nums = gets.chomp.split(" ").map(&:to_i)
one = nums[0]
two = nums[1]
if two != 100
  if one == 0
    p two
  elsif one == 1
    p two * 100
  elsif one == 2
    p two * 10000
  end
else
    if one == 0
    p two + 1
  elsif one == 1
    p two * 101
  elsif one == 2
    p two * 10100
  end
end

Measured memory_bytes: 1788
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
 
n = int(input())
edge = [[] for _ in range(n)]
edge_dict = dict()
 
for i in range(n - 1):
    a, b = [int(item) - 1 for item in input().split()]
    edge[a].append(b)
    edge[b].append(a)
    if a > b:
        edge_dict[(b, a)] = i
    else:
        edge_dict[(a, b)] = i
 
m = int(input())
uv = []
for _ in range(m):
    uv.append([int(item) - 1 for item in input().split()])
 
def dfs(p, v, dest):
    if v == dest:
        return [v]
    if p != -1 and len(edge[v]) == 1:
        return False
    for nv in edge[v]:
        if nv == p:
            continue
        ret = dfs(v, nv, dest)
        if ret:
            return ret + [v]
    return False
 
# edge-bitset of each constraint
target_edge = [0] * m
for i, (u, v) in enumerate(uv):
    ret = dfs(-1, u, v)
    for uu, vv in zip(ret, ret[1:]):
        if uu > vv:
            uu, vv = vv, uu
        if (uu, vv) in edge_dict:
            target_edge[i] |= (1 << edge_dict[(uu, vv)])

# edge-bitset of each set of constraints
edgest = [0] * 2**m
for i in range(1, 2**m):
    lsb = i & (-i)
    edgest[i] = edgest[i ^ lsb] | target_edge[lsb.bit_length() - 1]
 
# dp[set of constraints]
dp = [0] * 2**m
dp[0] = 1 << (n - 1)
ans = dp[0]
for i in range(1, 2**m):
    lsb = i & (-i)
    n_edgest = edgest[i]
    p_edgest = edgest[i ^ lsb]
    limit_num = bin(n_edgest ^ p_edgest).count("1")
    dp[i] = dp[i ^ lsb] >> limit_num
    if bin(i).count("1") % 2 == 0:
        ans += dp[i]
    else:
        ans -= dp[i]
print(ans)

Measured memory_bytes: 59356
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;
int main(){
  int n;cin >> n;
  for(int i=0;i<n;i++){
    char s;cin >> s;
    if(s=='Y'){
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    double a, b, C;
    cin >> a >> b >> C;
    double r = C * M_PI / 180;

    cout << fixed << setprecision(8)
        << a * b * sin(r) / 2 << endl
        << a + b + sqrt(a * a + b * b - 2 * a * b * cos(r)) << endl
        << b * sin(r) << endl;

    return 0;
}



Measured memory_bytes: 3480
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    vector<int> P(N);
    for (int i=0; i<N; i++) {
        cin >> S[i] >> P[i];
    }
    
    vector<pair<string, pair<int, int>>> SP(N);
    set<string> cities;
    for (int i=0; i<N; i++) {
        cities.insert(S[i]);
        SP[i]=make_pair(S[i], make_pair(P[i],i));
    }
    
    
    sort(SP.begin(), SP.end());
    //reverse(SP.begin(), SP.end());
    //vector<pair<string, int>> Si(N);
    string now=SP[0].first;
    
    int j=0;
    for (int i=0; i<cities.size(); i++) {
        vector<pair<int, int>> Pi;
        for(; j<N; j++){
            //cout << "/" << j << endl;
            if(now==SP[j].first){
                Pi.push_back(make_pair(SP[j].second.first, SP[j].second.second));
                if(j==N-1){
                    sort(Pi.begin(),Pi.end());
                reverse(Pi.begin(),Pi.end());
                for(int k=0; k<Pi.size(); k++){
                    cout << Pi[k].second+1 << endl;
                }
                break;
                }
            }
            else{
                //cout << '/' << endl;
                now=SP[j].first;
                sort(Pi.begin(),Pi.end());
                reverse(Pi.begin(),Pi.end());
                for(int k=0; k<Pi.size(); k++){
                    cout << Pi[k].second+1 << endl;
                }
                break;
            }
        }
    }
    
    
}


Measured memory_bytes: 256
n = int(input())

a_i_list = []

push_i = 1
GOAL_i = 2

is_loop = False
pushed_i_list = []

push_counter = 0

for i in range(n):
  a_i_list.append(int(input()))

while (True):
  push_counter += 1

  # pushed_i_list.append(push_i)
  current_index = push_i - 1
  push_i = a_i_list[push_i - 1]
  
  # 一度使用したボタンは数値を0にする
  a_i_list[current_index] = 0

  if a_i_list[push_i - 1] == 0:
    push_counter = -1
    break
  
  if push_i == GOAL_i:
    break


print(push_counter)

Measured memory_bytes: 7084
#include <bits/stdc++.h>
using namespace std;
#define int long long
int INF = 1e9+7;
typedef pair<int,int> P;
signed main() {
    int N;
    cin >> N;
    vector<int>h(N);
    for(int i = 0; i < N; i++) {
        cin >> h[i];
    }
    vector<int>dp(N);
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    for(int i = 2; i < N; i++) {
        dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
    }
    cout << dp[N-1] << endl;
}

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

using namespace std;
#define endl "\n"

const int MOD = 1000000007;
int main()
{
	int a, b;
	cin >> a >> b;
	int ara[b], s = 0;
	for(int i = 0 ; i< b; i++){
	 cin >> ara[i];s+= ara[i];
}
	if(s > a) cout << "-1" << endl;
	else cout << a - s << endl;
	
	
	return 0;
}


Measured memory_bytes: 3644
N = input()
A = map(int, raw_input().split())
print " ".join(map(str,A))
for i in range(1,N):
    v = A[i]
    j=i-1
    while (j>=0) & (A[j]>v):
        A[j+1]=A[j]
        j -= 1
    A[j+1]=v
    print " ".join(map(str,A))

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

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


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

long long toLong(string str, int n)
{
	long long res = 0;
	for (int i = 0; i < str.size(); i++){
		if (str[i] != 'X'){
			res = res * 10 + str[i] - '0';
		}
		else {
			if (i == 0 && n == 0 && str.size() > 1) return -1145141919;
			res = res * 10 + n;
		}
	}
	return res;
}

int main()
{
	//char A[128], B[128], C[128];
	while (true){
		string str[3];
		string line;
		if (!(cin >> line)) return 0;
		
		for (int p = 0, i = 0; p < line.size(); p++){
			if (line[p] != '+' && line[p] != '='){
				str[i] += line[p];
			}
			else {
				i++;
			}
		}
		
		int res = -1;
		for (int i = 0; i <= 9; i++){
			if (toLong(str[0], i) + toLong(str[1], i) - toLong(str[2], i) == 0LL){
				res = i;
			}
		}
		
		if (res != -1) printf("%d\n", res);
		else puts("NA");
	}
	
	return 0;
}

Measured memory_bytes: 1192
#include<stdio.h>
#include<stdlib.h>
int main() {
	int n, m;
	scanf("%d %d",&n,&m);
	int i;
	char** a = malloc(sizeof(char*) * n);
	char** b = malloc(sizeof(char*) * m);
	for ( i = 0; i < n; i++)
	{
		a[i] = malloc(sizeof(char) * (n + 1));
		scanf("%s", a[i]);
	}
	for (i = 0; i < m; i++)
	{
		b[i] = malloc(sizeof(char) * (m + 1));
		scanf("%s", b[i]);
	}
	int j, k, l;
	int count;
	for ( i = 0; i < n-m+1; i++)
	{
		for (j = 0; j < n - m + 1; j++)
		{
			count = 0;
			for ( k = 0; k < m; k++)
			{
				for ( l = 0; l < m; l++)
				{
					if (a[i + k][j + l] != b[k][l])
						goto out;
					count++;
					if (count == m * m) {
						printf("Yes");
						return 0;
					}
				}
			}
		out:;
		}
	}
	printf("No");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, a, b, d;
  a = 99999999999999;
  in(n);
  vector<ll> c(n);
  rep(i, n)
    in(c[i]);
  b = 0;
  rep(i, n)
    b += c[i];
  d = 0;
  rep(i, n - 1){
    d += c[i];
    b -= c[i];
    a = min(a, abs(b - d));
  }
  out(a);
  memi;
}

Measured memory_bytes: 1792
#include<iostream>
#include <cstring>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdlib.h>


using namespace std;
int main()
{
    int n,sum=0;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        sum += i;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <stdio.h>
using namespace std;

int main() {
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;

    if (a < b && b < c) {
        cout << "Yes" << endl;
    }
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3092
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cinttypes>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>


#define FSCNd64 "%" SCNd64
#define FPRId64 "%" PRId64

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

template<typename X>
bool max_u(X&m, X v)
{
	if(m<v)
	{
		m=v;
		return true;
	}
	return false;
}


template<typename X>
bool min_u(X&m, X v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


struct solve
{
	solve(){}
	ll operator()() {
		return 0;
	}
};

int pat(int x, int y, int z)
{
	static int ret[]={6, 3, 1, 1};
	int idx=0;
	if(x==y) idx++;
	if(y==z) idx++;
	if(z==x) idx++;
	return ret[idx];
}


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

	for(;;)
	{
		int n;
		cin >> n;
		if(cin.fail()) break;
		vi f(n+1);

		for(int x=1;x*x<=n;x++)
		{
			int rx=n-x*x;
			for(int y=x;y*y<rx;y++)
			{
				int ry=rx-y*y;
				for(int z=y;z*z<ry;z++)
				{
					int s=x*x+y*y+z*z+x*y+y*z+z*x;
					if(s<=n)
					{
						f[s]+=pat(x, y, z);
					}
				}
			}
		}
		for(int i=1;i<=n;i++) cout << f[i] << "\n";
	}
	return 0;
}


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

char area[100][100];
using P=pair<char,bool>;

int main(){
  ll l,r;
  std::cin >> l>>r;
  bool flag=false;
  ll mini=2020;

  for (ll i = l; i <= l+3000  && i<=r; i++) {
    for (ll j = i+1; j <= l+3000 &&  j<= r; j++) {
      ll temp=i*j%2019;


      mini=min(temp,mini);
      if(mini==0){
        flag=true;
        break;
      }
    }
    if(flag)break;
  }

  std::cout << mini << '\n';



  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 100001
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<int,ll>Pil;
typedef pair<P1,ll> P2;
typedef list<int> li;
typedef list<li> lli;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	ll a;
	int b;
};
ll dp[10][10];

int main(){

	int h,w;
	cin>>h>>w;
	rep(i,10){
		rep(j,10){
			int c;
			cin>>c;
			dp[i][j]=c;
		}
	}
	rep(k,10){
		rep(i,10){
			rep(j,10){
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
			}
		}
	}
	ll total=0;
	rep(i,h){
		rep(j,w){
			int a;
			cin>>a;
			if(a==-1)continue;
			total+=dp[a][1];
		}
	}
	cout<<total<<endl;

	return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

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

int main(){
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	while(n--){
		string ppl, mes;
		cin >> ppl >> mes;

		reverse(ALL(ppl));
		for (auto ch : ppl){
			string nxt;
			int m;
			switch (ch){
			case 'J':
				nxt = mes.back() + mes.substr(0, mes.size() - 1);
				break;
			case 'C':
				nxt = mes.substr(1) + mes[0];
				break;
			case 'E':
				m = mes.size() / 2;
				if (mes.size() & 1){
					nxt = mes.substr(m+1) + mes[m] + mes.substr(0, m);
				}
				else{
					nxt = mes.substr(m) + mes.substr(0, m);
				}
				break;
			case 'A':
				nxt = string(REV(mes));
				break;
			case 'M':
				for (auto c : mes){
					if ('0' <= c && c <= '8') ++c;
					else if (c == '9') c = '0';
					nxt += c;
				}
				break;
			case 'P':
				for (auto c : mes){
					if ('1' <= c && c <= '9') --c;
					else if (c == '0') c = '9';
					nxt += c;
				}
				break;
			}
			mes = nxt;
		}
		cout << mes << endl;
	}


	return 0;
}

Measured memory_bytes: 1204
s=input()
ans=753
for i in range(len(s)-2):
  if abs((int(s[i])*100)+(int(s[i+1])*10)+int(s[i+2])-753)<ans:
    ans=abs((int(s[i])*100)+(int(s[i+1])*10)+int(s[i+2])-753)
  else:
    ans+=0
print(ans)    
  

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
typedef long long int ll;
using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<vector<pair<int, int>>> A(N);
    int tmp_A;
    int x, y;
    rep(i, N)
    {
        cin >> tmp_A;
        rep(j, tmp_A)
        {
            cin >> x >> y;
            A[i].pb(mp(x - 1, y));
        }
    }
    int max_cnt = 0;
    int n = pow(2, N);
    reps(i, n + 1, 1)
    {
        set<int> honest;
        int ok = true;
        rep(j, N)
        {
            if (i & (1 << j))
            {
                honest.insert(j);
            }
        }
        rep(j, N)
        {
            for (auto v : A[j])
            {
                int p = v.first;
                int c = v.second;
                if (honest.count(j))
                {
                    if((c==0 && honest.count(p))||(c==1 && !honest.count(p))){
                        ok = false;
                    }
                }
            }
        }
        if (ok)
        {
            max_cnt = max(max_cnt, (int)honest.size());
        }
    }
    cout << max_cnt << endl;
    //system("pause");
    return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define per(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define enter cout << endl
#define siz(x) ((int)x.size())
typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi ;
typedef pair <int, int> pii ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int N = 17 ;
const int INF = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const int MOD = 1000000007 ;
void print(int x) { cout << x << endl ; exit(0) ; }
void PRINT(string x) { cout << x << endl ; exit(0) ; }
void douout(double x){ printf("%lf\n", x + 0.0000000001) ; }

int n ;
ll a[N][N] ;
ll sum[1 << N], dp[1 << N] ;

signed main(){
	scanf("%d", &n) ;
	for (int i = 0; i < n; i++)
	for (int j = 0; j < n; j++)
	scanf("%lld", &a[i][j]) ;
	for (int i = 0; i < (1 << n); i++) {
		sum[i] = 0 ;
		for (int j = 0; j < n; j++)
		if (i & (1 << j))
		for (int k = j + 1; k < n; k++)
		if (i & (1 << k))
		sum[i] += a[j][k] ;
	}
	dp[0] = 0ll ;
	for (int i = 0; i < (1 << n); i++)
	for (int j = i; j; j = (j - 1) & i)
	dp[i] = max(dp[i], dp[i - j] + sum[j]) ;
	printf("%lld\n", dp[(1 << n) - 1]) ;
	return 0 ;
}

/*
写代码时请注意：
	1.ll？数组大小，边界？数据范围？
	2.精度？
	3.特判？
	4.至少做一些
思考提醒：
	1.最大值最小->二分？
	2.可以贪心么？不行dp可以么
	3.可以优化么
	4.维护区间用什么数据结构？
	5.统计方案是用dp？模了么？
*/


Measured memory_bytes: 1280
#include <iostream>
using namespace std;
int A,B,C,X,Y;
int main() {
	cin>>A>>B>>C>>X>>Y;
	int sum=0;
	int minm=min(X,Y);
	if(2*C>A+B){
		sum+=minm*(A+B);
	}
	else
		sum+=minm*2*C;
	if(minm==X){
		int d=Y-X;
		if(C*2>B)
		sum+=d*B;
		else
		sum+=d*2*C;
	}
	else if(minm==Y){
		int d=X-Y;
		if(C*2>A)
		sum+=d*A;
		else
		sum+=d*2*C;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    map<pair <int, int>, int >mp;
    for (int i = 1; i <= n; i++){
        string s = to_string(i);

        mp[make_pair(*s.rbegin() - 48, *s.begin() - 48)]++;
    }
    int ans = 0;
    for (auto i : mp){
        pair<int, int> dig1 = i.first;
        int c1 = i.second;
        pair<int, int> dig2 = make_pair(dig1.second, dig1.first);
        mp[dig2]++;
        mp[dig2]--;
        int c2 = mp[dig2];
       // cout << dig2.first << " " << dig2.second << " " << c2 << endl;
        if (c2 > 0){
            ans += c1 * c2;
        }
    }
    cout << ans << endl;

    return 0;

}


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

v_dict = [{} for _ in range(2)]
for i in range(n):
    if i % 2 == 0:
        if v[i] in v_dict[0]:
            v_dict[0][v[i]] += 1
        else:
            v_dict[0][v[i]] = 1
    else:
        if v[i] in v_dict[1]:
            v_dict[1][v[i]] += 1
        else:
            v_dict[1][v[i]] = 1

evens = sorted([(key, val) for key, val in v_dict[0].items()], key=lambda comb: comb[1])
odds = sorted([(key, val) for key, val in v_dict[1].items()], key=lambda comb: comb[1])

ans = 0
for _, val in evens[:-1]:
    ans += val
for _, val in odds[:-1]:
    ans += val
if evens[-1][0] == odds[-1][0]:
    if len(evens) > 1 and len(odds) > 1:
        if evens[-2][1] < odds[-2][1]:
            ans += odds[-1][1] - odds[-2][1]
        else:
            ans += evens[-1][1] - evens[-2][1]
    elif len(evens) > 1:
        ans += evens[-1][1] - evens[-2][1]
    elif len(odds) > 1:
        ans += odds[-1][1] - odds[-2][1]
    else:
        ans = n // 2

print(ans)


Measured memory_bytes: 21276
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] chars={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
        int n=sc.nextInt();
        String[] input=new String[n];
        for(int i=0;i<n;i++){
            input[i]=sc.next();
        }
        int[] output=new int[26];
        int tmp;
        for(int i=0;i<26;i++){
            tmp=Integer.MAX_VALUE;
            for(int j=0;j<n;j++){
                tmp=Math.min(tmp,input[j].length()-input[j].replaceAll(chars[i],"").length());
            }
            output[i]=tmp;
        }
        for(int i=0;i<26;i++){
            for(int j=0;j<output[i];j++){
                System.out.print(chars[i]);
            }
        }
        System.out.println();
    }
}

Measured memory_bytes: 25812