akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    ll sum = 0;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
        mp[a[i]]++;
    }
    int q;
    cin >> q;
    while (q--) {
        int b, c;
        cin >> b >> c;
        sum += (c - b) * mp[b];
        mp[c] += mp[b];
        mp[b] = 0;
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 7956
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;

/*
struct point
{
long long dist; long long name;
bool operator<(const point& rhs) const {
return dist > rhs.dist;
}
};
*/

ll const MAX = 100005;
ll p[MAX], q[MAX];

int main() {
	ll h, w;
	cin >> w >> h;
	REP(i, 1, w) {
		cin >> p[i];
	}
	REP(j, 1, h) {
		cin >> q[j];
	}
	SORT(p, w);
	SORT(q, h);
	p[w + 1] = q[h + 1] = 1e11;
	ll cnt_p = 1; ll cnt_q = 1;
	ll ans = 0;
	while (cnt_p <= w || cnt_q <= h) {
		if (p[cnt_p] < q[cnt_q]) {
			ans += (h + 2 - cnt_q)*p[cnt_p];
			//cout << (w+2-cnt_q) << " " << p[cnt_p] << "?" << endl;
			cnt_p++;
		}
		else {
			ans += (w + 2 - cnt_p)*q[cnt_q];	
			//cout << h + 2 - cnt_p << " " << q[cnt_q] << "!" << endl;

			cnt_q++;
		}
		//cout << ans << endl;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main() {

	int n, a[6]={1, 5, 10, 50, 100, 500};

	while(cin >> n) {
		if(!n) {
			break;
		}
		int t=0;
		n=1000-n;
		int i=5;
		while(i!=-1) {
			if(n>=a[i]) {
				n-=a[i];
				t++;
			}
			else {
				i--;
			}
		}

		cout << t << endl;
	}

	return 0;

}

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

using namespace std;

long long gcd(long long a, long long b) { return b ? gcd(b,a%b) : a;}

map< long long, int > prime_factor(long long n) {
  map< long long, int > ret;
  for(long long i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main(){
  long long A,B,c;
  cin >> A >> B;
  c = gcd(A,B);

  map<long long, int> table;
  table = prime_factor(c);

  long long ans = 1;
  for( auto i = table.begin(); i != table.end() ; ++i ) {
    ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
S = input()
N, counter_zero, counter_one = len(S), 0, 0
for i in range(N):
    if S[i:i+1] == '0':
        counter_zero += 1
    elif S[i:i+1] == '1':
        counter_one += 1
ans = 2 * min(counter_zero, counter_one)
print(ans)

Measured memory_bytes: 3188
n =int(input())
A = []
sm = 0
ans = 0 
import math
def Comb(a,b):#aCbを返す
    if a>= b:
        return int(math.factorial(a)/(math.factorial(b)*math.factorial(a-b)))
    else:
        return 0

for inp in input().split():
    sm += int(inp)
    A.append(sm)
A.sort()

temp = 0
zeros = 0
num = 0
for a in A:
    if a == 0:
        zeros += 1
    elif a == temp:
        num += 1
    else:
        temp = a
        ans += Comb(num,2)
        num = 1
ans += Comb(zeros,2)+zeros+Comb(num,2)

print(ans)

Measured memory_bytes: 26492
import itertools

n = int(input())

s = list(map(int,input().split()))
p = list(itertools.combinations(s, 3))
#print(p)

ans = 0
for i in range(len(p)):
    if sum(p[i]) - max(p[i]) > max(p[i]) and len(p[i]) == len(set(p[i])):
        ans = ans + 1
        #print(i,ans)

#print(set(p[0]),len(set(p[0])))
print(ans)

Measured memory_bytes: 20616
#include<iostream>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
typedef long long int llint;
int main(){
	char a[11], b[11], c[11];
	cin >> a;
	cin >> b;
	cin >> c;
	if (a[strlen(a) - 1] == b[0] && b[strlen(b) - 1] == c[0]){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
	return 0;
}

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

int main(){
 int n,max=0,sum=0;
 cin >> n;
 vector<int> l(n);
 rep(i,n) cin >> l[i];
 rep(i,n){
   if(l[i]>max){
     max=l[i];
   }
 }
 rep(i,n) 
   sum += l[i];
   
 if(sum>2*max) cout << "Yes" << endl;
 if(sum<=2*max) cout << "No" << endl;
 
}

Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<deque>
#include<cassert>

using namespace std;

#define sz(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;++i)
#define per(i,a,b) for(int i=b-1;i>=a;--i)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
////////////////////////////

int const N = 1e5 + 41;
int a[N];

set<int> q;

void bad(){
	cout << "No" << endl;
	exit(0);
}

void ok(){
	cout << "Yes" << endl;
	exit(0);
}

void solve(){
	int mini = 1e9;
	int maxi = -mini;
	int n;
	cin >> n;
	rep(i, 0, n){
		int v;
		cin >> v;
		q.insert(v);
		a[i] = v;
		maxi = max(maxi, v);
		mini = min(mini, v);
	}
	if(sz(q) > 2) bad();
	if(maxi - mini > 1) bad();
	if(maxi == mini){
		if(mini > n / 2){
			if(mini == n - 1) ok(); else
			bad();
		}else ok();
	}
	int cntMin = 0;
	rep(i, 0, n) if(a[i] == mini) ++cntMin;
	int cntMax = n - cntMin;
	if(cntMin - 1 + 1 > mini) bad();
	if(cntMax == 1) bad();
	if(cntMin + cntMax / 2 < maxi) bad();
	ok();
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();

	return 0;
}

Measured memory_bytes: 5376
n=int(input())
f,s=0,0
while f*4+s*7<=n:
  if f*4+s*7==n:
    print("Yes")
    exit()
  while f*4+s*7<=n:
    if f*4+s*7==n:
      print("Yes")
      exit()
    s+=1
  s=0
  f+=1
print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int n; ll c; cin >> n >> c;
  vl dist(n), calorie(n);
  rep(i,n) cin >> dist[i] >> calorie[i];
  
  vl right(n), left(n);
  
  right[0] = calorie[0] - dist[0];
  rep(i,n-1) right[i+1] = right[i] + calorie[i+1] - (dist[i+1] - dist[i]);

  left[0] = calorie[n-1] - (c - dist[n-1]);
  rep(i,n-1) left[i+1] = left[i] + calorie[n-2-i] - (dist[n-1-i] - dist[n-2-i]);

  ll ans = 0;
  ans = max(ans, (ll)*max_element(all(right)));
  ans = max(ans, (ll)*max_element(all(left)));

  ll Rmax = -c, Lmax = -c;
  rep(i,n-1) {
    ll tmp = left[n-2-i] - (c - dist[i+1]);
    Rmax = max(Rmax, right[i]);
    ans = max(ans, tmp + Rmax);
  }
  rep(i,n-1) {
    ll tmp = right[n-2-i] - dist[n-2-i];
    Lmax = max(Lmax, left[i]);
    ans = max(ans, tmp + Lmax);
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <cmath>

#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{


    string n;
    
    cin >> n;
    
    switch(n[n.size()-1])
    {
        case '2':
        case '4':
        case '5':
        case '7':
        case '9':
            cout << "hon";
            break;
        case '0':
        case '1':
        case '6':
        case '8':
            cout << "pon";
            break;
        default:
            cout << "bon";
    }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define setDP(arr) memset(arr,-1,sizeof arr)
#define Clear(arr) memset(arr,0,sizeof arr)
#define oo 2000000000
#define inf 1000000000000000000
#define P1 31
#define P2 37
#define M  1000000007
#define M2 1000000009
#define pii pair<ll,ll>
typedef long long ll;
using namespace std;
const int N = 255001;
const int SQRTN = 320;
const int LOGN = 20;
const long double PI = acos(-1);
const long double TAU = 2*PI;

string s;
int ctr;
int ans = 0 ;

signed main(){
    cin >> s;
    for(int i = 0 ; i < s.size() ; i++){
        if(s[i]=='S')ctr++;
        if(s[i]=='T'){
            if(ctr)ctr--,ans++;
        }
    }
    cout << s.size()-(2*ans) << endl;



}


Measured memory_bytes: 640
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main(){
	map<string,vi> se;
	string s;
	while(cin>>s){
		int n;
		cin>>n;
		if(!EXIST(se,s)){
			se[s]=vi();
		}
		se[s].push_back(n);
	}
	for(map<string,vi>::iterator it=se.begin();it!=se.end();it++){
		cout<<(*it).first<<endl;
		sort(ALL((*it).second));
		REP(i,(*it).second.size()){
			cout<<(i==0?"":" ")<<(*it).second[i];
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1244
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
struct structure{
        int n,count;
};
int main(){
        int N,M;
        cin>>N>>M;
        vector<vector<int> > list(N+1);
        for(int i=0 ; i<M ; i++ ){
                int a,b;
                cin>>a>>b;
                list[a].push_back(b);
                list[b].push_back(a);
        }
        vector<bool> past(N,false);
        queue<structure> circle;
        structure now;
        now.n=1;now.count=0;
        circle.push(now);
        while(circle.size()!=0){
                now=circle.front();circle.pop();
                if(now.count>2)break;
                if(now.n==N){
                        cout<<"POSSIBLE"<<endl;
                        return 0;
                }
                if(past[now.n])continue;
                past[now.n]=true;
                vector<int>::iterator itr;
                for(itr=list[now.n].begin() ; itr!=list[now.n].end() ; ++itr ){
                        structure next;
                        next.n=*itr;
                        next.count=now.count+1;
                        circle.push(next);
                }
        }
        cout<<"IMPOSSIBLE"<<endl;
        return 0;
}

Measured memory_bytes: 12784
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
            Console.WriteLine(new List<long>
            {
                a[0] * a[2],
                a[0] * a[3],
                a[1] * a[2],
                a[1] * a[3]
            }.Max());
        }
    }
}

Measured memory_bytes: 28400
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    
    long ans = (long)Math.pow(K-1, N-1) * K;
    
    System.out.println(ans);
  }
}

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

const int maxn = 1e5;

int n;
int v[maxn+2], dp[maxn+2];

int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>v[i];
    }
    dp[2]=abs(v[1]-v[2]);
    for(int i=3; i<=n; i++)
    {
        dp[i]=min(dp[i-1]+abs(v[i-1]-v[i]),dp[i-2]+abs(v[i-2]-v[i]));
    }
    cout<<dp[n];
    return 0;
}


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

int main() {
  int n,m;
  cin >> n >> m;
  vector<pair<int,int>> vec(n);
  for(int i = 0; i < n; i++) {
    int x,y;
    cin >> x >> y;
    pair<int,int> p(x,y);
    vec[i] = p;
  }
  int64_t drink=0,ans=0;
  bool flag = false;
  sort(vec.begin(),vec.end());
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < vec[i].second; j++) {
      if(drink == m) {
        flag = true;
        break;
      }
      ans += vec[i].first;
      drink++;
    }
    if(flag) break;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)


class UnionFind:
    def __init__(self, n):
        self.p = [-1]*n
        self.r = [1]*n

    def find(self, x):
        if self.p[x] < 0:
            return x
        else:
            self.p[x] = self.find(self.p[x])
            return self.p[x]

    def union(self, x, y):
        rx, ry = self.find(x), self.find(y)
        if rx != ry:
            if self.r[rx] > self.r[ry]:
                rx, ry = ry, rx
            if self.r[rx] == self.r[ry]:
                self.r[ry] += 1
            self.p[ry] += self.p[rx]
            self.p[rx] = ry

    def count_roots(self):
        return sum(p < 0 for p in self.p)


n, m = map(int, input().split())
uf = UnionFind(n)
for _ in range(m):
    x, y, _ = map(lambda x: int(x)-1, input().split())
    uf.union(x, y)
print(uf.count_roots())


Measured memory_bytes: 7796
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
#define int long long
using namespace std;
inline int Calc(int x, int p) {
    return x / p;
}
inline int Calc(int a, int b, int c) {
    return (Calc(a, b) + Calc(a, c) - Calc(a, b * c / __gcd(b, c)));
}
int a, b, c, d, res;
main() {
    DAU
    cin >> a >> b >> c >> d;
    cout << (b - a + 1) - (Calc(b, c, d) - Calc(a - 1, c, d));
    PLEC
}


Measured memory_bytes: 3628
#include <stdio.h>

#define TIME_MIN 2
#define TIME_MAX 200000
#define VALUE_MIN 1
#define VALUE_MAX 1000000000

int get_int(int *p_num, int min, int max);
int judge_constraint(int test_num, int min, int max);
int max_profit(int size);

int main(void)
{
    int time_cnt;
    
    if(get_int(&time_cnt, TIME_MIN, TIME_MAX))
    {
        return -1;
    }

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

int max_profit(int size)
{
    int min;
    int max;
    int current;
    int i;
    
    /* init  */
    if(get_int(&current, VALUE_MIN, VALUE_MAX))
    {
        return -1;
    }
    min = current;
    max = VALUE_MAX * -1;
    
    /* calc */
    for(i = 1; i < size; i++)
    {
        if(get_int(&current, VALUE_MIN, VALUE_MAX))
        {
            return -1;
        }
        if(max < current - min)
        {
            max = current - min;
        }
        if(min > current)
        {
            min = current;
        }
    }
    
    
    return max;
}

int get_int(int *p_num, int min, int max)
{
	scanf("%d", p_num);
	
	if(judge_constraint(*p_num, min, max) == -1)
    {
        return -1;
    }
	
	return 0;
}
int judge_constraint(int test_num, int min, int max)
{
    if(test_num < min || test_num > max)
    {
        return -1;
    }
    
    return 0;
}

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

using namespace std;

int main(void){
    int n, x;
    while(true){
        cin >> n >> x;
        if(x + n == 0)break;
        int sum = 0;
        for(int i = 1; i <= n - 2; i++){
            for(int j = i + 1; j <= n - 1; j++){
                for(int k = j + 1; k <= n; k++){
                    if(i + j + k == x)sum++;
                }
            }
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int h, n;
    cin >> h >> n;
    int sum = 0;
    rep(i, n) {
        int a;
        cin >> a;
        sum += a;
    }
    if (sum >= h) cout << "Yes" << endl;
    else          cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef DEBUG
#include "_debug.cpp"
#include "callable.hpp/callable.hpp"
#endif
#define endl '\n'
using namespace std;
using ll = long long;
#define N 200
#define INF (200 * 200 * 100'000ll)
ll adj[N+1][N+1];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, r;
    cin >> n >> m >> r;
    vector<int> visit(r);
    for(int i = 0; i < r; i++) {
        cin >> visit[i];
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            adj[i][j] = INF;
        }
    }
    for(int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        adj[a][b] = c;
        adj[b][a] = c;
    }
    for(int k = 1; k <= n; k++) {
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
            }
        }
    }
    sort(visit.begin(), visit.end());
    ll ans = INF;
    do {
        ll curr = 0;
        for(int i = 0; i < visit.size() - 1; i++) {
            int u = visit[i];
            int v = visit[i + 1];
            curr += adj[u][v];
        }
        ans = min(ans, curr);
    } while(next_permutation(visit.begin(), visit.end()));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
int N,t,i,j,m;
int main()
{
	for(scanf("%d",&N);~scanf("%d",&N);printf("%d\n",i==1000001?-1:i))
		for(i=0;N/10!=0&&i<1000000;N=m,i++)
			for(m=0,j=10;N/j!=0;j*=10)
			{
				t=(N/j)*(N%j);
				m=m<t?t:m;
			}
	return 0;
}

Measured memory_bytes: 600
n, m = map(int, input().split())

g = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)


visited = [-1] * n
lst = []
k = 0
for i in range(n):
    if visited[i] != -1: continue
    visited[i] = k
    temp = [i]
    cnt = 1
    while temp:
        p = temp.pop()
        for q in g[p]:
            if visited[q] != -1: continue
            visited[q] = k
            temp.append(q)
            cnt += 1
    lst.append(cnt)
print(max(lst))

Measured memory_bytes: 44708
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

typedef long long ll;

ll k;

int main()
{
	cin >> k;

	vector<ll> ans;
	ll start = k / 50;

	ll era = 50 + start - k % 50;

	for(int i = 0;i < 51;i++)
	{
		if(start + i != era)
		{
			ans.push_back(start + i);
		}
	}

	cout << 50 << endl;

	for(int i = 0;i < 50;i++)
	{
		cout << ans[i] << " ";
	}

	cout << endl;
	return 0;




}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(){
	long int W;
	long int a, b;
	long int min_Length;

	cin >> W >> a >> b;

	if(a + W < b){
		min_Length = b - (a + W);
	}else if(b + W < a){
		min_Length = a - (b + W);
	}else{
		min_Length = 0;
	}

	cout << min_Length << endl;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N;

  std::string S;

  std::cin >> N >> S;

  int lp = 0;

  std::map<uint64_t, std::vector<int>> map;

  for (int i = 0; i < N; i ++)
    map[S[i]].push_back(i);

  for (int i = 0; i < N; i ++) {
    for (const auto& kv : map) {
      const std::vector<int>& a = kv.second;

      for (const auto& x : a)
        if (std::lower_bound(ALL(a), x + i + 1) != std::end(a)) {
          lp = i + 1;

          break;
        }
    }
    
    std::map<uint64_t, std::vector<int>> map2;

    for (const auto& kv : map) {
      uint64_t h = kv.first;

      const std::vector<int>& a = kv.second;

      if (a.size() == 1)
        continue;
      
      for (const auto& x : a) {
        int xx = x + i + 1;
        
        if (xx < N)
          map2[h * MOD + S[xx]].push_back(x);
      }
    }

    std::swap(map, map2);
  }

  std::cout << lp << std::endl;

  return 0;
}


Measured memory_bytes: 896
def main():
  s = input()
  t = input()
  sn, tn = len(s), len(t)
  dp = [[0]*(tn+1) for _ in range(sn+1)]
  for i, si in enumerate(s):
    di, di2 = dp[i], dp[i+1]
    for j, ti in enumerate(t):
      if si == ti:
        di2[j+1] = di[j] + 1
      else:
          if di[j+1] > di[j]:
              di2[j+1] = di[j+1]
          else:
              di2[j+1] = di2[j]
    dp[i+1] = di2
  ans = ""
  while sn and tn:
    di = dp[sn][tn]
    if di == dp[sn][tn-1]:
      tn -= 1
    elif di == dp[sn-1][tn]:
      sn -= 1
    else:
      tn -= 1
      sn -= 1
      ans += s[sn]
      
  print(ans[::-1])

if __name__ == "__main__":
  main()

Measured memory_bytes: 113116
k = gets.to_i
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
puts a[k-1]

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll zero = 0;
const ll INF = 10000000000000000; //10^16
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main() {
    int H,W;
    cin >> H >> W;
    vector<int> map(H*W);
    char tmp;
    for(int i = 0; i < H*W; i++){
        cin >> tmp;
        if(tmp == '.'){
            map.at(i) = 0;
        }
        else{
            map.at(i) = 1;
        }
    }
    
    vector<int> minchan(H*W);
    minchan.at(0) = map.at(0);
    for(int hw = 1; hw <= H+W-2; hw++){
        for(int i = max(hw-W+1, 0); i <= min(H-1, hw); i++){
            if(i == 0){
                minchan.at( i*W + hw-i ) = minchan.at( i*W + hw-i-1 ) + abs(map.at(i*W + hw-i) - map.at(i*W + hw-i-1));
            }
            else if(i == hw){
                minchan.at( i*W + hw-i ) = minchan.at( (i-1)*W + hw-i ) + abs(map.at(i*W + hw-i) - map.at((i-1)*W + hw-i));
            }
            else{
                minchan.at( i*W + hw-i ) = min( minchan.at( i*W + hw-i-1 ) + abs(map.at(i*W + hw-i) - map.at(i*W + hw-i-1)) ,
                                                minchan.at( (i-1)*W + hw-i ) + abs(map.at(i*W + hw-i) - map.at((i-1)*W + hw-i)) );                
            }
        }
    }
    minchan.at(H*W-1) += map.at(H*W-1);
    
    printf("%d\n", minchan.at(H*W-1)/2);
    
}


Measured memory_bytes: 384
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

ll com(ll a){
    return a*(a-1)/2LL; 
}

ll com2(ll b){
    ll a= b - 1; 
    return a*(a-1)/2LL; 
}

int main() {
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a.at(i);

    map<ll, ll> mp;
    rep(i,n){
        mp[a.at(i)]++;
    }

    ll sum = 0;
    for(auto x: mp){
        sum += com(x.second);
    }

    for(int i=0; i<n; i++){
        ll ans = sum;
        ll tmp = com(mp[a.at(i)]);
        ans -= tmp;
        tmp = com2(mp[a.at(i)]);
        ans += tmp;
        cout << ans << endl; 
    }

    return 0;
}


Measured memory_bytes: 12160
# Official House

n = int(input())
houses = 4
floors = 3
rooms = 10

official = [[[0 for k in range(rooms)] for j in range(floors)] for i in range(houses)]
# print(official)

for a in range(n):
    info = [int(x) for x in input().rstrip().split()]
    b = info[0] - 1
    f = info[1] - 1
    r = info[2] - 1
    v = info[3]
    currentFloor = official[b][f]
    # print(currentFloor)
    currentFloor[r] += v

# print(official)

for i in range(houses):
    for j in range(floors):
        for k in range(rooms):
            print(' ' + str(official[i][j][k]), end = '')
        print()
    if i < houses - 1:
        print('#' * 20)



Measured memory_bytes: 5624
x,y=map(int,input().split())

if(x>=0 and y>=0):
    if(x<=y):
        print(y-x)
    elif(x>y):
        t=x-y+2
        if(y==0):
            t-=1
        print(t)
elif(x<0 and y<0):
    if(x<=y):
        print(y-x)
    elif(x>y):
        print(x-y+2)
elif(x>=0 and y<0):
    print(abs(abs(x)-abs(y))+1)
elif(x<0 and y>=0):
    if(y==0):
        print(abs(x))
    else:
        print(abs(abs(x)-abs(y))+1)

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    while (n) {
        if (n % 10 == 7) {
            cout << "Yes\n";
            return 0;
        }
        n /= 10;
    }
    cout << "No\n";
}

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

int main() {
    string s;
    cin >> s;
    int counter = 0;
    for (int i = 0; i < 3; i++)
    {
        if(s[i] == s[i+1]) ++counter;
    }
    if (counter == 0) cout << "Good" <<endl;
    else cout << "Bad" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
func readInt() -> Int {
    return Int(readLine()!)!
}

func readInts(separator: String.Element = " ") -> [Int] {
    return readLine()!.split(separator: separator).map { Int($0)! }
}

func mainB() {
    let _ = readInt()
    let numbers = readInts()

    var count = 0
    numbers.enumerated().forEach { (index, number) in
        if !(index + 1).isMultiple(of: 2), !number.isMultiple(of: 2) {
            count += 1
        }
    }
    print(count)
}

mainB()

Measured memory_bytes: 8264
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;

int main(){
    int k,a,b;cin>>k>>a>>b;
    rep2(i,a,b+1){
        if(i%k==0){
            cout<<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;
}

Measured memory_bytes: 3592
n = int(input())
a = list(map(int, input().split()))

li1 = []
li1.append(a[0])

for i in range(len(a) - 1):
    S = a[i+1] - a[i]
    li1.append(S)

li1.append(-a[-1])

li2 = [abs(li1[i+1] + li1[i]) for i in range(len(a))]
li3 = [abs(li1[i+1]) + abs(li1[i]) for i in range(len(a))]

ab_li1 = map(lambda x:abs(x), li1)

S = sum(ab_li1)

for i in range(len(li3)):
    print(S - li3[i] + li2[i])


Measured memory_bytes: 20136
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>


#define rep(i,p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

//C
int main(void) {
	int n;
	cin >> n;
	vector<ll> a = vector<ll>(n);

	rep(i, 0, n) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	ll index = n;
	rep(i, 0, n) {
		if (a[i] >= 0) {
			index = i;
			break;
		}
	}
	if (index <= 1 && index != n) {
		ll sum = -a[0];
		rep(i, 1, n) {
			sum += a[i];
		}
		cout << sum << endl;
		rep(i, 0, n - 2) {
			cout << a[i] << " " << a[i + 1] << endl;
			a[i + 1] = a[i] - a[i + 1];
		}
		cout << a[n - 1] << " " << a[n - 2] << endl;
	}
	else {
		vector<string> ans = vector<string>();
		if (index == n)index = n - 1;
		for (int i = index - 1; i > 0; i--) {
			ans.push_back(to_string(a[n - 1]) + " " + to_string(a[i]));
			a[n - 1] -= a[i];
		}
		rep(i, index, n - 1) {
			ans.push_back(to_string(a[0]) + " " + to_string(a[i]));
			a[0] -= a[i];
		}
		ans.push_back(to_string(a[n - 1]) + " " + to_string(a[0]));
		a[n - 1] -= a[0];
		cout << a[n - 1] << endl;
		rep(i, 0, ans.size()) {
			cout << ans[i] << endl;
		}
	}
	
}


Measured memory_bytes: 9716
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		long A = sc.nextLong();
		long B = sc.nextLong();
		long gcd = gcd(Math.max(A, B),Math.min(A, B));
		int ans = 1;
		for (long i = 2; i*i <= gcd; i++) {
			if (gcd % i == 0) {
				ans++;
				while (gcd%i==0) { 
					gcd /= i;
				}
			}
		}
		if (gcd != 1) {
			ans++;
		}
		System.out.println(ans);
	}
	
	public static long gcd(long a, long b) {
		long remainder = a % b;
		if (remainder == 0) {
			return b;
		} else {
			return gcd(b, remainder);
		}
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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


Measured memory_bytes: 22740
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
# define maxn 100005
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define sz(x) (int)((x).size())
# define int ll
using namespace std;

string s,st = "";

int32_t main(){_
    //freopen("input","r",stdin);
    cin >> s;
    for(int i = 0;i < 4;i++)
    {
        st += s[i];
    }
    st += ' ';
    for(int j = 4;j < sz(s);j++)
    {
        st += s[j];
    }
    rc(st << '\n');
}

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

// #define  part ..
#define listi vector<int > 
#define listll vector<long long >
#define pii pair<int ,int > 
#define pll pair<long long ,long long >
#define heap priority_queue<long long >

#define pb(a) push_back(a)
#define mod 998244353
#define maxx 200006
#define ll long long 
#define quick  	ios_base::sync_with_stdio(NULL),cin.tie(0);
#define rep(i,a,b) for(int i=a;i<b;i++)
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// #define test int t;cin>>t;while(t--)
// end of #define 

// define globals ...


//write function from here ...



int Main(){



int k;
cin>>k;
string s;
cin>>s;

for(int i=0;i<min(k,int(s.length()));i++){
   cout<<s[i];
}

if(int(s.length())  > k)
{
	cout<<"...";
}

  
  return 0;

}
























// main function..
int main(){
	quick;  
  
    Main();
    
    
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<string.h>
int main(){
	int i,a[30];
	char s[30];
	scanf("%s",s);
	for(i=0;i<26;i++)
		a[i]=0;
	for(i=0;i<strlen(s);i++)
		a[s[i]-'a']++;
	for(i=0;i<26;i++){
		if(a[i]>1){
			printf("no\n");
			return 0;
		}
	}
	printf("yes\n");
	return 0;
}

Measured memory_bytes: 128
//各スタート地点からDFS
//探索が終わるまでの距離をカウント
//最も長かったスタート地点とそのゴール地点を返す

//bfsの引数：現在の場所/前の場所
//グローバル：W/H/S/mxdist
//任意のスタートから任意の位置までの距離 : dist


#include<bits/stdc++.h>
using namespace std;
int H, W, mxdist = 0;
vector<vector<char>> S(20, vector<char> (20));
typedef pair<int, int> P;
vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

//返り値は無して良い
void bfs(P pos, P ppos, int dist, vector<vector<int>> &_checked){
  
  int px = ppos.second, py = ppos.first;
  _checked.at(pos.first).at(pos.second) = min(_checked.at(pos.first).at(pos.second), dist);
  dist++;
  //cout << " " << pos.second << " " << pos.first << endl;
  
  for(int i = 0; i < 4; i++){
    int x = pos.second + dx.at(i), y = pos.first + dy.at(i);
    if(y >=0 && x >= 0 && y < H && x < W && dist < _checked.at(y).at(x)){
      
      if(!(x == px && y == py) && S.at(y).at(x) == '.') bfs(P(y, x), pos, dist, _checked);
    }
  }
  
  /*if(mxdist < _checked.at(pos.first).at(pos.second)){
    mxdist = _checked.at(pos.first).at(pos.second);
  }*/
}

int main(){
  
  int i, j;
  cin >> H >> W;
  
  for(i = 0; i < H; i++){
    for(j = 0; j < W; j++){
      
      cin >> S.at(i).at(j);
    }
  }
  
  for(i = 0; i < H; i++){
    for(j = 0; j < W; j++){
      
      vector<vector<int>> checked(H, vector<int>(W, 401));
      if(S.at(i).at(j) == '#') continue;
      bfs(P(i, j), P(-1, -1), 0, checked);
      
      for(int _i = 0; _i < H; _i++){
        for(int _j = 0; _j < W; _j++){
          if(mxdist <= checked.at(_i).at(_j) && checked.at(_i).at(_j) != 401) mxdist = checked.at(_i).at(_j);
        }
      }
      
    }
  }
  cout << mxdist << endl;
}

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

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

  if ((a * b) % 2 == 0 && a >= 0 && b >= 0) {
    cout << "Even" << endl;
  }
  else 
    cout << "Odd" << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	sc := NewScanner()

	a := sc.ReadInt()
	b := sc.ReadInt()
	fmt.Println(a * b)
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

func Ceil(divident, dividor int) int {
	quo := divident / dividor
	rem := divident % dividor

	if rem != 0 {
		if (divident > 0 && dividor > 0) ||
			(divident < 0 && dividor < 0) {
			return quo + 1
		}
	}
	return quo
}

// *   sortutil

func ReverseInts(a []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
}

func ReverseStrings(a []string) {
	sort.Sort(sort.Reverse(sort.StringSlice(a)))
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 1756
#include <stdio.h>

int main()
{
  int i,j,minj,A[100],temp,cnt=0,N;

  scanf("%d",&N);
  for(i=0;i<N;i++) scanf("%d",&A[i]);
  
  for(i=0;i<N-1;i++){
    minj=i;
    for(j=i;j<N;j++){
      if(A[j]<A[minj]){
	minj=j;
      }
    }
    temp=A[i];
    A[i]=A[minj];
    A[minj]=temp;
    if(i!=minj)cnt++;
  } 
 
  for(i=0;i<N-1;i++) printf("%d ",A[i]);
  printf("%d\n%d\n",A[N-1],cnt);

  return 0;
}

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

int main() {
	long a,b,c;
	long ans;
	cin >> a >> b >> c;
	if (a + b >= c) {
		ans = b + c;
	}
	else ans = a + 2*b + 1;

	cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(),v.end()
#define PI acos(-1)

const ll INF = 10010001010;
const int inf = 2000000000;
ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

typedef tuple<string, int, int> TUP;

bool tuplesort(const TUP &right, const TUP &left)
{
    if (get<0>(right) != get<0>(left))
    {
        return get<0>(left) < get<0>(right);
    }
    if (get<1>(left) != get<1>(right))
    {
        return get<1>(left) > get<1>(right);
    }
    return get<2>(left) < get<2>(right);
}

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

int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<char>> S(H,vector<char>(W));
    vector<vector<int>> kiroku(H, vector<int>(W));
    int ans = 0;
    for (int i = 0; i < H;i++)
    {
        for (int j = 0; j < W;j++)
        {
            cin >> S[i][j];
        }
    }
    for (int i = 0; i < H;i++)
    {
        for (int j = 0; j < W;j++)
        {
            if(S[i][j] != '#')
            {
                for (int k = 0; k < H;k++)
                {
                    for (int l = 0; l < W;l++)
                    {
                        kiroku[k][l] = -1;
                    }
                }
                queue<int> que;
                que.push(i);
                que.push(j);
                kiroku[i][j] = 0;
                while (!que.empty())
                {
                    int h = que.front();
                    que.pop();
                    int w = que.front();
                    que.pop();
                    for (int dir = 0; dir < 4;dir++)
                    {
                        int ny = h + dy[dir];
                        int nx = w + dx[dir];
                        if (ny < H && nx < W && ny >= 0 && nx >= 0)
                        {
                            if (S[ny][nx] == '.' && kiroku[ny][nx] == -1)
                            {
                                que.push(ny);
                                que.push(nx);
                                kiroku[ny][nx] = kiroku[h][w] + 1;
                            }
                        }
                    }
                }
                for (int k = 0; k < H; k++)
                {
                    for (int l = 0; l < W; l++)
                    {
                        ans = max(ans, kiroku[k][l]);
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll h, w;
  cin >> h >> w;
  ll cnt = 0;
  rep(i, h) rep(j, w) {
    char a;
    cin >> a;
    if(a == '#') cnt++;
  }
  cout << (cnt == h + w - 1 ? "Possible" : "Impossible") << endl;
}

Measured memory_bytes: 3572
from itertools import product
H, W = list(map(int, input().split()))
S = [input() for _ in range(H)]
ans = S[:]
ans = [list(a) for a in ans]
S = ['.' * (W + 2)] + ['.' + s + '.' for s in S] + ['.' * (W + 2)]
for h, w in product(range(1, H + 1), range(1, W + 1)):
    if S[h][w] == '#':
        continue
    count = 0
    for i, j in product(range(h - 1, h + 2), range(w - 1, w + 2)):
        if (i == h) and (j == w):
            continue
        if S[i][j] == '#':
            count += 1
    ans[h - 1][w - 1] = str(count)
ans = [''.join(a) for a in ans]
[print(a) for a in ans]

Measured memory_bytes: 44016
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const int INF = (1LL<<30);
#else
const ll INF = (1LL<<60);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;
 
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
 
VI g[100010];
int color[100010];
 
bool dfs(int v, int c) {
  color[v] = c;
  for(int i=0; i<g[v].size(); ++i) {
    if(color[g[v][i]] == c) return false;
    if(color[g[v][i]] == 0 && !dfs(g[v][i], -c)) return false;
  }
  return true;
}
 
signed main(void)
{
  int n, m;
  cin >> n >> m;
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].PB(b);
    g[b].PB(a);
  }
 
  REP(i, n) {
    if(color[i] == 0) {
      if(!dfs(i, 1)) {
        cout << n*(n-1)/2 - m << endl;
        return 0;
      }
    }
  }
 
  int black = 0, white = 0;
  REP(i, n) {
    if(color[i] == 1) black++;
    else if(color[i] == -1) white++;
    else assert(false);
  }
 
  int ret = 0;
  REP(i, n) {
    if(color[i] == 1) ret += white - g[i].size();
    else ret += black - g[i].size();
  }
  if(ret%2) assert(false);
  cout << ret/2 << endl;
 
  return 0;
}

Measured memory_bytes: 7424
#include <bits/stdc++.h>
//#include <boost/array.hpp>
//#include <boost/range/numeric.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/multiprecision/cpp_int.hpp>

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
//using namespace boost::multiprecision;

constexpr long long INF = LLONG_MAX;
constexpr long long MOD = 1000000007;
constexpr long double PI = M_PI;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); ++i)
#define RFOR(i,n,r) for(ll i = (ll)(n-1); i >= r; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,0)
#define ALL(x) x.begin(),x.end()
#define CALL(x) x.cbegin(),x.cend()
#define RALL(x) x.rbegin(),x.rend()
#define CRALL(x) x.crbegin(),x.crend()

#define cout cout << fixed << setprecision(12)
#define dbglf cerr << '\n'

#define ACCM(arr) accumulate(ALL(arr),0LL)
#define Yes(ex) cout << ((ex) ? "Yes" : "No") << endl
#define YES(ex) cout << ((ex) ? "YES" : "NO") << endl

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;
using pq = priority_queue<ll>;

template < typename T >
inline void veccin(vector<T>& v) {
    for (auto && e : v) { cin >> e; }
}

template < typename T >
inline void dbg(T a) { cerr << a << ' '; }

ll n, m, k;
ll ans = 0, sum = 0, cnt = 0;
//ld d;
string s/*1, s2, s3*/;
char c/*1, c2, c3*/;
bool flag = false;

/*--------------------template--------------------*/

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

    cin >> n;
	vi a(n); veccin(a);
	vp infos(n,make_pair(0,0));
	REP(i,n){
    	m = a[i];
    	if(i+m<n)(infos[i+m].first)++;
    	if(i-m>=0)(infos[i-m].second)++;
    	//dbg(infos[i].first);
    	//dbg(infos[i].second);
    }
	REP(i,n){
    	sum+=(infos[i].first)*(infos[i].second);
    }
	cout << sum;
}


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

int32_t main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int64_t x, k, d; cin >> x >> k >> d;
    x = abs(x);
    int64_t t = x / d;
    if (t >= k) {
        cout << x - d * k;
    } else {
        x -= t * d;
        k -= t;
        cout << (k%2 ? abs(x - d) : x);
    }
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main()
{
    int a,b, count;
    while( cin >>a>>b ) {
        count = 1;
        a += b;
        while( a > 9 ){
            a /= 10;
            count++;
        }
        cout << count << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 3012
import java.util.*;

public class Main{

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args){
        new Main().run();
    }

    void run() {

        String st = sc.next();

        if (st.equals("ABC")) {
            System.out.println("ARC");
        } else {
            System.out.println("ABC");
        }

    }
}


Measured memory_bytes: 35592
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <string>
#define rep(i,n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	char* S = (char*)calloc(5, sizeof(char));
	cin >> S;
	
	string ans;
	
	char* first = (char*)calloc(3, sizeof(char));
	first[0] = S[0]; first[1] = S[1];
	char* second = (char*)calloc(3, sizeof(char));
	second[0] = S[2]; second[1] = S[3];
	
	int f = atoi(first);
	int s = atoi(second);
	
	if(0 < f && f < 13){
		if(0 < s && s < 13) ans = "AMBIGUOUS";
		else ans = "MMYY";
	}
	else{
		if(0 < s && s < 13) ans = "YYMM";
		else ans = "NA";
	}
	
	cout << ans << endl;
	
}

Measured memory_bytes: 3556