akhauriyash/Code-Regression huggingface dataset:
<?php

$mn = explode(' ', trim(fgets(STDIN)));
$m = $mn[0];
$n = $mn[1];

function gcd($m, $n){
    if($n > $m) list($m, $n) = array($n, $m);
     
    while($n !== 0){
        $tmp_n = $n;
        $n = $m % $n;
        $m = $tmp_n;
    }
    return $m;
}
 
function lcm($m, $n){
    return $m * $n / gcd($m, $n);
}

echo lcm($m, $n);
  
?>

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

int main(){
  
  ll N,m=0;
  cin>>N;
  vector<ll> H(N);
  
  for(int i=0;i<N;i++)
    cin>>H.at(i);
  
  if(N==0)
    cout<<"Yes"<<endl;
  else{
    m = H.at(0);
    for(int i=1;i<N;i++){
      if(m-1>H.at(i)){
        cout<<"No"<<endl;
        return 0;
      }
      m = max(m,H.at(i));
    }
  }
  cout<<"Yes"<<endl;
  
}

Measured memory_bytes: 1024
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N):
    for j in range(i+1, N):
        x = L[i] + L[j]
        y = bisect_left(L, x)
        ans += y - j - 1
print(ans)

Measured memory_bytes: 73840
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}

int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}
// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
ll _pfact(ll a);
static ll pf[100000000];
static ll pc;

ll _pfact(ll a) {
	long i, r;
	if (a % 2 == 0) {
		pf[pc] = 2; pc++;
		return(_pfact(a / 2));
	}
	r = sqrt(a);
	for (i = 3; i <= r; i += 2) {
		if (a % i == 0) {
			pf[pc] = i; pc++;
			return(_pfact(a / i));
		}
	}
	if (a != 1) {
		pf[pc] = a; pc++;
	}
	return 0;

}


#pragma endregion

//ABC 161 -B
int main(void) {
	int i,n,m,a[101];
	float t = 0.0;

	scanf("%d %d", &n,&m);

	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		t += (float)a[i];
	}
	t = t / ((float)m*4);
	int c = 0;
	for(i=0;i<n;i++)
		if (a[i] >= t) c++;

    if(c>=m) printf("Yes\n");
	else     printf("No\n");
	return 0;
}

Measured memory_bytes: 2088
#include <stdio.h>
 
#define N 100
 
void display(int data[], int n);
void insertionSort(int data[], int n);
 
int main(){
     
    int data[N];
    int i, n;
     
    scanf("%d", &n);
     
    for(i=0; i<n; i++){
         
        scanf("%d", &data[i]);
         
    }
     
    display(data, n);
     
    insertionSort(data, n);
     
    return 0;
     
}
 
 
void display(int data[], int n){
     
    int i;
    for(i=0; i<n; i++){
        if(i>0){
            printf(" ");
        }
        printf("%d", data[i]);
    }
     
    printf("\n");
     
    return;
}
 
 
 
void insertionSort(int data[], int n){
     
    int i, j, temp;
     
    for(i=1; i<n; i++){
         
        j = i;
        temp = data[j];
         
        while(j>0 && temp < data[j-1]){
             
            data[j] = data[j-1];
            j--;
             
        }
        data[j] = temp;
        display(data, n);
    }
     
}

Measured memory_bytes: 1032
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
typedef long long LL;
typedef long double Lf;
#define in (void)scanf
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
//#define Rep(i,a,n)for(LL i=(LL)(a);i<(LL)(n);i++)
#define rep(i,n)Rep(i,0,n)
#define Repp(i,l,r,k)for(int i=(int)(l);i<(int)(r);i+=(int)(k))
//#define Repp(i,l,r,k)for(LL i=(LL)(l);i<(LL)(r);i+=(LL)(k))
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))
#define MOD 1000000007//998244353,1000000007,1000000009,4999999999999997
int upi(const void* a, const void* b) { return*(int*)a<*(int*)b ? -1 : *(int*)a> * (int*)b ? 1 : 0; }
int downi(const void* a, const void* b) { return*(int*)a<*(int*)b ? 1 : *(int*)a> * (int*)b ? -1 : 0; }
void sortupi(int* a, int n) { qsort(a, n, sizeof(int), upi); } //1,2,3,4,...
void sortdowni(int* a, int n) { qsort(a, n, sizeof(int), downi); }
int upLL(const void* a, const void* b) { return*(LL*)a<*(LL*)b ? -1 : *(LL*)a> * (LL*)b ? 1 : 0; }
int downLL(const void* a, const void* b) { return*(LL*)a<*(LL*)b ? 1 : *(LL*)a> * (LL*)b ? -1 : 0; }
void sortupLL(LL* a, int n) { qsort(a, n, sizeof(LL), upLL); }
void sortdownLL(LL* a, int n) { qsort(a, n, sizeof(LL), downLL); }
int cmp_char(const void* a, const void* b) { return *(char*)a - *(char*)b; } // a,b,c,d
int cmp_str(const void* a, const void* b) { return strcmp(*(const char**)a, *(const char**)b); } // aaa,aab
LL gcd(LL p, LL q) { while (q) { LL t = p % q; p = q; q = t; }return p; }
LL modpow(LL a,LL n,int m){LL x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invmodpow(b,p)modpow(b,p-2,p)// a/b≡a*b^{-1}(mod p)...return b^{-1}(mod p)
typedef struct fac { LL n, exp; }F;
LL fact(LL n,F*a){LL x=n,i,j,c=0;for(i=2;i*i<=x;i++){for(j=1;x%i==0;j++)x/=i;if(j>1){a[c].n=i;a[c++].exp=j-1;}}if(x-1){a[c].n=x;a[c++].exp=1;}return c;}
LL nibtan(LL* a,LL n,LL x){LL p=0,q=n/2,r=n-1;while(r-p>1){if(x>=a[q])p=q;if(x<=a[q])r=q;q=(p+r)/2;}return a[p]==x?p:r;}
//snippet

#define N 200009

void run() {
	int n, r = 0, w_tilr = 0;
	char s[N];
	in("%d%s", &n, s);
	rep(i, n)if (s[i] == 'R')r++;
	rep(i, r)if (s[i] == 'W')w_tilr++;
	printf("%d", w_tilr ? w_tilr : 0);
}

int main(void) {
	int test = 1;
//	in("%d", &test);
	while (test--) {
		run();
	}
	return 0;
}

Measured memory_bytes: 1932
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=1000000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(i,u) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
int n,m,tot=0,a[N+10],c[N+10],pri[N+10],mu[N+10];
ll f[N+10];
bool nopri[N+10];

int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

ll qpow(ll x,int y)
{
	ll ans=1;
	while (y)
	{
		if (y&1) ans=ans*x%maxd;
		x=x*x%maxd;y>>=1;
	}
	return ans;
}

void init()
{
	n=read();
	rep(i,1,n) {a[i]=read();m=max(a[i],m);}
	mu[1]=1;
	rep(i,1,n) c[a[i]]++;
	rep(i,2,m)
	{
		if (!nopri[i]) {pri[++tot]=i;mu[i]=-1;}
		for (int j=1;j<=tot && i*pri[j]<=m;j++)
		{
			nopri[i*pri[j]]=1;
			if (i%pri[j]==0) break;
			mu[i*pri[j]]-=mu[i];
		}
	}
	rep(i,1,m)
	{
		rep(j,1,m/i) f[i]=(f[i]+1ll*i*j%maxd*c[i*j])%maxd;
	}
}

int main()
{
	init();ll ans=0;
	rep(i,1,m)
	{
		ll tmp=0;
		rep(j,1,m/i)
		{
			tmp=(tmp+1ll*mu[j]*f[i*j]%maxd*f[i*j]%maxd)%maxd;
		}
		ans=(ans+tmp*qpow(i,maxd-2))%maxd;
	}
	rep(i,1,n) ans=(ans-a[i]+maxd)%maxd;
	ans=ans*qpow(2,maxd-2)%maxd;
	printf("%lld",ans);
	return 0;
}
			


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

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


Measured memory_bytes: 256
package main

import (
    "fmt"
)

func main() {
    b := make(map[string]int)
    r := make(map[string]int)

    var n int
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        var s string
        fmt.Scan(&s)
        b[s]++
    }

    var m int
    fmt.Scan(&m)
    for i := 0; i < m; i++ {
        var s string
        fmt.Scan(&s)
        r[s]++
    }

    var max int
    for k, v := range b {
        score := v
        if minus, ok := r[k]; ok {
            score -= minus
        }
        if score > max {
            max = score
        }
    }

    fmt.Println(max)
}


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


 
int main()
{
	string s;
    cin>>s;
    int sz=s.size();
    vector<char> v;
    for(int i=0;i<sz;i++)
    {
        if(s[i]=='B')
        {
            if(v.size())
                v.pop_back();
        }
        else
            v.push_back(s[i]);
    }
    for(auto x:v)
        cout<<x;
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;

namespace Competitive
{
    internal class BinarySearch
    {
        public int[] S;
        public int N { get { return S.Length; } }

        public BinarySearch(int[] s)
        {
            S = s;
        }

        public bool Cond(int i, int x)
        {
            if (S[i] >= x) return true;
            return false;
        }

        // 左側がfalse, 右側がtrue
        // 初めてCondがtrueを返すindexを返す
        // 全て条件を満たさない場合はNを返す
        public int Search(int x)
        {
            int left = 0;
            int right = N;

            if (Cond(0, x)) return 0;
            if (!Cond(N - 1, x)) return N;

            while (left + 1 < right)
            {
                int mid = (left + right) / 2;
                if (!Cond(mid, x))
                {
                    left = mid;
                }
                else
                {
                    right = mid;
                }
            }
            return right;
        }
    }

    internal class Solution
    {
        public int n, q;
        public int[] S, T;

        public void Run()
        {
            n = Input.ReadInt();
            S = Input.ReadIntArray();
            q = Input.ReadInt();
            T = Input.ReadIntArray();

            var bs = new BinarySearch(S);
            int ret = 0;
            for (int i = 0; i < q; i++)
            {
                int t = T[i];
                int idx = bs.Search(t);
                if (S[idx] == t) ret++;
            }

            Console.WriteLine(ret);
        }

    }

    
    internal static class Input
    {
        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }

    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}


Measured memory_bytes: 22784
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    static void solve() {
        int m = nextInt();
        int ans = 24 + (24 - m);
        out.println(ans);
    }

    static PrintWriter out;
    static Scanner sc;

    static int[][] newIntArray(int h, int w, int value) {
        int[][] ret = new int[h][w];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                ret[i][j] = value;
            }
        }
        return ret;
    }

    static int nextInt() {
        return Integer.parseInt(sc.next());
    }

    static long nextLong() {
        return Long.parseLong(sc.next());
    }

    static String nextString() {
        return sc.next();
    }

    static int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    static List<Integer> nextIntList(int n) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(nextInt());
        }
        return list;
    }

    static List<Long> nextLongList(int n) {
        List<Long> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(nextLong());
        }
        return list;
    }

    static char[][] nextCharArray(int h, int w) {
        char[][] c = new char[h][w];
        for (int i = 0; i < h; i++) {
            String str = nextString();
            for (int j = 0; j < w; j++) {
                c[i][j] = str.charAt(j);
            }
        }
        return c;
    }

    static <T extends Comparable<? super T>> void sort(List<T> list) {
        Collections.sort(list);
    }

    // greatest common divisor
    static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    // baseのn乗を計算を返す
    static int pow(int base, int n) {
        int ret = 1;
        for (int i = 0; i < n; i++) {
            ret *= base;
        }
        return ret;
    }

    // return n^k mod m
    static long powMod(long n, long k, long m) {
        if (k == 0) {
            return 1;
        } else if (k % 2 == 1) {
            return powMod(n, k - 1, m) * n % m;
        } else {
            long tmp = powMod(n, k / 2, m);
            return tmp * tmp % m;
        }
    }

    // intをlength桁のbit文字列に変換
    static String toBinaryString(int input, int length) {
        return toBinaryString(input).substring(29 - length);
    }

    // intを29桁のbit文字列に変換
    static String toBinaryString(int input) {
        String ret = "";
        int max = 0x10000000;
        for (int i = 0; i < 29; i++) {
            int tmp = input / max;
            ret += tmp;
            input %= max;
            max /= 2;
        }
        return ret;
    }

    public static void main(String[] args) {
        out = new PrintWriter(System.out);
        sc = new Scanner(System.in);

        solve();

        out.flush();
        sc.close();
    }

}


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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved
int main(){
    long long n,m;
    cin>>n>>m;
    long long a[m];
    long long key[m]={};

    rep(i,m){
        int b;
        cin>>a[i]>>b;
        rep(k,b){
            int c;
            cin>>c;
            key[i]+=(1<<(c-1));
        }
    }

    long long second[12];
    second[0]=1;
    rep(i,11)second[i+1]=second[i]*2;

    //long long dp[5000][1010]={};
    //jの2進数表記のk-1桁目が1=現在購入している鍵で宝箱kを開けることができる
    //dp[i][j]:=i+1番目までの鍵で状態をjにするために必要な最小費用

    //rep2(i,(1<<n))rep(j,m+1)dp[i][j]=INF;
    vector<long long>dp(5000,INF);
    dp[0]=0;

    for(int i=0;i<m;i++){
        int now=0;
        //for(int j=0;j<i;j++){
            now|=key[i];
        //}

        for(int bit=0;bit<(1<<n);bit++){
            dp[bit|now]=min(dp[bit]+a[i],dp[bit|now]);
        }
    }
    if(dp[(1<<n)-1]==INF)dp[(1<<n)-1]=-1;

    cout<<dp[(1<<n)-1]<<endl;

    return 0;

}
/*


*/


Measured memory_bytes: 384
def gcd(a, b):
	return gcd(b, a % b) if b else a

A, B = map(int, input().split())
c = gcd(A, B)
d = set()
i = 2
while i * i <= c:
	while c % i == 0:
		c /= i
		d.add(i)
	i += 1
if c != 1:
	d.add(c)
print(len(d) + 1)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<bitset>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define LONG_INF 9223372036854775807
#define INF 1000000000LL
#define EPS 1e-10
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define dump(a) rep(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define all(v) v.begin(),v.end()
#define pb push_back


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

    int H, N;
    cin >> H >> N;
    vector<int> A(N);
    rep(i, N) cin>>A[i];

    string ret="No";
    rep(i, N){
        H-=A[i];
        if(H<=0){
            ret="Yes";
            break;
        }
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll x; cin >> x;
	int a = x;
	int ans = 1;
	while(a % 360 != 0){
		ans++;
		a += x;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <cmath>

#define MAX_M 1000000

using namespace std;

typedef struct
{
	int num, prime, last;
}HOLE;

int M, N;
HOLE h[1000+2][1000+2];

bool prime_judge(int x){
	if(x == 0 || x == 1) return false;
	for (int i = 2; i*i <= x; i++)
	{
		if(x % i == 0) return false;
	}
	return true;
}

void solve(){
	int flag = 0, d = 1;//?????????????????????, ???????????¢
	int x = 500, y = 500, ox = 500, oy = 500;
	int ansx, ansy;
	for (int i = 0; i < 1002; i++)
	{
		for (int j = 0; j < 1002; j++)
		{
			h[i][j].num = 0;
			h[i][j].last = 0;
			h[i][j].prime = 0;
		}
	}
	for (int i = 1; i <= M; i++)
	{
		h[x][y].num = i;
		if(i == N){
			ansx = x;
			ansy = y;
		}
		if(flag == 0){
			x++;
			if(x - ox == d){
				ox = x;
				flag = 1;
			}
		}else if(flag == 1){
			y--;
			if(oy - y == d){
				oy = y;
				d++;
				flag = 2;
			}
		}else if(flag == 2){
			x--;
			if(ox - x == d){
				ox = x;
				flag = 3;
			}
		}else if(flag == 3){
			y++;
			if(y - oy == d){
				oy = y;
				d++;
				flag = 0;
			}
		}
	}
	for (int i = 1001; i >= 0; i--)
	{
		for (int j = 0; j < 1002; j++)
		{
			if(h[j][i].num != 0){
				h[j][i].prime = max(max(h[j-1][i+1].prime, h[j][i+1].prime), h[j+1][i+1].prime);
				if(h[j-1][i+1].last == 0 && h[j][i+1].last == 0 && h[j+1][i+1].last == 0)
				{
					if(prime_judge(h[j][i].num)) h[j][i].last = h[j][i].num;
				}else{
					int k;
					for (k = -1; k <= 1; k++)
					{
						if(h[j+k][i+1].prime == h[j][i].prime){
							h[j][i].last = h[j+k][i+1].last;
							break;
						}
					}
					for (int l = -1; l <= 1; l++)
					{
						if(h[j+k][i+1].prime == h[j+l][i+1].prime){
							h[j][i].last = max(h[j][i].last, h[j+l][i+1].last);
						}
					}
				}
				if(prime_judge(h[j][i].num)) h[j][i].prime++;
			}
		}
	}
	if(h[ansx][ansy].prime == 0) cout << "0 0" << endl;
	else cout << h[ansx][ansy].prime << " " << h[ansx][ansy].last << endl;
}

int main(){
	while(1){
		cin >> M >> N;
		if(M == 0 && N == 0) break;
		solve();
	}
	return 0;
}

Measured memory_bytes: 12928
#include<iostream>
using namespace std;
 
int main(){
    double l, r;
    int l_cnt[4] = {}, r_cnt[4] = {};
    while(cin >> l >> r){
        if(l >= 1.1) l_cnt[0]++;
        else if(l >= 0.6) l_cnt[1]++;
        else if(l >= 0.2) l_cnt[2]++;
        else l_cnt[3]++;
 
        if(r >= 1.1) r_cnt[0]++;
        else if(r >= 0.6) r_cnt[1]++;
        else if(r >= 0.2) r_cnt[2]++;
        else r_cnt[3]++;
    }
 
    for(int i = 0; i < 4; i++){
        cout << l_cnt[i] << " " << r_cnt[i] << endl;
    }
 
}

Measured memory_bytes: 3208
## constant

MAX_INT = 1 << 31

### main

n = gets.strip.to_i

as = [MAX_INT, MAX_INT, MAX_INT, MAX_INT]

n.times do
  ai = gets.strip.to_i
  as << ai
  as.sort!.pop
end
#p as

aas = []

for i in (0...as.length)
  ai = as[i].to_s
  for j in ((i + 1)...as.length)
    next if i == j
    aj = as[j].to_s
    aas << (ai + aj).to_i
    aas << (aj + ai).to_i
  end
end

puts aas.sort[2]

Measured memory_bytes: 6108
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for(int i=m; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <typename T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0; }
template <typename T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1;} return 0; }



int main() {
 int h,w; cin>>h>>w;
 int wall[10][10];
 rep(i,0,10) rep(j,0,10) cin>>wall[i][j];
 int ans[10]={0};
 rep(i,0,h) rep(j,0,w){
      int a; cin>>a;
      if(a!=-1) ans[a]++;
 }

 rep(k,0,10) rep(i,0,10) rep(j,0,10){
     wall[i][j] = min(wall[i][j], wall[i][k]+wall[k][j]);
 }

 ll res=0;
 rep(i,0,10){
     res+=wall[i][1]*ans[i];
 }
 cout<<res<<endl;

}

Measured memory_bytes: 256
import numpy as np
N=int(input())
X = list(map(int,input().split()))
X.sort()
a=list()
c=N-1
for i in range(X[0],X[c]+1):
    b=0
    for j in range(0,N):
        if i-X[j]>10**5:
            break
        b+=(i-X[j])**2
    a.append(b)
print(min(a))

Measured memory_bytes: 12420
#!/usr/bin/env python3


def solve(S, T):
    ans = len(T)

    # Sのi文字目から、Tに一致するかどうかを調べる
    for i in range(len(S) - len(T) + 1):
        target = S[i:]
        diff = 0

        # target と t の diff を算出
        for j in range(len(T)):
            if target[j] != T[j]:
                diff += 1

        ans = min(ans, diff)

    return ans


def main():
    S = input()
    T = input()
    result = solve(S, T)
    print(result)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9072
from collections import Counter

# forを逆から回して下から素直にmodを取るとTLEだった
# 累積和的な計算で高速化、やりやすくするためにreverse
S = input()[::-1]
# ex. 1817181712114 → 4112171817181
# print(S)

# 0桁目までのMODを0とすることで、
# 1桁目を含む数が2019の倍数の時に都合が良くなる
X = [0]

# 4,14,114,2114,12114,...のmod2019を計算

for i, s in enumerate(S):
    X.append((X[-1] + int(s) * pow(10, i, 2019)) % 2019)
# print(X)


C = Counter(X)
# print(C)

ans = 0
# Xが同じになったところを2つ選べば題意を満たす
# v_C_2の計算
for v in C.values():
    ans += v * (v - 1) // 2

print(ans)


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

int N;

int check(const char *s, char *t, int flag) {
    int i;

    if (flag & 1) t[0] = 'W';
    else t[0] = 'S';
    if (flag & 2) t[1] = 'W';
    else t[1] = 'S';
    i = 0;
    while (++i < N-1) {
        if (t[i] == 'S') {
            if (s[i] == 'o') t[i+1] = t[i-1];
            else if (t[i-1] == 'S') t[i+1] = 'W';
            else t[i+1] = 'S';
        } else {
            if (s[i] == 'o') {
                if (t[i-1] == 'W') t[i+1] = 'S';
                else t[i+1] = 'W';
            } else t[i+1] = t[i-1];
        }
    }
    if (((t[N-2] == t[0] && t[N-1] == 'S' && s[N-1] == 'o') || 
         (t[N-2] != t[0] && t[N-1] == 'S' && s[N-1] == 'x') ||
         (t[N-2] == t[0] && t[N-1] == 'W' && s[N-1] == 'x') ||
         (t[N-2] != t[0] && t[N-1] == 'W' && s[N-1] == 'o')) && 
        ((t[N-1] == t[1] && t[0] == 'S' && s[0] == 'o') || 
         (t[N-1] != t[1] && t[0] == 'S' && s[0] == 'x') ||
         (t[N-1] == t[1] && t[0] == 'W' && s[0] == 'x') ||
         (t[N-1] != t[1] && t[0] == 'W' && s[0] == 'o'))) {
        t[N] = '\0';
        return 0;
    } else {
        return 1;
    }
}

int main(void) {
    int i, res;
    char S[100010], T[100010];
    scanf("%d%s", &N, &S);
    memset(T,0,100010);

    memset(T,0,100010);
    res = check(S, T, 0);
    while (res && ++i<4) {
        memset(T,0,100010);
        res = check(S, T, i);
    }
    if (!res) printf("%s\n", T);
    else printf("-1\n");
    return 0;
}

Measured memory_bytes: 512
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#define WOULD
#define YOU
#define PLEASE
#define ACCEPT
#define MY
#define SUBMISSION
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#include <iostream> // cout, endl, cin
#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 <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100;
const long long MOD = 1000000007;
typedef pair<long long,long long> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    for (long long i = n - r + 1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A * B) % MOD;
}

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);
}

//long long A,B;
bool ok(long long key,long long index){
    if(index > key) return true;
    else if(index <= key) return false;
}
long long binary_search(long long key,long long size){
    //left,right,midはいずれもindex
    long long left = -1,right = size;
    while(right - left > 1){
        long long mid = left + (right-left)/2;
        long long hantei = ok(key,mid);
        if(hantei) right = mid;
        else left = mid;
    }
    if(left == -1)return 0;
    return left;
}

int main() {
    long long A,B,C;cin >> A >> B >> C;
    if(A % 2 == 0 || B % 2 == 0 || C % 2 == 0){
        cout << 0 << endl;
        return 0;
    }
    else{
        cout << min({A*B,C*A,B*C}) << endl;
    }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> k(n);
    vector<vector<int>> a(n);
    vector<int> like(m,0);
    REP(i,n){
        cin >> k[i];
        a[i].resize(k[i]);
        REP(j,k[i]){
            cin >> a[i][j];
            a[i][j]--;
            like[a[i][j]]++;
        }
    }
    int res = 0;
    REP(i,m){
        if(like[i]==n)res++;
    }
    put(res);
    return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i,k,n) for(int i = k; i < n; i++)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef pair<int, int> prii;

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

template<class T = ll> T in() {
    T _in;
    cin >> _in;
    return _in;
}

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

    int H, W;
    string f[50];
    cin >> H >> W;
    rep(h, H) {
        cin >> f[h];
    }

    rep(h, H) {
        rep(w, W) {
            if(f[h][w] == '.') {
                int cnt = 0;
                rep(i, 8) {
                    if(-1 < h+dy8[i] && h+dy8[i] < H
                    && -1 < w+dx8[i] && w+dx8[i] < W) {
                        if(f[h+dy8[i]][w+dx8[i]] == '#') {
                            cnt++;
                        }
                    }
                }
                f[h][w] = '0' + cnt;
            }
        }
    }

    rep(h, H) {
        cout << f[h] << endl;
    }

    return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
	string s;
	cin >> s;
	int len = s.size();
	int cnts = 0, cntst = 0;
	for (int i = 0; i < len; ++i) {
		if (s[i] == 'S')
			cnts++;
		else if (s[i] == 'T' && cnts != 0) {
			cnts--;
			cntst += 2;
		}
	}
	cout << len - cntst << endl;
	return 0;
}

Measured memory_bytes: 3708
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

struct P {
  int p, y, n;
};

signed main() {
  int N, M;
  cin >> N >> M;

  vector<P> vec(M);
  REP(i, M){
    cin >> vec[i].p >> vec[i].y;
    vec[i].n = i;
  }

  sort(ALL(vec), [](P const & l, P const & r){
      if(l.p != r.p) return l.p < r.p;
      return l.y < r.y;
      });


  int cnt = 1;
  REP(i, M){
    if(i != 0 && vec[i].p != vec[i-1].p) cnt = 1;
    vec[i].y = cnt++;
  }

  sort(ALL(vec), [](P const & l, P const & r){
      return l.n < r.n;
      });

  REP(i, M){
    cout << setw(6) << setfill('0') << vec[i].p;
    cout << setw(6) << setfill('0') << vec[i].y << "\n";
  }

  return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  int N; cin >> N;
  vi A(N); rep(i,N) cin >> A.at(i);
  
  ll x2 = 0;
  rep(i,N) {
    if (i%2) 
      x2 -= A.at(i);
    else
      x2 += A.at(i);
  }
  
  vi ans(N);
  ans.at(0) = x2/2;
  rep(i,N-1) {
    ans.at(i+1) = A.at(i) - ans.at(i);
  }
  rep(i,N) ans.at(i) *= 2;
  rep(i,N) printf("%d%c", ans.at(i), i==N-1?'\n':' ');
  return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define F_(i,a,b) for(int i=(a);i>=(b);--i)
#define G(i,u) for(int i=Head[a];i;i=Next[i])

typedef long long ll;
typedef double db;
typedef long double ld;

template<typename T> inline T max(T& a, T b) { return a>b?a:a=b; }
template<typename T> inline T min(T& a, T b) { return a<b?a:a=b; }

const int N = 2005; 

char str[5];
bool c[N<<1];
int  p[N<<1], pos[2][N], pre[N<<1][N], f[N][N];

int main() {
	int n;
	scanf("%d", &n);
	F(i,1,2*n) {
		scanf("%s%d", str, &p[i]);
		c[i] = str[0] == 'B';
		pos[c[i]][p[i]] = i;
	}
	F(i,1,2*n) {
		int tot = 0;
		F(j,1,i) if(c[j] != c[i]) pre[i][p[j]] ++; else if(p[j] <= p[i]) tot ++;
		F(j,1,n) pre[i][j] += pre[i][j-1];
		F(j,0,n) pre[i][j] += tot;
	}
	F(i,0,n) {
		F(j,0,n) {
			int p0 = pos[0][i], p1 = pos[1][j];
			if(i && j) f[i][j] = std::min( f[i-1][j] + p0 - pre[p0][j], f[i][j-1] + p1 - pre[p1][i] );
			else if(i) f[i][j] = f[i-1][j] + p0 - pre[p0][j];
			else if(j) f[i][j] = f[i][j-1] + p1 - pre[p1][i];
		}
	}
	printf("%d\n", f[n][n]);
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  each(x,vec) is >> x;
  return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
  rep(i,vec.size()) {
    if (i) os << " ";
    os << vec[i];
  }
  return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
  rep(i,vec.size()) {
    if (i) os << endl;
    os << vec[i];
  }
  return os;
}

ll gcd(ll a, ll b) {
  return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}

ll solve() {
  ll n, m; cin >> n >> m;
  ll l = lcm(n, m);
  string S, T; cin >> S >> T;
  if (S[0] != T[0]) return -1;
  map<ll, char> tbl;
  rep(i, n) tbl[i*l/n] = S[i];
  rep(i, m) {
    ll pos = i*l/m;
    if (tbl.count(pos) > 0) {
      if (tbl[pos] != T[i]) return -1;
    }
    else {
      tbl[pos] = T[i];
    }
  }
  return l;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << solve() << endl;
}


Measured memory_bytes: 10880
#include <bits/stdc++.h>
#define REP(i, n) for(long long i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;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());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;



int main() {
  int p[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
  int k;
  cin >> k;
  cout << p[k-1];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> diffA(n);
    rep(i,n) diffA[i] = a[i] - i - 1;
    sort(all(diffA));
    ll b1 = diffA[n/2];
    ll b2 = diffA[(n/2) - 1];
    ll ans1 = 0, ans2 = 0;
    rep(i,n) ans1 += abs(diffA[i] - b1);
    rep(i,n) ans2 += abs(diffA[i] - b2);
    cout << min(ans1, ans2) << endl;
    return 0;
}

Measured memory_bytes: 6404
# https://atcoder.jp/contests/abc075/tasks/abc075_b


H, W = gets.split.map(&:to_i)
Ss = Array.new(H) { gets.chomp }
ans = Array.new(H) { '#' * W }

# 行の繰り返し
H.times do |y|
  # 列の繰り返し
  W.times do |x|
    bom = 0

    # 爆弾の場合
    if Ss[y][x] == '#'
      next
    end

    # 時計回りに見ていく
    # 左上
    if y != 0 && x != 0
      bom += 1 if Ss[y - 1][x - 1] == '#'
    end

    # 上
    if y != 0
      bom += 1 if Ss[y - 1][x] == '#'
    end

    # 右上
    if y != 0 && x != W - 1
      bom += 1 if Ss[y - 1][x + 1] == '#'
    end

    # 右
    if x != W - 1
      bom += 1 if Ss[y][x + 1] == '#'
    end

    # 右下
    if y != H - 1 && x != W - 1
      bom += 1 if Ss[y + 1][x + 1] == '#'
    end

    # 下
    if y != H - 1
      bom += 1 if Ss[y + 1][x] == '#'
    end

    # 左下
    if y != H - 1 && x != 0
      bom += 1 if Ss[y + 1][x - 1] == '#'
    end

    # 左
    if x != 0
      bom += 1 if Ss[y][x - 1] == '#'
    end

    ans[y][x] = bom.to_s
  end
end

puts ans

#      -----
#      .....
#      .#.#.
#      .....
#      -----


Measured memory_bytes: 1788
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, K;
  cin>>N>>K;
  string S;
  cin>>S;
  bool zero;
  if(S[0]=='0') zero = true;
  else zero = false;
  vector<int> arr;
  int num = 1;
  for(int i=1;i<S.size();++i) {
    if((zero && S[i]=='0') || (!zero && S[i]=='1')) {
      num++;
    }
    else {
      zero ^= 1;
      arr.push_back(num);
      num = 1;
    }
  }
  if(num>0) arr.push_back(num);
  int ans = 0;
  int tmp = 0;
  int index;
  int arrnum = arr.size();
  if(S[0]=='0') {
    index = 2*K;
    for(int i=0;i<min(index, arrnum);++i) {
      ans += arr[i];
      tmp += arr[i];
    }
    for(int i=index;i<arrnum;i+=2) {
      if(i==index) tmp -= arr[i-index];
      else tmp -= arr[i-index-1]+arr[i-index];
      if(i+1<arrnum) tmp += arr[i]+arr[i+1];
      else tmp += arr[i];
      ans = max(ans, tmp);
    }
  }
  else {
    index = 2*K+1;
    for(int i=0;i<min(index, arrnum);++i) {
      ans += arr[i];
      tmp += arr[i];
    }
    for(int i=index;i<arrnum;i+=2) {
      tmp -= arr[i-index]+arr[i-index+1];
      if(i+1<arrnum) tmp += arr[i]+arr[i+1];
      else tmp += arr[i];
      ans = max(ans, tmp);
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 4012
# -*- coding: utf-8 -*-

def judge(x, y):
    if (x < 0 or x>100):
        return False
    if (y < 0 or y>100):
        return False
    if (x+y == 0):
        return False
    if (y%2):
        return False
    if x < y/4:
        return False
    if x*2 > y:
        return False
    return True

x, y = map(int, input().split())
if judge(x, y):
    print('Yes')
else:
    print('No')


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

int main() {

int n,m;
cin >> n >> m;
if(n>=m){
  for(int i=0;i<n;i++){
    cout << m;
  }
  cout <<endl;

}
else{
  for(int i=0;i<m;i++){
    cout << n;
  }
  cout <<endl;
}

}


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

int main() {
	int n;
	cin>>n;
	int arr[n];
	int ans[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
		ans[arr[i]-1]=i+1;
	}
	for(int i=0;i<n;i++)
    {
    	cout<<ans[i]<<" ";
    }
	return 0;
}

Measured memory_bytes: 1536
w, h, n = map(int, input().split())
min_xy = [0, 0]
max_xy = [w, h]
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        min_xy[0] = max(min_xy[0], x)
    if a == 2:
        max_xy[0] = min(max_xy[0], x)
    if a == 3:
        min_xy[1] = max(min_xy[1], y)
    if a == 4:
        max_xy[1] = min(max_xy[1], y)
if max_xy[0] >= min_xy[0] and max_xy[1] >= min_xy[1]:
    print((max_xy[0] - min_xy[0]) * (max_xy[1] - min_xy[1]))
else:
    print(0)

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

int main()
{
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    string S = "";
    for (int i = 0; i < ty - sy; i++)
    {
        S.append("U");
    }
    for (int i = 0; i < tx - sx; i++)
    {
        S.append("R");
    }
    for (int i = 0; i < ty - sy; i++)
    {
        S.append("D");
    }
    for (int i = 0; i < tx - sx; i++)
    {
        S.append("L");
    }
    S.append("L");
    for (int i = 0; i < ty - sy + 1; i++)
    {
        S.append("U");
    }
    for (int i = 0; i < tx - sx + 1; i++)
    {
        S.append("R");
    }
    S.append("D");
    S.append("R");
    for (int i = 0; i < ty - sy + 1; i++)
    {
        S.append("D");
    }
    for (int i = 0; i < tx - sx + 1; i++)
    {
        S.append("L");
    }
    S.append("U");
    cout << S << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
	var (primaryCupLimit, primaryCupAmount, secondaryCupAmount) = readLine()!!.split(' ').map { it.toInt() }
    
    var primaryCupRemain = primaryCupLimit - primaryCupAmount
    var secondaryCupRemain = Math.max(secondaryCupAmount - primaryCupRemain, 0)
    
    System.out.println(secondaryCupRemain)
}


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

int main(){
    int n,k;
    cin >> n >> k;
    int sum=0,y;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        y = k-x;
        if(x<=y)
            sum += x;
        if(x>y)
            sum += y;    
    }
    cout << sum*2 << endl;
}

Measured memory_bytes: 3632
N, K = (int(nk) for nk in input().split())

curr_S = 0
count = 1
max_ev = 0
index = 0
has_eval_sk = False
zero_e = []
for p_str in input().split():
    e = (int(p_str)+1) / 2
    zero_e.append(e)
    if has_eval_sk:
        curr_S += e - zero_e[index]
        max_ev = max(max_ev, curr_S)
        index += 1
    else:
        curr_S += e
        if count == K:
            max_ev = curr_S
            has_eval_sk = True
        count += 1

print(max_ev)


Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)
typedef pair<int,int> Pi;
#define F first
#define S second
#define INF 1 << 28

inline void chmax(int &a,int b) {
  a = max(a,b);
}

inline void chmin(int &a,int b) {
  a = min(a,b);
}

int main()
{
  int H, W;
  int mas[105][105];
  fill(mas[0],mas[105],INF);
  char c;
  
  cin >> H >> W;
  Rep(i,H)Rep(j,W) {
    if(cin >> c,c == 'c')mas[i][j] = 0;
  }
  Rep(i,H)for(int j = 1; j < W; j++) {
    if(mas[i][j - 1] != INF) {
      chmin(mas[i][j],mas[i][j - 1] + 1);
    }
  }
  Rep(i,H) {
    Rep(j,W) {
      if(mas[i][j] == INF)mas[i][j] = -1;
      cout << mas[i][j];
      if(j == W - 1)cout << endl;
      else cout << " ";
    }
  }
  return 0;
}
  

Measured memory_bytes: 3108
#include <bits/stdc++.h>
        using namespace std;
        const int maxn=1e5+10,mod=1e9+7;
        int n,m,k,t,a[maxn],rt;
        vector<int>e[maxn];
        bool flag=true;
        long long dfs(int x,int y=0)
        {
            if(!flag)return -1;
            if(e[x].size()==1)return a[x];
            long long sum=0;
            vector<long long>tmp;
            for(int i=0;i<e[x].size();i++)
            {
                int z=e[x][i];
                if(z==y)continue;
                long long j=dfs(z,x);
                if(j>a[x])
               {
                    flag=false;
                    return -1;
               }
                if(j==-1)return -1;
                tmp.push_back(j);
                sum+=j;
            }
            long long delta=(sum-a[x]),ans=sum-2*delta;
            if( ans <0 || delta <0)
            {
                flag=false;
                return -1;
            }
            sort(tmp.begin(),tmp.end());
            int pos=tmp.size()-1;
            if(x==rt&&ans>0)
            {
                flag=false;
            }
            return ans;
        }
        int main(){
            int i,j;
            scanf("%d",&n);
            for(i=1;i<=n;i++)scanf("%d",&a[i]);
            for(i=1;i<n;i++)
            {
                int x,y;
                scanf("%d%d",&x,&y);
                e[x].push_back(y);
                e[y].push_back(x);
            }
            if(n==2)
            {
                if(a[1]==a[2])puts("YES");
                else puts("NO");
                return 0;
            }
            for(i=1;i<=n;i++)if(e[i].size()>1)
            {
                rt=i;
                dfs(rt);
                break;
            }
            puts(flag?"YES":"NO");
            return 0;
        }

Measured memory_bytes: 16768
import queue
import copy

INF = 10 ** 10

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

maze = [[-1] * (W+2)]
for _ in range(H):
    maze.append( [-1] + list( map(lambda c: INF if c == '.' else -1, input()) ) + [-1] )
maze.append([-1] * (W+2))

maze_backup = copy.deepcopy(maze)
maxpath = 0
for start_y in range(1, H+1):
    for start_x in range(1, W+1):
        if maze[start_y][start_x] == -1:
            continue
        

        bfs_q = queue.Queue()
        bfs_q.put( (start_y, start_x) )
        maze[start_y][start_x] = 0

        while not bfs_q.empty():
            y, x = bfs_q.get()
            for dy, dx in ((-1, 0), (1, 0), (0, 1), (0, -1)):
                if maze[y+dy][x+dx] > maze[y][x] + 1:
                    maze[y+dy][x+dx] = maze[y][x] + 1
                    bfs_q.put( (y+dy, x+dx) )

        maxpath = max(maxpath, max(max(row) for row in maze))
        maze = copy.deepcopy(maze_backup)

print(maxpath)


Measured memory_bytes: 4080