akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define endl "\n"
#define pi 3.14159265358979323846264338327950288
#define MOD 1000000007
#define INF -100000000000000
#define ordered_set tree<pair< ll int ,ll  int>, null_type,less<pair<ll int, ll int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
#define lld long double
using namespace __gnu_pbds;
int main()
{
    fast;
    ll int n,i;
    cin>>n;
    ll int a[n],b[n],c[n];
    for(i=0;i<n;i++)
    {
    	cin>>a[i]>>b[i]>>c[i];
    }
    ll int dp[3][n];
    dp[0][0]=a[0],dp[1][0]=b[0],dp[2][0]=c[0];
    for(i=1;i<n;i++)
    {
    	dp[0][i]=max(dp[1][i-1],dp[2][i-1])+a[i];
    	dp[1][i]=max(dp[0][i-1],dp[2][i-1])+b[i];
    	dp[2][i]=max(dp[0][i-1],dp[1][i-1])+c[i];
    }
    cout<<max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]))<<endl;
}


Measured memory_bytes: 8300
#include <iostream>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
   int n,a=0,s=0,d=0,f=0;
   string y ;
   cin>>n;
   for(int i=1;i<=n;i++){
    cin>>y;
    if(y=="AC"){
        a++;
    }
    if(y=="WA"){
        s++;
    }
    if(y=="TLE"){
        d++;
    }
    if(y=="RE"){
        f++;
    }
   }
   cout<<"AC x "<<a<<endl;
   cout<<"WA x "<<s<<endl;
   cout<<"TLE x "<<d<<endl;
   cout<<"RE x "<<f<<endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

ll gcd(ll a, ll b) {
    if (b==0) return a;
    else return gcd(b,a%b);
}

int main() {
	int n;
	cin >> n;
	ll a[N];
	rep(i, n) cin >> a[i];
	
	ll b[N], c[N];
	b[0] = a[0];
	for(int i = 1; i <= n - 1; i++) {
		b[i] = gcd(b[i - 1], a[i]);
	}
	c[n - 1] = a[n - 1];
	for(int i = n - 2; i >= 0; i--) {
		c[i] = gcd(c[i + 1], a[i]);
	}

	ll ans = max(b[n - 2], c[1]);
	for(int i = 1; i <= n - 2; i++) {
		ans = max(gcd(b[i - 1], c[i + 1]), ans);
	}
	cout << ans << endl;
}


Measured memory_bytes: 2560
N,M = map(int,input().split())
A = list(map(int,input().split()))
CB = []
for i in range(0,M,1):
    b,c = map(int,input().split())
    CB.append([c,b])
A.sort()
CB.sort(reverse=True)

L = 0
ans = 0
owaowari = False
for i in range(0,M,1):
    for j in range(L,min(N,L+CB[i][1]),1):
        if A[j] < CB[i][0]:
            L = j+1
            A[j]=CB[i][0]
        else:
            owaowari = True
    if owaowari or L > N-1:
        break
print(sum(A))

Measured memory_bytes: 76568
import java.util.*;
import static java.lang.Math.*;
public class Main {
	final Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().init();
	}
	void init(){
		new AOJ1141();
	}
	
	class AOJ1141{
		boolean[] isNotPrime;
		AOJ1141(){
			isNotPrime=sieve(1000000);
			while(sc.hasNext()){
				int a=sc.nextInt(),d=sc.nextInt(),n=sc.nextInt();
				if((a|(d|n))==0)	break;
				solve(a,d,n);
			}
		}
		void solve(int a,int d,int n){
			int cnt=0;
			for(int i=a; i<=1000000; i+=d){
				if(!isNotPrime[i])	++cnt;
				if(cnt==n){
					System.out.println(i);
					break;
				}
				
			}
		}
		boolean[] sieve(int MAX){
			boolean[] isNotPrime=new boolean[MAX+1];
			isNotPrime[1]=true;
			for(int i=2; i*i<=MAX; ++i){
				if(!isNotPrime[i])for(int j=i+i; j<=MAX; j+=i)	isNotPrime[j]=true;
			}
			return isNotPrime;
		}
	}
	
	class AOJ1142{
		AOJ1142(){
			int n=sc.nextInt();
			while(--n>=0)	solve();
		}
		void solve(){
			StringBuilder line=new StringBuilder(sc.next());
			HashSet<String> set=new HashSet<String>();
			set.add(line.toString());
			for(int i=1; i<=line.length(); ++i){
				String s1=line.substring(0, i),
						s2=line.substring(i, line.length());
				String s1r=new StringBuilder(s1).reverse().toString(),
						s2r=new StringBuilder(s2).reverse().toString();
				set.add(s1+s2r);
				set.add(s1r+s2);
				set.add(s1r+s2r);
				set.add(s2+s1);
				set.add(s2+s1r);
				set.add(s2r+s1);
				set.add(s2r+s1r);
			}
//			System.out.println(set);
			System.out.println(set.size());
		}
	}
	
	class AOJ1144{
		AOJ1144(){
			while(sc.hasNext()){
				w=sc.nextInt();
				h=sc.nextInt();
				if((w|h)==0)	break;
				solve(w,h);
			}
		}
		final int INF=Integer.MAX_VALUE/4;
		final int[] vx={0,1,0,-1},vy={-1,0,1,0};
		int w,h;
		int sx,sy,ex,ey;
		void solve(int w,int h){
			boolean[][] b=new boolean[w][h];
			sx=0;	sy=0;	ex=0;	ey=0;
			for(int y=0; y<h; ++y)for(int x=0; x<w; ++x){
				int tmp=sc.nextInt();
				b[x][y]=(tmp!=1);
				if(tmp==2){
					sx=x;	sy=y;
				}else if(tmp==3){
					ex=x;	ey=y;
				}
			}
			
			int ans=-1;
			for(int cnt=0; cnt<=10; ++cnt){
				boolean[][] bc=new boolean[w][h];
				for(int x=0; x<w; ++x)for(int y=0; y<h; ++y)	bc[x][y]=b[x][y];
				int ret=DFS(sx,sy,0,cnt,bc);
				if(ret<INF){
					ans=ret;
					break;
				}
			}
			System.out.println(ans);
		}
		int DFS(int x,int y,int depth,int limit,boolean[][] b){
//			System.out.println(x+" "+y+" "+depth+" "+limit);
			if(depth>=limit)	return INF;
			if(x==ex&&y==ey)	return depth;
			
			int ret=INF;
			for(int v=0; v<4; ++v){
				int xx=x+vx[v],yy=y+vy[v];
				if(!(0<=xx&&xx<w && 0<=yy&&yy<h))	continue;
				if(!b[xx][yy])	continue;
				if(xx==ex&&yy==ey){
					ret=min(ret,depth+1);
					continue;
				}
				while(true){
					xx+=vx[v];
					yy+=vy[v];
					if(!(0<=xx&&xx<w && 0<=yy&&yy<h))	break;
					if(xx==ex&&yy==ey){
						ret=min(ret,depth+1);
						break;
					}
					if(!b[xx][yy]){
						xx-=vx[v];
						yy-=vy[v];
						b[xx+vx[v]][yy+vy[v]]=true;
						ret=min(ret, DFS(xx,yy,depth+1,limit,b));
						b[xx+vx[v]][yy+vy[v]]=false;
						break;
					}
				}
			}
			return ret;
			
		}
	}

}

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

int gcd(int a, int b){
    if(b==0){
        return a;
    }else return gcd(b,a%b);
}

int abs(int x){
    if(x > 0)return x;
    else return -x;
}

int main(){
    int N,X;
    int a,D;
    cin >> N >> X;
    cin >> a;
    D=abs(a-X);
    for(int i=0;i<N-1;i++){
        cin >> a;
        D=gcd(D,abs(a-X));
    }
    cout << D << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
int main(int argc, char *argv[]){
    std::string S;
    std::cin >> S;
    if(S == "Sunny"){
        std::cout << "Cloudy";
    }else if(S == "Cloudy"){
        std::cout << "Rainy";
    }else if(S == "Rainy"){
        std::cout << "Sunny";
    }
    std::cout << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int) n;i++)
#define rep1(i,m,n) for(int i=(int) m;i<(int) n;i++)
#define fix(n) cout << fixed << setprecision((int)n)

void absll(ll &x) {
    if(x>=0) return ;
    else x=-x; return;
}

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

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

const ll INF = 1LL << 60;

int N;

//DPテーブル
vector<ll> dp(100010);

int main() {
    int n,m,x;
    cin >>n>>m>>x;
    vector<int> c(n);
    vector<vector<int>> a(n,vector<int>(m));
    rep(i,n) {
        cin>>c.at(i);
        rep(j,m) {
            cin>>a.at(i).at(j);
        }
    }
    
    int sum=100000000;
    for(int bit=0;bit<(1<<n);bit++) {
        int cost=0;
        bool result=true;
        vector<int> b(m,0);
        for(int i=0;i<n;i++) {
            if(bit&(1<<i)) {
                cost+=c.at(i);
                rep(j,m) {
                    b.at(j)+=a.at(i).at(j);
                }
            }
        }
        rep(i,m) {
            if(x>b.at(i)) result=false;
        }
        if(result) {
            sum=min(cost,sum);
        }
    }
    if(sum==100000000) {
        sum=-1;
    }
    cout << sum << endl;


}

Measured memory_bytes: 3860
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <iterator>
#include <limits>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#define endl '\n'
#define INF (214748347/2)
#define LL long long
#define PII pair<int, int>
using namespace std;
const int MAXN = 40;

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

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    int a, b;
    while (cin >> a >> b) {
        int g = gcd(a, b);
        cout << g << " " << a / g * b << "\n";
    }
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=998244353;
const int N=3005;
int a[N],f[N];
int n,s;
int main() {
	ll ans=0;
	int i,j;
	cin>>n>>s;
	for (i=1;i<=n;i++) cin>>a[i];
	for (i=1;i<=n;i++) {
		f[0]++;
		for (j=s;j>=1;j--)
			if (j>=a[i]) f[j]=(f[j]+f[j-a[i]])%mod;
		ans=(ans+f[s])%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n, dp[100001][3], a[100001][3];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i = 0 ; i < n ; i++)
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];
    for(int i = 1 ; i < n ; i++){
        dp[i][0] = a[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = a[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] = a[i][2] + max(dp[i - 1][0], dp[i - 1][1]);
    }
    cout << max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]) << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int N, m=32;
  cin >> N;
  
  rep(i, N) {
    int x, tem;
    cin >> x;
    for (tem = 0; ; tem++) {
      if (x % 2 == 1)
        break;
      x /= 2;
    }
    if (m > tem)
      m = tem;
  }
  cout << m << endl;
}

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

int main()
{
  int i, j, x;
  cin >> i >> j >> x;
  for(int r = i; r <= j; r++){
    if(r < i + x || r > j - x) cout << r << endl;
  }

  return 0;
}


Measured memory_bytes: 3516
import java.util.Scanner;

public class Main {
    static Scanner sc;

    static int n,m;
    static boolean[][] ss;
    static int cnt;

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

        // ?????????????§???????
        String[] a;
        while(true) {
            a = GetSubStringLine();
            m = Integer.parseInt(a[0]);
            n = Integer.parseInt(a[1]);
            if (m == 0 && n == 0) {
                break;
            }
            ss = new boolean[n][m];
            int x = 0,y = 0;
            cnt = 0;
            for (int i=0;i<n;i++) {
                String sss = sc.nextLine();
                for (int j=0;j<sss.length();j++) {
                    switch (sss.charAt(j)) {
                        case '.':
                            ss[i][j] = true;
                            break;
                        case '#':
                            ss[i][j] = false;
                            break;
                        case '@':
                            ss[i][j] = true;
                            x = j;
                            y = i;
                            break;
                    }
                }
            }
            dfs(y,x);
            System.out.println(cnt);
        }
    }

    static void dfs(int y, int x) {
        if (y < 0 || y >= n || x < 0 || x>= m) {
            return;
        }
        if (!ss[y][x]) {
            return;
        }
        ss[y][x] = false;
        cnt++;
        dfs(y-1,x);
        dfs(y,x-1);
        dfs(y+1,x);
        dfs(y,x+1);
    }

    public static String[] GetSubStringLine() {
        String s = sc.nextLine();
        return s.split(" ");
    }
}

Measured memory_bytes: 42176
n, k = map(int,input().split())
cookie = [0] * n
d_lst = []
for i in range(k):
    d = int(input())
    d_lst.append(list(map(int,input().split())))

for row in range(k):
    for column in d_lst[row]:
        cookie[column-1] += 1

print(cookie.count(0))    

Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
const ll MODA=998244353;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
vector<ll> fac;
vector<ll> finv;
vector<ll> inv;
void COMinit(ll N,ll P){
    rep(i,N+1){
        if(i==0){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else if(i==1){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else{
            fac.push_back(fac.at(i-1)*i%P);
            inv.push_back(P-inv.at(P%i)*(P/i)%P);
            finv.push_back(finv.at(i-1)*inv.at(i)%P);
        }
    }
}

ll COM(ll n,ll k,ll P){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P;
}
int main()
{
    ll N;
    cin>>N;
    vector<ll> A(N);
    ll sum=0;
    rep(i,N){
        cin>>A.at(i);
        sum+=A.at(i);
    }
    ll ans=0;
    rep(i,N){
        sum-=A.at(i);
        ans=(ans+(sum%MOD)*A.at(i))%MOD;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4760
import sys
input = sys.stdin.readline

N = int(input())
A = [int(x) for x in input().split()]

A.sort()
total = sum(A)

def test(i):
    # i番の色の人が最大になれる
    size = sum(A[:i+1])
    for x in A[i+1:]:
        if size*2 >= x:
            size += x
        else:
            break
    return size == total

left = -1 # 最大になれない
right = N-1 # 最大になれる
while right > left + 1:
    mid = (left + right)//2
    if test(mid):
        right = mid
    else:
        left = mid

answer = N-right
print(answer)

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

typedef long long ll;
typedef pair<int,int> P;
#define INF (int)(1e9)
#define EPS (1e-7)
#define MOD ((ll)1e9+7)
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i = 1;i <= (int)(n); i++)
#define FOR(i,k,n) for(int i = (k); i < (int)(n); i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define pb push_back
#define vec vector<int>


/*--------------------------------------------*/
/*ll factorial(ll);
void list_Prime(ll);
ll divisor(ll);
ll lcm(ll, ll);//AとBの最小公倍数
ll gcd(ll,ll);

int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
*/
/*--------------------------------------------*/
/*--------------------------------------------*/
/*
ll factorial(ll n){
    if(n==1)return 1;
    return n*factorial(n-1);
}
ll lcm(ll A, ll B) {//最小公倍数
    ll a = A;
    ll b = B;
    if (a == 0 || b == 0) { return 0; }
    if (a < 0) { a = -a; }
    if (b < 0) { b = -b; }
    while (b > 0) {
        ll c = a % b;
        a = b;
        b = c;
    }
    return A/a*B;
}

ll gcd(ll a,ll b){
    while (b != 0) {
        int t = b;
        b = a % b;
        a = t;
    }
    return a;
}


void list_Prime(ll n){//n以下の素数を全て見つける
    ll Limit=(int)sqrt((double)n);
    for(ll i=2;i<=n;i++)prime[i]=1;//最初はみんな素数かも
    //素数の整数倍を消していく(ルートnまで)
    for(ll i=2;i<=Limit;i++){
        if(prime[i]){
            for(ll j=2*i;j<=n;j++){
                if(j%i==0){
                    prime[j]=0;                
                }
            }
        }
    }
}

ll divisor(ll n){
    for(ll i=2;i<=n;i++){
        ll d=1;
        ll tmp=i;
        while(tmp>0){
            d++;
            while(tmp%d==0){
                prime[i]++;
                tmp/=i;
            }
        }
    }
    ll sum=1;
    for(ll i=2;;i<=n;i++){
        sum*=(prime[i]+1)/MOD;
    }    
    cout<<"sum="<<sum<<endl;

    return sum%MOD;
}
*/
/*--------------------------------------------*/
int main(){
    int n;cin>>n;
    int maxx=-1;
    int ans;
    REP(i,n){
        int temp=i;
        int cnt=0;
        while(temp%2==0){
            cnt++;
            temp/=2;
        }
        if(maxx<cnt){
            maxx=cnt;
            ans=i;
        }
    }cout<<ans<<endl;
}



Measured memory_bytes: 256
import sys

N = int(input())
a = [int(input()) for _ in range(N)]

l = 1
p = a[0] - 1

if a[0] == 2:
    print(l)
    sys.exit()

while l < int(1e6):
    l += 1
    if a[p] == 2:
        print(l)
        break
    else:
        p = a[p] - 1
else:
    print(-1)

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

const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    string S, T;
    cin >> S >> T;
    int cnt = 0;
    for (int i=0; i<(int)S.size(); ++i) {
        if (S[i] != T[i]) cnt ++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3912
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();

		int[] t = new int[n];
		for (int i = 0; i < m; i++) {
			t[scan.nextInt() - 1]++;
			t[scan.nextInt() - 1]++;
		}
		for (int ans : t) {
			System.out.println(ans);
		}
	}

}

Measured memory_bytes: 23124
void main()
{
    long n = rdElem;
    long[] h = rdRow;

    bool ok = true;
    long cnt = 1;
    foreach (i; 1 .. n)
    {
        if (h[i] > h[i-1]) ++cnt;
        else if (h[i] < h[i-1])
        {
            if (h[i-1] - h[i] > cnt)
            {
                "No".writeln;
                return;
            }
            cnt = 0;
        }
    }

    "Yes".writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

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

int main()
{
	double a = 0, b = 1000000, t;

	while (cin >> t) {
		if (t > a)
			a = t;
		if (t < b)
			b = t;
	}

	cout << a - b << endl;

	return 0;
}


Measured memory_bytes: 3192
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
//最大公約数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
//最小公倍数
ll box(double a) 
{
	ll b = a;
	return b;
}
//切り捨て
ll fff(double a) 
{
	ll b = a + 0.5;
	return b;
}
//四捨五入
ll sum(ll n) { 
	return (1 + n) * n / 2;
}
//1から整数nまでの合計
bool prime(ll a)//素数判定、primeならtrue,違うならfalse
{
	if (a < 2) return false;
	else if (a == 2) return true;
	else if (a % 2 == 0) return false;
	double sqrtNum = sqrt(a);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (a % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}
//素数判定

// ===============================================================

int main() {
	ll n, m, x; cin >> n >> m >> x;
	vl a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	ll cnt = 0;
	ll count = 0;
	for (int i = x + 1; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (a[j] == i) {
				cnt++;
			}
		}
	}
	for (int i = 0; i < x; i++) {
		for (int j = 0; j < m; j++) {
			if (a[j] == i) {
				count++;
			}
		}
	}
	cout << min(cnt, count) << endl;
}

Measured memory_bytes: 3664
#include <vector>
#include <math.h>
#include <iostream>

using namespace std;

int main(){

  int A, B, C, D;
  cin >> A >> B >> C >> D;

  int t = 0;
  while(A > 0 && C > 0){
    if (t % 2 == 0) C -= B;
    else A -= D;
    t++;
  }

  //cout << A << " " << C << endl;

  if(A <= 0) cout << "No" << endl;
  else cout << "Yes" << endl;
  
  return 0;
}


Measured memory_bytes: 3624
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

// code
// ------------------------------------------------
int main()
{

  string s,t;
  cin >> s >> t;

  if(s == t.substr(0,sz(s)))
    cout << "Yes" << endl;
  else
  {
    cout << "No" << endl;
  }
  

  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 3600
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    string s;
    cin>>s;
    rep(i,s.size()){
        if(s[i]=='7'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    
return 0;
}


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

int main(){
  int N; cin >> N;
  vector<int>A(N);
  vector<int>B(N);
  vector<int>C(N-1);
  int sum = 0;
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  for(int i=0;i<N;i++){
    cin >> B.at(i);
  }
  for(int i=0;i<N-1;i++){
    cin >> C.at(i);
  }
  for(int i=0;i<N;i++){
    sum += B.at(i);
  }
  for(int i=0;i<N-1;i++){
    if(A.at(i+1)-A.at(i) == 1){
      sum +=C.at(A.at(i)-1);
    }
  }
  cout << sum << endl;
}


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

#define fr(i,a,b) for(int i=a;i<b;++i)
typedef long long ll;
////////////////////

int const N = 55;
int const M = 18;
int const MOD = 1e9 + 7;

int n, x, y, z;
int d[N][(1 << M)][2];
int lbit[(1 << M)], fbit[(1 << M)], nxt[(1 << M)][11];
bool good[(1 << M)];

void add(int &a, int b){
	a += b;
	if(a >= MOD) a -= MOD;
}

int getLastBit(int mask){
	for(int i=30;i>=0;--i) if((1 << i) & mask) return i;
	assert(false);
	return 41;
}

int getMinBit(int mask){
	for(int i=1;i<M;++i){
		if((1 << i) & mask) return i;
	}
	return 0;
}

bool bit(int mask, int id){
	return ( (1 << id) & mask) ? true : false;
}

bool have(int mask){
	bool ok = true;
	ok &= bit(mask, x);
	ok &= bit(mask, x + y);
	ok &= bit(mask, x + y + z);
	return ok;
}

void precalc(){
	fr(mask, 1, (1 << M)){
		fbit[mask] = getMinBit(mask);
		lbit[mask] = getLastBit(mask);
		good[mask] = have(mask);
	}
}

void solve(){
	cin >> n >> x >> y >> z;
	precalc();
	d[0][1][0] = 1;
	fr(i, 0, n) fr(mask, 1, (1 << M)) fr(f, 0, 2) fr(j, 1, 11){
		if(!d[i][mask][f]) continue;
		int nmask;
		bool nf = f;
		if(nxt[mask][j] == 0){
			nmask = mask;
			int lb =  lbit[nmask] + j;
			while(lb > x + y + z && nmask > 1){
				int b = fbit[nmask];
				nmask >>= b;
				lb -= b;
			}
			nmask ^= (1 << lb);
			nxt[mask][j] = nmask;
		}
		nmask = nxt[mask][j];
		nf = max(nf, good[nmask]);
		add(d[i+1][nmask][nf], d[i][mask][f]);
	}
	int ans = 0;
	fr(i, 0, (1 << M)) add(ans, d[n][i][1]);
	cout << ans << endl;
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();

	return 0;
}

Measured memory_bytes: 98560
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
int main() {
	int n,cou=0,nam=0,ma=0;
	int i,j,k;
	cin >> n;
	vector<int> h(n+1,0);
	for(i = 1; i <= n; ++i) {
		cin >> h.at(i);
		ma = max(ma, h.at(i));
		if(h.at(i - 1) <= h.at(i)) {
			if(h.at(i)>=ma)
				++cou;
		}
	}
	cout << cou << endl;
}

Measured memory_bytes: 256
n, m, q = map(int, input().split())

lr = [[0 for _ in range(n+1)] for _ in range(n+1)]
for _ in range(m):
    l, r = map(int, input().split())
    lr[l][r] += 1

sumlr = [[0 for _ in range(n+1)] for _ in range(n+1)]
for l, r in ((l, r) for l in range(1, n+1) for r in range(1, n+1)):
    sumlr[l][r] = lr[l][r] + sumlr[l-1][r] + sumlr[l][r-1] - sumlr[l-1][r-1]

for _ in range(q):
    p, q = map(int, input().split())
    print(sumlr[q][q] - sumlr[p-1][q] - sumlr[q][p-1] + sumlr[p-1][p-1])

Measured memory_bytes: 15528
#include<bits/stdc++.h>
using namespace std;
int Arr[ 200005 ] , Brr[ 200005 ];
int A[ 200005 ] , B[ 200005 ];

void _init( int a )
{
    for( int i = 1; i <= a; i++ )
    {
        Arr[ i ] = Brr[ i ] = i;
    }
}

int _roadfp( int a )
{
    if( Arr[ a ] == a )
        return a;
    return Arr[ a ] = _roadfp( Arr[ a ] );
}

int _railfp( int a )
{
    if( Brr[ a ] == a )
        return a;
    return Brr[ a ] = _railfp( Brr[ a ] );
}

void _roaduni( int x , int y )
{
    int u = _roadfp( x );
    int v = _roadfp( y );

    if( u != v )
    {
        Arr[ v ] = u;
    }
}

void _railuni( int x , int y )
{
    int u = _railfp( x );
    int v = _railfp( y );

    if( u != v )
    {
        Brr[ v ] = u;
    }
}

int main()
{
    int n , k , l;
    cin >> n >> k >> l;
    _init( n );

    for( int i = 0; i < k; i++ )
    {
        int a , b;
        cin >> a >> b;
        _roaduni( a , b );
    }

    for( int i = 0; i < l; i++ )
    {
        int a , b;
        cin >> a >> b;
        _railuni( a , b );
    }

    for( int i = 1; i <=n; i++ )
    {
        _roadfp( i );
        _railfp( i );
    }

    map < pair<int,int> , int > M;

    for(int i = 1; i <= n; i++ )
    {
        // cout << Arr[ i ] << "  " << Brr[ i ] << endl;
        M[ { Arr[ i ] , Brr[ i ] }  ] ++;
    }
//
//    for( auto it : M )
//    {
//        cout << it.first.first << " " << it.first.second << endl;
//        cout << it.second << endl;
//    }

    for( int i = 1; i < n; i++ )
    {
        printf("%d " , M[ { Arr[ i ] , Brr[ i ] } ] );
    }
    printf("%d\n" , M[ { Arr[ n ] , Brr[ n ] } ] );
    return 0;
}


Measured memory_bytes: 13568
import java.io.PrintWriter
import java.util.StringTokenizer

fun main() {

    fun PrintWriter.solve() {
        val n = nextInt()
        val L = List(n){nextInt()}

        var ans = 0
        for (i in L.indices){
            for (j in i+1..n-1){
                for (k in j+1..n-1){
                    if (L[i] == L[j] || L[j] == L[k] || L[i] == L[k]) continue
                    val list = listOf(L[i],L[j], L[k]).sorted()
                    if (list[0] + list[1] > list[2])ans++
                }
            }
        }

        println(ans)

    }

    writer.solve()
    writer.flush()


}


private val reader = System.`in`.bufferedReader()
private val writer = PrintWriter(System.out, false)

private var tokenizer: StringTokenizer = StringTokenizer("")

private fun next(): String {
    while (tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(reader.readLine())
    return tokenizer.nextToken()
}

private fun nextInt() = next().toInt()
private fun nextLong() = next().toLong()
private fun nextDouble() = next().toDouble()
private fun nextLine() = reader.readLine()



Measured memory_bytes: 55172
#include <bits/stdc++.h>
// atoi : atoi(str.c_str())
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  int n;
  cin >> n;
  vector<int> b(n-1);
  rep(i,n-1){
    cin >> b.at(i);
  }
  long answer = b.at(0) + b.at(n-2);
  rep(i,n-2){
    answer += min(b.at(i),b.at(i+1));
  }
  cout << answer << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES(n)          cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n)          cout << ((n) ? "Yes" : "No"  ) << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int n, a, b; cin >> n >> a >> b;
  int c1 = 0, c2 = 0, c3 = 0;
  rep(i, n) {
    int p; cin >> p;
    if (p <= a) c1++;
    else if (p <= b) c2++;
    else c3++;
  }
  outl(min({c1, c2, c3}));
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int K = 11;
const int KM = 1 << (K - 1);
int dat[1 << K], dat2[1 << K];
int laz[1 << K];
int zero = 0;

void eval(int A, int l, int r) {
	if (laz[A] == zero) return;
	if (A * 2 < 1 << K) {
		laz[A * 2] += laz[A];
		laz[A * 2 + 1] += laz[A];
	}
	dat[A] += laz[A];
	dat2[A] += laz[A];
	laz[A] = zero;
}

pair<int, int> update(int L, int R, int X, int A, int l, int r) {
	eval(A, l, r);
	if (r <= L || R <= l) return mp(dat[A], dat2[A]);
	if (L <= l && r <= R) {
		laz[A] = X;
		return mp(dat[A] + X, dat2[A] + X);
	}
	int a, b, c, d;
	tie(a, b) = update(L, R, X, A * 2, l, (l + r) / 2);
	tie(c, d) = update(L, R, X, A * 2 + 1, (l + r) / 2, r);
	dat[A] = max(a, c);
	dat2[A] = min(b, d);
	return mp(dat[A], dat2[A]);
}

void add(int L, int R, int X) {
	update(L, R, X, 1, 0, KM);
}

pair<int, int> check(int L, int R, int A, int l, int r) {
	eval(A, l, r);
	if (r <= L || R <= l) return mp(-1e9, 1e9);
	if (L <= l && r <= R) return mp(dat[A], dat2[A]);
	int a, b, c, d;
	tie(a, b) = check(L, R, A * 2, l, (l + r) / 2);
	tie(c, d) = check(L, R, A * 2 + 1, (l + r) / 2, r);
	return mp(max(a, c), min(b, d));
}

pair<int, int> query(int L, int R) {
	return check(L, R, 1, 0, KM);
}


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


	int N, K;
	cin >> N >> K;

	int gyaku = 0;
	int goukei = 0;
	int to[100001], ne[100001], he[100001] = {};
	rep1(i, N) {
		int x, y;
		char c;
		cin >> x >> y >> c;
		int k = x / K ^ y / K;
		x = x % K;
		y = y % K;
		if (c == 'W' ^ (k & 1)) {
			gyaku++;
			to[i] = -x - 1;
			ne[i] = he[y];
			he[y] = i;
			add(0, x, -1);
			goukei--;
		}
		else {
			to[i] = x;
			ne[i] = he[y];
			he[y] = i;
			add(0, x, 1);
			goukei++;
		}
	}
	int saidai = -1e9;
	int p = 0;
	rep(y, K) {

		auto kari = query(0, K);
		saidai = max(saidai, kari.first);
		saidai = max(saidai, goukei - kari.second);

		for (int i = he[y]; i; i = ne[i]) {
			int x = to[i];
			if (x >= 0) {
				add(0, x, -1);
				add(x, K, 1);
			}
			else {
				add(0, -x - 1, 1);
				add(-x - 1, K, -1);
			}
		}
	}
	co(gyaku + saidai);

	Would you please return 0;
}

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

int main() {
  int N; cin >> N;
  map<long long, long long> A, B;
  for (int i = 0; i < N; i++) {
    long long h;
    cin >> h;
    A[i + h] += 1;
    B[i - h] += 1;
  }

  long long ans = 0;
  for (int i = 0; i < N; i++) ans += A[i] * B[i];

  cout << ans << endl;
  
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int a, b, c;
	cin >> a >> b >> c;

	if (a == b + c ||
		b == c + a ||
		c == a + b) {
		out("Yes");
	}
	else {
		out("No");
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bitset>
#include<algorithm>
using namespace std;
int N,T;
bitset<1001>dp[1001];
main()
{
	dp[0][0]=1;
	cin>>N;
	int sum=0;
	for(int i=0;i<N;i++)
	{
		cin>>T;
		sum+=T;
		for(int j=1000;j>=0;j--)
		{
			if(j+T<=1000)dp[j+T]|=dp[j];
			dp[j]|=dp[j]<<T;
		}
	}
	int ans=sum;
	for(int i=0;i<=1000;i++)for(int j=0;j<=1000;j++)
	{
		if(dp[i][j])ans=min(ans,max(sum-i-j,max(i,j)));
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
Int INF = 1e18;
double EPS = 0.00000001;
//Int mod = 1e6+3;

int main() {
    Int n, k;
    cin >> n >> k;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) cin >> a[i];
    vector<Int> b(n + 1);
    for (Int i = 0; i < n; i++) b[i + 1] = b[i] + a[i];
    vector<Int> c;
    for (Int i = 0; i < n; i++) {
        for (Int j = i + 1; j <= n; j++) {
            c.emplace_back(b[j] - b[i]);
        }
    }
    vector<Int> d[41];
    d[40] = c;
    for (Int i = 40; i > 0; i--) {
        Int cnt = 0;
        for (Int j = 0; j < (Int)d[i].size(); j++) {
            if (d[i][j] & (1LL<<(i-1))) cnt++;
        }
        //cout << i << " " << cnt << endl;
        if (cnt < k) {
            d[i - 1] = d[i];
            continue;
        }
        for (Int j = 0; j < (Int)d[i].size(); j++) {
            if (d[i][j] & (1LL<<(i-1))) {
                d[i - 1].emplace_back(d[i][j]);
            }
        }
    }
    Int res = (1LL<<41) - 1LL;
    //dump(res);
    for (Int i = 0; i < (Int)d[0].size(); i++) res = res & d[0][i];
    dump(res);
    return 0;
}

Measured memory_bytes: 24304
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int sum =(int)(Math.pow((K-1),(N-1))*K);
		System.out.println(sum);
	}
}


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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int main() {
    ll x,k,d;
    cin >> x >> k >> d;
    x = abs(x);
    ll a = x/d;
    if (a > k) {
        cout << x-k*d << endl;
    } else {
        k -= a;
        x %= d;
        if (k%2) cout << d-x << endl;
        else cout << x << endl;
    }
}

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

  ll n,q;
  vector<ll> to[200001];
  ll ans[200001];

void counter(ll v,ll u=-1){
  for(ll w : to[v]){
    if(w==u)continue;
    ans[w]+=ans[v];
    counter(w,v);
  }
}

int main() {
  cin>>n>>q;
  rep(i,n-1){
    ll a,b;
    cin>>a>>b;
    a--;b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  rep(i,n){
    ans[i]=0;
  }
  rep(i,q){
    ll v,point;
    cin>>v>>point;
    v--;
    ans[v]+=point;
  }
  counter(0);
  rep(i,n){
    cout<<ans[i]<<" ";
  }
  return 0;
}

Measured memory_bytes: 24320
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=998244353;

int N;
vector<int> D;

int main(){
  cin>>N;
  D.resize(N);
  rep(i,N) cin>>D[i];

  if(D[0]!=0){
    cout<<0<<endl;
    return 0;
  }

  sort(D.begin(),D.end());
  map<ll,ll> mp;
  for(int i=1;i<N;i++){
    if(D[i]==0||D[i-1]+1<D[i]){
      cout<<0<<endl;
      return 0;
    }
    mp[D[i]]++;
  }

  D.erase(unique(D.begin(),D.end()),D.end());

  ll ans=1;
  ll pre=1;
  for(int i=1;i<D.size();i++){
    ll num=mp[D[i]];
    for(int j=0;j<num;j++) ans=ans*pre%MOD;
    pre=num;
  }
  cout<<ans<<endl;



  return 0;
}


Measured memory_bytes: 6912
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>

using namespace std;

int main(){
    int N, T;
    double A;
    cin >> N >> T >> A;
    vector<int> H(N);
    for(int i = 0; i < N; i++){
        cin >> H[i];
    }
    
    int ans = 0;
    double temp = 1000000.0;
    
    for(int i = 0; i < N; i++){
        double tmp = T - 0.006 * H[i];
        if(abs(A - tmp) < temp){
            temp = abs(A - tmp);
            ans = i + 1;
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod (1000000007)
const int MAX=100010;
ll n,k,a[MAX],ans=0;
ll fact[MAX];
ll power(ll x,ll n)
{
    ll res=1;
    while(n){
        if(n&1)res=res*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return res;
}
void init(){
    fact[0]=1;
    for(int i=0;i<n;i++)fact[i+1]=fact[i]*(i+1)%mod;
}
ll comb(ll n,ll r){
    if(n<0||r<0||n<r)return 0;
    return (fact[n]*power(fact[r],mod-2))%mod*power(fact[n-r],mod-2)%mod;
}
void solve() {
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    init();
    for(int i=0;i<n;i++)ans-=a[i]*comb(n-i-1,k-1),ans=(ans+a[i]*comb(i,k-1))%mod;
    cout<<ans<<endl;
}
int main()
{
    cin.tie(0);
	ios::sync_with_stdio(false);
    solve();
    return 0;
}


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

using namespace std;

const int HUGEI = 2147483647;  // (1 << 31) - 1
const long long HUGEL = 9223372036854775807;  // (1 << 63) - 1
const string ABC = "abcdefghijklmnopqrstuvwxyz";

int h, w;

long long min_parallel(long long x, long long y) {
    long long res = HUGEL;
    for (long long a = 1; a < y - 1; a++) {
        long long sa = x * a;
        long long sb, sc;
        if ((y - a) % 2 == 1) {
            sb = x * (y - a + 1) / 2;
            sc = x * (y - a - 1) / 2;
        } else {
            sb = x * (y - a) / 2;
            sc = x * (y - a) / 2;
        }
        long long ma = max(sa, max(sb, sc));
        long long mi = min(sa, min(sb, sc));
        res = min(res, ma - mi);
    }
    return res;
}

long long min_orthogonal(long long x, long long y) {
    long long res = HUGEL;
    for (long long a = 1; a < y; a++) {
        long long sa = x * a;
        long long sb, sc;
        if (x % 2 == 1) {
            sb = (y - a) * (x + 1) / 2;
            sc = (y - a) * (x - 1) / 2;
        } else {
            sb = (y - a) * x / 2;
            sc = (y - a) * x / 2;
        }
        long long ma = max(sa, max(sb, sc));
        long long mi = min(sa, min(sb, sc));
        res = min(res, ma - mi);
    }
    return res;
}

int main(void) {
    cin >> h >> w;
    // cout << h << w;
    long long res = HUGEI;
    res = min(res, min_parallel(h, w));
    res = min(res, min_parallel(w, h));
    res = min(res, min_orthogonal(h, w));
    res = min(res, min_orthogonal(w, h));
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

void dfs ( char pre_char, int n, string s, vector<string> &ans ) {
    if ( (int)s.length() == n ) {
        ans.push_back(s);
        return;
    }
    for ( int i = 'a'; i <= pre_char + 1; ++i ) {
        dfs(((i>pre_char)?(char)(pre_char+1):pre_char), n, s+(char)i, ans);
    }
    return;
}

int main(){
    int n;
    cin >> n;
    vector<string> ans;
    dfs('a', n, "a", ans);
    for ( auto a : ans ) {
        cout << a << endl;
    }  
    return 0;
}


Measured memory_bytes: 8820
def divisors(n):
    divs = set()
    for i in range(1,int(n**0.5)+1):
        if n % i == 0:
            divs |= {i, n//i}
    return sorted(divs)

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

def is_disjoint(n,m):
    return gcd(n,m) == 1

def appendable(list, n):
    return all(is_disjoint(l, n) for l in list)

#O(n**2)!
def filter_disjoint(divisors):
    list = []
    for d in divisors:
        if appendable(list, d):
            list.append(d) 
    return list


a,b = list(map(int, input().split()))

filterd = filter_disjoint(divisors(gcd(a,b)))
print(len(filterd))

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    string s;
    cin >> s;
    ll n = s.size();
    ll ans = 0;
    ll tmp = 0;
    for(int i=0;i<n;i++){
        if(s[i]=='B'){
            tmp++;
        }else{
            ans += tmp;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 832
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<time.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

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

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


int n, k, a[201010];

int main(){
	cin >> n >> k;
	i64 ans = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	sort(a,a+n);
	
	for(int i = 0; i < n-k; i++){
		ans += a[i];
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1024