akhauriyash/Code-Regression huggingface dataset:
input = STDIN.readlines.map{|line|line.strip.split()}
line = input.shift
n = line[0].to_i
m = line[1].to_i

y_list_hash = Hash.new do |h, k|
    h[k] = []
end

for i in input
    y_list_hash[i[0]].push(i[1].to_i)
end
y_list_hash.each_key do |key|
    y_list_hash[key] = y_list_hash[key].sort
end

rank = Hash.new do |h, k|
    h[k] = Hash.new
end
y_list_hash.each_key do |key|
    r = 1
    for y in y_list_hash[key]
        rank[key][y] = r
        r += 1
    end
end

for i in input
    prefix = i[0].to_i
    suffix = rank[i[0]][i[1].to_i]
    puts(sprintf("%06d%06d", prefix, suffix))
end


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

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N;

int main() {
    cin >> N;

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

    ll ans1 = 0;
    vi A1(A);
    for (int i = 0; i < N; i++) {
        int x = min(A[i], B[i]);
        int y = min(A[i + 1], B[i] - x);
        A[i] -= x;
        A[i + 1] -= y;
        ans1 += x + y;
    }

    ll ans2 = 0;
    vi A2(A);
    for (int i = N - 1; i > 0; i--) {
        int x = min(A[i + 1], B[i]);
        int y = min(A[i], B[i] - x);
        A[i + 1] -= x;
        A[i] -= y;
        ans2 += x + y;
    }

    cout << max(ans1, ans2) << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int selectionSort(int A[],int N){
    int cnt=0;
    int i,j,minj;
    for(i=0; i<N; i++){
        minj = i;
        for(j=i; j<N; j++){
            if(A[j] < A[minj]) minj = j;
        }
        if(minj != i) cnt++;
        int tmp;
        tmp = A[i];
        A[i] = A[minj];
        A[minj] = tmp;
    }

    return cnt;
}

int main(){
    int N,i;
    int A[100];
    int ans;
    
    scanf("%d",&N);
    for(i=0; i<N; i++) scanf("%d",&A[i]);

    ans = selectionSort(A,N);

    for(i=0; i<N; i++){
        if(i != 0) printf(" ");
        printf("%d",A[i]);
    }

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

    return 0;
}


Measured memory_bytes: 2044
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()

diff = [X[i] - X[i - 1] for i in range(1, M)]
diff.sort()
ret = 0
for i in range(len(diff) - N + 1):
    ret += diff[i]
print(ret)


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

#define pb push_back

#define int ll
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;

template<typename T, typename U>
ostream& operator<<(ostream& o, const pair<T,U>& p) {
  return o << "(" << p.first << "," << p.second << ")";
}

template<typename T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  for (const T& x : v)
    o << x << ",";
  return o << "]";
}

const int INF = 1e18;

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, k;
  cin >> n >> k;
  set<int> seen;
  for (int i=0; i<k; ++i) {
    int di;
    cin >> di;
    for (int j=0; j<di; ++j) {
      int snuke;
      cin >> snuke;
      seen.insert(snuke);
    }
  }
  cout << n - seen.size() << endl;
}


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

int main()
{
    int n;
    cin >> n;
    int a[n], b[n], c[n];
    for (int i = 0; i < n; i++)
        cin >> a[i] >> b[i] >> c[i];
    int dp[n][3];
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    for (int i = 1; i < n; i++) {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
    }
    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << "\n";
}


Measured memory_bytes: 2560
const main = stdin => {
  const S = stdin.trim()
  if (S.indexOf('A') !== -1 && S.indexOf('B') !== -1) {
    console.log('Yes')
  } else {
    console.log('No')
  }
}

// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 30260
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>

using namespace std;

const int maxn = 100002;

int n, k;
long long ans;

struct cake
{
	int kind;
	long long base;
};

bool mycmp(const cake &a, const cake &b) {
	return a.base > b.base;
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> k;
	vector<cake> data(n);
	vector<int> freq(n+2);

	for (int i = 0; i < n; ++i)
		cin >> data[i].kind >> data[i].base;

	sort(data.begin(), data.end(), mycmp);
	priority_queue<int, vector<int>, greater<int> > pq;

	long long tot = 0;
	for (int i = 0; i < k; ++i) {
		ans += data[i].base;
		if (!freq[data[i].kind])
			++tot;
		
		++freq[data[i].kind];

		if (freq[data[i].kind] > 1)
			pq.push(data[i].base);
	}

	long long sum = ans;

	ans += tot * tot;

	for (int i = k; i < n && !pq.empty(); ++i) {
		if (freq[data[i].kind] > 0)
			continue;

		sum += data[i].base;
		sum -= pq.top();
		pq.pop();

		++freq[data[i].kind];
		++tot;

		ans = max(ans, sum + tot * tot);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2560
#include <iostream>

using namespace std;

int main()
{
	int n, k = 100000;

	cin >> n;

	for (int i = 1; i <= n; i++)
	{
		k = static_cast<int>(k * 1.05 + 999) / 1000 * 1000;
	}

	cout << k << endl;

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>

using namespace std;

const unsigned int MAX = 200002;
char str[MAX];


int main(){
    int i=0;
    int top;
    int bottom;

    fgets(str, MAX, stdin);

    while(str[i] != '\0'){
        if(str[i] == 'A'){
            top = i;
            break;
        }
        i++;
    }

    i++;
    while(str[i] != '\0'){
        if(str[i] == 'Z')
            bottom = i;
        i++;
    }

    printf("%d\n", bottom - top + 1);
    return 0;
}

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

int main() {
  int toshi,douro;
  cin >> toshi >>douro;
  
  vector<int> v(toshi);
  
  for(int i=0; i<douro;i++){
    int a,b;
    cin >>a >>b;
    for(int j=1; j<=toshi;j++){
      if(a==j)
        v.at(j-1)+=1;
      if(b==j)
        v.at(j-1)+=1;
    }
  }
  
  for(int i=0; i<toshi;i++){
    cout <<v.at(i) << endl;
  }
}


Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

class bipartite_matching {
public:
    int n;
    vector<vector<int>> g;
    vector<int> match;

    bipartite_matching(int n_) : n(n_), g(n_), match(n_), used(n_) {}

    void add_edge(int u, int v) {
        g[u].push_back(v);
        g[v].push_back(u);
    }

    int maximum_matching(void) {
        int res = 0;
        fill(begin(match), end(match), -1);
        for (int v = 0; v < n; ++v) {
            if (match[v] == -1) {
                fill(begin(used), end(used), false);
                if (dfs(v)) res++;
            }
        }
        return res;
    }

private:
    vector<int> used;
    bool dfs(int v) {
        used[v] = true;
        for (int u : g[v]) {
            int w = match[u];
            if (w == -1 || (!used[w] && dfs(w))) {
                match[v] = u; match[u] = v;
                return true;
            }
        }
        return false;
    }
};

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

int n, m;
int a[500], b[500];

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

    while (cin >> n >> m && n) {
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        for (int i = 0; i < m; i++) {
            cin >> b[i];
        }

        bipartite_matching bm(n + m);

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (gcd(a[i], b[j]) != 1) {
                    bm.add_edge(i, n + j);
                }
            }
        }

        cout << bm.maximum_matching() << endl;
    }
}

Measured memory_bytes: 4448
import kotlin.math.*
import java.util.*

const val MOD = 1_000_000_007L

fun readI() = readLine()!!.toInt()
fun readL() = readLine()!!.toLong()
fun readD() = readLine()!!.toDouble()
fun readIs() = readLine()!!.split(' ').map(String::toInt)
fun readLs() = readLine()!!.split(' ').map(String::toLong)
fun readDs() = readLine()!!.split(' ').map(String::toDouble)

fun main(args: Array<String>) {
  val k = readI()
  var mod = 0
  var ans = 0
  do {
    mod = (mod * 10 + 7) % k
    ans++
    if (k < ans) {
      ans = -1
      break
    }
  } while (mod != 0)
  println(ans)
}


Measured memory_bytes: 34596
H, W = map(int, input().split())

def can_move(H, W):
    if W == 0:
        return 0
    elif H == 1 or W == 1:
        return 1
    masu = H * W
    return int((masu / 2) + (masu % 2))

print(can_move(H, W))


Measured memory_bytes: 2940
n = int(input())
for i in range(1,n+1):
    if i % 3 == 0:
        print(" {}".format(i), end='')
        flag = True
    else:
        x = i
        while x > 0:
            if x % 10 == 3:
                print(" {}".format(i), end='')
                break
            x = x // 10
print('')


Measured memory_bytes: 5876
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define f first
#define ss second

const int mod = 1e9+7;
void solve_case()
{
    int n,i,j,t,k,m;
    cin >> n >> m >> k;
    int a[n][m];
    for(i=0; i<n; i++) for(j=0; j<m; j++)
    {
        char c;
        cin >> c;
        if(c=='.') a[i][j] = 0;
        else a[i][j] = 1;
    }
    int ans = 0;
    for(int m1=0; m1 < (1<<n); m1++)
    {
        for(int m2=0; m2 < (1<<m); m2++)
        {
            int cnt=0;
            for(i=0; i<n; i++)
            {
                for(j=0; j<m; j++)
                {
                    if(m1 & (1<<i)) continue;
                    if(m2 & (1<<j)) continue;
                    cnt += a[i][j];
                }
            }
            if(cnt==k) ans++;
        }
    }
    cout << ans << "\n";
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int Testcases = 1;
    //cin >> Testcases;
    while(Testcases--)
    {
        solve_case();
    }
    return 0;
}


Measured memory_bytes: 3652
<?php

$input = explode(' ', rtrim(fgets(STDIN)));

$k = (int) $input[0];
$s = (int) $input[1];

$result = 0;
for ($x = 0; $x <= $k; $x++) {
    for ($y = 0; $y <= $k; $y++) {
        $z = $s - ($x + $y);

        if (0 <= $z && $z <= $k) {
            $result++;
        }
    }
}

echo $result;

Measured memory_bytes: 4728
import copy

N = int(input())

x = list(map(int,input().split()))
sort_x = copy.copy(x)
sort_x.sort()

center_num = (N-1) // 2

for l in x:
    if l <= sort_x[center_num]:
        print(sort_x[center_num+1])
    else:
        print(sort_x[center_num])


Measured memory_bytes: 32724
def mod1(x):
  mod=10**9+7
  ans=1
  y=1
  while y<=x:
    ans=ans*y
    y+=1
    ans=ans%mod
    
  return ans%mod

n,m=map(int,input().split())
if n==m:
  print((2*mod1(n)*mod1(m))%(10**9+7))
elif abs(n-m)==1:
  print((mod1(n)*mod1(m))%(10**9+7))
else:
  print(0)

Measured memory_bytes: 9064
N, A = map(int, input().split(' '))
X = list(map(int, input().split(' ')))
# ans_map[x][y] x+1枚選んで和がyになる組み合わせの数
ans_map = [[0 for i in range(50*(j+1)+1)] for j in range(N)]
count = 0
for n in X:
    count += 1
    for x in range(0, count)[::-1]:
        for y in range(len(ans_map[x])):
            if ans_map[x][y] != 0:
                ans_map[x+1][y+n] += ans_map[x][y]
    ans_map[0][n] += 1
ans = 0
for i in range(N):
    ans += ans_map[i][A*(i+1)]
print(ans)


Measured memory_bytes: 4212
import java.io.BufferedReader;
import java.io.InputStreamReader;

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

	    while (true) {
		    String[] line = br.readLine().split(" ");

		    int n = Integer.parseInt(line[0]);
		    int x = Integer.parseInt(line[1]);

		    if (n == 0 && x == 0) break;

		    int resultCount = 0;
		    for (int i = 1; i <= n; i++) {
		    	for (int j = i + 1; j <= n; j++) {
		    		for (int k = j + 1; k <= n; k++) {

		    			if (i + j + k == x) {
		    				resultCount++;
		    			}
		    		}
		    	}
		    }
		    System.out.println(resultCount);
	    }
	}
}

Measured memory_bytes: 24480
N=int(input())
H=list(map(int,input().split()))
flag=1
count=0
for i in range(N):
    for j in range(i):
        if H[j]>H[i]:
            flag=0
            break
        else:
            flag=1
    if flag==1:
        count=count+1

print(count)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
int n,k,ans;
int main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        ans+=min(x*2,(k-x)*2);
    }
    cout<<ans<<endl;
    return 0;
} 

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

int main(){
    int n,x;
    while(1){
        cin >> n;
        cin >> x;
        if (n == 0 && x == 0){
            break;
        }
        int i,j,k;
        int ans = 0;
        for(i = 1; i < n - 1; i++){
            for(j = i + 1; j < n; j++){
                for(k = j + 1; k <= n; k++){
                    if(i + j + k == x){
                        ans++;
                    }

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


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

void solve()
{
	string s;
	cin>>s;
	int cnt=0;
	int q;
	cin>>q;
	deque<char> qq;
	for(auto it:s)
		qq.push_back(it);
	while(q--){
		int ch;
		cin>>ch;
		if(ch==1)
			cnt++;
		else{
			int x; char c;
			cin>>x>>c;
			if(cnt%2==0){
				if(x==1)
					qq.push_front(c);
				else
					qq.push_back(c);
			}
			else{
				if(x==1)
					qq.push_back(c);
				else
					qq.push_front(c);
			}
		}
	}
	string ans="";
	for(auto it:qq){
		//cout<<qq.front();
		ans+=qq.front();
		qq.pop_front();
	}
	if(cnt%2)
		reverse(all(ans));
	cout<<ans;	
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	return 0;
}

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

using namespace std;

#define EMAX 100000
#define NOT -1

typedef long long LL;

/////Union-Find
LL par[EMAX];
LL rnk[EMAX];
 
//n要素で初期化
void UNinit(LL n){
    for(LL i=0;i<=n;i++){
        par[i]=i;
        rnk[i]=0;
    }
}
 
//木の根を求める
LL UNfind(LL x){
    if(par[x]==x){
        return x;
    }else{
        return par[x]=UNfind(par[x]);
    }
}
 
//xとyの属する集合を併合
void UNunite(LL x,LL y){
    x=UNfind(x);
    y=UNfind(y);
    if(x==y) return;
    if(rnk[x]<rnk[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(rnk[x]==rnk[y]) rnk[x]++;
    }
}
 
//xとyが同じ集合に属するか否か
bool UNsame(LL x,LL y){
    return UNfind(x)==UNfind(y);
}

struct ed{
	int u,v,co;
};

bool comp(const ed& e1,const ed& e2){
	return e1.co<e2.co;
}

int main(void){

	int V,E;
	int s,t,w;
	ed es[EMAX];

	cin>>V>>E;

	for(int i=0;i<E;i++){
		cin>>s>>t>>w;
		es[i].co=w;
		es[i].u=s;
		es[i].v=t;
	}

	sort(es,es+E,comp);
	UNinit(V);
	int res=0;
	for(int i=0;i<E;i++){
		ed e=es[i];
		if(!UNsame(e.u,e.v)){
			UNunite(e.u,e.v);
			res+=e.co;
		}
	}
	cout<<res<<endl;
}

Measured memory_bytes: 2508
import java.util.Scanner;

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

        int len = 3;

        int[] nums = new int[len];
        for (int i = 0; i < len; i++) {
            nums[i] = sc.nextInt();
        }

        int dummy;
        for (int i = len-1; i > 0; i--) {
            for (int j = 0; j < i; j++) {
                if (nums[j] > nums[j + 1]) {
                    dummy = nums[j];
                    nums[j] = nums[j + 1];
                    nums[j + 1] = dummy;
                }
            }
        }

        System.out.println(nums[0] + " " + nums[1] + " " + nums[2]);

        sc.close();
    }
}


Measured memory_bytes: 26196
#include <stdio.h>

int main(void) {
    int A[10][100]={0,0,0,0,0};
    int i,j,x,N;
    char che;
    
    scanf("%d",&N);
    for(i=0;i<=N;i++){
        scanf("%c %d\n",&che,&x);
        //printf("%c %d",che,x);
        switch(che){
            case'S':
            A[0][x] = 1;
             break;
            
            case'H':
            A[1][x] = 1;
             break;
            
            case'C':
            A[2][x] = 1;
             break;
            
            case'D':
            A[3][x] = 1;
             break;
        }
    }
    
    for(j=0;j<5;j++){
         for(i=1;i<=13;i++){
           //printf("%d ",A[j][i]);
             if(A[j][i] != 1){
                switch(j){
                     case 0:
                     printf("S %d\n",i);
                     break;
                     
                     case 1:
                     printf("H %d\n",i);
                      break;
                     
                     case 2:
                     printf("C %d\n",i);
                      break;
                     
                      case 3:
                     printf("D %d\n",i);
                      break;
                 }
             }
          
         }
        //printf("\n");
    }
    
    return 0;
       
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
int n;
int ans = -1e9;
void bitserch(vector<vector<int>> & storedata,vector <vector<int>>  &profit,string s){
    if(s.size()==10){
        //cout<<s<<endl;
        bool all0=true;
        for(int i=0;i<10;i++){
        if(s[i]=='1') all0 = false;
    }
    
    if(all0) return ;
        int tmp=0;
        for(int i=0;i<n;i++){
            int cnt=0;
        for(int j=0;j<10;j++){
            if(storedata[i][j] ==1&&s[j]=='1')
            cnt++;
        }
        tmp+= profit[i][cnt];
    }
    ans= max(ans,tmp);
        return ;
    }
    else {
        bitserch(storedata,profit,s+'0');
        bitserch(storedata,profit,s+'1');
    }
}
int main(void){
     cin>>n;
     vector <vector<int>> storedata(n ,vector <int>(10 ));
    
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            cin>>storedata[i][j];
            
        }
        
    }
    
    vector <vector<int>> profit(n ,vector <int>(11 ));
    for(int i=0;i<n;i++){
        for(int j=0;j<11;j++){
            cin>>profit[i][j];
        }
    }

    bitserch(storedata,profit,"");
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const long long INF = (long long)1e18+1;
#define DIV 1000000007

bool compare_by_pair(pair<long,long> a, pair<long,long> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }
    return a.second == b.second;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long idx=0;
    long N;
    cin >> N;
    long a;
    vector<pair<long, long>> A(N);
    for(size_t i=1;i<=N; i++)
    {
        //出席番号 i の出席したときの教室の人数 A[i]
        cin >> a;
        A[i-1] = make_pair(long(i), a);
    }
    sort(A.begin(), A.end(), compare_by_pair);
    for(size_t i=0;i<N; i++)
    {
        cout << A[i].first << " ";
    }
    cout << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <math.h>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

    ll N, K;

    cin >> N >> K;

    if(K%2==0){

        ll n_K = N / K;
        ll n_K_half = (N + K /2) / K;

        cout << n_K * n_K * n_K + n_K_half * n_K_half * n_K_half << endl;
    }else{

        ll n_K = N / K;
        cout << n_K * n_K * n_K << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[][] card = new int[3][3];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                card[i][j] = sc.nextInt();
            }
        }
        int n = sc.nextInt();
        HashSet<Integer> set = new HashSet<>();
        for (int i = 0; i < n; i++) {
            set.add(sc.nextInt());
        }
        for (int i = 0; i < 3; i++) {
            if ((set.contains(card[i][0]) && set.contains(card[i][1]) && set.contains(card[i][2])) ||
                (set.contains(card[0][i]) && set.contains(card[1][i]) && set.contains(card[2][i]))) {
                    System.out.println("Yes");
                    return;
                }
        }
        if ((set.contains(card[0][0]) && set.contains(card[1][1]) && set.contains(card[2][2])) || 
            (set.contains(card[2][0]) && set.contains(card[1][1]) && set.contains(card[0][2]))) {
                System.out.println("Yes");
                return;
            }
            
		System.out.println("No");
   }

}


Measured memory_bytes: 22228
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Test | diff Test.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Test.cpp && ./a.out

/*

 7/14/2020

 23:25-23:36 pause

 7/15/2020

 9:20-

 */

const int MAX_M=1000+1;
int N,M;
III E[MAX_M];

const int Inf=1e7;
void solve() {
  VV<int> mx(N,VI(N,Inf));
  VV<int> es(N,VI(N,-1));
  REP(i,N) mx[i][i]=0;
  REP(i,M) {
    auto e=E[i];
    int u,v,w; tie(u,v,w)=e;
    mx[u][v]=mx[v][u]=w;
    es[u][v]=es[v][u]=0;
  }

  REP(k,N)REP(i,N)REP(j,N) {
    int d=mx[i][k]+mx[k][j];
    if(d<mx[i][j]) {
      mx[i][j]=d;
      if(es[i][j]==0) es[i][j]=1;
    }
  }

  int res=0;
  REP(j,N)REP(i,j) res+=(es[i][j]==1);
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;

  cin>>N>>M;
  REP(i,M) {
    int u,v,w; cin>>u>>v>>w;
    --u,--v;
    E[i]={u,v,w};
  }
  solve();

  return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
int n;
ll a[300000];
set<ll> s;

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  cin>>n;
  a[0]=0;
  REP(i,n)cin>>a[i+1];
  ll cnt=0;
  REP(i,n)a[i+1]+=a[i];
  REP(i,n+1)s.insert(a[i]);
  sort(a,a+n+1);
  for(auto x:s){
    ll t1=lower_bound(a,a+n+1,x)-a;
    ll t2=upper_bound(a,a+n+1,x)-a;
    ll num=t2-t1;
    cnt+=num*(num-1)/2;
  }
  P(cnt);
  return 0;
}


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

int main()
{
    ll k;
    cin >> k;
    ll n = 0;
    for(int i=1; i<=1000000; ++i){
        n = (10 * n + 7) % k;
        if(n==0){
            cout << i;
            return 0;
        }
    }
    cout << -1;
    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>

using namespace std;
using pii = pair<int, int>;
using ull = unsigned long long;
static int dp[1 << 12];

int match_test(const string& s, const string& t){
	const int n = s.size();
	map<pii, int> mp;
	for(int i = 0; i < n; ++i){
		++mp[pii(s[i], t[i])];
	}
	int c = -1;
	for(const auto p : mp){
		const pii key(p.first.second, p.first.first);
		const int x = p.second;
		const int y = (mp.find(key) != mp.end()) ? mp[key] : 0;
		if(x != y){ return -1; }
		if(key.first == key.second && x % 2 != 0){
			if(n % 2 == 0 || c >= 0){ return -1; }
			c = key.first;
		}
	}
	int mask = 0;
	for(int i = 0; i < n; ++i){
		if(s[i] == c && t[i] == c){ mask |= (1 << i); }
	}
	return mask;
}

int palindrome_test(const string& s){
	const int n = s.size();
	vector<int> h(26);
	for(const int c : s){ ++h[c - 'a']; }
	int odd = -1;
	for(int i = 0; i < 26; ++i){
		if(h[i] % 2 == 1){
			if(odd >= 0){ return -1; }
			odd = i;
		}
	}
	int mask = 0;
	for(int i = 0; i < n; ++i){
		if(s[i] == odd + 'a'){ mask |= (1 << i); }
	}
	return mask;
}

int main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<string> s(n);
	for(int i = 0; i < n; ++i){ cin >> s[i]; }
	vector<vector<int>> matching(n, vector<int>(n, -1));
	for(int i = 0; i < n; ++i){
		matching[i][i] = palindrome_test(s[i]);
		for(int j = 1; j < n; ++j){
			matching[i][j] = matching[j][i] = match_test(s[i], s[j]);
		}
	}
	bool answer = false;
	for(int i = 0; i < (1 << n); ++i){
		if(__builtin_popcount(i) != n / 2){ continue; }
		vector<int> used, unused;
		used.reserve(n / 2);
		unused.reserve((n + 1) / 2);
		for(int j = 0; j < n; ++j){
			if(i & (1 << j)){
				used.push_back(j);
			}else{
				unused.push_back(j);
			}
		}
		vector<int> perm(unused.size());
		for(int j = 0; j < unused.size(); ++j){ perm[j] = j; }
		do {
			int bits = 0;
			for(int j = 0; j < n / 2; ++j){
				bits |= matching[used[j]][unused[perm[j]]];
			}
			if(n % 2 == 1){
				bits |= matching[unused[perm.back()]][unused[perm.back()]];
			}
			if(bits < 0){ continue; }
			if(m % 2 != 0 && bits == 0){ continue; }
			map<ull, int> mp;
			for(int j = 0; j < m; ++j){
				ull h = 0;
				for(int k = 0; k < n / 2; ++k){ h = (h << 5) + (s[used[k]][j] - 'a'); }
				for(int k = 0; k < n / 2; ++k){ h = (h << 5) + (s[unused[perm[k]]][j] - 'a'); }
				++mp[h];
			}
			bool accept = true;
			for(const auto p : mp){
				const int shift = (n / 2 * 5);
				const ull h = p.first;
				const ull lo = h & ((1ull << shift) - 1);
				const ull hi = h >> shift;
				const ull key = (lo << shift) | hi;
				const int x = p.second;
				const int y = (mp.find(key) != mp.end()) ? mp[key] : 0;
				if(x != y){ accept = false; }
			}
			if(accept){
				answer = true;
				break;
			}
		} while(next_permutation(perm.begin(), perm.end()));
	}
	cout << (answer ? "YES" : "NO") << endl;
	return 0;
}



Measured memory_bytes: 256
Sp = input()
T= input()
flag =False
ans_list = []
for i,s in enumerate(Sp):
    if i> len(Sp) - len(T):
        break
    for j,t in enumerate(T):
        if Sp[i+j]==t or Sp[i+j] =="?":
            flag=True
            continue
        else:
            flag =False
            break
    if flag:
        ans_list.append(i)

#print(ans_list)
n_ans_list = []
for i in ans_list:
    n_ans_list.append(
        (Sp[:i]+ T+Sp[i+len(T):]).replace("?","a"))
#print(n_ans_list)
n_ans_list.sort()
if n_ans_list:
    print(n_ans_list[0])
else:
    print("UNRESTORABLE")

Measured memory_bytes: 3064
import sys, re
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
import bisect
from heapq import heappush, heappop

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

N, T = MAP()
wv = [LIST() for _ in range(N)]
dp1 = [[0]*T for _ in range(N+1)]
dp2 = [[0]*T for _ in range(N+1)]


for i in range(N):
	for j in range(T):
		if j < wv[i][0]:
			dp1[i+1][j] = dp1[i][j]
		else:
			dp1[i+1][j] = max(dp1[i][j], dp1[i][j-wv[i][0]]+wv[i][1])

wv = wv[::-1]

for i in range(N):
	for j in range(T):
		if j < wv[i][0]:
			dp2[i+1][j] = dp2[i][j]
		else:
			dp2[i+1][j] = max(dp2[i][j], dp2[i][j-wv[i][0]]+wv[i][1])

wv = wv[::-1]
ans = 0
for i in range(1, N+1):
	tmp = 0
	for j in range(T):
		tmp = max(tmp, dp1[i-1][j] + dp2[N-i][T-1-j])
	ans = max(ans, tmp+wv[i-1][1])

print(ans)


Measured memory_bytes: 186076
/*
  ***
  0.0
  *-*
 * * *
*  *  *
*  *  *
   *
   *
  * *
 *   *
 *   *
 	   	  		*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pp pop_back
#define F first
#define S second
// set <int> :: iterator it = x.begin(); it != x.end(); it ++
using namespace std;
ll n,sum,num,maxi=-10e9,maxn=-10e9,mini=10e9,minn=10e9;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie();	cout.tie();
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	sum=n;
	while(n>=0){
		if(n%7==0){
			cout<<"Yes";
			return 0;
		}
		if(n%4==0){
			cout<<"Yes";
			return 0;
		}
		n-=4;
	}
	if(n%7==0||n%4==0){
		cout<<"Yes";
		return 0;
	}
	while(sum>=0){
		if(sum%4==0||sum%7==0){
			cout<<"Yes";
			return 0;
		}
		sum-=7;
	}
	cout<<"No";
	return 0;
}


Measured memory_bytes: 768
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# 入力の受け取り
n = int(input())
arrA = list(map(int,input().split()))

cbdp = [0,0]
cbdp2 = [i*(i-1)//2 for i in range(2,n+1)]
cbdp += cbdp2
# print(cbdp)

ctA = Counter(arrA)
# print(ctA)

totalconb = 0
for v in ctA.values():
    totalconb += cbdp[v]
# print(totalconb)

for a in arrA:
    print(totalconb-cbdp[ctA[a]]+cbdp[ctA[a]-1])

# print(*ans,sep="\n")
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する



Measured memory_bytes: 31460
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

vector<int> alphabetVector(string s){
    vector<int> ret(26);
    for(char c : s){
        int index = c - 'a';
        ret[index] = 1;
    }
    return ret;
}

int sameAlphabetNum(string s, string t){
    auto v0 = alphabetVector(s);
    auto v1 = alphabetVector(t);

    int count = 0;
    FOR(i, 0, 26){
        if(v0[i] == 1 && v1[i] == 1){
            count++;
        }
    }
    return count;
}

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

    // input
    int N;
    cin >> N;

    string S;
    cin >> S;

    int max_num = 0;

    FOR(i, 1, N){
        string s = S.substr(0, i);
        string t = S.substr(i, N-i);

        int num = sameAlphabetNum(s, t);
        max_num = max(max_num, num);
    }

    p(max_num);
    
    return 0;
}

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

const long long maxn = 1e5+10 ;
const long long mod = 1e9+7 ;
long long pp[maxn] ;
string s ;
long long solve(long long i){
    if(i==s.size()){
        return 1 ;
    }
    if(s[i] == '0'){
        return solve(i+1) % mod;
    }
    long long a = solve(i+1) ;
    return (pp[s.size()-i-1]+2*a)%mod ;

}
int main() {

    cin >> s ;
    pp[0] = 1;
    for(long long i = 1; i < maxn; i++){
        pp[i]=pp[i-1]*3%mod ;
    }
    cout << solve(0) ;

}


Measured memory_bytes: 2816
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define out(str) cout << str << endl

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 N,ans;

int main(){
    cin >> N;
    ans=0;
    int a[N];
    rep(i,N){
        cin >> a[i];
        while(a[i]%2==0){
            ans++;
            a[i] /= 2;
        }
    }
    out(ans);
    return 0;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

char G[1000][1000];
int cost[1000][1000];
int h, w, ch, cw, dh, dw;

#define P pair<int, pii>

int f() {
  ch--;
  cw--;
  dh--;
  dw--;
  cost[ch][cw] = 0;

  priority_queue<P, vector<P>, greater<P>> pq;
  pq.push(mp(0, mp(cw, ch)));

  while (!pq.empty()) {
    P p = pq.top();
    pq.pop();

    if (p.S.F == dw && p.S.S == dh) {
      return p.F;
    }

    for (int y = -2; y <= 2; y++) {
      for (int x = -2; x <= 2; x++) {
        if (y == 0 && x == 0) continue;

        int next = p.F + ((abs(y) + abs(x)) > 1);
        int nx = p.S.F + x;
        int ny = p.S.S + y;

        if (!(0 <= ny && ny < h && 0 <= nx && nx < w)) continue;
        if (G[ny][nx] == '#') continue;
        if (cost[ny][nx] > next) {
          cost[ny][nx] = next;
          pq.push(mp(cost[ny][nx], mp(nx, ny)));
        }
      }
    }
  }

  return -1;
}

int main() {
  cin >> h >> w;
  cin >> ch >> cw;
  cin >> dh >> dw;

  rep(i, h) rep(j, w) cin >> G[i][j];

  rep(i, h) rep(j, w) cost[i][j] = INF;

  cout << f() << endl;
}


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

int a[5];

int calc(int i,int j,int k,int l,int m)
{
    int b[5]={a[i],a[j],a[k],a[l],a[m]};
    int ans=0;
    for(int i=0;i<5;++i)
    {
        if(ans%10==0)
            ans+=b[i];
        else
            ans=(ans+10)/10*10+b[i];
    }
    return ans;
}

int main()
{
    int ans=1000,com=1000;
    for(int i=0;i<5;++i)
        cin>>a[i];
    for(int i=0;i<5;++i)
        for(int j=0;j<5;++j)
            if(i!=j)
                for(int k=0;k<5;++k)
                    if(i!=k&&j!=k)
                        for(int l=0;l<5;++l)
                            if(i!=l&&j!=l&&k!=l)
                                for(int m=0;m<5;++m)
                                {
                                    if(i!=m&&j!=m&&k!=m&&l!=m)
                                        com=calc(i,j,k,l,m);
                                    if(com<ans)
                                        ans=com;
                                }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include "stdio.h"
#include "math.h"
int main(int argc, char const *argv[])
{
	int a,b,c;
	double S,L,h,rad;
	scanf("%d",&a); scanf("%d",&b); scanf("%d",&c);
	rad = (double)c * M_PI / (double)180;
	S = (double)a * b * sin(rad) / 2;
	L = (double)a + b + sqrt( pow(a,2) + pow(b,2) - 2 * a * b * cos(rad) );
	h = (double)b * sin(rad);
	printf("%lf\n",S);
	printf("%lf\n",L);
	printf("%lf\n",h);
	return 0;
}


Measured memory_bytes: 636
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  int sum = 0;
  cin >> n;
  vector<int>d(n);
  for(int i=0; i<n; i++) {
    cin >> d[i];
  }
  for(int i=0; i<n; i++) {
    for(int j=i+1; j<n; j++) {
      sum += d[i]*d[j];
    }
  }
  cout << sum << endl;
  return 0;
}


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

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    vector<pair<int,int> >v(m,make_pair(0,0));
    int lmax=0,mmin=INT_MAX;
    for(int i=0;i<m;i++)
    {
     cin>>v[i].first>>v[i].second;
     if(v[i].first>lmax)lmax=v[i].first;
     if(v[i].second<mmin)mmin=v[i].second;
    }
    if(mmin-lmax+1>0)cout<<mmin-lmax+1;
    else cout<<"0";
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n;
  cin >> n;
  mat a(n,vec(3));
  for(ll i=0;i<n;i++) for(ll j=0;j<3;j++) cin >> a[i][j];
  mat dp(n+1,vec(3));
  for(ll i=0;i<n;i++) {
    for(ll j=0;j<3;j++) {
      for(ll k=0;k<3;k++) {
        if(j==k) continue;
        dp[i+1][j]=max(dp[i+1][j],dp[i][k]+a[i][j]);
      }
    }
  }
  cout << max({dp[n][0],dp[n][1],dp[n][2]}) << endl;
}

Measured memory_bytes: 11136
from collections import deque
import copy

def main():
  H, W = map(int, input().split())
  maps = [[j=="#" for j in input()] for i in range(H)]
  q = deque([(i, j) for i in range(H) for j in range(W) if maps[i][j]])
  count = 0
  while True:
    nq = deque()
    while q:
      x, y = q.popleft()
      if x > 0 and not maps[x-1][y]:
        maps[x-1][y] = True
        nq.append((x-1,y))
      if y > 0 and not maps[x][y-1]:
        maps[x][y-1] = True
        nq.append((x,y-1))
      if x < H-1 and not maps[x+1][y]:
        maps[x+1][y] = True
        nq.append((x+1,y))
      if y < W-1 and not maps[x][y+1]:
        maps[x][y+1] = True
        nq.append((x,y+1))
    if nq:
      q = copy.copy(nq)
    else:
        break
    count += 1
  print(count)

if __name__ == "__main__":
  main()

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define INF 2e8
#define all(a) a.begin(), a.end()

int main() {
  unordered_set<char> stLower;
  repeat(nAsciiCode, 97, 97 + 26) { stLower.emplace(nAsciiCode); }

  string szGiven;
  cin >> szGiven;
  bool fAccepted = true;

  if (szGiven[0] != 'A') {
    fAccepted = false;
  }

  auto itC = find(szGiven.begin() + 2, szGiven.end() - 1, 'C');
  if (itC == szGiven.end() - 1) {
    fAccepted = false;
  } else {
    int nPosiC = distance(szGiven.begin(), itC);
    repeat(i, 1, szGiven.size()) {
      if (i != nPosiC and not stLower.count(szGiven[i])) {
        fAccepted = false;
      }
    }
  }

  puts(fAccepted ? "AC" : "WA");
}


Measured memory_bytes: 256
s=input()
a,b=int(s[:2]),int(s[2:])
c,d=0,0
if 1<=a<=12:
    c=1
if 1<=b<=12:
    d=1
if c==1:
    if d==0:print("MMYY")
    else:print("AMBIGUOUS")
else:
    if d==0:print("NA")
    else:print("YYMM")

Measured memory_bytes: 3060
object Main extends App {
  import scala.io.StdIn.readLine
  import scala.io.StdIn.readInt
  
  	val bingo = (0 until 3).map(x => readLine.split(" ").map(_.toInt)).toList
  	val state = readInt;
  	val called = (0 until state).map(x => readInt).toList
  	val punched = bingo.map(_.map(x => called.contains(x)))
  	
  //this is the smartest solution in the universe
  	if(punched(0)(0) && punched(0)(1) && punched(0)(2)){println("Yes")}
  	else if(punched(1)(0) && punched(1)(1) && punched(1)(2)){println("Yes")}
  	else if(punched(2)(0) && punched(2)(1) && punched(2)(2)){println("Yes")}
  	else if(punched(0)(0) && punched(1)(0) && punched(2)(0)){println("Yes")}
  	else if(punched(0)(1) && punched(1)(1) && punched(2)(1)){println("Yes")}
  	else if(punched(0)(2) && punched(1)(2) && punched(2)(2)){println("Yes")}
  	else if(punched(0)(0) && punched(1)(1) && punched(2)(2)){println("Yes")}
    else if(punched(2)(0) && punched(1)(1) && punched(0)(2)){println("Yes")}
  	else println("No")
    
}

Measured memory_bytes: 54684
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main(){
    ll n, a, b, x, xm;
    cin >> n >> a >> b;
    cin >> xm;
    ll hi = 0;
    rep(i, n-1){
        cin >> x;
        if((x-xm)*a > b){
            hi += b;
        }else{
            hi += (x-xm)*a;
        }
        xm = x;
    }
    cout << hi << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {
        String[] inputs = Io.read();
        Integer[][] parsed = parse(inputs);

        int[][] blocks = new int[parsed[0][0]][parsed[0][1]];
        for (int i = 0; i < blocks.length; i++) {
            Arrays.fill(blocks[i], 1);
        }

        for (int y = 0; y < blocks.length; y++) {
            if (y < parsed[1][0]) {
                Arrays.fill(blocks[y], 0);
            }
            Arrays.fill(blocks[y], 0, parsed[1][1], 0);
        }

        int allBlocks = 0;
        for (int y = 0; y < blocks.length; y++) {
            for (int x = 0; x < blocks[y].length; x++) {
                allBlocks += blocks[y][x];
            }
        }

        Io.write(allBlocks);
    }

    private static Integer[][] parse(String[] lines) {
        Integer[][] result = new Integer[lines.length][2];
        for (int i = 0; i < lines.length; i++) {
            String[] split = lines[i].split(" ");
            result[i][0] = Integer.parseInt(split[0]);
            result[i][1] = Integer.parseInt(split[1]);
        }
        return result;
    }
}

class Io {

    /**
     * 標準入力から1行ずつ受け取る
     * @return
     * @throws IOException
     */
    public static String[] read() throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        List<String> inputs = new ArrayList<>();
        String line;
        while ((line = br.readLine()) != null) {
            if (line.equals(""))
                break;

            inputs.add(line);
        }
        br.close();
        return inputs.toArray(new String[0]);
    }

    /**
     * 標準出力
     * @param answer
     */
    public static void write(int answer)
    {
        System.out.println(answer);
    }
}


Measured memory_bytes: 22484
#include<iostream>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;

int main(){
  int n;
  while(cin >> n,n){
    vector<ll> cur(n);
    for(int i=0;i<n;i++)cin >> cur[i];

    int ans = 0;
    for(;;){
      map<ll,ll> freq;
      
      for(int i=0;i<n;i++)freq[cur[i]]++;

      vector<ll> nxt(n);
      for(int i=0;i<n;i++)nxt[i] = freq[cur[i]];

      bool f = true;
      for(int i=0;i<n;i++){
	if(nxt[i] != cur[i])f = false;
      }
      if(f)break;
      ans++;
      cur = nxt;
    }

    cout << ans << endl;
    for(int i=0;i<n;i++)cout << cur[i] << " \n"[i==n-1];
  }
}
      

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
int n, k, a[N];

bool check(int x) {
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (x < a[i]) cnt += a[i] / x;
		if (cnt > k) return 0;
	}
	return 1;
}

int main()
{
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) scanf("%d", a+i);
	int l = 0, r = 1e9+1;
	while (l+1 < r) {
		int mid = (l+r)>>1;
		if (check(mid)) r = mid;
		else l = mid;
	}
	printf("%d\n", r);
	return 0;
}

Measured memory_bytes: 4600
import numpy as np

N = int(input())
H = np.array(list(map(int, input().split())))
cnt = 0
f_f = 0 #前の花
n_f = 0 #今の花
v = 0 # 谷の数

cnt = min(H)
H -=cnt
precnt = 0
for i in range(max(H)):
    a = 0
    for j in range(N):
        v=0
        if j == 0 and H[j] > 0:
            v+=1
        elif H[j] > 0 and H[j-1] == 0:
            v+=1
        cnt+=v
        a+=v

    for j in range(N):
        if H[j] > 0:
            H[j]-=1
print(cnt)

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

int main()
{
    int N,i,j,k,n1,n2,n3,n4;
    scanf("%d",&N);
    n1=N%10;
    N=N/10;
    n2=N%10;
    N=N/10;
    n3=N%10;
    N=N/10;
    n4=N%10;
    if((n1==n2&&n2==n3)||(n2==n3&&n3==n4))
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 128