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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

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

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

int h, w;
int seen[1010][1010];

vector<string> mp;
int dx[4] = {0, -1, 0, 1};
int dy[4] = {-1, 0, 1, 0};

void bfs(queue<P> que, int lv)
{
  if (que.empty()) return;
  queue<P> tmp;

  // 歩き
  while(!que.empty())
  {
    P tp = que.front();
    tmp.push(tp);
    que.pop();
    for(int i = 0; i < 4; ++i)
    {
      int ny = tp.first  + dy[i];
      int nx = tp.second + dx[i];

      if (ny < 0 || h <= ny) continue;
      if (nx < 0 || w <= nx) continue;

      if (seen[ny][nx] == 0 && mp[ny][nx] == '.')
      {
        seen[ny][nx] = lv;
        que.push(P(ny, nx));
        tmp.push(P(ny, nx));
      }
    }
  }

  // ワープ
  queue<P> next_que;
  while(!tmp.empty())
  {
    P tp = tmp.front();
    tmp.pop();
    for(int y = -2; y <= 2; ++y)
    {
      int ny = tp.first + y;
      if (ny < 0 || h <= ny) continue;

      for(int x = -2; x <= 2; ++x)
      {
        int nx = tp.second + x;
        if (nx < 0 || w <= nx) continue;

        if (seen[ny][nx] == 0 && mp[ny][nx] == '.')
        {
          seen[ny][nx] = lv + 1;
          next_que.push(P(ny, nx));
        }
      }
    }
  }
  bfs(next_que, lv + 1);
}

void solve()
{
  int cy, cx;
  int dy, dx;

  cin >> h >> w;
  cin >> cy >> cx;
  cin >> dy >> dx;

  mp.resize(h);
  cx--; cy--;
  dx--; dy--;
  for(int i = 0; i < h; ++i)
  {
    cin >> mp[i];
  }

  queue<P> que;
  que.push(P(cy, cx));
  seen[cy][cx] = 1;

  bfs(que, 1);
  /*
  for(int ih = 0; ih < h; ++ih)
  {
    for(int iw = 0; iw < w; ++iw)
    {
      cout << seen[ih][iw];
    }
    cout << endl;
  }
  //*/
  cout << seen[dy][dx] - 1;

}

int main()
{
  fastio;
  solve();

  return 0;
}

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

int main() {
int n,a[3][3],b[10];
bool appear[3][3];
for(int i=0;i<3;i++){
	for(int j=0;j<3;j++){
		cin >> a[i][j];
	}
}
cin >> n;
for(int i=0;i<n;i++) cin >> b[i];
for(int i=0;i<n;i++){
	for(int j=0;j<n;j++){
		appear[i][j] = false;
		for(int k=0;k<n;k++){
			if(a[i][j] == b[k]) appear[i][j] = true;
		}
	}
}
string ans = "No";
for(int i=0;i<3;i++){
	if(appear[i][0] and appear[i][1] and appear[i][2]) ans = "Yes";
}
for(int i=0;i<3;i++){
	if(appear[0][i] and appear[1][i] and appear[2][i]) ans = "Yes";
}
	if(appear[0][0] and appear[1][1] and appear[2][2]) ans = "Yes";
	if(appear[0][2] and appear[1][1] and appear[2][0]) ans = "Yes";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
char a[5],R[];h,b;main(i){for(;scanf("%s%s",R,a)*R[1];h=!printf("%d %d\n",h,b/2-h)){for(b=4;b--;h+=R[b]==a[b])R[R[b]]++,R[a[b]]--;for(i=47;++i<58;R[i]=0)b+=!R[i];}}

Measured memory_bytes: 0
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<cstdlib>
#include<list>
#include<set>
#include<numeric>

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

int A[1010];

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

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

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

Measured memory_bytes: 3136
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
using P = pair<int, int>;
int h, w, m;
vector< int > x, y, ch(3e5, 0), cw(3e5, 0);
vector< set<int> > x2y(3e5, set<int>() );
int main(void){
    scanf("%d %d %d", &h, &w, &m);
    x.assign(m, 0);
    y.assign(m, 0);
    for(int i=0;i<m;i++){
        scanf("%d %d", &x[i], &y[i]);
        ch[--x[i]]++;
        cw[--y[i]]++;
        x2y[x[i]].insert(y[i]);
    }
    vector< P > ph, pw;
    for(int i=0;i<h;i++) ph.push_back(P(ch[i], i));
    for(int i=0;i<w;i++) pw.push_back(P(cw[i], i));
    sort(ph.begin(), ph.end(), greater<P>());
    sort(pw.begin(), pw.end(), greater<P>());
    bool flg = false;
    int ans = 0;
    for(int i=0;i<h;i++){
        if(i > 0 && ph[i].first < ph[i-1].first) break;;
        for(int j=0;j<w;j++){
            if(j > 0 && pw[j].first < pw[j-1].first) break;;
            int tmp = ph[i].first + pw[j].first;
            auto itr = x2y[ ph[i].second ].find( pw[j].second );
            if(itr != x2y[ ph[i].second ].end()) tmp--;
            else flg = true;
            ans = max(ans, tmp);
            if(flg) break;
        }
        if(flg) break;
    }
    printf("%d\n", ans);

}


Measured memory_bytes: 37048
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

int main() {
	int X, A, B;
	cin >> X >> A >> B;
	if (A >= B) cout << "delicious" << endl;
	else if ((B - A) <= X) cout << "safe" << endl;
	else cout << "dangerous" << endl;
	return 0;
}

Measured memory_bytes: 3556
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>


using namespace std;


int main() {

	int count = 0, ans;
	string s;
	bool key = false;

	cin >> s;

	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'A') {
			key = true;
		}
		if (key) {
			count++;
		}
		if (s[i] == 'Z') {
			ans = count;
		}
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 832
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, sum;
  cin >> N;
  sum = 0;
  int a=10, b=1;
  for (int i =0 ; i <8 ; i++) {
  sum += (N%a)/b;
  a*=10;
  b*=10;
  } 
  if (N%sum == 0) {
  cout << "Yes" << endl;
  }
  else {
  cout << "No" << endl;
  }
}

Measured memory_bytes: 256
/**
 *   author: malviyanshiv
 *   created: 01 February 2019  11:39:26
**/

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for(int i = a; i < b; i++)
#define RREP(i, a, b) for(int i = a-1; i >= b; i--)

#define FORE(a) for(auto ele : a )
#define PB push_back
#define MP make_pair
#define MOD 1000000007
#define INF 0x7fffffff
#define F first
#define S second
#define TC int t; cin >> t; while(t--)
#define ALL(a) begin(a), end(a)

typedef long long ll;
typedef pair< int, int > PII;


void optimizeIO(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
}

int main(){
    optimizeIO();

    ll n, w;
    cin >> n >> w;
    vector<ll> dp(100005, 10000000000000);
    vector<ll> vi(105), wi(105);
    REP(i, 0, n)
        cin >> wi[i] >> vi[i];
    dp[0] = 0;
    REP(i, 0, n){
        RREP(j, 100003, 0){
            if( j >= vi[i] )
                dp[j] = min( dp[j], dp[j-vi[i]] + wi[i]);
        }
    }

    RREP(i, 100001, 0){
        if( dp[i] <= w ){
            cout << i << endl;
            return 0;
        }
    }
    
    return 0;
}

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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(2e5) + 17;

struct matrix {
    int n;
    vector< vector<ll> > g;

    matrix() = default;

    matrix(int n) : n(n) {
        g.resize(n);

        forn (i, n)
            g[i].resize(n);
    }

    vector<ll>& operator[](int i) {
        return g[i];
    }
};

matrix operator *(matrix& a, matrix& b) {
    int n = a.n;
    matrix c(n);

    forn (i, n)
        forn (j, n)
            forn (k, n)
                c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % INF;

    return c;
}

int n;
ll k;
int a[100][100];

bool read() {
    if (!(cin >> n >> k))
        return false;

    forn (i, n)
        forn (j, n)
            cin >> a[i][j];

    return true;
}

matrix binpow(matrix a, ll n) {
    matrix res(a.n);

    forn (i, a.n)
        res[i][i] = 1;

    for (; n > 0; n /= 2, a = a * a)
        if (n & 1)
            res = res * a;

    return res;
}

void solve() {
    matrix g(n);

    forn (i, n)
        forn (j, n)
            g[i][j] = a[i][j];

    g = binpow(g, k);
    ll res = 0;

    forn (i, n)
        forn (j, n) 
            res = (res + g[i][j]) % INF;

    cout << res << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
#ifdef SEREZHKA
    freopen("file.in", "r", stdin);
#endif
    
    while (read())
        solve();
    
    return 0;
}



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

#define INF (2e9)
#define FOR(i, a, b) for (ll (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)

using namespace std;

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

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

using ll = long long;
using ld = long double;

#define ALL(x) (x).begin(), (x).end()
template<class T>
using vc = vector<T>;
using vi = vc<ll>;
using vvi = vc<vi>;

template<class T>
using va = valarray<T>;
using vad = va<ld>;
using vai = va<ll>;

using pii = pair<ll, ll>;

vi Read(ll n) {
    auto      v = vi(n);
    for (auto i = std::size_t(0); i < n; ++i) {
        cin >> v[i];
    }
    return v;
}

template<class T>
void DumpRow(const T& A) {
    for (const auto& value : A)
        cout << value << "\n";
}

template<class T>
void DumpColumn(const T& A) {
    auto isFirst = true;
    for (const auto& value : A) {
        if (isFirst) {
            cout << value;
            isFirst = false;
        } else {
            cout << " " << value;
        }

    }
    cout << endl;
}

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

    ll n;
    cin >> n;
    const auto a = Read(n);
    ll m;
    cin >> m;
    const auto b = Read(m);

    auto ans = vi();
    set_intersection(ALL(a), ALL(b), inserter(ans, ans.end()));

    DumpRow(ans);

    return 0;
}



Measured memory_bytes: 6576
import math


A,B,H,M = map(int, input().split())

jishin = [0.0, A]
hunshin = [0.0, B]
angle_ji = (H + (M / 60)) / 12 * 2 * math.pi
angle_hun = (M / 60) * 2 * math.pi

def func(x,y, ang):
    return (math.cos(ang) * x - math.sin(ang) * y, math.sin(ang) * x + math.cos(ang) * y)

nxt_ji_x, nxt_ji_y = func(0.0, A, angle_ji)
nxt_hu_x, nxt_hu_y = func(0.0, B, angle_hun)

ans = math.sqrt(abs(nxt_ji_x - nxt_hu_x)**2 + abs(nxt_ji_y - nxt_hu_y)**2)
print(ans)


Measured memory_bytes: 9596
H,W = map(int, input().split())

#迷路の初期化
a = [[-1] * (W+2) for i in range(H+2)]
for i in range(1,H+1):
    s = input()
    for j in range(1,W+1):
        if s[j-1] == ".":
            a[i][j] = 0
        elif s[j-1] == "#":
            a[i][j] = -1
        else:
            print("ERROR")

#dpの初期化
dp_sum = [[0] * (W+2) for i in range(H+2)]
#step
stepdic = {}
#stepdxy = [[1,0],[-1,0],[0,1],[0,-1]]
stepdxy = [[1,0],[0,1]]

def do_step(n):
    stepok = 0
    if n == 1:
        x,y = 1,1
        a[x][y] = -9
        for dx,dy in stepdxy:
            if a[x+dx][y+dy] == 0 or a[x+dx][y+dy] == n:
                dp_sum[x+dx][y+dy] += 1
                a[x+dx][y+dy] = n
                stepdic.setdefault(n,[]).append([x+dx,y+dy])
                stepok = 1
    if n-1 in stepdic.keys():
        for x,y in stepdic[n-1]:
            for dx,dy in stepdxy:
                if a[x+dx][y+dy] == 0:
                    dp_sum[x+dx][y+dy] += dp_sum[x][y]
                    a[x+dx][y+dy] = n
                    stepdic.setdefault(n,[]).append([x+dx,y+dy])
                    stepok = 1
                elif a[x+dx][y+dy] == n:
                    dp_sum[x+dx][y+dy] += dp_sum[x][y]
    return stepok

stepn = 1
while do_step(stepn) == 1:
    stepn += 1

print(dp_sum[H][W] % (10**9+7))

Measured memory_bytes: 307200
#include<stdio.h>
int main() {

	int x;

	scanf("%d", &x);

	if (400 <= x && x <= 599)
		printf("8");
	else if (600 <= x && x <= 799)
		printf("7");
	else if (800 <= x && x <= 999)
		printf("6");
	else if (1000 <= x && x <= 1199)
		printf("5");
	else if (1200 <= x && x <= 1399)
		printf("4");
	else if (1400 <= x && x <= 1599)
		printf("3");
	else if (1600 <= x && x <= 1799)
		printf("2");
	else if (1800 <= x && x <= 1999)
		printf("1");

	return 0;
}

Measured memory_bytes: 2088
#include <iostream>
#include <complex>
using namespace std;
using C = complex<double>;

int main(){
  C v[4];
  double x[4], y[4];
  while(cin >> x[0] >> y[0]){
    v[0] = C(x[0], y[0]);
    for(int i=1;i<4;i++){
      cin >> x[i] >> y[i];
      v[i] = C(x[i], y[i]);
    }
    C PA = v[0] - v[3], PB = v[1] - v[3], PC = v[2] - v[3];
    double pab = (conj(PA) * PB).imag(), pbc = (conj(PB) * PC).imag(), pca = (conj(PC) * PA).imag();
    if(pab * pbc > 0 && pbc * pca > 0)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}


Measured memory_bytes: 3192
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// 自分の得意な言語で
		// Let's チャレンジ！！

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();
		double maxSum = 0;
		double tmpSum = 0;
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			int num = sc.nextInt();
			list.add(num);
			tmpSum += num;
			if (list.size() >= k) {
				if (tmpSum > maxSum) {
					maxSum = tmpSum;
				}
				tmpSum -= list.get(i - (k - 1));
			}
		}

		double re = (maxSum + k) / 2;
		System.out.println(re);
	}

}

Measured memory_bytes: 88124
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e2+5;

int n;
pair < string , pair < int , int > > sp[N];

bool cmp(pair < string , pair < int , int > > a , pair < string , pair < int , int > > b){
    if(a.first < b.first)
        return 1;
    if(a.first == b.first){
        if(a.second.first > b.second.first)
            return 1;
    }
    return 0;
}

int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        string s;
        int p;
        cin >> s >> p;
        sp[i] = {s , {p , i}};
    }
    sort(sp + 1 , sp + n + 1 , cmp);
    for(int i = 1; i <= n; i++){
        cout << sp[i].second.second << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n; vector<int>vi;
struct seg{
	int seg[(1<<19)];
	void init(){
		fill(seg,seg+(1<<19),INF);
	}
	void update(int k,int a){
		k+=(1<<18)-1; seg[k]=a;
		while(k>0){
			k=(k-1)/2;
			seg[k]=min(seg[k*2+1],seg[k*2+2]);
		}
	}
	int query(int a,int b,int k,int l,int r){
		if(r<a || b<l) return INF;
		if(a<=l && r<=b) return seg[k];
		else{
			int vl=query(a,b,k*2+1,l,(l+r)/2);
			int vr=query(a,b,k*2+2,(l+r)/2+1,r);
			return min(vl,vr);
		}
	}
}O,E;
int rev[200005];
int main(){
	cin >> n;
	O.init(); E.init();
	for(int i=1;i<=n;i++){
		int a; cin >> a; vi.pb(a);
		if(i%2 == 1) O.update(i,a);
		else E.update(i,a);
		rev[a] = i;
	}
	set<pair<int,P> >S;
	S.insert(mp(O.query(1,n,0,0,(1<<18)-1),mp(1,n)));
	vector<int>ans;
	for(int i=1;i<=n/2;i++){
		pair<int,P>Q = *S.begin(); S.erase(S.begin());
		int L = Q.sc.fi,R = Q.sc.sc,pos = rev[Q.fi];
		ans.pb(Q.fi);
		if(pos%2 == 0){
			ans.pb(O.query(pos+1,R,0,0,(1<<18)-1));
		}
		else{
			ans.pb(E.query(pos+1,R,0,0,(1<<18)-1));
		}
		int pos2 = rev[ans[ans.size()-1]];
		if(L != pos){
			if(L%2 == 0){
				S.insert(mp(E.query(L,pos-1,0,0,(1<<18)-1),mp(L,pos-1)));
			}
			else{
				S.insert(mp(O.query(L,pos-1,0,0,(1<<18)-1),mp(L,pos-1)));
			}
		}
		if(pos+1<pos2){
			if(pos%2 == 1){
				S.insert(mp(E.query(pos+1,pos2-1,0,0,(1<<18)-1),mp(pos+1,pos2-1)));
			}
			else{
				S.insert(mp(O.query(pos+1,pos2-1,0,0,(1<<18)-1),mp(pos+1,pos2-1)));
			}
		}
		if(pos2 != R){
			if(pos2%2 == 1){
				S.insert(mp(E.query(pos2+1,R,0,0,(1<<18)-1),mp(pos2+1,R)));
			}
			else{
				S.insert(mp(O.query(pos2+1,R,0,0,(1<<18)-1),mp(pos2+1,R)));
			}
		}
	}
	for(int i=0;i<ans.size();i++) printf("%d%c",ans[i],(i==ans.size()-1)?'\n':' ');
}

Measured memory_bytes: 11124
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	string s, t;
	cin >> s >> t;
	int ans = 0;
	for(int i = 0; i < 3; i++){
		if(s[i] == t[i]) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
all = abs(a[0]) + abs(a[n-1])
for i in range(n-1):
	all += abs(a[i+1] - a[i])
for u in range(n):
	if u == 0:
		print(all + abs(a[1]) - abs(a[0]) - abs(a[1] - a[0]))
	elif u == n-1:
		print(all + abs(a[n-2]) - abs(a[n-1]) - abs(a[n-1] - a[n-2]))
	else:
	    b = abs(a[u] - a[u-1])
	    c = abs(a[u+1] - a[u])
	    d = abs(a[u+1] - a[u-1])
	    print(all - b - c + d)

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

int main() {
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;
    cout << min(N,K) * X + max(N-K, 0) * Y << endl;
}


Measured memory_bytes: 256
{
  const main = (
    input: string
  ): void | string | number | string[] | number[] => {
    const r = _reader(input)
    const S = r.s()

    let a = 0
    let b = 0

    for (let i = 0; i < S.length; i++) {
      if (S[i] === '01'[i % 2]) {
        a++
      } else {
        b++
      }
    }

    return Math.min(a, b)
  }

  const _reader = (str: string, i = 0) => {
    const lines = str.trim().split('\n')
    const s = () => lines[i++] || ''
    const n = () => Number(s())

    const mn = (v: string[]) => v.map(Number)
    const sp = (v: string) => v.split(' ')
    const ss = () => sp(s())
    const nn = () => mn(ss())
    const nls = () => mn(lines.slice(i))
    const nnls = () => lines.slice(i).map(v => mn(sp(v)))

    return { lines, s, n, ss, nn, nls, nnls }
  }

  const _getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')
  const _res = main(_getInput())

  if (typeof _res === 'number' || typeof _res === 'string') console.log(_res)
  if (typeof _res === 'object') console.log(_res.join(' '))
}


Measured memory_bytes: 7372
s = input()
n = len(s) - 1
ans = 0
for bit in range(1 << n):
    now = 0
    for i in range(bit):
        if bit & (1 << i):
            ans += int(s[now : i + 1])
            now = i + 1
    ans += int(s[now : len(s)])
print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
 long A[3];
 cin>>A[0]>>A[1]>>A[2];
 sort(A,A+3);
 if(A[0]+A[1]==A[2]) cout<<"Yes"<<endl;
 else cout<<"No"<<endl;

return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long
#define inf 1000000001
using namespace std;
ll read(){
	char ch=getchar();ll x=0;int op=1;
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') op=-1;
	for (;isdigit(ch);ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
#define N 105
int n,cnt,head[N],vis[N],dep[N],mx[N],ans1;ll ans2;
struct edge{int to,nxt;}e[N<<1];
void adde(int x,int y){e[++cnt].to=y;e[cnt].nxt=head[x];head[x]=cnt;}
void ins(int x,int y){adde(x,y);adde(y,x);}
void dfs(int u,int pr){
	int ch=0;
	for (int i=head[u],v;i;i=e[i].nxt){
		v=e[i].to;if (v==pr) continue;
		dep[v]=dep[u]+1;ch++;
		dfs(v,u);
	}
//	cerr<<"u="<<u<<"; ch="<<ch<<'\n';
	mx[dep[u]]=max(mx[dep[u]],ch);
}
int main(){
	n=read();
	rep (i,1,n-1){int x=read(),y=read();ins(x,y);}
	ans1=ans2=inf;
	rep (i,1,n){
		rep (j,1,n) dep[j]=0;
		rep (j,0,n) mx[j]=0;
		dfs(i,0);//--->直径中心 
//		rep (j,1,n) cerr<<dep[j]<<' ';cerr<<'\n';
		ll tmp=1;int mxdep=1;
		rep (j,0,n) if (mx[j]) mxdep=j+2,tmp*=mx[j];
//		cerr<<mxdep<<'\n';
		if (mxdep<ans1||mxdep==ans1&&tmp<ans2) ans1=mxdep,ans2=tmp;
	}
	rep (i,1,n) for (int j=head[i],v;j;j=e[j].nxt){
		v=e[j].to;if (v>i) continue;
		rep (j,1,n) dep[j]=0;
		rep (j,0,n) mx[j]=0;
		dfs(v,i);dep[i]=0;dfs(i,v);
//		cerr<<"u="<<i<<", v="<<v<<'\n';
//		rep (j,0,n) cerr<<mx[j]<<' ';cerr<<'\n';
		ll tmp=2;int mxdep=1;
		rep (j,0,n) if (mx[j]) mxdep=j+2,tmp*=mx[j];
//		cerr<<mxdep<<'\n';
		if (mxdep<ans1||mxdep==ans1&&tmp<ans2) ans1=mxdep,ans2=tmp;
	}
	cout<<ans1<<' '<<ans2<<'\n';
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

int C[2][9];


void solve() {
  int geits = 0;
  int cnt = 0;
  sort(C[0], C[1]);
  do {
    int g, j;
    g = j = 0;
    for(int i = 0; i < 9; ++i) {
      if(C[0][i] > C[1][i]) g += C[0][i] + C[1][i];
      else                  j += C[0][i] + C[1][i];
    }
    if(g > j) ++geits;
    ++cnt;
  } while(next_permutation(C[0], C[1]));

  double tmp = (double)geits/cnt;
  printf("%.5f %.5f\n", tmp, 1-tmp);
}

main() {
  int N;
  cin >> N;
  for(int t = 0; t < N; ++t) {
    for(int i = 0; i < 2; ++i) {
      for(int j = 0; j < 9; ++j) {
	cin >> C[i][j];
      }
    }
    solve();
  }
}

Measured memory_bytes: 908
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

long long mod = (long long)1e9 + 7;
long long memo[200010] = {1};
long long memoinv[200010] = {1};

long long int fact(long long n){
	if(memo[n] != 0) return memo[n];
	long long int ans = 1;
	for(int i = 1; i <= n; i++){
		ans = (ans * i) % mod;
		memo[i] = ans;
	}
	return ans % mod;
}

long long inverse(long long a, long long n = mod - 2){
	if(a == 0) return 1;
	if(a == 1) return 1;
	long long d;
	if(n == 0){
		return 1;
	} else if(n % 2 == 0){
		d = inverse(a, n / 2);
		return (d * d) % mod;
	} else{
		return (a * inverse(a, n - 1)) % mod;
	}
}

long long fact_inverse(long long a){
	if(memoinv[a] != 0) return memoinv[a];
	return memoinv[a] = inverse(fact(a));
}

long long comb(long long x, long long y){
	return ((((fact(x + y) * fact_inverse(x)) % mod) * fact_inverse(y)) % mod);
}

int main(){
	long long h, w, a, b, ans = 0;
	scanf("%lld%lld%lld%lld", &h, &w, &a, &b);
	fact(h + w);
	for(long long i = b; i < w; i++){
		ans += (comb(h - a - 1, i) * comb(a - 1, w - i - 1)) % mod;
		ans %= mod;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
vector < pair<ll, ll> > a[100010];
ll nm[100010], n;
bool vis[100010];
bool dfs(ll x, ll papa, ll val){
    if(vis[x]){
        if(val!=nm[x]){
            return 0;
        }
        return 1;
    }
    vis[x]=1;
    nm[x]=val;
    ll tmp;
    for(ll i=0; i<a[x].size(); ++i){
        if(a[x][i].fs==papa)
            continue;
        tmp=dfs(a[x][i].fs, x, a[x][i].sc-val);
        if(!tmp)
            return 0;
    }
    return 1;
}
bool chck(ll x, ll y){
    memset(vis, 0, sizeof vis);
    bool tmp=dfs(x, -1, y);
    if(!tmp)
        return 0;
    for(ll i=1; i<=n; ++i){
        if(nm[i]<=0)
            return 0;
    }
    return 1;
}
bool v[100010][2];
ll nmm[100010][2];
ll dfs1(ll x, ll papa, ll val, ll p){
    if(v[x][p]){
        if(val!=nmm[x][p]){
            return 0;
        }
        if(v[x][0]&&v[x][1]){
            if((nmm[x][1]-nmm[x][0])%2 || (nmm[x][1]-nmm[x][0])<=0){
                return 0;
            }
        }
        return 1;
    }
    v[x][p]=1;
    nmm[x][p]=val;
    if(v[x][0]&&v[x][1]){
            if((nmm[x][1]-nmm[x][0])%2 || (nmm[x][1]-nmm[x][0])<=0){
                return 0;
            }
        }
    bool tmp;
    for(ll i=0; i<a[x].size(); ++i){
        if(a[x][i].fs==papa)
            continue;
        tmp=dfs1(a[x][i].fs, x, a[x][i].sc-val, !p);
        if(!tmp)
            return 0;
    }
    return 1;
}
int main(){
  ll m, x, y, z;
  while(cin>>n>>m){
    for(ll i=1; i<=n; ++i)
        a[i].clear();
    for(ll i=0; i<m; ++i){
        cin>>x>>y>>z;
        a[x].push_back(mk(y, z));
        a[y].push_back(mk(x, z));
    }
    memset(vis, 0, sizeof vis);
    bool tmp;
    tmp=dfs1(1, -1, 0, 0);
    if(!tmp){
        cout<<0<<endl;
        continue;
    }
    else{
        if(v[1][1]){
            if(chck(1, (nmm[1][1]-nmm[1][0])/2))
                cout<<1<<endl;
            else
                cout<<0<<endl;
            continue;
        }
    }
    tmp=dfs(1, -1, 1);
    if(!tmp){
        cout<<0<<endl;
    }
    else{
        ll mn=1, val=1, ans;
        for(ll i=1; i<=n; ++i){
            if(nm[i]<mn){
                mn=nm[i];
                val=i;
            }
        }
//        cout<<val<<endl;
        ll st=1, nd=999999999, md;
        while(st<nd){
            md=(st+nd+1)/2;
            if(chck(val, md)){
                st=md;
            }
            else{
                nd=md-1;
            }
        }
        if(chck(val, st)){
            ans=st;
        }
        else{
            ans=st-1;
        }
        cout<<ans<<endl;
    }
  }
  return 0;
}




Measured memory_bytes: 22528
#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
using namespace std;
#define eps 0.000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 65536*16
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
#define int long long
	int a, b;
	cin >> a >> b;
	vector<int> tate, yoko;
	REP(i, a) {
		int c;
		cin >> c;
		tate.push_back(c);
	}
	REP(i, b) {
		int c;
		cin >> c;
		yoko.push_back(c);
	}
	sort(tate.begin(), tate.end(), greater<int>());
	sort(yoko.begin(), yoko.end(), greater<int>());
	for (int i = 1; i < tate.size(); ++i) {
		if (tate[i] == tate[i - 1]) {
			cout << 0 << endl;
			return 0;
		}
	}
	for (int i = 1; i < yoko.size(); ++i) {
		if (yoko[i] == yoko[i - 1]) {
			cout << 0 << endl;
			return 0;
		}
	}
	a = 0;
	b = 0;
	tate.push_back(0);
	yoko.push_back(0);
	long long remaining = 0;
	long long ans = 1;
	for(int i = (tate.size()-1) * (yoko.size()-1); i >= 1; --i) {
		if (tate[a] == i) {
			if (yoko[b] == i) {
				remaining += a + b;
				a++;
				b++;
			}
			else {
				remaining += (b-1LL);
				ans *= b;
				ans %= MAX_MOD;
				a++;
			}
		}
		else if (yoko[b] == i) {
			remaining += (a-1LL);
			ans *= a;
			ans %= MAX_MOD;
			b++;
		}
		else {
			if (remaining == 0) {
				cout << 0 << endl;
				return 0;
			}
			ans *= remaining;
			remaining--;
			ans %= MAX_MOD;
		}
	}
	cout << ans << endl;
	return 0;
}

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

queue<int> que;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    string s;
    cin>>n>>m>>s;
    vector<int> pre(n+1);
    for(int i = 0; i < n+1; i++){
        if(s[i]=='0')
            que.push(i);
        if(que.empty()){
            cout<<-1<<endl;
            return 0;
        }
        int pos = que.front();
        int len = i-pos;
        while(len>m){
            if(que.empty()){
                cout<<-1;
                return 0;
            }
            que.pop();
            pos=que.front();
            len = i-pos;
        }
        pre[i] = pos;
    }
    vector<int> ans;
    int now = n;
    while(now){
        int nxt = pre[now];
        ans.push_back(now-nxt);
        if(now==nxt){
            cout<<-1<<endl;
            return 0;
        }
        now = nxt;
    }
    reverse(ans.begin(), ans.end());
    for(auto it : ans) cout<<it<<' ';
    return 0;
}

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

int main(){
  char c;
  scanf("%s", &c);

  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
    puts("vowel");
  }else{
    puts("consonant");
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

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

  if(s == 1e18){
    cout << "0 0 1000000000 0 1000000000 1000000000" << endl;
    return 0;
  }

  ll x1, y1, x2, y2, x3, y3;
  x1 = 0;
  y1 = 0;
  x3 = 1;
  y3 = 1e9;
  
  // |x2 * y3 - x3 * y2| = s
  // (s + x3 * y2) mod y3 = 0
  // y3 - (s mod y3) = x3 * y2
  y2 = y3 - s % y3;
  x2 = (s + x3 * y2) / y3;

  cout << x1 << " " << y1 << " ";
  cout << x2 << " " << y2 << " ";
  cout << x3 << " " << y3 << endl;

	return 0;
}



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

    int main (){
        ll h,w;
        cin >> h >> w;
        if(h==1 || w==1){
            cout << 1 << endl;
        }
        else{
            cout << (h*w+1)/2 << endl;
        }
        return 0;
    }

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

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;

//vector<vector<ll> > comb(ll n, ll b){





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

  priority_queue<ll> q;
  ll tmp;
  
  rep(i,n) {
    cin >> tmp;
    q.push(tmp);
  }

  q.push(x);

  ll ans = q.top();
  q.pop();
  ll tmp3 = q.top();
  q.push(ans);
  ans -= tmp3;
  ll tmp1, tmp2;
  
  rep(i, n) {
    tmp1 = q.top();
    q.pop();
    tmp2 = q.top();
    // cout << tmp1 -tmp2 << endl;
    ans = __gcd(ans, abs(tmp1-tmp2));
    // cout << ans << endl;
  }
  

  cout << ans << endl;
  
  
}


Measured memory_bytes: 1400
/*
author: orthodoxparadox
27-Aug-2018
12:21:42
*/

#include <bits/stdc++.h>

using namespace std;
#define dbl long double
#define int ll
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define fup(i, a, n) for (ll i = a; i < n; i++)
#define fdw(i, a, n) for (ll i = n-1; i >= a; i--)
#define fnu for(ll i = 0; i < n; i++)
#define fnd for(ll i = n-1; i >= 0; i--)
#define fau(i, v) for(auto i:v)
#define rev(s) reverse(all(s))
#define oill ostream_iterator<ll>(cout, " ")
#define oiint ostream_iterator<int>(cout, " ") 
#define pb emplace_back
#define push_back emplace_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define zero(a) memset(a, 0, sizeof(a))
#define onlyunique(v) v.erase(unique(all(v)), v.end()); //only for sorted vector
// #define x real()
// #define y imag()
typedef complex<double> point;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#ifdef __APPLE__
#define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)

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...);
}
#else
#define dbg(...)
#endif

int __gcd(int a, int b)
{
	return b ? __gcd(b, a%b) : a;
}

// for set of pairs
struct pair_hash {
    inline std::size_t operator()(const std::pair<int,int> & v) const {
        return v.first*31+v.second;
    }
};

const int mod = 1e9 + 7;

vector<int> binarycut(int x){
	vector<int> v;
	while(x){
		if(x&1) v.pb(1);
		else v.pb(0);
		x>>=1;
	}
	reverse(all(v));
	return v;
}

int takemod(int a){
	return ((a%mod)+mod)%mod;
}

int fast_exp(int base, int expo) {
	int res=1;
	while(expo>0) {
		if(expo&1) res=(res*base)%mod;
		base=(base*base)%mod;
		expo>>=1;
	}
	return res;
}

int modinv(int a){
	return takemod(fast_exp(takemod(a), mod-2));
}

// void siev(int n)
// {
// 	sieve[0]=false;
// 	sieve[1]=false;
// 	for(int i=2; i<=sqrtl(n); i++)
// 	{
// 		if(sieve[i])
// 		{
// 			for(int j=i; i*j<=n; j++)
// 			{
// 			sieve[i*j]=false;
// 			}
// 		}
// 	}
// }

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	#ifdef __APPLE__
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
	#endif
	time_t t1, t2;
	t1 = clock();

	int n;
	cin >> n;
	n = 2*n;
	int a[n];
	fnu cin >> a[i];
	sort(a, a+n);
	int ans = 0;
	for(int i = 0; i < n; i+=2)
	{
		ans += a[i];
	}
	cout << ans;
	t2 = clock();
	cerr << "time taken: " << t2-t1;
	return 0;
}

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
cards = gets.split.map(&:to_i).sort
changes = []
m.times do
  b, c = gets.split.map(&:to_i)
  changes << {num: c, count: b}
end
changes.sort! { |a, b| b[:num] <=> a[:num] }
used = 0
until used > n || changes.empty?
  current = changes.shift
  used += current[:count]
  current[:count].times do
    cards << current[:num]
  end
end
puts cards.sort[-n..-1].inject(:+)


Measured memory_bytes: 44804
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        FastReader sc = new FastReader();
        System.out.println((int)(3*Math.pow(sc.nextInt(),2)));
    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 22612
#include <stdio.h>

int main()
{
	int cost;
	int in,out;
	int money;
	int month;
	int i, over;
	while(1){
		scanf("%d", &cost);
		if(cost==0){
			break;
		}
		money=0;
		over=0;
		for(i=0; i<12; i++){
			scanf("%d %d", &in, &out);
			money+=(in-out);
			if(money>=cost){
				over++;
			}
		}
		month=i-(over-1);
		if(month>12){
			printf("NA\n");
		}
		else{
			printf("%d\n", month);
		}
	}
	return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N, M;
  cin >> N >> M;
  
  vector<int> h(N);
  for (int i = 0; i < N; i++) {
    cin >> h.at(i);
  }
  
  vector<bool> check(N, true);
  
  for(int i = 0; i < M; i++) {
    for(int j = 0; j < 2; j++) {
      int a,b;
      cin >> a >> b;
      if (h.at(a-1) <= h.at(b-1)) {
        check.at(a-1) = false;
      }
      if (h.at(a-1) >= h.at(b-1)) {
        check.at(b-1) = false;
      }
    }
  }
  
  int count = 0;
  
  for (int i = 0; i < N; i++){
    if (check.at(i) == true) {
      count++;
    }
  }
  cout << count << endl;
  
  return 0;
  
}

Measured memory_bytes: 3792
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var len = int.Parse(Console.ReadLine());
            var list = new List<Tuple<int, long, long, long>>();

            for (int i = 0; i < len; i++)
            {
                var input = Console.ReadLine().Split(' ');

                var taka = long.Parse(input[0]);
                var ao = long.Parse(input[1]);

                list.Add(new Tuple<int, long, long, long>(i, taka, ao, taka + ao));
            }

            var sortList = list.OrderByDescending(_ => _.Item4);

            var takaSum = sortList.Where((value, index) => index % 2 == 0).Sum(_ => _.Item2);
            var aoSum = sortList.Where((value, index) => index % 2 == 1).Sum(_ => _.Item3);

            Console.WriteLine(takaSum - aoSum);
        }
    }
}

Measured memory_bytes: 29756
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on

void main()
{
    auto S = sread();
    writeln(S[1] == 'B' ? "ARC" : "ABC");
}


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

int main() {
  int H, W; cin >> H >> W;
  vector<vector<int>> c(10, vector<int>(10));
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) cin >> c[i][j];
  }
  vector<vector<int>> A(H, vector<int>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) cin >> A[i][j];
  }
  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (A[i][j] != -1) ans += c[A[i][j]][1];
    }
  }
  cout << ans << endl;
}

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

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

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

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

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MAX_N = 105;

int ame[2][MAX_N];

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int N; cin >> N;
    REP(i,2)
    {
        REP(j,N)
        {
            cin >> ame[i][j];
        }
    }
    LL ans = 0;

    FOR(i,1,N+1)
    {
        dump("start")
        LL kouho = 0;
        REP(j,i)
        {
            dump(j)
            dump(ame[0][j])
            kouho += ame[0][j];
        }
        FOR(j,i,N+1)
        {
            dump(j)
            dump(ame[1][j])
            kouho += ame[1][j-1];
        }
        dump(kouho)
        ans = max(ans,kouho);
    }
    cout << ans << endl;


}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 2010
ll n, m, m1, m2;
vector<int> g[N];
int used[N];

void dfs(int u, int &a, int &b, int d){
	if(used[u]) return;
	used[u] = true;
	d++;
	if(d>=m1) a++;
	if(d>=m2) b++;
	for(int v: g[u]) dfs(v, a, b, d);
	used[u] = false;
}

int main(){
	cin>>n>>m;
	m1 = m/2+1; m2 = (m+1)/2+1;
	for(int i = 0; i < n-1; i++){
		int a, b;
		cin>>a>>b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	int res = n;
	rep(i, n){
		used[i] = true;
		int mf = 0;
		int r = 0;
		for(int v: g[i]){
			int a, b;
			a = b = 0;
			dfs(v, a, b, 0);
			chmax(mf, a-b);
			r += a;
		}
		chmin(res, r-mf);
		used[i] = false;
	}
	cout<<res<<endl;
	
	return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<vector>
#include<map>
#include<cstring>
#include<string>
#include<iostream>
using namespace std;
map<string,int>myhash;
int hashclock=0;
int g[2000][310][310];
vector<int>fg[310][310];
bool visit[2000];
int n;
int getnu(){
	string tss;
	cin>>tss;
	if(myhash.count(tss))
		return myhash[tss];
	hashclock++;
	myhash[tss]=hashclock;
	return hashclock;
}
void floyd(int i){
	for(int j=1;j<=hashclock;j++)
		for(int a=1;a<=hashclock;a++)
			for(int b=1;b<=hashclock;b++)
				if((g[i][a][j]!=0)&&(g[i][j][b]!=0))
					g[i][a][b]=1;
}
bool getans(){
	int x,y;
	x=getnu();
	y=getnu();
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int m;
		scanf("%d",&m);
		for(int j=1;j<=m;j++){
			int a=getnu(),b=getnu();
			g[i][a][b]=1;
			fg[a][b].push_back(i);
		}
	}
	bool flag=1;
	g[0][x][y]=1;
	while(flag){
		flag=0;
		for(int i=1;i<=hashclock;i++)
			for(int j=1;j<=hashclock;j++)
				if(g[0][i][j]){
					for(vector<int>::iterator it=fg[i][j].begin();it!=fg[i][j].end();it++)
						if(visit[*it]==false){
							for(int a=1;a<=hashclock;a++)
								for(int b=1;b<=hashclock;b++)
									if(g[*it][a][b])
										g[0][a][b]=1;
							visit[*it]=true;
							flag=1;
						}
				}
		floyd(0);
	}
	for(int i=1;i<=hashclock;i++)
		for(int j=1;j<=hashclock;j++)
			if((g[0][i][j]!=0)&&(g[0][j][i]!=0)){
				//cout<<i<<endl<<j<<endl;
				return 0;

			}
	return 1;

}
int main(){
    //freopen("in2.txt","r+",stdin);
	if(getans()){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 202888
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n,a,b,*h=map(int,open(0).read().split());i,j=0,2**30\n"
"while j-i>1:\n"
" k=c=(j+i)//2\n"
" for t in h:c+=min(0,(b*k-t)//(a-b))\n"
" if c<0:i=k\n"
" else:j=k\n"
"print(j)\n"
"\"";
  system(s);
  return 0;
}            

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

int main(){
    ll k,sum=0;
    cin>>k;
    rep(i,k){
        rep(j,k){
            rep(l,k){
                sum+=__gcd(i+1,__gcd(j+1,l+1));
            }
        }
    }
    cout << sum;
}

Measured memory_bytes: 3588
#include <stdio.h>

int check_number(int target, int a[], int start, int end) {
  int is_match = 0;

  while(start <= end) {
    int middle = (start + end) / 2;

    if (target == a[middle]) {
      is_match = 1;
      break;
    } else if (a[middle] < target) {
      start = middle + 1;
    } else {
      end = middle - 1;
    }
  }
  return is_match;
}

int binary(int a[], int b[], int n, int m) {
  int cnt = 0;

  for (int i = 0; i < m; i++) {
    if(check_number(b[i], a, 0, n-1)) {
      cnt++;
    }
  }
  return cnt;
}

int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int m;
  scanf("%d", &m);
  int b[m];
  for (int i = 0; i < m; i++) {
    scanf("%d", &b[i]);
  }
  printf("%d\n", binary(a, b, n, m));

  return 0;
}



Measured memory_bytes: 2308
times=int(input())
side=input().split(" ")
maax=0
suum=0
check=0
for i in side:
    suum+=int(i)

for i in side:
    if suum-int(i)<=int(i):
        check+=1
        break;

if check==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
long long n,a[5][200],ans,pre[200],suf[200];
int main()
{
    cin>>n;
    for(int i=0;i<2;i++)
    {
        for(int j=0;j<n;j++)
        {
            cin>>a[i][j];
        }
    }
    pre[0]=a[0][0];
    for(int i=1;i<n;i++)
    {
        pre[i]=pre[i-1]+a[0][i];
    }
    suf[n-1]=a[1][n-1];
    for(int i=n-2;i>=0;i--)
    {
        suf[i]=suf[i+1]+a[1][i];
    }
    for(int i=0;i<n;i++)
    {
        long long  temp=pre[i]+suf[i];
        ans=max(ans,temp);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
use std::io::Read;
use std::cmp::max;

fn main() {
  let mut buf = String::new();
  std::io::stdin().read_to_string(&mut buf).expect("fail to read");
  let mut iter = buf.split_whitespace();
  
  let h:usize = iter.next().unwrap().parse().unwrap();
  let w:usize = iter.next().unwrap().parse().unwrap();
  let k:usize = iter.next().unwrap().parse().unwrap();

  let mut dp = vec![vec![vec![0_i64; 4]; w + 1]; h + 1];
  let mut map = vec![vec![None; w + 1]; h + 1];
  
  for _i in 0 .. k {
    let r:usize = iter.next().unwrap().parse().unwrap();
    let c:usize = iter.next().unwrap().parse().unwrap();
    let v:i64 = iter.next().unwrap().parse().unwrap();
    map[r][c] = Some(v);
  }
  let map = map;
  
  for y in 1 ..= h {
    for x in 1 ..= w {
      if let Some(v) = map[y][x] {
        dp[y][x][1] = max(dp[y][x][1], max(*dp[y - 1][x].iter().max().unwrap() + v, dp[y][x - 1][0] + v));
        dp[y][x][2] = max(dp[y][x][2], dp[y][x - 1][1] + v);
        dp[y][x][3] = max(dp[y][x][3], dp[y][x - 1][2] + v);
      }
      
      dp[y][x][0] = max(*dp[y - 1][x].iter().max().unwrap(), dp[y][x - 1][0]);
      dp[y][x][1] = max(dp[y][x][1], dp[y][x - 1][1]);
      dp[y][x][2] = max(dp[y][x][2], dp[y][x - 1][2]);
      dp[y][x][3] = max(dp[y][x][3], dp[y][x - 1][3]);
    }
  }
  println!("{}", *dp[h][w].iter().max().unwrap()); 
}


Measured memory_bytes: 779216