akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int A[3][3];
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            cin >> A[i][j];
        }
    }
    int N;
    cin >> N;
    int B[N];
    bool bingo[3][3]; for(int i=0; i<3; i++) fill(bingo[i], bingo[i] + 3, false);
    for(int i=0; i<N; i++) cin >> B[i];
    for(int i=0; i<N; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<3; k++){
                if(A[j][k] == B[i]) bingo[j][k] = true;
            }
        }
    }
    bool ans = false;
    for(int i=0; i<3; i++) {
        ans = (bingo[i][0] & bingo[i][1] & bingo[i][2]);
        if(ans) break;
    }
    for(int i=0; i<3; i++) {
        ans = ans | (bingo[0][i] & bingo[1][i] & bingo[2][i]);
        if(ans) break;
    }
    ans = ans | (bingo[0][0] & bingo[1][1] & bingo[2][2]) | (bingo[2][0] & bingo[1][1] & bingo[0][2]);
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l,ans;
string s,t;
ll d[200010],dp[500][500];

int main(){
  cin >> n >> m;
  if(n % 3 == 0 || m % 3 == 0){
    puts("0");
  }else{
    ll ans = INF;
    rep(k,0,2){
      rep(i,1,n){
        ll a = i * m;
        ll b = (n - i) / 2 * m;
        ll c = (n - i + 1) / 2 * m;
        ll p = max(abs(b-c),max(abs(a-b),abs(a-c)));
        ans = min(ans,p);
        b = m / 2 * (n - i);
        c = (m + 1) / 2 * (n - i);
        p = max(abs(b - c),max(abs(a - b),abs(a - c)));
        ans = min(ans,p);
      }
      swap(n,m);
    }
    print(ans);
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main ()
{   long long  n;
   scanf("%lld",&n);
   long long sum=0;
   long long  a3=n/3,a5=n/5,a15=n/15;
   sum=-a3*(3*a3+3)/2-a5*(5*a5+5)/2+n*(n+1)/2+a15*(15*a15+15)/2;
   printf("%lld",sum);
}

Measured memory_bytes: 1736
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication15
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] inputline = Console.ReadLine().Split(' ');
            int[] input = new int[3];

            input[0] = int.Parse(inputline[0]);
            input[1] = int.Parse(inputline[1]);
            input[2] = int.Parse(inputline[2]);

            int ret = input[0] + input[1] + input[2] - input.Max() + (input.Max() * 10);

            Console.WriteLine(ret.ToString());
        }
    }
}


Measured memory_bytes: 13524
N,K=map(int,input().split())
A=sorted(map(int,input().split()))
F=sorted(map(int,input().split()),reverse=True)

l=-1
r=A[-1]*F[0]
while l+1<r:
  x=(l+r)//2
  cnt=0
  for i in range(N):
    cnt+=max(A[i]-x//F[i],0)
  if cnt<=K:
    r=x
  else:
    l=x
    
print(r)

Measured memory_bytes: 119500
#include<iostream>
using namespace std;
int main()
{
  int N,T;
  cin >> N >> T;
  int c[N],t[N];
  int index = -1;

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

  for (int i = 0; i < N; i++) {
    if(t[i]<=T){
      if(index < 0){
        index = i;
      }
      else {
        index = (c[index] < c[i])?index:i;
      }
    }
  }
  if(index < 0){
    cout << "TLE" << endl;
  }

  else {
    cout << c[index] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define vc(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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

int main() {
  string s;
  cin >> s;
  if (s=="ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;

  return 0;
}

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

int main() {
  int A,B;
  cin >> A >> B;
  int a,b,c,d;
  int t=0;
  for(int i=A;i<B+1;i++){
    a=i/10000;
    b=i%10000/1000;
    c=i%10000%1000%100/10;
    d=i%10000%1000%100%10;
    if(a==d&&b==c){
      t++;
    }
  }
  cout << t << endl;
}


Measured memory_bytes: 3504
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;

int main(){
    double x1,x2,y1,y2;
    cin >> x1 >> y1 >> x2 >> y2;

    
    double l = sqrt((x2 -x1)*(x2 -x1)+(y2 - y1)*(y2 - y1));
    
    printf("%lf\n",l);
    
    
}


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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

void solve() {
	int n; scanf("%d", &n);
	set<int> s;
	for (int i = 0; i < n; ++i) {
		int a; scanf("%d", &a);
		if (s.count(a)) s.erase(a);
		else s.insert(a);
	}
	printf("%d", s.size());
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;



int main(void)
{
	string str; int num;
	cin >> num;
	while (num--)
	{
		int max = 0, min = 0, tempmax[8] = {}, tempmin[8] = {};
		cin >> str;
		for (int i = 0; i < 8; i++) tempmin[i] = str[i] - '0';
		sort(tempmin, tempmin + 8);
		for (int i = 0; i < 8; i++) tempmax[i] = tempmin[7 - i];
		int num = 10000000;
		for (int i = 0; i < 8; i++)
		{
			max += tempmax[i] * num;
			min += tempmin[i] * num;
			num /= 10;
		}
		cout << max - min << endl;;
	}
	return 0;
}


Measured memory_bytes: 3016
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int nm[100][100] = {0}, m1[100] = {0},i,j,c=0,n,m;
    
    scanf("%d %d",&n,&m);
    
    for (i = 0; i < n ; i++) {
        for (j = 0; j < m; j++) {
            scanf("%d",&nm[i][j]);
        }
    }
    
    for (i = 0; i < m ; i++) {
        scanf("%d",&m1[i]);
    }
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            c += nm[i][j] * m1[j];
        }
        printf("%d\n",c);
        c = 0;
    }
    return 0;

}

Measured memory_bytes: 648
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  cin >> N;
  int a = N / 1000;
  int b = (N - 1000 * a) / 100;
  int c = (N - 1000 * a - 100 * b) / 10;
  int d = N - 1000 * a - 100 * b - 10 * c;
  if(a == b || b == c || c == d) {
    cout << "Bad" << endl;
  } else {
    cout << "Good" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    int N; cin >> N;
    vector<vector<int>> a(2,vector<int>(N));
    int L=0; int R=0;
    for(int i=0;i<2;i++){
        for(int j=0;j<N;j++){
            cin >> a[i][j];
            if(i==0 && j==0) L+=a[i][j];
            if(i==1) R+=a[i][j];
        }
    }

    int m = L+R;
    for(int i=1;i<N;i++){
        L+=a[0][i]; R-=a[1][i-1];
        if(m < L+R) m = L+R;
        //cout << L << R << endl;
    }
    cout << m << endl;
}




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

int main()
{
    int a,b,c,d,n,i,j,tc=0;
    int N;

    cin >> N;
    int data[N];
    for(i=0;i<N;i++) cin >> data[i];

    int start = 0;

    int ans = 0;
  for(i=1;i<N;i++)
    {
        if (data[i] > data[i-1])
            start = i;
        ans = max(ans, i-start);
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 640
/*
--> WHEN IT'S OBVIOUS THAT THE GOAL CANNOT BE REACHED,
	DON'T ADJUST THE GOALS,
	ADJUST THE ACTION STEPS.

--> THE WAY YOU CONQUER SELF-DOUBT IS BY DOING THINGS THAT MAKE YOU UNCOMFORTABLE.

--> IT IS DURING OUR DARKEST MOMENTS WE MUST FOCUS TO SEE LIGHT.
*/

#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <climits>
using namespace std;
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortAll(x) sort(all(x))
#define sz(x) (int)x.size()
#define clr(x) memset(x, 0, sizeof(x))
#define PI 3.1415926535897932384626
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); IO();
typedef long long ll;
typedef pair< int, int >	pii;
typedef pair< ll, ll >		pl;
typedef vector< int >		vi;
typedef vector< ll >		vl;
typedef vector< pii >		vpii;
typedef vector< pl >		vpl;
typedef vector< vi >		vvi;
typedef vector< vl >		vvl;

const int MOD = 1e9 + 7;

ll power(ll a, ll b)
{
	ll ans = 1;

	while (b > 0)
	{
		if (b & 1)
			ans *= a;
		a = a * a;
		b >>= 1;
	}
	return ans;
}

ll powm(ll a, ll b)
{
	a %= MOD;
	ll ans = 1;

	while (b > 0)
	{
		if (b & 1)
			ans = (ans * a) % MOD;
		a = (a * a) % MOD;
		b >>= 1;
	}
	return ans;
}

void IO()
{
	#ifndef ONLINE_JUDGE
		freopen("Input.txt", "r", stdin);
		freopen("Output.txt", "w", stdout);
	#endif
}

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

int main()
{
	// FAST;
	
	int a, b, c;
	cin >> a >> b >> c;

	cout << c << " " << a << " " << b << "\n";
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<functional>
#include<algorithm>
#include<stack>
#include<queue>
#include<iomanip>
#include<set>
#include<utility>
#include<string>
#include<vector>

using namespace std;

#define LL long long

string s,t;

int main() {
	cin>>s>>t;
	cout <<t+s<<endl;

	return 0;
}



Measured memory_bytes: 256
from random import random
import math
import re
import fractions

K, T = map(int, raw_input().split(" "))
A = map(int, raw_input().split(" "))
s = 0
m = 0
for a in A:
    s += a
    m = max(a, m)
print max(m * 2 - s - 1, 0)


Measured memory_bytes: 4988
package main

import (
	"fmt"
	"strconv"
)

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func main() {
	var S string
	fmt.Scan(&S)

	var ans int = 999

	for i := 0; i < len(S)-2; i++ {
		v, _ := strconv.Atoi(S[i : i+3])
		diff := abs(v - 753)
		if ans > diff {
			ans = diff
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String s=sc.next();
        String[] t = {"eraser","erase","dreamer","dream"};
        for(int i=0;i<4;i++)s=s.replace(t[i],"");
        System.out.println(s.equals("")?"YES":"NO");
        
    }
}


Measured memory_bytes: 28688
s = str(input())
S = [s[i] for i in range(len(s))]
fr = 0
count = 0
if S[0] == 'A':
    S.pop(0)
else:
    fr = 1
for i in range(1,(len(S)-1)):
    if S[i] == 'C' and count == 0:
        S.pop(i)
        count += 1
s = ''.join(S)
if s.islower() and count == 1 and fr == 0:
    print('AC')
else:
    print('WA')

Measured memory_bytes: 38384
#include<stdio.h>
#include<string.h>
#define LEN 100005

//プロセスを表わす構造体
typedef struct pp{
    char name[100];
    int t;
}P;

P Q[LEN]; //ポインタ型
int head,tail,n;

void enqueue(P x){
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue(){
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b){ return a < b ? a : b;}

int main(){
    int elaps = 0,c;
    int i,q;
    P u;
    scanf("%d %d",&n,&q);
    for(i=1;i<= n;i++){
        scanf("%s",Q[i].name);
        scanf("%d",&Q[i].t);
    }
    head = 1; tail = n + 1;

    //シミュレーション
    while(head != tail){
        u = dequeue();
        c = min(q,u.t);
        u.t -= c;
        elaps += c;
        if(u.t > 0)enqueue(u);
        else{
            printf("%s %d\n",u.name,elaps);
        }
    }
    return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

int main() {
    int A, B;
    cin >> A >> B;
    int ans = -1;
    rep(i, 2000) {
        if(i == 0) continue;
        int value8 = i * 0.08;
        int value10 = i * 0.10;
        if(value8 == A && value10 == B) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

const int mod = 1000000007;
int dp[5001];
int dp2[5001];
int dp3[5001][2];

int main() {
    int n, a, b, ans, i, j, k;
    
    scanf("%d %d %d", &n, &a, &b);
    
    if (a > b) swap(a, b);
    
    dp[1] = 1;
    
    for (i = 1; i < n; i++) {
        dp[i + 1] += dp[i];
        if (dp[i + 1] >= mod) dp[i + 1] -= mod;
        
        for (j = a + 1; i + j <= n; j++) {
            dp[i + j] += dp[i];
            if (dp[i + j] >= mod) dp[i + j] -= mod;
        }
    }
    
    dp2[0] = 1;
    
    for (i = 0; i < n; i++) {
        dp2[i + 1] += dp2[i];
        if (dp2[i + 1] >= mod) dp2[i + 1] -= mod;
        
        for (j = a + 1; i + j <= n; j++) {
            dp2[i + j] += dp2[i];
            if (dp2[i + j] >= mod) dp2[i + j] -= mod;
        }
    }
    
    for (i = 0; i < b; i++) dp3[i][1] = dp2[i];
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < 2; j++) {
            if (dp3[i][j] == 0) continue;
            
            if (j != 0) {
                for (k = 1; k < a && i + k <= n; k++) {
                    dp3[i + k][0] += dp3[i][j];
                    if (dp3[i + k][0] >= mod) dp3[i + k][0] -= mod;
                }
            }
            
            if (j != 1) {
                for (k = 1; k < b && i + k < n; k++) {
                    dp3[i + k][1] += (long long)dp3[i][j] * dp[k] % mod;
                    if (dp3[i + k][1] >= mod) dp3[i + k][1] -= mod;
                }
                
                if (n - i < b) {
                    dp3[n][1] += (long long)dp3[i][j] * dp2[n - i] % mod;
                    if (dp3[n][1] >= mod) dp3[n][1] -= mod;
                }
            }
        }
    }
    
    ans = 1;
    for (i = 0; i < n; i++) ans = ans * 2 % mod;
    
    for (i = 0; i < 2; i++) {
        ans -= dp3[n][i];
        if (ans < 0) ans += mod;
    }
    
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 1796
n,q = map(int,input().split())
S = input()
tb = [0 for i in range(n)]
for i in range(1,n):
    if S[i]=='C' and S[i-1]=='A':
        tb[i] = tb[i-1]+1
    else:
        tb[i] = tb[i-1]
for i in range(q):
    l,r = map(int,input().split())
    print(tb[r-1]-tb[l-1])



Measured memory_bytes: 51872
#include<iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n, 0);

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

    sort(a.begin(), a.end());

    int sum = 0;
    for (int i = 0; i < k; i++) {
        sum += a[i];
    }

    cout << sum;

    return 0;
}

Measured memory_bytes: 3572
<?php
$n = (int)trim(fgets(STDIN));
$even_cnt = 0;
for ($i=0; $i < $n; $i++) { 
	$a = (int)trim(fgets(STDIN));
	if ($a % 2 === 0) {
		++$even_cnt;
	}
}

$ans = 'first';
if ($even_cnt === $n) {
	$ans = 'second';
}
echo $ans;

Measured memory_bytes: 4728
while True:
    n = int(raw_input())
    if n == 0: break
    res = [0]*n
    p = 0
    i = 0
    for c in raw_input():
        if c == 'M':
            res[i] += 1
        elif c == 'L':
            res[i] += p+1
            p = 0
        else:
            p += res[i]+1
            res[i] = 0
        i += 1
        if i == n:
            i = 0
    else:
        print ' '.join(map(str, sorted(res))), p

Measured memory_bytes: 4228
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
const double PI = acos(-1);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

/*C++になってるか確認したほうがよくない？WOWWOW*/
/*DP使ったほうがよくない？？WOWWOW*/

int main(){
    int N; cin>>N;
    N%=10;
    string ans;
    if(N==3){
        ans="bon";
    }
    else if(N==0 || N==1 || N==6 || N==8){
        ans="pon";
    }
    else{
        ans="hon";
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include <stdio.h>
int main(){
    int a,b,c,m1=0;
    scanf("%d%d%d", &a, &b, &c);
    if((a==b&&b!=c)||(a==c&&b!=c)||b==c&&b!=a){
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
import heapq
N, M = map(int, input().split())
ab = [list(map(lambda x:int(x)-1, input().split())) for _ in range(M)]
ans = 0

def dijkstra(s, graph, n):
  dist = [float('inf')]*n
  dist[s] = 0
  num = [0]*n
  num[s] = 1
  q = [[0, s]]
  heapq.heapify(q)
  while q:
    c, u = heapq.heappop(q)
    if dist[u] < c:
      continue
    for v, weight in graph[u]:
      if dist[v] > dist[u] + weight:
        dist[v] = dist[u] + weight
        num[v] = num[u]
        heapq.heappush(q, [dist[v], v])
      elif dist[v] == dist[u] + weight:
        num[v] += num[u]
  return dist, num

for i in range(M):
  graph = [[] for _ in range(N)]
  for j in range(M):
    if i != j:
      a, b = ab[j]
      graph[a] += [[b, 1]]
      graph[b] += [[a, 1]]

  for j in range(N):
    d, _ = dijkstra(j, graph, N)
    if max(d) == float('inf'):
      ans += 1
      break
print(ans)


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

int main() {
  int n;
  cin>>n;
  int ans=0;
  for (int i=0; i<n; i++) {
    int a;
    cin>>a;
    ans+=a-1;
  }
  
  cout<<ans<<endl;     
  return 0;
}




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

signed main(){
	int N, K;
	cin >> N >> K;
	vector<bool> snk(N, true);
	for(int i = 0; i < K; i++){
		int d;
		cin >> d;
		vector<int> A(d);
		for(int j = 0; j < d; j++)
			cin >> A.at(j);

		for(int j = 0; j < d; j++)
			snk.at(A.at(j)-1) = false;
	}
	
	int sum = 0;
	for(int i = 0; i < N; i++)
		if(snk.at(i))
			sum++;

	cout << sum << endl;

	return 0;	
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <unistd.h>
#include <cctype>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 1 << 30
#define LLINF LLONG_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
using ll = long long;
using Pll = pair<ll,ll>;
using Pii = pair<int,int>;
using Pdd = pair<double,double>;
using dcomplex = complex<double>;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll fact(ll a){ll b=1;FOR(i,1,a)b*=i;return b;}
ll power(ll x,ll n){ll a=1;REP(i,n)a*=x;return a;}
double inf() {return std::numeric_limits<double>::infinity();}

int main(int argc, char const *argv[]) {
  ll N, K; cin >> N >> K;
  ll ans = 0;
  if (K == 0) ans = N*N;
  else {
    for(ll i = K+1; i <= N; i++) {
      ans += ((N+1)/i)*(i-K);
      ll c = ((N+1)%i)-K;
      ans += c>0?c:0;
    }
  }
  cout << ans << endl;
}


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

using P = pair<int, int>;
const int inf = 1000000007;
const int M = inf;

// dinic
struct max_flow {
    struct edge { int to, cap, rev; };
    int V;
    vector<vector<edge>> G;
    vector<int> itr, level;

    max_flow(int V) : V(V) { G.assign(V,vector<edge>()); }

    void add_edge(int from, int to, int cap) {
        G[from].push_back((edge) {to, cap, (int) G[to].size()});
        G[to].push_back((edge) {from, 0, (int) G[from].size()-1});
        // G[to].push_back((edge) {from, cap, (int) G[from].size()-1});
    }

    void bfs(int s) {
        level.assign(V,-1);
        queue<int> q;
        level[s] = 0; q.push(s);
        while (!q.empty()) {
            int v = q.front(); q.pop();
            for(auto &e: G[v]){
                if (e.cap > 0 and level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    q.push(e.to);
                }
            }
        }
    }

    int dfs(int v, int t, int f) {
        if (v == t) return f;
        for (int& i = itr[v]; i < (int) G[v].size(); ++i) {
            edge& e = G[v][i];
            if (e.cap > 0 and level[v] < level[e.to]) {
                int d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    int run(int s, int t) {
        int ret = 0, f;
        while (bfs(s), level[t] >= 0) {
            itr.assign(V,0);
            while ((f = dfs(s, t, inf)) > 0) ret += f;
        }
        return ret;
    }
};

vector<int> dijkstra(int s, vector<vector<P>> edge) {
    int n = edge.size();
    vector<int> dist(n, M);
    priority_queue<P, vector<P>, greater<P>> q;
    dist[s] = 0;
    q.push(P(0, s));
    while (!q.empty()) {
        P p = q.top();
        q.pop();
        for (auto& e : edge[p.second]) {
            if (dist[e.second] > p.first + e.first) {
                dist[e.second] = p.first + e.first;
                q.push(P(p.first + e.first, e.second));
            }
        }
    }
    return dist;
}


int main() {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    --s;
    --t;
    vector<pair<P, P>> edges(m);
    vector<vector<P>> edge(n);
    for (int i = 0; i < m; ++i) {
        int u, v, d, c;
        cin >> u >> v >> d >> c;
        --u;
        --v;
        edges[i] = make_pair(P(u, v), P(d, c));
        edge[u].push_back(P(d, v));
    }
    vector<int> dist = dijkstra(s, edge);
    max_flow mf(n);
    for (auto& i : edges) {
        if (dist[i.first.second] - dist[i.first.first] == i.second.first) {
            mf.add_edge(i.first.first, i.first.second, i.second.second);
        }
    }
    cout << mf.run(s, t) << "\n";

    return 0;
}



Measured memory_bytes: 3236
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args){
 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 try{
     while(true){
  String str[]=br.readLine().split(" ");
  if(str[0].equals("0")&&str[1].equals("0"))break;
  
  int a[];
  a=new int[20001];
  
  int k=1,num=0;
  
  if(!str[0].equals("0")){
      
      String str1[]=br.readLine().split(" ");
      
      for(int i=0;i<str1.length;i++){
   num=0;
   for(int j=0;j<str1[i].length();j++)num=num*10+str1[i].charAt(j)-'0';
   a[k]=num;k++;
      }
      
  }
  
  if(!str[1].equals("0")){
      
      String str2[]=br.readLine().split(" ");
      
      for(int i=0;i<str2.length;i++){
   num=0;
   for(int j=0;j<str2[i].length();j++)num=num*10+str2[i].charAt(j)-'0';
   a[k]=num;k++;
      }

  }
  Arrays.sort(a,0,k);
  int max=0;
  for(int i=1;i<k;i++)
      if(a[i]-a[i-1]>max)max=a[i]-a[i-1];
  System.out.println(max);   
     }
 }
 catch(Exception e){return ;}
    }
}


Measured memory_bytes: 35208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(void)
{
    ll n;
    cin >> n;
    if(n % 2 == 1){
        cout << 0 << endl;
    }
    else{
        ll ans = 0;
        for (ll i = 5; i <= n; i *= 5)
        {
            ans += n / (i*2);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(a) int((a).size())
#define FI(i,a,b) for(int i=(a);i<=(b);++i)
#define FD(i,b,a) for(int i=(b);i>=(a);--i)
using namespace std;
using LL = long long;
using PII = pair<int, int>;

int main() {
    int n, m, s, t;
    scanf("%d%d%d%d", &n, &m, &s, &t);
    struct Edge { int u, v; LL a, b; };
    vector<vector<int>> G(n + 1);
    vector<Edge> E;
    FI(i, 1, m) {
        int u, v;
        LL a, b;
        scanf("%d%d%lld%lld", &u, &v, &a, &b);
        G[u].push_back(E.size());
        E.push_back(Edge{u, v, a, b});
        G[v].push_back(E.size());
        E.push_back(Edge{v, u, a, b});
    }
    auto dijkstra = [&](int src, bool flag) {
        vector<LL> Dis(n + 1, 1LL << 60);
        Dis[src] = 0;
        using PLI = pair<LL, int>;
        priority_queue<PLI, vector<PLI>, greater<PLI>> Q;
        Q.emplace(0, src);
        while (!Q.empty()) {
            int u = Q.top().second;
            Q.pop();
            for (auto i : G[u]) {
                auto e = E[i];
                auto w = flag ? e.a : e.b;
                int v = e.v;
                if (Dis[u] + w < Dis[v]) {
                    Dis[v] = Dis[u] + w;
                    Q.emplace(Dis[v], v);
                }
            }
        }
        return Dis;
    };
    auto From = dijkstra(s, true);
    auto To = dijkstra(t, false);
    using PLI = pair<LL, int>;
    set<PLI> S;
    FI(i, 1, n) {
        S.emplace(From[i] + To[i], i);
    }
    FI(i, 1, n) {
        printf("%lld\n", LL(1e15) - S.begin()->first);
        S.erase(PLI{From[i] + To[i], i});
    }
}



Measured memory_bytes: 20908
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <map>

using namespace std;

int main(){
    int coin[3] = {500, 100, 50};
    int a, b, c, x, cnt=0, n;
    cin >> a >> b >> c >> x;

    for(int i=0; i<=a; i++){
        n = coin[0] * i;
        // if(n > x) break;
        for(int j=0; j<=b; j++){
            n += coin[1] * j;
            // if(n > x) break;
            for(int k=0; k<=c; k++){
                n += coin[2] * k;
                if(n == x) cnt++;
                n = coin[0] * i + coin[1] * j;
            }
            n = coin[0] * i;
        }
    }
    cout << cnt << endl;
}

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

int main() {
//    freopen("in.txt", "r", stdin);

    int slen = 0, tlen = 0, pos = 0;
    char src[102] = {0}, tar[102] = {0}, tmp;

    while ((tmp = getchar()) != '\n') {
        src[pos++] = tmp;
    }
    slen = pos;

    pos = 0;
    while ((tmp = getchar()) != '\n' && tmp != EOF) {
        tar[pos++] = tmp;
    }
    tlen = pos;

    for (int i = 0; i < slen; ++i) {
        for (int j = 0; j < tlen; ++j) {
            pos = (i + j >= slen) ? (i + j - slen) : (i + j);
            if (tar[j] != src[pos]) {
                break;
            }
            if (j == tlen - 1) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3112
package main

import (
	"fmt"
	"sort"
)

func main() {
	nums := make([]int, 3)
	for i:=0; i<3; i++{
		fmt.Scan(&nums[i])
	}

	sort.Ints(nums)
	fmt.Printf("%d ", nums[0])
	fmt.Printf("%d ", nums[1])
	fmt.Printf("%d\n", nums[2])

}


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

struct edge{
    int from, to, cost;
};

edge e[100001];

struct UnionFind{
    vector<int> par, rank;

    UnionFind( int N ){
        par.resize( N ), rank.resize( N );
        REP( i, N ) par[i] = i, rank[i] = 0;
    }

    int root( int x ){
        if( x == par[x] ){
            return x;
        }else{
            return par[x] = root( par[x] );
        }
    }

    void unite( int x, int y ){
        x = root( x ), y = root( y );

        if( x == y ) return;
        if( rank[x] < rank[y] ) swap( x, y );
        if( rank[x] = rank[y] ) rank[x]++;
        par[y] = x;
    }

    bool same( int x, int y ){
        return root( x ) == root( y );
    }
};

bool comp( const edge& x, const edge& y ){
    return x.cost < y.cost;
}

signed main(){
    int V, E; cin >> V >> E;
    REP( i, E ){
        int from, to, cost; cin >> from >> to >> cost;
        e[i] = edge{ from, to, cost };
    }

    sort( e, e + E, comp );

    UnionFind uf( V );
    int ans = 0;
    REP( i, E ){
        if( !uf.same( e[i].from, e[i].to ) ){
            uf.unite( e[i].from, e[i].to );
            ans += e[i].cost;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 5572
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    string s;
    cin>>s;
    int n = s.size();
    vector<vector<int>> v(n+1);
    vector<int> cnt(n+1);
    rep(i,n){
        if(s[i]=='<'){
            v[i].emplace_back(i+1);
            ++cnt[i+1];
        }
        else {
            v[i+1].emplace_back(i);
            ++cnt[i];
        }
    }
    queue<int> q;
    vector<int> a(n+1);
    rep(i,n+1){
        if(!cnt[i])q.push(i);
    }
    while(q.size()){
        int x = q.front();q.pop();
        for(auto e:v[x]){
            a[e]=max(a[x]+1,a[e]);
            if(--cnt[e]==0)q.emplace(e);
        }
    }
    ll ans = 0;
    rep(i,n+1)ans += a[i];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 32004
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
 
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for(int i = 0; i < n; i++)
#define LL long long
const int mod = 1e9 + 7;
const int inf = 1e9;


string s, t, p;
int x, y;
int main() {
    //freopen("in", "r", stdin);
    cin >> s >> t; 
    cin >> x >> y;
    cin >> p;
    if(p == s) printf("%d %d\n", x - 1, y);
    else printf("%d %d\n", x, y - 1);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <utility>
#include <numeric>
#include <iomanip>

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

using namespace std;

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

    if (a + b + c >= 22)
    {
        cout << "bust" << endl;
    }
    else
    {
        cout << "win" << endl;
    }
    
    
}

/*

long int gcd(long int a, long int b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}

long int lcm(long int a, long int b)
{
    return a * b / gcd(a, b);
}

*/

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <fstream>
#include <stdint.h>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
using namespace std;

constexpr int INF       = 1000000000;/* 1e+9a */
constexpr int MODULO    = 1000000007;

constexpr int evx[4] = { 1, 0, -1, 0 };
constexpr int evy[4] = { 0, 1, 0, -1 };

//----------------------------------
//----------------------------------

signed main()
{
    ios::sync_with_stdio(false);
        int k;
        string s;
        cin >> s >> k;
        for(int i = 0; i < s.size(); ++i)
        {
                int d = 26 - (s[i]-'a');
                if(k >= d && d < 26)
                {
                        s[i] = 'a';
                        k -= d;
                }
        }
        s[s.size()-1] = ((s[s.size()-1]- 'a' + k) % 26) + 'a';
        cout << s << '\n';

}


Measured memory_bytes: 720
import java.util.*;

public class Main {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		int h = s / 3600;
		s = s % 3600;
		int m = s / 60;
		s = s % 60;
		System.out.println(h + ":" + m + ":" + s);
	}
}

Measured memory_bytes: 17320
ch :: Char -> String -> String
ch y [] = []
ch y (x:xs) = if x == y then x:(ch y xs) else '*':(ch y xs)

main :: IO ()
main = do
  n <- readLn :: IO Int
  s <- getLine
  k <- readLn :: IO Int
  putStrLn $ ch (s!!(k-1)) s


Measured memory_bytes: 508
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <functional>
using namespace std;

int main() {
  //input
  int a;
  cin >> a;
  string s;
  cin >> s;

  //process
  if (s.length() <= a) cout << s << endl;
  else {
    cout << s.substr(0, a) << "..." << endl;
  }
  
}

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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {
    int c[3][3];

    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> c[i][j];
        }
    }

    bool ans = false;

    for (int i = 0; i <= 100; ++i) {
        for (int j = 0; j <= 100; ++j) {
            if (i + j == c[0][0]) {
                int a[3];
                int b[3];
                a[0] = i;
                b[0] = j;

                a[1] = i + c[1][0] - c[0][0];
                a[2] = i + c[2][0] - c[0][0];

                b[1] = j + c[0][1] - c[0][0];
                b[2] = j + c[0][2] - c[0][0];

                bool t = true;

                for (int k = 0; k < 3; ++k) {
                    for (int l = 0; l < 3; ++l) {
                        if (c[k][l] != a[k] + b[l]) {
                            t = false;
                        }
                    }
                }

                if (t) {
                    ans = true;
                }
            }
        }
    }

    if (ans) {
        puts("Yes");
    } else {
        puts("No");
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vii = vector<vi>;
using vl = vector<ll>; using vll = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
//****************************************
// Graph template
//****************************************

// status of edge
template <typename X>
struct Edge{
  int from;
  int to;
  X cost;

  Edge() = default;

  Edge(int from, int to, X cost) : from(from), to(to), cost(cost) {}
};

// status of node
template <typename X>
struct Node{ 
  int idx;
  vector<Edge<X>> edge;
  
  Node() = default;

  explicit Node(int idx) : idx(idx) {}
};

template <typename X>
class Graph{
private:
  int n; // number of node
  int m; // number of edge
  vector<Node<X>> node; 

  void Init_Node() {
    rep(i,n) node.emplace_back(i);
  }
public:
  explicit Graph(int n) : n(n) {
    Init_Node();
  }

  // edges have no-weight 
  Graph(int n, int m, vector<int> from, vector<int> to) : n(n), m(m) {
    Init_Node();
    rep(i,m) {
      add_edge(from[i], to[i]);
      add_edge(to[i], from[i]);      
    }
  }  

  // edges have weight
  Graph(int n, int m, vector<int> from, vector<int> to, vector<X> cost) : n(n), m(m) {
    Init_Node();
    rep(i,m) {
      add_edge(from[i], to[i], cost[i]);
      add_edge(to[i], from[i], cost[i]);      
    }
  }

  void add_edge(int from, int to, X cost = 1) {
    node[from].edge.emplace_back(from, to, cost);
  }

  //------------------------------------------
  // 橋を見つけるアルゴリズム
  // 橋：取り除くとグラフが非連結になる辺
  //------------------------------------------
  vector<pi> Bridge() {
    vector<int> pre(n, -1), low(n);
    int cnt = 0;
    vector<pi> res;
    auto dfs = [&](auto self, int v, int p) ->int{
		 pre[v] = cnt++;
		 low[v] = pre[v];
		 for(auto next: node[v].edge) {
		   int w = next.to;
		   if(w == p) continue;
		   if(pre[w] == -1) {
		     low[v] = min(low[v], self(self, w, v));
		     if(pre[w] == low[w]) {
		       if(v < w) res.push_back({v, w});
		       else res.push_back({w, v});
		     }
		   }
		   else {
		     low[v] = min(low[v], pre[w]);
		   }
		 }
		 return low[v];
	       };

    dfs(dfs, 0, -1);
    return res;
    
  }
  
};

int main()
{
  int n,m; cin >> n >> m;
  vi a(m),b(m);
  rep(i,m) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
  }

  Graph<int> gp(n,m,a,b);
  vector<pi> res = gp.Bridge();
  cout << (int)res.size() << "\n";
  return 0;
}


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

using namespace std;

int board[55][55];
char ans[55][55];

int main(){
    int W,H;
    char r;
    scanf("%d%d",&H,&W);

    for (int i=0;i<H;i++){
        for (int j=0;j<W;j++){

            scanf(" %c",&r);

            if (r == '#'){

                board[i][j]=-100;
                for (int k=0;k<3;k++){
                    for (int l=0;l<3;l++){
                        if(i+k-1 < H && j-l+1 < W){
                            board[i+k-1][j-l+1]++;
                        }
                    }
                }
            }
        }
    }

    for (int i=0;i<H;i++){
        for (int j=0;j<W;j++){

            if (board[i][j]<0){

                ans[i][j]='#';
            }else{
                //printf("%d",board[i][j]);
                ans [i][j] = '0'+board[i][j];
            }
            printf("%c",ans[i][j]);
        }printf("\n");
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
    
ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>m>>d;
    rrep(i,1,m+1){
        rrep(j,1,d+1){
            s=to_string(j);
            if(Size(s)==1)continue;
            ll d1,d10;
            d1=s[0]-'0';
            d10=s[1]-'0';
            if(d1>=2&&d10>=2&&d1*d10==i)ans++;
        }
    }
    Cout(ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
lli n, q, b, c;

int main(void){
    cin >> n;
    vector<lli> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    long long sum = 0;
    vector<lli> d(100001);
    for(int i = 0; i < n; i++){
        sum+=a[i];
        d[a[i]]++;
    }
    cin >> q;
    for(int i = 0; i < q; i++){
        cin >> b >> c;
        lli sub = c-b;
        sum += sub*d[b];
        d[c] += d[b];
        d[b] = 0;
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 4796
n = int(input())
# num2alpha = lambda c: chr(c+64)
# for i in range(1,21):
#     if n-26**i>0:
#         n -= 26**i
#     else:
#         s = i
#         break
# b = ""
# for j in range(s):
#     t = s-j
#     b +=num2alpha(n%(26**(t-1)))
# print(b)
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
print(num2alpha(n).lower())

Measured memory_bytes: 9168
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n, k) for (int i = n; i < k; i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v)                      \
    for (int i = 0; i < v.size(); i++) \
        P(v[i]);
#define printt(a, b) cout << a << " " << b << endl;
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int MOD = 1e9 + 7;

void solve()
{
    string s;
    cin >> s;
    rep(i, s.length())
    {
        REP(j, i, s.length())
        {
            string subs = s.substr(0, i) + s.substr(j, s.length() - j);
            if (subs == "keyence")
            {
                P("YES");
                return;
            }
        }
    }
    P("NO");
}

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


Measured memory_bytes: 256
a,b,m=map(int,input().split())
af=list(map(int,input().split()))
bf=list(map(int,input().split()))
almin=sorted(af)
blmin=sorted(bf)
nmin=almin[0]+blmin[0]
bmin=blmin[0]
for i in range(m):
  x,y,c=map(int,input().split())
  k=af[x-1]+bf[y-1]-c
  if k<nmin:
    nmin=k
print(nmin)

Measured memory_bytes: 18736
#!/usr/bin/env python3
import sys


def solve(K: int, A: int, B: int):
    i = 0
    while True:
        if A <= K * i and K * i <=B:
            print('OK')
            return
        if K*i>1000:
            break
        i+=1
    print('NG')
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(K, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9196
#include<stdio.h>
int Merge(int *,int,int,int);
int MergeSort(int *,int,int);
int sum = 0;
int main()
{
  int i,a;
  int S[500000];

  scanf("%d",&a);
  for(i = 0;i < a;i++){
    scanf("%d",&S[i]);
  }
  
  MergeSort(S,0,a);

  for(i = 0;i < a-1;i++){
    printf("%d ",S[i]);
  }
  printf("%d\n",S[i]);
  printf("%d\n",sum);
  return 0;
}

int MergeSort(int *A,int left,int right)
{  
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    MergeSort(A,left,mid);
    MergeSort(A,mid,right);
    Merge(A,left,mid,right);
  }
  else return 0;
}

int Merge(int *A,int left,int mid,int right)
{
  int k,n1,n2,L[500000],R[500000],i,j;
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  L[n1]=999999999;
  R[n2]=999999999;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
      sum++;
    }
    else{
      A[k]=R[j];
      j++;
      sum++;
    }
  }
}



Measured memory_bytes: 5672
#include <bits/stdc++.h>
using namespace std;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
int main() {
  int N,M;
  cin >> N >> M;
  int used[N][M];
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      used[i][j]=-1;
    }
  }
  string s[N];
  for(int i=0;i<N;i++){
    cin >> s[i];
  }
  int ans=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      if(s[i][j]=='.'){
        queue<int> x;
        queue<int> y;
        x.push(i);
        y.push(j);
        for(int ii=0;ii<N;ii++){
          for(int jj=0;jj<M;jj++){
            used[ii][jj]=-1;
          }
        }
        used[i][j]=0;
        while(!x.empty()){
          int xxx=x.front();
          int yyy=y.front();
          x.pop();
          y.pop();
          for(int k=0;k<4;k++){
            int nx=xxx+dx[k]; 
            int ny=yyy+dy[k];
            if (nx>=0 and ny>=0 and nx<N and ny<M){
              if (s[nx][ny]=='.' and used[nx][ny]==-1){
                used[nx][ny]=used[xxx][yyy]+1;
                if (used[nx][ny]>ans){
                  ans=used[nx][ny];
                }
                x.push(nx);
                y.push(ny);
              }
            }
          }
        }
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256