akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long llint;
const llint MOD = 1'000'000'007;

int main() {
    llint N, Q;
    cin >> N >> Q;
    vector<vector<int>> vv(N + 5);
    for(int i = 1; i < N; i++) {
        int u, v;
        cin >> u >> v;
        vv[u].push_back(v);
        vv[v].push_back(u);
    }
    vector<llint> add(N+5);
    for(int i = 0; i < Q; i++) {
        llint p, x;
        cin >> p >> x;
        add[p] += x;
    }
    queue<int> q;
    vector<llint> parent(N+5); 
    q.push(1);
    parent[1] = 1;
    while(!q.empty()) {
        int u = q.front();
        q.pop();
        for(auto v: vv[u]) {
            if(parent[v] == 0) {
                parent[v] = u;
                add[v] += add[u];
                q.push(v);
            }
        }
    }
    for(int i = 1; i <= N; i++)
        cout << add[i] << " ";
}

Measured memory_bytes: 17908
# ABC132 D Blue and Red Balls

def comb(n, r):
    if n == 0 or r == 0:
        return 1
    if n < r:
        return 0
    a = b = 1
    r = min(n-r, r)
    for i in range(n-r+1,n+1):
        a*=i
    for i in range(1,r+1):
        b*=i
    
    return a//b

N, K = map(int, input().split())
MOD = int(1e9)+7

for i in range(1, K+1):
    temp = comb(N-K+1, i) * comb(K-1, i-1)
    print(int(temp % MOD))


Measured memory_bytes: 3316
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	string s;
	cin>>s;
	int mn=1000;
	int n=s.size();
	for(int i=0; i<=n-3; i++){
		int x=(s[i+2]-'0')+(s[i+1]-'0')*10+(s[i]-'0')*100;
		mn=min(mn, abs(x-753));
	}
	cout<<mn<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
ll val(ll a[],ll b[],ll w,ll i,vector<vector<ll> > &dp){
    if(w==0 || i<0)
    return 0;
    
    if(dp[i][w]!=-1)
    return dp[i][w];
    
    if(w-a[i]<0)
    return dp[i][w]=val(a,b,w,i-1,dp);
    
    return dp[i][w]=max(b[i]+val(a,b,w-a[i],i-1,dp),val(a,b,w,i-1,dp));
}
 
int main() {
    fastio
    
	ll n,i,j,x,t,k,m,w;
	cin>>n>>w;
	
	ll a[n],b[n];
	vector<vector<ll> > dp(n,vector<ll> (w+1,-1));
	
	for(j=0;j<n;j++)
	cin>>a[j]>>b[j];
	
	cout<<val(a,b,w,n-1,dp);
	
	return 0;
}

Measured memory_bytes: 82392
import sys
word = [chr(i) for i in range(97, 97+26)]
word_number = []
lines = ""
for line in sys.stdin:
    lines += line

for target in word:
    count = 0
    for character in lines:
        if character.lower() == target:
            count += 1
    word_number.append(count)

for i in range(26):
    print("{0} : {1}".format(word[i],word_number[i]))

Measured memory_bytes: 7432
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
//const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint f(int n) {
  if (n == 0) return 1;
  mint x = f(n/2);
  x *= x;
  if (n%2 == 1) x *= 2;
  return x;
}

mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i,a) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}


int main() {
    int n; cin >> n;
    vector<ld> ar(n);
    ld ans = 0;
    rep(i,n) cin >> ar[i];
    sort(ar.begin(),ar.end());
    ans = (ar[0] + ar[1]) / 2.0;
    repp(i,n,2) ans = (ans + ar[i]) / 2.0;
    cout << setprecision(20);
    cout << ans << endl;
}

Measured memory_bytes: 256
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
n=int(input())
a=factorization(n)
ans=0
if a[0][0]==1:
  print(0)
else:
  for i in a:
    now=(2*i[1])**0.5
    now=int(now//1)
    while now*(now+1)<=2*i[1]:
      now+=1
    ans+=now-1
  print(ans)

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

char button[10][10] = {
  {},
  {'\'', ',', '.', '!', '?'},
  {'a', 'b', 'c', 'A', 'B', 'C'},
  {'d', 'e', 'f', 'D', 'E', 'F'},
  {'g', 'h', 'i', 'G', 'H', 'I'},
  {'j', 'k', 'l', 'J', 'K', 'L'},
  {'m', 'n', 'o', 'M', 'N', 'O'},
  {'p', 'q', 'r', 's', 'P', 'Q', 'R', 'S'},
  {'t', 'u', 'v', 'T', 'U', 'V'},
  {'w', 'x', 'y', 'z', 'W', 'X', 'Y', 'Z'}
};
int button_num[10] = {0, 5, 6, 6, 6, 6, 6, 8, 6, 8};

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string str;
  while(cin >> str){
    int idx = 0;
    string ans;
    char c;
    for(int i = 0; i < str.length(); i++){
      int num = str[i] - '0';
      if(i == 0){
        if(num == 0) continue;
        c = button[num][idx];
        idx++;



      }else{
        int before = str[i-1] - '0';
        if(num != before && before != 0){
          ans.append(1, c);
          idx = 0;
        }
        if(num == 0){
          idx = 0;
          if(before == num){
            ans.append(1, ' ');
          }
        }else{
          c = button[num][idx];
          idx = (idx + 1) % button_num[num];

          if(i == str.length() - 1){
            ans.append(1, c);
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1184
from itertools import product

N = int(input())

xs = []
ys = []
hs = []

sampleX = -1
sampleY = -1
sampleH = 0

for n in range(N):
  x,y,h = map(int, input().split())
  xs.append(x)
  ys.append(y)
  hs.append(h)

  if h is not 0:
    sampleX = x
    sampleY = y
    sampleH = h

for cx, cy in product(range(101), range(101)):
  H = sampleH + abs(sampleX - cx) + abs(sampleY - cy)
  for x,y,h in zip(xs,ys,hs):
    if not max(H - abs(x-cx) - abs(y-cy), 0) == h:
      break
  else:
    print(cx, cy, H)
    break
else:
  raise "hoge"


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n, m;
	cin >> n >> m;
	vector<int> to, islands(n + 1);
	for(int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		if(a == 1) {
			islands[b] = 1;
		}
		if(b == n) {
			to.push_back(a);
		}
	}
	for(int i = 0; i < to.size(); i++) {
		if(islands[to[i]]) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;	
}


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

int main(void) {
    string s;
    cin >> s;
    deque<int> dq;
    
    for(char c: s) {
        if(c == '0') dq.push_back(0);
        else if(c == '1') dq.push_back(1);
        else if(c == 'B') {if(!dq.empty()) dq.pop_back();}
    }
    
    for(int e: dq) {
        cout << e;
    }
    cout << endl;
    
    return 0;
}

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

using namespace std;

int main() {

	string k;
	int d;
	cin >> k >> d;

	int numberOfDigits = k.length();
	// cout << numberOfDigits << endl;


	// The number of ways to make a number whose digit sum % d is x
	long long numberOfWays[d][numberOfDigits + 1];
	
	for (int i = 0; i < d; i++) {
		for (int j = 0; j < numberOfDigits + 1; j++) {
			numberOfWays[i][j] = 0;
		}
	}

	numberOfWays[0][0] = 1;
	for (int i = 0; i < 10; i++) {
		numberOfWays[i % d][1]++;
	}

	int currentVal = 2;

	while (currentVal <= numberOfDigits) {

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

			for (int j = -9; j <= 0; j++) {

				int accessVal = i + j;
				while (accessVal < 0) {
					accessVal += d;
				}

				numberOfWays[i][currentVal] += numberOfWays[accessVal][currentVal - 1];

			}

			numberOfWays[i][currentVal] %= 1000000007;

		}

		currentVal++;

	}

	long long finalNumberOfWays = 0;
	long long currentSum = 0;

	while (!k.empty()) {

		int firstDigit = k[0] - '0';
		int numberOfDigits = k.length();
		
		if (k.length() == 1) {
			for (int i = 0; i <= firstDigit; i++) {
				if ((i + currentSum) % d == 0) {
					finalNumberOfWays += 1;
				}
			}
			break;
		}
		

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

			int accessVal = 0 - i - currentSum;
			while (accessVal < 0) {
				accessVal += d;
			}

			finalNumberOfWays += numberOfWays[accessVal][numberOfDigits - 1];
			finalNumberOfWays %= 1000000007;
			// cout << numberOfWays[accessVal][numberOfDigits - 1] << endl;
		}

		// k /= 10;
		k = k.substr(1);
		currentSum += firstDigit;

		// cout << "k: " << k << endl;
	}

	finalNumberOfWays--;
	cout << finalNumberOfWays % 1000000007 << endl;

	// numberOfWays[0]--;
	// for (int i = 0; i < d; i++) {
	// 	for (int j = 0; j < numberOfDigits + 1; j++) {
	// 		cout << numberOfWays[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }

}

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

int main(void){

    int a, b;
    cin >> a >> b;
    
    if(a <= b){
        for(int i=0; i<b; i++){
            cout << (char)(a+'0');
        }
        cout << endl;
    }else{
        for(int i=0; i<a; i++){
            cout << (char)(b+'0');
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;


vector<int> era(int x)
{
	int search[x];
	int len = 0;
	vector<int> primes;
	search[0] = search[1] = 0;
	for (int i = 2; i < x; i++)
		search[i] = 1;
	double root_x = sqrt(x);
	for (int i = 0; ; i++) {
		int num = search[i];
		if (num == 1) {
			if (root_x <= i)
				break;
			else {
				primes.push_back(i); len++;
				for (int j = i; j < x; j+=i)
					search[j] = 0;
			}
		}
	}
	for (int i = 0; i < x; i++) {
		if (search[i] == 1) {
			primes.push_back(i); len++;
			search[i] = 0;
		}
	}
	return primes;
}

int main(void) {

	vector<int> primes = era(1000000);

	while (1) {
		int a, d, n;
		cin >> a >> d >> n;
		if (a == 0 && d == 0 && n == 0) break;
		int count_primes = 0;
		int primes_now = 0;
		for (int i = a; i < 1000000; i+=d) {
			for (int j = primes_now; j < primes.size(); j++) {
				if (primes[j] == i) {
					count_primes++;
					primes_now = j;
					break;
				}
				else if (primes[j] > i) {
					primes_now = j;
					break;
				}
			} 
			if (count_primes == n) {
				cout << i << endl;
				break;
			} 
		}
	}
	return 0;
}



Measured memory_bytes: 7160
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
    int H=1, W=1, i, j;
    while(H!=0&&W!=0){
        cin >>H>>W;
        if(H==0&&W==0) break;
        for(i=0;i<H;i++){
            for(j=0;j<W;j++){
                cout <<"#";
            }
            cout <<endl;
        }
        cout <<endl;
    }
    return 0;
}


Measured memory_bytes: 3072
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
#define repr(i ,n) for(int i=n;i>(int)(n);--i)
#define rep1(i ,n) for(int i=1;i<=(int)(n);++i)
#define ALL(a) a.begin(), a.end()
#define RSORT(a) sort(ALL(a),greater<>())
#define SORT(a) sort(ALL(a))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define PRINT(x) printf("%d\n",(x));
#define ENDL printf("\n");
using namespace std;
typedef long long int i64;
typedef unsigned long long u64;
template<class T> using V = vector<T>;
using VI = V<int>;
const int INF = 2e9;
const i64 MOD = 1e9 + 7;

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

signed main(){
    int r ; cin >> r;
    double PI = acos(-1);
    cout << fixed << 2 * PI * (double)r << endl;
}

Measured memory_bytes: 3788
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long[] a = sc.nextLongArray(n);
        for(int i = 0; i < n-k; i++){
            if(a[i] < a[i+k]){
                pw.println("Yes");
            }else{
                pw.println("No");
            }
        }
        pw.flush();
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

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


Measured memory_bytes: 55884
import sys
input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))

def main():
    N,P = ints_raw()
    return (N*3+P)//2

print(main())


Measured memory_bytes: 38256
#include<bits/stdc++.h>
#include<stdio.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;


#define ll                  long long
#define scl(n)              scanf("%lld",&n)
#define scll(n, m)          scanf("%lld%lld",&n, &m)
#define scc(c)	            scanf("%c",&c)
#define fr(i,n)             for (ll i=0;i<n;i++)
#define fr1(i,n)            for(ll i=1;i<=n;i++)
#define pfl(x)              printf("%lld\n",x)
#define pb                  push_back
#define debug               cout<<"I am here"<<endl;
#define pno                 cout<<"NO"<<endl
#define pys                 cout<<"YES"<<endl
#define tcas(i,t)           for(ll i=1;i<=t;i++)
#define all(x) 	            (x).begin(), (x).end()
#define allrev(x)           (x).rbegin(),(x).rend()
#define pr                  pair<ll, ll>
#define ff                  first
#define ss                  second
#define pn                  printf("\n")

#define N 200005

ll m,n,k, a[N],cut=0;

bool is_posi(ll x)
{
    cut=0;
    fr(i, n)
    {
        cut += a[i] / x;
        if (a[i] % x == 0)cut--;
    }

    //return cut<=k;

    if(cut<=k)return 1;
    else return 0;
}

int main()
{
    ll t;
    t=1;
    tcas(cs, t)
    {
        cin>>n>>k;
        ll cnt=0,cn=0,ans,sum=0, mx=-1 ;
        fr(i, n)cin>>a[i];

        ll l=1 , r=1e9, mid;
        ans=mx;

        while(l<=r)
        {
            mid=(l+r)/2;
            if(is_posi(mid ) )r=mid-1  , ans=mid;
            else l=mid+1;
        }

        cout<<ans<<endl;
    }

return 0;
}

/// **************************Before submit****************************

///    ****Please check all base case output  and printing " YES or NO " ***
///    *check for integer overflow,array bounds
///    *check for n=1


Measured memory_bytes: 5072
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<string.h>
#include<vector>
#include<math.h>
#include<queue>
#include <algorithm>
#include<functional>
#include<cstdlib>
#include<cmath>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;

int N;

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


void input(void) {
	
	return;
}


int main(void) {


	int answer = 0;
	
	while (CI N) {
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				for (int k = 0; k < 10; k++) {
					for (int l = 0; l < 10; l++) {
						if (i + j + k + l == N) {
							answer++;
						}
					}
				}
			}
		}

		CO answer E
		answer = 0;
	}
	
	return 0;
}

Measured memory_bytes: 2992
#include<iostream>
using namespace std;
int main(){
    int a, b, c;
    cin >> a >> b >>c;
    
    if ((a < b) && (b < c)) cout << "Yes" << endl;//if(a < b < c)とすると(a<b)||(b<c)の扱いになる
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 3100
//#define C
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var NW = ReadLine().Split().Select(int.Parse).ToArray();
        var N = NW[0];
        var W = NW[1];
        var w = new int[N + 1];
        var v = new int[N + 1];
        for (int i = 0; i < N; i++)
        {
            var wv = ReadLine().Split().Select(int.Parse).ToArray();
            w[i + 1] = wv[0];
            v[i + 1] = wv[1];
        }

        var dp = new long[N + 1, W + 1];

        for (int i = 1; i <= N; i++)
        {
            for (int j = 0; j <= W; j++)
            {
                if (j - w[i] >= 0) dp[i, j] = Math.Max(dp[i - 1, j], dp[i - 1, j - w[i]] + v[i]);
                dp[i, j] = Math.Max(dp[i, j], dp[i - 1, j]);
            }
        }

        WriteLine(dp[N, W]);
    }
}


Measured memory_bytes: 91104
// B - Touitsu
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N; cin>>N;
	string A,B,C; cin>>A>>B>>C;
	int count = 0;
	rpz(i, N){
		char a = A[i], b = B[i], c = C[i];
		if(a!=b && b!=c && c!=a) count += 2;
		else if(a==b && b==c) count += 0;
		else if(a==b || a==c || b==c) count += 1;
	}
	cout<< count <<endl;
}

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
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; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int h, a;
    cin >> h >> a;
    print((h + a - 1) / a);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int h, w, i, f=0, j;
    vector<string> s(101);
    vector<int> retu(101, 0);
    vector <int> gyou(101, 0);
    cin >> h >> w;
    for(i=0;i<h;i++){
        cin >> s[i];
    }
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            if(s[i][j]=='#'){
                retu[j]=1;
                gyou[i]=1;
            }
        }
    }

    for(i=0;i<h;i++){
        f=0;
        for(j=0;j<w;j++){
            if(gyou[i]==1 && retu[j]==1){
                cout << s[i][j];
                f=1;
            }
        }
        if(f==1) cout <<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define DB double
#define INF 1145141919810364364
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define MOD 998244353
#define ERR 0.00000001
#define NUM 200010

void swap(LL* a,LL* b){LL tmp=*a;*a=*b;*b=tmp;}
void YN(int a){if(a==1)printf("Yes\n");if(a==0)printf("No\n");}
LL lpow(LL a,LL n){LL ans=pow(a,n)*10;if(ans%10<5)return ans/10;return ans/10+1;}
LL dup(LL a,LL d){if(a%d==0)return a/d;else return a/d+1;}
LL GCD(LL a,LL b){LL c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int lcmpr(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return -1;if(*(LL*)a<*(LL*)b)return 1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int ccmpr(const void* a,const void* b){return *(char*)b-*(char*)a;}
int scmp(const void* a,const void* b){return strcmp((char*)a,(char*)b);}
int scmpr(const void* a,const void* b){return strcmp((char*)b,(char*)a);}
LL mod(LL a,LL m){if(a<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(&m,&d);x-=k*y;swap(&x,&y);}return mod(a*mod(x,MOD),MOD);}
LL FAC(LL a){LL i,ans=1;FOR(i,1,a+1){ans*=i;if(MOD>0&&ans>MOD)ans%=MOD;}return ans;}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
LL fact[NUM],finv[NUM],inv[NUM];
void comi(){LL i;fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}

int main(){
  LL N,K,i,ans=0,a=1;
  scanf("%lld%lld",&N,&K);
  while(a<=N){
    ans++;
    a*=K;
  }

  printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <bitset>
#include <list>
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a,n) for(ll i=n;i>=a;i--)
#define elif else if
#define all(s) s.begin(),s.end()
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF = 1e+17;
const ll MODcdf = 998244353;
bool pairCompare(const P& firstElof,const P& secondElof){
    return firstElof.first<secondElof.first;
}
string A="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string a="abcdefghijklmnopqrstuvwxyz";
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n;cin>>n;
    ll tp=n%100;
    ll bt=n/100;
    //cout<<tp<<" "<<bt<<endl;
    bool flag_tp=false;
    bool flag_bt=false;
    if(tp<13&&tp>0)flag_tp=true;
    if(bt<13&&bt>0)flag_bt=true;
    bool flag_both=false;
    if(flag_tp&&flag_bt)flag_both=true;
    //cout<<flag_tp<<" "<<flag_bt<<" "<<flag_both<<endl;
    string ans;
    if(flag_both)ans="AMBIGUOUS";
    elif(flag_tp)ans="YYMM";
    elif(flag_bt)ans="MMYY";
    else ans="NA";
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
const MOD: u64 = 1000000007;
#[allow(dead_code)]
fn to_num(c: char) -> i64 {
    c as i64 - 48
}


fn main() {
    input!{
        N: usize, K: usize,
        A: [usize; N]
    }
    println!("{}", (N - 2) / (K - 1) + 1 );
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
using namespace std;
int head, tail;
const int num = 100005;
typedef struct pp {
	char name[11];
	int t;
} p;
p s[num];
void enqueue(p a) {
	s[tail] = a;
	tail = (1 + tail) % num;
}
p dequeue() {
	p b = s[head];
	head = (1 + head) % num;
	return b;
}

int main() {
	int n, q, i, sum = 0;
	cin >> n;
	cin >> q;
	for (i = 0; i < n; i++) {
		cin >> s[i].name >> s[i].t;
	}
	head = 0;
	tail = n;
	while (head != tail) {
		p c = dequeue();
		int j = min(q, c.t);
		c.t -= j;
		sum += j;
		if (c.t > 0) 
			enqueue(c);
		else cout << c.name <<' '<< sum << endl;
	}
	return 0;
}

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

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


Measured memory_bytes: 3116
#include<iostream>
using namespace std;
int main(){
	int x,y;
	cin >> x >> y;
	bool ans=false;
	if(x==2 && y==2) ans=true;
	else if((x==4||x==6||x==9||x==11)&&(y==4||y==6||y==9||y==11)) ans=true;
	else if((x==1||x==3||x==5||x==7||x==8||x==10||x==12)&&(y==1||y==3||y==5||y==7||y==8||y==10||y==12)) ans=true;
	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100005
#define NIL -1

struct Node {
    int parent, left, right;
};

struct Node Tree[MAX];
int n, D[MAX], H[MAX];

void setDepth (int u, int d) {
    if (u == NIL) return;
    D[u] = d;
    setDepth(Tree[u].left, d + 1);
    setDepth(Tree[u].right, d + 1);
}

int setHeight (int u) {
    int h1 = 0, h2 = 0;
    if (Tree[u].left != NIL) h1 = setHeight(Tree[u].left) + 1;
    if (Tree[u].right != NIL) h2 = setHeight(Tree[u].right) + 1;
    return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling (int u) {
    if (Tree[u].parent == NIL) return NIL;
    if (Tree[Tree[u].parent].left != NIL && Tree[Tree[u].parent].left != u) return Tree[Tree[u].parent].left;
    if (Tree[Tree[u].parent].right != NIL && Tree[Tree[u].parent].right != u) return Tree[Tree[u].parent].right;
    return NIL;
}

void print (int u) {
    printf("node %d: ",u);
    printf("parent = %d, ",Tree[u].parent);
    printf("sibling = %d, ",getSibling(u));
    int deg = 0;
    if (Tree[u].left != NIL) deg++;
    if (Tree[u].right != NIL) deg++;
    printf("degree = %d, ",deg);
    printf("depth = %d, ",D[u]);
    printf("height = %d, ",H[u]);
    if ( Tree[u].parent == NIL) printf("root\n");
    else if ( Tree[u].left == NIL && Tree[u].right == NIL) printf("leaf\n");
    else printf ("internal node\n");
}

int main () {
    int i;
    int v,l,r, root = 0;
    scanf("%d",&n);

    for ( i = 0; i < n; i++) Tree[i].parent = Tree[i].parent = NIL;

    for ( i = 0; i < n; i++) {
        scanf("%d%d%d",&v,&l,&r);
        Tree[v].left = l;
        Tree[v].right = r;
        if (l != NIL) Tree[l].parent = v;
        if (r != NIL) Tree[r].parent = v;
    }

    for (i = 0; i < n; i++) if (Tree[i].parent == NIL) root = i;
    setDepth(root, 0);
    setHeight(root);

    for (i = 0; i < n; i++) print(i);
    return 0;
}


Measured memory_bytes: 2128
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        Set<String> s = new HashSet<>();
        for (int i = 0; i < N; i++) {
            s.add(scanner.next());
        }
        System.out.println(s.size());
    }
}

Measured memory_bytes: 77052
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

string s;

int32_t main()
{
	IOS;
	cin >> s;
	int carry = 0, ans = 0;
	for(int i = s.size() - 1; i >= 0; i--)
	{
		int val = s[i] - '0';
		val += carry;
		carry = val / 10;
		val %= 10;
		if(val >= 6)
		{
			ans += (10 - val);
			carry = 1;
		}
		else if(val == 5)
		{
			if(i - 1 >= 0 && s[i - 1] >= '5')
			{
				ans += (10 - val);
				carry = 1;
			}
			else
				ans += val;
		}
		else
			ans += val;
	}	
	cout << ans + carry;
	return 0;
}

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

#define watch(x) cout<<#x<<" -> "<<x<<endl
#define ALL(x) x.begin() , x.end()
#define INF 100000
typedef long long ll;
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
        long long  n;
        cin>>n;
        long long mod = 1e9 + 7;
        long long sum = 0;
        vector<long long> arr(n + 1) , pref(n + 1);
        for (int i = 1;i<=n ;i++){
            cin>>arr[i];
        }
        pref[n] = arr[n];
        for (int i = n-1;i >=1;i--){
            pref[i] = (pref[i + 1] + arr[i])%mod;
        }
        for (int i = 1;i<n ;i ++){
            sum = (sum + (arr[i] * pref[i + 1]) % mod) % mod;
        }
        cout<<sum<<endl;
}

Measured memory_bytes: 6336
#include<stdio.h>

int main(){
  char input;
  
  while(1){
    int cnt=0,ans=0;

    while(1){
      scanf("%c", &input);
      if(input =='\n') break;

      ans += input - '0';
      ++cnt;
    }

    if(ans == 0) break;

    printf("%d\n", ans);
  }
  
  return 0;
}



Measured memory_bytes: 2700
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;

int main()
{

    int N,T,c[110]={},t[110]={},f=0,ans=INT32_MAX;
    cin>>N>>T;

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

        if(t[i]<=T){
            ans = min(ans,c[i]);
            f=1;
        }
    }


    if(f==1){
        cout << ans <<endl;
    }else{
        cout <<"TLE"<<endl;
    }
    return 0;
}


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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

// del

const i64 MAXN = 303;

i64 n, m, l;
i64 q;
pair<i64, i64> a[MAXN * MAXN];

i64 d[MAXN][MAXN];
i64 E[MAXN][MAXN];


int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n >> m >> l;

    for (i64 i = 0; i < n; i++) {
        for (i64 j = 0; j < n; j++) {
            d[i][j] = inf;
        }
    }

    for (i64 i = 0; i < m; i++) {
        i64 u, v, c;
        cin >> u >> v >> c;
        u--;
        v--;
        d[u][v] = c;
        d[v][u] = c;
    }

    cin >> q;
    for (i64 i = 0; i < q; i++) {
        cin >> a[i].first >> a[i].second;
        a[i].first--;
        a[i].second--;
    }

    for (i64 k = 0; k < n; k++) {
        for (i64 i = 0; i < n; i++) {
            for (i64 j = 0; j < n; j++) {
                if (d[i][k] < inf && d[k][j] < inf) {
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }
    }

    for (i64 i = 0; i < n; i++) {
        for (i64 j = 0; j < n; j++) {
            E[i][j] = inf;
        }
    }

    for (i64 i = 0; i < n; i++) {
        for (i64 j = 0; j < n; j++) {
            if (d[i][j] <= l) {
                E[i][j] = 1;
            }
        }
    }

    for (i64 k = 0; k < n; k++) {
        for (i64 i = 0; i < n; i++) {
            for (i64 j = 0; j < n; j++) {
                if (E[i][k] < inf && E[k][j] < inf) {
                    E[i][j] = min(E[i][j], E[i][k] + E[k][j]);
                }
            }
        }
    }

    for (i64 i = 0; i < q; i++) {
        i64 c = E[a[i].first][a[i].second];
        cout << (c == inf ? -1 : c - 1) << endl;
    }



    return 0;
}

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

using namespace std;

const int N = 2e3 + 5;
int u[N][N] , d[N][N] , l[N][N] , r[N][N];

int main() {
    int n , m;
    cin >> n >> m;
    n += 2 ;
    m += 2;
    vector<string> grid(n , string(m , '#'));
    for (int i = 1 ;i < n - 1;i++)
        for (int j = 1 ;j < m - 1 ;j++)
            cin >> grid[i][j];

    for (int i = 1 ;i < n - 1 ;i++) {
        for (int j = 1 ;j < m - 1 ;j++)
            if (grid[i][j] != '#')
                l[i][j] = l[i][j - 1] + 1;

        for (int j = m - 2 ;j >= 1 ;j--)
            if (grid[i][j] != '#')
                r[i][j] = r[i][j + 1] + 1;
    }

    for (int j = 1 ;j < m - 1 ;j++) {
        for (int i = 1 ;i < n - 1 ;i++)
            if (grid[i][j] != '#')
                u[i][j] = u[i - 1][j] + 1;

        for (int i = n - 2 ;i >= 1 ;i--)
            if (grid[i][j] != '#')
                d[i][j] = d[i + 1][j] + 1;
    }


    int ans = 0;
    for (int i = 1 ;i < n - 1 ;i++)
        for (int j = 1 ;j < m - 1 ;j++)
            ans = max(ans , u[i][j] + d[i][j] + l[i][j] + r[i][j] - 3);

    cout << ans;
}


Measured memory_bytes: 70316
#include<iostream>
using namespace std;
int main(void){
  int N ,M ;
  cin>>N>>M;
  int i;
  int l,r;
  int s,d;
  s=0;
  d=100000;
  for(i=0;i<M;i++){
      cin>>l>>r;
      if(l>s){
          s=l;
      }
      if(r<d){
          d=r;
      }


  }

  if(s>d){
      cout<<0<<endl;
  }else{
      cout<<d-s+1<<endl;
  }

 return 0 ;
}
  


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var ans: Int
    if (n == 100000) return println(90909)
    if (n > 9999) ans = n - 9999 + 909
    else if (n > 999) ans = 909
    else if (n > 99) ans = n - 99 + 9
    else if (n > 9) ans = 9
    else ans = n
    println(ans)
}


Measured memory_bytes: 31956
// Problem : A - ∴ (Therefore)
// Contest : AtCoder - AtCoder Beginner Contest 168
// URL : https://atcoder.jp/contests/abc168/tasks/abc168_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define mi map<int,int>
#define ml map<ll,ll>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define MAX 4294967295
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MAXN 15000005
#define inf 1e10
#define PI acos(-1.0)
#define int long long

int n;

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    cin>>n;
    n %= 10;
    if(n==1 || n==0 || n==6 || n==8) cout<<"pon\n";
    else if(n==3) cout<<"bon\n";
    else cout<<"hon\n";
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) x.begin(),x.end()
using namespace std;


int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int n;
    cin >> n;
    ll ans=0;
    for (int i=1; i <= n; ++i) {
        for (int j=1; j<= n / i; ++j) {
            if (i * j >= n) break;
            else ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

memo = [float("INF")]*(10)
memo[1] = 0
flag = True
while flag:
    flag = False
    for i in range(10):
        for j in range(10):
            if memo[i]+costMap[j][i] < memo[j]:
                memo[j] = memo[i]+costMap[j][i]
                flag = True
ans = 0
for i in range(H):
    for j in range(W):
        a = wall[i][j]
        if a != -1:
            ans += memo[a]
print(ans)

Measured memory_bytes: 40284
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int MX = 1000005;

int main(){
    int n;
    cin>>n;
    rep(i,11){
        if (1000*i>=n){
            cout<<1000*i-n<<endl;
            break;
        }
    }
}

Measured memory_bytes: 3648
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 28 15:46:33 2019

@author: Yamazaki Kenichi
"""

N = int(input())
A = list(map(int,input().split()))
 
def eg(x,y):
    if y == 0:
        return x
    x, y = y, x%y
    return eg(x,y)

L, R = [0 for i in range(N)],[0 for i in range(N)]
L[0], R[N-1] = A[0], A[N-1]
for i in range(1,N):
    L[i] = eg(L[i-1], A[i])
    R[N-1-i] = eg(R[N-i], A[N-1-i])
ans = [0 for i in range(N)]
for i in range(N):
    if i == 0:
        ans[i] = R[i+1]
    elif i == N-1:
        ans[i] = L[i-1]
    else:
        ans[i] = eg(L[i-1],R[i+1])

print(max(ans))
    


    

Measured memory_bytes: 14428
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    string s;
    cin >> s;
    if (s == "Sunny")
        cout << "Cloudy" << endl;
    else if (s == "Cloudy")
        cout << "Rainy" << endl;
    else
        cout << "Sunny" << endl;
}

Measured memory_bytes: 256
def getsum(BITTree, i):
    s = 0  # initialize result

    # index in BITree[] is 1 more than the index in arr[]
    i = i + 1

    # Traverse ancestors of BITree[index]
    while i > 0:
        # Add current element of BITree to sum
        s += BITTree[i]

        # Move index to parent node in getSum View
        i -= i & (-i)
    return s


# Updates a node in Binary Index Tree (BITree) at given index
# in BITree. The given value 'val' is added to BITree[i] and
# all of its ancestors in tree.
def updatebit(BITTree, n, i, v):
    # index in BITree[] is 1 more than the index in arr[]
    i += 1

    # Traverse all ancestors and add 'val'
    while i <= n:
        # Add 'val' to current node of BI Tree
        BITTree[i] += v

        # Update index to that of parent in update View
        i += i & (-i)

    # Constructs and returns a Binary Indexed Tree for given


# array of size n.
def construct(arr, n):
    # Create and initialize BITree[] as 0
    BITTree = [0] * (n + 1)

    # Store the actual values in BITree[] using update()
    for i in range(n):
        updatebit(BITTree, n, i, arr[i])

        # Uncomment below lines to see contents of BITree[]
    # for i in range(1,n+1):
    #     print BITTree[i],
    return BITTree


n,k=map(int,input().split())
c=[]
a=[0]*(n+1)
a[1]=1
BITTree = construct(a,len(a))
mod=998244353
for i in range(k):
    x,y=map(int,input().split())
    c.append([x,y])

for i in range(2,n+1):
    for j in range(len(c)):
        p,q=c[j][0],c[j][1]
        if i-q>0:
            l,r=i-p,i-q

            z=(getsum(BITTree,l)-getsum(BITTree,r-1))%mod

            a[i]+=z
            updatebit(BITTree, len(a), i,z)

        else:
            q=i-1
            if i-q>0 and i-p>0:
                l, r = i - p, i - q

                z = (getsum(BITTree, l) - getsum(BITTree, r - 1))%mod
                ##z= getsum(BITTree, q) - getsum(BITTree, p - 1)
                ##print(z)
                a[i]+=z
                updatebit(BITTree, len(a), i, z)
                ##print(BITTree)

##print(a)
print(a[n]%mod)








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

using namespace std;

int main()
{
  long int n,m;
  cin>>n>>m;
  long int a[n],cnt=1,s=0;
  for(int i=1;i<=n;i++)
  {
      cin>>a[i];
          s+=a[i];
          if(s<=m)
          {
              cnt++;

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


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <map>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n) + 1; i++)
#define all(vecto) vecto.begin(), vecto.end()
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
typedef long long ll;

void ans(bool qus)
{
    if (qus == true)
        std::cout << "Yes" << std::endl;
    else
        std::cout << "No" << std::endl;
}

void Ans(bool qust)
{
    if (qust == true)
        std::cout << "YES" << std::endl;
    else
        std::cout << "NO" << std::endl;
}

using namespace std;

//ACしてくれ頼む

int main(){
    int n,d;
    cin >> n >> d;
    int s = (n / (2 * d + 1));
    int a = (n % (2 * d + 1));
    if(a == 0){
        cout << s << endl;
    }
    else
        cout << s + 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> r(n), b(n);
  rep(i, n) cin >> r[i].first >> r[i].second;
  rep(i, n) cin >> b[i].first >> b[i].second;

  sort(r.begin(), r.end());
  sort(b.begin(), b.end());

  vector<int> y;
  int idx = 0, ans = 0;
  rep(i, n) {
    while (idx < n && r[idx].first <= b[i].first) {
      y.push_back(r[idx].second);
      idx++;
    }
    sort(y.begin(), y.end());

    auto itr = upper_bound(y.begin(), y.end(), b[i].second);
    if (itr == y.begin()) continue;
    ans++;
    y.erase(itr - 1);
  }

  cout << ans << endl;


  
  return 0;
}

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

using namespace std;

typedef long long ll;

const int max_a = 202020;

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

	int n;
	cin >> n;

	vector<int> a(n);
	rep(i, n) cin >> a[i];

	vector<ll> b(max_a, 0);
	rep(i, n) b[a[i]]++;

	ll all = 0;
	rep(i, max_a){
		if(b[i] > 0) all += b[i] * (b[i] - 1) / 2;
	}

	rep(i, n){
		ll x = b[a[i]];
		ll adj = - (x * (x - 1) / 2);
		if(x > 1) adj += (x - 1) * (x - 2) / 2;
		cout << all + adj << endl;
	}
}


Measured memory_bytes: 4992