akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <cmath>
#include <math.h>
#include <ctime>
#include <cstring>
#include <climits>
#include <sstream>
#include <array>
#include <tuple>
#include <set>
#include <iterator>
#include <cstdio>
#include <string>
#include <stack>
#include <valarray>
#include <utility>
#include <iomanip>
#include <list>
#include <numeric>
#include <regex>
#include <map>
#include <queue>
#include <deque>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll          long long
#define PI          3.1415926535
#define pb          push_back
#define ins         insert
#define INF         LLONG_MAX
#define mk          make_pair
#define lb(v,x)     lower_bound(all(v),x)
#define ub(v,x)     upper_bound(all(v),x)
#define ff          first
#define ss          second
#define rev         reverse
#define uset        unordered_set
#define umap        unordered_map
#define endl        "\n"
#define max3(x,y,z)  max(x,max(y,z))
#define min3(x,y,z)  min(x,min(y,z))
#define sz(a)       (ll)a.size()
#define double      long double
#define minpq       priority_queue <ll,vector<ll>,greater<ll> > 
#define fill(x,y)   memset(x,y,sizeof(x))
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define MOD         1000000007 //1e9+7
#define bp(n)       __builtin_popcountll(n)
#define mxt(a)      *(max_element(a.begin(),a.end()))
#define mnt(a)      *(min_element(a.begin(),a.end())
#define unique_sort(c) (sort(all(c)), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define rep(i, a, b) for(ll i = (a); i<= (b); ++i)
#define trav(a, x) 	 for(auto &a : x)
#define re(i,n)      for(ll i = 0; i < n; ++i) 
const ll N = 4e5 + 7;
typedef pair<ll,ll>   pii;
typedef vector<pii>   vpii;
typedef vector<ll>    vll;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x);y=y>>1;x=(x*x);}return res;}
template<typename T> T gcd(T a,T b){ if(a==0) return b; return gcd(b%a,a); }
template<typename T> T powm(T a,T b, ll m){T cnt=1; while(b>0){ if(b%2==1) cnt=(cnt*a)%m; b/=2; a=(a*a)%m; }return cnt%m;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
ll sqr(ll x) { return x * x;}
// always use 1ll*ans to avoid signed integer overflow; 
void prec(){

}

void solve(){
	int n,a,b,c;cin>>n;
	int dp[n+2][4];
	fill(dp,-1);
	dp[0][1]=0,dp[0][2]=0,dp[0][3]=0;
	rep(i,1,n){
		cin>>a>>b>>c;
		dp[i][1]=a+max(dp[i-1][2],dp[i-1][3]);
		dp[i][2]=b+max(dp[i-1][1],dp[i-1][3]);
		dp[i][3]=c+max(dp[i-1][2],dp[i-1][1]);
	}
	cout<<max3(dp[n][1],dp[n][2],dp[n][3])<<endl;
}

int main()
{
    ios;
    int tc=1;
    //cin>>tc;
    prec();
    while(tc--)
    	solve();
    return 0; 
}


Measured memory_bytes: 1792
program sample
    implicit none
    integer::N, L, S, i, aji
    read(*,*) N, L
    S = N*L + N*(N+1)/2 - N

    do i = 1, N
        aji = L + i - 1
        if(aji >= 0) then
            exit
        end if
    end do
    write(*,*) S - aji

    stop

end program sample

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

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

    inf = 10**4*N
    dp = [inf]*N
    dp[0] = 0
    for i,h in enumerate(H):
        if i == 0:
            continue
        m = max(0, i-K)
        # 普通なら j=i~m のループを回すが、高速化のためこうする（配列アクセスを減らす）
        dp[i] = min([dpj + abs(h - hj) for dpj, hj in zip(dp[m:i], H[m:i])])
    print(dp[N-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 14104
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
    ll L, R;
    cin >> L >> R;
    
    ll md = 2018;
    if (R-L > 2019) {
        md = 0;
    } else {
        for(ll l=L; l<R; l++) {
            for(ll r=l+1; r<=R; r++) {
                ll lr_mod = (l*r) % 2019;
                md = min(md, lr_mod);
                if (md == 0) {
                    break;
                }
            }
        }
    }

    cout << md << endl;
    
    return 0;
}

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

#dp = [float("inf")] * (10**4 + 1)
dp = [10**9] * n

dp[0] = 0
dp[1] = abs(h_L[0]-h_L[1])

for i in range(2,n):
    #dp[i]
    # 1
    tmp1 = dp[i-1] + abs(h_L[i-1] - h_L[i])
    #dp[i] = min(dp[i],tmp1)
    # 2
    tmp2 = dp[i-2] + abs(h_L[i-2] - h_L[i])
    dp[i] = min(dp[i],tmp1,tmp2)
#print(dp)
print(dp[n-1])

Measured memory_bytes: 52208
#include <iostream>
#include <cmath>
#define EPS 1e-10
using namespace std;

int main() {
  int n;
  double x1, y1, x2, y2, x3, y3, x4, y4;
  cin >> n;
  while (n--) {
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
    if (fabs((x2 - x1) * (y4 - y3) - (x4 - x3) * (y2 - y1)) < EPS) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}


Measured memory_bytes: 3216
import java.io.*;
import java.security.acl.Group;
import java.util.*;

//@2001  Ý¾­¶
public class Main {

	static class Bar implements Comparable<Bar> {
		int h;
		int p;
		int q;
		public Bar(int h, int p, int q) {
			this.h = h;
			this.p = p;
			this.q = q;
		}
		@Override
		public int compareTo(Bar o) { // ~
			return o.h - h;
		}
	}
	
	public static void main(String[] args) throws IOException {
		
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

		
		for(int loop = 0;; loop++) {

			List<Bar> list = new ArrayList<Bar>();

			String s = reader.readLine();
			String[] sp = s.split(" ");
			int N = Integer.parseInt(sp[0]);
			int M = Integer.parseInt(sp[1]);
			int A = Integer.parseInt(sp[2]);
			if (N == 0)
				break;

			for(int i = 0; i < M; i++) {
				s = reader.readLine();
				sp = s.split(" ");
				int h = Integer.parseInt(sp[0]);
				int p = Integer.parseInt(sp[1]);
				int q = Integer.parseInt(sp[2]);
				
				Bar bar = new Bar(h, p, q);
				list.add(bar);
			}
			
			// ~É\[g
			Collections.sort(list);
			
			// »ÝÊu
			int pos = A;
			
			for(int i = 0; i < list.size(); i++) {
				Bar bar = list.get(i);
				if (pos == bar.p) {
					pos = bar.q;
				}
				else if (pos == bar.q) {
						pos = bar.p;
				}
			}
			
			System.out.printf("%d\n", pos);
				
		}		
		
		reader.close();
	}

}

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

void warshal_flotd(int n,vector<vector<int> > &d){
    rep(k,n){
        rep(i,n){
            rep(j,n){
                d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
}

int main(){
    int h,w; cin >> h >> w;
    vector<vector<int> > c(10,vector<int>(10));
    vector<vector<int> > A(h,vector<int>(w));
    rep(i,10) rep(j,10) cin >> c[i][j];
    rep(i,h) rep(j,w) cin >> A[i][j];
    warshal_flotd(10,c);
    ll ans = 0;
    rep(i,h){
        rep(j,w){
            int a = A[i][j];
            if(a==-1) continue;
            ans += c[a][1];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in1(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in1(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    int N;
    in1(N);

    vll p(N);
    inN(p, N);

    ll q = 0;
    ll sum = 0;
    rep(i, N)
    {
        sum += p[i];
        chmax(q, p[i]);
    }

    sum -= (q / 2);

    outl(sum);

    return 0;
}


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

//ポインタ渡しによる解法

void swap( int* a, int* b );

int main(){

 int a, b, c;

 cin >> a >> b >> c;

 if( a > b )
  swap( &a, &b );
 if( b > c )
  swap( &b, &c );

 if( a > b )
  swap( &a, &b );

 cout << a << " " << b << " " << c << endl;

 return 0;

}

void swap( int* a, int* b ){

  int temp = *a;
  *a = *b;
  *b = temp;

}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n;i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b;i++)
#define repv(x, arr) for (auto& x:arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a,b) make_pair(a,b)
#define op(i) cout << (i) << endl;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const ll mod = 1e9 + 7;


int main(){
    int N;
    cin >> N;
    map<int, int> cnt;
    int a;
    rep(i,N){
        cin >> a;
        cnt[a]++;
    }
    ll ans = 1;
    if (N%2==0){
        rep(i,N){
            if (i%2==0){
                if (cnt[i]!=0){
                    cout << 0 << endl;
                    return 0;
                }
            }
            else{
                if (cnt[i] != 2){
                    cout << 0 << endl;
                    return 0;
                }
                ans = (ans * 2) % mod;
            }
        }
    }
    else{
        rep(i,N){
            if (i==0){
                if (cnt[i]!=1){
                    cout << 0 << endl;
                    return 0;
                }
            }
            else if(i%2==0){
                if (cnt[i]!=2){
                    cout << 0 << endl;
                    return 0;
                }
                ans = (ans * 2) % mod;
            }
            else{
                if (cnt[i]!=0){
                    cout << 0 << endl;
                    return 0;
                }
            }
        }
    }
    cout << ans << endl;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long



int32_t main()
{
    IOS;
    int t=1;
    // cin>>t;
    while(t--)
    {
        int k;
        cin>>k;
        if(k%2==0||k%5==0){
            cout<<-1;
            return 0;
        }
        int n=0,ans=0;
        for (int i = 1; i <= k; ++i)
        {
            n=(n*10+7)%k;
            if(n==0){
                cout<<i;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3648
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

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

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

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

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

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

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

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

fn main() {
  input! {
    n: usize,
    a: [i64; n],
  }
  let count_neg = a.iter().filter(|&&x| x < 0).count();
  let mut abs: Vec<_> = a.into_iter().map(|x| x.abs()).collect();
  let sum: i64 = abs.iter().sum();
  let ans = if count_neg % 2 == 0 {
    sum
  } else {
    abs.sort();
    sum - abs[0] * 2
  };

  println!("{}", ans);
}


Measured memory_bytes: 8444
#include <stdio.h>

int main () {
    int n, T, c, t;
    scanf("%d %d", &n, &T);
    
    int smallest = -1;
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &c, &t);
        if (t <= T && (smallest == -1 || c < smallest)) {
            smallest = c;
        }
    }

    if (smallest == -1) {
        printf("TLE\n");
    } else {
        printf("%d\n", smallest);
    }

    return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

int N;
vector<int> D;

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

    cin >> N;
    D.resize(N);
    REP(i, N) {
        cin >> D[i];
    }

    ll ans = 0;
    REP(i, N) {
        REP(j, N) {
            if(i == j) { continue; }
            ans += D[i] * D[j];
        }
    }

    printf("%lld\n", ans/ 2);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <set>
#include <cmath>
#include <bits/stdc++.h>
#include <limits>

#define MOD 1000000007

using namespace std;

int main(void){
    // Your code here!
    int n, max_count = 0;
    string s;
    
    cin >> n;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        int count = 0;
        bool exists[26] = {};
        bool counted[26] = {};
        for(int j = 0; j < i; j++){
            exists[s[j]-'a'] = true;
        }
        for(int j = i; j < s.size(); j++){
            if(exists[s[j]-'a'] && !counted[s[j]-'a']){
                count++;
                counted[s[j]-'a'] = true;
            }
        }
        max_count = max(max_count, count);
    }
    
    cout << max_count << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int a;
	int b;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int j = 0;
	a = A[0];
	b = A[0];
	for (int i = 0; i < N; i++) {
		while(true) {
			if (j == N - 1)break;
			if (a + A[j + 1] == (b ^ A[j + 1])) {
				j++;
				a += A[j];
				b ^= A[j];
			}
			else {
				break;
			}
		}
		//cerr << i << " " << j << endl;
		//cerr << a << " " << b << endl;
		res += j - i + 1;
		a -= A[i];
		b ^= A[i];
	}
	cout << res << endl;
}

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

int main(){
    //card
    vector<int> card(9);
    for(int i=0; i<9; i++){
        cin >> card.at(i);
    }
    
    //n, numbers
    int n, num;
    cin >> n;;
    //check
    for(int i=0; i<n; i++){
        cin >> num;
        for(int j=0; j<9; j++){
            if(num == card.at(j)){
                card.at(j) = 0;
            }
            
        }
    }
    string ans = "No";
    for(int i=0; i<3; i++){
        //line
        if(card.at(3*i)==card.at(3*i+1)&&card.at(3*i+1)==card.at(3*i+2)){
            ans = "Yes";
            break;
        }
        //column
        if(card.at(i)==card.at(i+3)&&card.at(i+3)==card.at(i+6)){
            ans = "Yes";
            break;
        }
        //cross
        if(card.at(0)==card.at(4)&&card.at(4)==card.at(8)){
            ans = "Yes";
            break;
        }
        if(card.at(2)==card.at(4)&&card.at(4)==card.at(6)){
            ans = "Yes";
            break;
        }
    }
    /*for(int i=0; i<9; i++){
        cout << card.at(i) << endl;
    }
    */
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pii pair<int,int>
#define uu first
#define vv second
using namespace std;
int h,w,k,x11,y11,x2,y2;
vector<vector<char> > a ;
vector<vector<int> > vis,dist;
int dx[]={-1,+1,0,0};
int dy[]={0,0,-1,+1};
void bfs(int sx,int sy)
{
    queue<pii>q;
    q.push(pii(sx,sy));
    vis[sx][sy]=1;
    dist[sx][sy]=0;
    while(!q.empty()){
        pii top=q.front();
        q.pop();
        int x=top.uu;
        int y=top.vv;
        for(int i=0;i<4;i++){
            for(int len=1;len<=k;len++){
                int nx=x+len*dx[i];
                int ny=y+len*dy[i];
                if(nx<1 || nx>h || ny<1 || ny>w) break;
                if(a[nx][ny]=='@') break;
                if(vis[nx][ny] && dist[nx][ny]< dist[x][y]+1) break;
                if(vis[nx][ny]) continue;
                vis[nx][ny]=1;
                dist[nx][ny]=dist[x][y]+1;
                q.push(pii(nx,ny));
            }
        }
    }
    //return dist[x2][y2];
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    char ch;
    cin>>h>>w>>k;
    cin>>x11>>y11>>x2>>y2;
    a= vector<vector<char> > (h+1, vector<char> (w+1));
    vis=vector<vector<int> > (h+1, vector<int> (w+1,0));
    dist=vector<vector<int> > (h+1, vector<int> (w+1,0));
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin >> a[i][j];
            //scanf(" %c",&ch);
            //a[i][j]=ch;
        }
    }
    bfs(x11,y11);
    //cout<<bfs(x11,y11)<<endl;
    if(vis[x2][y2]==0){
        cout<<-1<<endl;
    }
    else{
        cout<<dist[x2][y2]<<endl;
    }
    return 0;
}


Measured memory_bytes: 24752
# 配るDP
# Hは1-index
# PyPyじゃないと厳しい。
# 二重for loop
import sys

input = sys.stdin.readline
n, k = map(int, input().split())
H = [0] + list(map(int, input().split()))
dp = [10 ** 10] * (n + 1)
dp[1] = 0
for i in range(1, n):
    for j in range(1, k + 1):
        if i + j <= n:
            dp[i + j] = min(dp[i + j], dp[i] + abs(H[i + j] - H[i]))
print(dp[n])


Measured memory_bytes: 52956
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

int H, W, c[10][10];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> H >> W;
    ll ans = 0;
    rep(i, 0, 10) rep(j, 0, 10) cin >> c[i][j];
    rep(k, 0, 10) rep(i, 0, 10) rep(j, 0, 10) {
      c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
    }
    rep(i, 0, H) rep(j, 0, W) {
      int a; cin >> a;
      if (a == -1) continue;
      ans += c[a][1];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
///#define int long long
#define ll long long
#define vi vector <int>
#define vii vector <pair<int,int> >
#define rep(i,a,b) for (int i=a;i<b;i++)
#define repD(i,a,b) for (int i=a;i>b;i--)
#define pb push_back
#define pii pair <int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define PI 3.14159265359
 
#define deb(x) {x}
#ifndef local
	#define deb(x) ;
#endif
///----------------------------------------------------------------------------------

int m,d;

void solve()
{
	cin>>m>>d;
	int ans=0,d10,d1;
	rep(i,1,m+1)rep(j,1,d+1)
	{
		d10=j/10;
		d1=j%10;
		
		if (d10>1&&d1>1&&d10*d1==i)ans++;
	}
	cout<<ans<<"\n";
	
}

signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
 	
 	#ifdef local
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    clock_t qwertyuiop = clock();
    #endif
 
 	int t=1;
    //cin>>t;
    
    rep(a,0,t)
    {
        ///cout<<"Case #"<<a+1<<": ";
        solve();
	}
	
    #ifdef local
    {qwertyuiop = clock() - qwertyuiop;double time_taken = ((double)qwertyuiop)/CLOCKS_PER_SEC;cerr<<fixed<<setprecision(5)<<"\n\nTime Taken : "<<time_taken<<" seconds\n";}
	#endif
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
void insertionsort(int *A, int N) {
  int v, i, j, k;
  for(i = 1; i <= N - 1; i++) {
	v = A[i];
	j = i - 1;
	while(j >= 0 && A[j] > v) {
	  A[j + 1] = A[j];
	  j--;
	}
	A[j + 1] = v;

	for(k = 0; k < N; k++) {
	  cout << A[k];
	  if(k < N - 1) {
		cout << " ";
	  }
	}
	cout << endl;
  }
}
int main() {
  int i, N, num;
  int A[1000];
  cin >> N;
  for(i = 0; i < N; i++) {
	cin >> num;
	A[i] = num;
  }
  for(i = 0; i < N; i++) {
	cout << A[i];
	if(i < N - 1) {
	  cout << " ";
	}
  }
  cout << endl;
  insertionsort(A, N);
  return 0;
}

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

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] s = new int[N];
            for (int i = 0; i < N; i++) {
                s[i] = in.nextInt();
            }

            int[] dp = new int[10101];
            Arrays.fill(dp, -1);
            dp[0] = 0;
            for (int si = 0; si < N; si++) {
                for (int i = 10000; i >= 0; i--) {
                    if (dp[i] < 0) {
                        continue;
                    }
                    dp[i + s[si]] = 0;
                }
            }

            int max = 0;
            for (int i = 0; i < dp.length; i++) {
                if (dp[i] < 0) {
                    continue;
                }
                max = Math.max(max, i % 10 == 0 ? 0 : i);
            }

            System.out.println(max);
        }
    }
}


Measured memory_bytes: 27564
#include<stdio.h>

int main() {
   int S;
   scanf("%d", &S);
   int a = S / 100;
   int b = S % 100;
   if(b <= 12 && b > 0) {
      if(a <= 12 && a > 0) {
         printf("AMBIGUOUS");
      } else {
         printf("YYMM");
      }
   } else {
      if(a <= 12 && a > 0) {
         printf("MMYY");
      } else {
         printf("NA");
      }
   }
}


Measured memory_bytes: 1728
#include <cmath>
#include <cstdio>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <map>
#include <stdio.h>
#include <functional>
#include <chrono>
#include <random>
#include <time.h>
using namespace std;

#define rep(i,s,n) for(ll i=s;i<(n);++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MAX_INF = 9223372036854775807;
//constexpr ll MOD = (1e9 + 7);
constexpr ll MOD = (998244353);

using vl = vector<ll>;
using vvl = vector<vector<ll>>;

template<class T>
vector<vector<T>> vvt(T init, ll m, ll n) {
	vector<vector<T>> ans = vector<vector<T>>(m, vector<T>(n, init));
	return move(ans);
}

template<class T>
vector<T> vt(T init, ll n) {
	vector<T> ans = vector<T>(n, init);
	return move(ans);
}

template<class T>
T maxVec(vector<T>& v) {
	T ans = -INF;
	rep(i, 0, v.size()) {
		ans = max(ans, v[i]);
	}
	return ans;
}

// 素数判定
bool judge(ll n) {
	for (ll i = 2; i * i <= n; i++) if (n %= i)return false;
	return true;
}


template <class C>
void print(const C & c, std::ostream & os = std::cout)
{
	std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, ", "));
	os << std::endl;
}
/*
ll count(ll n,ll r) {
	ll ans = 0,check = 1;
	rep(i,0, r) {
		if ((n & check) > 0) {
			ans++;
		}
		check = check << 1;
	}
	return ans;
}
*/
bool sortreverse(ll a, ll b) {
	return a > b;
}


ll kiriage(ll a, ll b) {
	if (a % b == 0)return a / b;
	return a / b + 1;
}

void warshall_floyd(ll v_num,vector<vector<long long>> &d) {
	for (long long k = 0; k < v_num; k++) {       // 経由する頂点
		for (long long i = 0; i < v_num; i++) {    // 始点
			for (long long j = 0; j < v_num; j++) {  // 終点
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}

uniform_real_distribution<> dist(0.0, 1.0);

float judge(float p, mt19937& engine) {
	float f = dist(engine);
	return p >= f;
}

float prob(float delta, float tmp) {
	return exp(delta / tmp);
}


int cost(vector<vector<int>>& s, vector<int>& c, vector<int>& ls) {
	int result = 0;
	vector<int> prev(26,-1);
	rep(i, 0, ls.size()) {
		prev[ls[i]] = i;
		result += s[i][ls[i]];
		rep(j, 0, 26) {
			result -= c[j] * (i - prev[j]);
		}
	}
	return result;
}


int main() {
	// ↓この２行が追加部分
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	random_device seed_gen;
	mt19937 engine(seed_gen());

	int d;
	cin >> d;
	int con = 0;
	vector<int> c(26);
	vector<vector<int>> s(d, vector<int>(26));
	rep(i, 0, 26) {
		cin >> c[i];
	}
	rep(i, 0, d) {
		rep(j, 0, 26) {
			cin >> s[i][j];
		}
	}

	// 初期化
	vector<int> ls(d);
	rep(i, 0, d) {
		ls[i] = con;
		++con;
		con %= 26;
	}
	
	
	int now_cost = cost(s,c,ls);

	rep(i, 0, 10) {
		rep(j, 0, d) {
			int ra = rand() % 24 + 1,val = ls[j];
			ls[j] = (ls[j] + ra) % 26;
			int cos = cost(s, c, ls);
			if (cos > now_cost) {
				now_cost = cos;
			}
			else {
				ls[j] = val;
			}
		}
	}

	rep(i, 0, d) {
		printf("%d\n", ls[i] + 1);
	}
}

Measured memory_bytes: 3868
while True:
    n=int(input())
    if n==0:break
    l=list(map(str,input().split()))
    d=dict()
    for i in range(26):
        d[chr(i+ord("A"))]=0
    for i in range(n):
        d[l[i]]+=1
        a=max(d.values())
        l2=sorted(list(d.values()),reverse=True)
        b=l2[1]
        if a-b>n-i-1:
            k=i+1
            break
    ans=0
    for i in range(26):
        if d[chr(i+ord("A"))]==a:
            if ans==0:
                ans=chr(i+ord("A"))
            else:
                ans=-1
                break
    if ans==-1:
        print("TIE")
    else:
        print(ans,k)


    
    
        


Measured memory_bytes: 5620
//84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 200005
#define maxK 20
#define oo 1000000007
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

struct segment{
    int l, r; ii pos; int val;
    bool inline operator < (const segment &o) const {
        return val < o.val;
    }
};

int n, k, a[2][maxN], b[maxN], bmin[2][maxK][maxN];
vector<int> ans;

int minPos(int r, int i, int j) {return (a[r][i] > a[r][j]) ? j : i;}

int query(int p, int l, int r) {
    int i = log2(r-l+1);
    return minPos(p, bmin[p][i][l], bmin[p][i][r-(1<<i)+1]);
}

int query(int l, int r) {return query(l%2, l, r);}

ii findPair(int l, int r) {
    int p1 = query(l, r);
    int p2 = query(p1+1, r);
    return mp(p1, p2);
}

segment get(int l, int r) {
    ii p = findPair(l, r);
    return {l, r, p, b[p.ff]};
}

int main () {
    scanf("%d", &n);
    fto(p, 0, 1) fto(i, 0, n-1) a[p][i] = oo;
    fto(i, 0, n-1) {
        scanf("%d", &b[i]);
        a[i%2][i] = b[i];
    }
    k = log2(n);

    fto(p, 0, 1) {
        fto(j, 0, n-1) bmin[p][0][j] = j;
        fto(i, 1, k) {
            fto(j, 0, n-(1<<i)) bmin[p][i][j] = minPos(p, bmin[p][i-1][j], bmin[p][i-1][j+(1<<(i-1))]);
        }
    }

    multiset<segment> s;
    s.insert(get(0, n-1));
    while (!s.empty()) {
        int l = s.begin()->l, r = s.begin()->r, x = s.begin()->pos.ff, y = s.begin()->pos.ss;
        s.erase(s.begin());
        ans.pb(b[x]); ans.pb(b[y]);
        if (x > l) s.insert(get(l, x-1));
        if (y-x > 1) s.insert(get(x+1, y-1));
        if (y < r) s.insert(get(y+1, r));
    }

    for(int x: ans) printf("%d ", x);

    return 0;
}


Measured memory_bytes: 38388
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

temp = [0 for i in range(N)]

for i in range(N):
    temp[i] = T - H[i] * 0.006

dist = 10000000
num = 0
for i in range(N):
    if dist > abs(temp[i] - A):
        dist = abs(temp[i] - A)
        num = i

print(num+1)


Measured memory_bytes: 3064
n,m=map(int,input().split())
x=list(map(int,input().split()))
x=sorted(x)

if n>=m:
    print(0)
    exit()

l=[]
for i in range(m-1):
    l+=[x[i+1]-x[i]]

l=sorted(l)
print(sum(l)-sum(l[-n+1:]) if n!=1 else sum(l))


Measured memory_bytes: 13960
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int ddx[6]={0,1,0,-1,1,-1},ddy[6]={-1,0,1,0,1,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


int n;
int h,w;
char xray[55][55];
int t;

int main(){
	cin>>t;
	for(int qu=0;qu<t;qu++){
		cin>>h>>w;
		REP(i,h)
			REP(j,w)
			cin>>xray[i][j];
		
		for(int i=0;i<7;i++){
			for(char c='A';c<='Z';c++){
				int y1=-1,y2=-1,x1=100,x2=-1;
				REP(k,h){
					REP(l,w){
						if(xray[k][l]==c){
							if(y1==-1)y1=k;
							y2=k;
							x1=min(x1,l);
							x2=max(x2,l);
						}
					}
				}
				if(y1==-1)continue;
				int flag=1;
				for(int k=y1;k<y2+1;k++){
					for(int l=x1;l<x2+1;l++){
						if(xray[k][l]!=c&&xray[k][l]!='0'){
							flag=0;
						}
					}
				}
				//if(c=='W')cout<<x1<<" "<<x2<<" "<<y1<<" "<<y2<<endl<<i<<endl;;
				if(flag){
					REP(k,h){
						REP(l,w){
							if(xray[k][l]==c){
								xray[k][l]='0';
							}
						}
					}
					break;
				}
			}
		}
		int ans=1;
		REP(i,h)
			REP(j,w)
				if(xray[i][j]!='.'&&xray[i][j]!='0')ans=0;
		if(ans)cout<<"SAFE"<<endl;
		else cout<<"SUSPICIOUS"<<endl;
	}
	return 0;
}
				


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

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

  if ((a % 2) == 0 || (b % 2) == 0) {
    cout << "Even" << endl;
  }

  else if ((a % 2) == 0 && (b % 2) == 0) {
    cout << "Even" << endl;
  }

  else {
    cout << "Odd" << endl;
  }
}


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

template<typename T, typename E, typename F, typename G, typename H>
class LazySegmentTree {
  int n, height;
  F f; G g; H h; const T ti; const E ei;
  vector<T> dat; vector<E> laz; vector<int> highest;

  void propagate(int k) {
    if(laz[k] != ei) {
      laz[2*k] = h(laz[2*k],laz[k]); laz[2*k+1] = h(laz[2*k+1],laz[k]);
      dat[k] = g(dat[k],laz[k],n/highest[k]);
      laz[k] = ei;
    }
  }
  inline void recalc(int k) {
    while(k >>= 1) dat[k] = f(g(dat[2*k],laz[2*k],n/highest[2*k]),g(dat[2*k+1],laz[2*k+1],n/highest[2*k+1]));
  }
  inline void thrust(int k) {
    for(int i = height; i > 0; i--) propagate(k >> i);
  }
public:
  LazySegmentTree(int _n, F f, G g, H h, T ti, E ei): f(f), g(g), h(h), ti(ti), ei(ei) {
    n = 1; height = 0;
    while(n < _n) n <<= 1, height++;
    dat.assign(2*n,ti); laz.assign(2*n,ei); highest.assign(2*n,0);
    int c = 1;
    for(int i = 1; i < 2*n; i++) {
      if(c*2 <= i) c <<= 1;
      highest[i] = c;
    }
  }
  void set(int k, T x) {
    dat[k+n] = x;
  }
  void build() {
    for(int i = n-1; i >= 0; i--) {
      dat[i] = f(dat[2*i],dat[2*i+1]);
    }
  }
  void update(int a, int b, const E x) {
    thrust(a += n); thrust(b += n-1);
    for(int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if(l & 1) laz[l] = h(laz[l],x), ++l;
      if(r & 1) --r, laz[r] = h(laz[r],x);
    }
    recalc(a); recalc(b);
  }
  T query(int a, int b) {
    thrust(a += n); thrust(b += n-1);
    T l = ti, r = ti; b++;
    while(a < b) {
      if(a & 1) l = f(l,g(dat[a],laz[a],n/highest[a])), a++;
      if(b & 1) b--, r = f(g(dat[b],laz[b],n/highest[b]),r);
      a >>= 1; b >>= 1;
    }
    return f(l,r);
  }
};

int main(){
  int n, q;
  cin >> n >> q;
  auto f = [](ll a, ll b){return a+b;};
  auto g = [](ll a, ll b, int l){return b == INF ? a : b*l;};
  auto h = [](ll a, ll b) {return b;};
  LazySegmentTree<ll,ll,decltype(f),decltype(g),decltype(h)> lst(n,f,g,h,0,INF);
  rep(i,n) lst.set(i,0);
  lst.build();
  vector<ll> ans;
  rep(i,q) {
    int t;
    cin >> t;
    if(t == 0) {
      int l, r; ll x;
      cin >> l >> r >> x;
      lst.update(l,r+1,x);
    } else {
      int l, r;
      cin >> l >> r;
      ans.push_back(lst.query(l,r+1));
    }
  }
  for(auto x : ans) cout << x << endl;
  return 0;
}


Measured memory_bytes: 8964
s = input()
def check(s):
    l  = len(s)
    if l%2 != 0:
        return "No"
    else:
        r =  int(l/2)
        for i in range(r):
            a = s[2*i]
            b = s[2*i+1]
            if a == "h" and b == "i":
                pass
            else:
                return "No"
        return 'Yes'
print(check(s))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

int main() {
  string s, t;

  cin >> s >> t;

  int ret = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] != t[i]) ++ret;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 3876
#include <iostream>
#include <stdlib.h>

using namespace std;

int top, S[1000];

void push(int x) {
    top += 1;
    S[top] = x;
}

int pop() {
    int x = S[top];
    top -= 1;
    return x;
}

int main() {
    char s[100];
    int a, b;

    while(cin >> s) {
        switch(s[0]) {
            case '+':
                b = pop();
                a = pop();
                push(a + b);
                break;
            case '-':
                b = pop();
                a = pop();
                push(a - b);
                break;
            case '*':
                b = pop();
                a = pop();
                push(a * b);
                break;
            default:
                push(int(strtol(s, NULL, 10)));
        }
    }
    cout << pop() << endl;
}


Measured memory_bytes: 3108
n=int(input())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
maxi=sum(l2)+l1[0]
summ=int(maxi)
for i in range(n-1):
  summ+=l1[i+1]-l2[i]
  maxi=max(summ,maxi)
print(maxi)

Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>

int main(void) {
  long long N;
  long long neck;
  long long traff[5];

  scanf("%lld", &N);
  for(int i=0;i<5;i++){
    scanf("%lld", &traff[i]);
  }
  neck = traff[0];
  for(int i=1;i<5;i++) neck = (neck > traff[i] ? traff[i] : neck);

  double permin = ceil((double)N/neck);
  printf("%lld\n", (long long)(permin) + 4);

  return 0;
}


Measured memory_bytes: 128
import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")
MAX_DIGIT = 50

############
############
############

N, K = l_inpl()
td = []
for _ in range(N):
    ti, di = l_inpl()
    td.append([ti, di])

td.sort(key=lambda x: -x[1])

x = 0 # 美味しさの和
kind = set()
changable = []

# 美味しい順からソートして上位K個を採用する
for i in range(K):
    x += td[i][1]
    if td[i][0] not in kind: # 新しいネタの種類のとき
        kind.add(td[i][0])
    else: # 過去に追加したネタの種類のとき
        changable.append(td[i][1])
    
ans = x + len(kind) ** 2

# 採用した上位K個を元に下位を採用したときのスコアを計算する
for i in range(K, N):
    # ありえるネタの種類と各種類において最大のスコアを採用し終わった
    if len(changable) == 0:
        break
    # 新しいネタがすでに存在している種類の場合
    if td[i][0] in kind:
        continue
    kind.add(td[i][0])
    x = x + td[i][1] - changable.pop()
    tmp = x + len(kind) ** 2
    ans = max(ans, tmp)

print(ans)

    

Measured memory_bytes: 68440
#include <iostream>
#include <string>
#include <map>

int n;
std::string s;
std::map<std::string, int> a;

int main() {
    std::ios::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);
    std::cin >> n;
    for (int i = 1; i <= n; ++i) {
        std::cin >> s;
        ++a[s];
    }
    std::cout << "AC x " << a["AC"] << std::endl;
    std::cout << "WA x " << a["WA"] << std::endl;
    std::cout << "TLE x " << a["TLE"] << std::endl;
    std::cout << "RE x " << a["RE"] << std::endl;
    return 0;
}


Measured memory_bytes: 3660
def f(V, k):
    n = len(V)
    for i in range(0, n, 2):
        for j in range(1, n, 2):
            Ans.append((V[i], V[j], k))
    V1 = [V[i] for i in range(0, n, 2)]
    V2 = [V[i] for i in range(1, n, 2)]
    if len(V1) > 1:
        f(V1, k+1)
    if len(V2) > 1:
        f(V2, k+1)

N = int(input())
V = list(range(1, N+1))
Ans = []
k = 1
f(V, 1)

Edge = [[None]*(N+1) for _ in range(N+1)]

for i, j, c in Ans:
    Edge[i][j] = c
    Edge[j][i] = c

for i in range(1, N):
    print(*Edge[i][i+1:])


Measured memory_bytes: 65500
#include <bits/stdc++.h>
#define MAX_V 10000 + 1
#define INF 1E9
using namespace std;

struct edge{
	int to, dis, cost;
	bool operator > (const edge &other) const{
		if(dis == other.dis) return cost > other.cost;
		return dis > other.dis;
	}
};

edge make_edge(int to, int dis, int cost){
	edge e;
	e.to = to, e.dis = dis, e.cost = cost;
	return e;
}

int V, E;
vector<edge> G[MAX_V];

int Dijkstra(){
	int sum = 0;
	bool visit[MAX_V];
	priority_queue<edge, vector<edge>, greater<edge>> pri_q;
	
	memset(visit, 0, sizeof(visit));
	pri_q.push(make_edge(1, 0, 0));
		
	while(!pri_q.empty()){
		edge p = pri_q.top();
		pri_q.pop();
		
		int u = p.to;
		if(visit[u]) continue;
		visit[u] = true;
		sum += p.cost;
		
		for(int i = 0; i < G[u].size(); i++){
			edge e = G[u][i];
			pri_q.push(make_edge(e.to, p.dis + e.dis, e.cost));
		}
	}
		
	return sum;
}

int main(){
	while(cin >> V >> E){
		if(!V && !E) break;
		
		for(int i = 0; i < E; i++){
			int from, to, dis, cost;
			cin >> from >> to >> dis >> cost;
			G[from].push_back(make_edge(to, dis, cost));
			G[to].push_back(make_edge(from, dis, cost));
		}
		
		cout << Dijkstra() << endl;
		
		for(int i = 0; i <= V; i++)
			G[i].clear();
	}
	
	return 0;
}


Measured memory_bytes: 5436
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

H,W,K = inpl()

num = [1,1,2,3,5,8,13,21]
# a_to_b[a][b] : a->b に行く高さ1の阿弥陀の数
a_to_b = [[0]*W for i in range(W)]
for a in range(W):
    for b in range(W):
        if a > b:
            a_to_b[a][b] = a_to_b[b][a]
        else:
            if abs(a-b) > 1:
                a_to_b[a][b] = 0
            else:
                a_to_b[a][b] = num[a]*num[W-b-1]

cnt = [0]*W
cnt[0] = 1
for h in range(H):
    next_cnt = [0]*W
    for a in range(W):
        for b in range(W):
            next_cnt[b] += a_to_b[a][b] * cnt[a]
    cnt = next_cnt[:]

print(cnt[K-1]%mod)


Measured memory_bytes: 4208
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;
        static void Main(string[] args)
        {
            var NM = Sarray();
            N = NM[0];
            M = NM[1];
            a = new int[N].Select(_ => new List<long>()).ToArray();
            for (var i = 0; i < N - 1; ++i)
            {
                var t = Sarray();
                a[t[0] - 1].Add(t[1] - 1);
                a[t[1] - 1].Add(t[0] - 1);
            }
            dpnode = new int[N].Select(_ => 1L).ToArray();
            dpoyaof = new long[N];

            dfs(0, -1);
            dpoyaof[0] = 1;
            ruil = new long[N + 1];
            ruir = new long[N + 1];
            ruil[0] = 1;
            ruir[0] = 1;

            dfs3(0);
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            for (var i = 0; i < N; ++i)
                WriteLine(dpoyaof[i] * dpnode[i] % M);
            Out.Flush();
        }
        static List<long>[] a;
        static long N;
        static long M;
        static long[] dpnode;
        static long[] dpoyaof;
        static void dfs(long v, long p)
        {
            a[v].Remove(p);
            foreach (var n in a[v])
            {
                dfs(n, v);
                dpnode[v] = dpnode[v] * (dpnode[n] + 1) % M;
            }
        }
        static long[] ruil;
        static long[] ruir;
        static void dfs3(long v)
        {
            var num = a[v].Count;
            for (var i = 0; i < num; ++i)
            {
                ruil[i + 1] = ruil[i] * (dpnode[a[v][i]] + 1) % M;
                ruir[i + 1] = ruir[i] * (dpnode[a[v][num - i - 1]] + 1) % M;
            }
            for (var i = 0; i < num; ++i)
                dpoyaof[a[v][i]] = ((ruil[i] * ruir[num - i - 1] % M) * dpoyaof[v] + 1) % M;
            for (var i = 0; i < num; ++i)
                dfs3(a[v][i]);
        }
    }
}

Measured memory_bytes: 42172
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long K = sc.nextLong();
        int[] A = new int[N];
        for (int i=0;i<N;i++) {
            A[i] = sc.nextInt();
        }
        Arrays.sort(A);

        long ok_key = 2_000_000_000_000_000_000L;
        long ng_key = -2_000_000_000_000_000_000L;
        while (Math.abs(ok_key-ng_key)>1) {

            long key = (ok_key+ng_key)/2;

            long cnt = 0L;
            for (int i=0;i<N-1;i++) {
                if (A[i]>=0) {
                    int ok = i;
                    int ng = N;
                    while (Math.abs(ok-ng)>1) {
                        int mid = (ok+ng)/2;
                        if ((long)A[mid]*A[i]<=key) {
                            ok = mid;
                        } else {
                            ng = mid;
                        }
                    }
                    cnt+=ok-i;
                } else { // A[i]<0
                    int ok = N;
                    int ng = i;
                    while (Math.abs(ok-ng)>1) {
                        int mid = (ok+ng)/2;
                        if ((long)A[mid]*A[i]<=key) {
                            ok = mid;
                        } else {
                            ng = mid;
                        }
                    }
                    cnt+=N-ok;
                }
                // System.out.println("ok: "+ok);
                // System.out.println("ok_cnt: "+(i));
            }

            if (cnt>=K) {
                ok_key = key;
            } else {
                ng_key = key;
            }
            // System.out.println("key, cnt: "+key+" "+cnt);
        }
        System.out.println(ok_key);
    }
}

Measured memory_bytes: 83612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,m;
  cin >> n >> m;
  vector<long> a(n);
  vector<vector<long>> cb(m,vector<long>(2));
  int i;
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  for(i=0;i<m;i++){
    cin >> cb[i][1] >> cb[i][0];
  }
  sort(a.begin(),a.end());
  sort(cb.begin(),cb.end());
  int nokori = n;
  long ans = 0;
  while(nokori > 0){
    if(m == 0||a[n-1] > cb[m-1][0]){
      ans += a[n-1];
      n--;
      nokori--;
    }else{
      if(cb[m-1][1] > nokori){
        ans += nokori * cb[m-1][0];
        nokori = 0;
      }else{
        ans += cb[m-1][0]*cb[m-1][1];
        nokori -= cb[m-1][1];
        m--;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 6528