akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<v<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;

//すべて半閉区間で扱う
struct cBIT {
  vector<ll> v;
  ll n;
  cBIT(ll n) : n(n), v(n) {}
  void add(ll i, ll x) {
    i++;
    while (i <= n) {
      v[i - 1] += x;
      i += i & -i;
    }
  }
  ll sum(ll i) {
    ll r = 0;
    while (i >= 1) {
      r += v[i - 1];
      i -= i & -i;
    }
    return r;
  }
  ll sum(ll l, ll r){
    if(l>=r)return 0;
    return sum(r)-sum(l);
  }
  ll get(ll i){return sum(i+1)-sum(i);}
};
 
struct BIT {
  cBIT p, q;
  BIT(ll n) : p(n + 1), q(n + 1) {}
  void add(ll l, ll r, ll w) {
    p.add(l, -w * l);
    p.add(r, w * r);
    q.add(l, w);
    q.add(r, -w);
  }
  ll sum(ll r) {
    return p.sum(r) + q.sum(r) * r;
  }
  ll sum(ll l, ll r){
    if(l>=r)return 0;
    return sum(r)-sum(l);
  }
  ll get(ll i){return sum(i+1)-sum(i);}
};
//↑すべて半閉区間で扱う

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll C;
    cin >> C;
    BIT tree(110000);
    vector<ll> s(N,0);
    vector<ll> t(N,0);
    vector<ll> c(N,0);
    vector<vector<P>> pro(31, vector<P>(0));
    for(ll i=0;i<N;++i){
        cin>>s[i]>>t[i]>>c[i];
        pro[c[i]].emplace_back(P(s[i],t[i]));
    }
    for(ll i=0;i<31;++i)sort(pro[i].begin(), pro[i].end());
    for(ll i=0;i<31;++i){
        for(ll j=0;j<pro[i].size();++j){
            if(j>0&&pro[i][j-1].second==pro[i][j].first)
                tree.add(pro[i][j].first+1,pro[i][j].second+1,1);
            else tree.add(pro[i][j].first,pro[i][j].second+1,1);
        }
    }
    ll ans=-INF;
    for(ll i=0;i<110000;++i){
        chmax(ans,tree.get(i));
    }
    prt(ans)
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  while(N--){
    int t,x,y;
    cin >> t >> x >> y;

    if(t<(x+y) || (x+y+t)%2){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class BAtCoderBeginnerContest111 {
public:
	void solve(istream& in, ostream& out) {
        int n; in >> n;
        for(int i = n;i <= 999;i++){
            int I = i;
            int a = I / 100;
            I %= 100;
            int b = I / 10;
            I %= 10;
            int c = I;
            if(a == b && b == c) {
                out << a << b << c << endl;
                break;
            }

        }
	}
};

int main() {
	BAtCoderBeginnerContest111 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
n, c, k = map(int, input().split())
from collections import deque

t = [int(input()) for _ in range(n)]
t.sort()
t=deque(t)

ans = 1
bus=t[0]+k
cnt = 0

while t:
    i=t.popleft()
    if i>bus:
        bus=i+k
        ans+=1
        cnt=1
    elif cnt==c:
        bus=i+k
        ans+=1
        cnt=1
    else:
        cnt+=1

print(ans)



Measured memory_bytes: 8124
import numpy as np
n,avea=tuple(map(lambda x:int(x),input().split()))
x=list(map(lambda x:int(x), input().split()))
x=np.array(x)
x=x-avea
w=max(abs(min(x)),abs(max(x)))*n
dp=np.zeros((n+1,2*w+1),dtype=int)
dp[0,w]=1
for i in range(n):
    for j in range(2*w+1):
        if 0<=j-x[i]<=2*w:
            dp[i+1,j]=dp[i,j]+dp[i,j-x[i]]
        else:
            dp[i+1,j]=dp[i,j]
print(dp[n,w]-1)


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

int main() {
    int N;  cin >> N;
    vector<int> V(N);
    int sumV=0, sumC=0;

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

    for (int i = 0; i < N; ++i) {
        int a; cin >> a;
        if (V[i]>a) {
            sumV += V[i];
            sumC += a;
        }
    }

    cout << sumV - sumC << endl;

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef long long ll;

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

int main() {

    ll N;
    cin >> N;
    ll d[N];
    rep(i,N) cin >> d[i];
    sort(d,d+N);
    ll out = d[N/2]-d[N/2-1];
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  bool ok = true;
  REP(i,S.size()){
    if (i%2==0 && S[i]=='L'){
      ok = false;
    }else if(i%2==1 && S[i] == 'R'){
      ok = false;
    }
  }
  if (ok){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    for i in 0..5 {
        input! {
            x: usize,
        }
        if x == 0 {
            println!("{}", i + 1);
            break;
        }
    }
}


Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

vector<string> v;

ll n;
void dfs(string s){
    int m=s.size();
    ll x=stoll(s);
    if(m>11) return;
    bool ok7=false,ok5=false,ok3=false;
    rep(i,m){
        if(s[i]=='7') ok7=true;
        else if(s[i]=='5') ok5=true;
        else ok3=true;
    }
    if(ok7 && ok5 && ok3 && x<=n) v.push_back(s);
    dfs(s+'7');
    dfs(s+'5');
    dfs(s+'3');
}


int main() {
    
    cin >> n;

    dfs("7");
    dfs("5");
    dfs("3");

    cout<<v.size()<<endl;
}




Measured memory_bytes: 1660
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    private const int MOD_N = 1000000000 + 7;

    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());

        var hist = new Dictionary<uint, int>();

        var list = Console.ReadLine().Split(' ');
        for (int i = 0; i < n; ++i)
        {
            var a = uint.Parse(list[i]);
            int count;
            hist.TryGetValue(a, out count);
            hist[a] = ++count;
        }

        bool result;

        switch (hist.Count)
        {
            case 3:
                {
                    var ass = hist.ToArray();
                    result = ((ass[0].Key ^ ass[1].Key) == ass[2].Key) && ass[0].Value == ass[1].Value && ass[0].Value == ass[2].Value;
                    break;
                }
            case 2:
                {
                    var ass = hist.ToArray();
                    result = (ass[0].Key == 0 && ass[0].Value * 2 == ass[1].Value) || (ass[1].Key == 0 && ass[0].Value == ass[1].Value * 2);
                    break;
                }
            case 1:
                {
                    int count;
                    hist.TryGetValue(0, out count);
                    result = n == count;
                    break;
                }
            default:
                result = false;
                break;
        }

        Console.WriteLine(result ? "Yes" : "No");
    }

    private static int GCD(int a, int b) => a > b ? GCD_impl(a, b) : GCD_impl(b, a);
    private static int GCD_impl(int a, int b) => b == 0 ? a : GCD_impl(b, a % b);
    private static long LCM(int a, int b) => (long)a * b / GCD(a, b);

    private static int Comb(int m, int n)
    {
        var t = m - n;
        if (n > t)
            n = t;

        long numerator = 1;
        for (int i = 0; i < n; ++i)
        {
            numerator *= m - i;
            numerator %= MOD_N;
        }
        long denominator = 1;
        for (; n != 0; --n)
        {
            denominator *= n;
            denominator %= MOD_N;
        }

        var inv_denominator = ModInv((int)denominator, MOD_N);
        var ret = (int)(numerator * inv_denominator % MOD_N);

        return ret >= 0 ? ret : ret + MOD_N;
    }

    private static int ModInv(int a, int m)
    {
        int b = m, x = 1, y = 0;
        while (b != 0)
        {
            var t = a / b;
            a -= t * b;
            Swap(ref a, ref b);
            x -= t * y;
            Swap(ref x, ref y);
        }
        x %= m;
        return x >= 0 ? x : x + m;
    }

    private static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
}


Measured memory_bytes: 21856
#include<stdio.h>
#define Num 100000
 
int a[Num];
int search(int c){
   if(c == a[c])
      return c;
   return a[c] = search(a[c]);
 }
int main(){
   int i,x,y,n,m,z;
   for(i=0;i<Num;i++){
      a[i] = i;
   }
   scanf("%d %d",&x,&y);
   for(i=0;i<y;i++){
      scanf("%d %d", &n,&m);
      if(search(n) != search(m)){
         a[search(m)] = search(n);
      }
   }
   scanf("%d",&z);
   for(i=0;i<z;i++){
      scanf("%d %d",&n,&m);
      if(search(n) == search(m))
         printf("yes\n");
      else
         printf("no\n");
   }
 
   return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define gc getchar_unlocked()
#define pc(x) putchar_unlocked(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;

int n, m, a[1002], sum;

int main(){
    scan(n, m);
    for(int i = 0; i < n; i++){
        scan(a[i]);
        sum += a[i];
    }
    sum = ceil(1.0*sum/(4.0*m));
    int cnt = 0;
    for(int i = 0; i < n ;i++){
        if(a[i] >= sum)
            cnt++;
    }
    
    if(cnt >= m)
        puts("Yes");
    else
        puts("No");
    
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000
#define LLINF 1e18

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

void solve_abc_a() {
	ll n, m;
	ll x, y;
	ll a, b, d;
	ll c;
	//char c;
	ll h, w;
	ll k;
	string s, t;
	//ll s, t;
	ll l_ans = 0;
	string s_ans = "NG";

	V val(3, 0);
	cin >> val[0] >> val[1] >> val[2] >> k;
	sort(ALL(val));

	val[2] = val[2] * pow(2, k);

	l_ans = val[0] + val[1] + val[2];

	cout << l_ans << "\n";

	return;
}


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed;
	cout << setprecision(7);

	solve_abc_a();

	return 0;
}


Measured memory_bytes: 4012
#include<iostream>
#include<vector>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;

int main(){
	int n,k; cin>>n>>k;
	vector<int>x(n);
	for(int i=0;i<n;i++){
		cin>>x[i];
	}
	vector<int>a(n),b(n);
	for(int i=0;i<n;i++){
		a[i]=x[i];
		b[i]=k-x[i];
	}
	int ans=0;
	for(int i=0;i<n;i++){
		ans+=min(a[i],b[i])*2;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define ABS(x)		((x)<0 ? -(x):(x))
int main(){
  long long		n,t,a,h,mini,tmp,min=999999999999999999;
  scanf("%lld%lld%lld", &n, &t, &a);
  for(int i=0; i<n; i++){
    scanf("%lld", &h);
    tmp = ABS((1000*t - 6*h) - 1000*a);
    if( tmp < min ){ min = tmp; mini = i; }
  }
  printf("%lld", mini+1);
  return 0;
}


Measured memory_bytes: 1708
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int a,c,i,j,k,N;
	c = 0;
	cin >> N;
	vector<int> s;
	for (i = 0; i < N; i++) {
		cin >> a;
		s.push_back(a);
	}
	for (j = 0; j < N-1; j++) {
		if (s[j] != 0) {
			for (k = j + 1; k < N; k++) {
				if (s[j] == s[k]) {
					c++;
					s[k] = 0;
				}
			}
		}
	}
	cout << N-c << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())

abc='abcdefghijklmnopqrstuvwxyz'

def dfs(keta,s):
  if keta==n:
    global ans
    ans.append(s)
    return

  st_l=len(set(s))
  for i in range(st_l+1):
    dfs(keta+1,s+abc[i])

ans=[]
dfs(1,'a')

for i in ans:
  print(i)

Measured memory_bytes: 17312
#include<cstdio>
#include<algorithm>

using namespace std;

int fz, fm;
int wa[3010], su[3010];

int main(){
	int a, b, c, d, e, f, i, j;
	scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);
	wa[0] = 1;
	for(i = a*100; i <= f; ++i)
		wa[i] |= wa[i-a*100];
	for(i = b*100; i <= f; ++i)
		wa[i] |= wa[i-b*100];
	
	su[0] = 1;
	for(i = c; i <= f * e / (100 + e); ++i)
		su[i] |= su[i-c];
	for(i = d; i <= f * e / (100 + e); ++i)
		su[i] |= su[i-d];
		
	fm = a*100; 
	for(i = 0; i <= f * e / (100 + e); ++i)
	if(su[i]){
		for(j = f-i; j * e >= i * 100; --j)
		if(wa[j] && fz * (i + j) < i * fm){
			fz = i;
			fm = i + j;
		}
	}
	printf("%d %d\n", fm, fz);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>

int same(char *T, char *P, int i, int plength){
  int j;

  for(j = 0; j < plength; j++){
    if(T[i+j] != P[j]){
      return 0;
    }
  }
  return -1;
}

int main(){
  char T[1000], P[1000];
  int i, tlength, plength;

  scanf("%s", T);
  scanf("%s", P);

  tlength = strlen(T);
  plength = strlen(P);

  for(i = 0; i < tlength; i++){
    if(same(T, P, i, plength)){
      printf("%d\n", i);
    }     
  }
  return 0;
}

Measured memory_bytes: 540
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <iomanip>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    int n;
    cin >> n;
    vector<string>s(n);
    rep(i,n)cin >> s[i];
    int t = 0;
    rep(k,n){
        bool flag = 1;
        rep(i,n){
            rep(j,n){
                if(s[(i+k)%n][j]!=s[(j+k)%n][i]){
                    flag = 0;
                }
            }
        }
        if(flag){
            t++;
        }
    }
    cout << t*n << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define MAX 1005
const ll MOD=1e9+7;
using namespace std;
ll gcd(ll a, ll b) {
  if(a==0) return b;
  if(a>b) return gcd(a%b, b);
  else return gcd(b%a, a);
}
ll lcm(ll a, ll b) {
  ll tmp=gcd(a,b);
  return (a/tmp)*(b/tmp)*tmp;
}

int main() {
  string s;
  cin >> s;
  string year=s.substr(0,4);
  string month=s.substr(5,2);
  string day=s.substr(8,2);
  if(stoi(month)>=5) cout << "TBD" << endl;
  else cout << "Heisei" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";

int main(){
  ll x; cin >> x;
  ll a,b;
  bool flg=false;
  for(ll i=1;i<1001;i++){
    if(flg) break;
    for(ll j=-1000; j<1001; j++){
      if(flg) break;
      if(pow(i,5)-pow(j,5)==x){
        a=i;
        b=j;
        cout << a << " " << b << endl;
        flg=true;
      }
    }
  }
  return 0;
}




Measured memory_bytes: 4068
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a, b = map(int, readline().split())
if a + b == 15:
    print('+')
elif a * b == 15:
    print('*')
else:
    print('x')


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

#define ll long long
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

int main() {
    while (true) {
        int H, W;
        cin >> H >> W;
        if (H == 0 && W == 0) break;
        rep(i, H) {
            rep(j, W) {
                if (i == 0 || i == H - 1 || j == 0 || j == W - 1) {
                    cout << "#";
                } else {
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 3076
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0385
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = RInt();
            int[] a = RArInt();
            int q = RInt();
            int[][] xy = new int[q][];
            for (int i = 0; i < q; i++) { xy[i] = RArInt(); }

            int[] correct = a.OrderBy(x => x).ToArray();
            int wrongCnt = 0;
            for (int i = 0; i < a.Length; i++) if (a[i] != correct[i]) wrongCnt++;

            if (wrongCnt == 0) Console.WriteLine(0);
            else
            {
                int res = -1;
                for (int i = 0; i < q; i++)
                {
                    int x = xy[i][0] - 1, y = xy[i][1] - 1;
                    if (a[x] == correct[x] && a[y] != correct[x]) wrongCnt++;
                    if (a[y] == correct[y] && a[x] != correct[y]) wrongCnt++;
                    if (a[x] != correct[x] && a[y] == correct[x]) wrongCnt--;
                    if (a[y] != correct[y] && a[x] == correct[y]) wrongCnt--;
                    if (wrongCnt == 0)
                    {
                        res = i + 1;
                        break;
                    }
                    int tmp = a[x]; a[x] = a[y]; a[y] = tmp;
                }
                Console.WriteLine(res);
            }
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}



Measured memory_bytes: 51544
# coding: utf-8
import math
A, B = map(int, input().split())
# print("A:", A, "B:", B)

for i in range(1, 1010):
    if math.floor(i * 0.08) == A and math.floor(i * 0.1) == B:
        print(i)
        exit()
print(-1)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
  char c;
  char c_prev;
  int cnt = 0;
  while(cin >> c) {
      if (c_prev != c) {
          cnt++;
      }

      c_prev = c;
  }

  cout << cnt-1 << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
using namespace std;
using ll = long long;


int main() {
	int a, b, c; cin >> a >> b >> c;
	cout << max(0, c - (a - b)) << endl;
	return 0;
}



Measured memory_bytes: 384
n,k = map(int,input().split())
l = list(map(int,input().split()))

mod = 10**9+7

fact = [1]
for i in range(n):
    fact.append(fact[-1]*(i+1)%mod)

finv = [1]*(n+1)
finv[n] = pow(fact[-1],mod-2,mod)
for i in range(n-1,0,-1):
    finv[i] = ((i+1)*finv[i+1])%mod

def combi(n,k,mod):
    return (fact[n]*finv[k]*finv[n-k])%mod

l.sort()

ans = 0
for i in range(n-k+1):
    tmp = combi(n-i-1,k-1,mod)
    ans += tmp*(l[-i-1]-l[i])
    ans %= mod

print(ans%mod)








Measured memory_bytes: 15320
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		while (true) {

			int h = in.nextInt();
			int w = in.nextInt();

			if (h == 0 && w == 0) {
				break;
			} else {

				for (int i = 0; i < h; i++) {

					for (int n = 0; n < w; n++) {

						System.out.print("#");
					}

					System.out.println();
				}

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

Measured memory_bytes: 35224
using System;

class MyClass
{
    public static void Main(string[] args)
    {
        int[, ,] list = new int[4, 3, 10];
        for (int b = 0; b < 4; b++)
        {
            for (int f = 0; f < 3; f++)
            {
                for (int r = 0; r < 10; r++)
                {
                    list[b, f, r] = 0;
                }
            }
        }
        int n = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++)
        {
            string[] str = Console.ReadLine().Split(' ');
            int b = int.Parse(str[0]);
            int f = int.Parse(str[1]);
            int r = int.Parse(str[2]);
            int v = int.Parse(str[3]);
            list[b - 1, f - 1, r - 1] += v;
        }
        for (int b = 0; b < 4; b++)
        {
            for (int f = 0; f < 3; f++)
            {
                for (int r = 0; r < 10; r++)
                {
                    Console.Write(" " + list[b, f, r]);
                }
                Console.WriteLine();
            }
            if (b != 3)
            {
                Console.WriteLine("####################");
            }
        }
    }
}


Measured memory_bytes: 5632
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

const int[] dr = [0, 0, 1, -1];
const int[] dc = [1, -1, 0, 0];

void main() {
    auto s = readln.split.map!(to!int);
    auto H = s[0];
    auto W = s[1];
    auto A = H.iota.map!(_ => readln.chomp).array;
    auto uf = new UnionFind(H*W);

    foreach (r; 0..H) {
        foreach (c; 0..W) {
            foreach (k; 0..4) {
                int nr = r + dr[k];
                int nc = c + dc[k];
                if (nr < 0 || nr >= H || nc < 0 || nc >= W || A[r][c] == A[nr][nc]) continue;
                uf.unite(nr*W+nc, r*W+c);
            }
        }
    }

    long ans = 0;
    auto cnt = new long[][](H*W, 2);

    foreach (i; 0..H*W) {
        int k = uf.find(i);
        cnt[k][A[i/W][i%W]=='#'] += 1;
    }

    foreach (i; 0..H*W) {
        ans += cnt[i][0] * cnt[i][1];
    }

    ans.writeln;
}

class UnionFind {
    int N;
    int[] table;

    this(int n) {
        N = n;
        table = new int[](N);
        fill(table, -1);
    }

    int find(int x) {
        return table[x] < 0 ? x : (table[x] = find(table[x]));
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (table[x] > table[y]) swap(x, y);
        table[x] += table[y];
        table[y] = x;
    }
}


Measured memory_bytes: 11388
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
	int N; cin>>N;
	vector<pair<int,int>> X(N);
	for(int i=0;i<N;i++){
		cin>>X[i].first;
		X[i].second=i;
	}
	sort(X.begin(),X.end());
	int left=X[N/2].first,right=X[N/2-1].first;
	for(int i=0;i<N;i++){
		X[i].first=i;
		swap(X[i].first,X[i].second);
	}
	sort(X.begin(),X.end());
	for(int i=0;i<N;i++){
		cout<<(X[i].second<N/2 ? left : right)<<endl;
	}
}

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

int main()
{
  int64_t n, ans = 10e12, j, tmp;
  cin >> n;

  for (int i = 1; i <= (int)sqrt(n); i++) {
    if (n % i == 0) j = n / i;
    tmp = i + j - 2;
    if (ans > tmp) ans = tmp;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>
#include <math.h>
#include <deque>
#include <stack>
#include <queue>

using namespace std;

typedef long long ll;
struct idx {
  ll x;
  ll y;
};



int solve() {
  ll n;
  cin >> n;
  vector<idx> a(n);
  ll all;
  all = 1;
  for(ll i = 0;i < n;i++){
    all *= i + 1;
    cin >> a[i].x >> a[i].y;
  }
  double len = 0.0;
  for(ll i = 0;i < n; i++){
    for(ll j = 0; j < n; j++){
      if(i == j){
        continue;
      }else{
        len += sqrt((double)(a[i].x - a[j].x) * (a[i].x - a[j].x) + (double)((a[i].y - a[j].y) * (a[i].y - a[j].y)));
      }
    }
  }
  printf("%f", len / n);
  return 0;
}


int main(void){
  solve();
  return 0;
}


Measured memory_bytes: 256
(declaim (ftype (function (string &optional character) (values (vector string *) &optional)) split))
(defun split (text &optional (delim #\Space))
    (let* ((result (make-array 0
                               :element-type 'string
                               :adjustable t
                               :fill-pointer 0)))
          (loop :for c character :across text
                :with temp = ""
                :do
                (cond ((char= c delim)
                       (vector-push-extend temp result)
                       (setf temp ""))
                    (t
                     (setf temp (concatenate 'string temp (string c)))))
                :finally
                (vector-push-extend temp result))
          result))

(declaim (ftype (function (integer) integer) by2count))
(defun by2count (num)
    (let* ((result 0))
          (declare (integer result))
          (loop :with n = num
                :while (zerop (mod n 2))
                :do
                (setf n (floor n 2))
                (setf result (1+ result)))
          result))

(declaim (ftype (function ((vector integer *)) integer) sum-vector))
(defun sum-vector (v)
    (let* ((result 0))
          (loop :for n of-type integer :across v
                :do
                (setf result (+ result n)))
          result))
          

(declaim (ftype (function ((vector integer *)) (values integer &optional)) solve))
(defun solve (input)
    (sum-vector (map 'vector #'by2count input)))
    
    

(defun main ()
    (let* ((n (read-line))
           (input (map 'vector #'parse-integer (split (read-line)))))
          ;; (print input)
          (format t "~d~%" (solve input))))
;; (format t "~A~%" (by2count 4))
;; (format t "~A~%" (sum-vector #(1 2 3)))
;; (print (sum-vector (map 'vector #'by2count #(5 2 4))))

(main)

Measured memory_bytes: 55776
import sys
n=int(input())
a=[int(i) for i in sys.stdin.readline().split()]
temps=[a[0]]+[0]*n

mod=1000000007
ans=0
for i in range(1,n):
    ans+=temps[i-1]*a[i]
    ans%=mod
    temps[i]=a[i]+temps[i-1]

print(ans)

Measured memory_bytes: 31352
#include<iostream>
using namespace std;
#include<stack>
int main()
{
	while(1)
	{
		int a,b,x,y,i,c[18][18]={0},n,v=0;
		pair<int,int> s,m;
		stack<pair<int,int> > u;
		cin>>a>>b;
		if(a==0&&b==0)
		break;
		cin>>n;
		for(i=0;i<=a;i++)
		{
			c[i][0]=1;
			c[i][b+1]=1;
		}
		for(i=0;i<=b;i++)
		{
			c[0][i]=1;
			c[a+1][i]=1;
		}
		for(i=0;i<n;i++)
		{
			cin>>x>>y;
			c[x][y]=1;
		}
		s.first=1;
		s.second=1;
		m.first=a;
		m.second=b;
		u.push(s);
		while(!u.empty())
		{
			s=u.top();
			u.pop();
			if(c[s.first+1][s.second]!=1)
			{
				s.first++;
				u.push(s);
				s.first--;
			}
			if(c[s.first][s.second+1]!=1)
			{
				s.second++;
				u.push(s);
				s.second--;
			}
			if(s==m)
			{
				v++;
			}
		}
		cout<<v<<endl;
	}
	return 0;
}

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

using ll=long long;
const ll INF=1e18;
const ll WIDTH=1;
struct Edge{
  int to;
  ll a,b;
};
using Graph=vector<vector<Edge>>;
ll f(ll t,ll a,ll b){
  return t+b/(t+a)+(int)(b%(t+a)>0);
}

using dbl=double;
ll calc(ll t,ll a,ll b){
  dbl X=2*a+1;
  dbl Y=(dbl)(a)*(a+1)-b;
  dbl t0=(-X+sqrt(X*X-4*Y))/2;
  ll res=f(t,a,b);
  ll tx=t0;
  for(int i=-WIDTH;i<=WIDTH;i++){
    ll topt=tx+i;
    if(topt<t) continue;
    res=min(res,f(topt,a,b));
  }

  return res;
}
vector<ll> Dijkstra(int s,Graph& g){
  int n=g.size();
  vector<ll> t(n,INF);
  using Item=pair<ll,int>;
  priority_queue<Item,vector<Item>,greater<>> que;
  t[s]=0;
  que.push({0LL,s});
  vector<int> used(n,false);
  while(!que.empty()){
    auto tmp=que.top(); que.pop();
    int v=tmp.second;
    if(t[v]<tmp.first) continue;
    assert(!used[v]);
    used[v]=true;
    for(Edge& e:g[v]){
      ll tot=calc(t[v],e.a,e.b);
      assert(t[v]<=tot);
      if(tot<t[e.to]){
	t[e.to]=tot;
	que.push({tot,e.to});
      }
    }
  }
  return t;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
  int n,m;
  int S,G;
  cin>>n>>m>>S>>G;
  S--,G--;
  Graph g(n);
  for(int i=0;i<m;i++){
    int u,v;
    ll a,b;
    cin>>u>>v>>a>>b;
    u--,v--;
    g[u].push_back(Edge{v,a,b});
    g[v].push_back(Edge{u,a,b});
  }

  auto t=Dijkstra(S,g);

  cout<<(t[G]>=INF ? -1LL : t[G])<<endl;
  return 0;
}


Measured memory_bytes: 27292
S=input()

if int(S[:2])>0 and int(S[:2])<13:
  a=True
else:
  a=False
  
if int(S[2:])>0 and int(S[2:])<13:
  b=True
else:
  b=False
  
if a==True and b==True:
  print('AMBIGUOUS')
elif a==True and b==False:
  print('MMYY')
elif a==False and b==True:
  print('YYMM')
else:
  print('NA')

Measured memory_bytes: 38256
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        int[] a = in.nextIntArray(n);
        int length = 1;
        for (int i : a) {
            if (i == length) {
                length++;
            }
        }

        out.println(length == 1 ? -1 : n - (length - 1));
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

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

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 47924
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,b,c,P=1e9,l[10];
void d(ll i,ll A,ll B,ll C,ll T){
    if(i==n+1)return;
    if(A&&B&&C)P=min(P,abs(a-A)+abs(b-B)+abs(c-C)+10*(max(0ll,T-3)));
    d(i+1,A+l[i],B,C,T+1);d(i+1,A,B+l[i],C,T+1);d(i+1,A,B,C+l[i],T+1);d(i+1,A,B,C,T);
}
int main(){
  cin>>n>>a>>b>>c;
  for(int i=0;i<n;i++)cin>>l[i];
  d(0,0,0,0,0);
  cout<<P<<endl;
  return 0;
}

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

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
const int MOD = 1000000007;
using mint = Fp<MOD>;

int main(){
    ll n,k; cin >> n >> k;
    mint ans=0;
    for(int i=k;i<=n+1;i++){
        mint mi=i; mi*=(i-1); mi/=2;
        mint ma=i; ma*=(2*n-i+1); ma/=2;
        mint ad = ma-mi+1;
        ans += ad;
    }
    cout << ans << endl;
}

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

int main() {
	int n;
	int cnt = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int l, r;
		cin >> l >> r;
		cnt += r - l + 1;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
    
    int x;
    long int ans, n=2, m=1;
    
    scanf("%d", &x);
    
    for (int i=1; i<x; i++) {
        ans=n+m;
        n=m;
        m=ans;
    }
    
    if (x==1) {
        ans=1;
    }
    
    printf("%ld", ans);

    return 0;
}


Measured memory_bytes: 1712
Q,H,S,D=map(int,input().split())
N=int(input())

q=Q*8
h=H*4
s=S*2
d=D
if N%2==0:
    ans=(N//2)*min(q,h,s,d)
    print(ans)
else:
    ans=(N//2)*min(q,h,s,d)
    q=Q*4
    h=H*2
    s=S
    ans+=min(q,h,s)
    print(ans)

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, a, b; cin >> N >> a >> b;
  if (a + b > N + 1) {
    cout << -1 << endl;
    return 0;
  }
  if (a * b < N) {
    cout << -1 << endl;
    return 0;
  }
  vector<ll> ans;
  ll seq = 1;
  auto block = [&](ll t) -> void {
    for (ll i = 0; i < t; i++) ans.push_back(seq + t - i - 1);
    seq += t;
  };
  block(b);
  if (a > 1) {
    ll x = (N - b) / (a - 1);
    ll y = (N - b) % (a - 1);
    for (ll i = 0; i < a - 1; i++) {
      if (i < y) block(x + 1);
      else block(x);
    }
  }

  bool first = true;
  for (ll t : ans) {
    if (first) first = false;
    else cout << " ";
    cout << t;
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 7436
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template <class T, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >>p.second ;
	return is;
}
template <class T>istream& operator>>(istream& is,  vector<T>& v) {
	rep(i, v.size()) {
		is >> v[i];
	}
	return is;
}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	string s;
	ll k;
	char ans=1;
	cin >>s>>k;
	for (int i = 0; i < k;i++){
		if(s[i]!='1'){
			cout << s[i] << endl;
			return 0;
		}
	} cout << 1<< endl;
}

Measured memory_bytes: 3576
#include <iostream>

using namespace std;

int main(){
  char c;

  cin >> c;

  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') cout << "vowel" << endl;
  else cout << "consonant" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)

#define vll    vector<ll>
#define vvll   vector<vector<ll>>
#define all(x) (x).begin(),(x).end()


int H, W;
vector<vector<ll>> c;
vector<vector<ll>> A;

int main()
{	
	cin >> H >> W;

	c.resize(10, vector<ll>(10));

	rep(i, 10)
	{
		rep(j, 10)
		{
			cin >> c[i][j];
		}
	}

	A.resize(H, vector<ll>(W));

	rep(i, H)
	{
		rep(j, W)
		{
			cin >> A[i][j];
		}
	}

	rep(k, 10)
	{
		rep(i, 10)
		{
			rep(j, 10)
			{
				c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
			}
		}
	}

	ll ans = 0;

	rep(i, H)
	{
		rep(j, W)
		{
			if (A[i][j] == -1) continue;

			ans += c[A[i][j]][1];
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,d;
    cin >> n;
    for(int i = 1;i <= sqrt(n);i++)
    {
        if(n % i == 0)
        {
            d = n / i;
        }
    }
    cout << max(floor(log10(d)) + 1,floor(log10(n / d)) + 1);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

	int A1, A2, A3;

	cin >> A1 >> A2 >> A3;

	if (A1 + A2 + A3 >= 22) {
		cout << "bust" << endl;
	}
	else cout << "win" << endl;

	return 0;
}

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

int c = 0;

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		char p;
		int x;
		cin >> p >> x;
		if(p=='(')c+=x;
		else c-=x;
		if( c < 0 ){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << (c==0?"YES":"NO") << endl;
}

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


int main(){
    long long A,B,N;
    cin >> A >> B >> N ;
    if(N >= B) cout << (A * (B - 1) / B ) << endl ;
    else cout << (A * N / B) << endl ;

}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int k,n;
    cin>>k>>n;
    int a[n],d[n];
    cin>>a[0];
    for(int i=1; i<n; i++){
        cin>>a[i];
        d[i]=a[i]-a[i-1];
    }
    d[0]=k+a[0]-a[n-1];
    sort(d,d+n);
    cout<<k-d[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 5180
//CODECHEF :-
//coded by AMAN BHARTI NIT PATNA
//ALL RIGHTS RESERVED
//ECE 2K18

#include<bits/stdc++.h>
using namespace std;

//#define home
#define TASK "soln"
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define ll long long int
#define br cout<<endl;
#define fo for(int i=0;i<n;i++)
 

void solve(){
    int n;
    cin>>n;
    int a[n];
    fo{cin>>a[i];}

    sort(a,a+n,greater<>());
    ll sum=0;

    if(n%2==1){n++;sum=sum-a[(n/2)-1];}
    n/=2;
    
    for(int i=0;i<n;i++)sum+=2*a[i];


    cout<<sum-a[0]<<endl;
}


int main(){
	#ifdef home
        assert(freopen(TASK".in", "r", stdin));
        assert(freopen(TASK".out", "w", stdout));
    #endif
 
    ios::sync_with_stdio(false);
    cin.tie(NULL);
 
    //int t;
    //cin>>t;
    //while(t-->0)
    solve();
 
    #ifdef home
        eprintf("Time: %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
 
    return 0;
}

Measured memory_bytes: 4408
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MOD 1000000007
#define INF 1000000010
typedef long long  ll;

using namespace std;

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

	ll N, M, K;
	cin >> N >> M >> K;

	vector<ll> A(N+1), B(M+1); // A[0],B[0]は使わない
	vector<ll> sa(N+1),sb(M+1);
	sa[0] = sb[0] = 0;
	repk(i, 1, N+1) {
		cin >> A[i];
		sa[i] = sa[i - 1] + A[i];
	}
	repk(i, 1, M+1) {
		cin >> B[i];
		sb[i] = sb[i - 1] + B[i];
	}

	ll ans = 0;
	ll j = M;
	rep(i, N+1) {
		if (sa[i] > K) break;

		while (1) {
			if (sa[i] <= K - sb[j]) {
				ans = max(ans, i + j);
				// cout << i << " : " << j << endl;
				break;
			}
			j--;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 9516
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

s = input()

if s == "RRR":
    print(3)
elif s == "RRS" or s == "SRR":
    print(2)
elif s == "SSS":
    print(0)
else:
    print(1)

Measured memory_bytes: 61936
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
    public static void main(String[] args){
        FastScanner sc = new FastScanner();
        String firstWord = sc.next();
        String secondWord = sc.next();
        String thirdWord = sc.next();
        StringBuilder builder = new StringBuilder();
        builder.append(firstWord.charAt(0));
        builder.append(secondWord.charAt(0));
        builder.append(thirdWord.charAt(0));
        System.out.println(builder.toString());

    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
    }
}


Measured memory_bytes: 22100