akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
using namespace std;
typedef long long ll;
//#define FOR(i,a,b) for(int i=(a);i<(b);++i)
//#define REP(i,n)  for(int i =0;i<n;++i)
#define mod (ll)(1e9+7)
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int  N= 0;
    cin >> N ;
    long ans = 0;
    int i=0;
    int tmp = 0;
    for(i=0;i<N;i++){
        cin >>tmp;
        while(tmp%2==0){
            ans++;
            tmp/=2;
        }
    }
    cout << ans << endl;
    return 0;
}



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

using namespace std;

int main()
{
    long long int n,i,m,cnt=0;
    scanf("%lld",&n);
    long long int a[n-1],b[n];
    for(i=0;i<n;i++) b[i]=0;
    for(i=0;i<n-1;i++){
        scanf("%lld",&a[i]);
        b[a[i]-1]+=1;
    }
    for(i=0;i<n;i++)
        printf("%lld\n",b[i]);
}


Measured memory_bytes: 6884
if __name__ == "__main__":
    S = input()
    text = "AKIHABARA"
    if S[0] == 'K':
        S = 'A' + S[:]
    while (True):
        update = False
        for i in range(len(S) - 1):
            if S[i] == 'H' and S[i + 1] == 'B':
                S = S[:i+1] + 'A' + S[i+1:]
                update = True
                break
            if S[i] == 'B' and S[i + 1] == 'R':
                S = S[:i + 1] + 'A' + S[i+1:]
                update = True
                break
        if not update:
            break
    if S[-1] == 'R':
        S = S[:] + 'A'
    if S == text:
        print ("YES")
    else:
        print ("NO")


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

using namespace std;

int main(){
	int W,H,N;
	cin >> W >> H >> N;

	int right, left, top, down;
	left=0;
	down=0;
	right=W;
	top=H;

	while(N--){
		int x,y,a;
		cin >> x >> y >> a;
		if(a==1){
			left = max(left,x);
		}
		else if(a==2){
			right = min(right,x);
		}
		else if(a==3){
			down = max(down,y);
		}
		else if(a==4){
			top = min(top,y);
		}
	}
	//There can be a case where both subtractions are negative and the multiplication ends up in a positive number
	if(down>=top || left>=right)
		cout << 0 << endl;
	else{
		int area = (top - down) * (right-left);
		cout << max(area,0) << endl;
	}
return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int a,b,cnt=0;
	string s;
	cin>>a>>b>>s;
	int cnt1=0,aha[a];
	int l[b],r[b];
	for(int i=0;i<b;i++){
		cin>>l[i]>>r[i];
	}
	aha[0]=0;
	for(int i=1;i<a;i++){
		if(s[i]=='C' and s[i-1]=='A'){
			cnt++;
		}
		aha[i]=cnt;
	}
	for(int i=0;i<b;i++){
		cout<<aha[r[i]-1]-aha[l[i]-1]<<endl;
	}
}
//FELAROSSO and aceka.b 2019

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main(){
  long N, P;
  cin >> N >> P;
  unordered_map<long, int>e;
  if(N != 1){
    if(P == 1){
      e[1] = 1;
    }else{
      long i = 2;
      while(P % i == 0){
        if(e.find(i) != e.end()){
          e[i]++;
        }else{
          e[i]=1;
        }
        P = P / i;
      }
      i++;
      while(P != 1 && pow(i, N) <= P){
        while(P % i == 0){
          if(e.find(i) != e.end()){
            e[i]++;
          }else{
            e[i]=1;
          }
          P = P / i;
        }
        i += 2;
      }
    }

    long ans = 1;
    for(auto pair:e){
      if(pair.second >= N){
        ans = ans * pow(pair.first, pair.second / N);
      }
    }
    cout << ans << endl;
  }else{
    cout << P << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a;
    int b;
    int c;
    cin >> a >> b >> c;
    for (int i = 1; i < 10001; i++){
        if ((a*i)%b == c){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

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

int main(void){
        long long int n,i,min=1000001,max=-1000001,sum=0;
        int *m;

        scanf("%lld",&n);
        m = malloc(sizeof(int) * n);

        for(i=0; i<n; i++){
                scanf("%d",&m[i]);
                if(m[i] < min)
                        min = m[i];
                if(m[i] > max)
                        max = m[i];
                sum += m[i];
        }

        printf("%lld %lld %lld\n",min, max, sum);
        free(m);

        return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
//Union木
struct UnionFind{
    vector<int> nxt;
    vector<int> num;
    void init(int x){
        nxt.clear();
        nxt.resize(x);
        num.assign(x, 1);
        for (int i = 0; i < x;i++){
            nxt[i] = i;
        }
    }
    int find(int x){
        if(nxt[x]==x)
            return x;
        return nxt[x] =find(nxt[x]);
    }
    inline void unite(int x,int y){
        if(find(x)==find(y))
            return;
        num[find(x)] += num[find(y)];
        nxt[find(y)] = find(x);
    }
    int numm(int x){
        return num[find(x)];
    }
};

vector<ll> vv[101010];
ll N, M, K;

ll i, j, k;
int main(){
    scanf("%lld%lld%lld", &N, &M, &K);
    UnionFind uf;
    uf.init(N + 1);
    fornum(i,0,M){
        ll a, b;
        scanf("%lld%lld", &a, &b);
        uf.unite(a, b);
        vv[a].push_back(b);
        vv[b].push_back(a);
    }
    fornum(i,0,K){
        ll a,b;
        scanf("%lld%lld",&a,&b);
        if(uf.find(a)!=uf.find(b))
            continue;
        vv[a].push_back(b);
        vv[b].push_back(a);
    }
    fornum(i,1,N+1){
        //cout << uf.numm(i) << endl;
        printf("%lld ", uf.numm(i) - vv[i].size() - 1ll);
    }
    return 0;
}

Measured memory_bytes: 10496
n,x,y = map(int, input().split())
x -= 1
y -= 1

ans = [0] * (n-1)

for j in range(n):
  for i in range(j):
    ans[min(j-i, abs(x-i)+1+abs(j-y)) - 1] += 1

print("\n".join([str(d) for d in ans]))

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

int main() {
    int n;
    cin >> n;
    vector<int> l(n);
    for (auto &i : l) cin >> i;
    // input

    sort(l.begin(), l.end());
    int ans {0};
    for (int i = 2; i < n; ++i) {
        for (int j = 1; j < i; ++j) {
            auto it = lower_bound(l.begin(), l.end(), l[i] - l[j] + 1);
            auto pos = distance(l.begin(), it);
            if (pos < j) {
                ans += j - pos;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    cin >> a >> b;
    if(a>=b+1) cout << 2*a -1 << endl;
    else if(a+1<= b) cout << 2*b -1 << endl;
    else if(a==b) cout << a + b << endl;
}

Measured memory_bytes: 256
using System;

namespace _6_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var bil = new int[4, 3, 10];
            for (var i = 0; i < n; i++)
            {
                var bfrv = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                var b = bfrv[0];
                var f = bfrv[1];
                var r = bfrv[2];
                var v = bfrv[3];
                bil[b - 1, f - 1, r - 1] += v;
            }
            for (var i = 0; i < 4; i++)
            {
                for (var j = 0; j < 3; j++)
                {
                    for (var k = 0; k < 10; k++)
                    {
                        if (k == 0) Console.Write(" " + bil[i, j, k]);
                        else Console.Write(" " + bil[i, j, k]);
                    }
                    Console.WriteLine();
                }
                if(i<3)
                {
                    for (var l = 0; l < 20; l++)
                    {
                        Console.Write("#");
                    }
                    Console.WriteLine();
                }               
            }
        }
    }
}



Measured memory_bytes: 15964
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int  k, n, ans;
  cin >> k >> n;
  vector<int> a(n), migi(n), hidari(n); 
  
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  
  for(int i = 0; i < n; i++){
    if(i == 0){
      migi[i] = a[n - 1] - a[0];
      hidari[i] = k - (a[1] - a[i]);
    }else if(i == n - 1){
      migi[i] = k - (a[i] - a[i - 1]);
      hidari[i] = a[n - 1] - a[0];
    }else{
      migi[i] = k - (a[i] - a[i - 1]);
      hidari[i] = k - (a[i + 1] - a[i]);
    }
  }
  sort(migi.begin(), migi.end());
  sort(hidari.begin(), hidari.end());
  ans = min(migi[0], hidari[0]);
  cout << ans <<endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    string s,t;
    string _s,_t;
    cin >> s >> t;
    map<int,int> mp1,mp2;
    string str = "abcdefghijklmnopqrstuvwxyz";

    int tmp;
    rep(i,s.length()){
        tmp = s[i]- 'a';
        mp1[tmp]++;
    }
    rep(i,26){
        rep(j,mp1[i]){
            _s += str[i];
        }
    }

    rep(i,t.length()){
        tmp = t[i]-'a';
        mp2[tmp]++;
    }
    rep(i,26){
        rep(j,mp2[25-i]){
            _t += str[25-i];
        }
    }

    if(_s < _t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb push_back
#define MOD 1000000007
#define pii pair<int,int>
#define LL long long int
using namespace std;















void solve() {
    int n, m;
    cin >> n >> m;
    int a[n];
    unordered_map<int, vector<int> > adj;

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

        cin >> a[i];
    }

    while (m--)
    {
        int x, y;
        cin >> x >> y;
        x -= 1;
        y -= 1;
        adj[x].pb(y);
        adj[y].pb(x);

    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        vector<int> v = adj[i];
        if (v.size() == 0)
        {
            ans++;
            continue;
        }

        int val = a[i];
        bool flag = true;
        for (int j = 0; j < v.size(); j++)
        {
            if (a[v[j]] >= val)
            {
                flag = false;
                break;
            }
        }
        if (flag)
            ans++;


    }



    cout << ans << "\n";







}




int main()
{


    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}




Measured memory_bytes: 11956
/*
	BIT ???????????¢?´¢?????¨??????
	http://hos.ac/slides/20140319_bit.pdf
	????????§???
*/
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

template<class T> class bit{
public:
	vector<T> dat;
	int N, M;
	
	bit(){}
	bit(int _N): N(_N){
		dat.assign(_N,0);
		M = 0;
		int p = 0;
		while(_N >= (1<<p)){
			M = (1<<p);
			++p;
		} // end while
	}
	
	// sum [0,i)
	T sum(int i){
		T ret = 0;
		for (--i; i >= 0; i = (i & (i + 1)) - 1){
			ret += dat[i];
		} // end for
		return ret;
	}

	// sum [i,j)
	T sum(int i, int j){
		return sum(j) - sum(i);
	}

	// add x to i
	void add(int i, T x){
		for (; i < N; i |= i + 1) dat[i] += x;
	}

	// w ??????????°????????????????????????????0-indexed????????????
	int lowerBound(int w){
		if (w < 0) return -1;
		int x = 0;
		for (int k = M; k > 0; k /= 2){
			if (x + k < N && dat[x + k - 1] <= w){
				w -= dat[x + k - 1];
				x += k;
			} // end if
		} // end for
		return x;
	}
};

bit<int> bs;
map<int,int> id;
int q, lim, l, r, vs[400010];
bool done[400010];

void normalize(void){
	if (bs.sum(r) > lim){
		while(done[l]) ++l;
		done[l] = 1;
		bs.add(l++, -1);
	} // end if
}

void solve(void){
	memset(vs, 0, sizeof(vs));
	memset(done, false, sizeof(done));

	id.clear();
	l = r = 0;

	bs = bit<int>(q);
	while(q--){
		int v, x, p;
		cin >> v >> x;
		switch(v){
			case 0:
				id[x] = r;
				vs[r] = x;
				bs.add(r++, 1);
				break;
			case 1:
				p = bs.lowerBound(x-1);
				bs.add(p, -1);
				done[p] = true;
				break;
			case 2:
				p = bs.lowerBound(x-1);
				cout << vs[p] << endl;
				break;
			case 3:
				p = id[x];
				bs.add(p, -1);
				done[p] = true;
				break;
		} // end switch
		normalize();
	} // end while 
}

bool input(void){
	cin >> q >> lim;
	return (q || lim);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	for(; input(); ){
		solve();
		cout << "end" << endl;
	} // end for

	return 0;
}

Measured memory_bytes: 25232
#include<stdio.h>

int main() {
	int i = 0;
	int m, f, r;
	int score[50][3] = { 0 };

	while (1) {
		scanf("%d %d %d", &m, &f, &r);

		if (m == -1 && f == -1 && r == -1) {
			break;
		}

		score[i][0] = m;
		score[i][1] = f;
		score[i][2] = r;

		if (score[i][0] == -1 || score[i][1] == -1) {
			printf("F");
		}else if (score[i][0] + score[i][1] >= 80) {
			printf("A");
		}else if (score[i][0] + score[i][1] >= 65) {
			printf("B");
		}else if (score[i][0] + score[i][1] >= 50) {
			printf("C");
		}else if (score[i][0] + score[i][1] >= 30) {
			if (score[i][2] >= 50) {
				printf("C");
			}else {
				printf("D");
			}
		}else {
			printf("F");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include<bits/stdc++.h>
using namespace std;


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

int main(){
    int H, W, C_H, C_W, D_H, D_W;
    cin >> H >> W >> C_H >> C_W >> D_H >> D_W;

    vector<vector<char>> S(H+1, vector<char>(W+1));
    vector<vector<int>> ans(H+1, vector<int>(W+1, -1));

    int dH[] = {1,-1,0,0}, dW[] = {0,0,1,-1};

    for(int i = 1; i <= H; ++i){
        for(int j = 1; j <= W; ++j){
            cin >> S[i][j];
        }
    }

    queue<int> Qh, Qw;
    Qh.push(C_H); Qw.push(C_W);
    int n = 0;
    ans[C_H][C_W] = 0;

    while(!Qh.empty()){
        queue<int> buf_h, buf_w;
        while(!Qh.empty()){
            int h = Qh.front(), w = Qw.front();
            buf_h.push(h), buf_w.push(w);
            Qh.pop(); Qw.pop();
            for(int i = 0; i < 4; ++i){
                int y = dH[i], x = dW[i];
                if(1<=h+y && h+y<=H && 1<=w+x && w+x<=W && S[h+y][w+x]=='.' && ans[h+y][w+x]==-1){
                    ans[h+y][w+x] = n;
                    Qh.push(h+y); Qw.push(w+x);
                }
            }
        }
        ++n;
        while(!buf_h.empty()){
            int h = buf_h.front(), w = buf_w.front();
            buf_h.pop(); buf_w.pop();
            for(int i = -2; i <= 2; ++i){
                for(int j = -2; j <= 2; ++j){
                    if(1<=h+i && h+i<=H && 1<=w+j && w+j<=W && S[h+i][w+j]=='.' && ans[h+i][w+j]==-1){
                        ans[h+i][w+j] = n;
                        Qh.push(h+i); Qw.push(w+j);
                    }
                }
            }
        }
    }

    cout << ans[D_H][D_W] << endl;


    return 0;
}

Measured memory_bytes: 8556
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		String S = scan.next();
		String T = scan.next();
		int ans = 0;

		String[] splitedS = S.split("");
		String[] splitedT = T.split("");

		for(int i = 0;i < S.length(); i++) {
			if(!(splitedS[i].equals(splitedT[i]))) {
				ans++;
			}
		}

		System.out.println(ans);

	}
}

Measured memory_bytes: 57812
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

const int mod = 1000000007; // const int mod = 998244353;
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 { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll n,k;
    cin >> n >> k;
    mint res = 0;
    for(ll j=k; j<=n+1; j++){
        mint dj = -j*j;
        mint nj = (n+1)*j;
        res += dj+nj+1;
    }
    cout << res << endl;
}

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



int main() {
	vector<vector<int>>A(3, vector<int>(3));
	vector<vector<bool>>ans(3, vector <bool>(3, false));
	rep(i, 3) {
		rep(j, 3) {
			cin >> A[i][j];
		}
	}
	int N;
	cin >> N;
	vector<int>B(N);
	rep(k, N) {
		cin >> B[k];
	}

	int count = 0;
	
	
	rep(i, 3) {
		rep(j, 3) {
				rep(k, N) {
				if (B[k] == A[i][j]) {
					ans[i][j] = true;
				}

			}
		}
		
	}

	
	




		rep(i, 3) {

			if (ans[0][0] == true && ans[1][1]==true && ans[2][2]==true) {
				cout << "Yes" << endl;
				return 0;
			}
			if (ans[0][i] == true && ans[1][i] == true && ans[2][i] == true) {
				cout << "Yes" << endl;
				return 0;
			}
			if (ans[i][0] == true && ans[i][1] == true && ans[i][2] == true) {
				cout << "Yes" << endl;
				return 0;
			}

			if (ans[0][2] == true && ans[1][1] == true && ans[2][0] == true) {
				cout << "Yes" << endl;
				return 0;

			}

		}


		cout << "No" << endl;

	}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np

from collections import deque

def main():
	n,m=MI()

	G=[[] for _ in range(n+1)]

	for _ in range(m):
		a,b=MI()
		G[a].append(b)
		G[b].append(a)

	ans=[0]*(n+1)

	Q=deque([1])
	sumi=set()

	while Q:
		now=Q.popleft()

		for next in G[now]:
			if next in sumi:
				continue
			else:
				Q.append(next)
				ans[next]=now
				sumi.add(next)

	print("Yes")

	print(*ans[2:],sep="\n")






































if __name__ == "__main__":
	main()


Measured memory_bytes: 106836
#include<cstdio>
using namespace std;
int H,W;
char a[101][102];
bool pdh[101],pdl[101];
int main()
{
	scanf("%d%d",&H,&W);
	for (int i=1;i<=H;i++)
	{
		for (int k=1;k<=W;k++)
		{
			scanf(" %c",&a[i][k]);
			if (a[i][k]=='#')
			{
				pdh[i]=true;
				pdl[k]=true;
			}
		}
	}
	for (int i=1;i<=H;i++)
	{
		if (pdh[i])
		{
			for (int k=1;k<=W;k++)
			{
				if (pdl[k]) printf("%c",a[i][k]);
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 128
N = int(input())
A = list(map(int,input().split(" ")))  #食べた順番
B = list(map(int,input().split(" "))) #満足度
C = list(map(int,input().split(" ")) )#追加満足度


#満足度を足し合わせていく
manzoku = 0
for i in range(N):
    manzoku += B[A[i]-1]
    
    if i != 0 and (A[i] ==A[i-1] + 1):
        manzoku += C[A[i-1]-1]
        

print(manzoku)

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

typedef struct {
    int head, tail, num, max;
    int *que;
    string *name;
} queue;

void initialize(queue *q, int max)
{
    q->head = q->tail = q->num = 0;
    q->que = new int[max];
    q->name = new string[max];
    q->max = max;
}

int isEmpty(queue *q)
{
    return q->head == q->tail;
}

int isFull(queue *q)
{
    return q->head == (q->tail + 1) % q->max;
}

int enqueue(queue *q, string n, int x)
{
    if (isFull(q))
        return -1;
    q->name[q->tail] = n;
    q->que[q->tail] = x;
    if (q->tail + 1 == q->max)
        q->tail = 0;
    else
        q->tail++;

    return 0;
}

int dequeue(queue *q, string *n, int *x)
{
    if (isEmpty(q))
        return -1;
    *n = q->name[q->head];
    *x = q->que[q->head];
    if (q->head + 1 == q->max)
        q->head = 0;
    else
        q->head++;

    return 0;
}

int main()
{
    int n, q, time, cnt = 0, total = 0;
    queue que, queO;
    string name;

    cin >> n >> q;
    initialize(&que, n + 1);
    initialize(&queO, n + 1);
    for (int i = 0; i < n; i++) {
        cin >> name >> time;
        if (enqueue(&que, name, time) == -1)
            return -1;
        cnt += time;
    }

    while (cnt > 0) {
        dequeue(&que, &name, &time);
        if (time >= q) {
            cnt -= q;
            total += q;
            time -= q;
            if (time)
                enqueue(&que, name, time);
            else
                enqueue(&queO, name, total);
        } else {
            cnt -= time;
            total += time;
            time = 0;
            enqueue(&queO, name, total);
        }
    }

    for (int i = 0; i < n; i++) {
        if (dequeue(&queO, &name, &time) == -1)
            return -1;
        cout << name << ' ' << time << endl;
    }
}


Measured memory_bytes: 6692
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>

constexpr int ALPHA_SIZE = 'z' - 'a' + 1;
using datum = std::array<int, ALPHA_SIZE>;
constexpr int MAX_SIZE = 10;
constexpr int mySize = 1e5;
std::vector<datum> S(1e5);

int main(void){
    int n; scanf("%d", &n);
    S.resize(n);
    for(int i = 0; i < n; ++i){
        getchar();
        for(int j = 0; j < MAX_SIZE; ++j) S[i][getchar()-'a']--;
    }
    std::sort(S.begin(), S.end());
    long long int res = 0;
    int i;
    while(i < n){
        long long int cnt = 0;
        while(i+cnt < n and S[i] == S[i+cnt]) cnt++;
        i += cnt;
        res += cnt * (cnt-1) / 2;
    }
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 10368
import java.util.*;

public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String c = sc.next();

        int countR = 0;
        for (int i = 0; i < n; i++) {
            if (c.charAt(i) == 'R') {
                countR++;
            }
        }

        int needMove = 0;
        for (int i = 0; i < countR; i++) {
            if (c.charAt(i) == 'W') {
                needMove++;
            }
        }

        System.out.println(needMove);
	}
}

Measured memory_bytes: 40912
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pie 3.142857143
#define ll long long int
#define fr(i,a,n) for(ll i=a;i<n;i++)
#define vi vector<int>
#define vlli vector<ll>
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fv(i,a) for(auto i:a)
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define frv(i,c) for(auto i = c.begin(); i != c.end(); i++)

void solve()
{
	ll n, w;
	cin >> n >> w;
	vector<ll>dp(1e5 + 1	, INT_MAX);
	dp[0] = 0;
	ll f = 0;
	fr(i, 0, n)
	{
		ll wt, val;
		cin >> wt >> val;
		f += val;
		for (ll j = f; j >= 0; j--)
		{
			if (dp[j] != INT_MAX || j == 0)
			{
				dp[j + val] = min(dp[j + val], dp[j] + wt);
			}
		}
	}
	ll ans = 0;
	fr(i, 0, f + 1)
	{
		if (dp[i] <= w)
			ans = i;
	}
	cout << ans << endl;
}


int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen ("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	//cin>>t;
	t = 1;
	while (t--)
	{
		solve();
	}


	return 0;
}

Measured memory_bytes: 3964
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define pb push_back
#define fi first
#define se second
const int N=1e6+10;
const int mod7=1e9+7;
const int mod=998244353;
void read(int &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0')
        if(ch=='-')
            d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9')
        a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
void read(ll &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0')
        if(ch=='-')
            d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9')
        a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
map <string,bool> vis;
int main()
{
    int n;read(n);
    int ans=0;
    for(re int i=1;i<=n;i++)
    {
        string s;cin>>s;
        if(!vis[s]) ans++,vis[s]=1;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 19328
/*
  AOJ 2517
  Title:Hotel
  @kankichi573
*/
#include <stdio.h>
#include <limits.h>

int N,D;
int charge[51][50];
int cheapest[51][50];
int times[51][50];
int result[50];
void calc_cheapest()
{
  int i,j,min_;

  for(i=0;i<D;i++)
    {
      min_=INT_MAX;
      for(j=0;j<N;j++)
	if(min_ > charge[j][i])
	  min_ = charge[j][i];
      for(j=0;j<N;j++)
	cheapest[j][i]=(min_==charge[j][i])?(-1):0;
    }
}
int min_yadogae(int dat)
{
  int i,min_;
  min_=INT_MAX;
  for(i=0;i<N;i++)
    if(times[i][dat]>=0 && min_ > times[i][dat])
      min_=times[i][dat];
  return(min_);
}
void calc_times()
{
  int i,j;
  for(i=0;i<N;i++)
    for(j=0;j<D;j++)
      times[i][j]=-2;
  for(i=0;i<N;i++)
    if(cheapest[i][D-1])
      times[i][D-1]=0;
  if(D==1)
    return;
  
  for(j=D-2;j>=0;j--)
    for(i=0;i<N;i++)
      if(cheapest[i][j])
	if(times[i][j+1]>=0)
	  times[i][j]=times[i][j+1];  
	else
	  times[i][j]=1+min_yadogae(j+1);
  
}
void dump1()
{
  int i,j;
  for(i=0;i<N;i++)
    {
      for(j=0;j<D;j++)
	printf("%02d|",cheapest[i][j]);
      printf("\n");
    }
}
void dump2()
{
  int i,j;
  for(i=0;i<N;i++)
    {
      for(j=0;j<D;j++)
	printf("%02d|",times[i][j]);
      printf("\n");
    }
}
int cheapest_total()
{
  int i,j,ret;
  ret=0;
  for(j=0;j<D;j++)
    {
      for(i=0;i<N;i++)
	if(cheapest[i][j])
	  {
	    ret += charge[i][j];
	    break;
	  }
    }
  return(ret);
}
int chepest_minimum(int d)
{
  int i,ret,min_;

  min_=INT_MAX;
  for(i=0;i<N;i++)
    if(times[i][d]<min_)
      {
	min_=times[i][d];
	ret =i;
      }
  return(ret);
}
void print_result()
{
  int i,j,yg,pv;

  yg=min_yadogae(0)+1;
  pv=-1;
 
  for(i=0;i<D;i++)
    {
     for(j=0;j<N;j++)
      if((j==pv && yg==times[j][i]) ||(j!=pv && yg==times[j][i]+1))
	{
	   printf("%d\n",j+1);
	   pv=j;yg=times[j][i];
	   break;
	}
    }
}
void solve()
{
  int i,P,M;

  P=cheapest_total();
  M=min_yadogae(0);
  printf("%d %d\n",P,M);
  print_result();

}

main()
{
  int i,j;

  scanf("%d %d",&N,&D);
  for(i=0;i<N;i++)
    for(j=0;j<D;j++)
      scanf("%d",&charge[i][j]);

  calc_cheapest();
  //dump1();
  //printf("--------\n");
  calc_times();
  //dump2();
  //printf("--------\n");
  solve();

  return(0);
}

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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define all(c) begin(c),end(c)

template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

const int INF = 1 << 29;

auto solve() {
    int D;
    cin >> D;
    cout << "Christmas";
    REP(i, 25 - D) {
        cout << " Eve";
    }
    cout << endl;
}


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

//    cout << solve() << endl;
    solve();
    return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string a, b;
  cin >> a >> b;
  int x, y;
  cin >> x >> y;
  string color;
  cin >> color;
  if (color == a) {
    cout << x - 1 << " " << y << '\n';
  } else {
    cout << x << " " << y - 1 << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define pf push_front
#define pi (acos(-1))
///#define for(i,a,b) for(i=(a);i<(b);++i)
///freopen("input.txt","r",stdin);
///   freopen("output.txt","w",stdout);
double l;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   cin>>l;
   cout<<setprecision(10)<<fixed<<(l/3)*(l/3)*(l/3)<<"\n";
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[1010][1010];
int B[1010][1010];
ll SA[1010][1010];
ll SB[1010][1010];
ll dp[1010][1010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(x,N) FOR(y,N) {
		if(x<y) cin>>A[x][y];
		if(x>y) cin>>B[x][y];
		SA[x+1][y+1]=SA[x][y+1]+SA[x+1][y]-SA[x][y]+A[x][y];
		SB[x+1][y+1]=SB[x][y+1]+SB[x+1][y]-SB[x][y]+B[x][y];
	}
	
	
	FOR(y,N+1) FOR(x,N+1) dp[y][x]=1LL<<60;
	for(i=1;i<=N;i++) {
		dp[0][i]=SA[i][i];
	}
	ll ret=dp[0][N];
	for(int l=0;l<N;l++) {
		for(int r=l+1;r<N;r++) {
			for(int x=r+1;x<=N;x++) {
				
				dp[r][x]=min(dp[r][x],dp[l][r]+SA[x][x]-SA[r][x]-SA[x][r]+SA[r][r]+SB[x][l]-SB[r][l]);
				if(x==N) ret=min(ret,dp[r][x]);
			}
		}
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 24832
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  int n; scanf("%d", &n);
  v1i t(n+1, 0); vector<pii> v(n+1, {0,0});
  rep(i, n) scanf("%d %d %d", &t[i+1], &v[i+1].fi, &v[i+1].se);
  bool b = 1;
  rep(i, n){
    int c = t[i+1]-t[i], d = abs(v[i+1].fi-v[i].fi)+abs(v[i+1].se-v[i].se);
    if(d > c){
      b = 0;
      break;
    }
    else if((c-d) % 2 & 1){
      b = 0;
      break;
    }
  }
  if(b) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 1408
import sys
input=sys.stdin.readline
import itertools
N,M,Q=map(int,input().split())
T=[]

H=0
for y in range(Q):
    a,b,c,d=map(int,input().split())
    t=(a,b,c,d)
    T.append(t)
A=[x+1 for x in range(M)]
B=list(itertools.combinations_with_replacement(A,N))
C=len(B)
for z in range(C):
    E=B[z]
    G=0
    for l in range(Q):
        F=T[l]
        g=F[0]-1
        h=F[1]-1
        i=F[2]
        if E[h]-E[g]==i:
            G+=F[3]
    if G>=H:
        H=G
print(H)



Measured memory_bytes: 84668
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;

const int INF = 100000000;
typedef pair<int ,int> P;

char maze[55][55];
int n,m;
int sx,sy;
int gx,gy;

int d[55][55];

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

int bfs()
{
    queue<P> que;
    for(int i = 0;i<n;i++)
    {
        for(int j = 0;j<m;j++)
        {
            d[i][j] = INF;
        }
    }
    que.push(P(sx,sy));
    d[sx][sy] = 0;


    while(que.size())
    {
        P p = que.front();// 小的p 是 大P 类型的。
        que.pop();
        if(p.first == gx && p.second == gy)
            break;
        for(int i = 0;i<4;i++)
        {
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
            if(nx>=0 && nx<=n && ny>=0 && ny<=m && maze[nx][ny] != '#' &&d [nx][ny] == INF)
            {
                que.push(P(nx,ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
    return d[gx][gy];
}


int main()
{
    cin>>n>>m;
    int sum1 = 0;
    for(int i = 0;i<n;i++)
    {
        for(int j = 0;j<m;j++)
        {
            cin>>maze[i][j];
            if(maze[i][j]=='.')sum1++;
        }
    }
    sx=0;
    sy=0;
    gx=n-1;
    gy=m-1;
    int resourt = bfs();
    if(resourt==INF)cout<<"-1"<<endl;
    else cout<<sum1-resourt-1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
ll LCM(ll a, ll b){
    return a/GCD(a,b)*b;
}
int main(){
    int N;
    string S;
    cin>>N>>S;
    if(N%2){
        cout<<"No"<<endl;
        return 0;
    }
    string t = S.substr(0,N/2);
    string t2 = S.substr(N/2,N);
    if(t==t2){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

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

int main()
{
  int n;
  cin >> n;
  valarray<uint64_t> a(n);
  uint64_t allxor = 0;

  for (auto&& e : a) {
    cin >> e;
    allxor ^= e;
  }
  a &= ~allxor;

  int j, rank = 0;

  for (int i = 59; i >= 0; i--) {
    for (j = rank; j < n; j++) {
      if ((a[j] & (1ULL << i)) != 0) break;
    }
    if (j == n) continue;
    if (j > rank) a[rank] ^= a[j];
    for (j = rank + 1; j < n; j++) {
      a[j] = min(a[j], a[j] ^ a[rank]);
    }
    rank++;
  }

  uint64_t x = 0;

  for (auto&& e : a) {
    x = max(x, x ^ e);
  }

  cout << x + x + allxor << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=1;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

const ll mod = 1e9+7;
const ll INF = ll(1e18)+1;
const ll MAXN = 1e6;

int main()
{
    int a,b,t;
    cin>>a>>b>>t;
    cout<<b*(t/a);
}

Measured memory_bytes: 256
//******* It's LEVI_17 ***************

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ff first
#define ss second
#define MP make_pair
#define mset(x,a) memset(x,a,sizeof(x))
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define sqr(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define f1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define vvll vector<vector<ll>>  
#define vll vector<ll> 
#define pll pair<ll,ll>
#define vpll vector<pll>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define cases ll t;cin >> t;while(t--)
#define rr return 0
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define deb(a)			std::cerr<<#a<<"="<<(a)<<"\n"
#define deb2(a,b)		std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define deb3(a,b,c)		std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
const int MOD = 1000 * 1000 * 1000 + 7;

//syntax for priority queue
// max queue -> priority_queue<ll>
// min queue -> priority_queue<ll,vector<ll>,greater<ll>>

//##############################################################################################

ll getRes(ll wt[],ll val[],ll n,ll w)
{
    ll dp[n + 1][w + 1];//[n+1][w+1]
    for (ll i = 0; i <= n; i++)
        dp[i][0] = 0;
    for (ll i = 0; i <= w; i++)
        dp[0][i] = 0;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = 1; j <= w; j++)
        {
            if (wt[i - 1] <= j)
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wt[i - 1]] + val[i - 1]);
            else
                dp[i][j] = dp[i - 1][j];
        }
    }

    return dp[n][w];
}

void solve()
{
    ll n,w;
    cin >> n >> w;
    ll wt[n],val[n];
    f(i, n)
        cin >> wt[i] >> val[i];
   
    ll res = getRes(wt,val, n,w);
    cout << res << "\n";
}

//###############################################################################################

int main()
{
    fast;
    ll t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    rr;
}


//Watashi wa tsuyoku modotte kimasu

Measured memory_bytes: 82484
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace abc160
{
    class Program
    {
        static void Main(string[] args)
        {
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
			solve_abc160A();
        }

        public static void solve_abc160B()
        {
        }

        public static void solve_abc160A()
        {
            string s = Console.ReadLine();
            Console.WriteLine(s[2] == s[3] && s[4] == s[5] ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<long long> vll, vLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
ll gcdll(ll a, ll b ){
    ll r, tmp;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}
ll lcmll(ll a, ll b ){
    if(a==0||b==0) return 0;
    return ((a/gcdll(a,b))*b);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    string s,t;
    cin >> n >> m;
    cin >> s >> t;
    ll x = gcdll(n,m);
    ll ans = lcmll(n,m);
    ll nx = ans/n;
    ll mx = ans/m;
    ll si = 0;
    ll ti = 0;
    while(si<n&&ti<m){
        if(s[si]!=t[ti]){
            cout << -1 << endl;
            return 0;
        }
        si += mx;
        ti += nx;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
using std::cin;
using std::cout;

int main() {
	int x, y;
	while(cin >> x >> y && (x || y)) {
		if(x > y) { int t = x; x = y; y = t; }
		cout << x << ' ' << y << '\n';
	}
	return 0;
}


Measured memory_bytes: 3084
H, W = list(map(int, input().split()))
S_list = []
for i in range(H):
    S_list.append(input())
for i in range(H):
    for j in range(W):
        m = S_list[i][j]
        if m == '#':
            print(m, end='')
        else:
            sum = 0
            if i != 0 and j != 0 and S_list[i-1][j-1] == '#': sum += 1
            if i != 0 and S_list[i-1][j] == '#': sum += 1
            if i != 0 and j != W-1 and S_list[i-1][j+1] == '#': sum += 1
            if j != 0 and S_list[i][j-1] == '#': sum += 1
            if j != W-1 and S_list[i][j+1] == '#': sum += 1
            if i != H-1 and j != 0 and S_list[i+1][j-1] == '#': sum += 1
            if i != H-1 and S_list[i+1][j] == '#': sum += 1
            if i != H-1 and j != W-1 and S_list[i+1][j+1] == '#': sum += 1
            print(sum, end='')
    print('')
        

Measured memory_bytes: 9156
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int W = s.nextInt();
        int[] w = new int[n];
        long[] v = new long[n];
        for (int i=0; i<n; i++){
            w[i] =s.nextInt();
            v[i] =s.nextLong();
        }        
        long maxGain = knapsack(w, v, W);
        System.out.println(maxGain);
    }

    private static Long knapsack(int[] w, long[] v, int W) {
        long[][] matrix = new long[w.length + 1][W + 1];

        for (int i = 0; i < w.length; i++) {
            for (int j = 0; j < W; j++) {
                matrix[i][j] = 0;
            }
        }

        for (int i = 1; i <= w.length; i++) {
            for (int j = 0; j <= W; j++) {
                int weight = w[i - 1];
                if(weight<=j){
                    matrix[i][j] = Math.max(
                            v[i - 1] + matrix[i - 1][j - weight],
                            matrix[i - 1][j]
                    );
                }else{
                    matrix[i][j]=matrix[i-1][j];
                }

            }
        }
        return matrix[w.length][W];
    }
}

Measured memory_bytes: 141400
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef map<int,int> mii;
 
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define mem(a) memset(a , 0 ,sizeof a)
#define rep(i,a,b) for(int i=a ; i<b ; ++i)
#define deb(x) cout << #x << " - " << x << "\n";
#define deb2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define D2(x) { cerr << "[" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }
#define ps(x,y) fixed<<setprecision(y)<<x
#define clz(x) __builtin_clzll(x)
#define setbit(x) __builtin_popcount(x)
 
#define PI 3.141592653589793
const ll MOD = 1e9 + 7;
const ll INF = 10000005;
const ll MAX_N = 1e4 + 10;

int calcAngle(double h, double m)  
{  
    // validate the input  
    if (h <0 || m < 0 || h >12 || m > 60)  
        printf("Wrong input");  
  
    if (h == 12) h = 0;  
    if (m == 60) m = 0;  
  
    // Calculate the angles moved  
    // by hour and minute hands  
    // with reference to 12:00  
    int hour_angle = 0.5 * (h * 60 + m);  
    int minute_angle = 6 * m;  
  
    // Find the difference between two angles  
    int angle = abs(hour_angle - minute_angle);  
  
    // Return the smaller angle of two possible angles  
    angle = min(360 - angle, angle);  
  
    return angle;  
}  
  

int main() {
    IOS;
    double a,b,h,m;
    cin >> a >> b >> h >> m;
    double a_h = (PI/(6.0))*(h+m/60.0);
    double a_m = (2.0*PI)*(h+m/60.0);
    cout << fixed << setprecision(20) << sqrt(a*a + b*b - 2*a*b*cos(a_h-a_m));
    return 0;
}

Measured memory_bytes: 4276
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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

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

const ll MOD = 1000000007;

vector<bool> stairs; // ok if true
vector<ll> dp;

void solve(const int N) {
    for (int i = 1; i <= N; i++) {
        if (!stairs[i]) continue;
        if (i >= 1 && stairs[i - 1]) {
            dp[i] = (dp[i] + dp[i -1]) % MOD;
        }
        if (i >= 2 && stairs[i - 2]) {
            dp[i] = (dp[i] + dp[i - 2]) % MOD;
        }
    }
}

int main(void) {
    int N, M;
    cin >> N >> M;

    stairs.resize(N + 1, true);
    for (int i = 0; i < M; i++) {
        int a;
        cin >> a;
        stairs[a] = false;
    }

    dp.resize(N + 1);
    dp[0] = 1;

    solve(N);

    cout << dp[N] << endl;

    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int main(void)
{
    int x,y;
    cin>>x>>y;
    if (!(x % y))
        puts("-1");
    else
        cout << 1ll * x * (y - 1) << '\n';
    return 0;
}


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

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    
    int ans = 0;
    for(int i=0; i<n-2; i++){
        string abc = s.substr(i,3);
        if(abc=="ABC") ans++;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
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 gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  vl dp(100001, 0);
  ll count = 0;
  rep(i, n){
    ll a;
    cin >> a;
    if(a>100000){
      count++;
      continue;
    }
    dp[a]++;
    if(dp[a]>a){
      count++;
    }
  }
  rep(i,100001){
    if(dp[i]<i){
      count+= dp[i];
    }
  }
  print(count);
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,K;cin>>A>>B>>K;
  int x=A;
  while(A%x!=0||B%x!=0)x--;
  int i=x,y=1;
  while(y<K){
    i--;
    if(x%i==0)y++;
  }
  cout<<i<<endl;
}

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

const int N = 2e5 + 10, mod = 1e9 + 7;

char s[N];

int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1; 
    //scanf("%d", &tc);
    while(tc--) {
        int n; scanf("%d", &n);
        int ans = 0;
        map<string, bool> vis;
        for(int i = 0; i < n; i++) {
            scanf("%s", &s);
            string t = s;
            ans += (!vis[t]);
            vis[t] = 1;
        }
        cout << ans << '\n';
    }    
    return 0;
}

Measured memory_bytes: 19248