akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

const double eps = 1e-10;
const int MOD = 1000000007;

void printv(vector<auto> const& s) {
  REP(i, s.size()) {
    cout << s[i] << endl;
  }
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int h, w, d; cin >> h >> w >> d;
  int a;
  map<int, P> m;
  REP(i, h) {
    REP(j, w) {
      cin >> a;
      m[a] = P(i, j);
    }
  }

  vi dist(h*w+1);

  REP(i, d+1) dist[i] = 0;
  
  FOR(i, d+1, h*w+1) {
    dist[i] = abs(m[i].fi - m[i-d].fi) + abs(m[i].se - m[i-d].se);
  }

  vi dsum(h*w+1);
  REP(i, d+1) dsum[i] = 0;
  FOR(i, d+1, h*w+1) {
    dsum[i] = dsum[i-d] + dist[i];
  }
  
  int q; cin >> q;
  int l, r;
  vi ans;
  REP(i, q) {
    cin >> l >> r;
    ans.pb(dsum[r] - dsum[l]);
  }

  REP(i, SZ(ans)) {
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 7928
#include <iostream>
#include <set>

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

using namespace std;

int main( void )
{
	int n;
	set<int> info[100];
	while(cin >> n, n) {
		rep(i, n) {
			int m; cin >> m;
			info[i].clear();
			rep(j, m) {
				int p; cin >> p;
				info[i].insert(p);
			}
		}
		int k, *kk, ans, count = 0;
		kk = new int[n];
		cin >> k;
		rep(i, k) cin >> kk[i];
		rep(i, n) {
			bool hit = true;
			rep(j, k) {
				hit &= (bool)info[i].count(kk[j]);
			}
			if(hit) {
				ans = i+1;
				count++;
			}
		}
		if(count == 1)
			cout << ans << endl;
		else
			cout << -1 << endl;
	}

	return 0;
}

Measured memory_bytes: 0
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int upperBound = (n - 1) * (n - 2) / 2;
        if (k <= upperBound) {
            int m = n - 1 + (upperBound - k);
            writer.println(m);
            for (int i = 2; i <= n; ++i)
                writer.println(1 + " " + i);
            for (int u = 2, v = 3; k < upperBound && u < n; ++k) {
                writer.println(u + " " + v);
                ++v;
                if (v > n) {
                    ++u;
                    v = u + 1;
                }
            }
        } else {
            writer.println(-1);
        }

        writer.close();
    }

    private static long compute(long a, long b, long c) {
        return b / c - (a / c + (a % c == 0 ? 0 : 1)) + 1;
    }

    private static long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        int nextInt() {
            return Integer.valueOf(next());
        }

        long nextLong() {
            return Long.valueOf(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

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


int main(){
    ll n,k;
    ll INF = 1001001001001001001;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i] ;
    }
    sort(a.begin(), a.end());
    ll l=-INF, r=INF;
    while(l+1<r){
        ll x=(l+r)/2;
        ll tot=0;
        rep(i,n){
            if (a[i]<0){
                int l2=-1, r2=n;
                while(l2+1<r2){
                    int c2=(l2+r2)/2;
                    if ((a[i]*a[c2])<x){
                        r2=c2;
                    } else{
                        l2=c2;
                    }
                }
                tot += n-r2;
            } else {
                int l2=-1, r2=n;
                while(l2+1<r2){
                    int c2=(l2+r2)/2;
                    if ((a[i]*a[c2])<x){
                        l2=c2;
                    } else{
                        r2=c2;
                    }
                }
                tot += r2;
            }
            if (a[i]*a[i]<x) tot-=1;
        }
        tot/=2;
        if (k>tot) l=x;
        else r=x;
    }
    cout << l << endl;
    return 0;
}

Measured memory_bytes: 1920
fn is_prime(p: usize) -> bool {
    if p < 2 {
        return false;
    }
    for i in 2..p {
        if i * i > p {
            return true
        }
        if p % i == 0 {
            return false
        }
    }
    return true
}

fn main() {
    let mut res = vec![];
    for i in 0..55555 {
        if i%5 != 1 {
            continue
        }
        if is_prime(i) {
            res.push(i);
        }
    }

    let sc = std::io::stdin();
    let mut s = String::new();
    sc.read_line(&mut s).unwrap();
    let n: usize = s.trim().parse().unwrap();

    for i in 0..n {
        print!("{}{}", res[i], if i==n-1 { '\n' } else { ' '});
    }
}

Measured memory_bytes: 4352
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int64 power(int64 n, int m) {
  int64 ret = 1;
  while (m--) ret *= n;
  return ret;
}

int main() {
  int64 x;
  cin >> x;
  for (int64 B = 0; B <= 200; ++B) {
    int64 cur = power(B, 5) + x;
    int64 A = (int64)pow(1.0 * cur, 1.0 / 5);
    if (power(A, 5) == cur) {
      cout << A << " " << B << endl;
      return 0;
    }
    ++A;
    if (power(A, 5) == cur) {
      cout << A << " " << B << endl;
      return 0;
    }
  }
  for (int64 B = 0; B <= 200; ++B) {
    int64 cur = power(B, 5);
    if (cur > x) break;
    cur = x - cur;
    int64 A = (int64)pow(1.0 * cur, 1.0 / 5);
    if (power(A, 5) == cur) {
      cout << A << " " << -B << endl;
      return 0;
    }
    ++A;
    if (power(A, 5) == cur) {
      cout << A << " " << -B << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 4096
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
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;
}

int main() {
    int n, k;
    cin >> n >> k;
    vl a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    auto check = [&](ll mid) {
        bitset<5001> dp;
        dp[0] = 1;
        for (int i = 0; i < n; ++i) {
            if (mid == i)
                continue;
            dp |= dp << a[i];
        }
        for (int i = max(0LL, k - a[mid]); i < k; ++i) {
            if (dp[i] == 1)
                return true;
        }
        return false;
    };
    ll ok = n;
    ll ng = -1;
    while (abs(ok - ng) != 1) {
        ll mid = (ng + ok) / 2;
        if (check(mid))
            ok = mid;
        else
            ng = mid;
    }
    cout << ok << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int N, T, c, t, i, m = 9999;
  
  scanf("%d %d", &N, &T);
  for(i = 0; i < N; i++){
    scanf("%d %d", &c, &t);
    if(t <= T){
      if(c < m) m = c;
    }
  }
  if(m == 9999){
    printf("TLE\n");
  }else{
    printf("%d\n", m);
  }
  
  return 0;
}

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

int binaryserach(int key,vector<int>a){
  int left=0;
  int right=a.size();
  int mid;

  while(left<right){
    mid=(left+right)/2;
    if(a[mid]==key)return 1;
    else if(a[mid]>key)right=mid;
    else left=mid+1;
  }
  
  return 0;
}

int main(){
  int n,q;
  cin>>n;
  vector<int>a(n);
  rep(i,n){
    scanf("%d",&a[i]);
  }
  cin>>q;
  vector<int>b(q);
  rep(i,q){
    scanf("%d",&b[i]);
  }
  //cout<<"入力終了"<<endl;
  int ans=0;

  rep(i,q){
    ans+=binaryserach(b[i],a);
  }

  cout<<ans<<endl;
} 


Measured memory_bytes: 3888
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N; 
	cin >> N; 
	long long int A[100010] = {}; 
	long long int S[100010] = {}; 
	for(int i = 0; i < N; i++){
		cin >> A[i]; 
	}
	sort(A, A+N); 
	for(int i = 1; i <= N; i++){
		S[i] = A[i-1] + S[i-1]; 
	}
	int ans = 1; 
	for(int i = N-1; i >= 0; i--){
		if(A[i] > S[i] * 2) break; 
		else ans ++; 
	}
	cout << ans << endl; 
}

Measured memory_bytes: 1792
N = int(input())
S = str(input())
#N = 13
#S = "strangeorange"

lb = 0
ub = N //2 + 1
flag = False
while (ub - lb > 1):
    mid = (lb + ub) // 2
    s = set()
    for i in range(N - 2*mid + 1):
        s.add(S[i:mid+i])
        if S[mid+i:i+2*mid] in s:
            flag = True
            break
        else:
            flag = False
    if flag == True:
        lb = mid
    else:
        ub = mid
print(lb)

Measured memory_bytes: 6388
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		int ngs=s.length();
		int[][] unko=new int[26][ngs+1];		//26*10^5
		for(int i=0; i<26; i++) {
			for(int j=0; j<=ngs; j++) {
				unko[i][j]=0;
			}
		}
		for(int i=0; i<ngs; i++) {
			unko[s.charAt(i)-97][i+1]++;
		}
		for(int i=0; i<26; i++) {		//26*10^5
			for(int j=1; j<=ngs; j++) {
				unko[i][j]=unko[i][j]+unko[i][j-1];
			}
		}
		int l=0;
		int r=0;
		int tmp=0;
		for(int i=0; i<26; i++) {
			for(int j=0; j<=ngs-2; j++) {
				if(unko[i][j+2]-unko[i][j]==2) {		// ooつまり同じものが2個連続している時
					System.out.println(j+1+" "+(j+2));
					System.exit(0);
				}
			}

			for(int j=0; j<=ngs-3; j++) {
				if(unko[i][j+3]-unko[i][j]>=2) {		//oxoのように真ん中が他の文字の時
					System.out.println(j+1+" "+(j+3));
					System.exit(0);
				}
			}
		}
		System.out.println(-1+" "+-1);
	}
}

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


int main(){
	int N,M;

	cin >> N >> M;

	int A[N];

	for(int i = 0;i < M;i++){
		cin >> A[i];
	}

	int sum = 0;
	for(int i = 0;i < M;i++){
		sum += A[i];
	}
	int answer = N - sum;

	if(answer < 0)
		cout << -1<< endl ;
	else
		cout << answer << endl;


	return 0;
}




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

int main(){
    string s;
    cin>>s;
    
    string week[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
    
    rep(i,7)
        if(s==week[i]) cout<<7-i<<endl;
    
    return 0;
}

Measured memory_bytes: 3576
"use strict"
function Main(input) {
  input = input.trim().split(' ').map(Number);
  const K = input[0];
  const X = input[1];

  if(K * 500 >= X) {
    console.log('Yes')
    return;
  }
  console.log('No');
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 22332
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

S = gets.chomp

if S == 'ABC'
  puts 'ARC'
else
  puts 'ABC'
end


Measured memory_bytes: 14260
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<long long> a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a.begin(),a.end(),greater<int>());
    long long ans = 1;
    int co = 0;
    for(int i = 0; i < n-1; i++)
    {
        if (a[i] == a[i+1]) {
            ans *= a[i];
            co++;
            i++;
        }
        if (co == 2) {
            break;
        }
    }
    if (co == 2) {
        cout << ans << endl;
    }
    else
    {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 1024
#include <stdio.h>
#define MAX 200010
#define MOD 1000000007

long long int fac[MAX]={0};
long long int inv[MAX]={0};
long long int finv[MAX]={0};
int i;

void comb_init()
{
	fac[0]=1;
	fac[1]=1;
	finv[0]=1;
	finv[1]=1;
	inv[1]=1;
	for(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;
	}
}


long long int comb(int n,int k)
{
	if(n<k)return 0;
	if(n<0||k<0)return 0;
	return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

long long int tetra(int n)
{
	long long int lln=(long long int)n;
	return (lln*(lln+1)*(lln+2)/6)%MOD;
}

int main()
{
	int n,m,k;
	
	long long int ans,a,b;
	scanf("%d %d %d",&n,&m,&k);
	comb_init();
	a=((tetra(m-1)*n)%MOD*n)%MOD;
	//printf("%d\n",((tetra(m-1)*n)%MOD*n));
	b=((tetra(n-1)*m)%MOD*m)%MOD;
	ans=(((a+b)%MOD)*(comb((n*m-2),(k-2)))%MOD);
	//printf("%d %d %d",a+b,comb((n*m-2),(k-2)),ans);
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 4864
#include <iostream>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <algorithm>
#include <set>

using namespace std;

using ll = long long;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, res = 0;
	cin >> n;
	int p[100000];
	for (int i = 0; i < n; ++i) {
		cin >> p[i];
	}
	for (int i = 1; i < n - 1; ++i) {
		if (p[i - 1] < p[i] && p[i] < p[i + 1] || p[i + 1] < p[i] && p[i] < p[i - 1]) {
			++res;
		}
	}
	cout << res << '\n';
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;

int main() {
 ll n,k;
  cin>>n>>k;
  vector<ll> h(n);
 rep(i,n) cin>>h[i];
  sort(all(h));
  reverse(all(h));
 ll sum=0;
  rep2(i,k,n) sum+=h[i];
 cout<<sum<<endl;
return 0;
}


Measured memory_bytes: 1792
//
//  main.cpp
//  ALDS1_4_D
//
//  Created by ptyuan on 2018/10/25.
//  Copyright © 2018 Sy. All rights reserved.
//

#include <iostream>
#include <cstdio>
using namespace std;

int T[100000];
int n = 0;
int k = 0;

int check(int p) {
    int count = 0;
    for (int i = 0; i < k; i++) {
        int s = 0;
        while (s + T[count] <= p) {
            s += T[count];
            count++;
            if (count == n) {
                return n;
            }
        }
    }
    return count;
}

int main(int argc, const char * argv[]) {
    
    
    scanf("%d%d", &n, &k);
    
    for (int i = 0; i < n; i++) {
        scanf("%d", T + i);
    }
    
    int left = 0;
    int right = 100000 * 10000;
    while (right - left > 1) {
        int middle = (right + left) / 2;
        int v = check(middle);
        if (v >= n) {
            right = middle;
        } else {
            left = middle;
        }
    }
    
    cout << right << endl;
    return 0;
}



Measured memory_bytes: 3644
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 300000000000000000
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[5]={-1,0,1,0,0};
int dy[5]={0,-1,0,1,0};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    /*int t;cin>>t;
    while(t--){

    }*/
    int n;cin>>n;
    V<int>l(2*n);
    for(int i=0;i<2*n;i++)cin>>l[i];
    int ans=0;
    sort(all(l));
    for(int i=0;i<2*n;i+=2){
        ans+=l[i];
    }
    cout<<ans<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------

















































Measured memory_bytes: 256
from itertools import permutations
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

ans = 0
l = list(permutations(xy,N))
for i in l:
  for j in range(N-1):
    ans += ((i[j][0] - i[j+1][0])**2 + (i[j][1] - i[j+1][1])**2)**0.5
print(ans/len(l))

Measured memory_bytes: 8180
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int n, a[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) cin >> a[i];
    sort(a+1, a+n+1);
    int s = 0;
    FOR(i,1,n) s += a[i];
    if (s % 10) cout << s;
    else {
        FOR(i,1,n)
            if (a[i] % 10) {
                s -= a[i];
                cout << s;
                return 0;
            }
        cout << 0;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

struct Seg {
    double X, Y;
    Seg () {}
    Seg(double _1, double _2) {
        X = _1;
        Y = _2;
    }
    bool operator < (const Seg& A) const {
        return X < A.X;
    }
};

vector <Seg> S;

int n, X[111], Y[111];

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d%d", &X[i], &Y[i]);
    for(int i = 1; i <= n; i++) {
        S.clear();
        for(int j = 1; j <= n; j++) if(j != i) {
            double tmp = atan2(Y[j] - Y[i], X[j] - X[i]);
            double l = tmp - M_PI / 2, r = tmp + M_PI / 2;
            if(r < 0) l += 2 * M_PI, r += 2 * M_PI;
            if(l > 2 * M_PI) l -= 2 * M_PI, r -= 2 * M_PI;
            if(l < 0) {
                S.push_back(Seg(l + 2 * M_PI, 2 * M_PI));
                S.push_back(Seg(0, r));
            } else S.push_back(Seg(l, r));
        }
        sort(S.begin(), S.end());
        double ans = 2 * M_PI, pr = S[0].X, nx = S[0].Y;
        for(int i = 1; i < S.size(); i++)
            if(S[i].X > nx) {
                ans -= nx - pr;
                pr = S[i].X;
                nx = S[i].Y;
            } else nx = max(nx, S[i].Y);
        ans -= nx - pr;
        printf("%.15lf\n", ans / 2 / M_PI);
    }
    return 0;
}

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

int main() {
    int N;
    string s;
    cin >> N >> s;
    int ans = 0;
    for (int i = 0; i < 1000; i++) {
        int dig[3] = {i/100, i/10%10, i%10};
        int flag = 0;
        for (int j = 0; j < N; j++) {
            if (dig[flag] + '0' == s[j]) flag++;
            if (flag == 3) break;
        }
        if (flag == 3) ans++;
    }
    cout << ans << endl;
}

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

int main(){
	int n,m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  for(int i = 0; m > i; i++){
   	int a,b;
    cin >> a >> b;
    a--,b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  
  vector<int> from(n, -1);
  queue<pair<int,int>> que;
  que.push({0,0});
  while(que.size()){
  	pair<int,int> cur = que.front();
    que.pop();
    
    if(from[cur.first]!=-1) continue;
    from[cur.first] = cur.second;
    for(auto ed : g[cur.first]){
    	que.push({ed, cur.first}); 
    }
  }
  cout << "Yes" << endl;
  for(int i = 1; n > i; i++)
    cout << from[i] + 1 << endl;
}

Measured memory_bytes: 12132
def bubble_sort(ca)
  c = ca.dup
  c.size.times do |i|
    (c.size - 1).downto(i+1) do |j|
      if c[j][1] < c[j - 1][1]
        c[j], c[j - 1] = c[j - 1], c[j]
      end
    end
  end
  c
end

def select_sort(ca)
  c = ca.dup
  c.size.times do |i|
    m = i
    i.upto(c.size - 1) do |j|
      if c[j][1] < c[m][1]
        m = j
      end
    end
    c[i], c[m] = c[m], c[i]
  end
  c
end
gets
input = gets.split.map! do |e|
  e =~ /(?<m>\w)(?<n>\d+)/
  [$1, $2.to_i]
end
a = bubble_sort(input).map(&:join).join(' ')
b = select_sort(input).map(&:join).join(' ')
puts a
puts 'Stable'
puts b
puts a == b ? 'Stable' : 'Not stable'

Measured memory_bytes: 8668
#include <iostream>
#include <algorithm>
#include <list>
#include <vector>
#include <stack>
#include <queue>

using namespace std;

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

    if(a <= x && x <= (a+b)) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

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

static const long long MOD = 1000000007;

long long fact[101010];

long long extgcd(long long a, long long b, long long& x, long long& y) {
        long long d = a;
        if (b != 0) {
                d = extgcd(b, a % b, y, x);
                y -= (a / b) * x;
        } else {
                x = 1;
                y = 0;
        }
        return d;
}

long long inv(long long a) {
        long long x, y;
        extgcd(a, MOD, x, y);
        return (x % MOD + MOD) % MOD;
}
 
long long nCr(long long n, long long r){
        if (n < r) return 0;
        if (n - r < r) r = n - r;
        long long ans = fact[n] * inv(fact[r]) % MOD * inv(fact[n - r]) % MOD;
        return ans;
}

void init() {
        fact[0] = 1;
        for (int i = 1; i < 101010; i ++) fact[i] = fact[i - 1] * i % MOD;
}

int main() {
        init();
        int n;
        cin >> n;
        vector<int> a(n);
        vector<int> cnt(n + 1, 0);
        rep(i, n + 1) { 
                cin >> a[i];
                cnt[a[i]] ++;
        }
        int twice;
        rep(i, n + 1) {
                if (cnt[i] >= 2) {
                        twice = i;
                }
        }
        int left = 0, mid = 0, right = 0;
        int i = 0;
        while (a[i] != twice) {
                left ++;
                i ++;
        }
        i ++;
        while (a[i] != twice) i ++;
        i ++;
        while (i < n + 1) {
                right ++;
                i ++;
        }
        int sum = left + right;
        for (int k = 1; k <= n + 1; k ++) {
                long long ans;
                if (sum >= k - 1) ans = ((nCr(n + 1, k) - nCr(sum, k - 1) % MOD) + MOD) % MOD ;
                else ans = nCr(n + 1, k) % MOD;
                cout << ans % MOD << endl;
        }
        return 0;
}



Measured memory_bytes: 2816
#include <bits/stdc++.h>
#include <math.h>
#include <chrono>
using namespace std;
#pragma GCC optimize("-O3")
#define endl "\n"
#define mp make_pair
#define st first
#define nd second
#define pii pair<int, int>
#define pb push_back
#define _upgrade ios_base::sync_with_stdio(0), cout.setf(ios::fixed), cout.precision(10) //cin.tie(0); cout.tie(0);
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FWD(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define fwd(i, a, b) for (int i = (a); i < (b); ++i)
#define all(c) (c).begin(), (c).end()
#define what(x) cerr << #x << " is " << x << endl;
#define int long long

vector<int> V;
int n, m, v, p;

queue<int> Q;
int suma = 0;

void add(int x)
{
    suma += x;
    Q.push(x);
}

int get(int x)
{
    if (!Q.empty() && x + m < Q.front())
    {
        return -1e18;
    }
    return ((x + m) * Q.size()) - suma;
}

void input()
{
    cin >> n >> m >> v >> p;
    V.resize(n);
    rep(i, n)
    {
        cin >> V[i];
    }

    sort(all(V), greater<int>());
}

void solve()
{
    int ile = p - 1;
    int j = 0;
    for (int i = p - 1; i < n; i++)
    {
        while (V[j] > V[i])
            j++;

        if (get(V[i]) + (n - i + p - 1) * m >= v * m)
        {
            /*
            what(i);
            what(V[i]);
            what(get(V[i]) + (n - i + p - 1) * m);
            */
            ile++;
        }
        add(V[i]);
    }
    cout << ile << endl;
}
main()
{
    _upgrade;
    input();
    solve();
}

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

int main() {
    int n, q; cin >> n >> q;
    vector<list<int>> li(n);
    while (q--) {
        int com; cin >> com;
        if (com == 0) {
            int t, x; cin >> t >> x;
            li[t].emplace_back(x);
        } else if (com == 1) {
            int t; cin >> t;
            int i = 0; for (int x: li[t]) cout << (i++ ? " " : "") << x;
            cout << endl;
        } else if (com == 2) {
            int s, t; cin >> s >> t;
            li[t].splice(end(li[t]), move(li[s]));
        }
    }
	return 0;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

template<typename T>
void O(T t){
  cout << t << endl;
}

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,a,b;
  cin >> n;
  vector<ll> ans(1000010);
  ans[0] = 0;
  rep(i,n){
    cin >> a >> b;
    /* if(a) a--; */
    /* if(b) b--; */
    --a;
    ans[a] ++;
    ans[b] --;
  }
  rep(i,100001){
    ans[i+1] += ans[i];
  }
  ll k = 0;
  REP(i,0,n+1){
    if(ans[i] >= i)
      k = max(k,i+ 0LL); 
  }
  cout << k << endl;
  return 0;
}

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

int main() {
	vector<int> vec(5);

	for(int i=0 ;i<5 ; i++)
		cin >> vec.at(i);
	
	for(int i=0; i<5; i++){
		if(vec.at(i) == 0){
			cout << i+1 << endl;
		}
	}
}

Measured memory_bytes: 3620
import math
a, b, h , m = map(int,input().split())
x = abs(30*h + 0.5*m-6*m) 
x = min(x, 360-x)

cos = math.cos(math.radians(x)) 

ans = (a**2+b**2 -2*a*b*cos)**(1/2)
print(ans)     

Measured memory_bytes: 9568
#include<cstdio>

int main(void){
  char s[100000];

  scanf("%s",s);

  int ans =0;

  for(int i=0;s[i+1]!=0;i++)
    if(s[i]!=s[i+1])
      ans++;

  printf("%d\n",ans);

  return 0;
}


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

int main(){
    char x;
    cin >> x;
    vector<char> v{'a', 'i', 'u', 'e', 'o'};
    auto itr = find(v.begin(), v.end(), x);
    if(itr != v.end()){cout << "vowel";}else{cout << "consonant";}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{ int n;
  while(~scanf("%d",&n))
  { if(n%3==0||n%3!=0)
     printf("%d\n",n/3);
     else
     if(n<=2)
     printf("0\n");
  }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
//#pragma gcc optimize("O3")
//#pragma gcc optimize("unroll-loops")
#ifdef EVAH
    #define _WIN32_WINNT 0x0500
    #include<windows.h>
#endif
#define openFile(n) ShellExecute(nullptr,"open",n,nullptr,nullptr,SW_SHOWNORMAL);
#define closeP(n) system((string("taskkill /im ")+n+" /f").c_str());
#define closeConsole PostMessage(GetConsoleWindow(), WM_CLOSE, 0, 0);
#define opf "output.txt"
#define ipf "input.txt"
#define mem(n,x) memset(n,x,sizeof(n));
#define sf scanf
#define pf printf
#define ff first
#define ss second
#define pb push_back
#define PII pair<int,int>
#define For(x,n) for(int i=x; i<n; i++)
#define stv v+2*(mid-tl+1)
#define LL long long int
#define PI acos(-1.0)
#define N 100000000


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    #ifdef EVAH
        //freopen(ipf,"r",stdin);
        //openFile(ipf);
        //closeConsole;
        //freopen(opf,"w",stdout);
    #endif

    int x;
    cin >> x;
    if(x>=30) cout << "Yes\n";
    else cout << "No\n";

    #ifdef EVAH
        //openFile(opf);
        //Sleep(3000);
        //closeP("notepad.exe");
        //closeConsole;
    #endif
}


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

int main(){
    string S;
    cin>>S;
    bool n=false;
    bool w=false;
    bool s=false;
    bool e=false;
    rep(i, S.length()){
        if(S[i]=='N') n=true;
        else if(S[i]=='S') s=true;
        else if(S[i]=='W') w=true;
        else e=true;
    }
    if((n==s)&&(e==w)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    multiset<int> s;
    for (int i=0; i<n; i++) {
        int ai;
        cin >> ai;
        auto lb = s.lower_bound(ai);
        if (s.begin() != lb) {
            lb--;
            s.erase(lb);
        }
        s.insert(ai);
    }
    cout << s.size() << '\n';
    return 0;
}

Measured memory_bytes: 4992
import java.util.Scanner;

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

        int A = sc.nextInt();
        int B = sc.nextInt();

        int max = A + B;
        max = Math.max(max, A - B);
        max = Math.max(max, A * B);

        System.out.println(max);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define fre freopen("in.txt","r",stdin)
#define IO ios::sync_with_stdio(false)
#define mem(a,n) memset(a,n,sizeof(a))
#define rep(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
typedef long long ll;
const int INF=0x3f3f3f3f;
const double PI=3.1415926;
const int MOD=1e9+7;
const int N=2e3+5;
int n;
bitset<N*N>dp;
int main()
{
    while(~scanf("%d",&n))
    {
        dp[0]=1;
        int sum=0;
        for(int i=1; i<=n; i++)
        {
            int x;
            scanf("%d",&x);
            sum+=x;
            dp|=dp<<x;
        }
        for(int i=(sum+1)/2;; i++)
            if(dp[i])
            {
                printf("%d\n",i);
                break;
            }
    }
    return 0;
}


Measured memory_bytes: 1664
#include <ctype.h>
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

//char rbuf[]; int rbufl;
//#define getchar() rbuf[rbufl++]
#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }
void printint(int32_t x){ if(x<0){x=-x; putchar('-');}else if(x==0){putchar('0');} int d=0; char s[10]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) putchar(s[i]); putchar('\n'); }
void rsorta_d32(void *base, const int count, const int size, const int index){
	typedef int32_t rsort_t;
	rsort_t (*a)[size] = (rsort_t(*)[size])base;
	rsort_t (*b)[size] = (rsort_t(*)[size])malloc(count*size*sizeof(rsort_t));
	int c[0x100];
	for(int k=0; k<4; k++){
		memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(k<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(k<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	}
	free(b);
}

long a[200];
char s[201];
long d[200];
int main(void){
	int t=nextint();
	while(t-->0){
		int n=nextint();
		for(int i=0; i<n; i++){
			a[i]=nextlong();
		}
		nextstr(s);
		int ans=0;
		int D=0;
		for(int i=n-1; i>=0; i--){
			long v=a[i];
			for(int j=0; j<D; j++){
				if(v>(d[j]^v)) v=(d[j]^v);
			}
			if(v!=0){
				if(s[i]=='1'){
					ans=1;
					break;
				}else{
					d[D++]=v;
				}
			}
		}
		putchar(ans+'0');
		putchar(10);
	}
}


Measured memory_bytes: 1492
n, a, b = gets.split.map(&:to_i)
res = 0
1.upto(n) do |nn|
  digit_sum = nn.to_s.chars.inject{ |sum, i| sum.to_i + i.to_i }.to_i
  res += nn if a <= digit_sum && digit_sum <= b
end
puts res

Measured memory_bytes: 1788
require 'prime'
require 'set'
require 'tsort'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end


a,b,c = gi
jd = false
cc = []
loop do
if a >= c % (a+b)
  jd = true
  break
end
c1 = (60 + c)
break if cc.include? c1 % (a+b)
c = c1
cc << c1 % (a+b)
end

puts jd ? c : -1

Measured memory_bytes: 9128
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

a = int(input())
b = int(input())
print(6-a-b)

Measured memory_bytes: 38256
#include <stdio.h>
int F[44];
int fibonacci(int);
int main(){
  int n,i;
  scanf("%d",&n);
  i=fibonacci(n);
  printf("%d\n",F[i]);
  return 0;
    }

int fibonacci(int n){
  int i;
  F[0]=1;
  F[1]=1;
  for(i=2;i<=n;i++) F[i]=F[i-2]+F[i-1];

  return i-1;
}

Measured memory_bytes: 596
#include <iostream>
#include <queue>
#include <vector>
#include <functional>
using namespace std;

//N 点、目的地の数
//M 辺、経路の数
//S 始点、Sからの距離を一覧で出す
//A[] 各辺の始点
//B[] 各辺の終点
//C[] 各辺の距離
//dist[] Sからの距離一覧
//G[]<int><int> グラフ、辺の集合

int intmax = 1000000007;
int N, M, S, A, B, C, h, w;
int cnt=0;
int dist[100009];
vector<pair<int, int>> G[100009];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> Q;

int main() {

	while (1) {
		cin >> h >> w;
		if (h + w == 0) break;

		for(int i=0;i<100009;i++) G[i].resize(0);
      	while (!Q.empty()) Q.pop();

		// グラフを入力する
		//scanf("%d%d", &N, &M);
		N = h * w;
		M = (w - 1)*h + w * (h - 1);
		for (int i = 0; i < 2 * w - 1; i++) {
          //cout<< "i" << i <<endl;
			if (i % 2 == 0) {
				for (int j = 1;j < h;j++) {
					A = h * i/2 + j;
					B = h * i/2 + j + 1;
					cin >> C;
                  	C=C*intmax+1;
					G[A].push_back(make_pair(B, C));
					G[B].push_back(make_pair(A, C));
                    //if(1) cout<< A << " " << B <<endl;
				}
			}
			else {
				for (int j = 1;j <= h;j++) {
					A = h * (i/2) + j;
					B = h * (i/2 + 1) + j;
					cin >> C;
                  	C=C*intmax+1;
					G[A].push_back(make_pair(B, C));
					G[B].push_back(make_pair(A, C));
                  	//if(1) cout<< A << " " << B <<endl;
				}
			}

		}
		S = 1;
      
      	cnt++;
      	//cout<< "rap " << cnt <<endl;

		// 距離を初期化する
		for (int i = 1; i <= N; i++) dist[i] = intmax;

		// 優先度付きキューには (距離, 頂点番号) の組を入れる
		Q.push(make_pair(0, S));
		dist[S] = 1;
		while (!Q.empty()) {
			int pos = Q.top().second; Q.pop();
			for (int i = 0; i < G[pos].size(); i++) {
				int to = G[pos][i].first, cost = G[pos][i].second;
				if (dist[to] > dist[pos] + cost) {
					dist[to] = dist[pos] + cost;
					Q.push(make_pair(dist[to], to));
				}
			}
		}

		// 距離を出力する
		if (dist[h*w] == intmax) cout << "0" << endl;
		else cout << dist[h*w] << endl;

	}
	return 0;
}


Measured memory_bytes: 5456
#include <iostream>

using ll = long long;

ll n, c;
ll a[400],b[400];
ll dp[401];

ll MOD = 1000000007;

int main()
{
	std::cin >> n >> c;
	for (int i = 0; i < n; ++i)
	{
		std::cin >> a[i];
	}
	for (int i = 0; i < n; ++i)
	{
		std::cin >> b[i];
	}
	for (int j = 0; j <= c; ++j)
	{
		dp[j] = 0;
	}
	dp[0] = 1;
	for (int i = 0; i < n; ++i)
	{
		ll newdp[401] = {};
		for (ll t = a[i]; t <= b[i]; ++t)
		{
			ll tas[401] = { dp[0] };
			for (int j = 0; j <= c; ++j)
			{
				if(j != 0)tas[j] = (tas[j - 1] * t + dp[j]) % MOD;
				newdp[j] += tas[j];
				newdp[j] %= MOD;
			}
		}
		for (int j = 0; j <= c; ++j)
		{
			dp[j] = newdp[j] % MOD;
		}
	}
	std::cout << dp[c] << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
#define chmax(x,y) x=max(x,y)
//biedge connected component
//bs???bridge,cc???????????£??????????????\???
typedef vector<int> vi;
typedef pair<int,int> P;
const int MAX_V=100;
vector<int> G[MAX_V];
int ord[MAX_V];
bool inS[MAX_V];
stack<int> roots,S;
vector<vi> cc;
vector<P> bs;
int cnt;
int N,M;
int cmp[MAX_V];
vector<int> cG[MAX_V];
int n[MAX_V];
void vis(int v,int p){
	ord[v]=++cnt;
	S.push(v);
	inS[v]=true;
	roots.push(v);
	for(int u:G[v]){
		if(ord[u]==0){
			vis(u,v);
		}else if(u!=p&&inS[u]){
			while(ord[roots.top()]>ord[u]) roots.pop();
		}
	}
	if(v==roots.top()){
		bs.pb(P(p,v));
		vector<int> vc;
		while(true){
			int w=S.top();S.pop();
			inS[w]=false;
			vc.pb(w);
			cmp[w]=cc.size();
			if(v==w) break;
		}
		roots.pop();
		n[cc.size()]=vc.size();
		cc.pb(vc);
	}
}
void bridge(){
	rep(i,N) if(ord[i]==0){
		vis(i,-1);
		bs.pop_back();	//P(-1,hoge)
	}
	for(P p:bs){
		int x=cmp[p.fs],y=cmp[p.sc];
		cG[x].pb(y),cG[y].pb(x);
	}
}
map<string,int> msi;
/*int rec(int v,int p,int x,int y,int e){
	if(x<0||y<0) return -inf;
	int& val=dp[v][x][y][e]=-inf;
	if(val>=0) return val;
	if(e==0){
		if(x==0&&y==0) return val=0;
		assert(false);
	}
	int w=G[v][e-1];
	if(w==p) return val=rec(v,p,x,y,e-1);
	rep(i,sz[w]+1){
		chmax(val,rec(v,p,x-i,y,e-1)+u[w][i]);
		chmax(val,rec(v,p,x,y-i,e-1)+d[w][i]);
	}
	if(e==G[v].size()){
		chmax(u[v][x],val+x*y);
		chmax(d[v][y],val+x*y);
	}
	return val;
}*/
int sz[MAX_V];
int u[MAX_V][MAX_V+1],d[MAX_V][MAX_V+1];
int t[MAX_V+1][MAX_V+1],nt[MAX_V+1][MAX_V+1];
int inf=1e8;
void dfs(int v,int p){
	for(int w:cG[v]) if(w!=p) dfs(w,v);
	rep(i,101) rep(j,101) t[i][j]=nt[i][j]=-inf;
	t[0][0]=0;
	for(int w:cG[v]){
		if(w==p) continue;
		rep(i,sz[v]+1) rep(j,sz[v]+1){
			rep(k,sz[w]+1){
				chmax(nt[i+k][j],t[i][j]+u[w][k]);
				chmax(nt[i][j+k],t[i][j]+d[w][k]);
			}
		}
		sz[v]+=sz[w];
		rep(i,100+1) rep(j,100+1) t[i][j]=nt[i][j],nt[i][j]=-inf;
	}
	rep(i,sz[v]+1) rep(j,sz[v]+1){
		chmax(u[v][i+n[v]],t[i][j]+(i+n[v])*(j+n[v]));
		chmax(d[v][j+n[v]],t[i][j]+(i+n[v])*(j+n[v]));
	}
/*	show(v);
	show(sz[v]);
	show(sz[v]+n[v]);
	rep(i,sz[v]+n[v]+1){
		printf("u[%d][%d]=%d\n",v,i,u[v][i]);
		printf("d[%d][%d]=%d\n",v,i,d[v][i]);
	}*/
	sz[v]+=n[v];
}
int main(){
	cin>>N>>M;
	rep(i,N){
		string s;
		cin>>s;
		msi[s]=i;
	}
	rep(i,M){
		string s,t;
		cin>>s>>t;
		int x=msi[s],y=msi[t];
		G[x].pb(y);
		G[y].pb(x);
	}
	bridge();
	dfs(0,-1);
	int ans=0;
	rep(i,N+1) chmax(ans,max(u[0][i],d[0][i]));
	cout<<ans<<endl;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

    string S;
    cin >> S;

    ll ans = 0;
    ll Slen = S.length();
    ll num = 0;
    for(int i = 0; i < Slen; i++){
      if(S[i] == '1'){
        ans = (ans + modpow(3, Slen-i-1, MOD)*modpow(2, num, MOD))%MOD;
        num++;
      }
    }

    ans = (ans + modpow(2, num, MOD))%MOD;

    
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String s = new StringBuffer(sc.nextLine()).reverse().toString();

        int i = Character.getNumericValue(s.charAt(0));
        if (i == 3) {
            System.out.println("bon");
        } else if (i ==0 || i == 1 || i == 6|| i == 8) {
            System.out.println("pon");
        } else {
            System.out.println("hon");
        }
    }
}

Measured memory_bytes: 35788