akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main(){
  int n, sum=0;
  cin >> n;
  int aux = n;
  while(n>0){
    sum+=n%10;
    n/=10;
  }
  if(aux%sum==0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

#define MAX_LENGTH 200

long stack[MAX_LENGTH];
int top = 0;

int isFull() {
  if (top == 199) {
    // printf("???????????§??????\n");
    return 1;
  } else {
    // printf("???????????§?????????????????????\n");
    return 0;
  }
}

int isEmpty() {
  if (top == 0) {
    // printf("?????§??????\n");
    return 1;
  } else {
    // printf("?????§?????????????????????\n");
    return 0;
  }
}

void push(long x) {
  if (!isFull()){
    stack[top + 1] = x;
    top++;
    // printf("%ld??????????????\???????????????\n", x);
  } else {
    // printf("???????????\??§???????????????\n");
  }
}

long pop() {
  if (!isEmpty()){
    top--;
    // printf("%ld???????????????????????????\n", stack[top + 1]);
    return stack[top + 1];
  } else {
    return 0;
    // printf("???????????§???????????????\n");
  }
}

int main(void) {
  char temp[10];
  int i, a, b;

  while(scanf("%s", temp) != EOF) {

    if (temp[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
      // printf("+?????\?????????????????????\n");
    } else if (temp[0] == '-') {
      a = pop();
      b = pop();
      push(b - a);
      // printf("-?????\?????????????????????\n");
    } else if (temp[0] =='*') {
      a = pop();
      b = pop();
      // printf("*?????\?????????????????????\n");
      push(a * b);
    } else if (temp[0] == EOF){
      // printf("????????§??????\n");
      break;
    } else {
      push(atol(temp));
      // printf("??´??°%ld?????\?????????????????????\n", atol(temp));
    }
  }

  printf("%ld\n", pop());

  return 0;
}

Measured memory_bytes: 548
use proconio::*;

fn main() {
    input! {
        n: usize,
        mut v: [i32; n],
        c: [i32; n]
    };
    for i in 0..n {
        v[i] -= c[i];
    }
    v.sort();
    v.reverse();
    println!("{}", v.iter().filter(|&x| x.is_positive()).fold(0, |acc, x| acc + x));
}


Measured memory_bytes: 2112
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var S = ReadLine();
            var Eright = S.Count(s => s == 'E');
            var Wleft = 0;
            var ans = N;
            foreach (var s in S)
            {
                if (s == 'E') --Eright;
                ans = Min(ans, Eright + Wleft);
                if (s == 'W') ++Wleft;
            }
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 14304
#include<bits/stdc++.h>
using namespace std;
int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,i,j,k,l;
    cin>>n>>k;
    long long int a[n+1];
    for(i=0;i<n;i++)
    cin>>a[i];
    long long int mini=1e18;
    for(i=0;i<=n-k;i++)
    {
        mini=min(mini,abs(a[i])+abs(a[i+k-1]-a[i]));
    }
    for(i=n-1;i>=k-1;i--)
    {
        mini=min(mini,abs(a[i])+abs(a[i-k+1]-a[i]));
    }
    cout<<mini;
}



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

int main() {
	int N;
  	int A;
  	int ct = 0;
  	vector<int> cal(N);
  	cin >> N;
  for(int i=0;i<N;i++){
  	cin >> A;
    ct = 0;
    for(;A%2==0;){
    	A /= 2;
      ct++;
    }
    cal.push_back(ct);
  }
  for(int j=N-1;j>0;j--){
  	if(cal.at(j)-cal.at(j-1) < 0)cal.at(j-1) = cal.at(j);
  }
  cout << cal.at(0) << endl;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int x;cin >> x;
    string ans = "NO";
    if(x == 3 || x == 5 || x == 7) ans = "YES";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod=MOD) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod=MOD) {
    return modpow(a, mod - 2, mod);
}

long long fac[100010], finv[100010], inv[100010];

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];

    COMinit();
    ll ans=0;
    rep(d,61){
        ll c1=0,c0=0;
        rep(i,n){   
            if(a[i] & 1LL<<d) c1++;
            else c0++;
        }
        ll cnt=(c0*c1)%MOD;
        ll tmp=(cnt*modpow(2,d))%MOD;
        ans=(ans+tmp)%MOD;
    }

    cout<<ans<<endl;
}

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

int main() {
    while (1) {
        int n;
        cin >> n;
        if (!n) break;
        
        vector< vector<int> > v(n, vector<int>(4, 0));
        for (int i = 0; i < n; i++) {
            int I, U, A, P;
            cin >> I >> U >> A >> P;
            v.at(i).at(0) = A;
            v.at(i).at(1) = 100000 - P;
            v.at(i).at(2) = 1000 - I;
            v.at(i).at(3) = 1000 - U;
        }
        
        sort(v.begin(), v.end());
        reverse(v.begin(), v.end());
        
        int cnt = 0;
        map<int, int> m;
        for (int i = 0; i < n; i++) {
            int x = 0;
            if (cnt < 10 - 1) {
                x = 3;
            } else if (cnt < 20 - 1) {
                x = 2;
            } else if (cnt < 26 - 1) {
                x = 1;
            }
            if (m.count(v.at(i).at(3))) {
                if (m.at(v.at(i).at(3)) >= x) {
                    continue;
                } else {
                    m.at(v.at(i).at(3))++;
                }
            } else {
                m[v.at(i).at(3)] = 1;
            }
            cout << 1000 - v.at(i).at(2) << endl;
            cnt++;
            if (cnt == 26) break;
        }
    }
    
    return 0;
}



Measured memory_bytes: 3024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    ll A, B, C; cin >> A >> B >> C;

    bool ans = false;
    foreps(i, 1, 101) {
        if ((A * i) % B == C) {
            ans = true; break;
        }
    }
    cout << (ans ? "YES" : "NO") << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <random>
#include <iomanip>
#include <map>

using namespace std;

typedef long long ll;

int main() {
    int N, a, p;
    vector<int> A;
    map<int, int> mp;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a;
        mp[a]++;
        A.push_back(a);
    }
    
    sort(A.begin(), A.end(), greater<int>());
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if(mp[A.at(i)] == 0) continue;
        for (int j = 32; j > 0; j--) {
            p = pow(2, j);
            if (mp.count(p - A.at(i))) {
                if (A.at(i) != p / 2 && mp[p - A.at(i)] >= 1) {
                    mp[A.at(i)]--;
                    mp[p - A.at(i)]--;
                    ans++;
                    break;
                } else if (A.at(i) == p / 2 && mp[A.at(i)] >= 2) {
                    mp[A.at(i)] -= 2;
                    ans++;
                    break;
                }
            }
        }
    }
    
    cout << ans << endl;
}


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

int main() {
  int N , A , B , S , x ;
  cin >> N >> A >> B;
  S = 0;
  for (int i = 1 ; i <= N ; i++){
    x = i/10000 + (i%10000)/1000 + (i%1000)/100 + (i%100)/10 + i%10 ;
    if (A <= x && x <= B) S = S + i;
  }
  cout << S ;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
int H[10];
int main() {
	for (int i = 0; i < 10; i++) {
		cin >> H[i];
	}
	sort(H, H+10,greater<int>());
	for (int i = 0; i <3 ; i++) {
		cout << H[i] << endl;
	}
}

Measured memory_bytes: 1176
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>
#include <stack>
#include <deque>

#define INF 1000000000;
#define MOD 1000000007;
#define LIMIT 1000000000000000000;
typedef long long ll;
using namespace std;

int main()
{
    string s; cin >> s;
    int a = s[0] - '0', b = s[1] - '0', c = s[2] - '0', d = s[3] - '0';
    string ans;
    if (a + b + c + d == 7) {
        printf("%d+%d+%d+%d=7\n", a, b, c, d);
    }
    else if (a - b + c + d == 7) {
        printf("%d-%d+%d+%d=7\n", a, b, c, d);
    }
    else if (a - b - c + d == 7) {
        printf("%d-%d-%d+%d=7\n", a, b, c, d);
    }
    else if (a - b - c - d == 7) {
        printf("%d-%d-%d-%d=7\n", a, b, c, d);
    }
    else if (a + b + c - d == 7) {
        printf("%d+%d+%d-%d=7\n", a, b, c, d);
    }
    else if (a + b - c - d == 7) {
        printf("%d+%d-%d-%d=7\n", a, b, c, d);
    }
    else if (a + b - c + d == 7) {
        printf("%d+%d-%d+%d=7\n", a, b, c, d);
    }
    else if (a - b + c - d == 7) {
        printf("%d-%d+%d-%d=7\n", a, b, c, d);
    }
}

Measured memory_bytes: 256
from time import time
start=time()
from copy import deepcopy
from random import randint

d=int(input())
c=list(map(int,input().split())) #scoreを減らす
s=[] #scoreを増やす
for i in range(d):
    t=list(map(int,input().split()))
    s.append(t)
last=[0]*26 #それぞれのコンテストが最後に行われたのは何日目か
ans_lst=[]

for i in range(1,d): #364日、1日目ならi=1
    temp_best=-100000000
    for j in range(26): #それぞれの日において、26個のコンテストを順番にピックアップ
        temp=s[i-1][j]
        for k in range(26): #ピックアップされていないコンテストは、スコアを減らす
            if j!=k:
                temp-=(c[k]*(i-last[k]))
        temp_last=deepcopy(last)
        temp_last[j]=i
        for k in range(26):
            temp+=s[i][k]
            for l in range(26):
                if k!=l:
                    temp-=(c[l]*(i+1-temp_last[l]))
        if temp>temp_best:
            temp_best=temp
            rem=j
    ans_lst.append(rem)
    last[rem]=i
    
temp_best=-100000000 #365日目は、次の日のことは考えなくてよい
for j in range(26): #26個のコンテストを順番にピックアップ
    temp=s[i-1][j]
    for k in range(26): #ピックアップされていないコンテストは、スコアを減らす
        if j!=k:
            temp-=(c[k]*(i-last[k]))
    if temp>temp_best:
        temp_best=temp
        rem=j
ans_lst.append(rem) #AtCoder運営お疲れ様です

score=0
las=[0]*26
for i in range(d):
    for j in range(26):
        las[j]+=1
    score+=s[i][ans_lst[i]]
    las[ans_lst[i]]=0
    for j in range(26):
        score-=c[j]*las[j]

for q in range(1,13):
    for p in range(d-q):
        las=[0]*26
        temp_score=0
        temp_ans_lst=deepcopy(ans_lst)
        temp_ans_lst[p],temp_ans_lst[p+q]=temp_ans_lst[p+q],temp_ans_lst[p]
        for i in range(d):
            for j in range(26):
                las[j]+=1
            temp_score+=s[i][temp_ans_lst[i]]
            las[temp_ans_lst[i]]=0
            for j in range(26):
                temp_score-=c[j]*las[j]
        if temp_score>score:
            score=temp_score
            ans_lst=temp_ans_lst

while time()-start<1.9:
    las=[0]*26
    temp_score=0
    temp_ans_lst=deepcopy(ans_lst)
    a=randint(0,d-2)
    b=randint(0,d-2)
    temp_ans_lst[a],temp_ans_lst[a+1]=temp_ans_lst[a+1],temp_ans_lst[a]
    temp_ans_lst[b],temp_ans_lst[b+1]=temp_ans_lst[b+1],temp_ans_lst[b]
    for i in range(d):
        for j in range(26):
            las[j]+=1
        temp_score+=s[i][temp_ans_lst[i]]
        las[temp_ans_lst[i]]=0
        for j in range(26):
            temp_score-=c[j]*las[j]
    if temp_score>score:
        score=temp_score
        ans_lst=temp_ans_lst

for i in ans_lst:
    print(i+1)

Measured memory_bytes: 89560
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100000
#define INF 1000000000

int N, K, h[MAXN + 3], dp[MAXN + 3];

int main() {
    cin >> N >> K;
    for (int i = 1; i <= N; i++)
        cin >> h[i];

    dp[1] = 0;
    for (int i = 2; i <= N; i++) {
        int mini = INF;
        for (int j = max(i - K, 1); j < i; j++)
            mini = min(mini, dp[j] + abs(h[j] - h[i]));

        dp[i] = mini;
    }

    cout << dp[N] << endl;
}

Measured memory_bytes: 1024
def bunkai(n:int):
    ls=list(str(n))
    top,bottom=int(ls[0]),int(ls[-1])
    if n<=99:
        middle=0
    else:
        middle=int("".join(ls[1:-1]))
    return top, middle, bottom

n=int(input())
Nt,Nm,Nb = bunkai(n)

count=0
for i in range(1,n+1):
    t,m,b = bunkai(i)
    if b==0:continue
    if t==b:count+=1
    if n<=99:
        if int(str(b)+str(t))<=n:count+=1
    else:
        keta = len(str(n))
        for x in range(keta-2):
            count+=10**x
        x+=1
        if Nt>b:
            count+=10**x
        elif Nt==b:
            if Nb>=t:
                count+=Nm+1
            else:
                count+=Nm
print(count)
    


Measured memory_bytes: 3064
def BubbleSort(a, n):
    flag = 1
    count = 0
    i = 0
    while flag:
        flag = 0
        for j in reversed(range(i+1,n)):
            if a[j][1] < a[j-1][1]:
                c = a[j]
                a[j] = a[j-1]
                a[j-1] = c
                flag = 1
                count += 1
        i += 1

def SelectionSort(a, N):
    count = 0
    minj = 0
    for i in range(n):
        minj = i
        for j in range(i,n):
            if a[j][1] < a[minj][1]:
                minj = j
        if i != minj:
            count += 1      
        c = a[i]
        a[i] = a[minj]
        a[minj] = c

n = int(input())
s = [x for x in input().split()]
s1 = s.copy()

BubbleSort(s,n)
for i in range(len(s)-1):
    print(s[i],end=' ')
print(s[-1])
print('Stable')

SelectionSort(s1,n)

for i in range(len(s1)-1):
    print(s1[i],end=' ')
print(s1[-1])
if s==s1:
    print('Stable')
else:
    print('Not stable')


Measured memory_bytes: 5612
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define vi vector<llong>
#define vvi vector<vi >
#define MOD (int)1e9+7
typedef long long llong;
using namespace std;

int main(){
	int h,w;
	cin>>h>>w;
	
	char a[h+1][w+1];
	REP(i,w+1) a[0][i]='#';
	REP(i,h+1) a[i][0]='#';
	for(int i=1;i<=h;++i){
		for(int j=1;j<=w;++j){
			cin>>a[i][j];
		}
	}
	
	vvi dp(h+1,vi(w+1,0));
	dp[1][1]=1;
	for(int i=1;i<=h;++i){
		for(int j=1;j<=w;++j){
			if(a[i][j]=='.'){
				dp[i][j]+=dp[i-1][j]+dp[i][j-1];
				dp[i][j]%=MOD;
			}
		}
	}
	
	cout<<dp[h][w]<<endl;
}

Measured memory_bytes: 9088
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;

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

   int n=s.size();

   ll a=0;

   rep(i,n){
      if(i%2==0){
         if(s[i]=='0') a++;
      }
      else{
         if(s[i]=='1') a++;
      }
   }
   ll b=0;
   rep(i,n){
      if(i%2==0){
         if(s[i]=='1') b++;
      }
      else{
         if(s[i]=='0') b++;
      }
   }

   cout<<min(a,b);

   
  
return 0;
}



Measured memory_bytes: 512
<?php
fscanf(STDIN, "%d", $N);

$prev_t = $prev_x = $prev_y = 0;
$flg = true;

for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%d %d %d", $t, $x, $y);
    $diff_t = $t - $prev_t;
    $diff_xy = abs($prev_x - $x) + abs($prev_y - $y);
    $prev_t = $t;
    $prev_x = $x;
    $prev_y = $y;
    if ($diff_xy > $diff_t || ($diff_xy - $diff_t) % 2 != 0) {
        $flg = false;
        break;
    }
}

echo $flg ? "Yes\n" : "No\n";


Measured memory_bytes: 4984
n,k=list(map(int,input().split()))
s=input()
cnt=[[],[]]
st=1
c=0
for i in s:
  if st==int(i):
    c+=1
  else:
    cnt[st].append(c)
    c=1
    st=1-st
cnt[st].append(c)
cnt[0].append(0)
cnt[1].append(0)
sm=[[],[]]
s=0
for i in cnt[0]:
  s+=i
  sm[0].append(s)
s=0
for i in cnt[1]:
  s+=i
  sm[1].append(s)
sm[0][-1]=0
sm[1][-1]=0
if len(cnt[0])<=k+1:
  print(n)
else:
  m=0
  for i in range(len(cnt[0])-k):
    s=sm[0][i+k-1]-sm[0][i-1]+sm[1][min(i+k,len(cnt[1])-2)]-sm[1][i-1]
    m=max(s,m)
  print(m)

Measured memory_bytes: 75084
#include <random>

#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;

template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}

struct Trie {
  Trie *node[26];
  vector<ll> val;
  Trie() : val(26, 0) { std::fill(node, node + 26, nullptr); }
  void insert(const std::string &s) {
    Trie *r = this;
    int sz = s.size();
    for (int i = 0; i < sz - 1; i++) {
      int c = s[i] - 'a';
      if (!r->node[c]) r->node[c] = new Trie;
      r = r->node[c];
    }
    int idx = s[sz - 1] - 'a';
    r->val[idx]++;
    return;
  }
  Trie *find(const char &s, Trie *pos) {
    int c = s - 'a';
    if (!pos->node[c]) return nullptr;
    return pos->node[c];
  }
  ll count(const string &s) {
    ll ans = 0;
    vector<int> cnt(26);
    for (auto c : s) cnt[c - 'a']++;
    Trie *r = this;
    for (int i = 0; i < (int)s.size(); i++) {
      for (int j = 0; j < 26; j++) {
        if (cnt[j]) {
          ans += r->val[j];
        }
      }
      auto nxt = find(s[i], r);
      if (!nxt) break;
      r = nxt;
      cnt[s[i] - 'a']--;
    }
    return ans;
  }
};

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

  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    reverse(s[i].begin(), s[i].end());
  }
  sort(s.begin(), s.end(),
       [](const string &x, const string &y) { return x.size() < y.size(); });
  Trie trie;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += trie.count(s[i]);
    trie.insert(s[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 456776
H,W=map(int,input().split())
grid=["" for i in range(H)]
for i in range(H):
  grid[i]=input()

def calc(y,x):
  if y<0 or y>=H or x<0 or x>=W:
    return 0
  if grid[y][x]=="#":
    return 1
  else:
    return 0

for i in range(H):
  line=""
  for j in range(W):
    ans=0
    if grid[i][j]=="#":
      line+=("#")
    else:
      ans+=calc(i-1,j-1)
      ans+=calc(i-1,j)
      ans+=calc(i-1,j+1)
      ans+=calc(i,j-1)
      ans+=calc(i,j+1)
      ans+=calc(i+1,j-1)
      ans+=calc(i+1,j)
      ans+=calc(i+1,j+1)
      line+=str(ans)
  print(line)


Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (Math.abs(x - a) < Math.abs(x - b)) {
            System.out.println("A");
        } else {
            System.out.println("B");
        }
    }
}


Measured memory_bytes: 21844
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	const mod = 1000000007

	l := next()
	n := len(l)

	dp := make([][2]int, n+1)
	dp[0][1] = 1
	for i := 1; i <= n; i++ {
		if l[i-1] == '0' {
			dp[i][0] = (3 * dp[i-1][0]) % mod
			dp[i][1] = dp[i-1][1]
		} else {
			dp[i][0] = (3*dp[i-1][0] + dp[i-1][1]) % mod
			dp[i][1] = (2 * dp[i-1][1]) % mod
		}
	}

	puts((dp[n][0] + dp[n][1]) % mod)
}


Measured memory_bytes: 2560
N = gets.to_i
hantei = readlines.map(&:chomp)  #これで改行コードを落とせている
a=0
b=0
c=0
d=0

(0..N-1).each do |x|
  if hantei[x] == "AC" then
    a += 1
  elsif hantei[x] == "WA" then
    b += 1
  elsif hantei[x] == "TLE" then
    c += 1
  else
    d += 1
  end
end
puts "AC x " + a.to_s
puts "WA x " + b.to_s
puts "TLE x " + c.to_s
puts "RE x " + d.to_s

Measured memory_bytes: 30740
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

template<typename T>
class BIT{
public:
    vector<T> bit;
    int size;
    BIT(int size):
        bit(vector<T>(size+1,0)),size(size){}
    
    T sum(int i){
        if(!i) return 0;
        return bit[i]+sum(i-(i&(-i)));
    }

    void add(int i,T x){
        if(i>size)return;
        bit[i]+=x;
        add(i+(i&(-i)),x); 
    }   
};

int inversion(const vector<pair<int,int>> &v) {
    BIT<int> bit(55);
    int res = 0;
    REP(i,v.size()) {
        res += i - bit.sum(v[i].second+1);
        bit.add(v[i].second+1,1);
    }
    return res;
} 

bool is_monotone_increasing(const vector<pair<int,int>> &v) {
    int n = v.size();
    bool res = true;
    FOR(i,1,n){ if(v[i].first<v[i-1].first) res = false; }
    return res;
}

int main() {
    int N; cin >> N;
    vector<pair<int,int>> v(N);
    REP(i,N) cin >> v[i].first;
    REP(i,N) cin >> v[i].second;
    int ans = 1<<29;
    REP(i,1<<N) {
        int odd_cnt = 0, even_cnt = 0;
        REP(j,N) {
            if( ( (j%2==0) && ((i>>j)&1)==0 ) || (j%2)&((i>>j)&1) ) even_cnt ++;
            else odd_cnt ++; 
        }
        if( !(even_cnt == N-N/2 && odd_cnt == N/2) ) continue;
        vector<pair<int,int>> evens, odds;
        REP(j,N) {
            int c = (((i>>j)&1) ? v[j].second : v[j].first);
            if( ( (j%2==0) && ((i>>j)&1)==0 ) || (j%2)&((i>>j)&1) ) {
                evens.push_back(make_pair(c,j));
            }
            else odds.push_back(make_pair(c,j));
        }
        sort(all(evens));
        sort(all(odds));
        vector<pair<int,int>> w;
        REP(j,N){
            if(j%2 == 0) w.push_back(evens[j/2]);
            else w.push_back(odds[j/2]);
        }
        if(!is_monotone_increasing(w)) continue;
        ans = min(ans, inversion(w));
    }
    cout << (ans==1<<29 ? -1 : ans) << endl;
}

Measured memory_bytes: 384
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a, b, x = MAP()

c = b // x
d = (a - 1) // x
print(c - d)

Measured memory_bytes: 10524
#include <iostream>

using namespace std;

int main(){
    int n, q, i, j, count = 0;
    cin >> n;
    int S[n];
    for(i = 0; i < n; i++) cin >> S[i];
    cin >> q;
    int T[q];
    for(i = 0; i < q; i++) cin >> T[i];
    for(i = 0; i < q; i++){
        for(j = 0; j < n; j++){
            if(S[j] == T[i]){
                count++;
                break;
            }
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3132
# input
a,b=gets.chomp.split(" ").map(&:to_i);

# odd_or_even?
def odd_or_even?(a, b)
  timed_val = a * b
  
  if timed_val % 2 == 0
    'Even'
  else
    'Odd'
  end
end

# output
print("#{odd_or_even?(a, b)}\n")

Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int gcd(int a, int b) {
  return b == 0 ? a : gcd(b, a%b);
}

int main() {
  int p, n;
  while(cin>>p>>n,p||n) {
    int x=1,y=1,u=p,v=1;
    for (int i=1; i<=n; ++i) {  // ツ閉ェツ陛ェ
      for (int j=max(1,int(i*sqrt(p)-1)); j<=min(n,int(i*sqrt(p)+2)); ++j) {
        if (gcd(i,j) > 1) continue;
        if (x*i < j*y && j*j<i*i*p) x=j,y=i;
        if (u*i > j*v && j*j>i*i*p) u=j,v=i;
      }
    }
    printf("%d/%d %d/%d\n",u,v,x,y);
  }
}

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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define all(c) begin(c),end(c)

template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


auto solve() {
    int N;
    cin >> N;

    map<int, int> num;
    FOR(i, 1, N + 1) {
        int u = i;

        int v = 2;
        while (u > 1) {
            if (u % v != 0)
                v++;
            else {
                num[v]++;
                u /= v;
            }
        }
    }

    vi cand;
    FOR(i, 1, 101) {
        if (num[i] >= 2)
            cand.push_back(num[i]);
    }

    int len = cand.size();


    int res = 0;
    REP(i, len) {
        REP(j, len) {
            if (i == j) continue;
            FOR(k, j + 1, len) {
                if (i == k) continue;
                if (cand[i] >= 2 && cand[j] >= 4 && cand[k] >= 4)
                    res++;
            }
        }
    }

    REP(i, len) {
        REP(j, len) {
            if (i == j) continue;
            if (cand[i] >= 14 && cand[j] >= 4)
                res++;
        }
    }

    REP(i, len) {
        REP(j, len) {
            if (i == j) continue;
            if (cand[i] >= 24 && cand[j] >= 2)
                res++;
        }
    }


    REP(i, len) {
        if (cand[i] >= 74)
            res++;
    }

    return res;
}

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

    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 256
//AtCoder ABC059 A - Three-letter acronym
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    string s1,s2,s3;
    cin>>s1>>s2>>s3;
    string ans;
    ans.push_back(s1[0]);
    ans.push_back(s2[0]);
    ans.push_back(s3[0]);
    transform(ans.begin(), ans.end(), ans.begin(), ::toupper);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
 
// Solution
public class Main {
  private static Scanner in;
  private static PrintWriter out;
  private static final String INPUT = ""; // input file name
 
  /**
   * Interactive get next command
   */
  static int get(int pos) {
    out.println(pos + 1);
    out.flush();
    return ni();
  }
 
  static void solve() {
    int x = ni();
    int y = ni();
    
    int f = (y / 2) - x;
    int t = x - f ;
    
    if (y % 2 != 0 || f < 0 || t < 0) {
      out.println("No");
    } else {
    	out.println("Yes");
    }
  }
 
  public static void main(String[] args) throws Exception {
    long S = System.currentTimeMillis();
    in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
    out = new PrintWriter(System.out);
 
    solve();
    out.flush();
    long G = System.currentTimeMillis();
    tr(G - S + "ms");
  }
 
  private static int ni() {
    return Integer.parseInt(in.next());
  }
 
  private static long nl() {
    return Long.parseLong(in.next());
  }
 
  // Math Utils
  private static int pi(int num, int pow) {
    int result = 1;
 
    while (pow > 0) {
      if (pow % 2 == 1) {
        result *= num;
      }
 
      num *= num;
      pow /= 2;
    }
 
    return result;
  }
 
  private static int pim(int num, int pow, int mod) {
    int result = 1;
 
    while (pow > 0) {
      if (pow % 2 == 1) {
        // keep collecting `odd` num in result
        result = (result * num) % mod;
      }
 
      num = (num * num) % mod;
      pow /= 2;
    }
 
    return result;
  }
 
  private static long pl(long num, long pow) {
    long result = 1;
 
    while (pow > 0) {
      if (pow % 2 == 1) {
        result *= num;
      }
 
      num *= num;
      pow /= 2;
    }
 
    return result;
  }
 
  private static long plm(long num, long pow, long mod) {
    long result = 1;
 
    while (pow > 0) {
      if (pow % 2 == 1) {
        // keep collecting `odd` num in result
        result = (result * num) % mod;
      }
 
      num = (num * num) % mod;
      pow /= 2;
    }
 
    return result;
  }
 
  static void tr(Object... o) {
    if (!INPUT.isEmpty())
      out.println(Arrays.deepToString(o));
  }
}

Measured memory_bytes: 38616
import java.util.Scanner;
import java.util.Stack;

public class Main {

	static final boolean debugMode = true;
	static final int[][] dir = { { 0, -1 }, { 0, 1 }, { -1, 0 }, { 1, 0 } };
	static char[][] map = new char[10][10];
	static int[][] countMap = new int[10][10];

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

		int a = readInt(sc);
		int b = readInt(sc);
		int c = readInt(sc);
		int d = readInt(sc);

		System.out.println(a + b > c + d ? "Left" : (a + b == c + d ? "Balanced" : "Right"));
	}

	static void dfs(Stack<Pair> stack, int depth) {
		Pair p = stack.pop();
		for (int[] d : dir) {
			int x = p.getX() + d[0];
			int y = p.getY() + d[1];

			// out of range
			if (x < 0 || x > 9 || y < 0 || y > 9)
				continue;
			// bridge
			int newDep = depth;
			if (map[x][y] == 'x')
				newDep++;
			// update only if fewer
			if (depth >= countMap[x][y] || depth >= 2)
				continue;

			log(String.format("x: %d, y: %d, depth: %d", x, y, newDep));
			countMap[x][y] = newDep;
			stack.add(new Pair(x, y));
			dfs(stack, newDep);
		}
	}

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

	static void log(String s) {
		if (debugMode) {
			System.out.println(s);
		}
		return;
	}

}

class Pair {
	private int x;
	private int y;

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public Pair() {

	}

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

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
 
using namespace std;
 
int main(void)
{
  string s;
  cin >> s;
 
  bool a = false;
  bool b = false;
  bool c = false;
  if (s[0] == 'A') a = true;
 
  for (int i = 2; i < s.size() - 1; ++i) {
    if (s[i] == 'C') {
      b = true;
      break;
    }
  }
 
  int count = 0;
  for (int i = 1; i < s.size(); ++i) {
    if (islower(s[i])) ++count;
  }
  c = count == (s.size() - 2);
 
  cout << (a && b && c ? "AC" : "WA") << endl;
 
  return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

typedef long long ll;
const int N=101000;

int n;
int A[N],B[N],C[N];
ll ans;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",A+i);
	for(int i=1;i<=n;i++)scanf("%d",B+i);
	for(int i=1;i<=n;i++)scanf("%d",C+i);

	std::sort(A+1,A+n+1);
	std::sort(B+1,B+n+1);
	std::sort(C+1,C+n+1);

	for(int i=1;i<=n;i++)
	{
		int x=std::lower_bound(A+1,A+n+1,B[i])-A-1,y=std::upper_bound(C+1,C+n+1,B[i])-C;
		y=(n-y+1);
		ans+=(ll)x*y;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#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 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;

int main()
{
	int a,b;
	cin>>a>>b;
	cout<<(a+b)%24<<endl;
	return 0;
}

Measured memory_bytes: 768
//                        Bismillahir Rahmanir Rahim
//ALGO:
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define FILL(a, x) memset(a, x, sizeof(a))
#define ll long long
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define INF INT_MAX
#define mx 1000010
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<pair<int, int>, null_type,less<pair<int, int> >, rb_tree_tag,tree_order_statistics_node_update>
*/
const double Pi=acos(-1);
using namespace std;
int debug=01;

int main() {
    string s;
    cin>>s;
    int l=s.size()-1;
    int x=l/2;
    for(int i=0; i<=x/2; i++){
        if(s[i]!=s[x-1-i]||s[i]!=s[x+1+i]||s[i]!=s[l-i]){cout<<"No"; return 0;}
    }
    cout<<"Yes";

}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

void rev(char* input)
{
	int index;
	int i;
	
	index = strlen(input) - 1;
	
	for( i = 0; i < index; i++, index-- )
	{
		char buf;
		buf = input[i];
		input[i] = input[index];
		input[index] = buf;
	}
}

char calcNum(char num1, char num2, int* over)
{
	char result = ( (num1 - '0') + (num2 - '0') + *over) % 10 + '0';
	if( (num1 - '0') + (num2 - '0') + *over > 9 )
	{
		*over = 1;
	}
	else
	{
		*over = 0;
	}
	
	return result;
}

void add(char* strnum1, char* strnum2, char* result)
{
	char* longstrnum;
	int i;
	int len1 = strlen( strnum1 );
	int len2 = strlen( strnum2 );
	int over = 0;
	int min;
	int max;
	
	rev( strnum1 );
	rev( strnum2 );
	
	if( len1 > len2 )
	{
		longstrnum = strnum1;
		min = len2;
		max = len1;
	}
	else
	{
		longstrnum = strnum2;
		min = len1;
		max = len2;
	}
	
	for( i = 0; i < min; i++ )
	{
		result[i] = calcNum( strnum1[i], strnum2[i], &over );
	}
	
	for(; i < max; i++ )
	{
		result[i] = calcNum( longstrnum[i], '0', &over );
	}
	
	for(; over == 1; i++ )
	{
		result[i] = calcNum( '0', '0', &over );
	}
	
	result[i] = '\0';
	
	rev( result );
}

int main(void)
{
	int n;
	char strnum[2][1024];
	char result[1024];
	char* resultp;
	int i;
	
	scanf( "%d", &n );
	for( i = 0; i < n; i++ )
	{
		scanf( "%s%s", strnum[0], strnum[1] );
		add( strnum[0], strnum[1], result );
		if( strlen( result ) <= 80 )
		{
			resultp = result;
			printf( "%s\n", resultp );
		}
		else
		{
			printf( "overflow\n" );
		}
	}
	
	return (0);
}

Measured memory_bytes: 588
S = input()
T = input()

cnt = 0
for i in range(len(S))[::-1]:
    is_ok = True
    for j in range(len(T)):
        if i + j >= len(S):
            is_ok = False
            break
        if S[i + j] != '?' and S[i + j] != T[j]:
            is_ok = False
            break
    if is_ok:
        S = S.replace('?', 'a')
        print(S[:i] + T + S[i + len(T):])
        exit()
print('UNRESTORABLE')


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <numeric>
#include <iomanip>
#include <sstream>
using namespace std;

vector<string> split(const string& s, char delim) {
	vector<string> elems;
	stringstream ss(s);
	string item;
	while (getline(ss, item, delim)) {
		if (!item.empty()) {
			elems.push_back(item);
		}
	}
	return elems;
}

int main() {

	long long n;
	cin >> n;

	string s;

	while (true)
	{
		int mod = n % 26;
		if (mod == 0) {
			mod = 26; 
			n--;
		}
		s.push_back(mod - 1 + 'a');
		n /= 26;
		if (n <= 0)
		{
			break;
		}
	}
	std::reverse(s.begin(), s.end());
	cout << s << endl;


	return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> p(N);
    for(int i;i<N;i++){
        cin >> p.at(i);
    }

    int count = 0;
    for(int i;i<N;i++){
        if(p.at(i) != i+1) count++;
    }
    if(count <= 2){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

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

int main()
{
	double m,t,n;
	
	while(scanf("%lf",&m)!=EOF){
		t=m/9.8;
		n=(4.9*t*t+5.0)/5.0;
		printf("%d\n",(int)ceil(n));
	}
	return 0;
}

Measured memory_bytes: 632
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;

const int inf = 1 << 26;
const int mod = 1e9+7;

int n, m;
LL ta, tb;

int main(){
	cin >> n >> m;
	vector<LL> a(n);
	vector<LL> b(m);
	for ( int i = 0; i < n; i ++ ) {
		cin >> a[i];
	}
	for ( int i = 0; i < m; i ++ ) {
		cin >> b[i];
	}
	
	for ( int i = 0; i < n; i ++ ) {
		ta -= a[i]*(n-i-1);
		ta += a[i]*i;
	}
	
	for ( int i = 0; i < m; i ++ ) {
		tb -= b[i]*(m-i-1);
		tb += b[i]*i;
	}
	
	LL q = (abs(ta%mod))*(abs(tb%mod))%mod;
	cout << q << endl;

	return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();

            int count = 0;
            for (int i = 0; i < S.Length; i++)
            {
                if (S[i] != T[i])
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 27288
import java.util.Scanner;

public class Main {


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

		// 入力を受け取る
		final int NUM = scan.nextInt();
		int[] step = new int[NUM];
		boolean[] jump = new boolean[NUM - 1];
		for(int i = 0; i < NUM; i++) {
			step[i] = scan.nextInt();
		}

		for(int i = 0; i < NUM-1; i++) {
			if(step[i] < step[i+1]) {
				jump[i] = false;
			} else {
				jump[i] = true;
			}
		}

		for(int i = 0; i < NUM - 1; i++) {
			if(jump[i]) {
				count++;
			} else {
				if(count > answer) {
					answer = count;
				}
				count = 0;
			}
		}

		if(count > answer) {
			answer = count;
		}
		System.out.println(answer);

	}
}


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

int main(){
	long n,k;
	long ans=0;
	cin>>n>>k;
	long d=n/k; 
	if(k%2==0){
		ans +=pow(d,3);
		if(n-d*k>=k/2){
			ans+=pow(d+1,3);
		}
		else{
			ans+=pow(d,3);
		}
	}
	else{
		ans=pow(d,3);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
typedef long long int ll;
#define FOR(i,a,n) for(int i=(ll)a;i<(ll)n;++i)
#define TFOR(i,n)FOR(i,0,n)
#define ALL(x) x.begin(),x.end();
const int INF = 1LL << 30;
const ll LLINF = 1LL << 60;
int main() {
	std::string s, a;
	std::cin >> s >> a;
	std::cout<<(s[0]==a[2]&&s[1]==a[1]&&s[2]==a[0]?"YES":"NO")<<std::endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define mset(x) memset(x, 0, sizeof(x))
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int cnt(0);
    string s;
    cin >> s;
    int i;
    int ans(0);
    rep(i, sz(s)) {
        if (s[i] == 'S') cnt = 0;
        else cnt++;
        ans = max(ans, cnt);
    }
    cout << ans << endl;
}


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

int main(int argc, char **argv)
{
  string s;
  cin>>s;
  
  if (s[s.size()-1]=='s') s+="es";
  else s+="s";
  
  cout<<s<<"\n";
	return 0;
}


Measured memory_bytes: 3628
from __future__ import division, print_function
import bisect
import math
import heapq
import itertools
import sys
from collections import deque
from atexit import register
from collections import Counter
from functools import reduce
if sys.version_info[0] < 3:
    from io import BytesIO as stream
else:
    from io import StringIO as stream
 
 
if sys.version_info[0] < 3:
    class dict(dict):
        """dict() -> new empty dictionary"""
        def items(self):
            """D.items() -> a set-like object providing a view on D's items"""
            return dict.iteritems(self)
 
        def keys(self):
            """D.keys() -> a set-like object providing a view on D's keys"""
            return dict.iterkeys(self)
 
        def values(self):
            """D.values() -> an object providing a view on D's values"""
            return dict.itervalues(self)
 
    input = raw_input
    range = xrange
 
    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip
 
 
def sync_with_stdio(sync=True):
    """Set whether the standard Python streams are allowed to buffer their I/O.
 
    Args:
        sync (bool, optional): The new synchronization setting.
 
    """
    global input, flush
 
    if sync:
        flush = sys.stdout.flush
    else:
        sys.stdin = stream(sys.stdin.read())
        input = lambda: sys.stdin.readline().rstrip('\r\n')
 
        sys.stdout = stream()
        register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

def main():
    # sys.stdin  = open("input.txt")
    s=input()
    if s[-1]=="s":
        print(s+"es")
    else:
        print(s+"s")

if __name__ == '__main__':
    sync_with_stdio(False)
    main()

Measured memory_bytes: 69260
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <iomanip>
#include <string>
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int mod = 1000000000 + 7;
vector<int> v;
class Calc
{
    // 宣言
    long long a;

    public:
        // 素因数分解
        void decompositPrime(long long a);
};

/*
 * 素因数分解
 */
void Calc::decompositPrime(long long n)
{
    // 割る数の初期値
    a = 2;
    // √n ≧ a ( n ≧ a * a ) の間ループ処理
    while (n >= a * a) {
        // a で割り切れたら、a は素因数
        // そして、割られる数を a で割る
        // a で割り切れなかったら、 a を 1 増加させる
        if (n % a == 0) {
            //printf("%d * ", a);
             v.push_back(a);
            n /= a;
        } else {
            a++;
        }
    }
    // 最後に残った n は素因数
    v.push_back(n);
    //printf("%d\n", n);
}

int main(){
    //std::stack<int> stack;
    long n;
    cin >> n;
    int sq = (int)sqrt(n);
    vector<long long> cnt(sq+1);
    int ans = 0;
    if(n == 1){
        ans = 0;
    }else{
        Calc objCalc;
        objCalc.decompositPrime(n);
        if(v.size() == 1){
            ans = 1;
            cout << ans << endl;
            return 0;
        }
        long tmp = v[0];
        int cnt = 1;
        int cnt2;
        for (int i = 1; i < v.size(); i++){
            if(tmp != v[i]){
                cnt2 = 1;
                while(cnt >= cnt2){
                    ans ++;
                    cnt -= cnt2;
                    cnt2++;
                }
                cnt = 1;
                tmp = v[i];
            }else{
                cnt++;
            }
        }
        cnt2 = 1;
        while(cnt >= cnt2){
            ans ++;
            cnt -= cnt2;
            cnt2++;
        }
        
    }
    cout << ans << endl;
    return 0;
}





Measured memory_bytes: 11152
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    int n, m;
    std::cin>>n>>m;
    std::vector<std::string> a(n), b(m);
    for(int i = 0;i < n;i++){
        std::cin>>a[i];
    }
    for(int i = 0;i < m;i++){
        std::cin>>b[i];
    }
    std::string ans = "No";
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            int cnt = 0;
            for(int k = 0;k < m;k++){
                for(int l = 0;l < m;l++){
                    if(i+k >= n || j+l >= n){
                        continue;
                    }
                    if(a[i+k][j+l] == b[k][l]){
                        //std::cout<<i+k<<":"<<j+l<<std::endl;
                        ++cnt;
                    }
                }
            }
            if(cnt == (m * m)){
                ans = "Yes";
                break;
            }
        }
    }
    std::cout<<ans<<std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int a[3];
int ans;
int main()
{
    for(int i=1;i<=3;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+3+1);
    for(int i=1;i<=2;i++)
    {
    	ans=a[1]+a[2];
    }
    cout<<ans;
}

Measured memory_bytes: 256
x, y, a, b, c = map(int,input().split())
datp = sorted(list(map(int, input().split())), reverse=True)
datq = sorted(list(map(int, input().split())), reverse=True)
datr = list(map(int, input().split()))
dat = sorted(datp[:x] + datq[:y] + datr, reverse=True)
print(sum(dat[:x+y]))

Measured memory_bytes: 29228