akhauriyash/Code-Regression huggingface dataset:
from bisect import bisect_left, bisect_right
N = int(input())
A = sorted([int(i) for i in input().split()])
B = sorted([int(i) for i in input().split()])
C = sorted([int(i) for i in input().split()])
# N = 6
# A = sorted([int(i) for i in '3 14 159 2 6 53'.split()])
# B = sorted([int(i) for i in '58 9 79 323 84 6'.split()])
# C = sorted([int(i) for i in '2643 383 2 79 50 288'.split()])
res = 0
for b in B:
    res += bisect_left(A, b) * (N -bisect_right(C, b))
print(res)

Measured memory_bytes: 23092
#include <bits/stdc++.h>
#include <map>
 #define rep(i,n) for(int i=0;i<n;i++)
 using namespace std;
  int main(){
      int x,y,z;
      cin >> x >> y >> z;
      int ans = 0;
      ans = (x-(2*z))/(y+z);
     if((x-(2*z))%(y+z)==y){
         ans++;
     }      
     cout << ans << endl;
     return 0;
     
  }

Measured memory_bytes: 3604
/*
    
*/
#include<bits/stdc++.h>
using namespace std;
#define CoDeFoRcEs_and_ChIlL ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
#define fl(i,a,b) for(ll i=a;i<b;i++)
#define rfl(i,a,b) for(ll i=a;i>b;i--)
#define pb push_back
#define mp make_pair
#define test ll t;cin>>t;while(t--)
#define lld long double
#define vpp vector<pair<ll,ll>>
#define pii pair<ll,ll>
#define ff first
#define ss second
#define endl '\n'
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
const ll M =1000000007;
const double pi  =acos(-1);
const int N = 2e5 + 10;
int main()
{  
    CoDeFoRcEs_and_ChIlL;
    ll a,b,c,d,i=0;
    cin>>a>>b>>c>>d;
    while(1)
    {
		c-=b;
		if(c<=0) {cout<<"Yes"; break;}
		a-=d;
		if(a<=0) {cout<<"No"; break;}
 
	}
} 

Measured memory_bytes: 3652
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n, = map(int, readline().split())
xyp = tuple(tuple(map(int, readline().split())) for _ in range(n))

N = 1<<n
INF = 1<<60
resx = []
resy = []
for i in range(n):
    x,y,p = xyp[i]
    rx = [min(abs(x),abs(y))]*N
    ry = [min(abs(x),abs(y))]*N
    for j in range(n):
        for k in range(1<<j):
            rx[k+(1<<j)] = min(rx[k],abs(x-xyp[j][0]))
            ry[k+(1<<j)] = min(ry[k],abs(y-xyp[j][1]))
    
    for j in range(N):
        rx[j] *= p
        ry[j] *= p
    resx.append(rx)
    resy.append(ry)

ans = [INF]*(n+1)
N = 3**n

p = tuple(3**i for i in range(n+1))
rv = [0]*N
rx = [0]*N
ry = [0]*N
for j in range(n):
    for k in range(p[j]):
        rv[k+  p[j]] = rv[k+2*p[j]] = rv[k]
        rv[k] += 1

        rx[k+  p[j]] = rx[k]|(1<<j)
        ry[k+  p[j]] = ry[k]

        rx[k+2*p[j]] = rx[k]
        ry[k+2*p[j]] = ry[k]|(1<<j)

for mask in range(N):
    v = rv[mask]
    x = rx[mask]
    y = ry[mask]
    
    r = 0    
    for i in range(n):
        r += min(resx[i][x],resy[i][y])
    if r < ans[v]:
        ans[v] = r

for i in ans[::-1]:
    print(i)



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

p=[1]*n
c=['w']*n
c[0]='r'


def ope(x,y):
    if c[x-1]=='r':
        c[y-1]='r'
    p[x-1] -= 1
    p[y-1] += 1
    if p[x-1]==0:
        c[x-1]='w'

for i in range(m):
    x,y=map(int,input().split())
    ope(x,y)


print(c.count('r'))


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

using namespace std;


int main()
{long long int A,B,C,a,b,c;
cin>>A>>B>>C;
long long int S = 0;
if(A==B&&A==C){
    if(A%2==0){
        S=-1;
    }else{
        S = 0;
    }
}else{
while(A%2==0&&B%2==0&&C%2==0){
    a = A,b = B,c = C;
    A = (b+c)/2;
    B = (a+c)/2;
    C = (a+b)/2;
    S++;
}


}
cout<<S<<"\n";
}


Measured memory_bytes: 256
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Map<String,Integer> blue = new HashMap<>();
		Map<String,Integer> red = new HashMap<>();
		int n = sc.nextInt();
		for(int i = 0; i < n; i++) {
			String s=sc.next();
			if(blue.get(s)==null) {
				blue.put(s,1);
			}else {
				blue.put(s,blue.get(s)+1);
			}
		}
		int m=sc.nextInt();
		for(int i=0;i<m;i++) {
			String s=sc.next();
			if(red.get(s)==null) {
				red.put(s,1);
			}else {
				red.put(s,red.get(s)+1);
			}
		}
		int max = 0;
		for(String key : blue.keySet()) {
			int now;
			if(red.containsKey(key)) {
				now =blue.get(key)-red.get(key);
			}else {
				now=blue.get(key);
			}
			if(max<now) {
				max=now;
			}
		}
		System.out.println(max>0?max:0);
	 }
}

Measured memory_bytes: 35884
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	bool flag=false;
	cin>>n;
	for(int i=1;i<=9;i++)
		for(int j=1;j<=9;j++)
			if(n==i*j)
				flag=true;
	if(flag)
		cout<<"Yes";
	else
		cout<<"No";
} 

Measured memory_bytes: 256
l = []
for i in range(5):
    A = int(input())
    if A%10 == 0:
        l.append([A,A%10])
    else:
        l.append([A,10 - A%10])
l.sort(key = lambda x : x[1])
s = 0
for j in range(4):
    s += l[j][0] + l[j][1]
s += l[4][0]
print(s)

Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
#include<sstream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<numeric>
#include<complex>

using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define X real()
#define Y imag()
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

typedef long long ll ;
typedef deque<int> di ;
typedef deque<ll> dl ;
typedef map<string,int> dict;
typedef complex<double> comd;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
const double PI = acos(-1.0) ;
double eps = 1e-10 ;

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  while(cin >> n){
    if(n ==0){
      break;
    }
    int j = 0;
    rep(i,n){
      int tmp = i+1;
      while(tmp % 5 == 0){
        tmp /= 5;
        ++j ;
      }
    }
    cout << j << endl;
  }
  return 0;
}

Measured memory_bytes: 3104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    String str = br.readLine();
	    StringTokenizer st = new StringTokenizer(str, " ");

		  int x  = Integer.parseInt(st.nextToken());
		  int y  = Integer.parseInt(st.nextToken());

		  System.out.print(x * y);
		  System.out.print(" ");
		  System.out.println((2*x) + (2*y));

	}

}

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

int count(int n,int x){
  int cnt=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)cnt++;
      }
    }
  }
  return cnt;
}

int main(void){
  int n,x;
  while(1){
    cin>>n>>x;
    if(n==0&&x==0)break;
    cout<<count(n,x)<<endl;
  }
}



Measured memory_bytes: 3108
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }

const ll INF=1e18;

const ull B=1000000007;//ハッシュの基数

//aはbに含まれているか？
void contain(string a,string b){
    int al=a.length(),bl=b.length();
    if(al>bl) return;

    //Bのal乗を計算
    ull t=1;
    for(int i=0;i<al;i++) t*=B;

    //aとbの最初のal文字に関するハッシュ値を計算
    ull ah=0,bh=0;
    for(int i=0;i<al;i++) ah=ah*B+a[i];
    for(int i=0;i<al;i++) bh=bh*B+b[i];

    //bの場所を1つずつ進めながらハッシュ値をチェック
    for(int i=0;i+al<=bl;i++){
        if(ah==bh) cout<<i<<'\n';//bのi文字目からのal文字が一致
        if(i+al<bl) bh=bh*B+b[i+al]-b[i]*t;
    }
}

int main(){
    string t,p;
    cin>>t>>p;
    contain(p,t);
}


Measured memory_bytes: 5060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
int n,k,a[N],dp[N];
inline int read(){
	int x=0,w=1;
	char ch=0;
	while (ch<'0' || ch>'9'){
		ch=getchar();
		if (ch=='-') w=-1;	
	}
	while (ch<='9' && ch>='0'){
		x=(x<<1)+(x<<3)+ch-'0';
		ch=getchar();
	}
	return x*w;
}
int main(){
	n=read(),k=read();
	for (int i=1;i<=n;++i) a[i]=read();
	dp[1]=0;
	for (int i=2;i<=n;++i){
		dp[i]=2e9;
		for (int j=max(1,i-k);j<i;++j)
			dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
	}
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

	private void doit(){
		Scanner sc = new Scanner(System.in);
		long mod = 1000000007;
		while(sc.hasNext()){
			char [] data = sc.next().toCharArray();
			int len = data.length;

			boolean flg = false;
			for(int i =0 ;i < len; i++){
				int [] array = new int[26];
				for(int j = i; j >= 0 && i - j < 3;j--){
					array[data[j] - 'a']++;
					if (j == i)continue;
					
					for(int k = 0; k < array.length; k++){
						if(array[k] > (i - j + 1) / 2){
							System.out.println(j + 1 + " " + (i + 1));
							flg = true;
							break;
						}
					}
					if(flg)break;
					
				}
				if(flg)break;
				
			}
			if(! flg){
				System.out.println("-1 -1");
			}
		}

	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

}


Measured memory_bytes: 19948
n,m = map(int,input().split())
light = [list(map(int,input().split()))[1:] for _ in range(m)]
check = list(map(int,input().split()))
ans = 0
for i in range(2**n):
    for j in range(m):
        cnt = 0
        ok = 1
        for k in light[j]:
            if i >> (k-1) & 1 == 1:cnt += 1
        if cnt%2 == check[j]:
            continue
        else:
            ok=0
            break
    ans += ok 
print(ans)

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

int main(){
    int n, m, q;
    cin >> n >> m >> q;
    vector<vector<int>> s(n+1, vector<int>(n+1));

    for(int i = 0; i < m; i++){
        int l, r;
        cin >> l >> r;
        s[l][r]++;
    }

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            s[i][j] += s[i][j-1];
        }
    }

    for(int i = 0; i < q; i++){
        int L, R;
        cin >> L >> R;
        int ans = 0;
        for(int j = L; j <= R; j++){
            ans += s[j][R];
        }
        cout << ans << endl;
    }
}

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

using namespace std;

#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define vvii vector<vector<pair<int, int>>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'

constexpr int INF = 2e18;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e5 + 3;

// #define MULTIPLE_TEST_CASES
void solve() {
  int n;
  cin >> n;
  cout << !n << endl;
}

signed main() {
  // freopen(".in", "r", stdin);
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);

  int t = 1;
#ifdef MULTIPLE_TEST_CASES
  cin >> t;
#endif
  while (t--)
    solve();
}

Measured memory_bytes: 3648
#include<stdio.h>

int main(){

    long long int X;

    scanf("%lld", &X);

    int flag=0;
    long long int y = 100;
    int ans=0;

    while( flag == 0 ){
        ans += 1;
        y = y * 1.01;
//        printf("%lld\n", y);
        if( y >= X ) flag = 1;
    }

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 1720
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  } else {
    return false;
  }
}

const int64_t INF = 1LL << 60;

int main() {
  int64_t n;
  cin >> n;

  vector<int64_t> h(n);
  rep(i, n) cin >> h.at(i);

  vector<int64_t> dp(n, INF);
  dp.at(0) = 0;
  dp.at(1) = abs(h.at(1) - h.at(0));
  for (int i = 2; i < n; i++) {
    chmin(dp.at(i), dp.at(i - 1) + abs(h.at(i) - h.at(i - 1)));
    chmin(dp.at(i), dp.at(i - 2) + abs(h.at(i) - h.at(i - 2)));
  }

  cout << dp.at(n - 1) << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
    int x;
    int i=0;
    
    while(1)
    {
        scanf("%d",&x);
        if(x == 0)  break;
        i++;
        printf("Case %d: %d\n",i,x);
    }
    
    return 0;
}



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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

int main(){
    string s;
    cin >> s;

    ll len = s.length();
    ll dp[len][13] = {};
    ll mt[len][10] = {};

    rep(i, len){
        if(i==0){
            rep(j, 10){
                mt[i][j] = j;
            }
        }
        else if(i==1){
            rep(j, 10){
                mt[i][j] = (j*10)%13;
            }
        }
        else{
            rep(j, 10){
                ll t = j*100 % 13;
                mt[i][j] = (mt[i-2][1]*t) % 13;
            }
        }
    }

    rep(i, len){
        if(i==0){
            if(s[len-1]=='?'){
                rep(j, 13){
                    dp[0][j] = (j<=5||j>=9)? 1 : 0;
                }
            }
            else{
                rep(j, 13){
                    dp[0][j] = ((ll)(s[len-1]-'0')+j)%13==5? 1 : 0;
                }
            }
        }
        else{
            if(s[len-1-i]=='?'){
                rep(j, 13){
                    ll count = 0;
                    rep(k, 10){
                        ll r = (mt[i][k]+j) % 13;
                        count += dp[i-1][r];
                    }
                    dp[i][j] = count % 1000000007;
                }
            }
            else{
                rep(j, 13){
                    ll r = (mt[i][s[len-1-i]-'0']+j) % 13;
                    dp[i][j] = dp[i-1][r] % 1000000007;
                }
            }
        }
    }
    cout << dp[len-1][0] << endl;
}


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

using namespace std;

int main(){

int a,b=0,c=0,d=0,e=1,j;
string mo;
cin >> a >> mo;
string ka[a];
for(int k=0;k<a;k++){
    cin >> ka[k];
}
//
for(int i=0;i<a;i++){
        for(int e=1;e<ka[i].size()/mo.size()+5&&c==0;e++){
for(int j=0;j<ka[i].size()-mo.size()+2&&c==0;j++){
for(int y=0; y<mo.size()&&c==0; y++){
    if(mo[y]==ka[i][j+y*e]){
        b=b+1;
        //cout << e;
    }else{
        b=0;
        break;
    }
    if(b==mo.size()){
        c=1;
        break;
    }
}
b=0;
}
}
if(c==1)d=d+1;
c=0;
}
cout << d << endl;
return 0;
}

Measured memory_bytes: 1224
col = [0, 399, 799, 1199, 1599, 1999, 2399, 2799, 3199]
flag = [False for _ in range(len(col))]
n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(n):
    for j in range(1, len(col)):
        if col[j-1] < a[i] <= col[j]:
            flag[j] = True
        if a[i] >= 3200:
            cnt += 1
            break
bs = flag.count(True)
mn = max(1, bs)
mx = bs+cnt
print(mn, mx)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pii;
typedef pair<double,double> pdd;
const double EPS=1e-9;
#define debug(c) (cerr<<#c<<": "<<c<<"\n")
#define fi first
#define se second
#define mod 1000000007
#define pi acos(-1)
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
int main()
{
	ios;
	ll d,sum=0;
	string s;
	cin>>s;
	for(ll i=0;i<s.length();i++)
	{
		d=s[i]-48;
		sum+=d;
	}
	if(sum%9==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}


Measured memory_bytes: 3756
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

int main() {
    return ([]() {
        std::function<void()> input;
        std::vector <int> list;
        (input = [&input, &list]() {
            int data;
            if ( std::cin >> data ) {
                list.push_back( data );
                input();
            } else {
                sort( list.rbegin(), list.rend() );
                for_each(
                    list.begin(),
                    list.begin() + 3,
                    [](int x){ std::cout << x << std::endl; }
                );
            }
        })();
        return 0;
    })();
}

Measured memory_bytes: 1216
import java.util.Scanner;
class Main {
	public static void main(String []args) {
		Scanner sc=new Scanner(System.in);
		int x=sc.nextInt(),a=sc.nextInt(),b=sc.nextInt(),l;
		x=x-a;
		l=x%b;
		System.out.println(l);
	}
}


Measured memory_bytes: 23892
s = input()
flag = 0
f = True
for i in range(len(s)):
    if s[i] == "h" and flag == 0:
        flag = 1
        continue
    if s[i] == "i" and flag == 1:
        flag = 0
        continue
    else:
        f = False
if f is False or flag != 0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 38384
import java.util.ArrayList;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	static int N;
	static int K;
	static GM[]map;
	static long[]node;


	public static void main(String[]args) throws CloneNotSupportedException{
		try(Scanner scan = new Scanner(System.in)){
			N = scan.nextInt();
			map = new GM[N+1];
			node = new long[N+1];


			for(int i = 1;i<=N;i++) {
				map[i] = new GM(i);
				node[i] = Long.MAX_VALUE;
			}

			for(int i = 0;i<N-1;i++) {
				int a = scan.nextInt();
				int b = scan.nextInt();
				int c = scan.nextInt();
				map[a].are.add(new Edge(b,c));
				map[b].are.add(new Edge(a,c));
			}
			int Q = scan.nextInt();
			K = scan.nextInt();
			dijkstr();



			for(int i = 0;i<Q;i++) {
				int x = scan.nextInt();
				int y= scan.nextInt();

				long A = Math.abs(node[x]);
				long B = Math.abs(node[K]-node[y]);

				System.out.println(A+B);



			}




		}


	}

	private static void dijkstr()throws CloneNotSupportedException {
		PriorityQueue<GM>que = new PriorityQueue<GM>(Comparator.comparingLong(p->p.cost));
		que.add(map[K]);
		node[K] = 0;
		map[K].cost = 0;

		while(!que.isEmpty()) {
			GM p = que.poll();
			if(p.cost>node[p.num])continue;
			for(Edge s:p.are) {
				int to = s.to;
				long d = s.d;
				//System.out.println(to+" "+d);
				if(p.cost+d<node[to]) {
					GM pc = node[to]!=Long.MAX_VALUE?map[to].clone():map[to];
					pc.cost =  p.cost+d;
					node[to] = pc.cost;
					que.add(pc);
				}
			}
		}

	}




	private static class GM implements Cloneable{
		int num;
		long cost = Long.MAX_VALUE;
		ArrayList<Edge>are = new ArrayList<Edge>();
		GM(int nu){
			num=nu;
		}

		//cloneメソッドをオーバーライド
				@Override
			    protected GM clone() throws CloneNotSupportedException {
					 GM  node = (GM)super.clone();
			    return node;
			}

	}



	private static class Edge{
		int to;
		long d;
		Edge(int T,int D){
			to =T;d = D;
		}
	}


}


Measured memory_bytes: 82024
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

bool cmp( pair< int, int > a, pair< int, int > b )
{
    return a.second > b.second ;
}

int main()
{
    vector< pair< int,int> > p( 30 );
    int key = 0, value = 0, cnt = 0;
    while( scanf( "%d,%d\n", &key, &value ) != EOF )
    {
        cnt++;
        if( key == 0 && value == 0 )break;
        p[cnt].first = key;
        p[cnt].second = value;    
    }
    sort( begin(p), end(p), cmp );
    /* for( int i = 0;i < 30; i++ )
    {
        key = p[i].first;
        value = p[i].second;
        printf( "key:%d ,value:%d\n", key, value );

    } */
    vector< pair< int, int > > rank(30);
    int pos = 0;
    rank[0].second = 1;
    while( pos < 30 )
    {
        rank[pos].first = p[pos].first;
        if( p[pos].second == p[pos + 1].second )
        {
            rank[pos + 1].second = rank[pos].second;
        }
        else
        {
            rank[pos + 1].second = rank[pos].second + 1;
        }
        
        pos++;
    }
    int num = 0;
    while( scanf( "%d\n", &num ) != EOF )
    {
        for( int i = 0; i < 30; i++ )
        {
            if( rank[i].first == num )
            {
                printf( "%d\n", rank[i].second );
                break;
            }
        }
    }
    return 0;
}


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

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define EACH(begin, end) for(auto itr = (begin); itr != (end); itr++)

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;



ll N = 0;
ll ret = 0;
ll A, B;

void input() {
  IN(A);
  IN(B);
}

void solve() {
  ll diff = abs(A-B);
  if (diff % 2 == 1) {
    PRINT("IMPOSSIBLE");
  } else {
    PRINT((A+B)/2);
  }
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=4999999996000000001;
ll dp[1<<21];

int main(){
    int n;
    cin>>n;
    vector<vector<int> > a(n,vector<int>(n));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>a[i][j];
        }
    }
    dp[0]=1;
    for(int men=1;men<(1<<n);men++){
        int wom=__builtin_popcount(men);
        wom--;
        for(int j=0;j<n;j++){
            int nmen=men^(1<<j);
            if(nmen>men) continue;
            //cout<<men<<":"<<j<<","<<wom<<endl;
            if(a[j][wom]){
                dp[men]+=dp[nmen];
                dp[men]%=MOD;
            }
        }
    }
    cout<<dp[(1<<n)-1]<<endl;
}

Measured memory_bytes: 19572
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_poizcy.hpp>
typedef long long  ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<double, double>  iidb;
typedef pair<ii, ll>  iii;
typedef vector<ll>     vi;
typedef vector<vi>     vvi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e18+7;
const double PI = acos(-1);
#define initseg ll new_nodo=(nodo*2),mid=(iz+der)/2;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define tam 210000
#define offset 200
#define ptr nodo*


using namespace std;
const int mod=1e6+3;
int main()
{
	int l,r,d;
	cin>>l>>r>>d;
	int c=0;
	forr(i,l,r+1)
	{
		if (i%d==0)c++;
	}
	cout<<c<<endl;	
}

Measured memory_bytes: 3568
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CMaximumVolume solver = new CMaximumVolume();
        solver.solve(1, in, out);
        out.close();
    }

    static class CMaximumVolume {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int l = in.nextInt();
            double lDouble = l;
            double part = lDouble / 3;
            double ret = part * part * part;


            out.println(BigDecimal.valueOf(ret).toPlainString());

        }

    }

    static class Scanner {
        private final InputStream in;
        private final byte[] buffer;
        private int ptr;
        private int buflen;

        public Scanner(InputStream in) {
            this.in = in;
            this.buffer = new byte[1024];
            this.ptr = 0;
            this.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 byte readByte() {
            if (hasNextByte()) return buffer[ptr++];
            return -1;
        }

        private boolean isPrintableChar(byte c) {
            return '!' <= c && c <= '~';
        }

        private void skipUnprintable() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
                ptr++;
            }
        }

        public boolean hasNext() {
            skipUnprintable();
            return hasNextByte();
        }

        public int nextInt() {
            if (!hasNext()) throw new NoSuchElementException();
            int n = 0;
            boolean minus = false;
            byte 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();
            }
        }

    }
}



Measured memory_bytes: 21076
#include<cstdio>
#define int long long
int n,mod,ans;
int f[6010][8010];
signed main(){
	scanf("%lld%lld",&n,&mod);
	f[0][n+1]=1;
	for(int i=0;i<=3*n;i++)
		for(int j=-n;j<=3*n;j++){
			(f[i+1][j+1+n+1]+=f[i][j+n+1])%=mod;
			(f[i+2][j-1+n+1]+=f[i][j+n+1]*(i+1)%mod)%=mod;
			(f[i+3][j+n+1]+=f[i][j+n+1]*(i+1)%mod*(i+2)%mod)%=mod;	
		}
	for(int i=0;i<=n;i++)
		(ans+=f[3*n][3*i+n+1])%=mod;
	printf("%lld\n",ans);
}

Measured memory_bytes: 375808
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int N = sc.nextInt();
		Integer[] p = new Integer[N];
		int b = 1000;
		int d = 0;
		for(int i=0; i<N; i++) {
			p[i] = sc.nextInt();
		}
		sc.close();
		for(int i=0; i<X*2; i++) {
			if(Arrays.asList(p).contains(i)) {
				continue;
			}else {
					int c = Math.abs(X-i);
					if(b>c) {
						b = c;
						d = i;
					}
				}
			}
		System.out.println(d);
	}

}


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


int main(){
  string s;
  cin >> s;
  int begin;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'A'){
      begin = i;
      break;
    }
  }
  int end;
  for(int i = s.size() - 1; i >= 0; i--){
    if(s[i] == 'Z'){
      end = i;
      break;
    }
  }
  cout << end - begin + 1 << endl;
  
}

Measured memory_bytes: 640
N = int(input())
txy = [list(map(int, input().split())) for _ in range(N)]
ct = 0
p = [0, 0]
failed = False
for i in range(N):
    t, x, y = txy[i]
    dx, dy = abs(p[0]-x), abs(p[1]-y)
    dt = t - ct
    if dt < dx+dy:
        failed = True
        break
    elif dt % 2 and (dx+dy) % 2 == 0:
        failed = True
        break
    elif dt % 2 == 0 and (dx+dy) % 2:
        failed = True
        break
    ct = t
    p = [x, y]

if failed:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 27380
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define MOD 998244353
//#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll po(ll a,int n){ll x=1;while(n--)x*=a;return x;}

typedef struct t{ll m,w,c;}T;
int tsort(const void*a,const void*b){
	T p=*(T*)a,q=*(T*)b;
	if(p.m<q.m)return -1;
	if(p.m>q.m)return  1;
	if(p.w<q.w)return -1;
	if(p.w>q.w)return 1;
	return 1;
}

ll x[4][2]={{1,0},{1,1},{2,2},{4,4}};
//x[i][j]=i個で和をjにする場合の数

T a[50010];
ll dp[100010][2];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	rep(i,0,m){
		int x,y,c;
		scanf("%d%d%d",&x,&y,&c);
		a[i].m=max(x,y);
		a[i].w=x+y;
		a[i].c=c;
	}

	qsort(a,m,sizeof(T),tsort);

	//番兵
	a[m].m=a[m].w=a[m].c=INF;
	a[m+1].m=a[m+1].w=a[m+1].c=INF;

	ll ptr=0;//まだ見てない最小index

	//2以下は愚直に見る
	ll c2=3,s2=0;
	while(a[ptr].m<=2&&a[ptr].w!=4){
		c2--;
		if(a[ptr].c==1)s2^=1;
		ptr++;
	}
	if(a[ptr].m==2&&a[ptr].w==4){
		dp[2][a[ptr].c]=x[c2][a[ptr].c^s2];
		ptr++;
	}else{
		dp[2][0]=x[c2][s2];
		dp[2][1]=x[c2][s2^1];
	}
		
	//3以上はwが同じ所が偶数で、右下3x3だけ調べる
	rep(i,3,n+1){
		ll cnt=i-3;

		while(a[ptr].m==i&&a[ptr].w<=2*i-3){
			if(a[ptr+1].m==i&&a[ptr].w==a[ptr+1].w){
				if(a[ptr].c!=a[ptr+1].c){
					puts("0");
					return 0;
				}
				cnt--;
				ptr+=2;
			}else{
				cnt--;
				ptr++;
			}
		}
		
		//残りcnt2個でs2^(i-1,i-1)
		ll cnt2=2,s2=0;
		while(ptr<m&&a[ptr].m==i&&a[ptr].w==2*i-2){
			cnt2--;
			if(a[ptr].c==1)s2^=1;
			ptr++;
		}
		
		//残りcnt3個でs3^(i-1,i-1)^(i,i)
		ll cnt3=2,s3=0;
		while(ptr<m&&a[ptr].m==i&&a[ptr].w==2*i-1){
			cnt3--;
			if(a[ptr].c==1)s3^=1;
			ptr++;
		}
		
		if(ptr<m&&a[ptr].m==i&&a[ptr].w==2*i){
			//右下が指定されている場合
			dp[i][a[ptr].c]=(dp[i-1][0]*x[cnt2][s2^0]*x[cnt3][a[ptr].c^0^s3]+dp[i-1][1]*x[cnt2][s2^1]*x[cnt3][a[ptr].c^1^s3])*pom(2,cnt,MOD)%MOD;
			ptr++;
		}else{
			dp[i][0]=(dp[i-1][0]*x[cnt2][s2^0]*x[cnt3][0^0^s3]+dp[i-1][1]*x[cnt2][s2^1]*x[cnt3][0^1^s3])*pom(2,cnt,MOD)%MOD;
			dp[i][1]=(dp[i-1][0]*x[cnt2][s2^0]*x[cnt3][1^0^s3]+dp[i-1][1]*x[cnt2][s2^1]*x[cnt3][1^1^s3])*pom(2,cnt,MOD)%MOD;
		}
	}
//	rep(x,0,n+1)printf("%d %d\n",dp[x][0],dp[x][1]);
	printf("%lld",(dp[n][0]+dp[n][1])%MOD);
}

Measured memory_bytes: 2920
#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;
  string s;
  cin >> a >> s;
  if (a >= 3200) cout << s << endl;
  else cout << "red" << endl;
  return 0;
}

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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

    int N;
    std::cin >> N;
    map<string, int> map;
    int m = 0;
    REP(i, N) {
        string S;
        std::cin >> S;
        chmax(m, ++map[S]);
    }
    vector<string> ans;
    for(const auto& v : map) {
        if(v.second == m) ans.push_back(v.first);
    }
    SORT(ans);
    REP(i, ans.size()) {
        std::cout << ans[i] << std::endl;
    }

    return 0;
}


Measured memory_bytes: 25584
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
using Graph = vector<vector<int>>;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;

int main (){
  int x;
  cin>>x;
  x=x-400;
  x=x/200;
  cout<<8-x;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    string Word1, Word2;
    vector<string> S(N);
    for(int i = 0; i < N; i++){
        cin >> S.at(i);
    }
    bool answer_is = true;
    for(int i =0; i < N-1; i++){
        Word1 = S.at(i);
        if(answer_is == false)
        break;
        for(int j = i+1;  j < N; j++){
        Word2 = S.at(j);
        if(Word1 == Word2){
        answer_is = false;
        break;
        }
        }
    }
    if(answer_is == false){
        cout << "No" << endl;
        return 0;
    }
    for(int i = 0; i< N-1; i++){
        Word1 = S.at(i);
        Word2 = S.at(i+1);
        if(Word1.at(Word1.size()-1) != Word2.at(0)){
            answer_is = false;
            break;
        }
    }
        if(answer_is == false){
            cout << "No" << endl;
        }
        else if(answer_is == true)
        cout << "Yes" << endl; 
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
using namespace std;
typedef long long int ll;

double d[1010][1010];
double x[1010],y[1010],r[1010];

double dist(double a,double b){
	return sqrt(a*a+b*b);
}

double X[2],Y[2];

double hyado[1010];
int used[1010];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	for(int i=0;i<2;i++){
		cin >> X[i] >> Y[i];
	}
	int n; cin >> n;
	for(int i=0;i<n;i++){
		cin >> x[i] >> y[i] >> r[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			double dis=dist(x[i]-x[j],y[i]-y[j]);
			d[i][j]=max((double)0,dis-r[i]-r[j]);
		}
		d[i][n]=d[n][i]=max((double)0,dist(x[i]-X[0],y[i]-Y[0])-r[i]);
		d[i][n+1]=d[n+1][i]=max((double)0,dist(x[i]-X[1],y[i]-Y[1])-r[i]);
	}
	d[n][n+1]=d[n+1][n]=dist(X[0]-X[1],Y[0]-Y[1]);

	for(int i=0;i<n+2;i++){
		hyado[i]=1e18;
	}
	for(int i=0;i<n;i++){
		used[i]=0;
	}
	hyado[n]=0;
	for(int i=0;i<n+2;i++){
		int ne=-1;
		for(int j=0;j<n+2;j++){
			if(used[j]==0&&(ne==-1||hyado[ne]>hyado[j]))ne=j;
		}
		used[ne]=1;
		for(int j=0;j<n+2;j++){
			 hyado[j]=min(hyado[j],hyado[ne]+d[ne][j]);
		}
	}
	printf("%.10f\n",hyado[n+1]);
	return 0;
}


Measured memory_bytes: 8192
A, B, M = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)

x = []
y = []
c = []

M.times do
  line = gets.chop.split.map(&:to_i)
  x << line.shift
  y << line.shift
  c << line.shift
end

price = a.min + b.min

discount = []

M.times do |i|
  X = x[i] - 1
  Y = y[i] - 1
  d = a[X] + b[Y] - c[i]
  discount << d
end

waribiki = discount.min

puts [price, waribiki].min


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

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

    string S, T;
    cin >> S >> T;
    int ans = 0;
    for (int i = 0; i < 3; i++) {
        if (S[i] == T[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool compare(pair<int, int> a, pair<int, int> b){
    if(a.first == b.first) return a.second > b.second;
    else return a.first < b.first;
}

int main(){
    int n;
    cin >> n;

    vector<pair<int,int>> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a.begin(),a.end(), compare);

    set<int> color;// (color, end-of-line)
    color.insert(a[0].second);
    for(int i=1; i<n; i++){
        auto itr = color.lower_bound(a[i].second);
        if(itr != color.begin()){
            color.erase(*prev(itr));
        }
        color.insert(a[i].second);
    }
    cout << color.size() << endl;
    return 0;
}

Measured memory_bytes: 5760
h,w = gets.split.map(&:to_i)
a = h.times.map{gets.split.map(&:to_i)}

ans = []
h.times{|i|
  (w-1).times{|j|
    a[i][j+1] += a[i][j]
  }
  (w-1).times{|j|
    if a[i][j]%2==1
      ans << [i+1,j+1,i+1,j+2]
    end
  }
}

(h-1).times{|i|
  if a[i][w-1]%2==1
    ans << [i+1,w,i+2,w]
  end
  a[i+1][w-1] += a[i][w-1]
}

p ans.size
ans.each{|x|
  puts x*" "
}

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

int main() {
    int X, Y;
    cin >> X >> Y;
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            if (i+j == X && i*2+j*4 == Y) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3624
""" AtCoder """

H, W = map(int, input().split())

S = ['.' * (W + 2)]

for _ in range(H):
    S.append('.' + input() + '.')

S.append('.' * (W + 2))

x = [-1, 0, 1, 0, -1, 1, 1, -1]
y = [0, -1, 0, 1, -1, 1, -1, 1]

ans = [['#' for _ in range(W)] for _ in range(H)]

for i in range(1, H + 1):
    for j in range(1, W + 1):
        if S[i][j] != '#':
            count = 0
            for k in range(8):
                if S[i + y[k]][j+x[k]] == '#':
                    count += 1
            ans[i - 1][j - 1] = str(count)

for i in range(H):
    print(''.join(ans[i]))


Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define INF 100000000

typedef struct {
	char a[24],b[24];
	int d,t;
} senro_t;

int n,m;
char s[24],p[24],g[24];
senro_t senro[5000];
const char* ekilist_raw[10000];
int ekinum;
const char* ekilist[500];

int qsort_comp(const void* x,const void* y) {
	return strcmp(*((const char**)x),*((const char**)y));
}

int get_ekiid(const char* eki) {
	int left,right,mid;
	left=0;right=ekinum-1;
	while(left<=right) {
		mid=(left+right)/2;
		int cmp=strcmp(eki,ekilist[mid]);
		if(cmp==0)return mid;
		else if(cmp<0)right=mid-1; else left=mid+1;
	}
	return ekinum;
}

int zikan[510][510];
int result[510];
int kakutei[510];

int tansaku(int s,int g) {
	int i;
	for(i=0;i<n;i++) {
		result[i]=INF;
		kakutei[i]=0;
	}
	result[s]=0;
	for(i=0;i<n;i++) {
		int minst=0,minresult=INF;
		int j;
		for(j=0;j<n;j++) {
			if(!kakutei[j] && result[j]<minresult) {
				minst=j;
				minresult=result[j];
			}
		}
		kakutei[minst]=1;
		for(j=0;j<n;j++) {
			if(result[minst]+zikan[minst][j]<result[j]) {
				result[j]=result[minst]+zikan[minst][j];
			}
		}
	}
	return result[g];
}

int main(void) {
	while(scanf("%d%d",&n,&m)==2 && (n|m)!=0) {
		int i,j;
		int start,chukan,goal;
		scanf("%s%s%s",s,p,g);
		for(i=0;i<m;i++) {
			scanf("%s%s%d%d",senro[i].a,senro[i].b,&senro[i].d,&senro[i].t);
			ekilist_raw[i*2]=senro[i].a;
			ekilist_raw[i*2+1]=senro[i].b;
		}
		qsort(ekilist_raw,m*2,sizeof(ekilist_raw[0]),qsort_comp);
		ekilist[0]=ekilist_raw[0];
		ekinum=1;
		for(i=1;i<m*2;i++) {
			if(strcmp(ekilist_raw[i],ekilist_raw[i-1])!=0) {
				ekilist[ekinum++]=ekilist_raw[i];
			}
		}
		start=get_ekiid(s);
		chukan=get_ekiid(p);
		goal=get_ekiid(g);
		for(i=0;i<n;i++) {
			for(j=0;j<n;j++) {
				zikan[i][j]=(i==j?0:INF);
			}
		}
		for(i=0;i<m;i++) {
			int a=get_ekiid(senro[i].a);
			int b=get_ekiid(senro[i].b);
			zikan[a][b]=zikan[b][a]=senro[i].d/40+senro[i].t;
		}
		printf("%d\n",tansaku(start,chukan)+tansaku(chukan,goal));
	}
	return 0;
}

Measured memory_bytes: 2096
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <set>

using ll = long long;

using namespace std;

int main() {
    long n;
    cin >> n;
    long p[n], pinv[n];
    for (long i=0; i<n; i++) {
        cin >> p[i];
        p[i]--;
        pinv[p[i]] = i;
    }
    set<long> used;
    used.insert(-1);
    used.insert(n);
    used.insert(pinv[n-1]);
    long ans = 0;
    for (long i=n-2; i>=0; i--) {
        auto itr = used.lower_bound(pinv[i]),
             r1 = itr,
             l1 = (--itr),
             r2 = r1,
             l2 = l1;
        if (*r1 < n) {
            r2++;
            ans += (i+1) * (*r2 - *r1) * (pinv[i] - *l1);
        }
        if (*l1 >= 0) {
            l2--;
            ans += (i+1) * (*r1 - pinv[i]) * (*l1 - *l2);
        }
        used.insert(pinv[i]);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 6528
#include <cstdio>
#include <queue>
using namespace std;
#define INF (1<<21)

int n, G[100][100], dist[100], visited[100];


int main(void) {
    int u, k, v, i, j;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
        for (j = 0; j < n; j++) G[i][j] = 0;

    for (i = 0; i < n; i++) {
        scanf("%d %d", &u, &k);
        u--;
        for (j = 0; j < k; j++) {
            scanf("%d", &v);
            v--;
            G[u][v] = 1;
        }
    }
    
    for (i = 1; i < n; i++) {
        dist[i] = INF;
        visited[i] = 0;
    }
    dist[0] = 0;
    visited[0] = 1;

    queue<int> q;
    q.push(0);
    while (!q.empty()) {
        u = q.front();
        q.pop();
        for (i = 0; i < n; i++) {
            if (G[u][i] == 0 || visited[i] == 1) continue;
            q.push(i);
            visited[i] = 1;
            dist[i] = dist[u] + 1;
        }
    }

    for (i = 0; i < n; i++) {
        if (dist[i] == INF) dist[i] = -1;
        printf("%d %d\n", i + 1, dist[i]);
    }

    return 0;
}

Measured memory_bytes: 1072
#include <bits/stdc++.h>
using namespace std;
vector<int> t[100005];
long long int dp[100005][2];
long long int m=1000000007;
long long int solve(int node,bool constraint,int par)
{
   long long  int ans=0;
    long long int w1=1;
    if(dp[node][constraint]!=-1)
    {
        return dp[node][constraint];
    }
    for(auto child:t[node])
    {
        if(child!=par)
        {
            w1=w1*solve(child,0,node);
            w1=w1%m;
        }
    }
    ans=ans+w1;
    if(constraint!=1)
    {
        long long int w2=1;
        for(auto child:t[node])
        {
            if(child!=par)
            {
                w2=w2*solve(child,1,node);
                w2=w2%m;
            }
         }
         ans=ans+w2;
         ans=ans%m;
    }
    return dp[node][constraint]=ans;
}
int main() {
    int n;
    memset(dp,-1,sizeof(dp));
    cin>>n;
    for(int i=1;i<n;i++)
    {
        int u,v;
        cin>>u>>v;
        t[u].push_back(v);
        t[v].push_back(u);
    }
    long long int ans=solve(1,0,-1);
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 18960
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll pow(ll x,ll y,ll mod){
    if(y==0) return 1;
    if(y&1) return x*pow(x,y-1,mod)%mod;
    ll p=pow(x,y/2,mod);
    return p*p%mod;
}

void solve(){
    ll k;
    cin >> k;
    ll a=0;
    ll ans=-1;
    rp(i,1000040){
        a+=7*pow(10,i,k);
        a%=k;
        if(a==0) {
            ans=i+1;
            break;
        }
    }
    print(ans);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

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

int main(){
    int n,k,ans=0;cin>>n>>k;
    vector<int> x(n);
    for(int i=0;i<n;i++){
        cin>>x.at(i);
        ans+=min(max(k-x.at(i),x.at(i)-k),x.at(i))*2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
sa = input()
sb = input()
sc = input()

card = sa[0]
sa = sa[1:]
  
while sa or sb or sc:
  if card == 'a':
    if len(sa) >= 1:
      card = sa[0]
      sa = sa[1:]
    else:
      print('A')
      quit()
  elif card == 'b':
    if len(sb) >= 1:
      card = sb[0]
      sb = sb[1:]
    else:
      print('B')
      quit()
  else:
    if len(sc) >= 1:
      card = sc[0]
      sc = sc[1:]
    else:
      print('C')
      quit()
  

Measured memory_bytes: 9068