akhauriyash/Code-Regression huggingface dataset:
//Do what you can't.

import java.io.*;
import java.util.*;
import java.math.BigInteger;

public class Main{
  public static void main(String[] args) {
    InputReader in = new InputReader(System.in);
    PrintWriter w = new PrintWriter(System.out);
    w.println(Math.max(in.nextLong() * in.nextLong(), in.nextLong() * in.nextLong()));

    w.close();
  }
  static class InputReader {

    private final InputStream stream;
    private final byte[] buf = new byte[8192];
    private int curChar, snumChars;
    private SpaceCharFilter filter;

    public InputReader(InputStream stream) {
      this.stream = stream;
    }

    public int snext() {
      if (snumChars == -1)
        throw new InputMismatchException();
      if (curChar >= snumChars) {
        curChar = 0;
        try {
          snumChars = stream.read(buf);
        } catch (IOException e) {
          throw new InputMismatchException();
        }
        if (snumChars <= 0)
          return -1;
      }
      return buf[curChar++];
    }

    public int nextInt() {
      int c = snext();
      while (isSpaceChar(c)) {
        c = snext();
      }
      int sgn = 1;
      if (c == '-') {
        sgn = -1;
        c = snext();
      }
      int res = 0;
      do {
        if (c < '0' || c > '9')
          throw new InputMismatchException();
        res *= 10;
        res += c - '0';
        c = snext();
      } while (!isSpaceChar(c));
      return res * sgn;
    }

    public long nextLong() {
      int c = snext();
      while (isSpaceChar(c)) {
        c = snext();
      }
      int sgn = 1;
      if (c == '-') {
        sgn = -1;
        c = snext();
      }
      long res = 0;
      do {
        if (c < '0' || c > '9')
          throw new InputMismatchException();
        res *= 10;
        res += c - '0';
        c = snext();
      } while (!isSpaceChar(c));
      return res * sgn;
    }

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

    public String readString() {
      int c = snext();
      while (isSpaceChar(c)) {
        c = snext();
      }
      StringBuilder res = new StringBuilder();
      do {
        res.appendCodePoint(c);
        c = snext();
      } while (!isSpaceChar(c));
      return res.toString();
    }

    public String nextLine() {
      int c = snext();
      while (isSpaceChar(c))
        c = snext();
      StringBuilder res = new StringBuilder();
      do {
        res.appendCodePoint(c);
        c = snext();
      } while (!isEndOfLine(c));
      return res.toString();
    }

    public boolean isSpaceChar(int c) {
      if (filter != null)
        return filter.isSpaceChar(c);
      return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    private boolean isEndOfLine(int c) {
      return c == '\n' || c == '\r' || c == -1;
    }

    public interface SpaceCharFilter {
      public boolean isSpaceChar(int ch);
    }
  }
}

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

int main(){
	int n;
	cin >> n;
	
	vector<int> v(n);
	for(int &e : v) 
		cin >> e;

	long long ans = 0;
	for(int i = 1;i < n;++i){
		ans += max(v[i],v[i-1]) - v[i];
		v[i] = max(v[i],v[i-1]);
	}	
	cout << ans;
}


Measured memory_bytes: 3944
#include<stdio.h>

int main()

{
   int a[1000];

   int v,i;

    scanf("%d",&v);

    for(i=1;i<=v;i++)
    {
        scanf("%d",&a[i]);
    }

   for(i=v;i>=1;i--)
   {
       printf("%d",a[i]);

       if(i!=1)
       {
           printf(" ");
       }

   }

printf("\n");






    return 0;



}



Measured memory_bytes: 2040
package main
 
import (
	"fmt"
)
 
func main() {
	var a, b, c, d int
	fmt.Scanf("%d %d %d %d", &a, &b, &c, &d)
	left := a + b
	right := c + d
	if left == right {
		fmt.Printf("%s", "Balanced")
	} else if left > right {
		fmt.Printf("%s", "Left")
	} else {
		fmt.Printf("%s", "Right")
	}
}

Measured memory_bytes: 1832
#include<bits/stdc++.h>
using namespace std;
const int N=1E5+7;
int arr[N];
int main(){
	int n,k,q;
	cin>>n>>k>>q;
	for(int i=1;i<=q;i++){
		int x;	
		cin>>x;
		arr[x]++;
	}
	for(int i=1;i<=n;i++){
		int a=k-(q-arr[i]);
		if(a<=0) cout<<"No"<<endl;
		else cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1024
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if
#define Lsn (x<<1)
#define Rsn (x<<1|1)
#define Mid (L+R>>1)

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=200000+19;
const ll oo=1ll<<60;

int A[N],B[N],val[N],pl[N],pr[N];
int n,k,l,r;
ll dp[N],L[N],R[N];
ll sum,ans;

int mn[N*4],pos,Ql,Qr,Qv;

void Work(int x,int L,int R,int Qx){
	pos=min(pos,mn[x]);
	if (L==R) return;
	Qx<=Mid?Work(Lsn,L,Mid,Qx):Work(Rsn,Mid+1,R,Qx);
}
void Modify(int x,int L,int R){
	if (Ql<=L&&R<=Qr){
		mn[x]=min(mn[x],Qv);
		return;
	}
	if (Ql<=Mid) Modify(Lsn,L,Mid);
	if (Qr>Mid) Modify(Rsn,Mid+1,R);
}

int s[N];

void Add(int x,int v){
	for (;x<=*val;x+=x&-x) s[x]+=v;
}
int Qry(int x){
	int res=0;
	for (;x;x-=x&-x) res+=s[x];
	return res;
}

int main(){
	n=IN(),k=IN();
	For(i,1,n+1){
		A[i]=IN(),B[i]=IN();
		if (A[i]>k/2&&B[i]==1){
			puts("-1");
			return 0;
		}
		if (B[i]==2){
			L[i]=0;
			R[i]=k-1;
		} else{
			L[i]=sum;
			R[i]=sum-2*A[i];
		}
		sum-=2*A[i];
	}
	For(i,1,n+1){
		val[++*val]=L[i]=(L[i]%k+k)%k;
		val[++*val]=R[i]=(R[i]%k+k)%k;
	}
	val[++*val]=0;
	val[++*val]=k-1;
	sort(val+1,val+*val+1);
	*val=unique(val+1,val+*val+1)-val-1;
	For(i,1,n+1){
		L[i]=lower_bound(val+1,val+*val+1,L[i])-val;
		R[i]=lower_bound(val+1,val+*val+1,R[i])-val;
	}
	For(i,0,N*4) mn[i]=n+1;
	for (int i=n;i;i--){
		dp[i]=oo;
		
		pos=n+1;
		Work(1,1,*val,L[i]);
		pl[i]=pos;
		if (pos==n+1) dp[i]=0;
		lf (L[pos]<=R[pos]){
			dp[i]=dp[pos]+(val[L[pos]]-val[L[i]]+k)%k;
		} else{
			dp[i]=dp[pos]+val[L[pos]]-val[L[i]];
		}
		
		pos=n+1;
		Work(1,1,*val,R[i]);
		pr[i]=pos;
		
		if (L[i]<=R[i]){
			Ql=1,Qr=L[i]-1,Qv=i;
			if (Ql<=Qr) Modify(1,1,*val);
			Ql=R[i]+1,Qr=*val,Qv=i;
			if (Ql<=Qr) Modify(1,1,*val);
		} else{
			Ql=R[i]+1,Qr=L[i]-1,Qv=i;
			if (Ql<=Qr) Modify(1,1,*val);
		}
	}
	ans=oo;
	For(i,1,n+1){
		if (Qry(L[i])==0) ans=min(ans,dp[i]);
		if (Qry(R[i])==0){
			ll tmp;
			pos=pr[i];
			if (pos==n+1) tmp=0;
			lf (L[pos]<=R[pos]){
				tmp=dp[pos]+(val[L[pos]]-val[R[i]]+k)%k;
			} else{
				tmp=dp[pos]+val[L[pos]]-val[R[i]];
			}
			ans=min(ans,tmp);
		}
		if (L[i]<=R[i]){
			Add(1,1);
			Add(L[i],-1);
			Add(R[i]+1,1);
			Add(*val+1,-1);
		} else{
			Add(R[i]+1,1);
			Add(L[i],-1);
		}
	}
	cout<<ans-sum<<endl;
}

Measured memory_bytes: 12160
#include <stdio.h>
#define MIN 1
#define MAX 9

int main(void){
        int i,j;
        for(i = MIN; i <= MAX; i++){
                for(j = MIN; j <= MAX; j++){
                        printf("%dx%d=%d\n",i,j,i*j);
                }
        }
        return 0;

}

Measured memory_bytes: 0
#include<iostream>

using namespace std;

int main()
{
	int x, y;

	while (true)
	{
		cin >> x >> y;

		if (x == 0 && y == 0)
			break;
		else
		{
			if (x > y)
			{
				int t;
				t = x;
				x = y;
				y = t;
			}
			cout << x << " " << y << endl;
		}
	}
}

Measured memory_bytes: 3016
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}

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

  vector<int> a;
  bool is_ok[1000005] = {};

  rep(i, n)
  {
    int x;
    cin >> x;
    a.push_back(x);
    is_ok[x] = true;
  }

  sort(a.begin(), a.end());
  int ans = 0;
  int index = 0;

  for (auto i : a)
  {
    // cout << "===" << endl;
    // cout << i << endl;

    if (index <= a.size() - 2 && i == a[index + 1])
    {
      is_ok[i] = false;
      index++;
      continue;
    }

    for (int j = 2; j <= a[a.size() - 1] / i; j++)
    {
      // cout << "j: " << j << " " << i * j << endl;
      if (binary_search(a.begin(), a.end(), i * j))
      {
        int x = i * j;
        is_ok[x] = false;
      }
    }
    index++;
  }

  for (auto i : a)
  {
    if (is_ok[i])
    {
      // cout << i << endl;
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5300
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void ABC159A()
{
	int N, M;
	cin >> N >> M;
	cout << (N * (N-1)  + M * (M-1)) / 2 << endl;
}
int main()
{
	ABC159A();
	return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
strToInt s = (read :: String -> Int) s

main :: IO ()
main = do
    -- 文字列の入力
    s <- getLine
    -- 出力
    putStrLn $ [head s] ++ (show $ length s - 2) ++ [last s]


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

int main(){
	int N, K, ans = 1, i;
	scanf("%d%d", &N, &K);
	for(i = 0; i < N; i++){
		if(ans < K){
			ans *= 2;
		}
		else{
			ans += K;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    N, K = li_input()
    L = []
    D = collections.defaultdict(lambda: 0)

    for i in range(N):
        a, b = li_input()
        L.append(a)
        D[a] += b

    L = sorted(set(L))

    c = 0
    for l in L:
        c += D[l]

        if c >= K:
            print(l)
            return

main()


Measured memory_bytes: 16316
#include<iostream>
#include<vector>
 
using namespace std;
 
int main(int argc, char const *argv[])
{
    int N, K, Q;
    
    cin >> N >> K >> Q;
    int temp = K - Q;
 
    vector<int> Person(N, temp);
 
    for (int i = 0; i < Q; i++)
    {
        cin >> temp;
        Person[temp - 1]++;
    }
    
    for (auto &&p : Person)
    {
        cout << ((p > 0)? "Yes": "No") << endl;
    }
 
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;

  int maxx = x, miny = y;
  for (int i = 0; i < n; i++) {
    int xi;
    cin >> xi;
    maxx = maxx < xi ? xi : maxx;
  }
  for (int i = 0; i < m; i++) {
    int yi;
    cin >> yi;
    miny = miny > yi ? yi : miny;
  }

  if (miny > maxx) {
    cout << "No War" << endl;
  } else {
    cout << "War" << endl;
  }

  return 0;
}


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

# avg = sum(A) / N
sum_a = sum(A)
ans = float('inf')
ansf = -1
for i, ai in enumerate(A):
    # diff = abs(ai - avg)
    diff = abs(N * ai - sum_a)
    if diff < ans:
        ans = diff
        ansf = i

print(ansf)

Measured memory_bytes: 3060
import math
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

ma,mb = AB[0]
for a, b in AB[1:]:
  i = -(-ma //a)
  j = -(-mb //b)
  k = max(i, j)
  
  ma = k*a
  mb = k*b
  
print(ma + mb)
   

Measured memory_bytes: 3188
N = gets.chop.to_i
WS = gets.chop.split.map(&:to_i)

w_sum = WS.inject(0, &:+)
ans = Float::INFINITY

1.upto(N - 1) do |i|
  ans = [ans, (w_sum - WS[0..i].inject(0, &:+) * 2).abs].min
end

puts ans

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define f first
#define s second
#define mk make_pair
using namespace std;
typedef pair<int,int> P;
int h,w,ans=0;
int dx[]={-1,-1,-1,0,0,1,1,1};
int dy[]={1,0,-1,1,-1,1,0,-1};
string s[1001];
bool used[1001][1001];
main(){
	cin>>h>>w;
	r(i,h)cin>>s[i];
	queue<pair<pair<int,int>,int> >q;
	r(i,h)r(j,w)if(isdigit(s[i][j])){
		int sum=0;
		r(k,8){
			int y=i+dy[k];
			int x=j+dx[k];
			if(y<0||x<0||x>=w||y>=h)continue;
			if(s[y][x]=='.')sum++;
		}
		if(s[i][j]-'0'<=sum){
			used[i][j]=1;
			q.push(mk(mk(i,j),1));
		}
	}
	while(!q.empty()){
		vector<P>v;
		while(!q.empty()){
			pair<pair<int,int>,int>p=q.front();q.pop();
			ans=p.s;
			s[p.f.f][p.f.s]='.';
			v.push_back(P(p.f.f,p.f.s));
		}
		r(i,v.size())r(j,8){
			int y=v[i].f+dy[j];
			int x=v[i].s+dx[j];
			if(0<=y&&y<h&&0<=x&&x<w&&isdigit(s[y][x])){
				int sum=0;
				r(k,8){
				  int yy=y+dy[k];
			      int xx=x+dx[k];
			      if(yy<0||xx<0||xx>=w||yy>=h)continue;
			      if(s[yy][xx]=='.')sum++;
			    }
			    if(s[y][x]-'0'<=sum&&!used[y][x]){
			    	used[y][x]=1;
			    	q.push(mk(mk(y,x),ans+1));
			    }
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 5124
#include <stdio.h>

int main (void)
{
  int n,k;
  scanf("%d %d",&n,&k);
  int ans = k;
  
  for(int i = 1;i < n;i++){
    ans= ans*(k-1);
  }
  
  printf("%d",ans);
  
  return 0;
}

Measured memory_bytes: 128
while True:
    m,f,r=list(map(int,input().split()))
    if m==-1 and f==-1 and r==-1:
        break
    elif m==-1 or f==-1:
        print("F")
    elif m+f>=80:
        print("A")
    elif 65<=m+f<80:
        print("B")
    elif 50<=m+f<65:
        print("C")
    elif 30<=m+f<50:
        if r>=50:
            print("C")
        else:
            print("D")
    elif m+f<30:
        print("F")

Measured memory_bytes: 7560
import sys
input=sys.stdin.buffer.readline
w,h=map(int,input().split())

L=[]

for i in range(w):
    n=int(input())
    L.append([n,0])
    
for i in range(h):
    n=int(input())
    L.append([n,1])
    
L.sort()

ans=0
for i in range(len(L)):
    if L[i][1]==0:
        ans+=L[i][0]*(h+1)
        w-=1
    else:
        ans+=L[i][0]*(w+1)
        h-=1
print(ans)

Measured memory_bytes: 64348
#include "bits/stdc++.h"

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
char capitalize(char c) { return static_cast<char>(std::toupper(static_cast<unsigned char>(c))); }
// template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
// template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "YES"
#define NO  "NO"
#define MOD 1000000000+7
#define forit(v) for(auto it = v.begin(); it != v.end(); ++it)

using namespace std;

int R;
int G;
int B;
int N;

signed main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int num = 0;
  // num = numeric_limits<int>::max();
  // num = numeric_limits<int>::min();
  bool flag = false;
  // flag = true;

  cin >> R >> G >> B >> N;

  for (int r = 0; ; ++r) {
    if (r * R == N) ++num;
    if (r * R >= N) break;
    for (int g = 0; ; ++g) {
      int tmp = r * R + g * G;
      if (tmp == N) ++num;
      if (tmp >= N) break;

      // B
      int tmpB = N - tmp;
      if (tmpB % B == 0) ++num;
    }
  }

  cout << num << endl;
  // cout << (flag ? YES : NO) << endl;
  
  return 0;
}


Measured memory_bytes: 256
words = lambda t : list(map(t, input().split()))
n = int(input())
a = words(int)
b = words(int)

ttl = 0
for i in range(n):
    if a[i] >= b[i]:
        ttl += b[i]
        a[i] -= b[i]
    else:
        ttl += min(a[i]+a[i+1],b[i])
        a[i+1] = max(0, a[i+1] - (b[i] - a[i]))
    #print(a)
print(ttl)


Measured memory_bytes: 19116
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	string a, b, c; cin >> a >> b >> c;
	cout << a[0] << b[0] << c[0] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define INF 10000000000

ll a, b, c, n, m, x, y, z, w, h, ans = 0, cnt = 0, mx = 0, mn = INF;
string s;

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

    cin >> n >> m;
    if((n >= 2) && (m >= 2)){
        cout << (n - 2) * (m - 2) << endl;
    }else if((n == 1) && (m != 1)){
        cout << m - 2 << endl;
    }else if((n != 1) && (m == 1)){
        cout << n - 2 << endl;
    }else{
        cout << 1 << endl;
    }
}


Measured memory_bytes: 256
INFTY = 998244353
N = int(input())
D = list(map(int,input().split()))
C = {}
dmax = 0
for i in range(N):
    d = D[i]
    dmax = max(dmax,d)
    if d not in C:
        C[d] = 0
    C[d] += 1
if D[0]!=0 or C[0]!=1:
    flag = 1
else:
    flag = 0
    for i in range(dmax+1):
        if i not in C:
            cnt = 0
            flag = 1
            break
if flag==1:
    cnt = 0
else:
    cnt = 1
    for i in range(1,dmax):
        cnt = (cnt*(C[i]**C[i+1]))%INFTY
print(cnt)

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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const int N = (int) 1e6 + 7;
int n, sumtop;

struct T {
  int top;
  int mn;
};

bool operator < (T a, T b) {
  return min(a.mn, a.top + b.mn) > min(b.mn, b.top + a.mn);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  vector<T> a, b;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    int top = 0, mn = 0;
    for (auto &ch : s) {
      if (ch == '(') {
        top++;
      } else {
        top--;
      }
      mn = min(mn, top);
    }
    a.push_back({top, mn});
    /**if (top >= 0) {
      a.push_back({top, mn});
    } else {
      b.push_back({top, mn});
    }**/
    sumtop += top;
  }
  if (sumtop != 0) {
    cout << "No\n";
    return 0;
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  int cur = 0;
  for (auto &it : a) {
    if (cur + it.mn < 0) {
      cout << "No\n";
      return 0;
    }
    cur += it.top;
  }
  for (auto &it : b) {
    if (cur + it.mn < 0) {
      cout << "No\n";
      return 0;
    }
    cur += it.top;
  }
  cout << "Yes\n";
  return 0;
}


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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

A,P = inputIL()

print((A*3+P)//2)

Measured memory_bytes: 65436
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;
string s;
bool pal(string k)
{
	rep(i,(k.size()+1)/2) if(k[i]!=k[k.size()-i-1]) return 0;
	return 1;
}
int main()
{
	cin>>s;
	if(pal(s)&&pal(s.substr(0,(s.size()-1)/2))&&pal(s.substr((s.size()+3)/2-1,(s.size()-1)/2))) re("Yes")
	else re("No")}

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

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) &= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double PI = (double)acos(-1);
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  int N;
  char s[310][310];
  cin >> N;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> s[i][j];
    }
  }

  map<int, int> mp;

  for (int a = 0; a < N; a++) {
    for (int b = 0; b < N; b++) {
      int tmp = b - a;
      mp[tmp]++;
    }
  }

  int ans = 0;
  for (int d = -N + 1; d < N; d++) {

    bool flag = true;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (s[i][j] != s[(j + d + N) % N][(i - d + N) % N]) {
          flag = false;
          break;
        }
        if (!flag) break;
      }
    }

    if (flag) ans += mp[d];
  }

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


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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define PI (acos(-1))

int main(){
  int N,C;
  cin >> N >> C;
  vector<int> table(100010);
  bool b[40][100010];

  rep(i,N){
    int s,t,c;
    cin >> s >> t >> c;
    if(b[c][s]){
      s++;
    }else{
      b[c][s] = true;
    }
    if(b[c][t]){
      t--;
    }else{
      b[c][t] = true;
    }
    table[s]++;
    table[t+1]--;
  }

  reps(i,1,100010){
    table[i] += table[i-1];
  }

  sort(all(table));
  reverse(all(table));
  cout << table[0] << endl;
}

Measured memory_bytes: 4352
//include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cstring> 
#include <set>
#include <map>
#define db double 
#define LL unsigned long long
#define int LL
#define rep(i,x,y) for (int i=x;i<=y;++i)
#define mp make_pair
#define ft first
#define sd second
#define P pair<int ,int >
#define pb push_back 
using namespace std;
const int N  =  2e5+233;
//const int mod = ;
void read(int &x)
{
	int f=1;
	x=0;
	char ch=getchar();
	while (!isdigit(ch)) (ch=='-'?f=-1:0),ch=getchar();
	while ( isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	x*=f;
	return ;
}
int n,X,x[N],f[N],ans,s[N];
signed main()
{
	read(n);read(X);
	rep(i,1,n) read(x[i]);reverse(x+1,x+1+n);
	rep(i,1,n) s[i]=s[i-1]+x[i];
	ans=n*2*X+5*s[n];
	rep(k,1,n)
	  {
	    LL S=(n+k)*X+s[k]*2;
	    for (int j=3,i=k;i<n+k;i+=k,j+=2)
	      S+=(s[min(i,n)]-s[i-k])*j;
	    ans=min(ans,S);
	  }
	printf("%llu",ans);
	return 0;	
}

Measured memory_bytes: 4480
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

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

    int k, n; cin>>k>>n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];

    vector<int> b(2*n);
    for(int i=0; i<n; i++) b[i] = a[i];
    for(int i=n; i<2*n; i++) b[i] = a[i-n] + k;

    int ans = inf;
    for(int i=n-1; i<2*n; i++){
        chmin(ans, b[i] - b[i-(n-1)]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			w = scanner.nextInt();
			h = scanner.nextInt();
			n = scanner.nextInt();
			if ((w | h | n) == 0)
				break;
			size = new int[n + 1];
			pos = new int[n + 1][2];
			for (int i = 0; i < n; i++) {
				int b = scanner.nextInt();
				int k = scanner.nextInt();
				size[b] = k;
			}
			m = new int[h][w];
			
			for (int[] a : m)
				Arrays.fill(a, -1);
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					int x = scanner.nextInt();
					m[i][j] = x;
					if (x > 0) {
						pos[x][0] = i;
						pos[x][1] = j;
					}
				}
			}
			assign = new int[n + 1][4];
			c = 0;
			ans = new int[h][w];
			f(1);
			if (c == 1) {
				for (int i = 0; i < h; i++) {
					for (int j = 0; j < w; j++) {
						if (j > 0)
							System.out.print(" ");
						System.out.print(ans[i][j]);
					}
					System.out.println();
				}
			} else {
				System.out.println("NA");
			}

		}
	}

	private void f(int k) {
		if (k == n + 1) {
			c++;
			if (c == 2)
				return;
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					int a = m[i][j];
					ans[i][j] = a >= 100 ? a / 100 : a;
				}
			}
			return;
		}
		int s = size[k];
		for (int x = 1; x <= s; x++) {
			if (s % x != 0)
				continue;
			for (int lj = pos[k][1] + 1 - x; lj <= pos[k][1]; lj++) {
				if (lj < 0 || lj > w)
					continue;
				loop: for (int li = pos[k][0] + 1 - s / x; li <= pos[k][0]; li++) {
					if (li < 0 || li > h)
						continue;
					int rj = lj + x;
					int ri = li + s / x;
					if (rj > w)
						continue;
					if (ri > h)
						continue;
					for (int i = li; i < ri; i++) {
						for (int j = lj; j < rj; j++) {
							if (m[i][j] != 0 && m[i][j] != k)
								continue loop;

						}
					}
					for (int i = li; i < ri; i++) {
						for (int j = lj; j < rj; j++) {
							if (m[i][j] != k)
								m[i][j] = k * 100;
						}
					}
					f(k + 1);
					if (c == 2)
						return;
					for (int i = li; i < ri; i++) {
						for (int j = lj; j < rj; j++) {
							if (m[i][j] != k)
								m[i][j] = 0;
						}
					}
				}
			}

		}

	}

	int[][] m;
	int[] size;
	int[][] pos;
	int[][] assign;
	int w, h, n, c;
	int[][] ans;
}

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

#define inrep int t; cin >> t; for(int tc=1; tc<=t; tc++)
#define ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
	ios;
	string s; cin >> s;
	long long n = stoll(s);
	long long sum = 0;
	for(int i=0; i<s.length(); i++) {
		sum += s[i]-'0';
	}

	if (n % sum == 0) {
		cout << "Yes" << "\n";
	}
	else cout << "No" << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1e6+69;
const int mod = 1e9+7;
const int INF = 1e18;
int m,n;
int t;
int cnt;
int x,y,z;
struct vl{
	int x,y;
	bool operator<(vl t)const {
		if(x==t.x)return y<t.y;
		return x<t.x;
	}
};
int a[MAXN];
int sum[MAXN];
int k;
string s;
map<int,vector<int> >mp;
signed main(){																																																																																						ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	cin>>s;
	int cur = n;
	a[n]=1;
	while(cur>=0){
		int tmp = cur;
		for(int i=1;i<=m;i++){
			if(cur-i<0){
				cur = tmp;
				goto ss;
			}
			if(s[cur-i]-'0'==0){
				tmp=cur-i;
				a[tmp]=a[cur]+1;	
			}
		}
		//cout<<cur<<' '<<tmp<<endl;
		if(tmp==cur){
			cout<<-1;
			return 0;
		}
		cur = tmp;
	}
	ss:;
	cnt = a[0];
	vector<int>ans;
	for(int i=0;i<=n;i++){
		if(a[i]==cnt){
			ans.push_back(i);
			cnt--;
		}
	}
	for(int i=1;i<ans.size();i++){
		cout<<ans[i]-ans[i-1]<<' ';
	}
}  

Measured memory_bytes: 5236
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

    unordered_map<int, int> m;

    int special_coder = 0;
    for (int i = 0; i < N; ++i) {
        int ai;
        cin >> ai;

        int color = ai / 400;
        if (color < 8) {
            m[color]++;
        } else {
            special_coder++;
        }
    }

    if (m.size() == 0) {
        cout << 1 << ' ' << special_coder << endl;
        return 0;
    }

    int min_ans = m.size();
    int max_ans = m.size() + special_coder;

    cout << min_ans << ' ' << max_ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define iter(it,a) for(auto it=a.begin();it!=a.end();it++)
#define mp make_pair
#define pb push_back
#define F first
#define S second
typedef long long ll;
typedef long double ld;
 
int main(){
    cin.tie(0);ios_base::sync_with_stdio(0);
    int n,k;
    cin>>n>>k;
    int a[n];
    int maxi = 1;
    int g;
    rep(i,0,n){
    	cin>>a[i];
    	maxi=max(maxi,a[i]);
    	if(i==0){
    		g=a[0];
    	}
    	else{
    		g=__gcd(g,a[i]);
    	}
    }
    if(k>maxi){
    	cout<<"IMPOSSIBLE"<<endl;
    	return 0;
    }
    else if(k==maxi){
    	cout<<"POSSIBLE"<<endl;
    	return 0;
    }
    if(k%g==0){
    	cout<<"POSSIBLE"<<endl;
    	return 0;
    }
    cout<<"IMPOSSIBLE"<<endl;
    return 0;
} 

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,w) for (int i = 0;i < (w); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using ld = long double; 
int INF = 1e9;
int main(){
  int n;cin >> n;
  vector<P> pos(n);
  vector<int> num(n);
  rep(i,n){
    cin >> pos[i].first >> pos[i].second;
    num[i] = i+1;
  }
  ld sum = 0;
  do{
    rep(i,n-1){
      sum += sqrt(ld((pos[num[i]-1].first - pos[num[i+1]-1].first)*(pos[num[i]-1].first - pos[num[i+1]-1].first)+(pos[num[i]-1].second - pos[num[i+1]-1].second)*(pos[num[i]-1].second - pos[num[i+1]-1].second)));
      }
  }while(next_permutation(num.begin(),num.end()));
  rep(i,n) sum /= (i+1);
  printf("%.6Lf\n",sum);


}

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

struct node {
  struct node *right;
  int key;
  struct node *left;
};
typedef struct node * NodePointer;

void init(void);
NodePointer makenode(int);
void insert(int,NodePointer);
void preorder(NodePointer);
void inorder(NodePointer);

NodePointer head, tail;

int main(){
  char str[7];
  int n,k;

  init();
  scanf("%d" ,&n);
  while(n--){
    scanf("%s" ,str);

    if(str[0] == 'i'){
      scanf("%d" ,&k);
      insert(k, head);
    }else{
      inorder(head->right);
      printf("\n");
      preorder(head->right);
      printf("\n");
    }
  }

  return 0;
}

void init(void){
  head=makenode(-1);
  tail=makenode(-1);
  head->right=tail;
  head->left=tail;
}

NodePointer makenode(int k){
  NodePointer x;

  x=malloc(sizeof(struct node));
  x->key = k;
  x->left = x->right = tail;

  return x;
}

void insert(int k, NodePointer p){
  if(k < p->key){
    if(p->left == tail){
      p->left = makenode(k);
    }else{
      insert(k , p->left);
    }
  }else{
    if(p->right == tail){
      p->right = makenode(k);
    }else{
      insert(k , p->right);
    }
  }
}

void preorder(NodePointer node){
  if(node != tail){
    printf(" %d", node->key);
    preorder(node->left);
    preorder(node->right);
  }
}

void inorder(NodePointer node){
  if(node != tail){
    inorder(node->left);
    printf(" %d", node->key);
    inorder(node->right);
  }
}

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

uint64_t f(uint64_t n)
{
  return n % 4 == 0 ? n : n xor f(n - 1);
}

int main()
{
  uint64_t a, b;
  cin >> a >> b;
  if (a > 0) a--;
  cout << (f(a) xor f(b)) << endl;
}


Measured memory_bytes: 256
import string
 
S = input()
if len(S) < 26:
    for c in string.ascii_lowercase:
        if c not in S:
            break
    print(S + c)
else:
    ret = None
    for i in range(1, 26):
        idx = 25 - i
        if max(S[idx:]) != S[idx]:
            mc = min([c for c in S[(idx+1):] if c > S[idx]])
            ret = S[:idx] + mc
            break
    if ret is None:
        print(-1)
    else:
        print(ret)

Measured memory_bytes: 3768
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

LL N, k, fl[55], f[55];

LL g(LL layer, int rank){
  if(rank == 0){
    return (layer > 0);
  }

  assert(rank >= 0);
//  assert(layer >= 0);

  if(layer <= 1 + fl[rank - 1]) return g(layer - 1, rank - 1);

  layer -= (2 + fl[rank - 1]);

  return 1LL + f[rank - 1] + g(layer, rank - 1);
}

int main(){
  FAST_IO

  cin >> N >> k;

  fl[0] = f[0] = 1;

  for(int rep = 1; rep <= N; ++rep){
    fl[rep] = 3 + 2LL * fl[rep - 1];
    f[rep] = 1 + 2LL * f[rep - 1];
  }

//  for(int rep = 0; rep <= N; ++rep){
//    cout << f[rep] << " " << fl[rep] << '\n';
//  }
//
//  cout << "\n-------------------\n";
//  for(int layer = 0; layer < 30; ++layer){
//    cout << g(layer, 3) << '\n'; 
//  }

  cout << g(k, N) << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define FORN(i, x, y) for (int i = x; i <= y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define scan1(X) scanf("%d", &X)
#define scan2(X, Y) scanf("%d%d", &X, &Y)
#define scan3(X, Y, Z) scanf("%d%d%d", &X, &Y, &Z)
#define scan4(X, Y, Z, W) scanf("%d%d%d%d", &X, &Y, &Z, &W)
#define scanl1(X) scanf("%lld", &X);
#define scanl2(X, Y) scanf("%lld%lld", &X, &Y)
#define scanl3(X, Y, Z) scanf("%lld%lld%lld", &X, &Y, &Z)
#define scanl4(X, Y, Z, W) scanf("%lld%lld%lld%lld", &X, &Y, &Z, &W)
#define print1(X) printf("%d\n", X);
#define print2(X, Y) printf("%d %d\n", X, Y);
#define print3(X, Y, Z) printf("%d %d %d\n", X, Y, Z);
#define print4(X, Y, Z, W) printf("%d %d %d %d\n", X, Y, Z, W);
#define printl1(X) printf("%lld\n", X);
#define printl2(X, Y) printf("%lld %lld\n", X, Y);
#define printl3(X, Y, Z) printf("%lld %lld %lld\n", X, Y, Z);
#define printl4(X, Y, Z, W) printf("%lld %lld %lld %lld\n", X, Y, Z, W);
#define max3(X, Y, Z) max(X, max(Y, Z))
#define max4(X, Y, Z, W) max(max(X, Y), max(Z, W))
#define min3(X, Y, Z) min(X, min(Y, Z))
#define min4(X, Y, Z, W) min(min(X, Y), min(Z, W))
#define popcount(X) __builtin_popcount(X)
#define all(x) x.begin(), x.end()
#define size(X) (int)X.size()
#define mp make_pair
#define pb push_back
#define fr first
#define sc second
#define lc(x) 2 * x
#define rc(x) 2 * x + 1
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pldld;
const long long l_inf = numeric_limits<long long>::max();
const long long l_ninf = numeric_limits<long long>::min();
const int inf = numeric_limits<int>::max();
const int ninf = numeric_limits<int>::min();
const double pi = 1.00 * acos(-1.00);
const double eps = 1e-8;
void cio(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
ll gcd(ll a, ll b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a * (b / gcd(a, b))); }
int sq( int x ) {return x * x;}
////////////////////////////////////////////////////////////////////Header
int main () {
    cio();
    int n;
    cin>>n;
    map<pii, int> cnt;
    FOR(i, 0, n) {
        double y; cin>>y;
        ll x = llround(y * 1e9);
        int a = 0, b = 0;
        while ( x % 2==0 ) {
            a++;
            x/=2;
        }
        while ( x % 5 == 0 ) {
            b++;
            x/=5;
        }
        cnt[{a, b}]++;
    }
    ll ans = 0;
    for ( auto p : cnt ) for ( auto q : cnt ) {
        if ( p.fr.fr + q.fr.fr >= 18 && p.fr.sc + q.fr.sc >= 18 ) {
            if ( p.fr == q.fr ) {
                ans += 1ll * ( p.sc - 1 ) * p.sc / 2;
            }
            else if ( p < q )  ans += 1ll * p.sc * q.sc;
        }
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int r, D, x;
	cin >> r >> D >> x;
	for (int i = 0; i < 10; ++i) {
		x = r * x - D;
		cout << x << '\n';
	}
	return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
N = II()
A = list(MI())
ans = 0
cum = defaultdict(int)
def couple_combination(n):
    if n >= 2:
        return int(n * (n - 1) / 2)
    else:
        return 0
for v in A:
    cum[v] += 1
for v in cum.values():
    ans += couple_combination(v)
for v in A:
    print(max(0,ans - cum[v] + 1))


Measured memory_bytes: 25912
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int length = Integer.parseInt(br.readLine());
		String[] inputNum = br.readLine().split(" ");
		List<Integer> numArray = new ArrayList<Integer>();
		for (int i = 0; i < length; i++) {
			numArray.add(Integer.parseInt(inputNum[i]));
		}
		Collections.reverse(numArray);
		for (int i = 0; i < numArray.size(); i++) {
			if (i == numArray.size()-1) {
				System.out.println(numArray.get(i));
			}else {
				System.out.print(numArray.get(i) + " ");
			}
		}
	}

}

Measured memory_bytes: 17112