akhauriyash/Code-Regression huggingface dataset:
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <queue>
#include <limits>
#include <deque>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <map>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>
#include <cwchar>
#include <cwctype>
#define mp make_pair
#define fs first
#define se second
#define memset(a,t) memset(a,t,sizeof(a))
#define all(v) v.begin(),v.end()
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define MN 0LL
#define Mx 2000000005
#define Mn -Mx
#define MX 20000000000000005
using namespace std;
int readint(){
	char c;
	while(c=getchar(),(c<'0'||c>'9')&&c!='-');
	bool flag=(c=='-');
	if(flag)c=getchar();
	int x=0;
	while(c>='0'&&c<='9'){
		x=x*10+c-48;
		c=getchar();
	}
	return flag?-x:x;
}
inline string tos(int x){
	string s;
	while(x) s=(char)(x%10+'0')+s,x/=10;
	return s;
}
map<unsigned long long,unsigned long long> a;
vector<unsigned long long> v;
vector<unsigned long long> t;
int main(){
	ios_base::sync_with_stdio(false);
	unsigned long long n,x,ans,i,j;
	cin>>n;
	for(i=0;i<n;i++) cin>>x,a[x]=a[x]+1,t.push_back(x);
	for(i=0;i<t.size();i++) if(a[t[i]]>1) v.push_back(t[i]);
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	if(v.size()<4){
		cout<<0<<endl;
		return 0;
	}
	for(i=0;i<v.size()-1;i++) if(v[i]==v[i+1]) break;
	if(i==v.size()-1){
		cout<<0<<endl;
		return 0;
	}
	for(j=i+2;j<v.size()-1;j++) if(v[j]==v[j+1]) break;
	if(j==v.size()-1){
		cout<<0<<endl;
		return 0;
	}
	cout<<v[i]*v[j]<<endl;
	return 0;
//	if(ans<=0) exit(11234)
}
 


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

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

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

  cout << b * (t / a) << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
long N = sc.nextInt();
long m = 0;
long a = 0;
long r = 0;
long c = 0;
long h = 0;

String name;
for(int i = 0;i<N;i++){
name = sc.next();
if(name.startsWith("M")){
m++;
}else if(name.startsWith("A")){
a++;
}else if(name.startsWith("R")){
r++;
}else if(name.startsWith("C")){
c++;
}else if(name.startsWith("H")){
h++;
}
}
long ans;
ans = m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h;
              System.out.println(ans);
    }
}


Measured memory_bytes: 45360
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    #
    n, m = map(int, input().strip().split())
    n_AC = 0
    n_penalty = 0
    l_penalty = [0 for _ in range(n)]
    l_status = [-1 for _ in range(n)]

    #
    for i in range(m):
        id, res = input().strip().split()
        id = int(id) - 1
        if res == "AC" and l_status[id] == -1:
            n_penalty += l_penalty[id]
            l_status[id] = 1
            n_AC += 1
        else:  # res == "WA"
            l_penalty[id] += 1

    #
    print(n_AC, n_penalty)


if __name__ == '__main__':
    main()


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

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

    int n;
    long long m;
    cin >> n >> m;
    vector<long long> A(n);
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }

    map<long long, long long> mp;
    mp[0]++; // 重要
    long long tmp = 0;
    for(int i = 0; i < n; i++){
        tmp += A[i];
        mp[tmp % m]++;
    }

    long long ans = 0;
    for(auto x: mp){
        ans += x.second * (x.second - 1) / 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4992
from functools import lru_cache
h = int(input())
count = 0

while h > 1:
  h = h//2
  count +=1

@lru_cache(maxsize=100000)
def f(n):
    if n < 1:
        return 1
    else:
        return f(n - 1)*2 + 1

print(f(count))

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()

int A[5], K;

string solve() {
    if (A[4]-A[0] > K) return ":(";
    return "Yay!";
}

int main() {
    REP (i, 5) cin >> A[i];
    cin >> K;
    cout << solve() << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int s = sc.nextInt();
    int w = sc.nextInt();
    if(w>=s){
      System.out.println("unsafe");
    }
    else{
      System.out.println("safe");
    }
  }
}
            

Measured memory_bytes: 35504
s = raw_input()

x = int(s[0:2])
y = int(s[2:])

yymm = 0
mmyy = 0

if y > 0 and y <= 12:
    yymm = 1

if x > 0 and x <= 12:
    mmyy = 1

if mmyy and yymm:
    print "AMBIGUOUS"
elif mmyy:
    print "MMYY"
elif yymm:
    print "YYMM"
else:
    print "NA"

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

using namespace std;

int main(){
	while(true){
		int m,f,r;
		cin >> m >> f >> r;
		if(m==-1 && f==-1 && r==-1)break;
		if(m==-1 || f==-1){
			cout << "F" << endl;
			continue;
		}
		int score=m+f;
		if(score>=80){
			cout << "A" << endl;
		}
		else if(score>=65){
			cout << "B" << endl;
		}
		else if(score>=50){
			cout << "C" << endl;
		}
		else if(score>=30){
			if(r>=50) cout << "C" << endl;
			else cout << "D" << endl;
		}
		else cout << "F" << endl;
	}

	return 0;
}

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

struct node {
  array<node *, 26> ch;
  array<int, 26> cnt;
};

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n;
  cin >> n;
  vector<string> s(n);
  for (auto&& e : s) {
    cin >> e;
    reverse(begin(e), end(e));
  }
  sort(begin(s), end(s), [](auto&& a, auto&& b) {
    return size(a) > size(b);
  });
  auto res = 0LL;
  auto trie = new node();
  for (auto&& e : s) {
    vector<int> rest(26);
    for (char c : e) {
      ++rest[c - 'a'];
    }
    int sz = size(e);
    auto ptr = trie;
    for (int i = 0; i < sz; ++i) {
      if (i == sz - 1) {
        res += ptr->cnt[e[i] - 'a'];
      }
      for (int x = 0; x < 26; ++x) {
        ptr->cnt[x] += rest[x] >= 1;
      }
      --rest[e[i] - 'a'];
      auto&& nxt = ptr->ch[e[i] - 'a'];
      if (nxt == nullptr) {
        nxt = new node();
      }
      ptr = nxt;
    }
  }
  cout << res << '\n';
}


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

int main(void){
  string x,y,z;
  cin >> x >> y >> z;
  if(x[x.length()-1] == y[0] && y[y.length()-1] == z[0]){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
ll mod=1e9+7;
#define PI acos(-1)
struct edge{int from, to;};

char dp[INT_MAX];
int main(){
    int n,k;
    cin>>n>>k;
    int R,S,P;
    cin>>R>>S>>P;
    string t;
    cin>>t;
    int score=0;
    for(int i=0;i<n;i++){
        if(i<k){//k以下は勝つ
            if(t[i]=='r') {
              score+=P;
              dp[i]='p';
            }
            else if(t[i]=='s') {
              score+=R;
              dp[i]='r';
            }
            else if(t[i]=='p'){
              score+=S;
              dp[i]='s';
            }
        }
        else{//iがk以上
            if(t[i]=='r'){//相手がグーで
                if(dp[i-k]!='p') {//k回前の手がパーじゃなかったら
                    score+=P;
                    dp[i]='p';
                }
                else dp[i]='x';
            }
            else if(t[i]=='s'){
                if(dp[i-k]!='r') {
                    score+=R;
                    dp[i]='r';
                }
                else dp[i]='x';
            }
            else if(t[i]=='p'){
                if(dp[i-k]!='s') {
                    score+=S;
                    dp[i]='s';
                }
                else dp[i]='x';
            }
        }
    }
    //rep(i,n)cout<<dp[i]<<" ";
    cout<<score<<endl;
    return 0;
}

Measured memory_bytes: 512
n=int(input())
K=int(input())
if K==1:
    counter=0
    for i in range(100):
        for j in range(1,10):
            a="0"*(i)+str(j)+"0"*(99-i)
            if 1<=int(a)<=n:
                counter+=1
    print(counter)
elif K==2:
    counter=0
    for i in range(100):
        for j in range(i+1,100):
            for k in range(1,10):
                for l in range(1,10):
                    a="0"*(i)+str(k)+"0"*(j-i-1)+str(l)+"0"*(99-j)
                    if 1<=int(a)<=n:
                        counter+=1
    print(counter)
elif K==3:
    counter=0
    for i in range(100):
        if 100-i>len(str(n)):
            pass
        elif 100-i<len(str(n)):
            for j in range(i+1,100):
                for k in range(j+1,100):
                    counter+=9*9*9
        elif 100-i==len(str(n)):
            for j in range(i+1,100):
                for k in range(j+1,100):

                        for b in range(1,10):
                            for c in range(1,10):
                                P=(str(n)[0])+"0"*(j-i-1)+str(b)+"0"*(k-j-1)+str(c)+"0"*(99-k)
                                if 1<=int(P)<=n:
                                    counter+=1
            counter+=((98-i)*(99-i)//2)*9*9*(int(str(n)[0])-1)
    print(counter)
                    


                    


Measured memory_bytes: 3188
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        
           int i ;
           int s ;
           int dog = 0;
           for(i = 0 ; i<10;i++){
               s = scan.nextInt();
               dog += s;
           }
           System.out.println(dog);

        }

    }




Measured memory_bytes: 26152
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


const ll INF = 1e16;

int main(){
    ll n,m;
    cin >> n >> m;
    vector<P>drink(n);
    rep(i,n){
        P p;
        ll a,b;
        cin >> a >> b;
        p=make_pair(a,b);
        drink[i]=p;
    }
    sort(drink.begin(),drink.end());
    ll cost=0;
    ll now = 0;
    int i=0;
    while(1){
        if(drink[i].second+now<m){
            cost+=drink[i].first*drink[i].second;
            now+=drink[i].second;
        }
        else{
            cost+=(drink[i].first*(m-now));
            cout << cost << endl;
            return 0;
        }
        i++;
    }
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
void f(long long int S,long long int &X,long long int k){
  X+=S;
  int a=10,b=1;
  for(int i=1;i<k;i++){
    X+=S/a*b;
    f(S%a,X,i);
    a*=10;
    b*=2;
  }
}
int main(){
  long long int S,X,i=0;
  cin>>S;
  X=S;
  while(X!=0)i++,X/=10;
  f(S,X,i);
  cout<<X<<endl;
}

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

using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
constexpr ll M2 = 998244353;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) { return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M; }
inline ll sum_1(const ll i, const ll j) { return (sum_1(j) - sum_1(i - 1) + M) % M; }
inline ll sum_2(const ll i, const ll j) { return (sum_2(j) - sum_2(i - 1) + M) % M; }
inline ll sum_3(const ll i, const ll j) { return (sum_3(j) - sum_3(i - 1) + M) % M; }

ll pow_f(ll b, ll e) {
    ll ans = 1;
    b = b % M;
    while (e) {
        if (e&1) {
            ans = (ans * b) % M;
        }
        b = (b * b) % M;
        e >>= 1;
    }
    return ans;
}

ll nCr(ll n, ll r) {
    if (r > n || n < 0 || r < 0) { return 0; }
    if (n == r || r == 0) { return 1; }
    r = min(r, n-r);
    ll ans = 1;
    for (ll i = 1; i <= r; ++i) {
        ans = (ans * (n-i+1))/(i); 
    }
    return ans;
}

ll nCr(tuple<ll,ll> t) {
    auto n = get<0>(t);
    auto k = get<1>(t);
    return nCr(n+k-1, k);
}

template<typename T>
void print(T v) {
    cout << v << " ";
}

template<typename T>
void print(vector<T> v) {
    for (auto &i : v) {
        print(i);
    }
    cout << endl;
}

void solve() {
    ll n, s;
    cin >> n >> s;

    vector<ll> A(n);
    for (auto &i : A) {
        cin >> i;
    }

    vector<vector<ll>> dp(n, vector<ll>(s+1, 0));
    vector<vector<ll>> pre(n, vector<ll>(s+1, 0));

    //Base
    for (int i = 0; i < n; ++i) {
        if (A[i] <= s) {
            dp[i][A[i]] = i+1;
            pre[i][A[i]] = i+1;
        }
    }

    //fill
    for (int i = 1; i < n; ++i) {
        for (ll j = 0; j <= s; ++j) {
            if (j-A[i] <= s && j-A[i] >= 0)
                dp[i][j] = (dp[i][j] + pre[i-1][j-A[i]]) % M2;
            pre[i][j] = (pre[i-1][j] + dp[i][j]) % M2;
        }
    }

    // print(dp);   

    ll ans = 0;
    for (ll i = 0; i < n; ++i) {
        ans = (ans + (dp[i][s]*(n-i)) % M2) % M2;
    }

    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifdef D_LOCAL
        freopen("in.in", "r", stdin);
        freopen("out.out", "w", stdout);
    #endif

    solve();

    return 0;
}

Measured memory_bytes: 141184
#include <iostream>

int main()
{
  int A,B,C,ans;
  std::cin >> A >> B >> C;
  if(A!=B) 
  {
  ans = A;
  if(B!=C)
  {
  ans = B;
  }
  }else if(A!=C)
  {
  ans = C;
  }

  std::cout << ans << std::endl;
}

Measured memory_bytes: 256
"use strict";
function Main(input) {
    let cin = new Inputer(input);
    let N = cin.getInt(), A = cin.getIntArray(N);
    let dp = new Array(N + 1).fill(0).map(() => new Array(2).fill(-1e10));
    dp[0][0] = 0;
    for (let n = 0; n < N; n++) {
        dp[n + 1][0] = Math.max(...[dp[n + 1][0], dp[n][0] + A[n], dp[n][1] - A[n]]);
        dp[n + 1][1] = Math.max(...[dp[n + 1][1], dp[n][0] - A[n], dp[n][1] + A[n]]);
    }
    console.log(dp[N][0]);
}
class Inputer{constructor(t){if(typeof t=='undefined')throw new Error('引数（stdin）を省略できません！');this.cnt=0,this.items=t.split(/\n|\s/)}getInt(){return this.items[this.cnt++]-0}getIntArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getInt();return r}getStr(){return this.items[this.cnt++]}getStrArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getStr();return r}}
if (typeof window == "undefined") Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 56936
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=1e9+7;
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(){
  ll h,w;
  cin>>h>>w;

  ll ans=0;

  if(h%2){
    ans=((w+1)/2+w/2)*(h/2)+(w+1)/2;
  }
  else
    ans=((w+1)/2+w/2)*(h/2);

  if(w==1 || h==1) ans=1;


  cout<<ans<<endl;
}


Measured memory_bytes: 256
def d(s):
    try:
        assert s[0] == 'A'
        assert s[2:-1].count('C') == 1
        assert s[1:].count('C') == 1
        cs = set(s[1:]) - {'C'}
        assert 'a' <= min(cs)
        assert max(cs) <= 'z'
    except AssertionError:
        return False
    else:
        return True


s = raw_input()
if d(s):
    print 'AC'
else:
    print 'WA'


Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    int n, m;
    cin >> n >> m;
    string ans = "No";
    if (n == m) {
        ans = "Yes";
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  char boin[5]={'a','i','u','e','o'};
  char c; cin>>c;
  for(int i=0;i<5;i++){
    if(c==boin[i]){
      cout<<"vowel"<<endl;
      return 0;
    }
  }
  
  cout<<"consonant"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const int INF = 2000000000;

    int H,W;
    string S[51];
    int dx[]={1,-1,0,0,1,1,-1,-1};
    int dy[]={0,0,1,-1,1,-1,1,-1};
    char A[51][51];
int main(){
    ios_base::sync_with_stdio(false);
    cin>>H>>W;
    REP(i,H)cin>>S[i];
    REP(i,H)REP(j,W){
        DEB(i)DEB(j)
        int cnt=0;
        if(S[i][j]=='#'){
            A[i][j]='#';
            continue;
        }else{
            REP(k,8){
                int a=i+dy[k],b=j+dx[k];
                if(a<0||b<0||a>=H||b>=W)continue;
                if(S[a][b]=='#')cnt++;
            }
            DEB(cnt)
            A[i][j]=cnt+'0';


        }
        DEB(A[1][1])END
    }
    REP(i,H){REP(j,W){cout<<(S[i][j]=='#'?'#':A[i][j]);}cout<<endl;}
    return 0;
}


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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 63;

LL l, r;
int al[MAXN], ar[MAXN];

void init ();
void input ();
void work ();



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method
	
	cin >> l >> r;
}

void work ()
{
	// main work
	
	if ( l == r ){
		printf ( "1\n" );
		return;
	}
	
	lp ( i, 0, MAXN ) al[i] = l >> i & 1, ar[i] = r >> i & 1;
	
	int n;
	lpdi ( i, MAXN-1, 0 ){
		if ( al[i] ^ ar[i] ){
			n = i;
			break;
		}else{
			if ( al[i] ) l ^= 1LL << i, r ^= 1LL << i, al[i] = ar[i] = 0;
		}
	}
	
	LL ans = ( 1LL << n ) - l;
	int di = 0;
	lpdi ( i, n-1, 0 ){
		if ( !al[i] ){
			ans += 1LL << i;
		}else{
			di = i + 1;
			break;
		}
	}
	
	if ( r >= ( 1LL << n ) + ( 1LL << di ) ){
		ans += 1LL << di;
	}else{
		int ti = -1;
		lpdi ( i, di-1, 0 ){
			if ( ar[i] ){
				ti = i;
				break;
			}
		}
		++ti;
		ans += qmin ( ( ( 1LL << di ) - l ) + ( 1LL << ti ), 1LL << di );
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(ll i = (ll)(n)-1;i >= 0;--i)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
//#define int ll
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
vvl dp;
vl w,v;
ll W;
ll n;
signed main(){
  cin >> n >> W;
  w.resize(n);
  v.resize(n);
  REP(i,n) cin >> w[i] >> v[i];
  ll sum = accumulate(ALL(v),0LL);
  dp.assign(n+1,vl(sum+1,LLONG_MAX/2));
  dp[0][0] = 0;
  REP(i,n)REP(j,sum+1){
    if(j<v[i]) {
      dp[i+1][j] = dp[i][j];
      continue;
    }
    dp[i+1][j] = min(dp[i][j],dp[i][j-v[i]]+w[i]);
  }
  RREP(i,sum+1){
    if(dp[n][i]<=W){
      cout << i << endl;
      break;
    }
  }
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF 2147483647//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    int ax,ay,bx,by;
    cin >> ax >> ay >> bx >> by;
    int dis_x_ab = bx-ax;
    int dis_y_ab = by-ay;
    cout << bx-dis_y_ab << " " << by + dis_x_ab << " " << ax-dis_y_ab << " " << ay+dis_x_ab;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long

const int N=1005;
const int MOD=1e9+7;
int power(int a,int b)
{
	if(b==0)
	{
		return 1;
	}
	int ans=power(a,b/2);
	ans=ans*ans;
	if(b%2==0)
	{
		ans=ans;
	}
	else
	{
		ans=ans*a;
	}
	return ans;
}
int32_t main()
{
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 int n;
 cin>>n;
 int t=n;
 int count=0;
 while(n!=0)
 {
 	count++;
 	n=n/2;
 }
 
 int b=power(2,count);
 //cout<<b<<endl;
 
 int c=b-1;
 cout<<c;
 int z=(t*2*c)/b;
 
 //cout<<z;

}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n,m,i,j,taro[100],hanako[100];
  int sum_taro,sum_hanako,min,ansTaro,ansHanako;
  while(1){
    min = 201;
    sum_taro = sum_hanako = 0;
    scanf("%d%d",&n,&m);
    if(n == 0 && m == 0){ break; }
    for(i = 0 ; i < n ; i++){
      scanf("%d",&taro[i]);
      sum_taro += taro[i];
    }
    for(i = 0 ; i < m ; i++){
      scanf("%d",&hanako[i]);
      sum_hanako += hanako[i];
    }

    for(i = 0 ; i < n ; i++){
      for(j = 0 ; j < m ; j++){
        if(sum_taro-taro[i]+hanako[j] == sum_hanako-hanako[j]+taro[i]){
          if(taro[i]+hanako[j] < min){
            min = taro[i]+hanako[j];
            ansTaro = taro[i];
            ansHanako = hanako[j];
          }
        }
      }
    }
    if(min == 201){
      printf("-1\n");
    }else{
      printf("%d %d\n",ansTaro,ansHanako);
    }
  }
  return 0;
}

Measured memory_bytes: 612
#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 a, b, c, d;
    cin >> a >> b >> c >> d;

    int x = c / b;
    if (c%b!=0) x++;

    int y = a / d;
    if (a%d!=0) y++;

    if (x<=y) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int pasta[3];
  int juce[2];

  for(int i = 0;i < 3;i++)cin >> pasta[i];
  for(int i = 0;i < 2;i++)cin >> juce[i];

  sort(pasta,pasta + 3);
  sort(juce,juce + 2);
  
  int ans = pasta[0] + juce[0] - 50;
  cout << ans << endl;
}

Measured memory_bytes: 1176
import math
N=int(input())
A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())
x=[A,B,C,D,E]
mi=A
for i in range(5):
 if mi<x[i]:
  x[i]=mi
 else:
  mi=x[i]
print(math.ceil(N/mi)+4)

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
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;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
struct UnionFind {
  vll par ;  //iの親
  vll rank ; //木の深さ
  vll siz ; //iの属する集合の要素数
  
  //n要素の初期化
  void init(int n){
    REP(i,n){
      par.PB(i) ;
      rank.PB(0) ;
      siz.PB(1) ;
    }
  }
  
  //木の根を求める
  //根が一緒なら同じ集合と判断するため
  int find(int x){
    if(par[x]==x){
      return x ;
    }
    else{
      return par[x] = find(par[x]) ;
    }
  }
  
  //木の併合
  //記録してあるrankをもとに併合
  void unite(int x,int y){
    x = find(x) ;
    y = find(y) ;
    if(x==y){
      return ;
    }
    
    if(rank[x] < rank[y]){
      par[x] = y ;
      siz[y] += siz[x] ;
    }
    else{
      par[y] = x ;
      siz[x] += siz[y] ;
      if(rank[x]==rank[y]){
        rank[x]++ ;
      }
    }
  }
  
  //xとyが同じ集合に属するか
  bool same(int x,int y){
    return find(x) == find(y) ;
  }
  
  //iが根であるかを返す
  bool root(int x){
    return x==find(x) ;
  }
    
  
  //xの属する集合の要素数を返す
  ll size(int x){
    return siz[find(x)] ;
  }
  
  //グラフ全体で何個の集合があるか返す
  ll cnt(int n){
    ll res = 0 ;
    REP(i,n){
      if(i==find(i)){
        res++ ;
      }
    }
    return res ;
  }
  
};
//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, m;
    cin >> n >> m;
    vll p(n);
    vpll pai(n);
    REP(i,n){
        ll q;
        cin >> q;
        q--;
        p[i] = q;
        pai[i] = MP(i,q);
    }
    UnionFind tree;
    tree.init(n);
    REP(i,m){
        ll x, y;
        cin >> x >> y;
        x--;
        y--;
        tree.unite(x,y);
    }
    ll ans = 0;
    REP(i,n){
        ll fi = pai[i].FI;
        ll se = pai[i].SE;
        if(tree.same(fi,se)){
            ans++;
        }
    }

    cout << ans <<endl;



    
    return 0;
}



Measured memory_bytes: 8176
#include<stdio.h>

int dp[50];

int fib(int n) {
	if ( n == 0 || n == 1 ) return dp[n] = 1;
	if( dp[n] != -1 ) return dp[n];
	return dp[n] = fib(n - 1) + fib(n - 2);
}

int main() {
	int n, i;
	for ( i = 0; i < 50; i++ ) dp[i] = -1;
	
	scanf("%d", &n);
	printf("%d\n", fib(n));
	
	return 0;
}


Measured memory_bytes: 2144
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main(){
  int a = 0;
  cin >> a;
  int b = 0;
  int c = 0;
  int d = 0;
  while(d == 0){
    for(int i = 2;i <= (int)pow(a,0.5);i++){
      if(a % i == 0){
        b = 1;
      }
    }
    if(b == 0){
      c = a;
      d = 1;
    }
    a++;
    b = 0;
  }
  cout << c << endl;
  return 0;
}
  

Measured memory_bytes: 512
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  if(n == 1) cout << m << endl;
  else{
    int k = m / n;
    for(int i = k; i >= 1; i--){
      if(m % i == 0){
        cout << i << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	string s = readln.chomp;
	
	long ans;
	string old = "", now = "";
	foreach(c; s){
		now ~= c;
		if(now != old){
			ans += 1;
			old = "" ~ now;
			now = "";
		}
		log("old:", old, "now:", now, "ans:", ans);
	}

	ans.writeln;

}

/*
	long n = read.to!long;
	long m = read.to!long;
	long k = read.to!long;

	long a = read.to!long;
	long b = read.to!long;
	
	long x = read.to!long;
	long y = read.to!long;
	long z = read.to!long;

	long[] as;
	foreach(i; 0 .. n) as ~= read.to!long;

	long[] bs;
	foreach(i; 0 .. n) bs ~= read.to!long;

	long[] as;
	foreach(j; 0 .. m) as ~= read.to!long;

	long[] bs;
	foreach(j; 0 .. m) bs ~= read.to!long;
	
	struct S{
		long a, b;
	}
	S[] xs;
	foreach(i; 0 .. n) xs ~= S(read.to!long, read.to!long);

*/


Measured memory_bytes: 3512
W, a, b = map(int, input().split())
result = 0
if ((a <= b) and (b <= a + W)) or ((a <= b + W) and (b + W <= a + W)):
  result = 0
elif (b + W < a):
  result = a - (b + W)
elif (a + W < b):
  result = b - (a + W)
print(result)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
void File(){
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
}
#define REP(i,a,b) for(register int i=a;i<=b;++i)
#define DREP(i,a,b) for(register int i=a;i>=n;--i)
#define ll long long
const int maxn=1e6+10;
ll n,a,b;
int s[maxn];
int main(){
	//File();
	cin>>n>>a>>b;
	if(n>a*b || n<a+b-1)
		cout<<-1<<endl;
	else{
		REP(i,1,a)s[i]=n-a+i;
		if(b!=1){
			ll unit=(n-a)/(b-1),res=(n-a)%(b-1);
			int p=a,from=n-a-unit+1,last=n-a;
			while(p!=n){
				if(res)--res,--from;
				REP(i,from,last)
					s[++p]=i;
				last=from-1;
				from=from-unit;
			}
		}
		REP(i,1,n)cout<<s[i]<<" ";
	}
	return 0;
}


Measured memory_bytes: 3328
#i = 0
N = int(input())
list = [int(input()) for i in range(N)]

list.sort(reverse = True)

j = 0
cnt = 1
temp = list[0]

for j in range(N):
    if(temp > list[j]):
        temp = list[j]
        cnt = cnt + 1

print(cnt)


Measured memory_bytes: 3060
a, b = map(int, input().split())
c = 2
d = []
while c > 0:
    if a > b :
        d.append(a)
        a -= 1
        c -= 1
    else:
        d.append(b)
        b -= 1
        c -= 1
print(d[0] + d[1])

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

using namespace std;

using int64 = long long;

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

  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int d = j - i;
      int l = 1;
      while (d % 2 == 0) {
        d /= 2;
        l++;
      }
      cout << l << " ";
    }
    cout << endl;
  }
}

Measured memory_bytes: 512
def gcd(a, b):
	if a > b:
		a, b = b, a
	if a % b == 0:
		return b
	while a % b != 0:
		c = a% b
		a = b
		b = c
	else:
		return c

def lcmCalc(x, y):
	return (x * y) // gcd(x, y)

n, m = map(int, input().split())
s = input()
t = input()

lcm = lcmCalc(n, m)

# str1 = ""
# for i in range(lcm):
# 	str1 += "-"

flg = 0
for i in range(n):
	index = i * lcm // n + 1
	if (index - 1) % (lcm // m) == 0:
		j = (index - 1) // (lcm // m)
		if s[i] != t[j]:
			print("-1")
			flg = 1
			break
if flg == 0:
	print(lcm)


# 	str1 = str1[:index] + s[i] + str1[index+1:]

# flg = 0
# for i in range(m):
# 	index = i * lcm // m + 1
# 	if str1[index:index+1] != "-" and str1[index:index+1] != t[i]:
# 		print("-1")
# 		flg = 1
# 		break

# if flg == 0:
# 	print(lcm)

Measured memory_bytes: 40304
#include <iostream>
using namespace std;
/*# coding: utf-8
# Here your code !
(a,b,c)=map(int,raw_input().split())
ans=0;
for i in range(a,b+1):
    if c%i==0:
        ans+=1
print ans
*/
int main(void){
    // Here your code !
    int a,b,c;
    cin>>a>>b>>c;
    int ans = 0;
    for(int i = a; i<=b; i++){
        if(c%i == 0){
            ans++;
        }
    }
    cout<<ans<<endl;
}


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

int main(){
    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    
    std::vector<int>test={a,b,c,d,e};
    
   if(test.at(0)==0){
       cout<<"1"<<endl;
   }
   else if(test.at(1)==0){
       cout<<"2"<<endl;
   }
   else if(test.at(2)==0){
       cout<<"3"<<endl;
   }
   else if(test.at(3)==0){
       cout<<"4"<<endl;
   }
   else{
       cout<<"5"<<endl;
   }
}

Measured memory_bytes: 3596
X,Y,Z,K = map(int,input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A = sorted(A, reverse = True)
B = sorted(B, reverse = True)
C = sorted(C, reverse = True)

ans = []

for i in range(min(K,X)):
  for j in range(min(K//(i+1),Y)):
    for k in range(min(K//(i+1)//(j+1),Z)):
      ans.append(A[i]+B[j]+C[k])
    
ans = sorted(ans, reverse=True)

for i in range(K):
  print(ans[i])

Measured memory_bytes: 9564
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A=sc.nextInt();
		int B=sc.nextInt();
		int T=sc.nextInt();
		sc.close();

		int cnt=T/A;
		int ans=B*cnt;

		System.out.println(ans);

	}
}

Measured memory_bytes: 35820
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

signed main() {
  ll N;
  cin >> N;

  map<P, ll> m;

  rep(i, N + 1) {
    if (i == 0) {
      continue;
    }
    ll keta = getDigit(i);
    ll left = i / (pow(10, keta - 1));
    ll right = i % 10;
    m[{left, right}]++;
  }

  ll sum = 0;
  rep(i, 10) {
    if (i == 0) {
      continue;
    }
    rep(j, 10) {
      if (j == 0) {
        continue;
      }
      P p1 = {i, j};
      P p2 = {j, i};
      sum += m[p1] * m[p2];
    }
  }
  COUT(sum);

  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef pair<double,int> PDI;
const double eps=1e-12;
const int INF=0x3f3f3f3f;
const LL inf=1e18;
const double pi=acos(-1.0);
const int mod=1e9+7;
//LL powmod(LL a,LL b) {LL res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
map<char,int>p;
int a[2][55];
int g[55][55];
LL dp[60][3][3];
int main(){
//    freopen("in.txt","r",stdin);
//    freopen("outt.txt","w",stdout);
    int n;
    string s1,s2;
    cin>>n>>s1>>s2;
    int cnt=0;
    for(int i=0;i<n;i++){
        if(!p[s1[i]]){
            p[s1[i]]=++cnt;
        }
        a[0][i]=p[s1[i]];
        if(!p[s2[i]]){
            p[s2[i]]=++cnt;
        }
        a[1][i]=p[s2[i]];
    }
    for(int i=0;i<n;i++){
        g[a[0][i]][a[1][i]]=g[a[1][i]][a[0][i]]=1;
        if(i){
            g[a[0][i-1]][a[0][i]]=g[a[0][i]][a[0][i-1]]=1;
            g[a[1][i-1]][a[1][i]]=g[a[1][i]][a[1][i-1]]=1;
        }
    }
    for(int i=0;i<3;i++){
        dp[1][i][0]=1;
    }
    for(int i=2;i<=cnt;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j==k&&g[i-1][i-2]) continue;
                for(int l=0;l<3;l++){
                    if(l==j&&g[i][i-2]) continue;
                    if(l==k&&g[i][i-1]) continue;
                    dp[i][l][k]+=dp[i-1][k][j];
                    dp[i][l][k]%=mod;
                }
            }
        }
    }
    LL ans=0;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            ans+=dp[cnt][i][j];
            ans%=mod;
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <map>
#define mp make_pair
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
int main()
{
	while (true) {
		int n; scanf("%d", &n); if (n == 0) break;
		pair<double, int> best = mp(99999999, 99999999);
		rep(i, n) {
			int k, h, w; scanf("%d%d%d", &k, &h, &w);
			double bmi = 10000 * w / ((double)h * h);
			pair<double, int> t = mp(fabs(22.0 - bmi), k);
			if (best > t) best = t;
		}
		printf("%d\n", best.second);
	}
	return 0;
}

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

#define D_MAX 1000000000
#define N_MAX 100000
#define M_MAX 10000
#define min(x,y) (((x)<(y))?(x):(y))

int d;
int n;
int m;

int ad[N_MAX+1];
int ak[M_MAX+1];

void MergeSort(int array[],int left,int right){
  int awork[N_MAX+1];
  int mid;
  int i;
  int j;
  int x;
  int y;
  
  if( left >= right ){
    return;
  }
  
  mid = (left + right) / 2;
  MergeSort( array, left, mid);
  MergeSort( array, mid+1, right);
  
  for( i=left; i<=mid; i++){
    awork[i] = array[i];
  }
  
  j = right;
  for( i=mid+1; i<=right; i++){
    awork[i] = array[j];
    j--;
  }
  
  x = left;
  y = right;
  
  for( i=left; i<=right; i++){
    if(awork[x] <= awork[y]){
      array[i] = awork[x];
      x++;
    }else{
      array[i] = awork[y];
      y--;
    }
  }
}


int calcDist(void){
  int i;
  int j = 1;
  int sum = 0;;
  int minDist = d;
  
  for( i=1; i<=m; i++){
    while(ad[j] < ak[i]){
      j++;
    }
    minDist = min( ak[i]-ad[j-1],ad[j]-ak[i] );
    sum += minDist;
  }
  return sum;
}


void input(void){
  int i;
  scanf("%d",&d);
  if( d != 0){
    scanf("%d",&n);
    scanf("%d",&m);
    ad[0] = 0;
    for( i=1; i<=n-1; i++){
      scanf("%d",&ad[i]);
    }
    ad[n] = d;
    for( i=1; i<=m; i++){
      scanf("%d",&ak[i]);
    }
  }
}

int main(void){
  int i;
  int sumDist = 0;
  while( 1 ){
    input();
    if( d == 0 ){
      break;
    }
    MergeSort( ad, 0, n);
    MergeSort( ak, 1, m);
    sumDist = calcDist();
    printf("%d\n",sumDist);
    sumDist = 0;
  }
}




Measured memory_bytes: 8764
import numpy as np
N , W = map(int, input().split())
goods = np.array([list(map(int , input().split())) for _ in range(N)])
dp = np.zeros((N + 1 , W + 1) , dtype = np.int)

for i in range(0,N):
    w, v = goods[i,:]
    dp[i + 1, w:] = np.maximum(dp[i,w:] , dp[i,:-w] + v)
    dp[i + 1, :] = np.maximum(dp[i + 1,:],dp[i,:])
print(int(dp[N,W]))

Measured memory_bytes: 92724
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;
 
int main() {
    int n, m;
    cin >> n >> m;

    vector<int> num(n, 1), red(n);
    
    red[0] = 1;
    rep(i, m) {

        int x, y;
        cin >> x >> y;
        x--;  y--;
        num[x]--;  num[y]++;

        if(red[x]) {
            red[y] = 1;
        }

        if(num[x] == 0) {
            red[x] = 0;
        }

    }

    int ans = 0;
    rep(i, n) {
        if(red[i]) {
            ans++;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#if 0

#endif

#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void p(A a){cout << (a) << endl;}
template<class A,class B>void p(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void p(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void p(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for copy
// for(int i=0;i<N;++i) {

int main(void) {
  string s;cin>>s;
  string yy = s.substr(0,2);
  string mm = s.substr(2,2);
  int a = stoi(yy);
  int b = stoi(mm);
  if(b <= 12 && b >= 1) {
    if(a <= 12 && a >= 1) {
      p("AMBIGUOUS");
    } else {
      p("YYMM");
    }
  } else {
    if(a <= 12 && a >= 1) {
      p("MMYY");
    } else {
      p("NA");
    }
  }
  return 0;
}



Measured memory_bytes: 256
// 5_abc141_e
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

vector<int> z_algorithm(string s){
    int n = s.length();
    int l = 0, r = 0;
    vector<int> z(n);

    z[0] = n;
    for(int i = 1; i < n; i++){
        if(i > r){
            l = r = i;
            while(r < n && s[r - l] == s[r]) r++;
            z[i] = r - l;
            r--;
        }else{
            int k = i - l;
            if(z[k] < r - i + 1){
                z[i] = z[k];
            }else{
                l = i;
                while(r < n && s[r - l] == s[r]) r++;
                z[i] = r - l;
                r--;
            }
        }
    }

    return z;
}

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

    int n;
    cin >> n;
    string s;
    cin >> s;

    int ans = 0;
    rep(i, n){
        string t = s.substr(i, n - i);
        vector<int> z = z_algorithm(t);
        for(int j = 1; j < n - i; j++){
            if(z[j] > j) z[j] = j;
            ans = max(z[j], ans);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256