akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define N 500000
#define INFTY 1000000000
 
void merge(int*,int,int,int);
void mergeSort(int*,int,int);
int n,count=0;
 
 
int main(){
  int i,A[N],l,r;
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
   
 
  mergeSort(A,0,n);
 
  for(i=0;i<n;i++){
    if(i>=1)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n%d\n",count);
   
  return 0;
}
void mergeSort(int *s, int left, int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(s,left,mid);
    mergeSort(s,mid,right);
    merge(s,left,mid,right);
  }
}
void merge(int *A, int left, int mid, int right){
  int i,j,k,n1,n2;
   
  n1=mid-left;
  n2=right-mid;
  int L[n1+1],R[n2+1];
  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
 
  L[n1]=INFTY;
  R[n2]=INFTY;
 
  i=0;
  j=0;
 
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i=i+1;
    }
    else{
      A[k]=R[j];
      j=j+1;
    }
  }
  count+=(i+j);
}

Measured memory_bytes: 4508
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
def main():
    n=int(input())
    a=list(map(int,input().split()))
    # 0個の皿がx0枚、1個の皿がx1枚、2個の皿がx2枚、3個の皿がx3枚
    # x0=n-x1-x2-x3
    ca={1:a.count(1),2:a.count(2),3:a.count(3)}
    memo=[[[-1]*(n+2) for _ in range(n+2)] for _ in range(n+2)]
    memo[0][0][0]=0
    for x3 in range(ca[3]+1):
        for x2 in range(ca[2]+ca[3]+1-x3):
            for x1 in range(ca[1]+ca[2]+ca[3]+1-x3-x2):
                if (x1,x2,x3)==(0,0,0):continue
                tmp=0
                if x1>0:tmp+=memo[x1-1][x2][x3]*x1
                if x2>0:tmp+=memo[x1+1][x2-1][x3]*x2
                if x3>0:tmp+=memo[x1][x2+1][x3-1]*x3
                tmp+=n
                tmp/=x1+x2+x3
                memo[x1][x2][x3]=tmp
    print(memo[ca[1]][ca[2]][ca[3]])
if __name__=='__main__':
    main()

Measured memory_bytes: 385152
N, K = map(int, input().split())

cnt = 0
for i in range(K + 1, N + 1):#b = K + 1 ... N
  k = int(N / i)
  l = N % i
  if K == 0:
    cnt += k * (i - K) + max(0, l - K)
  else:
    cnt += k * (i - K) + max(0, l - K + 1)
  #print(cnt, k, l)
  
print(cnt)  


Measured memory_bytes: 9096
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int A[3010];
ll mod=998244353, dp[3010][3010]={};

int main() {
	int N, S;
	cin >> N >> S;
	for(int i=0; i<N; ++i) cin >> A[i];
	for(int i=0; i<=S; ++i) dp[0][i]=0;
	ll ans=0;
	for(int i=0; i<N; ++i){
		for(int j=0; j<=S; ++j){
			if(j<S) dp[i+1][j]=dp[i][j];
			if(j==A[i]) (dp[i+1][j] += i+1) %= mod;
			if(j>A[i]) (dp[i+1][j] += dp[i][j-A[i]]) %= mod;
		}
		(ans += (dp[i+1][S]*(N-i))%mod) %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 70784
/*
 * FileName:     C_fix
 * CreatedDate:  2020-08-18 13:40:12 +0900
 * LastModified: 2020-08-18 13:42:43 +0900
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
    int n;scanf("%d", &n);
    int *a = malloc(n*sizeof(int));
    int xor = 0;
    for(int i=0; i<n; i++){
        scanf("%d", a+i);
        xor ^= a[i];
    }
    for(int i=0; i<n; i++){
        printf("%d ", xor ^ a[i]);
    }
    printf("\n");
    free(a);
    return 0;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  string s;cin>>s;cout<<(s=="ABC"?"ARC":"ABC");
}

Measured memory_bytes: 3592
k=0
import math
def combinations_count(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
a,b=map(int,input().split())
if b<2:
    if b==1:
        j=0
    else:
        j=b
else:
    j=combinations_count(b, 2)
for i in range(a):
    k=k+i
h=j+k
print(h)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int l,r;
	cin >> l >> r;
	int ans = 2019;
	if (l/2019 == r/2019)
	{
		int newl,newr;
		newl = l % 2019;
		newr = r % 2019;
		for (int i = newl;i < newr; i++)
		{
			for (int j = i+1; j <= newr; j++)
			{
				ans = min((i * j) % 2019,ans);
			}
		}
		printf("%d\n",ans);
	}
	else if(l/2019 + 1 == r/2019 && l%2019 > r%2019)
	{
		int newl = l% 2019;
		int newr = r % 2019;
		for (int i = newl - 2019;i < newr; i++)
		{
			for (int j = i+1; j <= newr; j++)
			{
				ans = min((i * j) % 2019,ans);
			}
		}
		printf("%d\n",ans);
	}
	else
	{
		for (int i = 0;i < 2019; i++)
		{
			for (int j = i+1; j <= 2019; j++)
			{
				ans = min((i * j) % 2019,ans);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int N, K; cin >> N >> K;
  int x[N]; rep(i,N) cin >> x[i];
  int ans = 1000000000;
  rep(i,N-K+1){
    int MAX = x[i+K-1], MIN = x[i];
    int tmp;
    if (MIN > 0 || MAX<0 ){
      tmp = max(abs(MIN), abs(MAX));
    } 
    else {
      tmp = MAX - MIN + min(MAX, abs(MIN));
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;


  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 4024
#include<cstdio>
#include<algorithm>
#define x first
#define y second
typedef std::pair<int,int> pii;
inline void read(int&r)
{
	register char c;r=0;
	do c=getchar();while(c<'0'||c>'9');
	do r=r*10+c-'0',c=getchar();while(c>='0'&&c<='9');
}

pii a[200001];
int main()
{
	int h,w,n,i,j=0,l=1;
	read(h),read(w),read(n);
	for(i=0;i<n;i++)read(a[i].x),read(a[i].y);
	a[n++]=pii(h+1,1);
	std::sort(a,a+n);
	for(i=1;i<h;i++)
	{
		while(a[j].x<=i)j++;
		if(a[j].x==i+1)
			if(a[j].y<=l)
				return printf("%d\n",i),0;
			else if(a[j].y==l+1)
				l--;
		l++;
	}
	printf("%d\n",h);
}

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

ll dest;
int matrix[22][22];
ll mod = 1000000007;
ll dp[22][(1<<22)];

ll go(int man,ll mask,int n)
{
    if(man == n+1)
    {
        if(mask == 0)
            return 1;
        return 0;
    }
    
    if(dp[man][mask] != -1)
        return dp[man][mask];
    
    ll ans = 0;
    
    for(int woman=0;woman<n;woman++)
    {
        bool avail = (((1<<(woman))&mask) == 0) ? 0 : 1;
        if(avail == 1 && matrix[man][woman+1] == 1)
        {
            ans = (ans + (go(man+1,mask ^ (1<<woman),n))%mod)%mod;
        }
    }
    
    return dp[man][mask] = ans;
}

int main()
{
    int n;
    cin >> n;
    
    dest = (1<<n)-1;

    memset(dp,-1,sizeof(dp));
    
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            cin >> matrix[i][j];
        }
    }
    
    cout << go(1,dest,n) << endl;
    return 0;
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

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

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n,m;
    cin>>n;

    vector<vector<int>> buka(n);

    rep(i,n-1){
        int ai;
        cin>>ai;
        --ai;
        buka[ai].pb(i+1);
    }

    rep(i,n){
        cout<< buka[i].size() <<endl;
    }
    //cout <<fixed<<setprecision(16)<< << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 13904
import java.util.Scanner;

public class Main {

	static long mod = 1000000007;

	public static void main(String[] args) {
		// AtCoder_A
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int H = sc.nextInt();
		int W = sc.nextInt();
		int N = sc.nextInt();
	    // Scannerクラスのインスタンスをクローズ
		sc.close();
		// 出力
		System.out.println(Math.min((N-1)/H+1, (N-1)/W+1));
	}
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        v.push_back(x);
    }
    for (int i = v.size() - 1; i >= 0; --i) {
        cout << v[i];
        if (i == 0) {
            cout << "\n";
        }
        else {
            cout << " ";
        }
    }
}

Measured memory_bytes: 1212
N, M, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arui = [0] * (N + 1)
brui = [0] * (M + 1)
for i in range(N):
    arui[i + 1] = a[i] + arui[i]
for i in range(M):
    brui[i + 1] = b[i] + brui[i]

ans = 0
bcnt = M
for i in range(N + 1):
    if arui[i] > K:
        break

    while brui[bcnt] + arui[i] > K:
        bcnt -= 1
    ans = max(ans, i + bcnt)

print(ans)


Measured memory_bytes: 47544
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
int main(void) {
  int n, k;
  cin >> n >> k;
  cout << ((n - 1) + (k - 1) - 1) / (k - 1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<sys/time.h>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int ri()
{
	register int x=0;register bool f=0;register char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();};
	return f?-x:x;
}
void wi(ll x)
{
	if(x<0)	x=-x,putchar('-');
	if(x>9)	wi(x/10);
	putchar('0'+x%10);
}

int main()
{
	ll n=ri(),m=ri();
	if(n>m)	swap(n,m);
	if(n>=2)	wi((n-2)*(m-2));
	else
	{
		if(m==1)	wi(1);
		else	wi(m-2);
	}
	putchar('\n');
	return 0;
}


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

using namespace std;
#define int long long
#define pb push_back
int n, q;

long long x[100005], l, y[100005][20];
vector<int> vec;

signed main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> x[i];
        vec.pb(x[i]);
    }
    vec.pb(-1);
    sort(vec.begin(), vec.end());
    cin >> l;
    cin >> q;
    for(int i = 1; i <= n; i++){
        int it = upper_bound(vec.begin(), vec.end(), x[i] + l) - vec.begin() - 1;
        y[i][0] = it;
    }
    for(int i = 1; i <= 18; i++){
        for(int j = 1;j <= n; j++)
            y[j][i] = y[y[j][i - 1]][i - 1];
    }
    while(q--){
        int a, b, sum = 0;
        cin >> a >> b;
        if(a == b){
            cout << sum << "\n";
            continue;
        }
        if(b < a)
            swap(a, b);
        for(int i = 18; i >= 0; i--){
            if(y[a][i] < b){
                a = y[a][i];
                sum += (1 << i);
            }
        }
        sum++;
        cout << sum << "\n";
    }
}



Measured memory_bytes: 18164
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
LIN=lambda : list(IN())
mod=1000000007

#+++++

def like_agc3(www):
	lkagc=['AGC','ACG','GAC']
	return  not (www in lkagc)

def like_agc(www,w):
	if www[0]+www[2]+w =='AGC':
		return False
	if www[0]+www[1]+w == 'AGC':
		return False
	return like_agc3(www[1]+www[2]+w)
	

def main():
	ll=['AAA','AAC','AAG','AAT','ACA',       'ACC', 'ACG', 'ACT',"AGA", "AGC",     "AGG", "AGT", "ATA", "ATC" ,"ATG",     "ATT", "CAA", "CAC", "CAG", "CAT",     "CCA", "CCC", "CCG", "CCT", "CGA" , "CGC" ,"CGG" ,"CGT" ,"CTA" ,"CTC" , "CTG" ,"CTT" ,"GAA" ,"GAC" ,"GAG" , "GAT" ,"GCA" ,"GCC" ,"GCG" ,"GCT" , "GGA" ,"GGC" ,"GGG" ,"GGT" ,"GTA" , "GTC" ,"GTG" ,"GTT" ,"TAA" ,"TAC" , "TAG" ,"TAT" ,"TCA" ,"TCC" ,"TCG" , "TCT" ,"TGA" ,"TGC" ,"TGG" ,"TGT" , "TTA" ,"TTC" ,"TTG" ,"TTT"]
	dll={}
	for i,w in enumerate(ll):
		dll[w]=i
	
	n = int(input())
	#b , c = IN()
	#s = input()
	#cc=[1]*64
	#cc[6]=0#ACG
	#cc[9]=0#AGC
	#cc[18]=0#CAG
	cll='AGCT'
	cc = [1 if like_agc3(w) else 0 for w in ll]
	for i in range(4,n+1):
		#print(i)
		ncc=[0]*64
		for word in ll:
			for c in cll:
				if like_agc(word, c):
					next_word=word[1:]+c
					ncc[dll[next_word]]+=cc[dll[word]]
					ncc[dll[next_word]] %= mod
		cc=ncc
	ret = sum(cc) % mod
	print(ret)
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 43684
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> a(1000001, 0);
    vector<int> c(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> c[i];
        ++a[c[i]];
    }
    for (int i = 1; i < 1000001; ++i)
        for (int j = 2 * i; j < 1000001; j += i)
            a[j] += a[i];
    int odp = 0;
    for (int i = 0; i < n; ++i)
        if (a[c[i]] == 1)
            ++odp;
    cout << odp;
    return 0;
}


Measured memory_bytes: 8008
a = list(map(int,input().split()))
b=list()
c=list()
d=([0]*a[0])
for i in range(a[1]):
    b = int(input())
    c = list(map(int,input().split()))
    for k in range(len(c)):
        d[c[k]-1]=1
print(len(d)-d.count(1))

Measured memory_bytes: 67860
from bisect import bisect_left
from collections import deque

n = int(input())
A = [int(input()) for _ in range(n)]

D = deque([])

for a in A:
    i = bisect_left(D, a)
    if i == 0:
        D.appendleft(a)
    else:
        D[i-1] = a

print(len(D))

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

int main(){
  int n;
  cin >> n;
  
  int array[200001] = {0};
  for(int i=0; i < n-1; i++){
    int manager;
    cin >> manager;
    array[manager-1]++;
  }
  
  for(int j=0; j < n; j++){
    cout << array[j] << endl;
  }
  
  return 0;
}

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

using namespace std;

namespace {

#define VEVE(i, a, b) for (ll i = a, __##i = b; i < __##i; ++i)
#define DYDY(i, a, b) for (ll i = a, __##i = b; i > __##i; --i)
#define RARA(x, seq) for (auto &x : seq)
#define SIZE(x) ((ll)(x.size()))
#define ALL(x) x.begin(), x.end()

typedef int ll;
typedef double dd;

void Solve(ll) {
  ll n;
  cin >> n;
  vector<ll> lens(2 * n);
  RARA(l, lens) cin >> l;
  sort(ALL(lens));
  ll res = 0;
  VEVE(i, 0, n) res += lens[2 * i];
  cout << res << endl;
}

void Init() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
}
}

int32_t main() {
#ifdef AZN
  freopen("input.txt", "r", stdin);
#endif
  Init();
  ll tests = 1;
  VEVE(test, 1, tests + 1) Solve(test);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, res = 0, ss;
    double sum = 0;
    cin >> n;
    vector<int> v(n);
    for (auto & i : v) {
        cin >> i;
        sum += i;
    }
    sum /= n;
    sum = round(sum);
    ss = (int)sum;
    for (auto i : v) res += (i - ss) * (i - ss);
    cout << res;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int N;
int A[1 << 18];
vector<PII> dp[1 << 18];

int main(){
  scanf("%d", &N);
  int lim = 1 << N;
  rep(i, lim) {
    scanf("%d", &A[i]);
    dp[i].emplace_back(PII(A[i], 1));
  }

  rep(i, N) {
    rep(st, lim) {
      int b = 1 << i;
      if (b & st) {
        dp[st].insert(dp[st].end(), all(dp[st ^ b]));
        sort(all(dp[st]), greater<PII>());
        
        vector<PII> tmp;
        for (auto &p : dp[st]) {
          if (tmp.empty()) {
            tmp.emplace_back(p);
            continue;
          }

          if (tmp.back().first == p.first) {
            tmp.back().second += p.second;
            continue;
          }

          tmp.emplace_back(p);
        }
        tmp.resize(2);
        dp[st].swap(tmp);
      }
    }
  }

  int ans = 0;
  reps(st, 1, lim) {
    assert(!dp[st].empty());
    if (dp[st][0].second > 1) {
      ans = max(ans, dp[st][0].first*2);
      printf("%d\n", ans);
    } else {
      assert(dp[st].size() > 1);
      ans = max(ans, dp[st][0].first + dp[st][1].first);
      printf("%d\n", ans);
    }
  }
  
  return 0;
}


Measured memory_bytes: 23296
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<cstdio>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
#define INF 1000000007

#define ARRAY_MAX 55

ll n,x,ans = 0;
ll p[ARRAY_MAX];
ll b[ARRAY_MAX];
ll cnt[ARRAY_MAX];


void dfs(ll now,ll sum){
    //レベルnow
    sum++;
    if(now == 0){
        ans++;
    }
    if(sum == x){
        //合計に達した
        return;
    }else if(sum + cnt[now-1] < x){
        //まだ足せる
        sum += cnt[now-1];
        ans += p[now-1];

        sum++;
        ans++;
        if(sum == x){
            return;
        }else{
            if(sum + cnt[now-1] < x){
                sum += cnt[now-1];
                ans += p[now-1];
            }else{
                dfs(now-1,sum);
            }
            sum++;
            return;
        }

    }else{
        //now-1までのなかでxに達する
        dfs(now-1,sum);
    }




}



int main(){

    cin >> n >> x;
    p[0] = 1;
    b[0] = 0;
    cnt[0] = 1;

    REP(i,50){
        p[i+1] = 2*p[i] + 1;
        b[i+1] = 2*b[i] + 2;
        cnt[i+1] = 2*cnt[i] + 3;
    }
    dfs(n,0);
    cout << ans << endl;

    
    return 0;
}

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

int main() {
	long long int N, X, ans = 0;
	cin >> N >> X;
	vector<long long int>A( N );
	for( size_t i = 0; i < N; i++ ) {
		cin >> A[i];
		if( i ) {
			if( A[i] + A[i - 1] > X ) {
				long long int sub = min( A[i], A[i] + A[i - 1] - X );
				ans += A[i] + A[i - 1] - X;
				A[i] -= sub;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
from collections import defaultdict
 
N = int(input())
A = list(map(int, input().split()))
D = defaultdict(int)
for a in A:
    D[a] += 1
 
memo = defaultdict(lambda: -1)
conv_D = defaultdict(int)
SUM = 0
for d in D:
    conv_D[d] = D[d] * (D[d] - 1) // 2
    SUM += conv_D[d]
 
for i in range(N):
    if memo[A[i]] == -1:
        tmp = SUM - conv_D[A[i]] + (D[A[i]] - 1)*(D[A[i]] - 2)//2
        print(tmp)
        memo[A[i]] = tmp
    else:
        print(memo[A[i]])

Measured memory_bytes: 42252
/******************************************
* NICK : nikhilsinghh59 *
******************************************/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"

#define PB push_back
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
const int M = 1e9+7;

int main()
{   
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#e/ndif

    double l;
    cin >> l;

    //ll a, b , c ;
    double ans=INT_MIN;

    ans = (l/3)*(l/3)*(l/3);

    cout <<fixed << setprecision(12) << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  while(true) {
      int a, b;
      char op;
      cin >> a >> op >> b;
      if(op == '?') return 0;
      if(op == '+') { cout << a + b << endl; continue;}
      if(op == '-') { cout << a - b << endl; continue;}
      if(op == '*') { cout << a * b << endl; continue;}
      if(op == '/') { cout << a / b << endl; continue;}
  }
  return 0;
}
//templete by private_yusuke


Measured memory_bytes: 3164
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define dump(x)  cerr << #x << " = " << (x) << endl;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL; 

 

//ここから書き始める
int main(int argc, char const *argv[])
{
	int N,K;
	cin >> N >> K;

	int x[N];
	int mcount = 0, pcount = 0, zero = 0;
	// 0があると面倒なので，別途処理
	REP(i, N)
	{
		int tmp;
		cin >> tmp;

		if(tmp == 0)
		{
			zero++;
			continue;
		}
		if(tmp < 0) 
		{
			x[i - zero] = -tmp; 
			mcount++;
		}
		if(tmp > 0) 
		{
			x[i - zero] = tmp; 
			pcount++;
		}
	}
	if(zero == 1) K--;


	if(K == 0)
	{
		cout << 0 << endl;
	}
	else
	{
		LL ans = 3000000000;
		REP(i, K+1) // iは左に行く数
		{
			int left = i;
			//dump(left);
			int right = K - i;
			//dump(right);
			if(left > mcount || right > pcount) continue;

			int ldis;
			if (left == 0) 
			{
				ldis = 0;
			}
			else
			{
				ldis = x[mcount - i];
			}
			//dump(ldis)

			int rdis;

			if (right == 0)
			{
				rdis = 0;
			}
			else
			{
				rdis = x[mcount + right - 1];
			}
			//dump(rdis)

			int kouho1 = ldis * 2 + rdis;
			int kouho2 = rdis * 2 + ldis;
			//dump(kouho1)
			//dump(kouho2)

			int kouho = (kouho1 > kouho2? kouho2 : kouho1);

			if(ans > kouho) ans = kouho;

		}

		cout << ans << endl;
	}



}


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

ll solve() {
    ll A, B, C;
    cin >> A >> B >> C;
    if ( A % 2 == 0 || B % 2 == 0 || C % 2 == 0 ) return 0;
    else return min ( {A*B, B*C, C*A} );
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(void){
  int a,b,i;
  scanf("%d %d",&a,&b);
  int count=0;
  for(i=a;i<=b;i++){
    char s[10];
    sprintf(s,"%d",i);
    if(s[0]==s[4]&&s[1]==s[3]) count++;
  }
  printf("%d",count);
  return 0;
}

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

using ll = long long;
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x, c) for (auto&& x : (c))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))
#define endl _endl
const char _endl = (cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout.precision(16), '\n');

void solve(ll n, ll m, vector<ll> a) {
  sort(a.begin(), a.end(), greater<ll>());
  vector<ll> asum(a.size() + 1);
  rep(i, n) asum[i + 1] = asum[i] + a[i];
  ll low = 0, high = 200001, lowc = n * n, highc = 0;
  while (high - low > 1) {
    ll middle = (high + low) >> 1;
    ll count = 0;
    rep(i, n) {
      ll target = middle - a[i];
      ll x = a.rend() - lower_bound(a.rbegin(), a.rend(), target);
      count += x;
    }
    if (count >= m) {
      low = middle;
      lowc = count;
    } else {
      high = middle;
      highc = count;
    }
    // cout << "pair of >= " << middle << " ... " << count << endl;
  }
  ll sum = 0;
  rep(i, n) {
    ll target = low - a[i];
    ll x = a.rend() - lower_bound(a.rbegin(), a.rend(), target);
    sum += asum[x] + a[i] * x;
  }
  sum -= (lowc - m) * low;
  cout << sum << endl;
}

int main() {
  ll n;
  scanf("%lld", &n);
  ll m;
  scanf("%lld", &m);
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  solve(n, m, move(a));
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
const int MOD = 1e9 + 7;

ll N, M, K, Q;
string S;

long double L, h, w, l;

int main() {
    cin >> L;

    cout << setprecision(11) << (L / 3.0) * (L / 3.0) * (L / 3.0) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define rep(i, a, b) for(int i = a; i < b; ++i)

main() {
    int n, ans = 0;
    cin >> n;
    rep(i, 1, n + 1) {
        if (i%3 && i%5) {
            ans += i;
        }
    }
    cout << ans;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) a.begin(),a.end()
#define lb(s,x) lower_bound(all(s),x)-s.begin()
#define debug(x) cout<<#x<<": "<<x<<endl
#define INF 1e9
typedef long long ll;

int main(void){
    int a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    bitset<3010> bsW,bsS;
    bsW[0] = bsS[0] = 1;
    rep(i,31){
        bsW |= bsW<<(100*a*i);
    }
    rep(i,31){
        bsW |= bsW<<(100*b*i);
    }
    rep(i,3001){
        bsS |= bsS<<(c*i);
    }
    rep(i,3001){
        bsS |= bsS<<(d*i);
    }

    double rate = 0;
    int resW=0,resS=0;
    rep(w,f+1)rep(s,f)if(bsW[w] && bsS[s])if(w+s<=f)if(w>0){
        if(e*w >= s*100){
            if(rate <= 1.0*s/w){
                rate = 1.0*s/w;
                resW = w;
                resS = s;
            }
        }
    }

    cout<<resS+resW<<" "<<resS<<endl;
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        n: usize,
        s: [Chars; n],
    }

    let cnt = s
        .iter()
        .map(|s| s.windows(2).filter(|w| w == &['A', 'B']).count())
        .sum::<usize>();

    let mut both = 0usize;
    let mut first = 0;
    let mut last = 0;
    for s in s {
        let (f, l) = (s.first() == Some(&'B'), s.last() == Some(&'A'));
        if f && l {
            both += 1;
        } else if f {
            first += 1;
        } else if l {
            last += 1;
        }
    }
    use std::cmp::min;
    let mut res = cnt + both.saturating_sub(1);
    if both != 0 && first != 0 {
        res += 1;
    } else if both != 0 && last != 0 {
        res += 1;
    }

    println!("{}", res + min(first, last));
}


Measured memory_bytes: 2784
#include <iostream>
#include <cstdio>
#include <map>

using namespace std;

typedef long long ll;
ll n;
ll a[200005];
ll ans;
map<ll, ll> mp;

ll f(ll p)
{
    if(p < 2) return 0;
    return p * (p - 1) / 2;
}

int main()
{
    scanf("%lld", &n);
    mp[0]++;
    for(ll i = 1; i <= n; i++)
    {
        ll t;
        scanf("%lld", &t);
        a[i] = a[i - 1] + t;
        mp[a[i]]++;
    }
    map<ll, ll>::iterator it;
    for(it = mp.begin(); it != mp.end(); it++)
    {
        ans += f(it->second);
    }
    printf("%lld", ans);
    return 0;
}


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

const double PI = 3.14159265358979323846;

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}


const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
    mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};


mint f(int n){
	if(n==0) return 1;
	mint x = f(n/2);
	x *= x;
	if(n % 2 == 1) x *= 2;
	return x;
}

mint comb(int n, int a){
	mint x = 1, y = 1;
	rep(i,a){
		x *= n - i;
		y *= i + 1;
	}
	return x / y;
}



int main(int argc, char *args[]) {
	ll n;
	int a, b;
	cin >> n >> a >> b;
	mint ans = f(n);
	ans -=1;
	ans -= comb(n,a);
	ans -= comb(n,b);
	cout << ans.x << endl;
}

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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


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

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const ll INF = 1e18;

int main() {

    ll N, M, X;
    cin >> N >> M >> X;
    ll A[N][M] = {0};
    vector<ll> C(N);
    REP(i, N){
        cin >> C[i];
        REP(j, M){
            ll a;
            cin >> a; 
            A[i][j] = a;
        }
    }

    // {0, 1, ..., n-1} の部分集合の全探索
    ll ans = INF;
    for (int bit = 0; bit < (1<<N); ++bit) {
        vector<int> S(N, 0);
        for (int i = 0; i < N; ++i) {
            if (bit & (1<<i)) { // 列挙に i が含まれるか
                S[i] = 1;
            }
        }
        vector<ll> algo(M, 0);
        ll res = 0;
        
        REP(i, N){
            if(S[i] == 1){
                REP(j, M){
                    algo[j] += A[i][j];
                }
                res += C[i];
            }
        }
        bool flag = true;
        
        REP(i, M){
            if(algo[i] < X){
                flag = false;
                break;
            }
        }
        // REP(i, M){
        //     cout << algo[i] << " ";
        // }cout << endl;
        if(flag == true)
            ans = min(ans, res);
    }
    if(ans == INF)cout << -1 << endl;
    else cout << ans << endl;

    
    
    

    



}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


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

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

  rep(i,n-1) { 
    if (a[i] < a[i+1]) {
      if (m > a[i]) {
        k += m / a[i];
        m -= k * a[i];
      }
    } else if (a[i] >= a[i+1]) {
      m += k * a[i];
      k = 0;
    }
  }
  cout << m + k * a[n-1] << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <algorithm>
using namespace std;
long long int n,c[10000];
int main() {
	while(scanf("%lld",&n),n) {
		for(int i=0;i<n;i++)scanf("%lld",&c[i]);
		sort(c,c+n);
		int sum=0;
		for(int i=0;i<n;i++) sum+=c[i]*(n-i-1);
		printf("%lld\n",sum);
	}
}

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

#define ll long long
#define LINF LLONG_MAX

using namespace std;

int main() {
  string s;
  cin >> s;
  string t;
  for (int i = 0; i < (int)s.size(); i++) {
    if (i != (int)s.size() - 1 && s[i] == 'B' && s[i + 1] == 'C') {
      t.push_back('D');
      i++;
    } else {
      t.push_back(s[i]);
    }
  }

  bool flag = false;
  ll ans = 0, Acount = 0;
  for (int i = 0; i < (int)t.size(); i++) {
    if (t[i] == 'A') {
      if (!flag) {
        flag = true;
      }
      Acount++;
    } else if (flag && t[i] == 'D') {
      ans += Acount;
    } else {
      flag = false;
      Acount = 0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 776
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long int 
#define ll long long int 
#define lol std::ios::sync_with_stdio(false);std::cin.tie(NULL);cout.tie(NULL);
template<typename T>
T gcd(const T& a, const T& b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int main() {
    int64_t a,b,i=0,k=0,ans=1;
    cin>>a>>b;
    auto d=gcd(a,b);
    const auto aa=static_cast<int64_t>(sqrt(d)+1);
    for(i=2;i<=aa;i++){
        if(d%i==0){
            ++ans;
            while(d%i==0){
                d/=i;
            }
        }
    }
    if(d!=1) ++ans;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

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

  int hsum[N+1][N+1];
  memset(hsum, 0, sizeof(hsum));
  for(int i = 1; i <= N; i++) {
    for(int j = 1; j <= N; j++) {
      hsum[i][j] = hsum[i][j - 1] + mat[i][j];
    }
  }

  int vsum[N+1][N+1];
  memset(vsum, 0, sizeof(vsum));
  for(int j = 1; j <= N; j++)
    for(int i = 1; i <= N; i++)
      vsum[i][j] = vsum[i - 1][j] + mat[i][j];

  int psum[N+1][N+1];
  memset(psum, 0, sizeof(psum));
  for(int i = 1; i <= N; i++)
    for(int j = 1; j <= N; j++)
      psum[i][j] = psum[i - 1][j - 1] + vsum[i][j] + hsum[i][j] - mat[i][j];

#if 0
  for(int y = 0; y <= N; y++)
    for(int x = 0; x <= N; x++)
      cerr << psum[y][x] << " \n"[x == N];
#endif

  int ans = -1000000000;
  for(int y = 0; y <= N; y++) {
    for(int x = 0; x <= N; x++) {
      for(int y2 = y + 1; y2 <= N; y2++) {
        for(int x2 = x + 1; x2 <= N; x2++) {
          ans = max(ans, psum[y2][x2] + psum[y][x] - psum[y2][x] - psum[y][x2]);
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1324
#include <iostream>
#include <algorithm>

int v[100000];

int main() {
  int n, max1, max2, fr, last;
  scanf("%d", &n);
  for(int i = 0; i < n; ++i)
    scanf("%d", &v[i]);
  std::sort(v, v + n);
  last = v[0];
  max1 = max2 = 0;
  for(int i = 0; i < n; ++i) {
    if(v[i] == last)
      fr++;
    else {
      fr = 1;
      last = v[i];
    }

    if(fr == 2) {
      max1 = max2;
      max2 = last;
    }
    if(fr == 4)
      max1 = max2 = last;
  }
  printf("%lld", (long long)max1 * max2);
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;

int main()
{
   int a,b,c;
   cin >> a >> b >> c;
   if(b-a==c-b)cout<<"YES"<<endl;
   else cout<<"NO"<<endl;
   
   return 0;
}

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vec p = ivec(n);
    vec q = ivec(n);

    vec v;
    For(i, 1, n) v.push_back(i);

    int a, b;
    int cnt = 0;
    do {
        bool samep = true;
        bool sameq = true;
        for (int i = 0; i < n; i++) {
            if (v[i] != p[i]) samep = false;
            if (v[i] != q[i]) sameq = false;
        }
        if (samep) a = cnt;
        if (sameq) b = cnt;
        cnt++;

    } while (next_permutation(all(v)));

    print(abs(a - b));

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main (String[] args) {

    int[][] c = new int[3][3];

    Scanner sc = new Scanner(System.in);
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        c[i][j] = sc.nextInt();
      }
    }
    sc.close();

    int[] a = new int[3];
    int[] b = new int[3];

    a[0] = 0;
    b[0] = c[0][0];
    b[1] = c[0][1];
    b[2] = c[0][2];
    a[1] = c[1][0] - b[0];
    a[2] = c[2][0] - b[0];

    String answer = "Yes";

    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (c[i][j] != a[i] + b[j]) {
          answer = "No";
        }
      }
    }

    System.out.println(answer);

  }

}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long

LL mod = 998244353;

int n,k;
LL dp[200001],dpsum[200001];
int l[11],r[11];

int main(){
  cin>>n>>k;
  REP(i,k)cin>>l[i]>>r[i];

  dp[1]=1;
  dpsum[0]=0;
  dpsum[1]=1;

  FOR(i,2,n+1){
    REP(j,k){
      int lind=l[j],rind=r[j];
      if(lind >= i)continue;
      rind = min(rind,i-1);
      //cerr<<"dbg"<<endl;
      //cerr<<i<<" "<<j<<" "<<dpsum[i-lind]<<" "<<dpsum[i-rind-1]<<endl;
      dp[i]+=mod+dpsum[i-lind]-dpsum[i-rind-1];
      dp[i]%=mod;
    }
    dpsum[i] = dpsum[i-1] + dp[i];
    dpsum[i]%=mod;
  }

  cout<<dp[n]%mod<<endl;
  return 0;
}


Measured memory_bytes: 6760
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;++i)
#define per(i,a,b) for(int i=(b),i##_end=(a);i>=i##_end;--i)
#define For(i,a,b) for(int i=(a),i##_end=(b);i<i##_end;++i)
#define fo(i,a) for(__typeof(a.begin())i=a.begin();i!=a.end();++i)
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef double ld;
typedef long long L;
typedef vector<int> VI;
typedef pair<int,int> pa;
const int N=1011;
int n,m;
char s[N][N];
int d[N][N];
int qx[N*N],qy[N*N],h,t;
int dr[]={1,-1,0,0},dc[]={0,0,1,-1};
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>m;
	rep(i,1,n)cin>>s[i]+1;
	rep(i,1,n)rep(j,1,m){
		if(s[i][j]=='#'){
			d[i][j]=1;
			qx[t]=i;
			qy[t++]=j;
		}
	}
	while(h<t){
		int x=qx[h],y=qy[h++];
		For(i,0,4){
			int nx=x+dr[i],ny=y+dc[i];
			if(nx>=1&&nx<=n&&ny>=1&&ny<=m&&!d[nx][ny]){
				d[nx][ny]=d[x][y]+1;
				qx[t]=nx;
				qy[t++]=ny;
			}
		}
	}
	printf("%d\n",d[qx[t-1]][qy[t-1]]-1);
}

Measured memory_bytes: 13184
#include <iostream>
#include <algorithm>

int main()
{
  int w, h, n;
  std::cin >> w >> h >> n;
  int xl, xr, yu, yd;
  xl = 0;
  xr = w;
  yu = h;
  yd = 0;
  for (int i = 0; i < n; ++i)
  {
    int x, y, a;
    std::cin >> x >> y >> a;
    switch (a)
    {
    case 1:
      xl = std::max(xl, x);
      xr = std::max(xr, x);
      break;
    case 2:
      xl = std::min(xl, x);
      xr = std::min(xr, x);
      break;
    case 3:
      yu = std::max(yu, y);
      yd = std::max(yd, y);
      break;
    case 4:
      yu = std::min(yu, y);
      yd = std::min(yd, y);
      break;
    
    default:
      break;
    }
  }
  std::cout << (xr - xl) * (yu - yd) << std::endl;

  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
diff = [0]*N
for i in range(N):
  diff[i] = A[i]-B[i]
diff = sorted(diff)
s = 0
cnt = 0
for i in range(N):
  if diff[i] < 0:
    s += abs(diff[i])
    diff[i] = 0
    cnt += 1
  else:
    break
if s == 0:
  print(0)
  exit()
for d in reversed(diff):
  if d > 0 and d >= s:
    cnt += 1
    s = 0
    break
  elif d > 0 and d < s:
    cnt += 1
    s -= d
  elif d <= 0:
    break
if s == 0:
  print(cnt)
else:
  print(-1)

Measured memory_bytes: 18708
package main

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

// AtCoder Functions
var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	N := nextInt()
	K := nextInt()
	Q := nextInt()

	m := map[int]int{}
	for i := 0; i < Q; i++ {
		a := nextInt()
		m[a]++
	}

	for i := 0; i < N; i++ {
		if m[i+1] > (Q - K) {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}


Measured memory_bytes: 7296
import scala.io.StdIn

object Main extends App {

  Iterator.continually(StdIn.readLine)
    .drop(1)
    .takeWhile(_ != null)
    .filter(_.contains('#'))
    .map(_.toCharArray)
    .toArray
    .transpose
    .filter(_.contains('#'))
    .transpose
    .toArray
    .foreach(ch => println(ch.mkString))

}

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

int gcd(int a, int b){

  if(a < b) swap(a,b);
  
  int r;

  while ((r=a%b)) {
    a = b;
    b = r;
  }
  
  return b;
}


int main(){
    int N,X;
    cin>>N>>X;
    vector<int> x;

    for(int i=0; i<N; i++){
        int a;
        cin>>a;
        x.push_back(a);
    }

    x.push_back(X);

    sort(x.begin(),x.end());

    int maxgcd=x[1]-x[0];

    for(int i=1; i<N+1; i++){
        int tmp = x[i]-x[i-1];

        maxgcd = gcd(maxgcd,tmp);
    }

    cout<<maxgcd<<endl;

    return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char a[11];
	cin>>a;
	int si=strlen(a);
	long long s=0;
	for(int i=0;i<(1<<(si-1));i++)
	{
		long long s1=a[0]-'0';
		for(int j=0;j<si-1;j++)
		{
			if(i&(1<<j))
			{
				s+=s1;
				s1=a[j+1]-'0';
			}
			else s1=s1*10+(a[j+1]-'0');
		}
		s+=s1;
	}
	cout<<s<<'\n';
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define endl '\n'
 
void solve(){
    int n;
    cin>>n;
    int arr[n+1];
    int c = 0;
    for(int i = 1;i<=n;i++)cin>>arr[i];
    for(int i = 1;i<=n;i++){
       // cout<<i%2<<" "<<arr[i]%2<<endl;
        if(i % 2 == 1 && arr[i] % 2 == 1){
            c++;
        }
    }
    cout<<c;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
    while(t--){
        solve();
    }
	return 0;
}


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

#define endl '\n'
#define ll long long

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    
    ll n, x, t;
    cin >> n >> x >> t;
    ll ans = ceil(1.0 * n / x) * t;
    cout << ans << endl;
}

Measured memory_bytes: 3644