akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#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_V = 410;  // デフォルトで頂点数の最大値は400

int main() {
    ll h, w;
    cin >> h >> w;

    const ll n = 10;

    vvl dist(MAX_V, vl(MAX_V));  // dist[v][u] : 頂点vと頂点uの最短距離
    rep(v, n) {
        rep(u, n) {
            if(v != u) {
                dist[v][u] = INF;
            }
        }
    }

    rep(i, n) {
        rep(j, n) {
            ll c;
            cin >> c;
            dist[i][j] = c;
        }
    }
    
    // ワーシャルフロイド法。計算量はO(V^3)
    rep(k, n) {
        rep(i, n) {
            rep(j, n) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    ll ans = 0;
    rep(i, h) {
        rep(j, w) {
            ll a;
            cin >> a;
            if(a != -1) {
                ans += dist[a][1];
            }
        }
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main(){
 
int n ; cin>>n;
int a[n];
bool b= false;
for(int i = 0  ; i<n ;i++){
    cin>>a[i];
 
}
for(int i = 0 ; i<n ; i++)
{
    if(a[i]%2==0){
 
        if(a[i]%3!=0 && a[i]%5 != 0){ b= true;
        break;
                                    }
    }
}
if(b==true)cout<<"DENIED";
else cout<<"APPROVED";
return 0 ;
 
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(i%2==0)
			cout<<s[i];
		continue;
	}
	return 0;

}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
    int N, L;
    string S[110];
    cin >> N >> L;
    for (int i = 0; i < N; i++) cin >> S[i];

    sort(S, S + N);
    string connected = "";
    for (int i = 0; i < N; i++){
        connected += S[i];
    }
    cout << connected << endl;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fo(i, n) for(int i = 1; i <= n; ++i)

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

const int N = 200200;
const int mod = 1e9 + 7;
int n,m,u,v,cost;
int in[N], out[N];

vector<int> g[N], gr[N], er[N], e[N];
vector<int> order;
int d[N];
int used[N];
int q[N];
int was[N];

inline void dfs(int v, int p = -1)
{
	used[v] = 1;
	for(int to : g[v])
	{
		if(to == p) continue;
		if(used[to] == 1)
		{
			cout << "No";
			exit(0);
		}
		if(!used[to])
			dfs(to, v);
	}
	used[v] = 2;
}

inline void placeon(int v)
{
	for(int i = 0; i < g[v].size(); ++i)
	{
		int to = g[v][i], cost = e[v][i];
		if(was[to] == 0)
			was[to] = 1, d[to] = d[v] + cost, placeon(to);
		else
			if(d[to] != d[v] + cost)
			{
				cout << "No";
				exit(0);
			}
	}
	for(int i = 0; i < gr[v].size(); ++i)
	{
		int to = gr[v][i], cost = er[v][i];
		if(was[to] == 0)
			was[to] = 1, d[to] = d[v] - cost, placeon(to);
		else
			if(d[to] != d[v] - cost)
			{
				cout << "No";
				exit(0);
			}
	}
}

int main()
{
	scanf("%d%d", &n, &m);
	fo(i, m)
	{
		scanf("%d%d%d",&u,&v,&cost);
		g[u].pb(v);
		e[u].pb(cost);
		gr[v].pb(u);
		er[v].pb(cost);
		out[u]++;
		in[v]++;
	}	
	fo(i, n)
		if(!used[i])
			dfs(i);
	fo(i, n)
		if(!was[i])
			was[i] = 1, placeon(i);
	cout << "Yes";
	return 0;            
}

Measured memory_bytes: 50304
#include <iostream>
#include <map>

using namespace std;

int main(){
    long long TS, TA, AS, AA;
    int flag=0;

    cin >> TS >> TA >> AS >> AA;
    while(TS>0&&AS>0){
        AS-=TA;
        if(AS<=0) {
            flag=1;
            cout << "Yes" << endl;
            break;
        }
        TS-=AA;
        if(TS<=0) {
            flag=2;
            cout << "No" << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3604
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

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

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

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

    int N, Z, W;
    read(N, Z, W);

    vector<int> a(N);
    for (auto &e : a) read(e);

    // dp[i][turn]
    auto dp = make_v<i64>(0, N+5, 2);

    repr(i, N-1, 0) {
        {
            const int P = (i >= 1 ? a[i-1] : W);
            dp[i][0] = abs(a[N-1] - P);
            reps(k, i+1, N-1) chmax(dp[i][0], dp[k][1]);
        }
        {
            const int P = (i >= 1 ? a[i-1] : Z);
            dp[i][1] = abs(a[N-1] - P);
            reps(k, i+1, N-1) chmin(dp[i][1], dp[k][0]);
        }

    }

    print(dp[0][0]);

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int main(){
  int n; cin >> n;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  sort(all(a));
  sort(all(b));

  if(n%2 == 0){
    double mi = (double)(a[n/2-1] + a[n/2]) / 2;
    double ma = (double)(b[n/2-1] + b[n/2]) / 2;
    double ans = (ma-mi) * 2 + 1;
    cout << (int)ans << endl;
  }

  else{
    int mi = a[n/2];
    int ma = b[n/2];
    int ans = ma - mi + 1;
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;


int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n){
        cin >> a.at(i);
    }
    const ll s = accumulate(ALL(a), 0LL);
    ll ans = 0;
    REP(i, n){
        if(abs(a.at(i) * n - s) < abs(a.at(ans) * n - s)){
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3596
N=int(input())
ans=10**20
for a in range(1,N//2+2):
    b=N-a
    A=a
    B=b
    s=0
    while(A!=0):
        s+=A%10
        A//=10
    while(B!=0):
        s+=B%10
        B//=10
    ans=min(ans,s)
print(ans)


Measured memory_bytes: 41068
N,M,K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))

from itertools import accumulate
from collections import deque
A=deque(list(accumulate(A)))
B=deque(list(accumulate(B)))
A.appendleft(0)
B.appendleft(0)
ans1=0
for i in range(N+1):
    if A[i]>K:
        ans1=i-1
        break
else:
    ans1=N
ans2=0
ans3=0
# print(ans1)
for i in range(ans1+1):
#     print(i)
    while i+ans2<=M and A[ans1-i]+B[i+ans2]<=K:
        ans2+=1
#         print(ans1,ans2,i)
    ans3=max(ans3,ans1+ans2-1)
print(ans3)

Measured memory_bytes: 119516
/* 
 Author:N_o_o_B 
 Created:September 28 2019 17:08:15
*/
#include <bits/stdc++.h>
using namespace std;

#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define endl '\n'
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
const ll mod=1e9+7;
const ll INF=1e18;
const ll sz=(1<<12)+5;
vector<ll> dp(sz,-1);
vector<bool> adj[1005];
vector<ll> a(1005);
int n,m;
ll f(vector<bool> cur){
    int cnt=0;
    for(int i=0;i<n;i++) cnt+=cur[i]*(1<<i);
    if(cnt==((1<<n)-1)) return 0;
    if(dp[cnt]!=-1) return dp[cnt];
    dp[cnt]=1e18;
    fori(i,m){
        vector<bool> nxt=cur;
        fori(j,n){
            nxt[j]=adj[i][j]||cur[j];
        }
        if(nxt==cur) continue;
        dp[cnt]=min(dp[cnt],a[i]+f(nxt));
    } 
    return dp[cnt];
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;

    cin >> n;
    cin >> m;
    fori(i,m){
        int b;
        cin >> a[i] >> b;
        adj[i]=vector<bool>(n,0);
        while(b--){
            int x;
            cin >> x;
            x--;
            adj[i][x]=1;
        }
    }
    vector<bool> foo(n,0);
    cout << (f(foo)>=1e18?-1:f(foo)) << endl;
    time_taken();
    return 0;
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
	h := nextInt()
	w := nextInt()
	if h == 1 || w == 1 {
		fmt.Println(1)
	} else {
		if (h+w)%2 == 0 {
			fmt.Println(h*w/2 + (h*w)%2)
		} else {
			fmt.Println(h * w / 2)
		}
	}
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

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

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
}

Node treeMaximum(Node x){
}

Node treeSearch(Node u, int k){
}

Node treeSuccessor(Node x){
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x != NIL){
    y=x;
    if(z->key<x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL)root = z;
  else if(z->key<y->key)y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if(u == NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



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

int main() {
  long long A, B, K;
  cin >> A >> B >> K;
  if (K <= A) {
    cout << A - K << " " << B << endl;
  } else if (K <= A + B) {
    cout << 0 << " " << A + B - K << endl;
  } else {
    cout << 0 << " " << 0 << endl;
  }
}

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

int main()
{
    string s;
    cin >> s;
    if(s == "ABC") puts("ARC");
    else puts("ABC");
    return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>

#define NMAX 100000
#define INF (1 << 30)

typedef struct {
    char color;
    int val;
} CARD;

int merge(CARD A[], int left, int mid, int right) {
    CARD L[NMAX], R[NMAX];
    int i, j, k, cnt;
    for (i = 0; i < mid - left; i++) {
        L[i] = A[left + i];
    }
    L[i].val = INF;
    for (i = 0; i < right - mid; i++) {
        R[i] = A[mid + i];
    }
    R[i].val = INF;
    i = 0, j = 0, cnt = 0;
    for (k = left; k < right; k++) {
        if (L[i].val <= R[j].val) {
            A[k] = L[i++];
        } else {
            A[k] = R[j++];
            // cnt += mid - left - i;
        }
        cnt++;
    }
    return cnt;
}

int mergeSort(CARD A[], int left, int right) {
    if (right - left <= 1) {
        return 0;
    }
    int mid = (left + right) / 2, cnt = 0;
    cnt += mergeSort(A, left, mid);
    cnt += mergeSort(A, mid, right);
    cnt += merge(A, left, mid, right);
    return cnt;
}

int partition(CARD A[], int p, int r) {
    int i = p - 1, j = p, x = A[r].val;
    CARD t;
    while (j < r) {
        if (A[j].val > x) {
            // A[p,i]<=x
            j++;
        } else {
            // A[i,j)>x
            i++;
            t = A[i];
            A[i] = A[j];
            A[j] = t;
            j++;
        }
    }
    t = A[i + 1];
    A[i + 1] = A[r];
    A[r] = t;
    return i + 1;
}

void quickSort(CARD A[], int p, int r) {
    if (r - p <= 0) {
        return;
    }
    int q = partition(A, p, r);
    quickSort(A, p, q - 1);
    quickSort(A, q + 1, r);
}

int main() {
    CARD A[NMAX], B[NMAX];
    int n;
    scanf("%d", &n);
    char buf[100];
    for (int i = 0; i < n; i++) {
        scanf("%s %d", buf, &A[i].val);
        A[i].color = buf[0];
        B[i] = A[i];
    }
    quickSort(A, 0, n - 1);
    mergeSort(B, 0, n);
    int b = true;
    for (int i = 0; i < n; i++) {
        if (A[i].color != B[i].color || A[i].val != B[i].val) {
            b = false;
            break;
        }
    }
    if (b) {
        printf("Stable\n");
    } else {
        printf("Not stable\n");
    }

    for (int i = 0; i < n; i++) {
        printf("%c %d\n", A[i].color, A[i].val);
    }
    return 0;
}


Measured memory_bytes: 4912
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<string> substr(10);
  for (int i = 0; i < 10; i++) {
    auto pos = s.find(to_string(i));
    if (pos != string::npos)
      substr[i] = s.substr(pos + 1);
    else
      substr[i] = "";
  }
  
  vector<vector<vector<bool>>> t(10, vector<vector<bool>>(10, vector<bool>(10, false)));
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      auto pos = substr[i].find(to_string(j));
      string sj;
      if (pos != string::npos)
        sj = substr[i].substr(pos + 1);
      else
        continue;

      for (int k = 0; k < 10; k++) {
        auto posk = sj.find(to_string(k));
        if (posk != string::npos) {
          t[i][j][k] = true;
        }
      }
    }
  }
  int count = 0;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
        if (t[i][j][k])
          count++;
      }
    }
  }
  
  cout << count << endl;

  
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long hey;
#define hi string
#define pi 3.141592653589793238
#define fi first
#define mod 1000000007
#define se second
#define pb push_back 
#define pop pop_back 
#define bs binary_search
#define mp make_pair
#define ma map< hey,hey >
#define vi vector < hey > 
#define vs vector < hi > 
#define all(v) v.begin(),v.end()
#define qu priority_queue< hey >
#define endl '\n'
#define forn(a,b) for (hey i = a; i <hey(b); ++i)
#define yorn(i, n) for (hey i = 0; i <hey(n); ++i)
#define vp vector< pair<hey,hey> >
// lower bound - first element equal to or greater than given value.
// upper bound - first element greater than given value.
        // 2 Pointers is love
hey prime(hey n)
{
    if(n<=1)
	return 0;
	if(n<=3)
	return 1;
	if(n%2==0 || n%3==0)
	return 0;
	for(hey i=5;i*i<=n;i=i+6)
	{
		if(n%i==0 || n%(i+2)==0)
		return 0;
	}
	return 1;
}

void curious()
{
    hey a[6];
    forn(1,6)
    {
        cin>>a[i];
    }
    forn(1,6)
    {
        if(a[i]==0)
        {
            cout<<i;
          return;
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{
	    curious();
	}
	return 0;
}

Measured memory_bytes: 3572
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define M 1000000007LL
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(v) ((ll)v.size())
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pii pair<ll,ll> 
#define mod 1000000007LL
#define MAXN 300002
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
ll pre[300002];
ll a[300002],b[300002];
int main() {
string s;
cin>>s;
ll ans=0,cnt=0;
for(ll i=s.size()-1;i>=0;i--)
{
if(i and s[i]=='C' and s[i-1]=='B')
    {cnt++;i--;}
else if(s[i]=='A') ans+=cnt;
else cnt=0;
}
cout<<ans;
}

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

using pii = pair<int, int>;

constexpr int dx[2][8] = {{0, 1, 0, -1, 0, 0, 0, 0}, {0, 1, 1, 1, 0, -1, -1, -1}};
constexpr int dy[2][8] = {{1, 0, -1, 0, 0, 0, 0, 0}, {-1, -1, 0, 1, 1, 1, 0, -1}};

string dfs(int y, int x, vector<vector<bool>>& visited, vector<string> const& v) {
    const int H = v.size();
    const int W = v[0].size();
    bool black = v[y][x] == '#';
    visited[y][x] = true;
    queue<pii> que;
    que.push(make_pair(y, x));
    vector<pii> next;
    while(!que.empty()) {
        auto p = que.front();
        int y2 = p.first,
            x2 = p.second;
        que.pop();
        for(int i = 0; i < (black ? 8 : 4); ++i) {
            int ny = y2 + dy[black][i],
                nx = x2 + dx[black][i];
            if(ny < 0 || H <= ny || nx < 0 || W <= nx || visited[ny][nx]) {
                continue;
            }
            if(v[ny][nx] != v[y][x]) {
                next.push_back(make_pair(ny, nx));
            } else {
                visited[ny][nx] = true;
                que.push(make_pair(ny, nx));
            }
        }
    }

    string res = "(";
    vector<string> tmp;
    for(auto& to : next) {
        if(visited[to.first][to.second]) {
            continue;
        }
        tmp.push_back(dfs(to.first, to.second, visited, v));
    }
    sort(tmp.begin(), tmp.end());
    for(auto& s : tmp) {
        res += move(s);
    }
    res += ")";
    return res;
}

int main() {
    int h1, w1;
    int cnt = 0;
    while(cin >> h1 >> w1, h1) {
        cnt ++;
        vector<string> v(h1 + 2, string(w1 + 2, '.'));
        vector<vector<bool>> visited1(h1 + 2, vector<bool>(w1 + 2));
        for(int i = 1; i <= h1; ++i) {
            string s;
            cin >> s;
            v[i] = "." + s + ".";
        }
        int h2, w2;
        cin >> h2 >> w2;
        vector<string> v2(h2 + 2, string(w2 + 2, '.'));
        vector<vector<bool>> visited2(h2 + 2, vector<bool>(w2 + 2));
        for(int i = 1; i <= h2; ++i) {
            string s;
            cin >> s;
            v2[i] = "." + s + ".";
        }
        bool same = dfs(0, 0, visited1, v) == dfs(0, 0, visited2, v2);
        cout << (same ? "yes" : "no") << endl;
    }
}


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

using namespace std;

int main(int argc, char const *argv[]) {
	int n,temp;
	std::cin >> n;
	std::vector<int> v;
	for (size_t i = 0; i < n; i++) {
		std::cin >> temp;
		v.push_back(temp);
	}

	bool flag = false;
	int count = 0;
	while (true) {
		for (size_t i = 0; i < n; i++) {
			if (v[i] % 2 == 0) {
				v[i] /= 2;
			}
			else {
				flag = true;
				break;
			}
		}
		if (flag) {
			std::cout << count << '\n';
			break;
		}
		count++;
	}
	return 0;
}


Measured memory_bytes: 256
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
#define endl '\n'
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size() 
#define UB upper_bound
#define LB lower_bound
#define BP(x) __builtin_popcountll(x)
#define PQS priority_queue <int, vector<int>, greater<int> > 
#define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getRand(int l, int r) {
  uniform_int_distribution<int> uid(l, r);
  return uid(rng);
}

const int INF = 1e18 + 0;
const int mod = 1e9 + 7;
//const int mod = 998244353;

int toPower(int a, int p){
    int res = 1;
    while (p){
        if (p & 1) res = ll(res) * a % mod;
        p >>= 1; a = ll(a) * a % mod;
    }
    return res;
}

int sub(int a, int b) { a %= mod; b %= mod; return  ((a - b + mod) % mod);}
int add(int a, int b) { a %= mod; b %= mod; return ((a + b) % mod); }

void solve() {
  int n; cin >> n;
  int ans = add(toPower(10,n), toPower(8,n));
  ans = sub(ans, 2*toPower(9,n));
  cout << ans << '\n';
}

/*
  * overflow, array bounds
  * do smth instead of nothing and stay organized
*/
signed main() {   
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

  #ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
  #endif
   int t = 1; // cin >> t;
   for(int i = 1; i <= t; i++) {
   //  cout << "Case #" << i << ": ";
     solve();
  }
}    

/*

*/

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string s, m;
	cin >> s >> m;
	reverse(s.begin(), s.end());
	if (s==m) {
		cout << "YES";
		return 0;
	}
	cout << "NO";
	return 0;
}

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

int main(void)
{
	char message[2002];
	int i, j, num, len;
	
	scanf("%d", &num);
	getchar();
	while (num--){
		memset(message, '\0', sizeof(message));
		scanf("%[^\n]", message);
		getchar();
		
		len = strlen(message);
		for (i = 0; i <= len - 7; i++){
			if (strncmp(&message[i], "Hoshino", 7) == 0){
				strncpy(&message[i], "Hoshina", 7);
			}
		}
		
		printf("%s\n", message);
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>

using namespace std;

int main(void) {
	char s[3];
	cin >> s;
	int price = 700;
	for (int i = 0; i < 3; i++) {
		if (s[i] == 'o') {
			price += 100;
		}
	}
	cout << price << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bitset>
using namespace std;
#define Bit(A) bitset<3>(A)
int main(){
	string s;
	int a[114514],t[114514],sum;
	cin>>s;
	for(int i=0;i<s.size();i++)a[i]=(s[i]-'0');
	for(int i=0;i<(1<<3);i++){
		sum=a[0];
		for(int j=0;j<3;j++){
			if(i&(1<<j)){//0以外のとき
				sum+=a[j+1];
				t[j]=1;
			}
			else{
				sum-=a[j+1];
				t[j]=0;
			}
		}
		if(sum==7){
			break;
		}
	}
	cout<<a[0];
	for(int i=0;i<3;i++){
		if(t[i]==1)cout<<"+";
		else cout<<"-";
		cout<<a[i+1];
	}
	cout<<"=7"<<endl;
	return 0;
}

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

using namespace std;
const int N = 200000 + 10;
typedef long long ll;
ll arr[N];
int n, a, b;
int check(ll x)
{
    ll sum = 0;
    for(int i = 1; i<=n; i++)
    {
        if(arr[i] <= 1LL*x*b)
            continue;
        else
        {
            sum += (arr[i] - 1LL*x*b) / (a-b);
            if((arr[i] - 1LL*x*b) % (a-b)!=0)
                sum++;
        }
    }
    //cout<<sum<<" "<<x<<endl;
    return sum <= x;
}
int main()
{

    while(cin>>n>>a>>b)
    {
        for(int i = 1; i<=n; i++)
            scanf("%lld", &arr[i]);
        ll l= 0, r = 1e9 + 10;
        while(l<=r)
        {
            ll mid = (l+r)>>1;
            if(check(mid))
                r = mid - 1;
            else l = mid + 1;
        }
        cout<<l<<endl;
    }
    return 0;
}



Measured memory_bytes: 1024
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

results = [-1]*2001
results[0]=0
results[1]=0
results[2]=0

def cc(v):
	global results
	if results[v] >= 0:
		return results[v]
		
	ret = 1
	for i in range(3, v+1):
		ret += cc(v-i)
		ret %= mod
	
	results[v]=ret
	return ret
		
def main():
	s = int(input())
	#b , c = tin()
	#s = input()
	return cc(s)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 70600
#include<iostream>
#include <algorithm>
#include <string>
#include<math.h>
using namespace std;
int main() {
	int A;
	int B;
	cin>>A>>B;
	if(A<=9&&B<=9)
		cout<<A*B<<endl;
	else
		cout<<-1<<endl;
	return 0;
}

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

#define ms(a,v)        memset(a,v,sizeof a)
#define lll            long long
#define FOR(i,a,b)     for(int i=a;i<=b;i++)
#define fast           ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Read           freopen("READ.txt", "r", stdin)
#define Write          freopen("OUTPUT.txt", "w", stdout)
#define INF            -999999999
#define Co(x)          cout<<x<<endl;
#define Cos(x)         cout<<x<<" ";

typedef vector<long long>vii;
typedef pair<long long,long long>Pair;
typedef map<long long,long long>Map;

int dr[]={1,0,-1, 0 };
int dc[]={0,1, 0,-1 };

//int dr[]={1,1,0,-1,-1,-1, 0, 1};
//int dc[]={0,1,1, 1, 0,-1,-1,-1};

/*while(1) {
    if(!getline(cin,s)||s.empty()) break;
}*/

const int RT = 10000000;
vector<int>prime;
bitset<10000003> status;

void sieve()
{
    int rt = sqrt(RT);
    //for(int i = 4; i <= rt; i+=2) status[i]=true;
    for(int i = 3; i <= rt; i+=2)
        if(!status[i])
            for(int j = i*i; j < RT; j+=(i<<1))
                status[j] = true;
    prime.push_back(2);
    for(int i = 3; i <= RT; i+=2)
        if(!status[i])
            prime.push_back(i);
}

void Binary_Con(int n)
{
    int binaryNum[70];
    int i = 0;
    while (n > 0) {
        binaryNum[i] = n % 2;
        n = n / 2;
        i++;
    }
    // printing binary array in reverse order
    for (int j = i - 1; j >= 0; j--)
        cout << binaryNum[j];
}


void solve()
{
   int x;
   cin>>x;
   if(x==0) cout<<1<<endl;
   else cout<<0<<endl;
}

void kick_ass()
{
    fast
    #ifndef ONLINE_JUDGE
    Read;
    Write;
    #endif
    //int t; cin>>t; while(t--) solve();
    solve();
}

int main()
{
   kick_ass();
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
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 = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1'000'000'007;
// const ll MOD = 998244353;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/
template<typename T>
vector<T> smallest_prime_factors(T n) {

    vector<T> spf(n + 1);
    for (int i = 0; i <= n; i++) spf[i] = i;


    for (T i = 2; i * i <= n; i++) {

        // 素数だったら
        if (spf[i] == i) {

            for (T j = i * i; j <= n; j += i) {

                // iを持つ整数かつまだ素数が決まっていないなら
                if (spf[j] == j) {
                    spf[j] = i;
                }
            }
        }
    }

    return spf;
}

template<typename T>
map<T, int> factolization(T x, vector<T> &spf) {
    // vector<T> ret;
    map<T, int> mp;
    while (x != 1) {
        // ret.push_back(spf[x]);
        mp[spf[x]]++;
        x /= spf[x];
    }
    // sort(ret.begin(), ret.end());
    // return ret;
    return mp;
}
int main(){
    constexpr int MAX = 1000000;

    auto spf = smallest_prime_factors(MAX);

    int Q;
    cin >> Q;
    vector<int> v(MAX, 0);
    ll G = -1;
    while (Q--) {
        int x;
        cin >> x;
        if(G == -1)G = x;
        else{
            G = gcd(G, x);
        }
        auto result = factolization(x, spf);
        // for (auto z: result)cout << z << " ";
        // cout << endl;
        // print(result);
        for(auto p: result){
            v[p.first]++;
        }
    }
    bool ok = true;
    rep(i,MAX)if(v[i] >= 2)ok = false;
    if(ok){
        cout << "pairwise coprime" <<endl;
    }
    else if(G == 1){
        cout << "setwise coprime" << endl;
    }
    else{
        cout << "not coprime" << endl;
    }
    return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  REP(i, H) cin >> S[i];
  // x W i
  // y H j
  // S[y][x]
  int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
  int dy[8] = {1, 1, 1, 0, 0, -1, -1, -1};
  for(int j = 0; j < H; j++) {
    for(int i = 0; i < W; i++) {
      if(S[j][i] == '#') {
        cout << '#';
        continue;
      }
      int cnt = 0;
      for(int d = 0; d < 8; d++) {
        int x = i + dx[d];
        int y = j + dy[d];
        if(x < 0 || x >= W) continue;
        if(y < 0 || y >= H) continue;
        if(S[y][x] == '#') cnt++;
      }
      cout << cnt;
    }
    cout << endl;
  }

  return 0;
}

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

using namespace std;

int C[10001] = {0};

int main(){
    int n;
    short num;
    scanf("%d",&n);
    
    for (int i = 0; i < n; i++) {
        scanf("%hd",&num);
        C[num]++;
    }
    
    short count = 0;
    int s = 1;
    
    while (s <= n-1) {
        if (C[count]) {
            printf("%d ",count);
            s++;
            C[count]--;
        }else{
            count++;
        }
    }
    while (C[count]==0) {
        count++;
    }
    printf("%d\n",count);
    
    return 0;
}

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

#define LL long long

LL n,a,b,k;
LL fact[300009];
LL M = (LL)(998244353);

void pre(){
	fact[0] = 1;
	for(int i=1;i<=n;i++){
		fact[i] = (fact[i-1]*i)%M;
	}
}

LL power(LL x,LL y){
	LL res=1;
	while(y>0){
		if(y%2 != 0){
			res = (res * x)%M;
		}
		y/=2;
		x = (x*x)%M;
	}
	return res;
}

LL inv(LL x){
	return power(x,M-2);
}

int main(){
	

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin>>n>>a>>b>>k;

	pre();

	LL ans = 0;
	for(int i=0;i<=n;i++){
		if((k-(i*a))%b == 0){
			if(((k-(i*a))/b)<=n && ((k-(i*a))/b)>=0){
				int j = (k-(i*a))/b;
				LL x = (fact[n]*inv(fact[i]))%M;
				x = (x*inv(fact[n-i]))%M;
				LL y = (fact[n]*inv(fact[j]))%M;
				y = (y*inv(fact[n-j]))%M;
				ans = ans + (x*y)%M;
				ans = ans%M;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"YES\n":"NO\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  REP(i,n) {cin >> a[i]; b[i] = a[i];}
  sort(b.begin(), b.end());
  int cnt = 0;
  REP(i,n) {
    if(a[i] != b[i]) cnt++;
  }
  bool f = false;
  if(cnt == 0 || cnt == 2) f = true;
  YesorNo(f);
  return 0;
}
//templete by private_yusuke

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

ll dist[10][10];
vector<Vi> A;
int H, W;



int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    cin >> H >> W;
    A.assign(H, Vi(W));
    fill_n(&dist[0][0], sizeof(dist) / sizeof(dist[0][0]), L_INF);
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            ll d;
            cin >> d;
            dist[i][j] = d;
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            ll x;
            cin >> x;
            A[i][j] = x;
        }
    }


    for (int k = 0; k < 10; k++) {
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                if (dist[i][k] != L_INF && dist[i][k] != L_INF)
                    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }


    ll ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (A[i][j] == -1) continue;
            ans += dist[A[i][j]][1];
        }
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;
typedef long long ll;
const ll p = 1e9 + 7;
const int N = 1e5 + 10;
ll x[N];
ll y[N];

ll add(ll a, ll b) {
    a += b;
    if (a >= p)
        a -= p;
    return a;
}

ll sub(ll a, ll b) {
    a -= b;
    if (a < 0)
        a += p;
    return a;
}

ll mult(ll a, ll b) {
    return (a * b) % p;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    ll sum_x = 0;
    ll sum_y = 0;
    for (int i = 0; i < n; i++) {
        cin >> x[i];
        sum_x = add(sum_x, mult((n - 1 - 2 * (n - 1 - i)), x[i]));
    }
    for (int i = 0; i < m; i++) {
        cin >> y[i];
        sum_y = add(sum_y, mult(m - 1 - 2 * (m - 1 - i), y[i]));
    }
    sum_x = sum_x % p;
    if (sum_x < 0)
        sum_x += p;
    sum_y = sum_y % p;
    if (sum_y < 0)
        sum_y += p;
    cout << sum_x * sum_y % p << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
const int inf = 1e9;
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = 1;i <= n;i++)
typedef pair<int,int> P;

queue<P> q1, q2;
char str[1004][1004];
int a[1004][1004], b[1004][1004], h, w;
int dy[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dx[] = {-1, 0, 1, -1, 1, -1, 0, 1};

void calc(int y, int x){
	if(b[y][x] || !a[y][x] || a[y][x] == -1)return ;
	if(a[y][x] != inf){
		if(!(--a[y][x]))q1.push(P(y, x));
		return ;
	}
	b[y][x] = 1;
	for(int i = 0;i < 8;i++)calc(y+dy[i], x+dx[i]);
}

int solve(int k){
	if(q1.empty())return 0;
	while(!q1.empty()){
		P p = q1.front();q1.pop();
		b[p.fi][p.se] = 1;
		for(int i = 0;i < 8;i++){
			int yy = p.fi+dy[i], xx = p.se+dx[i];
			if(!b[yy][xx] && a[yy][xx] != inf && a[yy][xx] != 0){
				if(--a[yy][xx] == 0)q2.push(P(yy, xx));
			}
		}
	}
	swap(q1, q2);
	return k+1;
}

int main(){
	fill((int*)a, (int*)(a+1004), -1);
	scanf("%d%d", &h, &w);
	rep(i,h)scanf("%s", str[i]);
	rep(i,h)rep(j,w){
		if(str[i][j] == '.')a[i+1][j+1] = inf;
		else a[i+1][j+1] = str[i][j]-'0';
	}
	
	int res = 0, ans = 1;
	rrep(i,h)rrep(j,w)if(a[i][j] == inf)calc(i, j);
	while(1){
		res = solve(res);
		if(res == 0)break;
		ans = res;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 12248
#include <iostream>

using namespace std;

int main(void){
	double num;
	double min;
	double max;
	cin >> num;
	min = num;
	max = num;
	while(cin >> num){
		if(num>max) max = num;
		if(num<min) min = num;
	}
	cout << max - min << endl;
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 100;
int a[maxn];
int main(){
	int n, m;
	cin >> n >> m;
	int sum = 0;
	for (int i = 1; i <= n; i++)
		cin >> a[i], sum += a[i];
	double x = sum*1.0 / 4*1.0 / m;
	int cnt = 0;
	for (int i = 1; i <= n; i++){
		if (a[i] >= x)
			cnt++;
	}
	if (cnt >= m) cout << "Yes" << endl;
	else cout << "No" << endl;;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>

int main() {
  
  int n,i,j,a,M[100][100],G[100],h[100],gn,weight,min,index;
  
  scanf("%d",&n);
  for (i = 0;i < n;i++){
    G[i] = 1;
    h[i] = 0;
    for (j = 0;j < n;j++) scanf("%d",&M[i][j]);
  }
  
  h[0] = 1;
  G[0] = 0;
  gn = n - 1;
  weight = 0;
  
  while(gn--){
    min = INT_MAX;
    
    for (j = 0;j < n;j++){
      if(!h[j])
	continue;
      for (i = 0;i < n;i++){
	if(!G[i])
	  continue;
	a = M[j][i];
	if (0 <= a && a < min){
	  index = i;
	  min = a;
	}
      }
    }
    h[index] = 1;
    G[index] = 0;
    weight += min;
  }
  printf("%d\n",weight);
  
  return 0;
  
}


Measured memory_bytes: 2084
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <queue>
#include <functional>

#define out(t) cout << (t) << "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;

void swap(int &a, int &b) {
    a ^= b;
    b ^= a;
    a ^= b;
}

uint tzcnt(uint x) {
    x = ~x & (x - 1);
    x -= x >> 1 & 0x55555555;
    x = (x & 0x33333333) + (x >> 2 & 0x33333333);
    x = x + (x >> 4) & 0x0F0F0F0F;
    return x * 0x01010101 >> 24;
}

int c[100000 + 1];
int c2[100000 + 1];

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

    long long N, M;
    cin >> N >> M;

    if (N >= 3 && M >= 3) {
        out((N - 2) * (M - 2));
    }
    else if (N == 1) {
        if (M == 1) {
            out(1);
        }
        else {
            out(M - 2);
        }
    }
    else if (M == 1) {
        out(N - 2);
    }
    else {
        out(0);
    }

    int aaa;
    cin >> aaa;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
 

int main(){
    ll N;
    cin >> N;
    if (N%2==1) {
        cout << 0 << endl;
        return 0;
    }
    ll num5 = 0;
    N /= 2;
    while(true){
        if (N<4) break;
        num5 += N/5;
        N /= 5;
    }
    cout << num5 << endl;

}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int D,T,S;
    cin >> D >> T >> S;
    if(T*S>=D){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;
  ll sum=0;
  cin>>n;
  vector<ll> a(n+1),d(n+1);
  FOR(i,1,n+1){
    cin>>a[i];
    sum+=a[i];
  }
  if(sum%(n*(n+1)/2)!=0){
    cout<<"NO"<<endl;
    return 0;
  }else k=sum/(n*(n+1)/2);
  FOR(i,1,n) d[i]=a[i+1]-a[i]-k;
  d[n]=a[1]-a[n]-k;
  int ans=0;
  FOR(i,1,n+1){
    if(d[i]<0) d[i]*=-1;
    if(d[i]%n!=0){
      cout<<"NO"<<endl;
      return 0;
    }else ans+=d[i]/n;
  }
  if(ans==k) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
#define MAX 100
#define INFINITY 100000000
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[MAX][MAX];

int prim(){
  int i, minv, u, v, sum;
  int d[MAX], p[MAX], color[MAX];

  for(i = 0; i < n; i++){
    d[i] = INFINITY;
    p[i] = -1;
    color[i] = WHITE;
  }
  
  d[0] = 0;
  
  while(1){
    minv = INFINITY;
    u = -1;
    for(i = 0; i < n; i++){
      if(minv > d[i] && color[i] != BLACK){
	u = i;
	minv = d[i];
      }
    }
    if(u == -1) break;
    color[u] = BLACK;
    for(v = 0; v < n; v++){
      if(color[v] != BLACK && M[u][v] != INFINITY){
	if(d[v] > M[u][v]){
	  d[v] = M[u][v];
	  p[v] = u;
	  color[v] = GRAY;
	}
      }
    } 
  }

  sum = 0;
  for(i = 0; i < n; i++){
    if(p[i] != -1) sum += M[i][p[i]];
  }

  return sum;
  
}

int main(){
  int i, j, e;
  
  scanf("%d", &n);

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      scanf("%d", &e);
      M[i][j] = (e == -1) ? INFINITY : e;
    }
  }

  printf("%d\n", prim());

  return 0;
}



Measured memory_bytes: 2048