akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

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
















int main(){
    int A, B, m;
    scanf("%d %d %d", &A, &B, &m);
    int a[100000], b[100000];
    int min1 = 1e9, min2 = 1e9;
    for(int i = 0; i < A; i++){
        scanf("%d", &a[i]);
        min1 = min(min1, a[i]);
    }
    for(int i = 0; i < B; i++){
        scanf("%d", &b[i]);
        min2 = min(min2, b[i]);
    }
    int ans = min1 + min2;
    for(int i = 0; i < m; i++){
        int x, y, c;
        scanf("%d %d %d", &x, &y, &c);
        ans = min(ans, a[x - 1] + b[y - 1] - c);
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"YES"<<endl;}else cout<<"NO"<<endl;//条件によってYes、Noを出力する

int main(){
    int n;
    cin>>n;
    vector<int64_t> a(n);
    rep(i,n){
        cin>>a[i];
    }
    int ans = n;
    all(a);
    for(int i=0;i<n-1;i++){
        if(a[i]*2<a[i+1]){
            ans = n-(i+1);
        }
        a[i+1] += a[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
//AOJ0118 Property Distribution
#include<cstdio>
char map[105][105];
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
int W,H;
void dfs(int x,int y,char ch){
    map[x][y]='.';
    for(int i=0;i<4;i++){
        int nx=x+dx[i],ny=y+dy[i];
        if(nx>=0&&nx<H&&ny>=0&&ny<W&&map[nx][ny]==ch)
            dfs(nx,ny,ch);
    }
}
int main(){
    while(scanf("%d%d",&H,&W),H!=0&&W!=0){
        int cnt=0;
        for(int i=0;i<H;i++)
            scanf("%s",map[i]);        
        for(int i=0;i<H;i++)
            for(int j=0;j<W;j++)
                if(map[i][j]!='.'){
                    cnt++;
                    dfs(i,j,map[i][j]);
                }
        printf("%d\n",cnt);
    }
    return 0;
}

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

#define int long long

signed main() {
    int n;
    cin >> n;
    int a = 1;
    while(true) {
        if(a*a>=n) break;
        a++;
    }
    if(a*a>n) a--;
    cout << a*a << endl;
    return 0;
}



Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val a = Array.fill(n)(sc.nextInt()-1)
  val map = a.zipWithIndex.map{case (e, i) => i -> e}.toMap
  val ans = map.count{ case (k, v) => map(v) == k} / 2
  println(ans)
}


Measured memory_bytes: 74832
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
 #define PI 3.141592653
using namespace std;

int A[101];

void solve(){
	int n; cin>>n;
	for(int i=1; i<n; i++){
		cin>>A[i];
	}
	ll ans =0;
	ans += A[1];
	for(int i=2; i<=n-1; i++){
		ans += min(A[i-1],A[i]);
	}
	ans += A[n-1];
	cout<<ans;

}


int main()
{ 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout<<fixed<<setprecision(12);
	int t =1; //cin>>t;
	for(int i=1; i<=t; i++){
		solve();
		cout<<"\n";
	}
	return 0;

}


Measured memory_bytes: 256
#include <cstdio>

unsigned long long T[100];

int main() {
    int N;

    scanf("%d", &N);

    T[0] = 2;
    T[1] = 1;

    for(int i = 2; i <= N; ++i) {
        T[i] = T[i-1] + T[i-2];
    }

    printf("%llu\n", T[N]);

    return 0;
}

Measured memory_bytes: 128
begin
	writeln('1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1');
end.


Measured memory_bytes: 1380
N,M = map(int, input().split())
arr = [int(input()) for _ in range(0,M)]
MOD = 10**9 + 7
stairs = [True for _ in range(0,N+1)]
for x in arr:
    stairs[x] = False

dp = [0 for _ in range(0,N+1)]

dp[0] = 1 if 0 not in arr else 0
dp[1] = 1 if 1 not in arr else 0

for i in range(2,N+1):
    if dp[i-1] == 0 and dp[i-2] == 0:
        break
    if stairs[i-1]: dp[i] += dp[i-1]
    if stairs[i-2]: dp[i] += dp[i-2]

    dp[i] %= MOD

print(dp[-1] % MOD)

Measured memory_bytes: 9612
main = do
  li <- getLine
  let [h1,m1,h2,m2,k] = map read $ words li
  let ans = compute h1 m1 h2 m2 k
  print ans

compute :: Int -> Int -> Int -> Int -> Int -> Int
compute h1 m1 h2 m2 k = max 0 $ x2 - x1 - k
  where
    x1 = h1 * 60 + m1
    x2 = h2 * 60 + m2

Measured memory_bytes: 3892
N = int(input())
a = list(map(int, input().split()))

dp0 = [0] * N
dp1 = [0] * N
dp0[0] = a[0]
dp1[0] = -(10 ** 10)
for i in range(1, N):
    dp0[i] = max(dp0[i - 1] + a[i], dp1[i - 1] + a[i])
    dp1[i] = max(dp0[i - 1] - 2 * a[i - 1] - a[i], dp1[i - 1] + 2 * a[i - 1] - a[i])

print(max(dp0[N - 1], dp1[N - 1]))

Measured memory_bytes: 16068
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int h1, m1, h2, m2;
  cin >> h1 >> m1 >> h2 >> m2;
  int a = h1 * 60 + m1;
  int b = h2 * 60 + m2;
  int k;
  cin >> k;
  cout << max(0, b - a - k) << '\n';
}


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

int main() {
	int n; cin >> n;
	int res = 0;
	for (int i=1; i<=n; ++i) {
		int x; cin >> x;
		if (i%2 && x%2) res++;
	}
	cout << res << endl;
}

Measured memory_bytes: 3548
from collections import deque
n = int(input())
d = deque()

ar = [0 for _ in range(n)]

ar = [int(s) for s in input().split()]

ar.sort()
res = 1
flag = 0

if(ar[0] == 0):
    res = 0
else:
    ar = [i for i in ar if i != 1]
    if(len(ar) < 50):
        for i in ar:
            res = res*i
            if(res > 10**18):
                print(-1)
                flag = 1
                break
    else:
        print(-1)
        flag = 1

if(flag == 0):
    print(res)

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

signed main() {
	int a, b;
	cin >> a >> b;
	if (a >= 13) cout << b << endl;
	else if (a >= 6) cout << b / 2 << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
ll n;
ll m;
vector<ll> a(n);
ll cnt = 0;

bool ok(ll i){
  ll res = 0;
  rep(j,n){
    ll idx = upper_bound(a.begin(),a.end(),i-a[j]) - a.begin();
    res += n - idx;
  }
  return res < m;
}

ll getsum(ll p){
  vector<ll> cumsum(n+1,0);
  rep(i,n) cumsum.at(i+1) = a.at(n-i-1);
  rep(i,n) cumsum.at(i+1) += cumsum.at(i);
  ll res = 0;
  rep(i,n){
    ll idx = lower_bound(a.begin(),a.end(),p-a[i]) - a.begin();
    res += cumsum.at(n-idx);
    res += a[i] * (n-idx);
    cnt += n - idx;
  }
  return res;
}
 
int main() {
  cin >> n >> m;
  a.resize(n);
  rep(i,n) cin >> a.at(i);
  sort(a.begin(),a.end());
  ll left = -1,right = 1000000;
  while(right - left > 1){
    ll mid = (right + left)/2;
    if(ok(mid)) right = mid; else left = mid;
  }
  
  ll ans = getsum(right+1);
  ans += right * (m-cnt);
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define all(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;
const ll inf = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };

int main()
{
	string s;
	cin >> s;
	int num = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '+') {
			num++;
		}
		else {
			num--;
		}
	}
	cout << num << endl;
	return 0;
}

Measured memory_bytes: 768
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int mod = 1000000007;
ll facmod(ll n,ll mod){
    ll a=1;
    for(;n>0;n--){
        a*=n;
        a %=mod;
    }
    return a;
}

int main(){
    ll n,m,ans;
    cin>>n>>m;
    if(abs(n-m)>=2) ans=0;
    else if(abs(n-m)==1) ans=(facmod(n,mod)*facmod(m,mod));
    else ans=2*(facmod(n,mod)*facmod(m,mod));
    ans %= mod;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <random>
#include <bitset>
#include <time.h>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define sp system("pause")
#define queuel queue<long long>
#define all(x) (x).begin(),(x).end()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(),v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for(auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for(ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for(int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for(int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for(int i = 0; i < n; ++i){int a; cin >> a; s.insert(a);}
#define fastio() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL));
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const ll INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
const int inf = 1000 * 1000 * 1000;
const ld PI = acos(-1.0);
const ll mod1 = inf + 7;
const ll mod2 = inf + 9;
const int MAXN = 500001;
const ld EPS = 1e-9;
int hp = 179;

signed main()
{
	fastio();
	int a, b;
	cin >> a >> b;
	if (a <= 8 && b <= 8)
	{
		cout << "Yay!";
	}
	else
	{
		cout << ":(";
	}
	sp;
}

Measured memory_bytes: 504
#include <iostream>

using namespace std;

typedef unsigned long long int ll;

int main(void){
  ll X;
  cin >> X;
  double num = 100;
  ll count = 0;
  while(true){
    if(num >= X){
      break;
    }
    num = (101*num)/100;
    num = (double)(ll)num;
    count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3672
#include<iostream>

int maxi(int a,int b){
	return (a<b)?b:a;
}

int main(){
	//入力機構
	int A[3];
	std::cin>>A[0]>>A[1]>>A[2];
	//解答
	//全ての差の絶対値を求め、小さい方から2つの和を求めればよい。
	const int abs[3]={std::abs(A[0]-A[1]),std::abs(A[1]-A[2]),std::abs(A[2]-A[0])};
	const int absmax=maxi(maxi(abs[0],abs[1]),abs[2]);
	int ans=abs[0]+abs[1]+abs[2]-absmax;

	//結果出力
	std::cout<<ans<<std::endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
long long ra, rb, ca, cb;
long long p = 1000000007;
long long ans, x, y;
long long kai[2000100];
long long inv[2000100];
long long e[2000100];
long long rui(long long rui_a, long long rui_b) {
	if (rui_b == 0)return 1;
	if (rui_b == 1)return rui_a % p;
	long long rui_c;
	rui_c = rui(rui_a, rui_b / 2);
	rui_c = rui_c * rui_c % p;
	if (rui_b % 2) {
		return rui_c * rui_a % p;
	}
	return rui_c;
}
int main() {
	kai[0] = 1;
	for (long long i = 1; i < 2000100; i++) {
		kai[i] = kai[i - 1] * i % p;
	}
	inv[1] = 1;
	for (int i = 2; i < 2000100; i++) {
		inv[i] = p - inv[p % i] * (p / i) % p;
	}
	e[0] = 1;
	for (int i = 1; i < 2000100; i++) {
		e[i] = e[i - 1] * inv[i] % p;
	}
	scanf("%lld%lld%lld%lld", &ra, &ca, &rb, &cb);
	for (long long i = ca; i <= cb; i++) {
		x = kai[i + rb + 1] * e[rb] % p * e[i + 1] % p;
		y = kai[i + ra] * e[ra - 1] % p * e[i + 1] % p;
		ans += x;
		ans -= y;
		if (ans < 0)ans += p;
		ans %= p;
	}
	printf("%lld\n", ans);
}

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

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

int main(void) {
    int l, r;
    cin >> l >> r;
    int ans = 2018;
    bool flag = false;
    for(ll i = l; i < r; ++i) {
        for(ll j = i+1; j <= r; ++j) {
            int tmp = (i * j) % 2019;
            if(ans > tmp) {
                ans = tmp;
            }
            if(ans == 0) {
                    flag = true;
                    break;
                }
            }
            if(flag) break;
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 256
#!/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
n,m = map(int,input().split())
print(((n-m)*100+m*1900)*2**m)

Measured memory_bytes: 3316
import sys
import math
import copy
a = int(input());
b = [int(input()) for i in range(a)];
c = 0;
first = max(b);
g = b.copy();
h = g.index(first);
del g[h];
second = max(g);

for i in range(a):
    if first > b[i]:
        print(first);
    elif first == b[i]:
        print(second);

Measured memory_bytes: 14560
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  int N, M;
  get(N, M);
  vector<vector<int>> G(N);
  FOR(i, M) {
    int A, B;
    get(A, B);
    A--;
    B--;
    G[A].push_back(B);
    G[B].push_back(A);
  }
  deque<int> ans;
  stack<int> st;
  st.push(0);
  vector<int> visited(N);
  visited[0] = 1;
  while (!st.empty()) {
    int v = st.top();
    st.pop();
    ans.push_back(v);
    visited[v] = 1;
    debug(v);
    bool f = 0;
    for (int x : G[v]) {
      debug("next", x);
      if (!visited[x]) {
        f = 1;
        st.push(x);
      }
    }
    if (!f)
      break;
  }
  st.push(0);
  while (!st.empty()) {
    int v = st.top();
    st.pop();
    if (v > 0)
      ans.push_front(v);
    visited[v] = 1;
    debug(v);
    bool f = 0;
    for (int x : G[v]) {
      if (!visited[x]) {
        f = 1;
        st.push(x);
      }
    }
    if (!f)
      break;
  }
  print(ans.size());
  while (!ans.empty()) {
    cout << ans.front() + 1 << " ";
    ans.pop_front();
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 7020
#include<stdio.h>
int main(){
int x;
scanf("%d",&x);
if(x%7==2)printf("sat\n");
if(x%7==3)printf("sun\n");
if(x%7==4)printf("mon\n");
if(x%7==5)printf("tue\n");
if(x%7==6)printf("wed\n");
if(x%7==0)printf("thu\n");
if(x%7==1)printf("fri\n");
return 0;
}



Measured memory_bytes: 2100
n = int(input())
A = [int(x) for x in input().split()]

from collections import Counter
import operator
def f():
    a = Counter(A[::2]).most_common(2)
    b = Counter(A[1::2]).most_common(2)
    ac, bc = a[0][1], b[0][1]
    ret = n - (ac + bc)
    if a[0][0] == b[0][0]:
        bc_2 = b[1][1] if len(b) != 1 else 0
        ac_2 = a[1][1] if len(a) != 1 else 0
        ret = n - max(ac + bc_2, ac_2 + bc)
    return ret
print(f())

Measured memory_bytes: 15460
n = int(input())
A = [0]*n
B = [0]*n
for i in range(n):
  A[i],B[i] = map(int,input().split())

ans = 0
for i in range(n)[::-1]:
  j = i  
  tmp = (A[j]+ans) % B[j]
  if tmp:
    ans += B[j] - tmp
  
print(ans)  

Measured memory_bytes: 16804
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

const ll inf = 1e18;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}


int main(){
	fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
	ll k, x;
	cin>>k>>x;
	forn(i, x-k+1, x+k){
		cout<<i<<" ";
	}
	cout<<endl;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  string s,t;
  cin >> s;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='B'){
      t=t.substr(0,t.size()-1);
    }else{
      t+=s.at(i);
    }
  }
  cout <<t;
}

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

#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

//#define int long long
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;

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; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

vector<vector<int>> G;
int match[210];
bool used[210];

bool dfs(int v)
{
	used[v] = true;
	rep(i, 0, SZ(G[v]))
	{
		int u = G[v][i], w = match[u];
		if (w < 0 || !used[w] && dfs(w))
		{
			match[v] = u;
			match[u] = v;
			return true;
		}
	}
	return false;
}

int bipartite_matching(int X)
{
	int res = 0;
	rep(i, 0, 210)match[i] = -1;
	rep(v, 0, X)
	{
		if (match[v] < 0)
		{
			rep(i, 0, 210)used[i] = false;
			if (dfs(v))
			{
			//	cout << v << endl;
				res++;
			}
		}
	}
	return res;
}

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

	int X, Y, E, x, y;
	cin >> X >> Y >> E;
	G.resize(X + Y);
	while (E--)
	{
		cin >> x >> y;
		G[x].push_back(X + y);
		G[X + y].push_back(x);
	}

	cout << bipartite_matching(X) << endl;

	return 0;
}


Measured memory_bytes: 3304
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,i,j,k;
    cin >> N;

    int cnt = 0;
    int L[N];
    for(i=0;i<N;i++)cin>>L[i];
    sort(L, L+N);

    for(i=0;i<N-2;i++){
      for(j=i+1;j<N-1;j++){
        for(k=j+1;k<N;k++){
          if(L[i] != L[j] && L[i] != L[k] && L[j] != L[k]){
            if(L[i] + L[j] > L[k]){
              cnt++;
              //cout << i+1 << j+1 << k+1 << endl;
            }
          }
        }
      }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>

int a[10];

int solve( int i, int b, int c ) {

	if ( i == 10 ) { return 1; }

	if ( b < a[i] ) { return solve( i + 1, a[i], c ); }
	if ( c < a[i] ) { return solve( i + 1, b, a[i] ); }

	return 0;

}

int main() {

	int n, i;

	scanf( "%d", &n );

	while ( n-- ) {

		for ( i = 0; i < 10; i++ ) {
		
			scanf( "%d", &a[i] );
		
		}

		if ( solve( 0, 0, 0 ) == 1 ) {

			printf ( "YES\n" );

		} else {

			printf( "NO\n" );

		}

	}

	return 0;

}

Measured memory_bytes: 580
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
static const int N = 8;
static const int FREE = -1;
static const int NOT_FREE = 1;

int row[N], col[N], dpos[2 * N - 1], dneg[2 * N - 1];
bool X[N][N];

void initialize()
{
    for (int i = 0; i != N; ++i)
        for (int j = 0; j != N; ++j) X[i][j] = false;
    for (int i = 0; i != N; ++i) row[i] = col[i] = FREE;
    for (int i = 0; i != 2 * N - 1; ++i) dpos[i] = dneg[i] = FREE;
}

void printBoard()
{
    for (int i = 0; i != N; ++i)
    {
        for (int j = 0; j != N; ++j)
        {
            if ( X[i][j] )
            {
                if (row[i] != j) return;
            }
        }
    }
    for (int i = 0; i != N; ++i)
    {
        for (int j = 0; j != N; ++j)
        {
            cout << ( ( row[i] == j ) ? "Q" : "." );
        }
        cout << endl;
    }
}

void recursive(int i)
{
    if (i == N)
    {
        printBoard();
        return;
    }

    for (int j = 0; j != N; ++j)
    {
        if ( NOT_FREE == col[j] ||
             NOT_FREE == dpos[i + j] ||
             NOT_FREE == dneg[i - j + N - 1] ) continue;
        row[i] = j; col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE;
        recursive(i + 1);
        row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE;
    }
}

int main()
{
    int k, r, c;

    initialize();

    cin >> k;
    for (int i = 0; i != k; ++i)
    {
        cin >> r >> c;
        X[r][c] = true;
    }

    recursive(0);
    return 0;
}


Measured memory_bytes: 3112
// In The Name Of God
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define sqr(A) ((A) * (A))
#define X first
#define Y second
#define MP make_pair
#define bsz  __builtin_popcount
#define all(A) A.begin(), A.end()
using namespace std;
using namespace __gnu_pbds;
template < typename T >
using ordered_set = tree < T , null_type , less < T > , rb_tree_tag , tree_order_statistics_node_update >;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int PR = 727;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;

const int N = 1e5 + 20;
ll dp[N], n, h[N], k;

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> h[i];
	for (int i = n - 2; i >= 0; i--) {
		dp[i] = INF;
		for (int j = i + 1; j <= min(i + k, n - 1); j++)
			dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
	}
	cout << dp[0] << endl;
}



Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<list>
#include<queue>
#include<string.h>
#include<functional>
#include<stack>
#include<deque>
#include<string>
#include<limits.h>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#define int long long
using namespace std;

signed main() {
	int S = 999999999ll, G = 9999999991ll;//[S,G)
	while (G - S > 1) {
		int T = (S + G) / 2;
		string K = to_string(T);
		K += "555";
		cout << "?" << " " << K << endl;
		char i; cin >> i;
		if (i == 'N')S = T;
		else G = T;
	}
	//G
	string s = to_string(G);
	set<char>O;
	string q = to_string(G);
	for (char v : q) {
		O.insert(v);
	}
	if (O.size() == 1 && *O.begin() == '9' || O.size() == 2 && *O.begin() == '9' && *++O.begin() == '9') {
		string x = to_string(G);
		while (1) {
			if (x[x.size() - 1] != '0') { cout <<"! "<< x << endl; break; }
			int y = stoll(x);
			x.erase(--x.end());
			string u;
			for (int i = 0; i < x.size()+1; i++) {
				u += '1';
			}
			cout << "?" << " " << u << endl;
			char i; cin >> i;
			if (i == 'Y') { cout << "! " << x << "0" << endl; break; }
		}
		return 0;
	}
	string x = to_string(G);
	while (1) {
		if (x[x.size() - 1] != '0') { cout << "! " << x << endl; break; }
		int y = stoll(x);
		x.erase(--x.end());
		string u;
		for (int i = 0; i < x.size(); i++) {
			u += '9';
		}
		cout << "?" << " " << u << endl;
		char i; cin >> i;
		if (i == 'N') { cout << "! "<< x << "0" << endl; break; }
	}
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(void) {
    int N, K;
    cin >> N >> K;
    vector<int> a(N+2);
    for(int i=1; i<=N; i++) {
        cin >> a[i];
    }

    vector< vector<int> > l(N+2, vector<int>(K)), r(N+2, vector<int>(K));
    l[0][0] = 1;
    r[N+1][0] = 1;
    for(int i=1; i<=N; i++) {
        for(int j=0; j<K; j++) {
            l[i][j] += l[i-1][j];
            if(j + a[i] >= K) continue;
            l[i][j + a[i]] += l[i-1][j];
        }
    }
    for(int i=N; i; i--) {
        for(int j=0; j<K; j++) {
            r[i][j] += r[i+1][j];
            if(j + a[i] >= K) continue;
            r[i][j + a[i]] += r[i+1][j];
        }
    }

    int need = 0;
    for(int i=1; i<=N; i++) {
        partial_sum(r[i+1].begin(), r[i+1].end(), r[i+1].begin());
        for(int j=0; j<K; j++) {
            if(l[i-1][j] == 0) continue;
            if(K-a[i] <= j && j < K) {
                ++need;
                break;
            }
            if(r[i+1][K-1-j] - r[i+1][max(K-a[i]-1-j, 0)]) {
                need++;
                break;
            }
        }
    }

    cout << N - need << endl;
    return 0;
}


Measured memory_bytes: 196096
#include <bits/stdc++.h>
#define P pair<int,int>
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int cntl = 0, cntr = 0;
	//cout << "---cntl---" << endl;
	for (int i = 0; i < (int)s.size(); i++) {
		if (s[i] == '(') {
			cntl++;
			//cout << "i:" << i << " cntl:" << cntl << endl;
		} else {
			cntl = max(0, cntl - 1);
			//cout << "i:" << i << " cntl:" << cntl << endl;
		}
	}
	//cout << "---cntr---" << endl;
	for (int i = (int)s.size() - 1; i >= 0; i--) {
		if (s[i] == ')') {
			cntr++;
			//cout << "i:" << i << " cntr:" << cntr << endl;
		} else {
			cntr = max(0, cntr - 1);
			//cout << "i:" << i << " cntr:" << cntr << endl;
		}
	}
	for (int i = 0; i < cntr; i++) {
		cout << "(";
	}
	cout << s;
	for (int i = 0; i < cntl; i++) {
		cout << ")";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
map<int, int> primeCount(int n) {
  map<int, int> pc;
  LL ma = ceil(sqrt(n));
  REPC(i, 2, ma) {
    while (n % i == 0) {
      n /= i;
      ++pc[i];
    }
  }
  if (n > 1) {
    ++pc[n];
  }
  return pc;
}

int main() {
  LL N, M;
  cin >> N >> M;
  auto pc = primeCount(M);
  VEC<LL> s;
  s.push_back(1);
  for (auto v : pc) {
    int siz = s.size();
    REP(k, 0, siz) {
      LL sum = s[k];
      REP(i, 0, v.second) {
        sum *= v.first;
        s.push_back(sum);
      }
    }
  }
  LL ma = 0;
  REP(i,0,s.size()){
    if(s[i]>=N){
      ma=max(ma,M/s[i]); 

    }
  }
  cout<<ma<<endl;


  return 0;
}


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

vector<string> s;
char win;

bool next(int n)
{
	if(s[n].size() == 0) return 0;
	win = s[n][0];
	s[n].erase(s[n].begin());
	return 1;
}

int main()
{
	for(int i = 0; i <= 2; i++){
		string t;
		cin >> t;
		s.push_back(t);
	}
	win = 'a';
	for(;;){
		if(win == 'a'){
			if(next(0) == 0) break;
			continue;
		}
		if(win == 'b'){
			if(next(1) == 0) break;
			continue;
		}
		if(win == 'c'){
			if(next(2) == 0) break;
			continue;
		}
	}
	cout << char(int(win) + int('A') - int('a')) << endl;
	return 0;
}

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

int main(){
	string line;
	cin>>line;
	for(int i=0;i<line.size();i+=2){
		switch(line[i]-'0'){
			case 1:break;
			case 2:cout<<'k';break;
			case 3:cout<<'s';break;
			case 4:cout<<'t';break;
			case 5:cout<<'n';break;
			case 6:cout<<'h';break;
			case 7:cout<<'m';break;
			case 8:cout<<'y';break;
			case 9:cout<<'r';break;
			case 0:if(line[i+1]=='U')cout<<'n';else cout<<'w';break;
		}
		if(line[i+1]=='U')
			if(line[i]=='0')cout<<'n';
			else cout<<'u';
		else if(line[i+1]=='T')cout<<'a';
		else if(line[i+1]=='L')cout<<'i';
		else if(line[i+1]=='R')cout<<'e';
		else if(line[i+1]=='D')cout<<'o';
		
	
	}
	cout<<endl;
}

Measured memory_bytes: 1180
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"sort"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func solve1() int {
	// init
	sc.Split(bufio.ScanWords)
	a := nextInt()
	b := nextInt()
	c := nextInt()

	ab := a + b
	ac := a + c
	bc := b + c

	dataInt := []int{ab, ac, bc}
	sort.Ints(dataInt)
	return dataInt[0]
}

func main() {
	fmt.Println(solve1())
}


Measured memory_bytes: 640
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int N, X[1 << 18], Y[1 << 18], T[1 << 18];

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> T[i] >> X[i] >> Y[i];
	}
	for (int i = 1; i <= N; i++) {
		int tm = T[i] - T[i - 1];
		int ds = abs(X[i] - X[i - 1]) + abs(Y[i] - Y[i - 1]);
		if (ds > tm || (tm - ds) % 2 == 1) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 4716
import re
s = raw_input()

ans = 0
for joi_str in re.findall('(J*)(O*)(I*)', s):
    j = len(joi_str[0])
    o = len(joi_str[1])
    i = len(joi_str[2])
    if j >= o and o <= i:
        ans = max(ans, o)

print ans

Measured memory_bytes: 49564
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

int main(int argc, char const* argv[])
{
	int q;
	cin >> q;
	for(int i = 0; i < q; i++){
			string a, b;
			cin >> a;
			cin >> b;
			int **dp = new int*[a.size() + 1];
			for(int j = 0; j < a.size() + 1; j++){
					dp[j] = new int[b.size() + 1];
			}
			for(int j = 0; j <= a.size(); j++)dp[j][0] = 0;
			for(int j = 0; j <= b.size(); j++)dp[0][j] = 0;
			for(int j = 0; j < a.size(); j++){
					for(int k = 0; k < b.size(); k++){
							if(a[j] == b[k])dp[j + 1][k + 1] = dp[j][k] + 1;
							else{
									dp[j + 1][k + 1] = max(dp[j][k], dp[j+1][k]);
									dp[j + 1][k + 1] = max(dp[j + 1][k + 1], dp[j][k+1]);
							}
					}
			}
			cout << dp[a.size()][b.size()] << endl;
	}
	return 0;
}



Measured memory_bytes: 81828
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll W,H, v;
	while(cin>>H>>W) {
		VVI w(10, VI(10));
		REP(y, 10) REP(x, 10) cin>>w[y][x];
		REP(k, 10) REP(i, 10) REP(j, 10) w[i][j] = min(w[i][j], w[i][k]+w[k][j]);
		ll ans = 0;
		REP(i, W*H) {
			cin>>v;
//			DD(v);
			if(v!=-1) ans += w[v][1];
		}
		cout<<ans<<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;
typedef long long ll;

int main() {
    
    int n;

    cin >> n;

    if(n % 10 == 3) cout << "bon";
    else if(n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) cout << "pon";
    else cout << "hon";
    
    return 0;
}



Measured memory_bytes: 3624
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int M;
    cin >> M;
    vector<ll> d(M), c(M);
    REP(i, M) {
        cin >> d[i] >> c[i];
    }

    ll ans = 0;
    REP(i, M) {
        ans += c[i];
    }
    ans -= 1;

    ll cnt = 0;
    REP(i, M) {
        cnt += d[i] * c[i];
        // cnt %= ll(10);
    }
    cnt--;
    ans += cnt / 9;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6428
main = do
  input <- last . lines <$> getContents
  let left = fst $ countLeft input (0, 0)
      right = fst $ countRight input (0, 0)
  putStrLn $ (replicate right '(') ++ input ++ (replicate left ')')

countLeft :: String -> (Int, Int) -> (Int, Int)
countLeft [] (l, r) = (l, r)
countLeft ('(':ss) (l, r) = countLeft ss (l+1, r)
countLeft (')':ss) (l, r) = if l > 0 then countLeft ss (l-1, r)
                                     else countLeft ss (l, r)
countLeft (_:ss) (l, r) = countLeft ss (l, r)


countRight :: String -> (Int, Int) -> (Int, Int)
countRight [] (r, l) = (r, l)
countRight ('(':ss) (r, l) = countRight ss (r, l+1)
countRight (')':ss) (r, l) = if l > 0 then countRight ss (r, l-1)
                                      else countRight ss (r+1, l)
countRight (_:ss) (r, l) = countLeft ss (r, l)


Measured memory_bytes: 508
INF = 2**31-1
class SegmentTree():
    def __init__(self, N):
        self.N0 = 2**(N-1).bit_length()
        self.data = [INF]*((2*self.N0)+1)

    # a_k の値を x に更新
    def update(self, k, x):
        k += self.N0-1
        self.data[k] = x
        while k >= 0:
            k = (k - 1) // 2
            self.data[k] = min(self.data[2*k+1], self.data[2*k+2])

    # 区間[l, r)の最小値
    def query(self, l, r):
        L = l + self.N0; R = r + self.N0
        s = INF
        while L < R:
            if R & 1:
                R -= 1
                s = min(s, self.data[R-1])

            if L & 1:
                s = min(s, self.data[L-1])
                L += 1
            L >>= 1; R >>= 1
        return s

# N: 処理する区間の長さ
N, Q = map(int, input().split())
segtree = SegmentTree(N)
segtree.data
#初期化:
"""
for i in range(1, N+1):
    update(i, a[i])
"""
for i in range(Q):
    q, l, r = map(int, input().split())
    if q == 1:
        print(segtree.query(l, r+1))
    else:
        segtree.update(l, r)



Measured memory_bytes: 8704
N,A,B = map(int,input().split())

if N == 2:
    print(1)
    exit()

if (B-A) % 2 == 0:
    print((B-A)//2)
    exit()

if A == 1 or B == N:
    if B - A == 1:
        print(1)
        exit()
    else:
        print(1 + (B-A)//2)
        exit()

# Aが近い
if (A-1) <= (N-B):
    flag = True
# Bが近い
else:
    flag = False

if flag:
    answer = A + (B-A)//2
else:
    move = N-B
    answer = move + 1 + (B-A)//2

print(answer)

Measured memory_bytes: 3064
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


long long gcd(long long a, long long b)
{
  if (b == 0)
    return a;

  return gcd(b, a % b);
}


bool solve(long long A, long long B, long long C, long long D)
{
  long long k = gcd(B, D);

  if (A < B)
    return false;

  if (D < B)
    return false;

  if (B <= C)
    return true;

  if (C < A) {
    long long x = A - (A - C) / k * k;

    if (x == C) {
      if (x + k < B)
        return false;
    }
    else if (x > C) {
      if (x < B)
        return false;
    }
  }

  return true;
}


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int T;

  std::cin >> T;

  long long A, B, C, D;

  for (int t = 0; t < T; t ++) {
    std::cin >> A >> B >> C >> D;

    bool f = solve(A, B, C, D);

    std::cerr << "      " << (f ? "Yes" : "No") << std::endl;
    std::cout <<             (f ? "Yes" : "No") << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
#define MAXX 500005
 
#define PI   3.14159265358979323846264338327950
 
#define PB push_back 
#define PF push_front
#define F first
#define S second
 
#define fixx(n) fixed << setprecision(n)
 
#define ll 	  long long 
 
#define mod  1000000007



int main()
{
	FAST;
	int h, a;
	cin >> h >> a;
	int b[a+4];
	ll x = 0;
	for(int i = 0; i < a; i ++){
		cin >> b[i];
		x += b[i];
	}
	if(x >= h){
		cout << "Yes";
		return 0;
	}
	cout << "No";
	return 0;
}

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


int main(){
  ll N;
  cin >> N;
  vector<ll> A(N);
  for(ll i=1;i<N;++i){cin >> A[i];
  A[i]--;
  }
  vector<ll> B(N,0);
  for(ll i=1;i<N;++i){
    B[A[i]]++;
  }
  for(ll i=0;i<N;++i){
    cout << B[i] << endl;
  }
}

Measured memory_bytes: 6424
#include<stdio.h>

int main(){
  int n,a,now = -1,count = 0;
  scanf("%d",&n);
  for(;n > 0;n--){
    scanf("%d",&a);
    if(now <= a){count++;now = a;}
  }
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int p=1e9+7;
const int N=100005;
int n,m;
long long ans;
int main()
{
	scanf("%d%d",&n,&m);
	if(abs(n-m)>1){
		puts("0");
		return 0;
	}
	else{
		ans=1;
		for(int i=1;i<=n;i++)
			ans=ans*i%p;
		for(int i=1;i<=m;i++)
			ans=ans*i%p;
		if(n==m)ans=ans*2%p;
		printf("%lld",ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
#define all(c) begin(c),end(c)
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
using ll = long long;
using vi = vector<int>; using vs = vector<string>;
int dd[] = { 0, 1, 0, -1, 0 }; //→↓←↑

bool B[25][25]; int N, M;
void dfs(int ty, int tx, vs S)
{
	for (int r = 0; r < 4; r++)
	{
		int y = ty + dd[r];
		int x = tx + dd[r + 1];
		if (y < 0 || y >= N || x < 0 || x >= M)
		{
			continue;
		}
		if (S[y][x] == '.' && B[y][x] == false)
		{
			B[y][x] = true;
			dfs(y, x, S);
		}
	}
}

void solve()
{
	while (true)
	{
		cin >> M >> N;
		if (N == 0 && M == 0)
		{
			break;
		}

		vs S(N);
		for (int i = 0; i < N; i++)
		{
			cin >> S[i];
		}
		int sy = -1, sx = -1;
		for (int i = 0; i < N; i++)
		{
			for (int j = 0; j < M; j++)
			{
				if (S[i][j] == '@')
				{
					sy = i;
					sx = j;
					break;
				}
			}
		}
		for (int i = 0; i < N; i++)
		{
			for (int j = 0; j < M; j++)
			{
				B[i][j] = false;
			}
		}

		dfs(sy, sx, S);
		int ans = 0;
		for (int i = 0; i < N; i++)
		{
			for (int j = 0; j < M; j++)
			{
				if (B[i][j])
				{
					ans++;
				}
			}
		}
		cout << (ans+1) << endl;
	}

}

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


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

int gcd(int x,int y){
    if(y==0)return x;
    x=x%y;
    gcd(y,x);
}
int kota(string x,int c){
    int a=0;
    rep(i,x.length()){
    a+=x[i];
    c++;
    }
    c--;
    if(a<10) return c;
    string d=to_string(a);
    kota(d,0);
}
main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    rep(i,s.length()){
        if((s[i]+n)>90)s[i]=s[i]+n-90+64;
        else s[i]=s[i]+n;
    }
    cout<<s<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int bserch(int w[],int n,int mid){
    int k=1,s=0;
    for(int i=0;i<n;i++){
        if(w[i]+s<=mid){
            s=s+w[i];
        }
        else{
            s=w[i];
            k++;
        }
    }
    return k;
}
int main(){
    int n,q,max=0,sum=0;
    int w[100000]={};
    cin>>n>>q;
    for(int i=0;i<n;i++){
        cin>>w[i];
        if(max<w[i]){
            max=w[i];
        }
        sum=sum+w[i];
    }
    while(max!=sum){
        int mid=(max+sum)/2;
        int ans=bserch(w,n,mid);
        if(ans>q){
            max=mid+1;
        }
        else{
            sum=mid;
        }
    }
    cout<<max<<endl;
    return 0;
}


Measured memory_bytes: 3508