akhauriyash/Code-Regression huggingface dataset:
n,W=map(int,raw_input().split())
wv=[map(int,raw_input().split()) for _ in xrange(n)]
diff=[[0] for _ in xrange(4)]
for i in xrange(n):
    w,v=wv[i]
    diff[w-wv[0][0]].append(v)
for i in xrange(4):
    diff[i].sort(reverse=True)
ans=0
for i in xrange(len(diff[0])):
    for j in xrange(len(diff[1])):
        for k in xrange(len(diff[2])):
            for l in xrange(len(diff[3])):
                if wv[0][0]*(i+j+k+l)+(j+2*k+3*l)<=W:
                    ans=max(ans,sum(diff[0][0:i])+sum(diff[1][0:j])+sum(diff[2][0:k])+sum(diff[3][0:l]))
print ans

Measured memory_bytes: 33772
#include<iostream>
#include<iomanip>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<math.h>
#include<unordered_set>
using namespace std;
const int INF = 2147483647;
const int MAX = 100000;

int N, K;
int A[MAX], B[MAX];

long long solve(int x) {
	long long cnt = 0;

	for (int j = 0; j < N; j++) {
		if ((x | A[j]) == x) {
			cnt += B[j];
		}
	}
	return cnt;
}

int main(){
	
	long long ans = 0;

	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> A[i] >> B[i];
	}

	ans = max(ans, solve(K));
	for (int i = 0; i < 30; i++) {
		if (K & (1 << i)) {
			int x = (K ^ (1 << i)) | ((1 << i) - 1);
			int cnt = 0;
			ans = max(ans, solve(x));
		}
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <vector>

int main() {
  size_t N;
  int M, T;
  scanf("%zu %d %d", &N, &M, &T);

  std::vector<int> a(N);
  for (auto& ai: a) scanf("%d", &ai);
  a.insert(a.begin(), -M);

  int t = 0;
  for (size_t i = 1; i <= N; ++i) {
    t += std::max(0, a[i]-a[i-1]-2*M);
  }
  t += std::max(0, T-a[N]-M);
  printf("%d\n", t);
}



Measured memory_bytes: 2772
N, M=map(int, input().split())
if M>0:
  a=[int(input()) for i in range(M)]

  if a[0]==1:
    way=[1, 0]
    a.remove(1)
  else:
    way=[1, 1]
else:
  a=[]
  way=[1, 1]
  
for i in range(2, N+1):
  if len(a)>0:
    if i==a[0]:
      a.remove(i)
      way=[way[1], 0]
    else:
      way=[way[1], sum(way)]
  else:
    way=[way[1], sum(way)]
    
print(way[1]%1000000007)

Measured memory_bytes: 7080
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;
 
int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}
 
ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

bool is_prime(long long N){
    if (N == 1) return false;
    for (long long i = 2;i * i <= N;i++){
        if (N % i == 0) return false;
    }
    return true;
}
 
ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}
 
double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}
 
 
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 
 
///////////////////////////////////////////////////////////////////////////////////

int main(){
    int n;
    cin >> n;
    map<long long, int> mp;
    bool ok = false;
    for (int i = 0;i < n;i++){
        long long a;
        cin >> a;
        mp[a]++;
    }
    long long m1 = 0, m2 = 0;
    for (auto v:mp){
        if (v.second >= 2){
            if (v.first > m1){
                m2 = m1;
                m1 = v.first;
            }
            else if (v.first > m2){
                m2 = v.first;
            }
        }
    }

    if (m1 == 0 || m2 == 0){
        cout << 0 << endl;
        return 0;
    }

    if (mp[m1] >= 4){
        cout << m1 * m1 << endl;
    } else{
        cout << m1 * m2 << endl;
    }
}

Measured memory_bytes: 9652
#include<bits/stdc++.h>
using namespace std;
string s[3];
int get(char x) {
  if (x=='a') return 0;
  if (x=='b') return 1;
  return 2;
}
char Mp[3]={'A','B','C'};
int p[3],nw=0;
int main() {
  cin>>s[0]>>s[1]>>s[2];
  while (1) {
    if (p[nw]==s[nw].length()) {
      cout<<Mp[nw];
      return 0;
    }
    ++p[nw];
    nw=get(s[nw][p[nw]-1]);
  }
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

int calc(int x, char op, int y)
{
    switch(op)
    {
    case '+': return x+y;
    case '-': return x-y;
    case '*':
    default:  return x*y;
    }
}

string dfs(int[] vs, string[] e)
{
    if(vs.length==1) return vs[0]==10?e[0]:[];
    foreach(i;1..vs.length)
        foreach(op;"+-*")
        {
            auto r = dfs(vs[0..i-1]~[calc(vs[i-1],op,vs[i])]~vs[i+1..$],
                         e[0..i-1]~["("~e[i-1]~[op]~e[i]~")"]~e[i+1..$]);
            if(r !is null) return r;
        }
    return [];
}

string solve(int[] a, int[] b)
{
    if(b is null)
        return dfs(a,a.map!(to!string).array());
    foreach(i;0..b.length)
    {
        auto r = solve(a~b[i],b[0..i]~b[i+1..$]);
        if(r !is null)
            return r;
    }
    return [];
}

void main()
{
    foreach(vs;stdin.byLine().map!(s=>s.split().map!(to!int).array())())
    {
        if(vs.all!"a==0"()) break;
        auto r = solve([],vs);
        writeln(r is null?"0":r);
    }
}

Measured memory_bytes: 2032
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int N = 3001;
using ll = long long;
int n;
ll arr[N], dp[N][N][2];
int main()
{
    scanf("%d", &n);
    for(int i = 0; i < n; i++) scanf("%lld",  &arr[i]);
    for(int sz = 1;sz <= n; sz++) {
        for(int i = 0; i < n; i++) {
            int j = i+sz-1;
            if(j >= n) continue;
            if(sz==1) {
                dp[i][j][1] = arr[i];
                dp[i][j][0] = 0;
                continue;            
            }
            for(int k = 1; k >= 0; k--) {
                int x, y;
                if(k==1) {
                    //dp[i][j][1] = max(arr[i]+dp[i+1][j][0], arr[j]+dp[i][j-1][0]);
                    ll h1=0, h2 = 0;
                    h1 = arr[i]+dp[i+1][j][0];
                    h2 = arr[j] + dp[i][j-1][0];
                    if(h1 > h2) {
                        dp[i][j][1] = h1;
                        x = i+1, y = j;
                    }
                    else {
                        dp[i][j][1] =h2;
                        x = i, y = j-1;
                    }
                }
                else {
                    dp[i][j][0] = dp[x][y][1];
                }
            }
        }
    }
    printf("%lld\n", dp[0][n-1][1]-dp[0][n-1][0]);
    return 0;
}

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

public class Main {

    class Point implements Comparable<Point> {
        int x, y;

        Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public String toString() {
            return "[" + this.x + ", " + this.y + "]";
        }

        @Override
        public int compareTo(Point that) {
            if (this.y == that.y) {
                return this.x - that.x;
            }
            return this.y - that.y;
        }
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        Point[] arr = new Point[m];

        for (int i = 0;  i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            arr[i] = new Point(a, b);
        }

        Arrays.sort(arr);

//        debug(arr);

        int count = 1;
        int currentEnd = arr[0].y;

        for (int i= 1 ;i < m; i++) {
            Point p = arr[i];
            if (currentEnd <= p.x) {
                currentEnd = p.y;
                count++;
            }
        }
        System.out.println(count);
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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


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

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX];

// テーブルを作る前処理
/*
void COMinit() {
    fac[0] = fac[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
    }
}
*/

ll pow_kai(ll a,ll n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a%MOD;
    }
    a = a*a%MOD;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    ll tmp=1;
    for(ll i=n;i>=n-k+1;i--) tmp = (tmp*i)%MOD;

    return (tmp * pow_kai(fac[k],MOD-2)) % MOD;
}




int main()
{
    ll N;

    cin >> N ;

    ll h[N],dp[N];

    rep(i,N) cin >> h[i];

    dp[0]=0;
    dp[1]=abs(h[0]-h[1]);

    if(N==2){
        cout << dp[1] << endl;
        return 0;
    }

    for(int i=2;i<N;i++){
        dp[i]=min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]));
    }

    cout <<dp[N-1]<< endl;



 
    return 0;

}

Measured memory_bytes: 1792
#include<iostream>
#include<math.h>

using namespace std;


bool isprime(int x) {
	int sqrtx = (int)sqrt(x);

	if (x == 2)return true;
	if (x < 2 || x % 2 == 0)return false;

	for (int i = 3; i <= sqrtx; i += 2) {
		if (x%i == 0)return false;
	}
	return true;
}

int main() {
	int n;
	int PrimeNum = 0;

	cin >> n;
	for (int i = 0; i < n; i++) {
		int Input;
		cin >> Input;
		if (isprime(Input))PrimeNum++;
	}

	cout << PrimeNum << endl;

	return 0;
}

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

using namespace std;

int main(){

    int n;
    cin>>n;

    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans[n];
    memset(ans,-1,sizeof ans);
    ans[0]=0;
    for(int i=0;i<n-1;i++){

        if(ans[i+1]==-1){
            ans[i+1]=abs(a[i+1]-a[i])+ans[i];
        }
        else{
            ans[i+1]=min(ans[i+1],abs(a[i+1]-a[i])+ans[i]);
        }
        if(i<n-2){
            if(ans[i+2]==-1){
                ans[i+2]=abs(a[i+2]-a[i])+ans[i];
            }
            else{
                ans[i+2]=min(ans[i+2],abs(a[i+2]-a[i])+ans[i]);
            }
        }

    }
    cout<<ans[n-1];
}


Measured memory_bytes: 1024
N, K = map(int, input().split())
A = list(map(int, input().split()))
Kb = format(K, 'b')
f = lambda x: sum(a ^ x for a in A)
table = [f(2 ** i) - f(0) for i in range(42)]
candy = {i: x for i, x in enumerate(table) if x > 0 and 2 ** i <= K}
mask = [K]
for i in range(len(Kb) - 1, 0, -1):
    if K & (1 << i):
        mask += [K ^ (1 << i) | ((1 << i) - 1)]
res = 0
for m in mask:
    tmp = 0
    for b in range(42):
        if b in candy and m & (1 << b):
            tmp += candy[b]
    res = max(res, tmp)
print(res + f(0))

Measured memory_bytes: 14836
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void) {
	int n, k, d, a;
	cin >> n >> k;
	vector<int> v(n, 0);
	for (int i = 0; i < k; ++i) {
		cin >> d;
		for (int j = 0; j < d; ++j) {
			cin >> a;
			++v[a - 1];
		}
	}
	int ans = count(v.begin(), v.end(), 0);
	cout << ans;
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
ll L[N], R[N];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<ll> vec;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        vec.push_back(x);
    }
    sort(vec.begin(), vec.end());
    ll g = 0;
    for (int i = 0; i < n; i++) {
        g = __gcd(g, vec[i]);
        L[i] = g;
    }
    g = 0;
    for (int i = n - 1; i >= 0; i--) {
        g = __gcd(g, vec[i]);
        R[i] = g;
    }
    ll res = 0;
    for (int i = 1; i < n - 1; i++) {
        res = max(res, __gcd(L[i - 1], R[i + 1]));
    }
    cout << max({res, L[n - 2], R[1]});
    return 0;
}

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

public class Main {
	public static void main(String[] age)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String ans = br.readLine();
		int a = Integer.parseInt(ans);
		String[] input = br.readLine().split(" ");
		StringBuilder sb = new StringBuilder();
		int i = 0;
		long z = 0;
		int[] you = new int[a];

		for( i=0 ; i<a ; i++ ){
			you[i] = Integer.parseInt(input[i]);
			z = z+you[i];
		}

		int x = you[0];
		int y = you[0];

		for ( i=1 ; i<a ; i++ ){
			if( you[i]>x ) x = you[i];
			if( you[i]<y ) y = you[i];
		}
		sb.append(y).append(" ").append(x).append(" ").append(z);
		System.out.println(sb);
	}
}

Measured memory_bytes: 28456
#include <iostream>
#include <algorithm>
#include <sstream>
#define OPEN 0
#define MAXN 25
using namespace std;
int ans;
int N;
int value[MAXN];
int cost[MAXN];
void DFS(int level, int X, int Y) {
	if (level == N) {
		if (X - Y > ans)ans = X - Y;
		return;
	}
	DFS(level + 1, X + value[level], Y + cost[level]);
	DFS(level + 1, X, Y);
	return;

}
int main() {
#if OPEN
	freopen("input.txt", "r", stdin);

#endif
	
	// N equals to how many gems we have
	//value of each gem
	//cost of each gem
	stringstream ss;
	while (cin >> N) {
		string str;
		getline(cin, str);	//eat the space
		for (int j = 0; j < 2; j++) {
			getline(cin, str);
			ss << str;
			int t;
			int i = 0;
			while (ss >> t) {
				if (!j)
					value[i] = t;
				else
					cost[i] = t;
				i++;
			}
			ss.str("");
			ss.clear();

		}
		//each case
		ans = -10000;
		DFS(0, 0, 0);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
   int a,b;
   scanf("%d %d",&a,&b);
   if(a<b) {
    printf("a < b\n");
   }
   else if(a>b) {
    printf("a > b\n");
   }
   else if(a == b) {
    printf("a == b\n");
   }

    return 0;
}



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

int main(){
	int n, count=0;
	long long A,B,tmp;
	
	cin>>n>>A>>B;
	
	for(int i=0;i<n;i++){
		cin>>tmp;
		if(tmp<A||tmp>=B) count++;
	}
	
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
#define _(_1,_2,_3,N,...)N
#define pr(...) _(__VA_ARGS__,pr3,pr2,pr1)(__VA_ARGS__)
template<C T>void pr1(T a){cout<<a;ln;}
template<C T,C T2>void pr2(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr3(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n;
  while(R n && n) {
    int x=-MAX,y=MAX;
    bool f=0;
    int a[n];
    rep(i,n) {
      string s;
      R s;
      if(s=="x") {
        a[i]=MAX;
        continue;
      }
      stringstream ss;
      ss << s;
      ss >> a[i];
    }
    
    rep(i,n) {
      if(a[i]==MAX) {
        if(i%2) {
          if(i-1>=0) {
            if(a[i-1]!=MAX) x=max(x,a[i-1]);
            else f=1;
          }
          if(i+1<n) {
            if(a[i+1]!=MAX) x=max(x,a[i+1]);
            else f=1;
          }
        } else {
          if(i-1>=0) {
            if(a[i-1]!=MAX) y=min(y,a[i-1]);
            else f=1;
          }
          if(i+1<n) {
            if(a[i+1]!=MAX) y=min(y,a[i+1]);
            else f=1;
          }
        }
      } else {
        if(i+1==n || a[i+1]==MAX) continue;
        if(i%2==0) {
          if(a[i]>=a[i+1]) f=1;
        } else {
          if(a[i]<=a[i+1]) f=1;
        }
      }
    }
    if(y<=x+1 || f) pr("none");
    else if(x+1==y-1) pr(x+1);
    else pr("ambiguous");
  }
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}


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

int D[30][30];
int c[500][500];

ll cost0[30], cost1[30], cost2[30];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, C;
	cin >> n >> C;
	rep(i,C)rep(j,C) cin >> D[i][j];
	rep(i,n)rep(j,n){
		cin >> c[i][j];
		--c[i][j];
		rep(k,C){
			if((i+j)%3 == 0) cost0[k] += D[c[i][j]][k];
			if((i+j)%3 == 1) cost1[k] += D[c[i][j]][k];
			if((i+j)%3 == 2) cost2[k] += D[c[i][j]][k];
		}
	}
	ll ans = 1e18;
	rep(i,C)rep(j,C)rep(k,C){
		if(i == j || j == k || k == i) continue;
		chmin(ans, cost0[i] + cost1[j] + cost2[k]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4640
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

void solve(){
    vector<int> a(5);
    for(int i=0;i<5;i++){cin>>a[i];if(a[i]==0){cout<<i+1<<endl;return;}}
}

int main()
{
    //freopen("IN.txt","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3624
package main
import (
    "bufio"
    "fmt"
    "os"
    "strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() (int,error) {
    sc.Scan()
    i, e := strconv.Atoi(sc.Text())
    return i,e
}

func min(x int,y int,z int)(ans int){
  ans = x
  if(y < ans){
    ans = y
  }
  if(z < ans){
    ans = z
  }
  return
}

func main(){
  sc.Split(bufio.ScanWords)
  _,_ = nextInt()
  A,_ := nextInt()
  B,_ := nextInt()
  mon1,mon2,mon3 := 0,0,0
  for{
    i,e := nextInt()
    if e != nil{
      break
    }
    if i <= A {
      mon1 ++
    }else if i <= B{
      mon2 ++
    }else{
      mon3 ++
    }
  }
  fmt.Println(min(mon1,mon2,mon3))
}


Measured memory_bytes: 640
N=input()
n=len(N)
ans=0
if n%2==0:
    for i in range(1,n):
        if i%2==0:
            pass
        else:
            ans+=10**i-10**(i-1)
else:
    for i in range(1,n):
        if i%2==0:
            pass
        else:
            ans+=10**i-10**(i-1)
    ans+=int(N)-10**(n-1)+1      
print(ans)        

Measured memory_bytes: 3060
require"prime"
n=gets.to_i
if n==1
  puts 0
  exit
end

def l_eq(ary1,ary2)
  ary1.size.times{|i|
    return false if ary1[i]>ary2[i]
  }
  true
end

primes=Prime.each(n).to_a
prime_count=Hash.new(0)
2.upto(n){|k|
  k.prime_division.each{|p,a|
    prime_count[p]+=a}
}

ans=0
h={}
[[74],[2,24],[4,14],[2,4,4]].each{|factor_nums|
  k=factor_nums.size
  primes.permutation(k){|ps|
    ns=ps.map{|p|prime_count[p]}
    if l_eq(factor_nums,ns)
      key=ps.zip(factor_nums).sort_by(&:first)
      unless h[key]
        ans+=1
        h[key]=true
      end
    end
  }
}
puts ans

Measured memory_bytes: 4348
#include <stdio.h>

int main(void){

  char s[100];

  scanf("%s",s );

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

    if(i%2 ==0){
      if(s[i]=='L'){
        printf("No\n");
        return 0;
      }
    }else{
      if(s[i]=='R'){
        printf("No\n");
        return 0;
      }
    }

  }

printf("Yes\n" );



  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const LL mo=1000000007;
LL x,a,b,y; int n,m;
int main(){
	scanf("%d%d",&n,&m);
	scanf("%lld",&y);
	for (int i=2;i<=n;++i){
		scanf("%lld",&x);
		a+=(x-y)*(i-1)%mo*(n-i+1)%mo;
		a%=mo; y=x;
	}
	scanf("%lld",&y);
	for (int i=2;i<=m;++i){
		scanf("%lld",&x);
		b+=(x-y)*(i-1)%mo*(m-i+1)%mo;
		b%=mo; y=x;
	}
	printf("%lld",a*b%mo);
	return 0;
}

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

using namespace std;
using ll = long long;


int main()
{
    int N,M;cin >> N >> M;
    map<ll, ll> mp;
    for(int i = 0;i < N;i++){
        int A;cin >> A;
        mp[A]++;
    }
    for(int i = 0;i < M;i++){
        int a,b;cin >> a >> b;
        mp[b] += a;
    }
    vector<pair<ll, ll>> p;
    for(auto a : mp)p.push_back(a);
    sort(p.begin(), p.end());
    reverse(p.begin(), p.end());
    ll ans = 0;
    int cnt = 0;
    int i = 0;
    while(1){
        if(cnt + p[i].second <= N){
            ans += p[i].first * p[i].second;
            cnt += p[i].second;
        }else{
            ans += p[i].first * max(N - cnt, 0);
            break;
        }
        i++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 18800
N = gets.to_i - 1
ALP = ('a'..'z').to_a # 26
# A B C 5 % 3:2 AB
ANS = []

n = N
while true do
    i = n % 26
    ANS.push ALP[i]
    n /= 26
    break if n == 0
    n -= 1
end

puts ANS.reverse.inject(:+)


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

using namespace std;

int main (void) {
    int N;
    cin >> N;
    vector<int> a(N);
    for ( int i=0; i<N; i++ ) {
        cin >> a.at(i);
    }

    vector<int> b;
    for ( int i=0; i<N; i++ ) {
        if ( i % 2 == 0 ) {
            b.push_back(a.at(i));
        }
        else {
            b.insert(b.begin(), a.at(i));
        }
    }

    if ( N % 2 == 0 ) {
        for ( int i=0; i<N; i++ ) {
            cout << b.at(i);
            if ( i != N - 1 )
                cout << " ";
        }
    }
    else {
        for ( int i=N-1; i>=0; i-- ) {
            cout << b.at(i);
            if ( i != 0 )
                cout << " ";
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3828
import java.util.Scanner;

class Main{

  private static int solve(String[] play, int H, int W){

    int[][] dp = new int[H][W];
    dp[0][0] = 0;
    
    for(int i = 1; i < play[0].length(); i++){
      if(play[0].charAt(i) == '.')
        dp[0][i] = 1;
      else 
        break;
    }
    
    for(int i = 1; i < H; i++){
      if(play[i].charAt(0) == '.')
        dp[i][0] = 1;
      else 
        //char '#' encountered so make all 0
        break;
    }
    for(int i = 1; i < H; i++){
        for(int j = 1; j < W; j++){
          dp[i][j] = (play[i].charAt(j) == '.' ? (dp[i][j-1] + dp[i-1][j])%INF : 0);
        }
    }
    return dp[H-1][W-1];
  }

  private static final int INF = (int)1e9+7;
  
  public static void main(String... args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		sc.nextLine();
		String[] play = new String[H];

		for (int i = 0; i < play.length; i++) {
			play[i] = sc.nextLine();
		}

		System.out.println(solve(play, H, W));
		if (sc != null)
			sc.close();
	}
}


Measured memory_bytes: 36816
n = gets.to_i
a = gets.split.map(&:to_i)

puts a.join(' ')
(1..a.length - 1).each do |i|
  key = a[i]
  j = i - 1
  while j >= 0 && a[j] > key do
    a[j + 1] = a[j]
    j -= 1
  end
  a[j + 1] = key

  puts a.join(' ')
end

Measured memory_bytes: 6116
while True:
  r, a = input().split()
  if r == "0":
    break
  
  hit = 0
  for x, y in zip(r, a):
    if x == y:
      hit += 1
  
  blow = -hit
  for x in r:
    if x in a:
      blow += 1

  print(hit, blow)


Measured memory_bytes: 5572
#include <stdio.h>
typedef long long int ll;
int main(){
	int n;
	ll a[200000];
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%lld",&a[i]);
	
	for(int i=n-1;i>=0;i-=2)
		printf("%lld ",a[i]);
	
	for(int i=n%2;i<n;i+=2)
		printf("%lld ",a[i]);

	return 0;
}

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

int main() {
    string o, e;
    cin >> o >> e;

    string pw;
    for (int i = 0; i < o.size() + e.size(); i++) {
        if (i % 2 == 0) pw += o[i/2];
        else pw += e[i/2];
    }

    cout << pw << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int m = sc.nextInt();
    	Map<Integer, List<Integer>> root = new HashMap<>();
    	for(int i = 0; i < m; i++) {
	    	int a = sc.nextInt();
	    	int b = sc.nextInt();
    		List<Integer> list = root.get(a);
    		if(list == null) {
    			list = new ArrayList<>();
    			root.put(a,list);
    		}
    		list.add(b);
    		list = root.get(b);
    		if(list == null) {
    			list = new ArrayList<>();
    			root.put(b,list);
    		}
    		list.add(a);
    	}
    	Set<Integer> checkedSet = new HashSet<>();
    	checkedSet.add(1);
    	int[] michi = new int[n - 1];
    	List<Integer> nextCheck = new ArrayList<>();
    	nextCheck.add(1);
    	while(!nextCheck.isEmpty()) {
    		List<Integer> next = new ArrayList<>();
    		for(Integer checking : nextCheck) {
    			List<Integer> toList = root.get(checking);
    			for(Integer to : toList) {
    				if(checkedSet.contains(to)){
    					continue;
    				}
    				michi[to - 2] = checking;
    				checkedSet.add(to);
    				next.add(to);
    			}
    		}
    		nextCheck = next;
    	}
    	System.out.println("Yes");
    	for(int i : michi) {
    		System.out.println(i);
    	}
    }
}

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

class HonestOrUnkind
{
    static void Main(string[] args)
    {
        var people = int.Parse(Console.ReadLine());

        var honestList = new List<List<int>>();
       

        int ans = 0;

        for(var i = 0; i < people; i++)
        {
            var number = int.Parse(Console.ReadLine());
            honestList.Add(new List<int>());

            for (var j = 0; j < number; j++)
            {
                var info = Console.ReadLine().Split(' ');

                honestList[i].Add(int.Parse(info[0]));
                honestList[i].Add(int.Parse(info[1]));
            }
        }

        for(var i = 0; i < Math.Pow(2, people); i++)
        {
            int[] trueOrfalseList = new int[people];
            bool flag = true;
            int total = 0;

            for(var j = 0; j < people; j++)
            {
                trueOrfalseList[j] = ((i >> j) & 1);
            }

            for(var k = 0; k < people;k++)
            {
                if(trueOrfalseList[k] == 1)
                {
                    for(var l = 0; l < honestList[k].Count; l++)
                    {
                        if(l % 2 == 0)
                        {
                            if(trueOrfalseList[honestList[k][l] -1] != honestList[k][l + 1])
                            {
                                flag = false;
                            }
                        }
                    }
                }
            }
            if (flag)
            {
                foreach(var c in trueOrfalseList)
                {
                    if(c == 1)
                    {
                        total++;
                    }
                }
            }
            ans = Math.Max(ans, total);
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 15316
def fdigit(a,b):
    if len(str(a)) > len(str(b)):
        return len(str(a))
    else:
        return len(str(b))

N = int(input())
result = 10000000000
goal = int((N**0.5)//1)

for i in range(1, goal+1):
    if N%i ==0:
        #print(i)
        if result > fdigit(i, N//i):
            result = fdigit(i, N//i)
            #print(i, N/i,fdigit(i, N//i))

print(result)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n;
    cin >> n;
    vll a(n);
    REP(i, n) cin >> a[i];
    VSORT(a);
    vll s(n + 1);
    REP(i, n) s[i + 1] = s[i] + a[i];
    ll neck = 0;
    REP(i, n - 1){
        if(a[i + 1] > 2 * (a[i] + s[i])) neck = i + 1;
    }
    ll res = n - neck;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << min(a,b)+min(c,d)<<endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve()
}

func resolve() {
	a, b, c, d := scanInt(sc), scanInt(sc), scanInt(sc), scanInt(sc)
	num := b - a + 1 - divisorNum(a, b, c) - divisorNum(a, b, d) + divisorNum(a, b, lcm(c, d))
	fmt.Println(num)
}

func divisorNum(a, b, c int) int {
	return b/c - (a-1)/c
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}

func gcd(a, b int) int {
	for b > 0 {
		t := a / b
		b, a = a-t*b, b
	}
	return a
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;

int m, nMin, nMax;
int P[210];
pair<int, int> ans[210];

signed main()
{
    while (true) {
        cin >> m >> nMin >> nMax;
        if (m == 0 && nMin == 0 && nMax == 0) break;

        REP(i,m) cin >> P[i];
        sort(P, P + m, greater<int>());

        int idx = 0;
        for (int i=nMin; i<=nMax; i++) {
            ans[idx++] = make_pair(P[i-1] - P[i], i);
        }

        sort(ans, ans + idx);
        cout << ans[idx-1].second << endl;
    }
}

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

const ll INF = 1e18;

int main(int argc, char const *argv[])
{
	int n, d, a; cin >> n >> d >> a;
	vector<pair<int, int>> v(n);
	rep(i, n) {
		int x, h; cin >> x >> h;
		v[i] = make_pair(x, h);
	}
	sort(v.begin(), v.end());

	ll ans = 0;
	ll sum = 0;
	queue<pair<ll, ll>> que; // <x, damage>
	rep(i, n) {
		ll x = v[i].first, h = v[i].second;
		while(not que.empty() and que.front().first < x) {
			sum -= que.front().second;
			que.pop();
		}
		h -= sum;
		if (h <= 0) continue;
		int time = (h + a - 1) / a;
		ans += time;
		sum += a * time;
		que.push(make_pair(x + 2 * d, a * time));
	}

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


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

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

int main(){

  long long n; 
  cin >> n;
  vector<int> a(n),b(n),c(n);
  rep(i,n)cin >> a[i];
  rep(i,n)cin >> b[i];
  rep(i,n)cin >> c[i];
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  // rep(i,n)cout << a[i]<<" ";
  // cout<<endl;
  // rep(i,n)cout<<b[i]<<" ";
  // cout<<endl;
  // rep(i,n)cout<<c[i]<<" ";
  // cout<<endl;

  vector<long long> b_pos(n);
  rep(i,n){
    vector<int>::iterator up;
    up = upper_bound(c.begin(),c.end(),b[i]);
    b_pos[i] = n-(long long)(up-c.begin());
    // cout << b_pos[i]<<endl;
  }
  rep(i,n){
    if(i==0)continue;
    b_pos[n-1-i] += b_pos[n-i];
  }
  //rep(i,n)cout<<b_pos[i]<<endl;
  //cout << endl;

  long long sum = 0;
  rep(i,n){
    vector<int>::iterator up;
    up = upper_bound(b.begin(),b.end(),a[i]);
    sum += b_pos[(int)(up-b.begin())]; 
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 2552
#include<iostream>
#include<vector>
#define Number 300000
using namespace std;

int main(){
  int n;
  int num_table[Number]={0};
  for(int i=0;i<Number;i++){
    if(i%7==1 || i%7==6) num_table[i]=1;
  }
  num_table[1]=0;
  vector<int> prime_table;
  for(int i=6;i<Number;i++){
    if(num_table[i]){
      prime_table.push_back(i);
      for(int j=i+i;j<Number;j+=i){
	num_table[j]=0;
      }
    }
  }

  while(cin>>n,n!=1){
    cout<<n<<":";
    for(int i=0;i<(int)prime_table.size();i++){
      if(n%prime_table[i]==0){
	cout<<" "<<prime_table[i];
      }
    }
    cout<<endl;
  }
  return 0;
}

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

using namespace std;

using int64 = long long;
const int64 INF = 1LL << 58;

int N;
int64 W[4000];
int64 dp[4000][4001];
int opt[4000][4001];

inline int64 getcost(int left, int right)
{
  return (W[right] - W[left]);
}

int64 rec(int left, int right)
{
  if(~dp[left][right]) return (dp[left][right]);
  if(left + 1 >= right) {
    opt[left][right] = left;
    return (0);
  }
  rec(left, right - 1);
  rec(left + 1, right);
  dp[left][right] = INF;
  for(int k = opt[left][right - 1]; k <= opt[left + 1][right]; k++) {
    int64 cost = rec(left, k) + rec(k, right);
    if(cost < dp[left][right]) {
      dp[left][right] = cost;
      opt[left][right] = k;
    }
  }
  return (dp[left][right] += getcost(left, right));
}

int main()
{
  cin >> N;
  for(int i = 0; i < N; i++) {
    int64 x;
    cin >> x;
    W[i + 1] = W[i] + x;
  }
  memset(dp, -1, sizeof(dp));
  cout << rec(0, N) << endl;
}

Measured memory_bytes: 173652
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<complex>
#include<string>
#include<cstring>

using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 10000000000000
#define MAX_OTURI 50005
#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;
int coin[17];
int dp[300];
int n;
int main()
{
	dp[0]=1;
	rep(i,17)coin[i]=(i+1)*(i+1);
	rep(i,17)
	{
		rep(j,300)
		{
			if(j>=coin[i])dp[j]+=dp[j-coin[i]];
		}
	}
	while(1)
	{
		cin>>n;
		if(n==0)break;
		cout<<dp[n]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
use std::cmp::min;

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).unwrap();
    let n: usize = n.trim().parse().unwrap();

    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    let v_a: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    let v_b: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();

    let mut counter: u64;
    let mut killed_by_past_hero: u64;
    let mut a = *v_a.get(0).unwrap();

    {
        let &a_plus1 = v_a.get(1).unwrap();
        let &b = v_b.get(0).unwrap();

        counter = min(a, b);
        killed_by_past_hero = min(a_plus1, b - counter);
        counter += killed_by_past_hero;
        a = a_plus1;
    }

    for i in 1..n {
        let &a_plus1 = v_a.get(i+1).unwrap();
        let &b = v_b.get(i).unwrap();
        let killed1 = min(a - killed_by_past_hero, b);
        let killed2 = min(a_plus1, b - killed1);
        killed_by_past_hero = killed2;
        counter += killed1 + killed2;
        a = a_plus1;
    }

    println!("{}", counter);
}


Measured memory_bytes: 10492
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int i=0,j;
  int ans=0;
  string s;

  cin>>s;
  j=s.size()-1;

  while(i<j){
    if(s[i]!=s[j]) ans++;
    i++;
    j--;
  }

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


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

string S;
vector<ll> dp(4, 0);
 
int main(void){
	
	cin >> S;
	
	dp[0] = 1;
	for(int i = 0; i < S.size(); ++i){
	    int m = S[i] - 'A' + 1;
	    if(1 <= m && m <= 3) dp[m] += dp[m - 1];
	    else{
	        for(int i = 3; i >= 1; --i) dp[i] = dp[i] * 3 + dp[i - 1];
	        dp[0] *= 3;
	    }
	    for(int i = 0; i < 4; ++i) dp[i] %= MOD;
	}
    cout << dp[3] << endl;
    
	return 0;
}

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

public class Main {

	public  static int merge(int[] afterA, int left, int mid, int right) {
		int n1 = mid - left;
		int n2 = right - mid;

		int[] lMatrix = new int[n1 + 1];
		int[] rMatrix = new int[n2 + 1];

		for(int i = 0; i < n1; i++) {
			lMatrix[i] = afterA[left + i];
		}

		for(int i = 0; i < n2; i++) {
			rMatrix[i] = afterA[mid + i];
		}

		lMatrix[n1] = 1000000001;
		rMatrix[n2] = 1000000001;

		int i = 0;
		int j = 0;
		int count = 0;
		for(int k = left; k < right; k++) {
			if (lMatrix[i] <= rMatrix[j]) {
				afterA[k] = lMatrix[i];
				i = i + 1;
				count++;
			} else {
				afterA[k] = rMatrix[j];
				j = j + 1;
				count++;
			}
		}
		return count;
	}

	public static int mergeSort(int[] afterA, int left, int right) {
		int countSum = 0;
		int countMergeSortLeft = 0;
		int countMergeSortRight = 0;
		if (left + 1 < right) {
			int mid = (left + right) / 2;

			countMergeSortLeft = mergeSort(afterA, left, mid);
			countMergeSortRight = mergeSort(afterA, mid, right);
			countSum = merge(afterA, left, mid, right);
		}
		return countSum + countMergeSortLeft + countMergeSortRight;
	}

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader( new InputStreamReader(System.in));

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

		String[] targetMatrix = br.readLine().split(" ");

		int[] targetMatrixInt = new int[n];

		for(int i = 0; i < n; i++) {
			targetMatrixInt[i] = Integer.parseInt(targetMatrix[i]);
		}

		int targetMatrixMid = 0;

		int countResult = mergeSort(targetMatrixInt, targetMatrixMid, n);

		StringBuilder sb = new StringBuilder();

		for(int i = 0; i < targetMatrixInt.length; i++) {
			sb.append(targetMatrixInt[i]);
			if(i == targetMatrixInt.length - 1){
				break;
			}
			sb.append(" ");
			
		}
		System.out.println(sb.toString());
		System.out.println(countResult);
	}
}

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

int main()
{
    string a;
    cin>>a;
    if(a[2]==a[3] && a[4]==a[5])
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
using namespace std;

#define ll long long int

int main()
{
    int n, a[100];
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    reverse(a, a + n);
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (i % 2 == 0)
            ans += a[i];
        else
            ans -= a[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>

int func(int n){
	int res=0;
	for(int i=1; i*n != 600; i++){
		res += i*n*i*n*n;
	}
	return res;
}

int main(void){
	int in;
	while(std::cin >> in){
		std::cout << func(in) << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1160
n = gets.to_i
a = gets.split.map(&:to_i)

h = Hash.new(0)

a.each do |i|
  h[i] += 1
end

cnt =  h.count

k = h.each_value.map { |v| v.even? }
if k.count(true).even?
  puts cnt
else
  puts cnt - 1
end


Measured memory_bytes: 18052
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

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

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  vector<vector<char> > ans(h, vector<char>(w, '#'));
  rep(y,h) rep(x,w) {
    if (s[y][x] == '#') continue;
    int res = 0;
    rep(i,8) {
      int nx = x + dx[i], ny = y +dy[i];
      if (nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
      if (s[ny][nx] == '#') res++;
    }
    ans[y][x] = '0' + res;
  }
  rep(y,h) {
    rep(x,w) {
      cout << ans[y][x];
    }
    cout << "\n";
  }
  return 0;
}

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

int main(){
	int a;
  	cin >> a;
  	int i=0;
  	for(int j=0; j < 3; j++){
  		if(a % 2 == 1){
      		i++ ;
      		a = a - 1;
    	}
      	a = a / 10;
    }
  	
    cout << i <<endl; 	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
const int MOD = 1000000007;

bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N,a[100001];
  cin >> N;
  REP(i,N){
    cin >> a[i];
  }
  sort(a,a+N);
  int mi,ma;
  mi = a[0];
  ma = a[N-1];
  if(mi + 2 <= ma){
    cout << "No" << endl;
    return 0;
  }
  if(mi == ma){
    if(mi == N-1){
      cout << "Yes" << endl;
      return 0;
    }else{
      if(ma <= N/2){
        cout << "Yes" << endl;
      }else
        cout << "No" << endl;
      return 0;
    }
  }
  int mincnt=0,maxcnt=0;
  REP(i,N)if(mi == a[i])mincnt++;
  else maxcnt++;
  if(mincnt < a[N-1] && 2*(a[N-1]-mincnt) <= maxcnt){
    cout << "Yes" << endl;
    return 0;
  }else{
    cout<< "No" << endl;
    return 0;
  }
  
  
  return 0;
}


Measured memory_bytes: 640
#include <cstdio>

using namespace std;

int main(){
	int i,j;
	int p[14][14],x,y,s;
	for(i=2;i<12;i++)for(j=2;j<12;j++)p[i][j]=0;
	while(scanf("%d,%d,%d",&x,&y,&s)!=-1){
		y+=2;x+=2;
		p[y][x]++;
		p[y+1][x]++;
		p[y-1][x]++;
		p[y][x+1]++;
		p[y][x-1]++;
		if(s>=2){
			p[y+1][x+1]++;
			p[y+1][x-1]++;
			p[y-1][x-1]++;
			p[y-1][x+1]++;
			
		}
		if(s>=3){
			p[y+2][x]++;
			p[y-2][x]++;
			p[y][x+2]++;
			p[y][x-2]++;
		}
	}
	int mx=0,no=0;
	for(i=2;i<12;i++){
		for(j=2;j<12;j++){
			if(!p[i][j])no++;
			if(p[i][j]>mx)mx=p[i][j];
		}
	}
	printf("%d\n%d\n",no,mx);
	return 0;
}

Measured memory_bytes: 0
from collections import Counter
n = int(input())
a = list(map(int, input().split()))

cum = [0] * (n + 1)
for i in range(n):
    cum[i + 1] = cum[i] + a[i]

c = Counter(cum)
ans = 0
for v in c.values():
    ans += v * (v - 1) // 2
print(ans)

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

string shuffle(string deck, int num) {
  string shuffled = "";

  shuffled += deck.substr(num, deck.size() - num);
  shuffled += deck.substr(0, num);

  return shuffled;
}

int main() {
  string deck;
  int shuffle_size;
  int shuffle_card_num;

  while(true) {
    cin >> deck;

    if(deck == "-") {
      break;
    }

    cin >> shuffle_size;

    string shuffled_deck = deck;
    for(int i = 0; i < shuffle_size; i++) {
      cin >> shuffle_card_num;

      shuffled_deck = shuffle(shuffled_deck, shuffle_card_num);
    }


    cout << shuffled_deck << endl;
  }
}



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

//素数判定
bool isPrime(int num){
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false;
  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2){
    if (num % i == 0) return false;
  }
  return true;
}

int main(){
  int n;
  cin >> n;
  vector<int> a(n-1);
  rep(i,n-1) cin >> a[i];
  vector<int> ans(n);
  rep(i,n-1) ans[a[i]-1]+=1;
  rep(j,n) cout << ans[j] << endl;
}

Measured memory_bytes: 4724
def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    q = int(input())
    m = [int(x) for x in input().split()]
    ans = ["no"] * q
    for j in range(2 ** n):
        total = 0
        for k in range(n):
            if (j >> k) & 1:
                total += a[k]
        if total in m:
            for i, v in enumerate(m):
                if v == total:
                    ans[i] = "yes"

    print("\n".join(map(str, ans)))


main()




Measured memory_bytes: 5608
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		int c = a * b;

		if(c % 2 == 0) {
			System.out.println("Even");
		}else {
			System.out.println("Odd");
		}

	}


}


Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if (H == 0 && W == 0) {
                break;
            } else {
                for (int i = 1; i <= H; ++i) {
                    for (int j = 1; j <= W; ++j) {
                        System.out.print("#");
                    }
                    System.out.print("\n");
                }
                System.out.print("\n");
            }
        }
    }
}



Measured memory_bytes: 37988
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a, b, c, d, M = -10e18;
    cin >> a >> b >> c >> d;

    M = max(M, (a*c));
  //  cout << "a*c" << M << endl;
    M = max(M, (a*d));
    //cout << "a*d" << M << endl;
    M = max(M, (b*c));
    //cout << "b*c" << M << endl;
    M = max(M, (b*d));
   // cout << "b*d" << M << endl;
    cout << M << endl;


}


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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int res = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    res += i % 2 == 0 and a & 1;
  }
  cout << res << '\n';
}


Measured memory_bytes: 3584
#include<iostream>
using namespace std;
int main(){
	int n,b,f,r,v,a[4][3][14]={0};
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>b>>f>>r>>v;
		a[b-1][f-1][r-1]=a[b-1][f-1][r-1]+v;
	}
	for(int k=0;k<4;k++){
		for(int j=0;j<3;j++){
			for(int s=0;s<10;s++){
				cout<<" "<<a[k][j][s];
			}
		cout<<endl;
		}
		if(k==0||k==1||k==2){cout<<"####################"<<endl;}

	}
	return 0;
}


Measured memory_bytes: 3080
a, b, k = gets.split.map(&:to_i)
if a > k
  puts [(a-k), b].join(" ")
elsif a == k
  puts [0, b].join(" ")
elsif a+b > k
  puts [0, (a+b-k)].join(" ")
else
  puts [0, 0].join(" ")
end
  
  


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}

int main(){
    int H, W; cin >> H >> W;
    vector<string> S(H); REP(i, H) cin >> S[i];

    vector<int> vectx = {1, 1, 0, -1, -1, -1, 0, 1};
    vector<int> vecty = {0, 1, 1, 1, 0, -1, -1, -1};

    for(int i = 0; i < H; ++i) {
        for(int k = 0; k < W; ++k) {
            if(S[i].at(k) == '.') {
                int cnt = 0;
                for(int m = 0; m < 8; ++m) {
                    if((k + vecty[m] < 0 || k + vecty[m] >= W) || (i + vectx[m] < 0 || i + vectx[m] >= H)) {
                        continue;
                    } else {
                        if(S[i + vectx[m]][k + vecty[m]] == '#') cnt++;
                    }
                }

                S[i].at(k) = '0' + cnt;
            }
        }
    }

    REP(i, H) {
        cout << S[i] << endl;
    }
}

Measured memory_bytes: 256