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

signed main() {
  int H, N;
  cin >> H >> N;
  
  vector<pair<int, int>> AT(N);
  int A, B;
  for( int i = 0; i < N; i++ ){
    cin >> A >> B;
    AT.at(i) = make_pair(A, B);
  }
  
  vector<int> dp(H+100, 10000000000);
  dp.at(0) = 0;
  for( int i = 0; i <= H; i++ ){
    for( int j = 0; j < N; j++ ){
      int n = min(H, i + AT.at(j).first);
      dp.at(n) = min( dp.at(n), dp.at(i) + AT.at(j).second );
    }
  }
  cout << dp.at(H) << endl;
  
  
}
  

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<cassert>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
int N;

struct P
{
  int x,y,type;
  P(int x = -1,int y = -1,int type = -1):x(x),y(y),type(type){}
};
int SMLx[3][12] = {{0,0,1,-1},{1,2,2,2,1,1,0,0},{0,0,0,0,1,1,1,2,-1,-1,-1,-2}};
int SMLy[3][12] = {{1,2,1,1},{0,0,1,2,1,2,1,2},{1,2,3,4,1,2,3,2,1,2,3,2}};
int SML[] = {4,8,12};
bool F;
int Cx[] = {0,1,0};
int Cy[] = {1,1,2};

bool check(VVI& G,int x,int y,int type)
{
  G[y][x]--;
  for(int i=0;i<SML[type];i++)
    {
      int nx = x + SMLx[type][i];
      int ny = y + SMLy[type][i];
      if(!(0 <= nx && nx < 10 && 0 <= ny && ny < 10) || G[ny][nx] <= 0)
	{
	  G[y][x]++;
	  for(int j=i-1;j>=0;j--)
	    {
	      nx = x + SMLx[type][j];
	      ny = y + SMLy[type][j];
	      G[ny][nx]++;
	    }
	  return false;
	}
      G[ny][nx]--;
    }
  return true;
}

void draw(VVI& G,int x,int y,int type)
{
  G[y][x]++;
  for(int i=0;i<SML[type];i++)
    {
      int nx = x + SMLx[type][i];
      int ny = y + SMLy[type][i];
      G[ny][nx]++;
    }
}


void dfs(VVI& G,int x,int y,int cnt,vector<P> perm)
{
  if(cnt > N)
    return;
      
  perm.push_back(P(-1,-1,-1));
  for(int i=y;i<10;i++)
    for(int j= (i == y?x:0);j<10;j++)
      if(G[i][j] >= 1)
	{
	  bool found = false;
	  for(int k=0;k<3;k++)
	    {
	      if(!check(G,j,i,k))
		continue;
	      perm[perm.size()-1] = P(j+Cx[k],i+Cy[k],k+1);
	      dfs(G,j,i,cnt+1,perm);
	      draw(G,j,i,k);
	    }
	  return;
	}


  if(cnt == N  && !F)
    {
      for(int i=0;i<N;i++)
	  cout << perm[i].x << " " << perm[i].y << " " << perm[i].type << endl; 
      F = true;
    }
}

int main()
{
  F = false;
  cin >> N;
  VVI G(10,VI(10));

  for(int i=0;i<10;i++)
    for(int j=0;j<10;j++)
      cin >> G[i][j];
  dfs(G,0,0,0,vector<P>());
  return 0;
}

Measured memory_bytes: 1220
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

//#include <bits/stdc++.h>
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <random>
#include <assert.h>
#include <time.h>
#include <random>
#include <chrono>
#include <memory>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

#define plus dfghjk
#define minus tyughj
#define y1 tyjnm

using namespace std;

inline void setmin(int &x, int y) { if (y < x) x = y; }
inline void setmax(int &x, int y) { if (y > x) x = y; }
inline void setmin(ll &x, ll y) { if (y < x) x = y; }
inline void setmax(ll &x, ll y) { if (y > x) x = y; }

const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = 998244353;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int a, b, k;
    cin >> a >> b >> k;
    repb(i, min(a, b), 0) {
        if (a % i == 0 && b % i == 0) {
            k--;
            if (k == 0) {
                cout << i << "\n";
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, '%f %f %f', $start, $cnt, $length);
$start = (int)abs($start);
$tmp = floor($start / $length);
if ($tmp >= $cnt) {
    $ans = (int)($start - $cnt * $length);
} else {
    $ans = (int)($start - $tmp * $length);
    $cnt -= $tmp;
    if ($cnt % 2 != 0) {
        $ans = (int)($ans - $length);
    }
}
echo (int)abs($ans);

Measured memory_bytes: 16124
#include <iostream>
using namespace std;
int main(){
  int m,d,s[]={0,31,29,31,30,31,30,31,31,30,31,30};
  string day[]={"Thursday","Friday","Saturday","Sunday","Monday","Tuesday","Wednesday"};
  for(;cin>>m>>d,m||d;)
    {
      d--;
      for(int i=0;i<m;i++)
	d+=s[i];
      cout<<day[d%7]<<endl;
    }
  return 0;
}

Measured memory_bytes: 1196
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    // インタラクティブ問題では除去した方がいいかも
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll a, b, c, k; cin >> a >> b >> c >> k;

    ll ans = k % 2 ? b - a : a - b;

    ll lim = 1000000000000000000LL;
    cout << (abs(ans) > lim ? "Unfair"s : to_string(ans)) << endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
struct S{
    mint val, unit;
};
struct F{
    int digit, time;
};
S op(S a, S b){
    return {a.val + b.val, a.unit + b.unit};
}
S e(){
    return {0, 0};
}
S mapping(F f, S x){
    if(f.time != -1){
        x.val = f.digit * x.unit;
    }
    return x;
}
F composition(F f, F g){
    if(f.time > g.time){
        return f;
    }
    return g;
}
F id(){
    return {0, -1};
}
int main(){
    int n, q;
    cin >> n >> q;
    vector<S>v(n);
    mint pw = 1;
    for(int i = n - 1; i >= 0; i--){
        v[i] = {pw, pw};
        pw *= 10;
    }
    lazy_segtree<S, op, e, F, mapping, composition, id>seg(v);
    for(int i = 1; i <= q; i++){
        int l, r, d;
        cin >> l >> r >> d;
        l--;
        seg.apply(l, r, {d, i});
        cout << seg.all_prod().val.val() << '\n';
    }
    return 0;
}

Measured memory_bytes: 10928
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    LL N,M,K; cin >> N >> M >> K;
    VL A(N),B(M);
    REP(i,N) cin >> A[i];
    REP(i,M) cin >> B[i];
    VL SA(N+1),SB(M+1);
    REP(i,N){
        SA[i+1] = SA[i] + A[i];
    }

    REP(i,M){
        SB[i+1] = SB[i] + B[i];
    }
    int ans = 0;
    REP(i,N+1){
        int idx = lower_bound(SB.begin(), SB.end(), K-SA[i]+1) - SB.begin()-1;
        if(idx == -1) continue;
        dump(i)
            dump(idx)
        chmax(ans, i+idx);

    }

    cout << ans << endl;

}

Measured memory_bytes: 9532
#include <iostream>
#include<cstdio>
#include<string>
#include<stdio.h>
using namespace std;

int main() {
	string s, p;

	cin >> s;
	cin >> p;

	s = s + s;

	if (s.find(p) != string::npos) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}




Measured memory_bytes: 3224
#include <stdio.h>
int main(void){
    
    int n;
    int a;
    int x=0,y=0,z=0;
    scanf("%d",&n);
    for(;~scanf("%d",&a);){
        if(a%4==0){
            z++;
        }else if(a%2==0){
            y++;
        }else{
            z--;
        }
    }
    puts((!y&&z>-2||y&&z+1)?"Yes":"No");
}

Measured memory_bytes: 1656
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define dum(x) cout<<#x<<'='<<x<<endl
#define dum2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define dum3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());

int a[100010];

int main() {
    int N;
    cin >> N;
    rep(i, N)cin >> a[i];

    //+,-,+,-
    ll cou = 0;

    ll sum = 0;
    for (int i = 0; i < N; i++) {
        sum += a[i];
        if (i % 2 == 0) {
            if (sum <= 0) {
                cou += -sum + 1;
                sum = 1;
            }
        }
        else {
            if (sum >= 0) {
                cou += sum + 1;
                sum = -1;
            }
        }
    }
    ll coub = 0;
    ll sumb = 0;
    for (int i = 0; i < N; i++) {
        sumb += a[i];
        if (i % 2 == 0) {
            if (sumb >= 0) {
                coub += sumb + 1;
                sumb = -1;
            }
        }
        else {
            if (sumb <= 0) {
                coub += -sumb + 1;
                sumb = 1;
            }
        }
    }
    cout << min(cou,coub) << endl;
}

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

using namespace std;
typedef long long ll;

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> sub(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        sub[i] = a[i] - i;
    }
    sort(sub.begin(), sub.end());
    int b = sub[n / 2];
    // cout << b << endl;
    ll sum = 0;
    for (int i = 0; i < n; i++)
    {
        sum += abs(a[i] - (b + i));
        // cout << a[i] << "," << (b + i) << endl;
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h> 
#include <math.h>
using namespace std;
 
int main(){
	int N, K;
	string S;
	cin >> N >> S >> K;
	for(int i = 0; i < N;i++){
		if(S.at(i) != S.at(K - 1)){
			S.at(i) = '*';
		}
	}
	cout << S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define For(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int a[maxn];
int main()
{
	int n,sum=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]>a[i-1]) sum+=a[i]-a[i-1];
		else sum+=a[i-1]-a[i];
	}
	a[n+1]=0;
	sum+=abs(a[n+1]-a[n]);
	for(int i=1;i<=n;i++)
	{
		if(a[i]>=a[i-1]&&a[i]<=a[i+1]||a[i]<=a[i-1]&&a[i]>=a[i+1]) printf("%d\n",sum);
		else
		{
			int l1=abs(a[i]-a[i-1]);
			int l2=abs(a[i+1]-a[i]);
			int minn=min(l1,l2);
			printf("%d\n",sum-2*minn);
		}
	}
} 

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

long long ans = (1LL << 60);

void diff(long long a, long long b, long long c){
    vector<long long> v;
    v.emplace_back(a);
    v.emplace_back(b);
    v.emplace_back(c);
    ans = min(ans, *max_element(all(v)) - *min_element(all(v)));
}

void solve(long long h, long long w, long long size){
    if(h % 2 == 0 || w % 2 == 0){
        diff(size, h * w / 2, h * w / 2);
    }

    long long dh = h / 2;
    long long dw = w / 2;
    if(h == 1) diff(size, dw, w - dw);
    else diff(size, dh * w, (h - dh) * w);

    if(w == 1) diff(size, dh, h - dh);
    else diff(size, dw * h, (w - dw) * h);
}

int main(){
    long long h,w;
    cin >> h >> w;

    if(h % 3 == 0 || w % 3 == 0) ans = 0;
    range(i,1,h / 2 + 1){
        solve(h - i,w,i * w);
    }
    range(i,1,w / 2 + 1){
        solve(h,w - i,h * i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let r: i32 = buf.trim().parse().ok().unwrap();

    if r < 1200 {
        println!("ABC");
    } else if r < 2800 {
        println!("ARC");
    } else {
        println!("AGC");
    }
}

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

using namespace std;
typedef long long ll;
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

bool isMatch(string sub, string obj) {
  for (int i = 0; i < sub.size(); i++) {
    if (!(sub[i] == '?' || sub[i] == obj[i])) {
      return false;
    }
  }
  return true;
}

int main() {
  int n, m, a, b;
  cin >> n >> m;
  vector<int> roads(n, 0);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    roads[a - 1]++;
    roads[b - 1]++;
  }

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

  return 0;
}


Measured memory_bytes: 256
def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())

N = intinp()
d = list(mapint_inp())

sorted_d = sorted(d)

m = N//2
if sorted_d[m-1] == sorted_d[m]:
    print(0)
else:
    print(sorted_d[m]-sorted_d[m-1])

Measured memory_bytes: 14396
#if 0

#endif

#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void p(A a){cout << (a) << endl;}
template<class A,class B>void p(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void p(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void p(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for copy
// for(int i=0;i<N;++i) {

int main(void) {
  string s;cin>>s;
  if(s[2]==s[3]&&s[4]==s[5]) p("Yes");
  else p("No");
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 100000000000000
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

using namespace std;
typedef long long int  ll;
typedef pair<int, int> P;


//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}


////////////////////////////////////////////////////////////////////

int main() {
int h,w;
cin>>h>>w;



int d[10][10];
rrep(i,10){
	rrep(j,10){
if(i!=j){
d[i][j]=100000000;}
else d[i][j]=0;
	}
}

rrep(i, 10){
 rrep(j,10){
int p;
cin>>p;
d[i][j]=p;
 }
}



for(int l=1;l<=100;l++){
rrep(k,10){
	rrep(i,10){
		rrep(j,10){
d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
		}
	}
}
}

int ans=0;
rrep(i,h){
	rrep(j,w){
		int u;
		cin>>u;
		if(u!=-1)
		ans+=d[u][1];
	}
}


cout<<ans<<endl;
return 0;



}




Measured memory_bytes: 256
w, h, n = map(int, input().split())
a_r = w
a_l = 0
a_u = h
a_d = 0
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        a_l = max(a_l, x)
    elif a == 2:
        a_r = min(a_r, x)
    elif a == 3:
        a_d = max(a_d, y)
    else:
        a_u = min(a_u, y)


print(max(0, a_r - a_l) * max(0, a_u - a_d))



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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 1; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

int N, X, Y;
int dist[10010];

int make_dist(int i, int j) {
    int d = min(j - i, abs(X - i) + abs(j - Y) + 1);
    return d;
}

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

    cin >> N >> X >> Y;

    REPS(i, 1, N) {
        REPS(j, i+1, N) {
            int d = make_dist(i, j);
            dist[d]++;
        }
    }

    REP(i, 1, N) {
        cout << dist[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll            long long
#define pb            push_back
#define eb            emplace_back
#define ppb           pop_back
#define si            set <ll>
#define endl          '\n'
#define F             first
#define S             second
#define mii           map<ll ,ll >
#define msi           map<string,ll >
#define mis           map<ll , string>
#define rep(i,a,b)    for(ll  i=a;i<b;i++)
#define all(v)        v.begin(),v.end()
#define vsort(v)         sort(all(v))
#define pii           pair<ll ,ll >
#define vi            vector<ll >
#define vii           vector<pair<ll , ll > >
#define vs            vector<string>
#define sz(x)         (ll )x.size()
#define sl(x)          (ll )x.length()
#define hell          1000000007
#define bs            binary_search
#define mp            make_pair
#define sp(n)         setprecision(n)<<fixed
#define spl           " "
#define arr(a,n)        rep(i,0,n)cin>>a[i]
#define mod            998244353
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define M       10000001
    /*
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        std::cerr << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    */
     
//#define abc   cin
//#define qwe   cout
using namespace std;
     
     
ll fact(ll n) {
  if (n == 0 || n == 1)
    return 1;
  else
    return n * fact(n - 1);}
ll power(ll base,ll exp) {
  ll res=1;
  while(exp>0) {
    if(exp%2==1) res=((res)*(base));
      base=((base)*(base));
      exp/=2;}
  return res;}

ll n,k; 


int solve()
{
ll w;
cin>>n>>w;
ll we[n],val[n];
rep(i,0,n)
cin>>we[i]>>val[i];
ll dp[n+1][w+1];
rep(i,0,n+1)
rep(j,0,w+1)
dp[i][j]=0;
rep(i,1,n+1)
{
rep(j,0,w+1)
{

  dp[i][j]=dp[i-1][j];
  if(j>=we[i-1])
  {
    dp[i][j]=max(dp[i][j],dp[i-1][j-we[i-1]]+val[i-1]);
  }
}
}
ll ma=0;
rep(i,0,n+1)
rep(j,0,w+1)
ma=max(ma,dp[i][j]);
cout<<ma<<endl;


 return 0;
 }

     
signed main(){

  ios
  
  int test=1;   
  
 // cin>>test;

  while(test--){
    solve();}

  return 0;} 


Measured memory_bytes: 82508
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int i;
  int n = s.length();
  int chk = 0;
  for(i=0;i<=7;i++){
    if(s.substr(0,i)+s.substr(n-7+i)=="keyence")chk =1;
  }
  if(chk==1)cout<<"YES"<<endl;
  else cout <<"NO"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<long long> A;
	A.resize(N);
	for (int n = 0; n < N; n++)cin >> A[n];
	vector<vector<long long>> DP;
	DP.resize(N, vector<long long>(N, 0));
	if ((N - 1) % 2 == 0) {
		for (int n = 0; n < N; n++)DP[n][n] = A[n];
	}
	else {
		for (int n = 0; n < N; n++)DP[n][n] = -A[n];
	}
	for (int k = 1; k < N; k++) {
		for (int l = 0; l < N; l++) {
			int r = l + k;
			if (r >= N)continue;
			if ((N - r + l - 1) % 2 == 0) {
				DP[l][r] = max(DP[l + 1][r] + A[l], DP[l][r - 1] + A[r]);
			}
			else {
				DP[l][r] = min(DP[l + 1][r] - A[l], DP[l][r - 1] - A[r]);
			}
		}
	}
	cout << DP[0][N - 1] << endl;
	return 0;
}

Measured memory_bytes: 72192
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    ll x;
    cin >> x;

    ll tmp = x/500LL;
    ll tmp2 = x%500LL;
    ll tmp3 = tmp2/5LL;

    cout << 1000*tmp + 5*tmp3 << endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(void){
	int H = 0, W = 0;
	while (1){
		scanf("%d %d", &H, &W);

		if (H == 0 && W == 0){
			break;
		}

		for (int i = 0; i < H; i++){
			for (int j = 0; j < W; j++){
				if (i != 0 && j != 0 && i != H - 1 && j != W - 1){
					printf(".");
				}
				else{
					printf("#");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
}

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

int e;
const int max_e = 2000000;

signed main() {
	while (cin >> e && e > 0) {
		int ans = max_e;
		for (int z = 0; pow(z, 3) <= e; ++z) {
			for (int y = 0; y*y <= e - z*z*z; ++y) {
				int x = e - z*z*z - y*y;
				int eTemp = x + y + z;
				ans = min(ans, eTemp);
			}
		}
	cout << ans << endl;
	}
}





Measured memory_bytes: 3244
#include<iostream>
#include<sstream>
#include<ios>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<string>
#include<numeric>
#include<set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using vi = vector<int>;
using vl = vector<long>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
using vpii = vector<pii>;
using vpll = vector<pll>;

int main(){
  long N;
  cin >> N;
  vl a(N);
  rep(i, N) cin >> a[i];

  vl LIS(N, 200001);

  rep(i, N){
    if(LIS[0] > a[i]){
      LIS[0] = a[i];
    } else{
      auto itr = lower_bound(LIS.begin(), LIS.end(), a[i]);
      long ind = itr - LIS.begin();
      LIS[ind] = a[i];
    }
  }

  long length = 0;

  rep(i, N){
    if(LIS[i] != (i + 1)) break;
    length++;
  }

  if(length == 0) cout << -1 << endl;
  else cout << N - length << endl;
    
  return 0;
}

Measured memory_bytes: 3328
const main = (input) => {
  let [a, b, c, d] = input.trim().split(' ').map(Number)

  while (a>0 && c>0) {
    c -= b
    if (c <= 0) return console.log('Yes')
    a -= d
  }
  return console.log('No')
}

process.env.MYTEST ? test() : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 29512
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long ll;


int main()
{
	string str;
	cin>>str;
	for(int i = 0 ; i < str.length(); i++){
		if( i % 2 == 0){
			cout<<str[i];
		}
	}
	cout<<endl;
	return 0;
}



Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
 
using ll = long long;
const ll INF = LLONG_MAX - 100;
ll mod = 1e9 + 7;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;

class fact {
public:
	int fmod = 1e9+7;
	vector<int> fac, inv;
	fact (int n, int Mod = 1e9+7) {
		fmod = Mod;
		fac = vector<int>(n,0);
		inv = vector<int>(n,0);
		fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i-1] * i % fmod;
		for (int i = 0;i < n;i++) inv[i] = fact::POW(fac[i],fmod-2);
	}
	ll nCr(ll n, ll r) {return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;}
	ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;}
};
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}
bool isSqrt(ll a) {return pow(sqrt(a),2) == a ? 1 : 0;}
void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;}
void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;}
void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;}

vector<pair<int,int>> ans;
void add(int a,int b) {
    ans.pb({a,b});
}

bool solve() {
	int n; cin >> n;
    int tm = 1;
    if (n == 1) {
        cout << "No" << endl;
        return 0;
    }
    for (;tm <= n; tm *= 2) {
        if (tm == n) {
            cout << "No" << endl;
            return 0;
        }
    }
    tm /= 2;
    add(n+1,n+2);
    for (int i = 2;i < n; i += 2) {
        add(1,i);
        add(1,i+1);
        add(i,i+n+1);
        add(i+1,i+n);
    }
    if (n % 2 == 0) {
        add(n,tm);
        add(tm^(n+1),2*n);
    }
    cout << "Yes" << endl;
    for (auto&& a : ans) {
        cout << a.first << " " << a.second << endl;
    }
}

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


Measured memory_bytes: 6128
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
const int NR = 1005;
ifstream in ("date.in");

string s;
int main(){
    int i ;
            int sw = 0 ;
        cin >> s ;
        for ( i = 0 ; i < s.size() ; ++ i ) {
            if ( s[ i ] == 'C' ) sw = 1 ;

            if ( sw == 1 && s [ i ] == 'F' ){
                sw = 2  ;
                break;
                }
        }
    if ( sw == 2 )
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
from itertools import combinations
N, M, X = map(int, input().split())
C = []
A = []
for _ in range(N):
    tmp = list(map(int, input().split()))
    C.append(tmp[0])
    A.append(tmp[1:])
del tmp
costs = []
for i in range(1, N + 1):
    comb_idx = combinations(range(N), i)
    for indices in comb_idx:
        sub_A = [A[idx] for idx in indices]
        sub_C = [C[idx] for idx in indices]
        sum_sub = [0] * M
        for row in sub_A:
            for j, v in enumerate(row):
                sum_sub[j] += v
        if all(X <= v for v in sum_sub):
            costs.append(sum(sub_C))
if costs:
    print(min(costs))
else:
    print(-1)
    


Measured memory_bytes: 9268
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    string s;
    cin>>s;
    lli ans=0;
    char rec=s[0];
    for(lli i=1;i<s.size();i++){ 
        if(s[i]==rec){ 
            ans++;
            rec=(rec=='0'?'1':'0');
        }
        else{ 
            rec=s[i];
        }
    }
    out(ans);
}

Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int>v;
    f(n){
        int add;
        cin >> add;
        v.pb(add);
    }
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    if(v.size()==n){
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
//#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef pair<int,int> P;
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define lowbit(x) (x&-x)
const ll INF=0x3f3f3f3f;
const double EPS=1e-7;
const int N=3e5+10;
const ll mod=1e9+7;
const ll MOD=998244353;
inline ll read()  
{  ll f=1,x=0;char ch=getchar();
   for(;ch>'9'||ch<'0';ch=getchar())if(ch=='-') f=-1;
   for(;ch<='9'&&ch>='0';ch=getchar())x=(x<<3)+(x<<1)+(ch^48);
   return x*f;
}
ll n,m,k,ans;
int a[3005][3005];
ll dp[2][3005][4];
int main()
{  cin>>n>>m>>k;
   for(int i=1;i<=k;i++)
   {  int x,y,v;
      cin>>x>>y>>v;
      a[x][y]=v;
   }
   int t=0;
   for(int i=1;i<=n;i++)
   {  t=t^1;
      for(int j=1;j<=m;j++)
        {  ll temp=max(dp[t^1][j][0],max(dp[t^1][j][1],max(dp[t^1][j][2],dp[t^1][j][3])));
           ll v=a[i][j];
           dp[t][j][0]=max(dp[t][j-1][0],max(dp[t][j-1][0],temp));
           dp[t][j][1]=max(dp[t][j-1][1],max(dp[t][j-1][0]+v,temp+v));
           dp[t][j][2]=max(dp[t][j-1][2],dp[t][j-1][1]+v);
           dp[t][j][3]=max(dp[t][j-1][3],dp[t][j-1][2]+v);   
           //printf("%d ",a[i][j]); 
        }
      //printf("\n");
   }
   for(int i=0;i<=3;i++)ans=max(ans,dp[t][m][i]);
   cout<<ans;
}

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

const ll MOD = 1000000007;
const ll MAX = 3e5;

vector<ll> fac(MAX);
vector<ll> finv(MAX);

ll power_MOD(ll a, ll b){
  ll ans = 1;
  while(b > 0){
    if(b&1) ans = (ans * a) % MOD;
    a = (a * a) % MOD;
    b = (b >> 1);
  }
  return ans;
}

void comb_ini(){
  fac[0] = 1; fac[1] = 1;
  finv[0] = 1; finv[1] = 1;
  for(ll i = 2; i <= MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    finv[i] = finv[i - 1] * power_MOD(i, MOD - 2) % MOD;
  }
}

ll comb_MOD(ll n, ll r){
  if(n < r) return 0;
  if(n < 0 || r < 0) return 0;
  if(r == 0) return 1;
  return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

int main(){
  comb_ini();

  ll H, W, A, B; cin >> H >> W >> A >> B;
  ll ans = comb_MOD(H+W-2, H-1);
  ll sub = 0;
  
  for(int i = 0; i < B-1; i++){
    sub += (comb_MOD(H-A + i, i) * comb_MOD(A-2 + W-i-1, A-2)) % MOD;
    sub %= MOD;
  }
  sub += (comb_MOD(H-A + B-1, B-1) * comb_MOD(A-1 + W-B, A-1)) % MOD;
  sub %= MOD;
  ans -= sub;
  ans %= MOD;
  
  while(ans < 0){
    ans += MOD;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 4992
INF = 10**10

N,M = map(int,input().split())

key = [[]]#index調整のために一ついれとくわ
for i in range(M):
    a,b = map(int,input().split())
    c = list(map(int,input().split()))
    tmp=0
    for i in range(0,b,1):
        tmp += pow(2,c[i]-1)
    key.append([a,tmp])#key[2]で開けられる宝箱について表す。一つも開けられないなら0 一つ目だけ開けられるなら1　2:2 3:4 4:8

#DP[i][j] i個目までのなかで状態jにするために必要な値段の最小値（不可能なら INF）

DP = [[INF for i in range(0,pow(2,N),1)] for j in range(0,M+1,1)]
for i in range(0,M+1,1):
    DP[i][0]=0 #一つも開けていない状態には0円で到達可能

for i in range(0,M,1):
    cost,openable = key[i+1][0],key[i+1][1]


    for j in range(0,pow(2,N),1):
        if DP[i][j]!=INF:
            DP[i+1][j | openable] = min(DP[i+1][j | openable],DP[i][j]+cost) #買う
            DP[i+1][j] = min(DP[i+1][j],DP[i][j]) #買わない

print(DP[M][pow(2,N)-1] if DP[M][pow(2,N)-1]!=INF else -1)
    

Measured memory_bytes: 107276
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

ll c[51][51];

void comb_table(int n) {
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= i; ++j) {
            if (j == 0 || j == i) c[i][j] = 1LL;
            else c[i][j] = c[i-1][j-1] + c[i-1][j];
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, a, b;
    cin >> n >> a >> b;
    comb_table(n);
    vll v(n);
    rep(i, n) cin >> v[i];
    sort(v.rbegin(), v.rend());
    double mx = (double)accumulate(v.begin(), v.begin() + a, 0LL) / a;
    int cnt = 0;
    int x = 0;
    rep(i, n) {
        if (v[a-1] == v[i]) {
            cnt++;
            if (x == 0) x = i;
        }
    }
    ll ans = 0;
    if (v[0] == v[a-1]) {
        for (int k = a; k <= b; ++k) {
            ans += c[cnt][k];
        }
    } else {
        ans += c[cnt][a - x];
    }
    cout << fixed << setprecision(10) << mx << endl;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 100000;
const int INF = 19191919;
vector<int> G[N];

ll solve()
{
    int n,m;
    cin >>n >>m;

    vector<int> a(m),b(m);
    rep(i,m)
    {
        cin >>a[i] >>b[i];
        --a[i]; --b[i];
        G[a[i]].pb(b[i]);
        G[b[i]].pb(a[i]);
    }

    vector<int> d(n,INF);
    d[0] = 0;
    queue<int> que;
    que.push(0);
    while(!que.empty())
    {
        int v = que.front();
        que.pop();
        for(int e:G[v])
        {
            if(d[e] > d[v]+1)
            {
                d[e] = d[v]+1;
                que.push(e);
            }
        }
    }

    bool odd_loop = false;
    rep(i,m)
    {
        if(abs(d[a[i]]-d[b[i]])%2==0) odd_loop = true;
    }

    ll U = (ll)n*(n-1)/2;
    if(odd_loop) return U - m;

    ll ct[2]={};
    rep(i,n) ++ct[d[i]%2];
    return ct[0]*ct[1] - m;
}

int main()
{
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 7040
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000

int main(void){
    
    int n, m; cin >> n >> m;
    int p[100010];
    for(int i = 0; i < m; i++){
        cin >> p[i];
    }
    long long array[100010] = {};
    for(int i = 0; i < m-1; i++){
        if(p[i] < p[i+1]){
            for(int j = p[i]; j < p[i+1]; j++){
                array[j]++;
            }
        }else{
            for(int j = p[i+1]; j < p[i]; j++){
                array[j]++;
            }
        }
    }

    
    long long ans = 0;

    for(int i = 1; i < n; i++){
        long long a, b, c; cin >> a >> b >> c;
        ans += min(a*array[i], c + b*array[i]);
    }
    cout << ans << endl;
    return 0;
}

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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    int D,X; cin >> D >> X;

    int ans = X;
    REP(i,N){
        int a; cin >> a;
        ans += (D-1)/a + 1;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
	int N,A;
	cin>>N>>A;
	vector<int>arr;
	int tmp;
	for(int i=0;i<N;++i){
		cin>>tmp;
		arr.push_back(tmp-A);
	}
	sort(arr.begin(),arr.end());
	
	vector<vector<long> >DParr;
	vector<long>tmparr;
	for(int i=0;i<N;++i){
		tmparr.push_back(0);
	}
	for(int i=0;i<100*N;++i){
		DParr.push_back(tmparr);
	}
	for(int i=0;i<N;++i){
		if(i==0){
			for(int j=0;j<100*N;++j){
				if(arr[i]==j-50*N)DParr[j][i]++;
				if(j-50*N==0)DParr[j][i]++;
			}
		}
		else{
			for(int j=0;j<100*N;++j){
				if(DParr[j][i-1]!=0){
					DParr[j+arr[i]][i]+=DParr[j][i-1];
					DParr[j][i]+=DParr[j][i-1];
				}
			}
		}
	}
	/*
	for(int j=0;j<100;++j){
		for(int i=0;i<N;++i){
			cout<<DParr[j][i]<<" ";
		}
		cout<<endl;
	}
	cout<<endl;
	*/
	cout<<DParr[50*N][N-1]-1<<endl;
}


Measured memory_bytes: 2432
import sys
import re
import math
import collections
import decimal
import bisect

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    a, b, c = ns()
    tmp = decimal.Decimal(a).sqrt() + decimal.Decimal(b).sqrt() - decimal.Decimal(c).sqrt()
    print("Yes" if tmp < 0 else "No")


if __name__ == '__main__':
    main()


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

const int INF = 1e9;
const long long LINF = 1e18;

void solve(void){
    int N;
    cin >> N;
    vector<vector<int>> G(N);
    for(int i = 0; i < N-1; i++){
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    queue<int> que;
    vector<int> fennec(N, INF), sunuke(N, INF);
    fennec[0] = 0;
    que.push(0);
    
    while(!que.empty()){
        int cur = que.front();
        que.pop();
        for(int next : G[cur]){
            if(fennec[next] == INF){
                fennec[next] = fennec[cur] + 1;
                que.push(next);
            }
        }
    }

    sunuke[N-1] = 0;
    que.push(N-1);
    while(!que.empty()){
        int cur = que.front();
        que.pop();
        for(int next : G[cur]){
            if(sunuke[next] == INF){
                sunuke[next] = sunuke[cur] + 1;
                que.push(next);
            }
        }
    }

    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(fennec[i] <= sunuke[i]) cnt++;
        else cnt--;
    }
    if(cnt > 0) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
}
int main(){

    solve();

    return 0;
}

Measured memory_bytes: 6528
#include <stdio.h>

int main()
{
  int a,b;
  scanf("%d %d",&a,&b);
  if(b % a == 0){
    printf("%d\n",a + b);
    return 0;
  }
  else{
    printf("%d\n",b - a);
    return 0;
  }
}

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

int main(){
    int n;
    cin >> n;
    
    scanf("%d", &n);
    int tmp = n;
    int b = 0;

    while (tmp > 0) {
            b += tmp % 10;
            tmp /= 10;
    }
    if(n % b == 0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#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 ll long long
#define pb push_back

// スマートすぎる回答
// https://atcoder.jp/contests/abc136/submissions/10368936

void print_lr(vector<int> lr){
  for(int i: lr){
    cout << i << " ";
  }
  cout << endl;
}

vector<pair<char, int> > RunLengthEncoding(string s){
  char c = s[0];
  int cnt = 0;
  vector<pair<char, int> > rle;
  for(char i: s){
    if(c==i){
      cnt++;
    } else {
      rle.push_back(make_pair(c, cnt));
      c = i;
      cnt = 1;
    }
  }
  rle.push_back(make_pair(c, cnt));
  // デバッグ用
  // for(pair<char, int> p : rle){
  //   cout << p.first << " " << p.second << endl;
  // }
  return rle;
}

vector<int> gather(string s){
  int N = s.size();
  vector<int> x(N, 0);
  vector<pair<char, int> > rle = RunLengthEncoding(s);
  int num = rle[0].second - 1, j = 0;
  int r_num, l_num, ave, tmp, sum;
  rep(i, N){
    if(i == num){
      r_num = rle[j].second;
      l_num = rle[j+1].second;
      ave = (r_num + l_num)/2;
      sum = r_num+l_num;
      if(sum%2==0) { // 合計が2で割れる場合
        r_num = ave;
        l_num = ave;
      } else { // 合計が2で割れない場合
          r_num = ave + abs(sum - r_num+1)%2;
          l_num = ave + abs(sum - l_num+1)%2;
      }
      x[i] = r_num;
      x[i+1] = l_num;
      i++; // 0を代入しないで欲しいので二つ進める
      if (j + 2 < rle.size()){
        num += rle[j+1].second + rle[j+2].second;
        j += 2;
      }
    } else {
      x[i] = 0;
    }
  }
  return x;
}

int main() {
  string s;
  cin >> s;
  int N = s.size();
  vector<int> lr(N, 1);
  
  lr = gather(s);
  print_lr(lr);
}


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

using namespace std;

int main() 
{
    string a, b;
    cin >> a >> b;
    bool check = false;
    for (int i = 0; i < a.length(); i++)
    {
        if (a[i] == b[i])
        {
            check = true;
        }
        else
        {
            check = false;
            break;
        }
    }
    if (check)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}


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

using namespace std;

inline void print_sharps(int w) { 
    for (int i = 0; i < w; i++) {
      printf("#");
    }
    printf("\n");
}

int main() {
  int h, w;
  scanf("%d %d", &h, &w);
  while (h && w) {
    print_sharps(w);
    for (int i = 0; i < h - 2; i++) {
      printf("#");
      for (int j = 1; j < w - 1; j++) {
        printf(".");
      } 
      printf("#\n");
    }
    print_sharps(w);
    printf("\n");
    scanf("%d %d", &h, &w);
  }
  return 0;
}



Measured memory_bytes: 3124
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

const int MAX = 100000;
const int INF = 1 << 30;

int main(){
    int N;
    int A[MAX];
    int cnt = 0;
    int m = INF;
    long long sum = 0;

    cin >> N;
    for(int i = 0;i < N;i++){
        cin >> A[i];
        if(A[i] < 0)cnt++;
        m = min(m,abs(A[i]));
        sum += abs(A[i]);
    }

    if(cnt % 2)cout << sum - m * 2 << endl;
    else cout << sum << endl;

    return 0;
}

Measured memory_bytes: 640