akhauriyash/Code-Regression huggingface dataset:
N,A,B,C=map(int, input().split())
MOD=10**9+7
max_n=(10**5)*2-1
fac=[1]*(max_n+1)
inv=[1]*(max_n+1)
ifac=[1]*(max_n+1)
for n in range(2,max_n+1):
    fac[n]=(fac[n-1]*n)%MOD
    inv[n]=MOD-inv[MOD%n]*(MOD//n)%MOD
    ifac[n]=(ifac[n-1]*inv[n])%MOD
def comb(n,k):
    if n<k:
        return 0
    if n<0 or k<0:
        return 0
    return (fac[n]*ifac[k]*ifac[n-k])%MOD

ans=0
a=pow(A,N,MOD)
b=pow(B,N,MOD)
P=pow(A+B,MOD-2,MOD)
d=pow(P,N,MOD)
ans+=(N*(a+b)*d)%MOD
ans%=MOD
for n in range(1,N):
    a=(a*B)%MOD
    b=(b*A)%MOD
    d=(d*P)%MOD
    ans+=((N+n)*comb(N+n-1,N-1)*(a+b)*d)%MOD
    ans%=MOD
print((ans*100*pow(100-C,MOD-2,MOD))%MOD)

Measured memory_bytes: 26740
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
	int a, b, res1, res2, res3;
	while (scanf("%d%d", &a, &b)!=EOF){
		res1 = a+b;
		res2 = a-b;
		res3 = a*b;
		int max;
		if (res1 > res2)max = res1;
		else max = res2;
		if (max < res3) max = res3;
		printf("%d\n", max);
	}
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdlib>
#include <list>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(void)
{
    int X,A;
 
    cin >> X >> A;

    if (X<A) 
    {
        cout << 0 << endl;
    }
    else
    {
        cout << 10 << endl;
    }
    

    
    return 0;
}


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

int main() {
	long long n;
	cin>>n;
	
	long long ans =0;
	ans = n/500*1000;
	n = n%500;
	
	ans += n/5*5;
	
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#define rep(i,n) (int i = 0; i < (int)(n); i++)
using namespace std;

int main(){
    int a,b,i;
    cin >> a >> b;
    int ans,sa,sum=0;
    
    sa = b - a;
    
    for(i = 0; i <= sa; i++) sum += i;
    ans = sum-b;
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3604
INF = 1e9 +7

def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct

n = int(input())
a = 1
for i in range(1,n+1):
    a *=i
b = factorize(a)
m = len(b)
ans = 1
for i in range(m):
    ans = ans*(b[i][1]+1)
    ans = ans%INF
    ans = int(ans)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define sci1(a) scanf("%d",&a)
#define sci2(a,b) scanf("%d %d",&a,&b)
#define sci3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define scs1(s) scanf("%s",s)
int main(){
    int n,tmp,i,j;
    int64_t rec[2]={0,0};
    vector<int> data;
    sci1(n);
    for(i=0;i<n;i++){
        sci1(tmp);
        data.push_back(tmp);
    }
    sort(data.begin(),data.end());
    j=0;
    for(i=n-1;i>0;i--){
        if(data[i]==data[i-1]){
            rec[j]=(int64_t)data[i];
            i--;
            j++;
        }
        if(j==2)break;
    }
    if(j!=2){
        printf("0");
        return 0;
    }
    cout<<rec[0]*rec[1];
    return 0;

}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int n;
int t[300000];

int solve(){
  int last=0;
  for(int i=0;i<n;i++){
    if(last<i*10)return 0;
    last=max(last,i*10+t[i]);
  }
  return 1;
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>t[i];
  int a=solve();
  reverse(t,t+n);
  int b=solve();
  if(a==1&&b==1)cout<<"yes"<<endl;
  else cout<<"no"<<endl;
  return 0;
}

Measured memory_bytes: 4260
my @str;
	my $input = <STDIN>;
    chomp $input;
	my $i =1;
	my $result = "Yes";
	my $len = length($input);
#    print "$len\n";
	@str = split //, $input;
    my $j = ($len - 1)/2 ;
	for ($i=0; $i < $j; $i++){
    my $r = $len - $i -1;
	if ($str[$i] ne $str[$r]) {$result = "No";}
	}
    $j = ($len - 1) / 2 - 1;
    for ($i=0; $i < $j; $i++){
	    my $r = $j - $i;
#        print "$str[$i] $i $str[$r] $r \n";
		if ($str[$i] ne $str[$r]) {$result = "No";}
		$right1 = $i + ($len + 3)/2-1;
	    $right2 = $len - $i -1;
#        print "$str[$right1] $right1 $str[$right2] $right2 \n";
	if ($str[$right1] ne $str[$right2]){$result = "No"}
	}
	print "$result\n";


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(void){
  ll a,b,c;
  cin >> a >> b >> c;
  if(c <= a + b) {
    puts("No");
    return 0;
  }
  ll d = c - (a + b);
  if(d*d > 4*a*b){
    puts("Yes");
  } else {
    puts("No");
  }
  return 0;
}


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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define btinpct(x) __builtin_popcountll((x))
mt19937 rng(8);    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?b:gcd(b%a,a); }

#define ll long long int 
#define ld long double
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
typedef pair <ll, ll> pi; typedef pair <ll, pi> spi; typedef pair <pi, pi> dpi;

#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (200006)
ll n, k, A[MAXN];
struct node {
	pi key;
	ll prior, sz;
	node *l, *r;
}; typedef node* pnode;
void init(pnode &t,pi key) {
	t->key=key;
	t->prior=rand(0, 1e18);
	t->sz=1;
	t->l=t->r=0;
}
ll cnt(pnode t) {
	return t?t->sz:0;
}
void split(pnode t, pnode &l, pnode &r, pi key) {
	if(!t) return void(l=r=0);
	if(t->key <= key) {
		split(t->r, t->r, r, key);
		l=t;
	} else {
		split(t->l, l, t->l, key);
		r=t;
	}
	if(l) l->sz = cnt(l->l) + cnt(l->r) + 1;
	if(r) r->sz = cnt(r->l) + cnt(r->r) + 1;
}
void insert(pnode &t, pnode k) {
	if(!t) return void(t=k);
	if(t->prior > k->prior) {
		if(t->key > k->key) insert(t->l, k);
		else insert(t->r, k);
	} else {
		if(t->key > k->key) {
			split(t->l, k->l, t->l, k->key);
			t->sz = cnt(t->l) + cnt(t->r) + 1;
			k->r = t;
			t = k;
		} else {
			split(t->r, t->r, k->r, k->key);
			t->sz = cnt(t->l) + cnt(t->r) + 1;
			k->l=t;
			t=k;
		}
	}
	t->sz = cnt(t->l) + cnt(t->r) + 1;
}
ll query(pnode t, pi key) {
	if(!t) return 0;
	if(t->key <= key) {
		return cnt(t->l) + 1 + query(t->r, key);
	} else {
		return query(t->l, key);
	}
}
void output(pnode t) {
	if(!t) return;
	cerr<<"lll\n";
	output(t->l);
	cerr<<"backk\n";
	cout<<"T: "<<t->key.f<<' '<<t->key.s<<' '<<t->sz<<'\n';
	output(t->r);
}
int main()
{
	FAST
	cin>>n>>k;
	FOR(i,1,n) cin>>A[i];
	ll sum = 0, ans = 0, co = 0;
	pnode treap, tmp; treap=new node;
	init(treap, pi(0, co++));
	FOR(i,1,n) {
		sum += A[i];
		ans += query(treap, pi(sum-i*k, LLINF));
		tmp=new node;
		// cerr<<"i: "<<i<<"\n"; output(treap); cerr<<"\n\n";
		// cerr<<sum-i*k<<' '<<query(treap, pi(sum-i*k, LLINF))<<'\n';
		init(tmp, pi(sum-i*k, co++));
		insert(treap, tmp);
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 14336
#include<stdio.h>
#include<math.h>
int main(){
    int n,d;
    long long int x[200000];
    long long int y[200000];
    int count=0;
    scanf("%d %d",&n,&d);
    for(int i=0;i<n;i++){
        scanf("%llu",&x[i]);
        scanf("%llu",&y[i]);
    }
    for(int i=0;i<n;i++){
      if(sqrt(x[i]*x[i]+y[i]*y[i])<=d){
        count=count+1;
      }
    }
    printf("%d\n",count);
}

Measured memory_bytes: 5276
#include<stdio.h>
int main(void)
{
    int l,r;
    int i,j;
    int imod;
    int iminmod = 2020; 
     0 <= l < 2000000000;
    0 < r <= 2000000000;
 
    scanf("%d%d",&l,&r);
 
    i = l;
    if(r-l>=2019){
        printf("%d\n",0);
        return 0;
    }
    else{
    for(j =i+1; j<=r; j++ ){
        for(i = l; i<=j-1;i++){
            imod=(i%2019)*(j%2019)%2019;
            if(imod < iminmod){
                iminmod = imod;               
            }
        }
    }
    }
       
     printf("%d\n",iminmod);
     return 0;
     }

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

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

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

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

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

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll l,n,m;
  while(cin>>l&&l){
    ll ans = 0;
    rep(i,12){
      cin >> n >> m;
      l -= n - m;
      if(l <= 0 && !ans){
        ans = i+1;
      }
    }
    if(!ans){
      cout << "NA"<<endl;
    }
    else{
      cout << ans << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3108
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long int lnt;
typedef pair<lnt,lnt> P;
lnt a,b;
lnt euk(lnt x,lnt y){
	if(x<y) return euk(y,x);
	if(y==0) return x;
	return euk(y,x%y);
}

int main()
{
	while(scanf("%lld%lld",&a,&b)!=EOF){
		lnt x=euk(a,b);
		cout<<x<<' '<<a*b/x<<endl;
	}
}

Measured memory_bytes: 1208
function gcd(a, b) {
	if (b > a) return gcd(b, a);
	if (b == 0) return a;
	return gcd(b, a % b);
}

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');

var line;
while (line = lines.shift()) {
	var nums = line.split(' ').map(function(n){return +n;});
	var a = nums[0];
	var b = nums[1];
	var d = gcd(a, b);
	var m = a * b / d;
	console.log(d + ' ' + m);
}

Measured memory_bytes: 7904
def get_sieve_of_eratosthenes(n):
    import math
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]


def abc149c_next_prime():
    import bisect
    x = int(input())
    list = get_sieve_of_eratosthenes(100003)
    idx = bisect.bisect_left(list, x)
    print(list[idx])


abc149c_next_prime()

Measured memory_bytes: 13296
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<bitset>
#include<tuple>
#include<time.h>
#include<list>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;

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



int n, a[202020];
void solve(){
	cin >> n;
	set<int> s;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		s.insert(a[i]);
	}
	
	if(s.size() == n) cout << "YES" << endl;
	else cout << "NO" << endl; 
}

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

Measured memory_bytes: 10368
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c,d;
	while(~scanf("%d %d %d %d",&a,&b,&c,&d))
	{
		int x=a*b;
		int y=c*d;
		printf("%d\n",x>y?x:y);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#ifdef PRAGMA
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#define fst first
#define snd second
#define fore(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define bs binary_search
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(n) ((int) (n).size())
#define MAXI ((ll)1e16)
#define MINI ((ll)-1e16)
using namespace std;
typedef long long ll;  
     
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b,a%b); } 
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }        
ll n,m;
char a[1001][1001];
ll dp[1001][1001];

const long long M = 1e9 + 7;

long long suma(long long a, long long b){
    return (a+b) % M;
}


ll solve(ll i , ll j){
	if(i>n || j>m || a[i][j]=='#')return 0;
	if(i==n&&j==m)return 1;
	if(dp[i][j]!=-1)return dp[i][j];
	dp[i][j]=solve(i+1,j);
	dp[i][j]=suma(dp[i][j],solve(i,j+1));
	return dp[i][j];
}

int main(){FIN;
	cin >> n >> m;
	fore(i,1,n+1){
		fore(j,1,m+1){
			cin >> a[i][j];
		}
	}
	memset(dp,-1,sizeof(dp));
	cout << solve(1,1);
}

Measured memory_bytes: 9088
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int m=31;
ll a[200000];
int ans=0;

void add(int i,int j,int k){
  cout << "+ " << i << " " << j << " " << k << endl;
  a[k]=a[i]+a[j];
  ans+=1;
}

void comp(int i,int j,int k){
  cout << "< " << i << " " << j << " " << k << endl;
  a[k]=(a[i]<a[j]);
  ans+=1;
}

void rev(int x){
  comp(x,199998,x);
}

void pro(int i,int j,int k){
  add(i,j,199996);
  comp(199996,199997,k);
  rev(k);
}

void solve(){
  cout << 37186 << endl;
  a[0]=10;
  a[1]=53;
  comp(2,0,199998);
  add(3,199998,3);
  add(199998,199998,199997);
  rep(i,m){
    add(i+3,i+3,i+4); 
  }
  per(i,m+1){
    add(35,i+3,36);
    comp(0,36,37);
    rev(37);
    add(199999,37,38+i);
    rep(j,i){
      add(37,37,37);
    }
    add(35,37,35);
  }
  per(i,m+1){
    add(70,i+3,71);
    comp(1,71,72);
    rev(72);
    add(199999,72,73+i);
    rep(j,i){
      add(72,72,72);
    }
    add(70,72,70);
  }
  rep(i,m+1){
    rep(j,m+1){
      pro(38+i,73+j,105+(m+1)*i+j);
      rep(k,i+j){
        add(105+(m+1)*i+j,105+(m+1)*i+j,105+(m+1)*i+j);
      }
      add(105+(m+1)*i+j,2,2);
    }
  }
  // rep(i,100) cout << i << " " << a[i] << endl;
  // Rep(i,105,105+(m+1)*(m+1)){
  //   cout << (i-105)/(m+1) << " " << (i-105)%(m+1) << " " << a[i] << endl;
  // }
  //cout << ans << endl;
  //cout << a[2] << endl;
}

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

Measured memory_bytes: 3624
#include <stdio.h>
#define N 60
#define FACT 20
main ()
{
  int a[N];
  int i,n,carry,x,p;
  


  while(1){
    a[0]=1;
    for (i=1; i<N; i++)
      a[i]=0;
    if(scanf("%d", &x)==EOF) break;
    if(x==1){
      printf("1\n");
      continue;
    }
    for(n=2; n<=FACT; n++){
      carry=0;
      for(i=0; i<N; i++) {
	a[i]=a[i]*n;
	a[i]=a[i]+carry;
	carry = a[i]/10;
	
	a[i]=a[i]-carry*10;
      }
      if(n==x){
	p=0;
	for(i=N-1; i>=0; i--){
	  if(a[i]!=0) p=1;
	  if(p==1){
	    printf("%d", a[i]);
	  }
	}
	printf("\n");
      }
    }
  }
}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S = input()
N = len(S)

T = 'gp' * (N//2) + 'g' * (N%2)
cnt = 0
for i in range(N):
    if S[i] == 'g' and T[i] == 'p':
        cnt += 1
    elif S[i] == 'p' and T[i] == 'g':
        cnt -= 1
print(cnt)


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

using namespace std;

int gcd(int a, int b) {
	//
	if (a<0) a = b;
	if (b<0) b = a;
	//
	if (b == 0) return a;
	return gcd(b, a%b);
}

int main() {

	int n;
	long long int ans = 0;

	cin >> n;

	for (int i = 1;i <= n;i++) {
		for (int j = 1;j <= n;j++) {
			for (int k = 1;k <= n;k++) {
				ans += gcd(gcd(i, j), k);
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3632
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include<list>
#include<map>
#include<utility>
#include<tuple>
#include<numeric>
#include<set>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) a.begin(),a.end()
using namespace std;

int main()
{
	int n;
	cin >> n;
	int i = 1;
	while (n > i * 111) {
		i++;
	}
	cout << i * 111 << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define int long long
#define eps 1e-9
#define all(c) (c).begin(), (c).end()
#define cpresent(c,x) ((c).find(x) != (c).end()) // present in container?
#define vpresent(c,x) (find(all(c),x) != (c).end()) // present in vector?
#define endl '\n'
using namespace std;

double n;

void solve(){
    cin >> n;
    int ans = -69;
    int hmm;
    for(double i = 1; i <= n; ++i){
        if(i*1.08 - (int)i*1.08 >= 0.5)
            hmm = ceil(i*1.08);
        else
            hmm = floor(i*1.08);
        if(hmm ==(int) n)
            ans = (int)i;
    }
    if(ans == -69){
        cout << ":(" << endl;
        return;
    }
    cout << ans << endl;
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	// int t; cin >> t;
	// while(t--)
		solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define y1 zzz
#define fi first
#define se second
#define PII pair<int,int>
#define PII2 pair<int,PII >
#define PII3 pair<PII,int >
#define PII4 pair<PII,PII >
#define all(x) (x).begin(),(x).end()
#define pb push_back
int h,a;
void solve()
{
    cin>>h>>a;
    cout<<h/a+(h%a!=0);
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("XORQUERY.inp","r",stdin);
    //freopen("XORQUERY.out","w",stdout);
    //int t;cin>>t;while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){

    int n; cin >> n;
    int a[n];
    for (int i=0; i<n; i++){
         cin >> a[i];
     }
    for (int i=n-1; i>=1; i--){
        cout << a[i] << " ";
    }
    cout << a[0] << endl;
}


Measured memory_bytes: 3088
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { 
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int M = input.nextInt();
		int Pow2 = 1;
		int ans = 0;
		for (int i = 0; i < M; i++) {
			Pow2*=2;
		}
		ans+=(N-M)*100;
		ans+=1900*M;
		ans*=Pow2;
		System.out.println(ans);
	}	
}

Measured memory_bytes: 21844
n,q=map(int,input().split())
tasknums=[]
times=[]
finish_task=[]
finish_time=[]
take=0
for i in range(0,n):
    a,b=input().split()
    tasknums.append(a)
    times.append(int(b))
while tasknums:
    tasknum=tasknums.pop(0)
    time=times.pop(0)
    if time>q:
        time-=q
        tasknums.append(tasknum)
        times.append(time)
        take+=q
    else:
        finish_task.append(tasknum)
        finish_time.append(take+time)
        take+=time
for i in range(0,n):
    print(finish_task[i]+" "+str(finish_time[i]))


Measured memory_bytes: 10900
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int64 x;
  scanf("%lld",&x);
  int64 cnt=x/11*2;
  x%=11;
  cnt+=(x==0?0:x<=6?1:2);
  printf("%lld\n",cnt);
}

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

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

#define input_from_file freopen("input.txt","r",stdin)
#define output_to_file freopen("output.txt" , "w",stdout)
#define fastio ios_base::sync_with_stdio(0)
#define endl '\n'

const int N = 1e3+1 , mod = 1e9+7;
char arr[N][N];
int dp[N][N];

int main()
{
	 #ifdef LOCAL
        input_from_file;
        output_to_file;
    #endif
	fastio;cin.tie(0);cout.tie(0);
	int n , m ; cin >> n >> m ;
	for(int i = 1 ; i <= n ; ++i)
		for(int j = 1 ; j <= m ; ++j)
			cin >> arr[i][j];
	for(int i = 1 ; i <= n ; ++i)
	for(int j = 1 ; j <= m ; ++j)
		dp[1][1] = 1;
	for(int i = 1 ; i <= n ; ++i)
	{
		for(int j = 1 ; j <= m ; ++j)
		{
			if(i == 1 && j == 1) continue;
			if(arr[i][j] == '.')
				dp[i][j] = ((long long)(dp[i-1][j] + dp[i][j-1]))%mod;
			else dp[i][j] = 0;
			// cerr << i << " "<< j << " "<<dp[i][j] << endl;
		}
	}
	cout << dp[n][m];

	return 0;
}

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

int main() {
  int N,K;
  cin>>N>>K;
  int R,S,P;
  cin>>R>>S>>P;
  string T;
  cin>>T;
  vector<int> a(N);
  int answer=0;
  for(int i=0;i<N;i++){
    if(i-K>=0&&T[i-K]==T[i]&&a[i-K]!=0)
      a[i]=0;
    else if(T[i]=='r')
      a[i]=P;
    else if(T[i]=='s')
      a[i]=R;
    else if(T[i]=='p')
      a[i]=S;
  }
  for(int i=0;i<N;i++){
    answer+=a[i];
  }
  cout<<answer;
}

Measured memory_bytes: 896
#include<stdio.h>
int main(void)
{
	int a,b,c,x;
	scanf("%d %d %d",&a,&b,&c);
	if(a>b){
		x=a;
		a=b;
		b=x;
	}
	if(b>c){
		x=b;
		b=c;
		c=x;
	}
	if(a>b){
		x=a;
		a=b;
		b=x;
	}
	printf("%d %d %d\n",a,b,c);
	return 0;
}



Measured memory_bytes: 2128
import numpy as np
N = int(input())
plan = np.array([[0, 0, 0]] + [list(map(int, input().split())) for i in range(N)])

diff = np.diff(plan, axis = 0)

def is_possible(t, x, y):
    if (t + x + y) % 2 == 0 and abs(x) + abs(y) <= t:
        return True
    else:
        return False

for i in range(N):
    ti, xi, yi = diff[i]
    if not is_possible(ti, xi, yi):
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 38664
#include <iostream>

#define u unsigned
#define s short
#define ll long long
#define REP(i, a, b) for (u ll int i = (a); i < (b); i++)
#define REPR(i, a, b) for (int i = (a-1); i >= (b); i--)

using namespace std;

u ll int fizzbuzz(u ll int N);

int main()
{
    u ll int N;

    cin >> N;

    cout << fizzbuzz(N) << "\n";

    return 0;
}

u ll int fizzbuzz(u ll int N)
{
    u ll int sum = 0;

    REP(i, 1, N + 1)
        if ((i % 3 != 0) and (i % 5 != 0))
            sum += i;
    
    return sum;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
  vector<int> edge;
  int rgt_num, act_num, obt_num;

  rgt_num= 0;
  act_num= 0;
  obt_num= 0;
  while(1) {
    for(int i = 0; i < 3; i++) {
      int E;
      cin >> E;
      edge.push_back(E);
    }

    sort(edge.begin(), edge.end(), greater<int>());

    int a = edge[0];
    int b = edge[1];
    int c = edge[2];

    if(a >= b + c)
      break;
    else if(pow(a, 2) == pow(b, 2) + pow(c, 2))
      rgt_num++;
    else if(pow(a, 2) < pow(b, 2) + pow(c, 2))
      act_num++;
    else
      obt_num++;
    edge.clear();
  }
  cout << rgt_num + act_num + obt_num << ' ' <<  rgt_num
       << ' ' << act_num << ' ' << obt_num << endl;
}



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


int main(){
    int h,w;
    cin >> h >> w;
    while(h!=0 && w!=0){
        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                if(i==0 || i==h-1){
                    cout << "#";
                }
                else{
                    if(j==0 || j==w-1){
                        cout << "#";
                    }
                    else{
                        cout << ".";
                    }
                }

            }
            cout << endl;
        }
        cout << endl;
        cin >> h >> w;
        
    }
}


Measured memory_bytes: 3116
#include<stdio.h>

int main(){
	char A;
	while((A=fgetc(stdin))!='\n'){
		if('A'<=A&&A<='Z')
			A+='a'-'A';
		else if('a'<=A&&A<='z')
			A-='a'-'A';
		printf("%c",A);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstdlib>
#include <cmath>
int main() {
  int N,i,j,tmp,a,b;
a=0;
tmp=0;
cin>>N;
b=N-1;
int A[N];
for(i=0;i<N;i++){
cin>>A[i];
if(tmp<A[i]){
tmp=A[i];
}
}

for(i=0;i<N;i++){
a=a+A[i];
}
a=a-tmp/2;
cout<<a<<endl;
}

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

int main() {
	string S;
  	cin >> S;
  	int len = S.length();
  	int ans = 0;
  	int black = 0;
  	int white = 0;
  	bool isOdd = len % 2 == 0 ? false : true;
  	
  	char mae = S[0];
  	for ( int i = 1; i < len; i++ )
    {
      if ( S[i] == mae )
        ans++;
      
      if ( mae == '0' )
        mae = '1';
      else
        mae = '0';
    }
  	
  	cout << ans << endl;
}

Measured memory_bytes: 512
//#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <vector>
#include <cassert>
#include <fstream>
#include <algorithm>
#include <list>
#include <random>
#include <ctime>
#include <cmath>
#include <random>
#include <bitset>
#include <complex>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define mmin(a, b) a = min(a, (b))
#define mmax(a, b) a = max(a, (b))
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define ALL(a) a.begin(),a.end()
#define sqr(x) (x) * (x)
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define cint const int & 
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;

const double PI = 2 * acos(0.0);

template<class T>
void show(const vector<T> &a) {
	for (T x : a)
		cout << x << " ";
	cout << endl;
}



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

	ll a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	ll ans = 1e9;
	for (int i = 0; i <= max(x, y); ++i) {
		ll cost = i * 2LL * c;
		ll rx = max(0LL, x - i);
		ll ry = max(0LL, y - i);
		cost += rx * a + ry * b;
		mmin(ans, cost);
	}
	cout << ans << endl;

}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main() {
  long long n;
  scanf("%lld", &n);
  long long ans = 0;
  for (long long i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      if (i - 1 > 0 && n / i == n / (i - 1)) {
        ans += i - 1;
      }
      long long j = n / i;
      if (j != i) {
        if (j - 1 > 0 && n / j == n / (j - 1)) {
          ans += j - 1;
        }
      }
    }
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 128
//confilm 0LL and 1LL
//confilm cornercase such as 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll h, w;
	cin >> h >> w;
	ll a[h][w];
	rep(i, h) rep(j, w) cin >> a[i][j];

	VecP ans;
	rep(i, h){
		rep(j, w){
			if(a[i][j]%2){
				if(i == h-1 && j == w-1) continue;
				else if(j == w-1){
					ans.pb(mp(i, j));
					a[i][j]--;
					a[i+1][j]++;
				}else{
					ans.pb(mp(i, j));
					a[i][j]--;
					a[i][j+1]++;
				}
			}
		}
	}

	co(ans.size());
	for(P i : ans){
		cosp(i.fs+1);
		cosp(i.sc+1);
		if(i.sc == w-1){
			cosp(i.fs+2);
			co(i.sc+1);
		}else{
			cosp(i.fs+1);
			co(i.sc+2);
		}
	}

	return 0;
}


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

int main() {
  vector<vector<int>> C(3,vector<int>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> C.at(i).at(j);
    }
  }
  int count=0;
  for(int i=0;i<2;i++){
    if(C.at(i+1).at(0)-C.at(0).at(0)==C.at(i+1).at(1)-C.at(0).at(1)
       && C.at(i+1).at(1)-C.at(0).at(1)==C.at(i+1).at(2)-C.at(0).at(2)){
      count++;
    }
  }
  if(count==2){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
const ll inf = 1e18 + 7;
const int maxN = 1 << 20;

ll n, ans;

int main() {
	ios_base::sync_with_stdio(0);
	cin >> n;
	if (n % 2 == 1) cout << 0 <<endl;
	else {
		ll x = 10;
		ll y = 5;
		int pot = 1;
		while (pot <= 25) {
			ans += (n / y / 2);
			x *= 10;
			y *= 5;
			pot++;
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i++)
using namespace::std;

int n;

int main(){
	int a,b,c,d,e,f,ans;
	cin>>a>>b>>c>>d>>e>>f;
	ans=a+b+c+d+e+f;
	ans-=min(min(a,b),min(c,d));
	ans-=min(e,f);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3076
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a  = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if(c > (a -b)) {
			System.out.println(c - (a - b));
		}else {
			System.out.println(0);
		}
		}
	}


Measured memory_bytes: 21844
N,K = map(int, input().split())
A = [0]+list(map(int,input().split()))
inf = float('INF')
costs = [inf for i in range(N+1)]
costs[0] = costs[1] = 0
for i in range(1,N+1):
    for j in range(i+1,i+K+1):
        if j > N:
            break
        costs[j] = min(costs[i]+abs(A[i]-A[j]), costs[j])
print(costs[N])


Measured memory_bytes: 59616
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <class... T> void printl(T&&...){ }
template <class... T> void printc(T&&...){ }
template <class... T> void prints(T&&...){ }
template <class... T> void printd(T&&...){ }
#endif

int main(){
    int n, c, k;
    cin >> n >> c >> k;
    vector<int> ts(n);
    for(int i=0;i<n;i++){
        cin >> ts[i];
    }
    sort(ts.begin(), ts.end());
    int idx = 0, ans = 0, space = c;
    while(idx < ts.size()){
        int limit = ts[idx] + k;
        while(space && idx < ts.size() && ts[idx] <= limit){ space--; idx++; }
        ans++;
        space = c;
    }
    cout << ans << '\n';
    return 0;
}


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

int main(){  
	while(true){     
		int n;
		int i=0;
		int x[256],y;
		cin >> n;
		if(n==0)         
			break;   

		while(true){
			x[i] = n;
			i++;
			n = n/8;
			if(n==0)
				break;
			
		}
		for(int j=i; j>0; j--){
			y = x[j-1] % 8;
			
			if(y < 4)
				cout << y;
			else if(y == 4)
				cout << y+1;
			else if(y > 4)
				cout << y+2;
		}
		cout << endl;
	}
	return 0;
}

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

mt19937_64 llrand((int) chrono::steady_clock::now().time_since_epoch().count());

#define st first
#define nd second
#define pb push_back

#ifndef ONLINE_JUDGE
  #define db(x) cerr << #x << " == " << x << endl
  #define dbs(x) cerr << x << endl
  #define _ << ", " <<
#else
  #define db(x) ((void)0)
  #define dbs(x) ((void)0)
#endif

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;

const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e5+5;

ll n, m, a, sum;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  while(m--) cin >> a, sum += a;

  if(sum > n) cout << -1 << "\n";
  else cout << n - sum << "\n";
}


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

using namespace std;

typedef long long ll;

vector<vector<int> > G;
int* dist;
int* par;


void dijkstra(int n, int s) {
    for (int i = 0; i < n; i++) {
        dist[i] = 999999;
    }
    priority_queue<pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > > pque;
    dist[s] = 0;
    pque.push(pair<int,int>(0, s));

    while (!pque.empty()) {
        pair<int, int> p = pque.top();
        int v = p.second;
        int d = p.first;
        
        pque.pop();
        if (d > dist[v])
            continue;
        for (int i = 0; i < G[v].size(); i++) {
            int u = G[v][i];
            if (dist[u] <= d+1)
                continue;
        
            dist[u] = d+1;
            pque.push(pair<int,int>(dist[u], u));
            par[u] = v;
        }
    }
}

int main() {
    int n, m;   cin >> n >> m;
    G.resize(n);
    dist = new int[n], par = new int[n];

    for (int i = 0; i < m; i++) {
        int a, b;   cin >> a >> b;
        a--;    b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    dijkstra(n, 0);
    
    for (int i = 0; i < n; i++) {
        if (dist[i] == 999999) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    for (int i = 1; i < n; i++) {
        cout << par[i]+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 11204
#include <iostream>
using namespace std;
#define MAX_N 20

int main()
{
    int n;
    int a[MAX_N];
    int b[MAX_N];
    int c[MAX_N];

    cin >> n;
    for(int i = 0; i < n; ++i)
    {
        int t;
        cin >> t;
        a[i] = t;
    }
    for(int i = 0; i < n; ++i)
    {
        int t;
        cin >> t;
        b[i] = t;
    }
    for(int i = 0; i < n - 1; ++i)
    {
        int t;
        cin >> t;
        c[i] = t;
    }

    int score = 0;
    int tmp = 0;
    int tIdx = -1;
    for(int i = 0; i < n; ++i)
    {
        score += b[a[i]-1];
        if(tIdx >= 0
        && tIdx + 1 == a[i]-1)
        {
            score += tmp;
        }
        
        if(i != n-1)
        {
            tmp = c[a[i]-1];
            tIdx = a[i]-1;
        }
        else
        {
            tmp = 0;
            tIdx = -1;
        }
    }
    cout << score << endl;
}

Measured memory_bytes: 384
//#include <cmath>
//#include <cstdio>
//#include <vector>
//#include <map>
//#include <iostream>
//#include <algorithm>
//#include <set>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vb = vector<bool>;
using pli = pair<ll,int>; 		
#define fi first
#define v vector
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
int INF = 1e9+7;
const int W = 100010;

ll dp[W];

void solve(){
	int n,w;
	scanf("%d%d",&n,&w);
	v<pil> arr(n);
	//dp[w] -> max value that can be get to make w capactity knapsack
	for(int item = 0; item < n; ++item){
		int tw;
		ll tv;
		scanf("%d%lld", &tw,&tv);
		
		for(int i = w-tw; i >= 0; --i){
			dp[i+tw] = max(dp[i+tw], dp[i] + tv);
		}
	}
	printf("%lld\n",dp[w]);
	
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	//cin >> t;
	//scanf("%d",&t);
	while(t--){
		solve();
	}
		
			
}


Measured memory_bytes: 4560
H, W = map(int, input().split())
cost = []
for _ in range(10):
    cost.append(list(map(int, input().split())))
wall = []
for _ in range(H):
    wall.append(list(map(int, input().split())))

dp = [[0 for _ in range(10)] for _ in range(10)]
for i in range(10):
    for j in range(10):
        dp[i][j] = cost[i][j]
for k in range(10):
    for i in range(10):
        for j in range(10):
            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

ans = 0
for h in range(H):
    for w in range(W):
        A = wall[h][w]
        if A >= 0:
            ans += dp[A][1]

print(ans)


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

int main () {
	string str;
	int n[26]={};
	while (getline(cin,str)) {
		for (int i=0; i<str.length(); i++) {
			if (str[i]>='A'&&'Z'>=str[i]) n[str[i]-'A']++;
			else if (str[i]>='a'&&'z'>=str[i]) n[str[i]-'a']++;
		}
	}
	for (int i=0; i<26; i++) cout << ((char)('a'+i)) << " : " << n[i] << endl;
}


Measured memory_bytes: 3164
def divisor(x):
  ret=[]
  for i in range(1,x+1):
    if x%i==0:
      ret.append(i)
  return len(ret)

ans=0
n=int(input())
for i in range(1,n+1):
  if divisor(i)==8 and i%2==1:
    ans+=1
print(ans)


Measured memory_bytes: 2940
n= int(input())
a =list(map(int,input().split()))
ans = a[0]

def gcd(c, b):
    if b == 0:
        return c
    return gcd(b,c%b)

for i in range(n-1):
    ans = ans*a[i+1] // gcd(ans,a[i+1])
sum = 0
for i in range(n):
    sum += (ans-1)%a[i]
print(sum)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (int)(n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}

#define int __int128
const int N = 3e5 + 233;
int n, X;
int x[N], sp[N];
inline int getsum(int L, int R) {
	L = max <__int128> (L, 0);
	if (L > R) return 0;
	return sp[R] - (L ? sp[L - 1] : 0);
}

signed main(void) {
	read(n); read(X);
	rep (i, n) read(x[i]), sp[i] = sp[i - 1] + x[i];
	int ans = 1e18;
	rep (k, n) {
		int cur = X * k + getsum(n - k + 1, n) + n * X;
		for (int i = n, t = 2; i >= 1; i -= k, ++t) {
			int dist = getsum(i - k + 1, i) - getsum(i - 2 * k + 1, i - k);
			cur += dist * t * t;
		}
		// cout << k << " " << cur << "\n";
		ans = min(ans, cur);
	}
	cout << (unsigned long long) ans << "\n";
}


Measured memory_bytes: 8448
S=input()
Slist=[]
for i in range(len(S)):
    Slist.append(int(S[i]in['A','C','G','T']))
ans=0
counter=1
for i in range(1,len(S)):
    if Slist[i]!=Slist[i-1]:
        if Slist[i-1]==1:
            ans=max(ans,counter)
        counter=1
    else:
        counter+=1
if Slist[-1]==1:
    ans=max(ans,counter)
print(ans)


Measured memory_bytes: 38296
N,Y=map(int,input().split())
Flag=0
a=0
b=0
while a<=N:
  while b<=N-a:
    c=N-a-b
    if 10000*a+5000*b+1000*c==Y:
      Flag=1
      break
    b+=1
  if Flag==1:
    break
  a+=1
  b=0
if Flag==1:
  print(a,b,c)
else      : 
  print(-1,-1,-1)
  

Measured memory_bytes: 3060
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vint a(n+2);
    a[0]=0;
    a[n+1]=0;
    int sum = 0;
    REP(i,n){
        cin >> a[i+1];
        sum += abs(a[i+1]-a[i]);
    }
    sum+=abs(a[n]-a[n+1]);
    REP(i,n){
        int ret = sum - abs(a[i+1]-a[i]) -abs(a[i+1] - a[i+2]) + abs(a[i+2] - a[i]);
        cout << ret << endl;
    }


    return 0;
}

Measured memory_bytes: 1664
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

    N = II()
    A = []
    match = defaultdict(lambda : -1)
    for i in range(N):
        a = deque(map(lambda x: int(x)-1, input().split()))
        match[i] = a[0]
        A.append(a)
    

    ans = 0
    players = deque(range(N))

    matched = True
    while matched and len(players) > 0:
        matched = False
        next_players = deque()
        next_match = defaultdict(lambda : -1)

        for i in players:
            if match[i] == -1:
                continue
            a = A[i]
            j = a[0]
            b = A[j]

            if match[j] == i and match[i] == j:
                a.popleft()
                b.popleft()
                matched = True
                match[i] = -1
                match[j] = -1
                if len(a) > 0:
                    next_match[i] = a[0]
                    next_players.append(i)

                if len(b) > 0:
                    next_match[j] = b[0]
                    next_players.append(j)


            else:
                next_match[i] = a[0]

        players = next_players
        match.update(next_match)
        ans += 1


        
    print(ans if matched and len(next_players)==0 else -1)








    

    ans = 0

    

    
   
main()

Measured memory_bytes: 103888
# coding: utf-8
# Your code here!
s = input()
# print(len(s))
alpha = [0] * 26

# if len(s) == 27:
#     print(-1)
# else:
for c in s:
    i = ord(c)-97
    alpha[i] = 1
        # print(c)

flag = True
for i,e in enumerate(alpha):
    if e == 0:
        s += chr(i + 97)
        flag = False
        break

#全ての文字が使われている時
if flag:
    i = len(s) - 1
    while i >= 1:
        alpha[ord(s[i])-97] = 0
        if s[i] > s[i-1]:
            # print(s[i])
            s = s[:i]
            break
        i -= 1
    
    if i == 0:
        print(-1)
    else:
        # print((ord(s[-1])-97))
        # print(ord('x')-97)
        for i,e in enumerate(alpha):
            if e == 0 and i > (ord(s[-1])-97):
                s = s[:-1]
                s += chr(i + 97)
                print(s)
                break
else:
    print(s)

# print(ord("b")-97)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

const ll INF = 1e16;
vector<vector<ll> > d;  // グラフの距離を格納した2次元配列（隣接行列）
// d[u][v]は辺e=(u,v)のコスト（辺が存在しない場合はINF、ただしd[i][i]=0）

void warshall_floyd(int n){  // nは頂点数
  for(int i = 0; i < n; i++){  // 経由する頂点
    for(int j = 0; j < n; j++){  // 開始頂点
      if(d[j][i] == INF) continue;
      for(int k = 0; k < n; k++){  // 終端
        if(d[i][k] == INF) continue;
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
      }
    }
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int V, E; cin >> V >> E;
  d.assign(V, vector<ll>(V, INF));
  REP(i, V){
    d[i][i] = 0;
  }
  REP(i, E){
    int a, b, c; cin >> a >> b >> c;
    d[a][b] = c;
  }
  warshall_floyd(V);
  REP(i, V){
    if(d[i][i] < 0){
      cout << "NEGATIVE CYCLE" << endl;
      return 0;
    }
  }
  REP(i, V) REP(j, V){
    if(d[i][j] == INF){
      cout << "INF";
    }else{
      cout << d[i][j];
    }
    if(j != V-1){
      cout << " ";
    }else{
      cout << endl;
    }
  }
}


Measured memory_bytes: 3228