akhauriyash/Code-Regression huggingface dataset:
#ifndef LOCAL
#include "bits/stdc++.h"
#endif
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
template<class T>using vv = vector<vector<T>>; template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

vv<int> graph;
vector<bool> visited;
vv<int> tree;
vector<pair<int, int>> edge;
vector<bool> parity;

void dfs(int v, int p) {
    visited[v] = true;

    for (int u : graph[v]) {
        if (u != p) {
            if (visited[u]) {
                if (v < u) {
                    parity[v] = parity[v] ^ 1;
                    edge.emplace_back(v + 1, u + 1);
                }
            }
            else {
                tree[v].push_back(u);
                tree[u].push_back(v);
                dfs(u, v);
            }
        }
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    graph.resize(N);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    if (M % 2) {
        write(-1);
        return 0;
    }

    visited.resize(N);
    tree.resize(N);
    parity.resize(N);

    dfs(0, -1);

    vector<int> deg(N);
    rep(i, N) deg[i] = tree[i].size();

    //visited.assign(N, false);
    rep(i, N) {
        int v = i;
        while (deg[v] == 1) {
            //visited[v] = true;

            for (int j = tree[v].size() - 1; j >= 0; --j) {
                int u = tree[v][j];

                if (deg[u] == 0) {
                    continue;
                }
                else {
                    if (parity[v]) {
                        edge.emplace_back(v + 1, u + 1);
                        parity[v] = parity[v] ^ 1;
                    }
                    else {
                        edge.emplace_back(u + 1, v + 1);
                        parity[u] = parity[u] ^ 1;
                    }

                    deg[v]--;
                    deg[u]--;
                    v = u;
                    break;
                }
            }
        }
    }

    for (auto& e : edge) {
        cout << e.first << " " << e.second << endl;
    }
}

Measured memory_bytes: 19960
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int main()
{
	lint n,m;cin>>n>>m;
	if(n==1LL){
		if(m==1LL) cout<<1<<endl;else cout<<m-2<<endl;
	}
	else if(m==1LL){
		cout<<n-2<<endl;
	}
	else cout<<(n-2)*(m-2)<<endl;
}


Measured memory_bytes: 768
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    S = list(input())
    R = set()
    G = set()
    B = set()

    MIN_MAX = lambda a, b: (b, a) if a > b else (a, b)

    for i, s in enumerate(S):
        if s == 'R':
            R.add(i)
        elif s == 'G':
            G.add(i)
        else:
            B.add(i)

    b_len = len(B)
    ans = 0
    for r in R:
        for g in G:
            v1, v2 = MIN_MAX(r, g)
            rg_diff = v2 - v1
            ans += b_len
            if v2 + rg_diff in B:
                ans -= 1
            if v1 - rg_diff in B:
                ans -= 1
            if (r + g) % 2 == 0 and (r + g) // 2 in B:
                ans -= 1
    print(ans)

if __name__ == '__main__':
    main()


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

int main() {
    int N, ans=0, K, A, B;
    cin >> K;
    cin >> A >> B;
    bool flag =false;

    for(int i=A; i<=B; i++){
	if(i%K==0)
	    flag=true;
    }


    cout << (flag? "OK": "NG") << endl;
} 




Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    long long int n, a, b;
    long long int sa;

    cin >> n >> a >> b;

    if ((n == 1 && a != b) || a > b) {
        cout << 0 << endl;
    }
    else if (a == b) {
        cout << 1 << endl;
    }
    else {
        cout << (n-2)*(b-a)+1 << endl;
    }
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

even, odd = 0, 0
for a in A:
	if a % 2:
		odd += 1
	else:
		even += 1

if not even:
	print(3 ** N - 1)
else:
	print(3 ** N - 2 ** even)


Measured memory_bytes: 2940
#include<stdio.h>
#include<stdlib.h>
int cmp(const int *a, const int *b){
  return *a - *b;
}
int main(){
  int n;
  scanf("%d",&n);
  int l[n];
  for(int i=0;i<n;i++)scanf("%d",&l[i]);
  qsort(l,n,4,cmp);
  int ans=0;
  for(int i=0;i<n-2;i++){
    for(int j=i+1;j<n-1;j++){
      for(int k=j+1;k<n;k++){
        ans+=(l[i]+l[j]>l[k]);
      }
    }
  }
  printf("%d",ans);
}


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

int dp[5005][5005];

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

    for(int i = n-1; i>=0; i--){
        for(int j=n-1; j>=0; j--){
            if(s[i] != s[j]) dp[i][j] = 0;
            else dp[i][j] = dp[i+1][j+1] + 1;
        }
    }
    int ans = 0;
    rep(i,n)rep(j,n){
        if(i>=j) continue;
        int now = min(dp[i][j], j-i);
        ans = max(ans, now);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 101272
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)

int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

int main(void){
  int r,c;
  while(cin>>r>>c,r+c){
    if(!(r%2 == 1 && c%2 == 1))cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }

}

Measured memory_bytes: 1156
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;

#define ISEQ(c) (c).begin(), (c).end()
typedef long long ll;

int main() {
  set<char> left;
  left.insert('y');
  left.insert('h');
  left.insert('n');
  left.insert('u');
  left.insert('j');
  left.insert('m');
  left.insert('i');
  left.insert('k');
  left.insert('o');
  left.insert('l');
  left.insert('p');
  while (true) {
    string s;
    cin >> s;
    if (s == "#") break;
    int len = s.size();
    bool lr = (left.count(s[0]) == 0);
    int res = 0;
    for (int i = 1; i < len; i++) {
      if (lr != left.count(s[i]) == 0) {
	res++;
	lr = !lr;
      }
    }
    cout << res << endl;
  }
}

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

typedef long long ll;
const int N=2e5+5;

int h[N];
ll t[N*4];
#define lson (Node*2)
#define rson (lson|1)
void modify(int Node,int l,int r,int x,ll v) {
	if(l==r) return void(t[Node]=v);
	int mid=(l+r)/2;
	if(x<=mid) modify(lson,l,mid,x,v);
	else modify(rson,mid+1,r,x,v);
	t[Node]=max(t[lson],t[rson]);
}
ll query(int Node,int l,int r,int L,int R) {
	if(L<=l&&r<=R) return t[Node];
	int mid=(l+r)/2; ll ret=0;
	if(L<=mid) ret=query(lson,l,mid,L,R);
	if(mid+1<=R) ret=max(ret,query(rson,mid+1,r,L,R));
	return ret;
}

int main() {
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	
	int n; scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&h[i]);
	ll f;
	for(int i=1,a;i<=n;++i) {
		scanf("%d",&a);
		f=query(1,1,n,1,h[i])+a;
		modify(1,1,n,h[i],f);
	}
	printf("%lld\n",t[1]);
	
	return 0;
}


Measured memory_bytes: 7168
import sys, re
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from collections import deque, defaultdict, Counter
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop, heapify
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()
c = [LIST() for _ in range(10)]
A = [LIST() for _ in range(H)]

#ワーシャルフロイド法  注意 PyPy非対応!!!!
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

graph = csr_matrix(c) #隣接行列からcsr行列をつくる
c = floyd_warshall(graph, directed=True) #無向の場合directed=True
#dist_matrixの中身はfloatになっているので注意！
	

#for i in range(10):
#	print(c[i])

import numpy as np
#距離
def distance(p1, p2):
	p1 = np.array(p1)
	p2 = np.array(p2) 
	return np.linalg.norm(p1-p2)
	

ans = 0
for i in range(H):
	for j in range(W):
		if A[i][j] != -1:
			ans += c[A[i][j]][1]

print(int(ans))



Measured memory_bytes: 30584
#include <stdio.h>

int main() 
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
     int d;
     d=a-b;
     if(d>c)
     printf("0");
     else
     
    { int p;
     p=c-d;
     printf("%d",p);}
}

Measured memory_bytes: 128
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP

██╗███████╗████████╗██╗ █████╗ ██╗  ██╗
██║██╔════╝╚══██╔══╝██║██╔══██╗██║ ██╔╝
██║███████╗   ██║   ██║███████║█████╔╝
██║╚════██║   ██║   ██║██╔══██║██╔═██╗
██║███████║   ██║   ██║██║  ██║██║  ██╗
╚═╝╚══════╝   ╚═╝   ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝




*/
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define in insert
#define mp make_pair
#define lw(v) sort(v.begin(),v.end());
#define hi(v) sort(v.begin(),v.end(),greater<long long>());
#define all(v) v.begin(),v.end()
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
    vector<long long>v;
    vector<long long>u;
    set<long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
    cin>>s1;
    if(s1=="SAT"){cout<<1<<endl;}
    if(s1=="SUN"){cout<<7<<endl;}
    if(s1=="MON"){cout<<6<<endl;}
    if(s1=="TUE"){cout<<5<<endl;}
    if(s1=="WED"){cout<<4<<endl;}
    if(s1=="THU"){cout<<3<<endl;}
    if(s1=="FRI"){cout<<2<<endl;}
}



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

int main() {
  string S;
  cin >> S;
  
  for( int i = 0; i < 3; i++ ){
    if( S.at(i) == S.at(i+1) ){
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cctype>  // std::islower(), std::isupper(), std::tolower, std::toupper
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

long long gcd ( long long a, long long b ) {
  if ( b == 0 ) return a;
  else return gcd ( b, a%b );
}

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

int main (void) {

  int N; std::cin >> N;
  std::cout << lcm(2,N) << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

int main(){
  int N, K;
  scanf("%d",&N);
  scanf("%d",&K);
  std::string S;
  std::cin >> S;
  std::vector<int > zero, one;
  char selecting = '1';
  int i=0;
  int continuenum=0;
  while(i<S.length()){
    //printf("s=%c\n",S[i]);
    if (selecting!=S[i]){
      if (selecting=='0'){
        zero.push_back(continuenum);
        selecting='1';
      } else {
        one.push_back(continuenum);
        selecting='0';
      }
      continuenum=1;
    } else {
      continuenum++;
    }
    i++;
  }
  if (selecting=='1'){
    one.push_back(continuenum);
  } else {
    zero.push_back(continuenum);
  }

  /*for (int i=0; i<zero.size(); i++){
    printf("zero[%d]=%d\n",i,zero[i]);
  }
  for (int i=0; i<one.size(); i++){
    printf("one[%d]=%d\n",i,one[i]);
    }*/

  int ans = 0;
  if (K>=zero.size()){
    ans = N;
  } else {
    for (int i=0; i<=zero.size()-K; i++){
      int sum = 0;
      for (int k=0; k<K; k++){
        sum += zero[i+k];
        sum += one[i+k];
      }
      if (i+K<one.size()){
        sum += one[i+K];
      }
      ans = std::max(ans, sum);
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 1020
#include<bits/stdc++.h>
#define ll long long int
#define mp(a,b) make_pair(a,b)
using namespace std;

vector<pair<ll,ll>> fives;
vector<pair<ll,pair<ll,ll>>> options;

int main(){
    ll i,j;
    for(i = -120; i<=120; i++){
        ll val = 1;
        val = i*i*i*i*i;
        fives.push_back(mp(val,i));
    }
    ll len = fives.size();
    for(i = 0; i<len; i++){
        for(j = 0; j<len; j++){
            if(i != j){
                options.push_back(mp(fives[i].first - fives[j].first, mp(fives[i].second,fives[j].second)));
                options.push_back(mp(fives[j].first - fives[i].first, mp(fives[j].second,fives[i].second)));
            }
        }
    }
    sort(options.begin(), options.end());
    ll x;
    cin>>x;
    ll left = 0, right = options.size() - 1, mid = (left + right)/2, ans = -1;
    while(right >= left){
        if(options[mid].first >= x){
            ans = mid;
            right = mid - 1;
        } 
        else left = mid + 1;
        mid = (left+right)/2;
    }
    cout<<options[ans].second.first<<" "<<options[ans].second.second<<endl;

}


Measured memory_bytes: 6228
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  scanf("%d %d",&n,&k);
  int arr[n];
  int dp[100001];
  memset(dp,1000000,sizeof(dp));
  for(int i=0;i<n;i++){
  scanf("%d",&arr[i]);
  }
  dp[0]=0;
  dp[1]=abs(arr[1]-arr[0]);
  for(int i=2;i<n;i++){
    
  for(int j=1;j<=min(i,k);j++){
  dp[i]=min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j]));
    }
  }
    
  
  printf("%d",dp[n-1]);
  return 0;
}

Measured memory_bytes: 1024
n = gets.to_i
a = gets.split(' ').map(&:to_i)
        b = gets.split(' ').map(&:to_i)
sum = 0
n.times do |s|
    if a[s] >= b[s]
        sum = sum + b[s]
    else
        sum = sum + a[s]
        b[s] = b[s] - a[s]
        if a[s+1] >= b[s]
            sum = sum + b[s]
            a[s+1] = a[s+1] - b[s]
        else
            sum = sum + a[s+1]
            a[s+1] = 0
        end
    end
end
puts sum

Measured memory_bytes: 15400
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
    string s; cin >> s;
    int n = s.size();
    int ans = 0;
    rep(i,n-1){
        if(s[i] != s[i+1]) ans ++;
    }
    cout << ans << endl;
}

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

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

	int maxv = 0;
	int sum = 0;
	int *L = new int[N];
	for( int i = 0; i < N; i++ )
	{
		cin >> L[i];
		maxv = max( maxv, L[i] );
		sum += L[i];
	}

	cout << (( maxv < sum-maxv )? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>


using namespace std;

int main() {
    int N,i,sum;

    cin >> N;
    i = N;
    while(i > 0){
        sum += i % 10;
        i /= 10;
    }

    if(N % sum == 0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <map>
#include <stack>
using namespace std;

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

bool isp(int x){
  if(x<=1)return false;
  if(x==2)return true;
  if(x%2==0)return false;
  for(int y=3;y*y<=x;y+=2){
    if(x%y==0)return false;
  }
  return true;
}

int n;
int x[125];
int cap[252][252];
int main(void){
  scanf("%d",&n);
  REP(i,n)scanf("%d",x+i);
  map<int,int> M;
  REP(i,n){
    M[x[i]] ^= 1;
    M[x[i]+1] ^= 1;
  }
  vector<int> even,odd;
  for(auto P : M)if(P.second==1){
    (P.first%2==0 ? even : odd).push_back(P.first);
  }
  int ne = even.size();
  int no = odd.size();
  n = ne + no + 2;
  int s = ne+no;
  int t = ne+no+1;
  REP(i,ne)cap[s][i] = 1;
  REP(i,no)cap[ne+i][t] = 1;
  REP(i,ne)REP(j,no){
    int d = abs(even[i]-odd[j]);
    if(d<3)continue;
    if(isp(d)){
      cap[i][ne+j] = 1;
    }
  }
  int f = 0;
  while(true){
    vector<int> bef(n,-1);
    vector<bool> vstd(n,false);
    stack<int> S;
    S.push(s);
    vstd[s] = true;
    while(S.size()){
      int p = S.top(); S.pop();
      if(p==t)break;
      REP(i,n)if(cap[p][i] && !vstd[i]){
        vstd[i] = true;
        bef[i] = p;
        S.push(i);
      }
    }
    if(bef[t]==-1)break;
    f++;
    int cur = t;
    while(true){
      int nxt = bef[cur];
      if(nxt==-1)break;
      cap[nxt][cur] = 0;
      cap[cur][nxt] = 1;
      cur = nxt;
    }
  }
  int ans = 0;
  ans += f;
  ans += (ne-f);
  ans += (no-f);
  if((ne-f)%2==1)ans++;
  printf("%d\n",ans);
}


Measured memory_bytes: 512
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

const MOD = 1000000007

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := make([]int, n)

	m := map[int]int{}

	for i := 0; i < n; i++ {
		a[i] = nextInt()
		m[a[i]]++
	}

	if n%2 == 0 {
		for k, v := range m {
			if (k%2 != 1) || (v != 2) {
				fmt.Println(0)
				return
			}
		}
	}
	ans := 1
	for k, v := range m {
		if (k == 0 && v != 1) || (k != 0 && v != 2) {
			fmt.Println(0)
			return
		}

		ans = ans * v % MOD
	}

	fmt.Println(ans)
	// if n%2 == 0 {

	// } else {
	// 	sum := int(math.Pow(2, float64(n-1/2)))

	// 	for i := n - 3; i >= 1; i-- {
	// 		sum *= i
	// 	}
	// 	fmt.Println(sum)
	// }

}


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

namespace Recursion___Divide_and_Conquer
{
    class Program
    {
        static Queue<int> queue;

        static void Main(string[] args)
        {
            queue = new Queue<int>();
            Console.ReadLine();
            var A = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var sum = 0;
            for (int i = 0; i < A.Length; i++)
            {
                queue.Enqueue(A[i]); sum += A[i];
            }

            Console.ReadLine();
            var m = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            for (int i = 0; i < m.Length; i++)
            {
                var canMake = false;
                if (sum/2 <m[i]) canMake = CanMake(sum - m[i]);
                else canMake = CanMake(m[i]);
                if (canMake) Console.WriteLine("yes");
                else Console.WriteLine("no");
            }
        }

        static bool CanMake(int n)
        {
            if (n < 0) return false;
            if (n == 0 || queue.Contains(n)) return true;
            var c = queue.Count;
            for (int i = 0; i < c; i++)
            {
                var m = queue.Dequeue();
                if (CanMake(n - m)) { queue.Enqueue(m); return true; }
                queue.Enqueue(m);
            }
            return false;
        }
    }
}

Measured memory_bytes: 10408
from collections import Counter
from functools import reduce
# import statistics
import bisect
import copy
import fractions
import math
import pprint
pp = pprint.PrettyPrinter(width = 300)
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers):
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v):
    # ノードに訪れた
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  # そもそもvとv2が辺でつながっていない
            continue
        if visited[v2] == True:  # もう見た
            continue
        dfs(v2)


# dp
n = II()
s = [II() for i in range(n)]
tmp = 10010
dp = [[0 for i in range(tmp)] for j in range(n+1)]
dp[0][0] = 1
for i in range(n):
    for j in range(tmp):
        if s[i] <= j:
            dp[i+1][j] = dp[i][j-s[i]] or dp[i][j]
        else:
            dp[i+1][j] = dp[i][j]

ans = 0
for i, num in enumerate(dp[n]):
    if num == 1 and i % 10 != 0:
        ans = i
print(ans)


Measured memory_bytes: 13752
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			int a = Integer.parseInt(br.readLine());

			System.out.println(a*a*a);
		}
	}
}

Measured memory_bytes: 25380
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll cap[105][105]; int par[105];
vector<int>adj[105];
const ll inf=1e12;
ll bfs(){
	memset(par, -1, sizeof(par));
	par[0]=-2;
	queue<pair<int, ll> >q;
	q.push({0, inf});
	for(;!q.empty();q.pop()){
		int nw=q.front().first; ll flow=q.front().second;
	//	cout<<nw<<" "<<flow<<" "<<par[nw]<<endl;
		for(int nx:adj[nw]) if(par[nx]==-1 && cap[nw][nx]>0){
			par[nx]=nw;
			ll nflw=min(flow, cap[nw][nx]);
		//	for(int i=1; i<=6; i++) cout<<par[i]<<" "; cout<<endl;
			if(nx==101) return nflw;
			q.push({nx, nflw});
		}
	}
	return 0;
}
ll maxflow(){
	ll flow=0, nflw;
	for(nflw=bfs();nflw;nflw=bfs()){
		flow+=nflw;
		int nw=101;
		while(nw!=0){
			int bf=par[nw];
			cap[bf][nw]-=nflw;
			cap[nw][bf]+=nflw;
			nw=bf;
		//	cout<<nw<<" "<<par[nw]<<endl;
		}
	}
	return flow;
}
void addedge(int u, int v, ll cp){
	cap[u][v]=cp;
	adj[u].push_back(v);
	adj[v].push_back(u);
}
int n, a[105];
int main(){
	scanf("%d", &n);
	for(int i=1; i<=n; i++) scanf("%d", &a[i]);
	ll optimal=0ll;
	for(int i=1; i<=n; i++){
		if(a[i]>0){
			optimal+=a[i];
			addedge(i, 101, 1ll*a[i]);
		}else{
			addedge(0, i, -1ll*a[i]);
		}
		for(int j=2*i; j<=n; j+=i)
			addedge(i, j, inf);
	}
	/*for(int i=0; i<=101; i++) if(adj[i].size()){
		for(int j:adj[i]){
			if(cap[i][j]){
				printf("%d %d %lld\n", i, j, cap[i][j]);
			}
		}
	}*/
	ll mincut=maxflow();
	printf("%lld\n", optimal-mincut);
	return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {

	public static long answer = 0;
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		String s = in.next();
		
		if ((s.charAt(0) == s.charAt(1) && s.charAt(1) == s.charAt(2)) || 
			(s.charAt(1) == s.charAt(2) && s.charAt(2) == s.charAt(3))) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 22996
from itertools import combinations
n, m, x = map(int, input().split())

a = [[0 for j in range(m)] for i in range(n)]
c = [0] * n

for i in range(n):
    ca = list(map(int, input().split()))
    for j in range(m):
        c[i] = ca[0]
        a[i][j] = ca[j+1]

for i in range(m):
    s = 0
    for j in range(n):
        s += a[j][i]
    if s < x:
        print(-1)
        exit()

s = 1000000000

for i in range(1, n+1):
    for j in list(combinations(range(n), i)):
        t = [0] * m
        S = 0
        for k in range(len(j)):
            S += c[j[k]]
            for l in range(m):
                t[l] += a[j[k]][l]
        p = s
        s = min(s, S)
        for y in range(m):
            if t[y] < x:
                s = p
                break
print(s)


Measured memory_bytes: 9384
# -*- coding: utf-8 -*-
# 標準入力を取得
S = input()

# 求解処理
N = len(S)
ans = 0
ACGT = ["A", "C", "G", "T"]
for i in range(N):
    if S[i] not in ACGT:
        continue
    length = 1
    for j in range(i + 1, N):
        if S[j] not in ACGT:
            break
        length += 1
    ans = max(ans, length)

# 結果出力
print(ans)

Measured memory_bytes: 9060
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "First" << endl; else cout << "Second" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl; }}


signed main(){

    int N, K; cin >> N >> K;
    vec a(N); readv(a);

    vec G(K + 1);
    G[0] = 0;
    FOR(i, 1, K + 1){
        set<int> s;
        REP(j, N) if(i - a[j] >= 0) s.insert(G[i - a[j]]);
        int tmp = 0;
        bool f = false;
        for(auto v: s){
            if(v != tmp){
                G[i] = tmp;
                f = true;
                break;
            }else tmp++;
        }
        if(!f) G[i] = tmp;
    }
    //REP(i, K + 1) cout << G[i] << endl;
    ANS(G[K]);
    
    return 0;
}

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

// for loop
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

// abbreviati
#define PB(v) push_back(v)
#define MP(A,B) make_pair(A,B)
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

// constant
const int INF = 1<<30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

/***Snippet***************************************************
ifelse, isprime, torad, todeg, lcm, bfs,chmin,chmax
**************************************************************/

// adjacency list
vector<int> to[100005];

// Graph
using Graph = vector<vector<int>>;

// Grid
int H,W;
vector<vector<int>> field;

// 4方向への移動ベクトル
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m; cin >> n >> m;
    vector<bool> a(n+1,true);
    rep(i,0,m){
        int b; cin >> b;
        a[b]=false;
    }


    vector<ll> dp(n+1);
    // dp[0]=1;
    // rep(now,0,n){
    //     rep(next,now+1,min(n,now+2)){
    //         if(a[next]){
    //             dp[next]+=dp[now];
    //             dp[next]%=MOD;
    //         }
    //     }
    // }

    dp[0]=1;
    dp[1]=1;
    rep(i,2,n+1){
        if(a[i-1]){
            dp[i]+=dp[i-1];
        }
        if(a[i-2]){
            dp[i]+=dp[i-2];
        }
        dp[i]%=MOD;
    }



    cout << dp[n] ENDL;
    return 0;
}

Measured memory_bytes: 6356
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <cstdlib>
#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
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {

	ll N,K;
	cin >> N>>K;
	vector<ll> P(N);
	rep(i, N) {
		cin >> P.at(i);
	}
	sort(P.begin(), P.end());
		ll an = 0;
		rep(i, K) {
			an += P.at(i);
		}
		cout << an << endl;
}


Measured memory_bytes: 3604
import std.stdio, std.algorithm, std.range, std.conv, std.string;
import core.stdc.stdio;
// foreach, foreach_reverse, writeln

void main() {
	int n;
	scanf("%d", &n);
	int[] a = new int[n];
	int[] b = new int[n];
	foreach (i; 0..n) scanf("%d", &a[i]);
	foreach (i; 0..n) scanf("%d", &b[i]);
	int ans = 0;
	foreach (k; 0..29) {
		int mask = (1<<k)-1;
		int s = 0;
		if (n&1) {
			foreach (x; a) s ^= x>>k&1;
			foreach (x; b) s ^= x>>k&1;
		}
		int[] c = new int[n];
		c[] = b[]&mask;
		sort(c);
		auto sorted = assumeSorted(c);
		foreach (x; a) {
			x &= mask;
			int l = n - to!int(sorted.lowerBound((1<<k)-x).length);
			s ^= l&1;
		}
		ans |= s<<k;
	}
	writeln(ans);
}



Measured memory_bytes: 5628
#pragma GCC optimize ("O2")
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"
#pragma GCC diagnostic ignored "-Wsign-compare"

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

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, A) for (auto & a : A)
#define all(a) (a).begin (), (a).end ()
#define f first
#define s second

typedef long long ll;

const ll MOD = 1e+9+7;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MAXN = 1e+6+7;

vector <vector <int>> tree;
int n;

void update (int p, char c)
{
	//trav (v, tree)
	//{
	//	trav (a, v)
	//		cout << a << ' ';
	//	cout << '\n';
	//}
	//cout << "-----------------------------------------\n";
	int i, j; p += n;
	for (j = 0; j < 26; ++j)
		tree[p][j] = 0;
	tree[p][c - 'a'] = 1;
	for (i = p; i > 1; i >>= 1)
		for (j = 0; j < 26; ++j)
			tree[i >> 1][j] = tree[i][j] || tree[i ^ 1][j];
}

int query (int l, int r)
{
	int i, j;
	vector <int> res (26, 0);
	for (l += n, r += n; l < r; l >>= 1, r >>= 1)
	{
		if (l&1)
		{
			for (j = 0; j < 26; ++j)
				res[j] = res[j] || tree[l][j];
			++l;
		}
		if (r&1)
		{
			--r;
			for (j = 0; j < 26; ++j)
				res[j] = res[j] || tree[r][j];
		}
	}
	int sum = 0;
	trav (a, res) if (a) ++sum;
	return sum;
}

int main ()
{
	ios_base::sync_with_stdio (0);
	cin.tie (0);
	int tc = 1; //cin >> tc;
	while (tc--)
	{
		int i, j, q;
		string s;
		cin >> n >> s >> q;
		
		tree.resize (2*n, vector <int> (26, 0));
		for (i = 0; i < n; ++i)
			tree[i + n][s[i] - 'a'] = 1;
		for (i = n - 1; i > 0; --i)
			for (j = 0; j < 26; ++j)
				tree[i][j] = tree[i << 1][j] || tree[i << 1 | 1][j];
		
		for (int qqq = 0; qqq < q; ++qqq)
		{
			int type; cin >> type;
			if (type == 1)
			{
				int pos; char c; cin >> pos >> c; --pos;
				while (c < 'a' || 'z' < c) cin >> c;
				//cout << pos << ' ' << c << '\n';
				update (pos, c);
			}
			else
			{
				int l, r; cin >> l >> r; --l;
				cout << query (l, r) << '\n';
			}
		}
		//trav (v, tree)
		//{
		//	trav (c, v)
		//		cout << c << ' ';
		//	cout << '\n';
		//}
		//cout << "=================================================\n";
	}

	return 0;
}



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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;

using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;
using vll = vector<ll>;

int calc(vii& dp, const string& x, const string& y) {
    int m = x.size(), n = y.size();

    rep(i, 0, m) {
        rep(j, 0, n) {
            if (x[i] == y[j]) {
                dp[i + 1][j + 1] = dp[i][j] + 1;
            } else {
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
            }
        }
    }
    return dp[m][n];
}

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

    int q;
    cin >> q;

    rep(i, 0, q) {
        string x, y;
        cin >> x >> y;

        vii dp(x.size() + 1, vi(y.size() + 1, 0));
        cout << calc(dp, x, y) << endl;
    }

    return 0;
}


Measured memory_bytes: 6832
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define en '\n'
#define rep(i,n)    for(ll i=0; i<n; i++)
#define rep1(i,a,b)    for(ll i=a; i<=b; i++)
#define repVect(i,n)    for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(1);
#define yes cout<<"YES"<<'\n'
#define no cout<<"NO"<<'\n'
using namespace std;

int main()
{
    godspeed
    ll i,n,k;
    string s;
    map<ll,ll>v;
    cin>>n;
    ll a[n];
    for(i=0; i<n; i++)
    {
        cin>>a[i];
        v[a[i]]++;
    }
    ll sum=0;
    for(auto it:v)
    {
        ll tmp=it.se;
        sum+=(tmp*(tmp-1))/2;
    }

    for(i=0; i<n; i++)
    {
        ll tmp=sum-v[a[i]]+1;
        cout<<tmp<<en;
    }

    return 0;
}


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

int main() {
int n,k;
  cin>>n>>k;
  vector<char> d(k);
  rep(i,k) cin>>d[i];

  bool x =true; 
  while(x){
    int count=0;
    string num=to_string(n);
  rep(i,num.size()){
    rep(j,k){
    if(num[i]==d[j]) count++;
    }
  }
    if(count!=0){
    n++;
      x=true;
    }else{
    x=false;
    }
  }
    
  
    
  
  cout<<n<<endl;

}

Measured memory_bytes: 256
from collections import deque
import sys, copy, itertools
input = sys.stdin.readline

n = int(input())
A = list(map(int,input().split()))

ans = 0
x = 0

for i in range(1,n):
  if A[i-1] > A[i]:
    x = A[i-1] - A[i]
    A[i] = A[i] + x
    ans += x

#print(A)
print(ans)

Measured memory_bytes: 93656
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
    int b = sc.nextInt();
    System.out.println(a*a-b);
  }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}


struct edge { int to; ll cost; };
struct dijkstra {
    vector<vector<edge>> g;
    vector<ll> d;
    vector<int> from_v;
    int V;
    
    dijkstra(int v){
        V = v;
        d.resize(V);
        g.resize(V);
        from_v.assign(V,-1);
    }
    
    void solve_d(int s){
        from_v[s] = 1;
        pq1<pair<ll,int>> que;
        rep(i,V) d[i] = infl;
        d[s] = 0;
        que.push({0,s});
        
        while (!que.empty()) {
            auto p = que.top();
            que.pop();
            int v = p.se;
            if(d[v] < p.fi) continue;
            rep(i,int(g[v].size())){
                edge e = g[v][i];
                if(d[e.to] > d[v] + e.cost){
                    d[e.to] = d[v] + e.cost;
                    from_v[e.to] = v;
                    que.push({d[e.to],e.to});
                }
            }
        }
    }
    
    int dis(int a){
        return d[a];
    }
};



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

    int N,M,s,t;
    cin >> N >> M >> s >> t;
    s--,t--;
    dijkstra A(N),B(N);
    rep(i,M){
        int u,v,a,b;
        cin >> u >> v >> a >> b;
        u--,v--;
        A.g[u].pb({v,a});
        A.g[v].pb({u,a});
        B.g[u].pb({v,b});
        B.g[v].pb({u,b});
    }
    
    A.solve_d(s);
    B.solve_d(t);
    
    //outve(A.d);
    //outve(B.d);
    
    pq1<pair<ll,int>> que;
    rep(i,N) que.push({A.d[i]+B.d[i], i});
    
    vl ans;
    
    rep(i,N){
        
        while (!que.empty()) {
            if(que.top().se < i) que.pop();
            else break;
        }
        
        ans.pb(que.top().fi);
        
        
    }
    
    rep(i,int(ans.size())) cout << 1000000000000000 - ans[i] << endl;
    
    

    return 0;
}


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

using namespace std;

const int N = 1e5 + 5;

int n, a[N];

int main(){
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);

    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += a[i] / 2;
        a[i] %= 2;
        if (a[i] == 1 && i < n && a[i + 1] > 0) {
            a[i + 1]--;
            ans++;
        }
    }

    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;
public class Main{

    public static void main(String[] args) {
// 標準入力からデータを読み込む準備
                Scanner sc = new Scanner(System.in);
// 2つの文字の固まりをそれぞれ整数値と想定して読み込む
                int a = sc.nextInt();
                int b = sc.nextInt();
                int area = a*b/* ここを変えて面積を求めよう */;
                int length = 2*a + 2*b /* ここを変えて周囲の長さを求めよう */;
                System.out.println(area + " " + length);
    }
}



Measured memory_bytes: 26108
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<set>
#include<map>
#include<utility>
#define ul unsigned long long int
#define ll long long int
#define MAX 1000000+1
using namespace std;
#define F first
#define S second
#define pi 2*acos(0.0)
#define PB push_back
#define LSTAGE 1



int main()
{

    int n, m;
    cin >> n >> m;
    string s[n];
    for(int i = 0; i < n; i++)
        cin >> s[i];
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            if(s[i][j]=='.')
            {
            int c = 0;
                if(i-1>=0 )
                {
                    if(j>=1 && s[i-1][j-1]=='#')
                        c++;
                    if(s[i-1][j]=='#')
                        c++;
                    if(j+1 < m && s[i-1][j+1]=='#')
                        c++;
//                cout << c<< endl;
                }
                if(j-1>=0&&s[i][j-1]=='#') c++;
                if(j+1<m && s[i][j+1]=='#') c++;

//                cout << c<< endl;
                if(i+1 < n)
                {
                    if(j-1>=0 && s[i+1][j-1]=='#')
                        c++;
                    if(s[i+1][j]=='#')
                        c++;
                    if(j+1 < m && s[i+1][j+1]=='#')
                        c++;

//                cout << c<< endl;
                }

            s[i][j] = char(c+48);
            }
        }
    }
  for(int i= 0; i < n; i++)  cout << s[i]<<"\n";


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
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; }

const int MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
	int h, a;
	cin >> h >> a;
	int ans = (h+a-1)/a;
	cout << ans << endl;
}

Measured memory_bytes: 256
//#include "bipartite-graph.hpp"
//#include <vector>
//using namespace std;
//int main(){
//	vector<vector<int> > G(4);
//	cout << bipartite_graph(G) << endl;
//}

// AOJ0200
#include <iostream>
#include <vector>
using namespace std;

struct edge {
    edge(){}
    edge(int to, int from, int cost, int time): to(to), from(from), cost(cost), time(time) {}
    int to, from, cost, time;
};

const int INF = 100000000;

int d[101];
edge es[7000];
int n,m;

// 頂点sから各頂点への最短経路を求める
void bellman_ford(int s, bool r){
    for (int i = 0; i < m; ++i) d[i]=INF;
    d[s]=0;
    while(1){
        bool update=false;
        for (int i = 0; i < n*2; ++i) {
            edge e=es[i];
            int cost;
            if(r) cost=e.time;
            else cost=e.cost;
            if(d[e.from]!=INF && d[e.to]>d[e.from]+cost){
                d[e.to]=d[e.from]+cost;
                update=true;
            }
        }
        if(!update) break;
    }
}

int main(){
    while(cin >> n >> m,n+m){
        for (int i = 0; i < n; ++i) {
            int to,from,cost,time;
            cin >> to>>from>>cost>>time;
            es[i]=edge(to-1,from-1,cost,time);
            es[n+i]=edge(from-1,to-1,cost,time);
        }
        int k; cin>>k;
        for (int i = 0; i < k; ++i) {
            int p,q,r;
            cin>>p>>q>>r;
            bellman_ford(p-1,r);
            cout<<d[q-1]<<endl;
        }
    }
}

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

#define FOR(i, j, k) for(int i=j; i<k; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {

    string s; cin >> s;
    int ans = 0;
    REP(i, s.size()) {
        if (s[i] == '+') ans++;
        else ans--;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

namespace {

#define VEVE(i, a, b) for (ll i = a, __##i = b; i < __##i; ++i)
#define DYDY(i, a, b) for (ll i = a, __##i = b; i > __##i; --i)
#define RARA(x, seq) for (auto &x : seq)
#define SIZE(x) ((ll)(x.size()))
#define ALL(x) x.begin(), x.end()

typedef int64_t ll;
typedef double dd;
typedef vector<ll> Vec;
const ll INF = 1LL << 60;

void Min(ll& a, ll b) { a = min(a, b); }

void Solve(ll) {
  ll n, l;
  cin >> n >> l;
  Vec xvals(n), takes(n);
  RARA(x, xvals) cin >> x;
  RARA(t, takes) cin >> t;
  xvals.push_back(l);
  const ll m = min(n, ll(2e8) / n) + 2;
  Vec cur(m), pred(m, INF);
  pred[1] = 2 * xvals.front();
  const ll per = 2 * l;
  VEVE(i, 0, n) {
    const ll len = xvals[i + 1] - xvals[i];
    const ll t = takes[i] % per;
    const ll same = takes[i] + (per - t) % per;

    // cost of enter left leave right
    const ll up = takes[i] + (2 * xvals[i] - t + per) % per;

    // cost of enter right leave left
    const ll dw = takes[i] + (2 * (l - xvals[i]) - t + per) % per;

    fill(ALL(cur), INF);
    VEVE(j, 1, m - 1) {
      Min(cur[j], pred[j] + same + 2 * len * j);
      Min(cur[j - 1], pred[j] + dw + 2 * len * (j - 1));
      Min(cur[j + 1], pred[j] + up + 2 * len * (j + 1));
    }
    swap(pred, cur);
  }
  const ll res = pred[0];
  cout << res << endl;
}

void Init() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
}
}

int32_t main() {
#ifdef AZN
  freopen("input.txt", "r", stdin);
#endif
  Init();
  ll tests = 1;
  VEVE(test, 1, tests + 1) Solve(test);
  return 0;
}


Measured memory_bytes: 9344
// 問題の URL を書いておく
// 

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

using ll = int64_t;

int main(int, const char**)
{
    int n;
    cin >> n;
    vector<int> ans(n, 0);
    rep(i, n - 1)
    {
        int a;
        cin >> a;
        a--;
        ans[a]++;
    }
    rep(i, n)
    {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 4056
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
//#define int ll
typedef long long ll;

const int md = 1000000007;
const int INF = 1<<30;
using namespace std;

int main(){
    int n; cin >> n;
    int p[n];
    rep(i,n) cin >> p[i];

    sort(p,p+n);

    ll ans = 0;
    rep(i,n){
        ans += p[i];
    }
    cout << ans - (p[n-1]/2) << endl;
    
}


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

int main() {
   int N,T,A;
  cin >> N >> T >> A;
  
  int H[1000];
  int answer;
  double min_dif=10000;
  double temp;
  for(int i=0;i<N;i++){
    cin >> H[i];
    temp = double(T)-double(H[i])*0.006;
    if(abs(temp-A)<min_dif){
      min_dif = abs(temp-A);
      answer = i+1;
    }
  }
  cout << answer << endl;
}


Measured memory_bytes: 256