akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
long long a[10][103];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 1 ; i <= 2 ; i++) {
        for(int j = 1 ; j <= n ; j++) {
            cin >> a[i][j];
        }
    }
    set < long long > ans;
    long long pre = 0;
    for(int i = 1 ; i <= n ; i++) {
        long long sum = pre + a[1][i];
        pre += a[1][i];
        sum += a[2][i];
        for(int j = i + 1 ; j <= n ; j++) {
            sum += a[2][j];
        }
        ans.insert(sum);
    }
    cout << (*ans.rbegin()) << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
for i in range(len(a)):
  a[i] -= 1
b = list(map(int, input().split()))
c = list(map(int, input().split()))
m = 0
bef = -10
for i in range(n):
  m += b[a[i]]
  if(bef + 1 == a[i]):
    m += c[bef]
  bef = a[i]
print(m)

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

#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    int N,M; cin >> N >> M;
    vector<vector<int>> edge(N);
    for(int i = 0; i < M; ++i) {
        int u,v; cin >> u >> v;
        u--,v--;
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    queue<int> q;
    q.push(0);
    vector<int> dp(N,-1);
    dp[0] = 0;
    while(q.size()) {
        int from = q.front();
        q.pop();
        for(int to:edge[from]) {
            if(dp[to]!=-1) continue;
            dp[to] = from;
            q.push(to);
        }
    }
    cout << "Yes" << endl;
    for(int i = 1; i < N; ++i) cout << dp[i]+1 << endl;
    return 0;
}


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

#define ff first
#define ss second
#define pb push_back
#define ll long long
#define ull unsigned long long
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define mst(ss,b) memset(ss,b,sizeof(ss));
#define dbg(x) cout << #x << "= " << x << endl;
typedef pair <int, int> pii;
const int inf = 0x3f3f3f3f;
const ll INF = (1LL<<63)-1;
const ll mod = 1e9+7;
const int N = 1e5+5;

int n, m, q;
int vis[N];
vector<int>E[N];
tuple<int, int, int>op[N];
int col[N];

void dfs(int u, int d, int c){
    if(d == -1)return ;
    if(vis[u] >= d)return ;
    vis[u] = d;
    if(!col[u])col[u] = c;
    for(auto v : E[u])dfs(v, d-1, c);
}

int  main(){
    scanf("%d%d", &n, &m);
    for(int i=1; i<=m; i++){
        int u, v;
        scanf("%d%d", &u, &v);
        E[u].pb(v);
        E[v].pb(u);
    }
    scanf("%d", &q);
    int v, d, c;
    for(int i=1; i<=q; i++){
        scanf("%d%d%d", &v, &d, &c);
        op[i] = make_tuple(v, d, c);
    }
    mst(vis, -1);
    for(int i=q; i>=1; i--){
        tie(v, d, c) = op[i];
        dfs(v, d, c);
    }
    for(int i=1; i<=n; i++)printf("%d\n", col[i]);
    return 0;
}


//    lower_bound()
//    __builtin_popcount()
//    ios::sync_with_stdio(false);
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
//    const double eps=1e-12;
//    #pragma comment(linker,"/STACK:102400000,102400000")




Measured memory_bytes: 8440
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << ' '; clog << LF;}

struct Rect { int height, left; Rect(int h=0, int l=0): height(h), left(l) {} };

i64 slv(const int *bar, int W)
{
  stack<Rect> s;
  s.emplace(-1, -1);

  i64 largest = 0;
  for(int i = 0; i <= W; ++i) {
    const int h = bar[i];

    if(s.top().height < h) {
      s.emplace(h, i);
    }
    else if (s.top().height > h) {
      Rect r;
      while(s.top().height >= h) {
        r = s.top(); s.pop();
        chmax(largest, (i64)(i - r.left) * r.height);
      }
      s.emplace(h, r.left);
    }
  }

  return largest;
}

int N;
int a[100100];
signed main()
{
  cin >> N;
  for(int i = 0; i < N; ++i) {
    cin >> a[i];
  }

  cout << slv(a, N) << endl;
  return 0;
}





Measured memory_bytes: 4008
import itertools
D, G = map(int, input().split())
ans = 10000000000
list_pro = [list(map(int, input().split())) for _ in range(D)]
for ptr in itertools.product([0,1], repeat=D):
  cnt_pro = 0
  res = 0
  for i,k in enumerate(ptr):
    if k == 1:
      cnt_pro += list_pro[i][0]
      res += 100 * (i+1) * list_pro[i][0] + list_pro[i][1]
  if res < G:
    for j, l in enumerate(reversed(ptr)):
      if l == 0:
        for _ in range(list_pro[D-1-j][0]):
          if res >= G:
            break
          res += 100 * (D-j)
          cnt_pro += 1      
  if res >= G:
    ans = min(ans, cnt_pro)
print(ans)

Measured memory_bytes: 74072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<
#define AA(i) cout<<i<<endl;
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

int main(){
    int i,N; cin>>N;
    vector<ll> L(N);
    rep(i,N) cin >> L[i];
    int j,k;
    int ans = 0;
    for(i=0;i<N-2;i++){
        for(j=i+1;j<N-1;j++){
            for(k=j+1;k<N;k++){
                if((L[i]+L[j]>L[k])&&(L[j]+L[k]>L[i])&&(L[i]+L[k]>L[j])&&L[i]!=L[j]&&L[j]!=L[k]&&L[k]!=L[i]){
                    ans++;
                }
            }
        }
    }
    AA(ans);
    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll arr[n+1];
    for(ll i=1;i<=n;i++)
        cin>>arr[i];
        ll dp[n+1];
        dp[0]=0;
        dp[1]=0;
        dp[2]=abs(arr[1]-arr[2]);
        for(ll i=3;i<=n;i++)
    dp[i]=min(abs(arr[i]-arr[i-2])+dp[i-2],abs(arr[i]-arr[i-1])+dp[i-1]);
    cout<<dp[n];
}


Measured memory_bytes: 1792
/*
 * wafuIroha.cpp
 *
 *  Created on: 2020/02/23
 *      Author: black
 */
#include <iostream>
using namespace std;

int main(){
	int h, w;
	cin >> h >> w;
	char *moji = new char[h*w];

	for (int i = 0; i < h; ++i){
		for (int j = 0; j < w; ++j){
			cin >> moji[i*w+j];
		}
	}

	for (int i = 0; i < h; ++i){
		for (int j = 0; j < w; ++j){
			cout << moji[i*w+j];
		}
		cout << "\n";
		for (int j = 0; j < w; ++j){
			cout << moji[i*w+j];
		}
		cout << "\n";
	}


	return 0;
}


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

int main() {
  long long H;
  int N;
  cin >> H >> N;
  vector<int> vec(N);
  int count = 0;
  for(int i = 0; i < N ;i++) {
    cin >> vec.at(i);
  }
  for(int i = 0; i < N ;i++) {
    count = count + vec.at(i);
  }
  if(count >= H) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<iomanip>
#define BUG puts("no bug")
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define ll long long
#define ull unsigned long long
#define REP(a,b,c) for(ll a=b;a<=c;a++)
#define PER(a,b,c) for(ll a=b;a>=c;a--)
#define lb(a) (a&(-a))
#define pp (p<<1)
#define ppp (p<<1|1)
#define pi pair<ll,ll>
#define pii pair<pair<ll,ll>,ll>
using namespace std;
const double Pi=acos(-1.0);
const ll MAXN=1e6+5;
ll n,tot,x,y,z;
ll target;
ll dp[50][MAXN];
const ll mod=1e9+7;
int main(){
    cin>>n>>x>>y>>z;
    target=(1<<(x-1))+(1<<(x+y-1))+(1<<(x+y+z-1));
    ll ans=1;
    REP(i,1,n)ans=ans*10%mod;
    tot=(1<<(x+y+z))-1;
    dp[0][0]=1;
    REP(i,1,n){
        REP(j,0,tot){
            if(!dp[i-1][j])continue;
            REP(k,1,10){
                ll tmp=(j<<k)+(1<<(k-1));
                tmp&=tot;
                if((tmp&target)==target)continue;
                dp[i][tmp]=(dp[i][tmp]+dp[i-1][j])%mod;
            }
        }
    }
    REP(i,0,tot)ans=(ans-dp[n][i]+mod)%mod;
    cout<<ans;
}

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

#define LL long long
#define int long long
#define MIN LLONG_MIN
#define MAX LLONG_MAX
#define PB push_back
#define N 200001
#define MX 262144
#define LG 17
#define M 1000000007
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define LD long double
#define F first
#define S second
#define endl "\n"

int32_t main()
{
    LL i,j,lt,d,z,v,c,r,l,t1,k,h,u,q,ts,te,x,y,n,m;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    LL ct[26]={0};
    for(i=0;i<s.length();i++)
        ct[s[i]-'A']++;
    k=0;
    for(i=0;i<26;i++)
        if(ct[i]==2)
            k++;
    if(k==2)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}   

Measured memory_bytes: 764
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> 

using namespace std;

int a[100100];

int main()
{
	int n;
	long long k;
	scanf("%d%lld",&n,&k);
	for(int i = 1;i <= n;i++)
	{
		long long x,y;
		scanf("%lld%lld",&x,&y);
		a[x] += y;
	}
	long long sum = 0;
	for(int i = 1;i <= 100000;i++)
	{
		if(sum < k && sum + a[i] >= k)
		{
			printf("%d\n",i);
			return 0;
		}
		sum += a[i];
	}
	printf("100000\n");
}

Measured memory_bytes: 512
#include<iostream>

using namespace std;

int a,b,temp;
int gcd(int a,int b){
  return (a%b==0) ? b : gcd(b,a%b);
}
int main(){
  cin >> a >> b;
  if(a < b){
    temp = b;
    b = a;
    a = temp;
  }
  cout << gcd(a,b) << endl;
}

Measured memory_bytes: 1160
n = int(input())
a = []
for i in range(n):
	s,t = map(str, input().split())
	t = int(t)
	a.append([s,t])
x = input()
a.reverse()
ss = 0
for i in range(n):
	if a[i][0] == x:
		print (ss)
		exit()
	ss += a[i][1]
print (ss)


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

using namespace std;
typedef long long ll;
int _w;

ll n, m;

ll solve( ll n, ll m ) {
	if( !m ) return 0;
	return solve(m, n%m) + (n/m)*m*3;
}

int main() {
	cin >> n >> m, n = n-m;
	printf( "%lld\n", solve(n, m) );
	return 0;
}


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

using namespace std;

int main() {
   ios_base::sync_with_stdio(false);
   int N;
   cin >> N;
   vector<vector<int>> adj(N);
   for (int i = 1; i < N; ++i) {
      int par;
      cin >> par; --par;
      adj[par].emplace_back(i);
   }
   vector<int> X(N), Y(N);
   for (int i = 0; i < N; ++i) {
      cin >> X[i];
   }
   for (int v = N - 1; v >= 0; --v) {
      int sum = 0;
      int rem = X[v];
      vector<int> deltas;
      for (int u : adj[v]) {
         sum += X[u] + Y[u];
         rem -= min(X[u], Y[u]);
         deltas.emplace_back(abs(X[u] - Y[u]));
      }
      if (rem < 0) {
         cout << "IMPOSSIBLE\n";
         return 0;
      }
      vector<bool> dp(rem + 1);
      dp[rem] = true;
      for (int val : deltas) {
         for (int i = val; i <= rem; ++i) {
            if (dp[i]) dp[i - val] = true;
         }
      }
      int add = 0;
      while (!dp[add]) add++;
      Y[v] = sum + add - X[v];
   }
   cout << "POSSIBLE\n";
   return 0;
}


Measured memory_bytes: 384
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict
from functools import lru_cache

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

setrecursionlimit(100000)

def main():
	MOD = 10**9 + 7
	k, d = int(rl()), int(rl())
	ans = 0

	def totup(num):
		ans = deque()
		while num:
			num, dig = divmod(num, 10)
			ans.appendleft(dig)
		return tuple(ans)

	x = totup(k)

	dp = [[[0]*2 for j in range(d)] for i in range(len(x)+1)]
	dp[0][0][1] = 1
	for i in range(len(x)):
		for digsum in range(d):
			for tight in range(2):
				for dig in range(x[i]+1 if tight else 10):
					ns = (digsum + dig) % d 
					ntight = 1 if tight and dig == x[i] else 0
					dp[i+1][ns][ntight] += dp[i][digsum][tight]
					dp[i+1][ns][ntight] %= MOD

	ans = (dp[len(x)][0][0] + dp[len(x)][0][1] - 1) % MOD
	print(ans)
	stdout.close()

if __name__ == "__main__":
	main()

Measured memory_bytes: 130908
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <unordered_map>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

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

    int n, m, k, tmp;
    cin >> n >> m >> k;
    queue<int> a, b;
    unsigned long long ts;
    vector<unsigned long long> sa(n), sb(m);
    ts = 0;
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        ts += tmp;
        sa[i] = ts;
        a.push(tmp);
    }
    ts = 0;
    for (int i = 0; i < m; i++) {
        cin >> tmp;
        ts += tmp;
        sb[i] = ts;
        b.push(tmp);
    }

    int ans = 0, tans;

    for (int i = 0; i <= n; i++) {
        tans = 0;
        if (!i || sa[i - 1] <= k) {
            tans += i; // first partition
            int left = k - (i ? sa[i - 1] : 0); // max amount we can get from the other deck

            if (sb[0] > left) {
                ans = max(tans, ans);
                continue;
            }

            if (sb[m - 1] <= left) {
                ans = max(tans + m, ans);
                continue;
            }

            int lo = 0, hi = m - 1, mid, res;
            while (true) {
                mid = (lo + hi) / 2;
                if (sb[mid] <= left && sb[mid + 1] > left) {
                    res = mid;
                    break;
                }
                if (sb[mid] <= left) {
                    lo = mid;
                } else {
                    hi = mid;
                }
            }
            ans = max(tans + res + 1, ans);
        }
    }

    cout << ans;
}

/*
3 4 100000
60 90 120
80 150 80 150



 10 10 100
 20 20 20 20 20
 25 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1


 */

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

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

    int cost = 1000000000;
    rep(i, 0, max(2 * x + 1, 2 * y + 1))
    {
        int now = 0;
        now += c * i;
        now += max(0, x - i / 2) * a;
        now += max(0, y - i / 2) * b;
        // cout <<  max(0, x - i / 2) << ' ' <<  max(0, y - i / 2) << ' ' << i << endl;
        cost = min(cost , now);
    }
    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a,b;
	
	scanf("%d %d",&a,&b);
	
	if(a>=13){
		printf("%d\n",b);
	}else if(a >=6 && a <=12){
		printf("%d\n",b/2);
	}else if(a <= 5){
		printf("0\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); };
template<typename T> void OUT(T && a) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };

int main() {
	IN(LL, n, a, b);
	if((b - a) % 2 == 0) {
		OUT((b - a) / 2);
	} else {
		LL A = n - a;
		LL B = n - b;
		a--; b--;
		OUT(ce(min(a + b, A + B), 2));
	}
}


Measured memory_bytes: 256
nums = list(map(int, input().split()))
Alice = nums[0]
Bob = nums[1]

if Alice == Bob:
    print("Draw")
    
else:
    if Alice == 1:
        print("Alice")
    elif Bob == 1:
        print("Bob")
    else:
        if Alice > Bob:
            print("Alice")
        else:
            print("Bob")

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

int main(){
  string N;
  cin >> N;
  vector<int> E(N.size()+1.0);
  vector<int> P(N.size()+1,1);
  for(int i=1; i<=N.size(); i++){
    int num = N[i-1]-'0';
    E[i]=min(E[i-1]+num, P[i-1]+10-num);
    P[i]=min(E[i-1]+num+1, P[i-1]+9-num);
  }
  cout << E[N.size()] << endl;
  return 0;
}

Measured memory_bytes: 9220
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
const int N = 1e5+5;
const int M = 1e6+5;
const LL Mod = 1e18;
#define pi acos(-1)
#define INF 1e8
#define INM INT_MIN
#define pb(a)  push_back(a)
#define mk(a,b) make_pair(a,b)
#define dbg(x) cout << "now this num is " << x << endl;
#define met0(axx) memset(axx,0,sizeof(axx));
#define metf(axx) memset(axx,-1,sizeof(axx));
#define sd(ax) scanf("%d",&ax)
#define sld(ax) scanf("%lld",&ax)
#define sldd(ax,bx) scanf("%lld %lld",&ax,&bx)
#define sdd(ax,bx) scanf("%d %d",&ax,&bx)
#define sddd(ax,bx,cx) scanf("%d %d %d",&ax,&bx,&cx)
#define sfd(ax) scanf("%lf",&ax)
#define sfdd(ax,bx) scanf("%lf %lf",&ax,&bx)
#define pr(a) printf("%d\n",a)
#define plr(a) printf("%lld\n",a)
int slove(int x)
{
    int num = 0,cnt = 1;
    while(x >= cnt)
    {
        num++;
        x -= cnt;
        cnt++;
    }
    return num;
}
int main()
{
    LL n;sld(n);
    LL m = sqrt(n);
    vector<LL> G;
    LL ans = 0;
    for(LL i=2;i<=m;++i)
    {
        if(n%i == 0)
        {
            int cnt = 0;
            while(n%i == 0) cnt++,n /= i;
            ans += slove(cnt);
        }
    }
    if(n != 1) ans++;
    plr(ans);
 //   system("pause");
    return 0;
}

Measured memory_bytes: 3788
rooms = Hash.new(0)

def report(rooms)
  (1..4).each do |b|
    (1..3).each do |f|
      nums = (1..10).map do |r|
        rooms["#{b}#{f}#{r}"]
      end
      print "\s"
      puts nums.join("\s")
    end
    puts "#" * 20 unless b == 4
  end
end

_ = gets
ARGF.each_line do |line|
  b, f, r, v = line.split.map(&:to_i)
  rooms["#{b}#{f}#{r}"] += v
end

report(rooms)

Measured memory_bytes: 6108
#include <stdio.h>
int main()
{
    
    int a[10000], min, max, n, i;
    long long sum = 0;
    scanf("%d", &n);
    for(i = 0;i < n; i++){
        scanf("%d",&a[i]);
        sum += a[i];
    }
    max = min = a[0];
    for(i = 1;i < n;i++){
        if(a[i] > max)max = a[i];
        if(a[i] < min)min = a[i];
    }
    printf("%d %d %lld\n", min, max, sum);
    
    return 0;
}



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

int main()
{
	int n; cin >> n;
	string s; cin >> s;
	
	vector<int> E_accum(n,0);
	vector<int> W_accum(n,0);
		
	for (int i = 0; i < n; i++) {
		if (i == 0) {
			if (s.at(i) == 'E')	E_accum[i]++;
			if (s.at(i) == 'W')	W_accum[i]++;
		}
		else {
			E_accum[i] += E_accum[i - 1];
			W_accum[i] += W_accum[i - 1];

			if (s.at(i) == 'E') {
				E_accum[i]++;
			}
			else { // s.at(i) == 'W'
				W_accum[i]++;
			}
		}
	}

	int ans = 2147483647;
	for (int i = 0; i < n; i++) {
		
		int tmp = 0;
		
		if (i == 0) {
			tmp = E_accum[n - 1] - E_accum[0];
		}
		else if (i == n - 1) {
			tmp = W_accum[n - 2];
		}
		else { // 1 <= i && i <= n - 2
			tmp = W_accum[i - 1] + E_accum[n - 1] - E_accum[i];
		}

		ans = min(ans, tmp);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

ll N;
ll bit[1000010];

void bit_init(vector<ll> v){
	if(!v.empty()){
		N=v.size();
		for(ll x=1; x <= N; ++x) bit[x] = v[x];
		for(ll x=1; x < N; ++x) bit[x+(x&-x)] += bit[x];
	}
}
void bit_add(ll a, ll w){
		for(ll x=a; x <= N; x+=x&-x)bit[x]+=w;
}
ll bit_sum(ll a){
	ll ret=0;
	for(ll x=a;x>0;x-=x&-x) ret+=bit[x];
	return ret;
}

int main(){
	ll n;cin>>n;
	vector<ll> a(n+1);

	rep(i,n){
	  cin>>a[i+1];
	}
	bit_init(a);
  ll left,right,mid,ans=1e10,B,C,D,E,max_num,min_num;
  FOR(i,2,n-1){
  	// 前半部分は1~i
  	left = 1,right= i;
  	while (right!=left+1) {
  	    mid =(right+left)/2;
  	    // i~mid+1までの和　midまでの和
  	    if(bit_sum(i)-bit_sum(mid)>=bit_sum(mid)){
  	    	left=mid;
  	    }else right=mid;
  	}

  	if(abs(bit_sum(i)-bit_sum(left)-bit_sum(left))<abs(bit_sum(i)-bit_sum(right)-bit_sum(right))){
  		B=bit_sum(i)-bit_sum(left);
  		C=bit_sum(left);
  	}else{
  		B=bit_sum(i)-bit_sum(right);
  		C=bit_sum(right);
  	}

  	left = i+1,right= n;
  	// 後半部分はi+1~n
  	while (right!=left+1) {
  	    mid =(right+left)/2;
  	    // n~mid+1までの和, mid~i+1までの和
  	    if(bit_sum(n)-bit_sum(mid)>=bit_sum(mid)-bit_sum(i)){
  	    	left=mid;
  	    }else right=mid;
  	}
  	if(abs(bit_sum(n)-bit_sum(left)-bit_sum(left)+bit_sum(i))<abs(bit_sum(n)-bit_sum(right)-bit_sum(right)+bit_sum(i))){
  		D=bit_sum(n)-bit_sum(left);
  		E=bit_sum(left)-bit_sum(i);
  	}else{
  		D=bit_sum(n)-bit_sum(right);
  		E=bit_sum(right)-bit_sum(i);
  	}
  	max_num=max(B,max(C,max(D,E)));
  	min_num=min(B,min(C,min(D,E)));
  	ans=min(max_num-min_num,ans);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 7040
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<tuple>
#include<string>
typedef unsigned long long ll;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define F first
#define S second
using namespace std;
const ll INF = 1e12;
const int i_INF = 2147483647;

int main() {
  double a,b;
  cin>>a>>b;
  printf("%.11f\n", a/b);
}

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

int main(){
  int N, M;
  cin >> N >> M;
  cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
  
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100
int main(){
  int A[N];
  int minj,n,i,j,k,count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<n;i++){
    minj = i;
    for(j=i;j<n;j++){
      if(A[j]<A[minj]) minj = j;
    }
    k=A[i];
    A[i]=A[minj];
    A[minj]=k;
    if(A[i]!=A[minj])count++;
  }
   for(i=0;i<n-1;i++) printf("%d ",A[i]);
  printf("%d\n",A[n-1]);
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2084
n = int(input()) - 1

l = 1
s = 0
while s <= n:
    s += pow(26, l)
    l += 1

l -= 1
s -= pow(26, l)

ans = ['a' for _ in range(l)]

dif = n - s
for i in range(l):
    tmp = pow(26, l - i - 1)
    ans[i] = chr(ord(ans[i]) + dif // tmp)
    dif %= tmp

print(''.join(ans))

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);


int main(int argc, char* argv[])
{
  string s;
  cin >> s;
  int a_p = s.size() / 2;
  int a_g = s.size() - a_p;
  int t_g = 0;
  int t_p = 0;
  rep(i, s.size()) {
    if (s[i] == 'p') t_p++;
    else t_g++;
  }

  // 負けを減らす -> g は g にぶつける
  // 勝ちを増やす -> p は g にぶつける
  a_p -= t_p;
  t_p = 0;

  t_g -= a_g;
  a_g = 0;


  ll ans = 0;
  if (a_p != 0 && t_g != 0) {
    ans += a_p;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
import sys
N=int(input())
D=list(map(int,input().split()))
M=int(input())
T=list(map(int,input().split()))
D.sort()
T.sort()
for i in range(M-1,-1,-1):
  while D:
    q=D.pop()
    if T[i]==q:
      #print(i)
      break
    elif T[i]>q:
      print("NO")
      sys.exit()
  else:
    print("NO")
    sys.exit()
print("YES")

Measured memory_bytes: 35420
#include<bits/stdc++.h>
using namespace std;
int n, m = 0, a[200010], b[200010];
int main() {
    cin >> n;
    for(int i = 1; i <= n; i++) scanf("%d", a + i);
    for(int i = n; i >= 1; i--) {
        int s = 0;
        for(int j = i; j <= n; j += i) s += b[j];
        s &= 1;
        if(s != a[i]) b[i] = 1, m++;
    }
    cout << m << endl;
    for(int i = 1; i <= n; i++) if(b[i]) cout << i << " ";
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MAX_INF 0x7f
#define MAX_INF_VAL 0x7f7f7f7f
#define pi 3.141592653589
#define eps 1e-6
//#define p 2173412051LL
#define sz 2

using namespace std;

int a[ 100 ];

int main() {
	int n, mi = MAX_INF_VAL;
	scanf( "%d", &n );
	for( int i = 0; i < n; ++i )
		scanf( "%d", &a[ i ] );
	for( int i = 1; i <= 100; ++i ) {
		int tmp = 0;
		for( int j = 0; j < n; ++j )
			tmp += ( i - a[ j ] ) * ( i - a[ j ] );
		mi = min( tmp, mi );
	}
	printf( "%d", mi );
	return 0;
}

Measured memory_bytes: 256
while True:
    a, b = map(int, input().split())
    if a*b == 0:
        exit()
    for i in range(a):
        if i%2==0:
            if b%2==0:
                print('#.'*(b//2))
            else:
                print('#.'*(b//2)+'#')
        else:
            if b%2==0:
                print('.#'*(b//2))
            else:
                print('.#'*(b//2)+'.')
    print()



Measured memory_bytes: 5612
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(a + b >= c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 22228
#include<stdio.h>
#include<math.h>
int main(){
	double a,b,C,S,L,h;
	
	scanf("%lf %lf %lf",&a,&b,&C);
	double rad=C*M_PI/180.0;
	S=(((a*b)*sin(rad)))/2;
	L=a+b+sqrt(((a*a)+(b*b))-(2*a*b*cos(rad)));
	h=S*2/a;     
	printf("%lf %lf %lf\n",S,L,h);
	return 0;
}

Measured memory_bytes: 648
package main

import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	if n <= 2 {
		if k == 0 {
			fmt.Println(1)
			fmt.Println("1 2")
			return
		}
		fmt.Println(-1)
		return
	}
	ar := []string{}
	for i := 2; i <= n; i++ {
		ar = append(ar, fmt.Sprintf("%d %d", 1, i))
	}
	sum := (n - 1) * (n - 2) / 2
	for i := 2; i <= n-1; i++ {
		for j := i + 1; j <= n; j++ {
			if k < sum {
				sum--
				ar = append(ar, fmt.Sprintf("%d %d", i, j))
			}
		}
	}

	if sum != k {
		fmt.Println(-1)
		return
	}
	fmt.Println(len(ar))
	for _, v := range ar {
		fmt.Println(v)
	}
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;


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

  string S, T;
  cin >> S >> T;
  cout << T << S << endl;


}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int numberOfPlayer = sc.nextInt();
		int number[][] = new int [numberOfPlayer][3];
		int point [] = new int [numberOfPlayer];
		
		for (int i = 0; i < numberOfPlayer; i++) {
			for (int j = 0; j < 3; j++) {
				number[i][j] = sc.nextInt();
			}
			point[i] = 0;
		}
		
		for (int p = 0; p < 3; p++) {
			for (int q = 0; q < numberOfPlayer; q++) {
				boolean flag = false;
				for (int l = 0; l < numberOfPlayer; l++) {
					if (q != l && number[q][p] == number[l][p]) {
						flag = true;
					}
				}
				if (!flag) {
					point[q] += number[q][p];
				}
			}
		}
		
		for (int i = 0; i < numberOfPlayer; i++) {
			System.out.println(point[i]);
		}

	}

}

Measured memory_bytes: 20836
#include <bits/stdc++.h>
#define ll long long

using namespace std;

map<int, int> fr;

int main() {
   // freopen("a.in", "r", stdin);
 //  freopen("a.out", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, m;
    cin >> n >> m;
    vector<int> v(n + 1, 0);
    for(int i = 1; i <= n; i ++)
        cin >> v[i];
    ll sol = 0;
    for(int i = 1; i <= n; i ++) {
        v[i] = (v[i - 1] + v[i]) % m;
        sol += 1LL * fr[v[i]];
        if(v[i] == 0)
            sol ++;
        fr[v[i]] ++;
    }
    cout << sol;
    return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>> N;
    bool flag = false;
    for(int a=1;a<10;a++){
       for(int b=1;b<10;b++) {
           if(a*b==N)
         flag =true;
       }
    }
if(flag)
        cout << "Yes" << endl;
else
        cout << "No" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define space putchar(' ')
#define enter putchar('\n')
#define mp make_pair
#define pb push_back
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
template<class T>
void read(T &res) {
	res = 0;T f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		res = res * 10 + c - '0';
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0){putchar('-');x = -x;}
	if(x >= 10) out(x / 10);
	putchar('0' + x % 10);
}
int N,D[2];
struct node {
	int to,next;
}E[10000005];
int head[400005],sumE,dx[] = {-1,-1,1,1},dy[] = {1,-1,-1,1};
int col[400005],cr[400005],cnt[5];
int to_int(pii p) {
	return p.fi * 2 * N + p.se;
}
void add(int u,int v) {
	E[++sumE].to = v;
	E[sumE].next = head[u];
	head[u] = sumE;
}
void dfs(int u) {
	if(col[u] == -1) col[u] = 0;
	for(int i = head[u] ; i ; i = E[i].next) {
		int v = E[i].to;
		if(col[v] == -1) {col[v] = col[u] ^ 1;dfs(v);}
	}
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	read(N);read(D[0]);read(D[1]);
	for(int t = 0 ; t <= 1 ; ++t) {
		memset(head,0,sizeof(head));sumE = 0;
		for(int x = 0 ; x < 2 * N ; ++x) {
			if(D[t] < x * x) break;
			int y = sqrt(D[t] - x * x);
			if(y * y != D[t] - x * x) continue;
			for(int i = 0 ; i < 2 * N ; ++i) {
				for(int j = 0 ; j < 2 * N ; ++j) {
					for(int k = 0 ; k < 4 ; ++k) {
						int tx = i + dx[k] * x,ty = j + dy[k] * y;
						if(tx >= 0 && tx < 2 * N && ty >= 0 && ty < 2 * N) {
							add(to_int(mp(i,j)),to_int(mp(tx,ty)));
						}
					}
				}
			}
		}
		memset(col,-1,sizeof(col));
		for(int i = 0 ; i < 4 * N * N ; ++i) {
			if(col[i] == -1) dfs(i);
			cr[i] = cr[i] << 1 | col[i];
		}
	}
	for(int i = 0 ; i < 4 * N * N ; ++i) ++cnt[cr[i]];
	int t = 0;
	for(int i = 1 ; i < 4 ; ++i) {
		if(cnt[i] > cnt[t]) t = i;
	}
	int a = N * N;
	for(int i = 0 ; i < 4 * N * N ; ++i) {
		if(!a) break;
		if(cr[i] == t) {
			out(i / (2 * N));space;out(i % (2 * N));enter;
			--a;
		}
	}
}


Measured memory_bytes: 81152
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val s = sc.nextLine()
    val r = (s.toBigInteger() % 9.toBigInteger()).toInt()
    println(if (r == 0) "Yes" else "No")
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 40024
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	string S;
	cin >> N >> S;
	if (N >= 3200) {
		cout << S << endl;
	}
	else {
		cout << "red" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
N,k = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
MOD = 10**9+7
for i in range(N):
    for j in range(i+1,N):
        if A[i] > A[j]:
            ans += k*(k+1)//2
        elif A[i] < A[j]:
            ans += k*(k-1)//2

        ans %= MOD

print(ans)

Measured memory_bytes: 3188
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author ExplodingFreeze
 */

#include <iostream>
#include <fstream>

#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define int long long
#define f(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
using pii=std::pair<int,int>;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); <-- PUT IN main()/solve()!

using namespace std;

int n,a[3005],ans[3005][3005];
class LDeque {
public:
	void solve(std::istream& in, std::ostream& out) {
		in >> n;
		f(i,0,n)
			in >> a[i];
		f(i,0,n)
			f(j,0,n)
				ans[i][j]=-1;
		out << dp(0,n-1) << "\n";
	}
	int dp(int i,int j)
	{
		if(i>j)
			return 0;
		else if(ans[i][j]==-1)
			ans[i][j]=max(a[i]-dp(i+1,j),a[j]-dp(i,j-1));
		return ans[i][j];
	}
};


int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	LDeque solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 71040
h, w = map(int, input().split())
graph = [[] for _ in range(10)]
for i in range(10):
    graph[i] += list(map(int, input().split()))


graph = list(zip(*graph))

vst = 1
n = 10
checked = [0] * n
dist = [float('inf')] * n
dist[vst] = 0
for _ in range(n):
    min_dist = float('inf')
    for i in range(n):
        if checked[i] == 0 and dist[i] < min_dist:
            target_v = i
            min_dist = dist[i]
    checked[target_v] = 1
    for to_v in range(n):
        cost = graph[target_v][to_v]
        dist[to_v] = min(dist[target_v] + cost, dist[to_v])



ret = 0
for i in range(h):
    for j in map(int, input().split()):
        if j != -1:
            ret += dist[j]


print(ret)

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

  map<int,int> ring;
  int i;
  for (i = 0; i < N; i++){
  	int key;
    cin >> key;
    ring[key] = 1;
  }
  
  int counter = 0;
  for (auto x : ring)
    counter++;
  cout << counter << endl;
}

Measured memory_bytes: 764
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
long long xo(long long x)
{
	long long i=x-x%8ll;
    long long sum=0;
    for(; i<=x; i++)
        sum^=i;
    return sum;
}
int main()
{
	long long l,r;
    scanf("%lld%lld",&l,&r);
    printf("%lld\n",xo(r)^xo((l-1)));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;
 
    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }
    
    vvl dp(n+1, vl(n+1));  // dp[l][r] : aの区間[l,r)から始めて二人が最適に行動したときのx-yの値
    exrep(len, 1, n) {
        for(ll l = 0; l + len <= n; l++) {
            ll r = l + len;
            if(n%2 == len%2) {
                dp[l][r] = max(dp[l+1][r] + a[l], dp[l][r-1] + a[r-1]);
            }
            else {
                dp[l][r] = min(dp[l+1][r] - a[l], dp[l][r-1] - a[r-1]);
            }
        }
    }
    
    out(dp[0][n]);
    re0;
}

Measured memory_bytes: 70784
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s = scn.next();
		String t = scn.next();
      	char[] ss = s.toCharArray();
      	Arrays.sort(ss);
      	String sss = new String(ss);
      	char[] tt = t.toCharArray();
      	Arrays.sort(tt);
      	String T = new String(tt);
      	String ttt = new StringBuilder(T).reverse().toString();
      	if (sss.compareTo(ttt) < 0)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}


Measured memory_bytes: 35724
//be naame khodaa
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
#define F first
#define S second
#define pb push_back
#define sz(x) ((int)(x).size())

inline int in(){ int x, y; y = scanf("%d", &x); return x; }

const int N = 105;

int a[N];

int main(){
	int n = in();
	for (int i = 0; i < n; i++)
		a[i] = in()-1;
	vector <int> ans;
	for (int i = 0; i < n; i++){
		int nxt = -1;
		for (int j = 0; j < n-i; j++)
			if (a[j] == j)
				nxt = j;
		if (nxt == -1)
			return (cout << -1 << endl), 0;
		ans.pb(nxt);
		for (int j = nxt; j+1 < n-i; j++)
			a[j] = a[j+1];
	}
	reverse(ans.begin(), ans.end());
	for (auto x : ans)
		cout << x+1 << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define PI          acos(-1)
#define INF         100000000
#define sc(n)       scanf("%d",&n);
#define ssc(n)      scanf("%s",n);
#define lsc(n)      scanf("%lld",&n);
#define dsc(n)      scanf("%lf",&n);
#define csc(n)       scanf("%c",&n);
#define LL          long long int
#define UI          unsigned int
#define ULL         unsigned long long int
#define DB          double
#define pii         pair<int,int>
#define VI          vector<int>
#define MII         map<int,int>
#define PB          push_back
#define MP          make_pair
#define M(mx,a)     mx=max(mx,a)
#define IT          ::iterator
#define all(a)      a.begin(),a.end()
#define mems(a,b)   memset(a,b,sizeof(a))
#define F(i,a,b)    for(i=a;i<b;i++)
#define IN(n,aa)    for(i=0;i<n;i++)scanf("%d",&aa[i]);
#define PNT(n,aa)   for(i=0;i<n;i++)printf("%lld ",aa[i]);
#define mod         1000000007
#define NUM         10000009
#define NUM2        1000000000


int main()
{
    int T=1,QQ=0;
    //cin >> T ;
    while(T--)
    {
        int n;
        cin >> n;
        int i,j,k,sm=0;
        int aa[n],bb[n],cc[n];
        for(i=0;i<n;i++)sc(aa[i]);
        for(i=0;i<n;i++)
        {
            sc(bb[i]);
            sm+=bb[i];
        }
        for(i=0;i<n-1;i++)sc(cc[i]);
        for(i=0;i<n;i++)
        {
            if(aa[i]+1==aa[i+1])sm+=cc[aa[i]-1];
        }
        cout << sm ;
    }
}

//printf("Case %d: ",++QQ);


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

int main(){
    string S;
    cin >> S;
    string X = S.substr(0,S.size()/2);
    string Y = S.substr(S.size()/2+1);
    for(int i = 0; i < S.size(); i++) {
        if(S[i] != S[S.size()-1-i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    for(int i = 0; i < S.size()/2; i++) {
        if(X[i] != X[S.size()/2-1-i]) {
            cout << "No" << endl;
            return 0;
        }
        else if(Y[i] != Y[S.size()/2-1-i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

#define V (1000000007)

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N,0);
    for (int i=0; i<N; ++i) {
        cin >> A[i];
    }
    ll ans0 = 0;
    // Aの転倒数
    for (int i=0; i<N-1; ++i) {
        for (int j=i+1; j<N; ++j) {
            ans0 += A[i] > A[j] ? 1 : 0;
        }
    }
    ll ans1 = 0;
    // 2つのAの間の転倒数
    for (int i=0; i<N; ++i) {
        for (int j=0; j<N; ++j) {
            if (j==i) continue;
            ans1 += A[i] > A[j] ? 1 : 0;
        }
    }

    // cout << "ans0: " << ans0 << endl;

    ll ans=0;
    // K個のAの繰り返しの転倒数
    // K個 + (K comb 2 = KC2)
    ans += (K * ans0) % V;
    ans += (K*(K-1)/2 % V) * (ans1 % V) % V;
    ans %= V;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
const long long INF = LLONG_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ll long long int
#define ALL(x) x.begin(),x.end()
using namespace std;
ll ans = 0, sum = 0, n, k, counter = 0, w, h;
string s;
vector<ll> v;
vector < pair<ll, ll > > vp;
vector<vector<ll> > vv(50, vector<ll>(50, INF));
vector<string> vs;
vector<char> vc;
vector<ll> vi;
/*--------------------template--------------------*/


int main() {
	cin >> n;
	w = n / 11;
	k = n % 11;
	if (k > 6) {
		sum = 2;
	}
	else if (k == 0) {
		sum = 0;
	}
	else {
		sum = 1;
	}
	cout << w * 2 + sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

struct UnionFind{
private:
    vector<int> par;
    vector<int> rank;
    vector<int> sz;

public:
    //n要素で親を初期化、par[x]はxの親を表す
    UnionFind(int n){
        par.resize(n,0);
        rank.resize(n,0);
        sz.resize(n,1);
        rep(i,n){
            par[i] = i;
        }
    }

    //木の根を求める
    int root(int x){
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    //xとyの属する集合を併合
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        else{
            par[y] = x;
            sz[x] += sz[y];
            if(rank[x] == rank[y]) rank[x]++;
        }
    }

    //xとyが同じ集合に属するか否か
    bool same(int x, int y){
        return root(x) == root(y);
    }

    //xが属する集合のサイズを返す
    int size(int x){
        return sz[root(x)];
    }
};

int main(){
    int n,m; cin >> n >> m;
    UnionFind uf(n);
    rep(i,m){
        int x,y; cin >> x >> y;
        int z; cin >> z;
        x--;y--;
        uf.unite(x,y);
    }
    set<int> st;
    rep(i,n){
        st.insert(uf.root(i));
    }
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 6144
p = input().split()
n = int(p[0])
k = int(p[1])
if n % 2 == 1:
    if k <= n//2+1:
        print("YES")
    else:
        print("NO")
else:
    if k < n//2+1:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 3060
#include <stdio.h>

int main( void )
{
	int H;
	int W;
	int loop1;
	int loop2;

	while( 1 ){
		scanf( "%d %d", &H, &W );
		if( ( 0 == H ) && ( 0 == W ) ) {
			break;
		}

		for ( loop1 = 0; loop1 < H; loop1++ ) {
			for ( loop2 = 0; loop2 < W; loop2++ ) {
				if ( ( 0 == loop1 ) || ( ( H - 1 ) == loop1 ) ) {
					printf("#");
				} else {
					if ( ( 0 == loop2 ) || ( ( W - 1 ) == loop2 ) ) {
						printf( "#" );
					} else {
						printf( "." );
					}
				}
			}
			printf("\n");
		}
		printf( "\n" );

	}

	return ( 0 );
}

Measured memory_bytes: 572