akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--)
#define mst(a,a0) memset(a,a0,sizeof(a))
#define vector basic_string
#define fi first
#define se second
#ifndef qwq
int cansel_sync=(ios::sync_with_stdio(0),cin.tie(0),0);
#endif
//mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=200010; const double err=1e-11; typedef long long ll; const int inf=~0u>>2; const ll INF=~0ull>>2; ll read(){ll x; if(scanf("%lld",&x)==-1)exit(0); return x;} typedef double lf; typedef long double llf; const lf pi=acos(-1.0); lf readf(){lf x; if(scanf("%lf",&x)==-1)exit(0); return x;} template<typename T> T sqr(const T &x){return x*x;} typedef pair<int,int> pii;
const int mod=(1?1000000007:998244353); ll mul(ll a,ll b,ll m=mod){return a*b%m;} ll qpow(ll a,ll b,ll m=mod){ll ans=1; for(;b;a=mul(a,a,m),b>>=1)if(b&1)ans=mul(ans,a,m); return ans;} ll getinv(ll v,ll m=mod){return qpow(v,m-2,m);}
#define int ll
int n,m;
int dp[N],w[N],ans[N];
vector<pii> rec;
vector<int> a[N];
bool vis[N];
void dfs(int x){
	{
		int p=lower_bound(dp,dp+n,w[x])-dp;
		rec.push_back({p,dp[p]});
		dp[p]=w[x];
		//orz(x);
		//orzarr(dp,n);
	}
	vis[x]=1;
	
	ans[x]=lower_bound(dp,dp+n,inf)-dp;
	for(auto p:a[x])
	if(!vis[p]){
		dfs(p);
	}
	dp[rec.back().fi]=rec.back().se;
	rec.pop_back();
}
signed main(){
	cin>>n;
	repeat(i,1,n+1)cin>>w[i];
	repeat(i,0,n-1){
		int x,y;
		cin>>x>>y;
		a[x]+=y; a[y]+=x;
	}
	fill(dp,dp+n+2,inf);
	dfs(1);
	repeat(i,1,n+1)cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 39308
#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;


void run_case() {
    int n; cin >> n;
    vector<int> a(n);
    for(auto &x: a) cin >> x;
    sort(a.begin(), a.end());
    function<int(int,int)> solve = [&](int i, int j) {
        int l = j, r = n-1, mid, ans;
        while(l <= r) {
            mid = (l+r) >> 1;
            if(a[mid] < a[i]+a[j]) {
                ans = mid;
                l = mid + 1;
            } else
                r = mid - 1;
        }
        return ans - j;
    };
    LL ans = 0;
    for(int i = 0; i < n; ++i)
        for(int j = i+1; j < n; ++j)
            ans += solve(i, j);
    cout << ans;
}


int main() {
    //freopen("input", "r", stdin);
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(9);
    //int t; cin >> t;
    //while(t--)
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3652
#include<cstdio>
#include<algorithm>

int dp[101][10001];

int main(){
    int n, w;
    scanf("%d %d\n", &n, &w);
    int val[n], wei[n];
    for(int i=1; i<=n; i++){
        scanf("%d %d\n",&val[i], &wei[i]);
    }
    // init. dp table
    for(int i=0; i<=n; i++){
        dp[i][0] = 0;
    }
    for(int j=0; j<=w; j++){
        dp[0][j] = 0;
    }

    for(int i=1; i<=n; i++){
        for(int j=1; j<=w; j++){
            if(wei[i]<=j){
                dp[i][j] = std::max(dp[i-1][j-wei[i]] + val[i], dp[i-1][j]);
            }else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    printf("%d\n", dp[n][w]);
/*
    for(int i=0; i<=n; i++){
        for(int j=0; j<=w; j++){
            printf("%d ",dp[i][j]);
        }
        printf("\n");
    }
*/

    return 0;
}

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

using namespace std;
typedef long long ll;
const ll mx = 10000007;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))

int main() {
    ll a, b, h, m;
    cin >> a >> b >> h >> m;
    m = (h * 60.0) + m;
  long double d = sqrt((ll)pow(a, 2.0) + (ll)pow(b, 2.0) - (2.0 * a * b * cos ((2.0/60 - 2.0/720) * m * pi)));
    cout <<fixed << setprecision(21) <<  d << endl;
    return 0;
}


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

int main(void)
{
	int n,m,a;

	
	while(cin >> n >> m, n | m){
		int d[100001] = {};
		cin >> d[0];
	
		for(int i = 1; i < n; i++){
			cin >> a;
			d[i] += d[i-1] + a;
		}
		int MAX = 0;
		for(int i = 0; i < n - m; i++){
			if(d[i+m] - d[i] > MAX)
				MAX = d[i+m] - d[i];
		}
		cout << MAX << endl;
	}

	return 0;
}

Measured memory_bytes: 1556
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		for(;;){
			String input = null;

			try {
				input = br.readLine();
			} catch (IOException e) {
			}
			String[] inputs = input.split(" ");
			int h = Integer.parseInt(inputs[0]);
			int w = Integer.parseInt(inputs[1]);

			if(h == 0 && w == 0){
				break;
			}

			String line = "";

			for(int j = 0; j < w; j++){
				line += "#";
			}
			for(int i = 0; i < h; i++){
				System.out.println(line);
			}
			System.out.println("");
		}
	}
}



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

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

long lcm(long a, long b) {
    return a * b / gcd(a, b);
}

int main()
{
    long a, b;
    cin >> a >> b;
    long res = lcm(a, b);

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
import bisect
n = int(input())
lis = sorted(list(map(int,input().split())))
count = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        index = bisect.bisect_left(lis,lis[i]+lis[j])
        count += index-1-j
print(count)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

string s;

int main(){
	cin>>s;
	int n=s.size(),res=n,t=1;
	for(int i=1;i<n;i++){
		if(t&&s[i]==s[i-1]){
			if(i<n-1) i++;
			res--;
			t=0;
		}
		else t=1;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 640
#from collections import deque
#from heapq import heapify, heappop, heappush
#from bisect import insort
#from math import gcd
#mod = 10**9 + 7
N = int(input())
#N, K = map(int, input().split())
#A = list(map(int, input().split()))
flag1 = False
flag2 = False
flag3 = False
c, d = map(int, input().split())
if c == d:
	flag1 = True
c, d = map(int, input().split())
if c == d:
	flag2 = True
c, d = map(int, input().split())
if c == d:
	flag3 = True

k = 3
while k < N:
	if flag1 and flag2 and flag3:
		break
	k += 1
	c, d = map(int, input().split())
	flag1 = flag2
	flag2 = flag3
	if c == d:
		flag3 = True
	else:
		flag3 = False
		

#ans = 0
#print(ans)
#print('Yes')
if flag1 and flag2 and flag3:
	print('Yes')
else:
	print('No')

Measured memory_bytes: 9216
import 'dart:io';

List<String> getStdStr() => stdin.readLineSync().split(' ');
List<int> getStdInt() {
  var strings = getStdStr();
  List<int> outs = [];
  for (var out in strings) {
    outs.add(int.parse(out));
  }
  return outs;
}

void main() {
  var inputs = getStdInt();
  if (inputs[0] <= inputs[1] * inputs[2]) {
    print('Yes');
    return;
  }
  print('No');
}


Measured memory_bytes: 13096
// ※※※ 解答不能 ※※※
// snuke氏.
// https://atcoder.jp/contests/abc163/submissions/12204917
// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using vvi = vector<vector<int>>;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back

const int MX = 200005;
vector<int> to[MX];
int t[MX], c[MX];
LL ans[MX];
LL f(LL n){ return n * (n + 1) / 2; }

int tfs(int v, int p = -1){
    t[v] = 1;
    for(int u : to[v]){
        if(u == p) continue;
        t[v] += tfs(u, v);
    }
    return t[v];
}

stack<int> st[MX];
int d[MX], remsz[MX];
void dfs(int v, int p = -1){
    st[c[v]].push(v);
    for(int u : to[v]){
        if(u == p) continue;
        d[v] = t[u];
        dfs(u, v);
        ans[c[v]] -= f(d[v]);
    }
    st[c[v]].pop();
    if(st[c[v]].size()) d[st[c[v]].top()] -= t[v];
    else                remsz[c[v]] -= t[v];
}

int main(){
    int n;
    scanf("%d", &n);
    rep(i, n){
        scanf("%d", &c[i]);
        c[i]--;
    }
    rep(i, n - 1){
        int a, b;
        scanf("%d %d", &a, &b);
        --a; --b;
        to[a].pb(b);
        to[b].pb(a);
    }
    tfs(0);
    rep(i, n) ans[i] = f(n);
    rep(i, n) remsz[i] = n;
    dfs(0);
    rep(i, n) ans[i] -= f(remsz[i]);
    rep(i, n) printf("%lld\n", ans[i]);
    return 0;
}

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


#define MAX 100002
char buf[MAX];


vector<int> v[26];

int main(){
	scanf("%s", buf);
	int n = strlen(buf);
	for (int i = 0; i < n; i++){
		v[buf[i] - 'a'].push_back(i);
	}
	for (int i = 0; i < 26; i++){
		for (int j = 0; j+1 < v[i].size(); j++){
			int l = v[i][j];
			int r = v[i][j + 1];
			if (r - l + 1 <= 3){
				printf("%d %d\n", l + 1, r + 1);
				return 0;
			}
		}
	}
	puts("-1 -1");
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int a,b,c,d,e;
		
		if((a = sc.nextInt()) < 40)a = 40;
		if((b = sc.nextInt()) < 40)b = 40;
		if((c = sc.nextInt()) < 40)c = 40;
		if((d = sc.nextInt()) < 40)d = 40;
		if((e = sc.nextInt()) < 40)e = 40;
		
		System.out.println((a + b + c + d + e) / 5);
		
		sc.close();
	}
}

Measured memory_bytes: 17172
_ = input()
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
C = tuple(map(int, input().split()))
AA = tuple(zip(A, A[1:]))
CC = {(i,i+1):c for i, c in enumerate(C, 1)}
print(sum(B) + sum(CC.get(aa, 0) for aa in AA))


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

int main(){
    int n, a, b, c, x;
    while(cin >> n >> a >> b >> c >> x, n != 0){
        vector<int> y;
        for(int i=0;i<n;++i){
            int tmp;
            cin >> tmp;
            y.push_back(tmp);
        }
        int cnt = (x == y[0] ? 1 : 0), frame = 0;
        for(;frame<=10000;++frame){
            if(cnt >= n)break;
            x = (a * x + b) % c;
            if(x == y[cnt])cnt++;
        }
        cout << (cnt == n && frame <= 10000 ? frame : -1) << endl;
    }

    return 0;
}


Measured memory_bytes: 3048
#include <stdio.h>
int main ()
{
	int A,B,C;
	0 <= A;
	B <= 23;
	scanf ("%d", &A);
	scanf ("%d", &B);
	C = A + B;
	if (C>=24){
		printf ("%d", C - 24);
	} else if ( C < 24){
		printf ("%d",C);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <float.h>
#include <math.h>
#include <fstream>
 #define  PI 3.14159265358979323846264338327950L
using namespace std;
int main(){
  int a,b,h,m;
  long double ans,s,hs,ms,s1;
  
  cin >> a >> b >> h >> m;
  hs=h*30+m*0.5;
  ms=m*6;
  if(hs>ms){
    s=hs-ms;
  }
  else
    s=ms-hs;
 long double a1=double(a*a+b*b);
  ans = a1-2*a*b*cos(s * PI /180.0);
  ans =sqrt(ans);
  cout << fixed << setprecision(20) << ans << endl; 
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<pii,int>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int n; cin >> n;
    vector<piii>v,u;
    priority_queue<pii,vector<pii>>vque;
    rep(i,n){
        pii temp; cin >> temp.first >> temp.second;
        v.push_back(piii(temp,i));
        vque.push(pii(temp.first+temp.second,i));
    }
    int cnt = 0,vsum = 0,usum = 0;
    while(cnt < n){
        auto top = vque.top();
        vque.pop();
        if(cnt % 2 == 0){
            vsum += v[top.second].first.first;
        } else {
            usum += v[top.second].first.second;
        }
        cnt++;
    }
    cout << vsum - usum << endl;
}





Measured memory_bytes: 5804
E = []
v, e = map(int, input().split())
for _ in range(e):
    s, t, w = map(int, input().split())
    E.append((w, s, t))


class UnionFind:
    def __init__(self, N):
        self.N = N
        self.parent = [-1]*N

    def findset(self, A):
        if self.parent[A] < 0:
            return A
        self.parent[A] = self.findset(self.parent[A])
        return self.parent[A]

    def size(self, A):
        return -self.parent[self.findset(A)]

    def unite(self, A, B):
        A = self.findset(A)
        B = self.findset(B)

        if A == B:
            return False

        if self.size(A) > self.size(B):
            A, B = B, A

        self.parent[A] += self.parent[B]
        self.parent[B] = A

        return True

    def is_same(self, A, B):
        return self.findset(A) == self.findset(B)
        

def kruskal(N):
    edges = sorted(E)
    ans = 0
    union = UnionFind(N)
    cnt = 0
    for w, s, t in edges:
        if cnt == N-1:
            break

        if union.is_same(s, t):
            continue
        else:
            union.unite(s, t)
            ans += w
            cnt += 1
            
    return ans

print(kruskal(v))


Measured memory_bytes: 23964
#include<stdio.h>
int main(void)
{
	int n,i,cnt,max,a[100];
	scanf("%d",&n);
	for(i=0;i<n;i++){
			scanf("%d",&a[i]);
	}
	cnt=0;
	max=0;
	for(i=0;i<n;i++){
			if(a[i]==1){
				cnt++;
				if(max<cnt){
					max=cnt;
				}
			}
			else {	cnt=0;
			}
	}
	max++;
	printf("%d\n",max);
	return 0;
}


Measured memory_bytes: 2712
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll int64_t
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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


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

#define N_MAX 100000

struct Card{
    char suit;
    int value;
};

struct Card L[N_MAX/2],R[N_MAX/2];

void merge(struct Card A[],int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    REP(i,n1) L[i] = A[left+i];
    REP(i,n2) R[i] = A[mid+i];
    L[n1].value = INF;
    R[n2].value = INF;
    int i=0,j=0;
    for(int k=left;k<right;k++){
        if(L[i].value<=R[j].value){
            A[k] = L[i];
            i++;
        }
        else{
            A[k] = R[j];
            j++;
        }
    }
}
void mergeSort(struct Card A[],int left,int right){
    if(left+1 < right){
        int mid = (left+right)/2;
        mergeSort(A,left,mid);
        mergeSort(A,mid,right);
        merge(A,left,mid,right);
    }
}

int partition(struct Card A[],int p,int r){
    int i,j;
    struct Card t,x;
    x = A[r];
    i = p-1;
    for(j=p;j<r;j++){
        if(A[j].value<=x.value){
            i++;
            t = A[i];
            A[i]=A[j];
            A[j]=t;
        }
    }
    t = A[i+1];
    A[i+1] = A[r];
    A[r] = t;
    return i+1;
}

void quickSort(struct Card A[],int p, int r){
    if(p<r){
        int q = partition(A, p, r);
        quickSort(A,p,q-1);
        quickSort(A,q+1,r);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    Card A[N_MAX],B[N_MAX];
    REP(i,n){
        cin>>A[i].suit>>A[i].value;
        B[i].suit=A[i].suit;
        B[i].value=A[i].value;
    }
    mergeSort(A,0,n);
    quickSort(B,0,n-1);
    bool stable=true;
    REP(i,n){
        if(A[i].suit!=B[i].suit) stable=false;
    }
    if(stable) cout<<"Stable"<<endl;
    else cout<<"Not stable"<<endl;
    REP(i,n) cout<<B[i].suit<<" "<<B[i].value<<endl;
}


Measured memory_bytes: 5484
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;
  vector<int> K(N);
  vector<vector<int>> A(N,vector<int>(30,0));
  for (int i=0;i<N;i++) {
    cin >> K.at(i);
    for (int j=0;j<K.at(i);j++) {
      cin >> A.at(i).at(j);
    }
  }
  
  vector<int> x(30);
  for (int i=0;i<N;i++) {
    for (int j=0;j<K.at(i);j++) {
      for (int k=0;k<30;k++) {
        if (A.at(i).at(j)==k+1) {
          x.at(k)++;
        }
      }
    }
  }
  
  int count=0;
  for (int i=0;i<30;i++) {
    if (x.at(i)==N) {
      count++;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<bitset>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define INF 0X3F3F3F3F
#define N 100005
#define M 200005
#define LL long long
#define FF(i, a, b) for(int i = a; i <= b; ++i)
#define RR(i, a, b) for(int i = a; i >= b; --i)
#define FJ(i, a, b) for(int i = a; i < b; ++i)
#define SC(x) scanf("%d", &x)
#define SCC(x, y) scanf("%d%d", &x, &y)
#define SCCC(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define SS(x) scanf("%s", x)
#define PR(x) printf("%d\n", x)
#define CL(a, x) memset(a, x, sizeof(a))
#define _P fd[rt]
#define _L fd[rt << 1]
#define _R fd[rt << 1 | 1]
#define MID int mid = ((l + r) >> 1)
#define lson rt<<1 ,l, mid
#define rson rt<<1 | 1, mid + 1, r
#define VI vector<int>
#define PII pair<int, int>
#define PL pair<long long, long long>
#define MP make_pair
#define PB push_back
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
using namespace std;
const int MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-8;
inline void II(int &n){char ch = getchar(); n = 0; bool t = 0;
for(; ch < '0'; ch = getchar()) if(ch == '-') t = 1;
for(; ch >= '0'; n = n * 10 + ch - '0', ch = getchar()); if(t) n =- n;}
inline void OO(int a){if(a < 0) {putchar('-'); a = -a;}
if(a >= 10) OO(a / 10); putchar(a % 10 + '0');}
inline int sgn(double x){return (x > EPS) - (x < -EPS);}
//struct EE{int v, w, nx;}E[M * 2 + N * 2]; int hd[N], EN;
//void init_edge(int num){EN = 0; memset(hd, -1, (num + 2) << 2);}
//void add_edge(int u, int v, int w){
//    E[EN].w = w; E[EN].v = v; E[EN].nx = hd[u]; hd[u] = EN++;
//    E[EN].w = w; E[EN].v = u; E[EN].nx = hd[v]; hd[v] = EN++;
//}
//const int dir[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};
int n, a[N];
int main(){
   // IN;
    SC(n);
    FF(i, 1, n) II(a[i]);
    sort(a + 1, a + 1 + n);
    int s1 = 0, s2 = 0;
    int i = n;
    while(i >= 1){
        if(a[i] == a[i - 1]){
            if(s1 == 0) s1 = a[i];
            else s2 = a[i];
            --i;
        }
        if(s1 != 0 && s2 != 0) break;
        --i;
    }
    cout << 1LL * s1 * s2 << endl;
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

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

    long A = scanner.nextInt();
    long B = scanner.nextInt();
    long C = scanner.nextInt();
    int tot = 0;
    while (allEven(A, B, C)) {
      if (allSame(A, B, C)) {
        System.out.println(-1);
        return;
      }
      long newA = (B + C) / 2;
      long newB = (A + C) / 2;
      long newC = (A + B) / 2;
      A = newA;
      B = newB;
      C = newC;
      tot++;
    }
    System.out.println(tot);
  }

  private static boolean allSame(long... nums) {
    return nums[0] == nums[1] && nums[1] == nums[2];
  }

  private static boolean allEven(long... nums) {
    for (long n : nums) if (n % 2 != 0) return false;
    return true;
  }
}


Measured memory_bytes: 23636
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define F(i,a,n) for(int i=a; i<n; i++)


int main(){
    int n;
    scanf("%d",&n);
    int n1,n2,n3;
    F(i,0,3){
        n1=n%10;
        n2=(n/10)%10;
        n3=(n/100)%10;
    }
    if(n1==7 || n2==7 || n3==7){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 1644
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

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

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll dp[201010];
ll dpsum[201010];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	double w, h, x, y;
	cin >> w >> h >> x >> y;
	double ans = (h * w) / 2;
	exout(ans);
	if (2 * x == w && 2 * y == h) {
		cout << 1 << endl;
	}
	else cout << 0 << endl;
	return 0;
}


Measured memory_bytes: 3780
#include<stdio.h>
#include<string.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
int main()
{
  int i=0,N=IN(),Q=IN(),H=N,W=N,col[N],row[N];long b=1l*(N-2)*(N-2);
  memset(col,N,sizeof(col));memcpy(row,col,N*sizeof(int));
  while(Q--)
  {
    int type=IN(),x=IN()-1;
    if(type==1){if(x<W){i=x;while(i<W-1){col[i++]=H;}W=x+1;}b-=col[x]-2;}
    else{if(x<H){i=x;while(i<H-1){row[i++]=W;}H=x+1;}b-=row[x]-2;}
  }
  return OUT(b),0;
}

Measured memory_bytes: 3092
#include<stdio.h>
     
    int main(){
      int n,k,x,y,ans=0;
      scanf("%d%d%d%d",&n,&k,&x,&y);
      if(n>=k){
      for(int i=0;i<k;i++){
      ans += x;
      }
      for(int i=k;i<n;i++){
        ans += y;
      }
      }
      else
        ans = n*x;
      printf("%d",ans);
      return 0;
    }

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;


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

  vector<int> A(N);
  vector<int> B(N);
  int sum = 0;
  REP(i, N){
    cin >> A[i] >> B[i];
    sum += A[i];
  }


  REP(i, N){
    if(A[i] != B[i]) break;
    if(i == N-1){
      cout << 0 << endl;
      return 0;
    }
  }

 int minimum = INF;
  REP(i, N){
    if(A[i] > B[i]) chmin(minimum, B[i]);
  }

  cout << sum-minimum << endl;

  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
using namespace std;

typedef pair<int,string> P;

int main(void)
{
	char c;
	int n;

	while(cin >> n,n){
		vector<P> data[30];

		while(--n, n >= 0){
			cin >> c;
		char fc = c;
		
		string word;

		word += c;
		while(c = cin.get(), c != '\n'){
			if(c == ' '){
				bool flag = false;
				for(int i = 0; i < (signed)data[fc-'a'].size(); i++){
					if(data[fc-'a'][i].second == word){
						data[fc-'a'][i].first--;
						flag = true;
						break;
					}
				}
				if(!flag){
					data[fc-'a'].push_back(P(3000,word));
				}

				//cout << word << endl;
				word.clear();
				fc = 0;
			}
			else{
				word += c;
				if(!fc)
					fc = c;
			}
				
		}
		{
			bool flag = false;
			for(int i = 0; i < (signed)data[fc-'a'].size(); i++){
				if(data[fc-'a'][i].second == word){
					data[fc-'a'][i].first--;
					flag = true;
					break;
				}
			}
			if(!flag){
				data[fc-'a'].push_back(P(3000,word));
			}
		}
		}

		for(int i = 0; i < 26; i++){
			if(data[i].size())
				sort(data[i].begin(), data[i].end());
		}

		char in;

		cin >> in;


		if(data[in-'a'].size()){
			cout << data[in-'a'][0].second;
			for(int i = 1; i < (signed)data[in-'a'].size(); i++){
				if(i >= 5)
					break;
				cout << ' ' << data[in-'a'][i].second;
			}
			cout << endl;
		}
		else
			cout << "NA" << endl;
		cin.get();

	}



	return 0;
}



// 1144

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()

int N;
vector<string> S;

ll solve() {
    REP (i, N) sort(ALL(S[i]));
    sort(ALL(S));
    ll ans = 0;
    ll i = 0;
    while (i < N) {
        ll j = i+1;
        while (j < N) {
            if (S[i] == S[j]) j++;
            else break;
        }
        ans += (j-i)*(j-i-1)/2;
        i = j;
    }
    return ans;
}

int main() {
    cin >> N;
    S = vector<string>(N);
    REP (i, N) cin >> S[i];
    cout << solve() << endl;
}

Measured memory_bytes: 7296
#入力した　STRING　を　そのまま表示したり　逆にしたり　新しい文字に変えたりするプログラム
inputstring=gets.chomp
inputtimes=gets.to_i
inputtimes.times do
    command,inputrange1,inputrange2,replacewrd=gets.split
    range1=inputrange1.to_i                     #インプットを数字に変える
    range2=inputrange2.to_i                     #インプットを数字に変える

    case command
        when "print"
         puts inputstring[range1..range2]
        when "reverse"
           inputstring[range1..range2]=inputstring[range1..range2].reverse
        when "replace"
             inputstring[range1..range2]=replacewrd
    end

end


Measured memory_bytes: 8892
from collections import Counter
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=Counter(a)
d=c.most_common()
if k<=len(d):
  s=0
  for i in range(k):
    s+=d[i][1]
  print(n-s)
else:
  print(0)

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

#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
#define CININIT cin.tie(0),ios::sync_with_stdio(false)
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

int main(){
    int H,W;cin>>H>>W;
    vector<string> blue(H,string(W,'.')),red(H,string(W,'.'));
    rep(i,H){
        cin>>blue[i];
        red[i]=blue[i];
    }

    rep(i,H){
        red[i][0]='#';
        if(i%2==0){
            for(int j=0;j<W-1;j++) red[i][j] = '#';
        }
    }

    rep(i,H){
        blue[i][W-1]='#';
        if(i%2!=0){
            for(int j=1;j<W;j++) blue[i][j]='#';
        }
    }

    for(int i=0;i<H;i++) cout << red[i] << endl;
    cout << endl;
    for(int i=0;i<H;i++) cout << blue[i] << endl;
}


Measured memory_bytes: 1280
#include<cstdio>
#include<algorithm>
using namespace std;
int gi(){
	int x=0,w=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')w=0,ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
const int N=3005;
const int mod=1e9+7;
int n,m,f[N][N],g[N][N],ans;
void add(int &x,int y){x+=y;x>=mod?x-=mod:x;}
int main(){
	n=gi();m=gi();
	for(int i=1;i<=n;++i)f[0][i]=1;g[0][0]=1;
	for(int i=0;i<=m;++i)
		for(int j=0;j<=n;++j){
			if(f[i][j]){
				if(j)add(j==1?g[i+1][j-1]:f[i+1][j-1],f[i][j]),add(j==1?g[i+1][j]:f[i+1][j],f[i][j]);
				if(j<n)add(f[i+1][j+1],f[i][j]),add(f[i+1][j],f[i][j]);
			}
			if(g[i][j]){
				if(j)add(g[i+1][j-1],g[i][j]),add(g[i+1][j],g[i][j]);
				if(j<n)add(g[i+1][j+1],g[i][j]),add(g[i+1][j],g[i][j]);
			}
		}
	for(int i=0;i<=n;++i)ans=(ans+g[m][i])%mod;
	printf("%d\n",ans);return 0;
}


Measured memory_bytes: 69376
#include <bits/stdc++.h>
#define N 50001
#define M 100011
#define f first
#define s second
#define INF (1e9)
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
int n,m,T;
vector<PP> G[M]; // to,cost,y,x
vector<int> g[M],used[M];
vector<P> D[M];

priority_queue<PP,vector<PP>,greater<PP> >Q;  
P dijkstra(int a,int b){

  while(!Q.empty()){
    PP t=Q.top();Q.pop();
    int cost=t.f.f,cnt=t.f.s;
    int y=t.s.f, x=t.s.s;
    int pos=g[y][x];
    if(D[y][x]<t.f||used[y][x]++)continue;
    if(pos==b) return t.f;
    
    for(int i=0;i<G[pos].size();i++){
      PP e=G[pos][i];
      int ncost=cost+e.f.s,ncnt=cnt;
      int ny=e.s.f,nx=e.s.s;
      if(pos!=a&&(ny!=y||abs(x-nx)!=1)) ncost+=T,ncnt++;
      if(D[ny][nx]>P(ncost,ncnt)){
	D[ny][nx]=P(ncost,ncnt);
	Q.push(PP(D[ny][nx],P(ny,nx)));
      }
    }
  }
  return P(-1,-1);
}

int main(){
  string s,t;
  cin>>m>>T>>s>>t;
  map<string,int> mp;
  mp[s]=n++;
  mp[t]=n++;

  for(int i=0,a;i<m;i++){
    cin>>a;
    D[i].resize(a,P(INF,INF));
    used[i].resize(a,0);
    for(int j=0;j<a;j++){
      string str;
      cin>>str;
      if(!mp.count(str))mp[str]=n++;
      if(str==s)D[i][j]=P(0,0);
      if(str==s&&Q.empty())Q.push(PP(P(0,0),P(i,j)));
      g[i].push_back(mp[str]);
    }

    for(int j=0,pre=g[i][0],cost;j<a-1;j++){
      cin>>cost;
      int pos=g[i][j+1];
      G[pre].push_back(PP(P(pos,cost),P(i,j+1)));
      G[pos].push_back(PP(P(pre,cost),P(i,j)));
      pre=pos;
    }
  }

  P ans=dijkstra(0,1);
  if(ans==P(-1,-1)) cout<<-1<<endl;
  else cout<<ans.f<<" "<<ans.s<<endl;
  return 0;
}

Measured memory_bytes: 26244
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS

void solve(){
	string is;
	cin>>is;
	string s;
	char c = is[0];
	s += c;
	int cnt = 0;
	for(int i=1;i<is.size();i++){
		if(is[i] == c){

		}
		else{
			s += is[i];
			c = is[i];
			cnt += 1;
		}
	}
	cout<<cnt<<endl;
}

int main(){
	fastread;
	int t = 1;
	// cin>>t;	
	for(int i=1;i<=t;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 592
def main():
    n = int(input())
    if n == 0:
        print(0)
        return

    ss = []
    t = 0
    m = 1
    while n != t:
        s = int((n - t) % (abs(m) * 2) != 0)
        ss.append(s)
        if s:
            t += m
        m *= -2
    print(''.join(map(str, reversed(ss))))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
            using namespace std;
            #define rep(i,a,b) for(ll i =a; i<b;++i)
            #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
            #define endl "\n"
            #define pb push_back
            #define F first
            #define S second
            #define print(a)       for(auto x : a) cout << x << " "; cout << endl
            #define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
            #define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl
            #define mk(x,y)  make_pair(x,y)
            typedef  long long  int ll;
            const int N = ( 5e5 + 5 );
            const int mod = 1e9+7;
            ll  n,a[N],fact[N] ,ans;

    ll pow_mod_m(ll a , ll n)
    {
        if(!n)
            return 1;
        ll pt =  pow_mod_m(a,n/2);
        pt *= pt ; pt %= mod;
        if(n&1)
            pt *= a , pt %= mod;
        return pt;
    }


    int main()
    {
         IOS;
      //     freopen("a_example (2).txt","r",stdin);
      //     freopen("c.txt","w",stdout);

        int ts =1;
      //  cin>>ts;
        rep(t,1,ts+1)
        {
            fact[0] = 1;
            cin>> n;
            map < ll, ll > mp;
            rep(i,0,n) {cin >> a[i];  mp[a[i]]++;}
            for(auto u : mp)
            {
                ans += (u.S)*(u.S-1)/2;
            }
            rep(i,0,n){
                cout << ans - (mp[a[i]]-1) << endl;
            }
        }

    }


Measured memory_bytes: 13696
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll MOD = 1e9+7;
const ll inf = (LLONG_MAX>>2);
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll a,b;
  cin >> a >> b;
  cout << (b-1+a-2)/(a-1);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
    int R[MAX], n;
    
    cin >> n;
    for (int i = 0; i < n; i++) cin >> R[i];
    
    int maxv = -2000000000;
    int minv = R[0];
    
    for( int i = 1; i < n; i++){
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }
    
    cout << maxv << endl;
    
    return 0;
}

Measured memory_bytes: 1940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define int ll
//#define double ld
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ifstream in("input.txt");ofstream out("output.txt");
const int inf=1e18;
const int mod=1e9+7;

int n;
vector<vector<int> > mat;
vector<int> dp;
void init()
{
    cin>>n;
    mat.resize(n,vector<int>(n));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cin>>mat[i][j];
        }
    }
    dp.resize(1<<n);
    dp[0]=1;
}

int solveIter()
{
    for(int mask=1;mask<(1<<n);mask++)
    {
        int ones=__builtin_popcount(mask);
        for(int j=0;j<n;j++)
        {
            if(mask&(1<<j))
            {
                int curr=mask^(1<<j);
                if(mat[ones-1][j])
                    dp[mask]=(dp[mask]+dp[curr])%mod;
            }
        }
    }
    return dp[(1<<n)-1];
}

signed main()
{
    init();
    cout<<solveIter();
    return 0;
}


















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

using namespace std;

int main(){
	int n;
	cin>>n;
	long long sum=0LL;
	for(int i=1;i<=n;i++){
		if(i%3!=0&&i%5!=0){
			sum+=i;
		}
	}
	cout<<sum;
	return 0;
}

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

const int N = 1e5;

int li[N+5];
int n;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		if(x-1 >= 0)li[x-1]++;
		li[x]++;
		li[x+1]++;
	}
	int ans = 0;
	for(int i=0;i<=N+1;i++){
		ans = max(ans,li[i]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>

#define MOD 1000000007
#define INTMAX 0x7fffffff
#define INTMIN 0x80000000
#define LLMAX 0x7fffffffffffffffLL
#define LLMIN 0x8000000000000000LL

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;
using ll = long long;

ll f(ll a, ll b) {
	if (a == b) {
		return 1;
	}

	ll mask = 0x4000000000000000LL;
	int r = 63;
	bool d = false;
	while ((a & mask) == (b & mask)) {
		if ((b & mask) != 0){
			d = true;
		}
		mask >>= 1;
		--r;
	}
	if (d) {
		mask = LLMAX >> (63 - r);
		return f(a & mask, b & mask);
	}

	if (r == 1){
		return 2;
	}

	// calculate k
	mask = 1LL << (r - 2);
	int k = r - 1;
	while ((b & mask) == 0 && mask != 0){
		mask >>=1;
		k--;
	}

	ll powr = 1LL << r; // 2 ^ r
	ll powk = 1LL << k; // 2 ^ k
	return powk + powr - a - max(a, powk);
}

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

	cout << f(A, B) << endl;
}

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

ans = 0
for i in range(N):
  ans += B[A[i]-1]
  if i < N-1 and A[i+1] - A[i] == 1: ans += C[A[i]-1]
    
print(ans)

Measured memory_bytes: 9152
N = int(input())
W = [int(w) for w in input().split()]
front = [0]
count = 0
for w in W:
        count += w
        front.append(count)
count = 0
minimam = 100*100
for index, w in enumerate(W[::-1]):
        count += w
        minimam = min(minimam, abs(count - front[N - 1 - index]))
print(minimam)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;




int main(){
	int n;
	cin >> n;
	
	vector<int> s(n);
	int sum = 0;
	rep(i, 0, n) {
		cin >> s[i];
		sum += s[i];
	}


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

	if (sum % 10 != 0) {
		cout << sum << endl;
		exit(0);
	}
	else {
		rep(i, 0, n) {
			if (s[i] % 10 != 0) {
				cout << sum - s[i] << endl;
				exit(0);
			}
		}
	}
	
	cout << "0" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <map>
#include <cstdio>
using namespace std;
void solve(int T){
	map<pair<int,int>,int> m;
	char cmd[2];
	int n,k;
	for(;T--;){
		scanf("%s%d",cmd,&n);
		if(*cmd=='D'){
			for(auto it=m.begin();it!=m.end();)if(it->second==n)m.erase(it++);else	++it;
		}else if(*cmd=='R'){
			auto it=m.lower_bound(make_pair(n,2000000000));
			printf("%d\n",it==m.begin()||n<(--it)->first.first||it->first.second<n ? -1 : it->second);
		}else if(*cmd=='W'){
			int cur=0;
			scanf("%d",&k);
			for(auto it=m.begin();it!=m.end();++it){
				int d=it->first.first-cur;
				if(d>k)d=k;
				if(d)m[make_pair(cur,cur+d-1)]=n;
				k-=d;
				if(k==0)break;
				cur=it->first.second+1;
			}
			if(k)m[make_pair(cur,cur+k-1)]=n;
		}
	}
}
int main(){for(int T;~scanf("%d",&T)&&T;puts(""))solve(T);}

Measured memory_bytes: 1240
import java.io.*
import java.util.*

var pw = PrintWriter(System.out)
fun solve(N: Int, S: String){
    var ans = 0
    for(i in 0 until S.length - 2){
        if(S.slice(i..i+2) == "ABC") ans++
    }
    println(ans)
    pw.flush()
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val S = sc.next()
    solve(N, S)
}



Measured memory_bytes: 31372
from collections import Counter
import heapq
N,M = map(int,input().split())
A = Counter(list(map(int,input().split())))

cards = []
for x,y in A.items():
  heapq.heappush(cards, (-x,y))

for _ in range(M):
  b,c = map(int,input().split())
  heapq.heappush(cards, (-c,b))

cnt = N
res = 0
while cnt <= N:
  v,c = heapq.heappop(cards)
  v *= -1

  if cnt-c < 0:
    res += v*cnt
    break
  else:
    res += v*c
    cnt -= c

print(res)

Measured memory_bytes: 93976
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  
  if(s == "Sunny"){
    cout << "Cloudy" << endl;
  }
  
  else if (s == "Cloudy"){
    cout << "Rainy" << endl;
  }
  
  else{
    cout << "Sunny" << endl;
  }
  
}

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

constexpr int INF = 2e9;

int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  map<string, ll> mp;
  rep(i,n) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
    mp[s[i]]++;
  }
  ll res = 0;
  for (auto e : mp) {
    res += (e.second) * (e.second - 1) / 2;
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 18176
//by achhhy
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
inline int in()
{
	char ch=getchar();
	int f=1,x=0;
	while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	return f*x;
}
//need changing
const int inf=(1<<30);
const int mod=1e9+7;
const int N=2010;

int n,k,Q;
LL a[N],b[N];
LL ans=inf;

bool check(int L,int R)
{
	int ret=0;
	for(int i=1,j;i<=n;i=j+1)
	{
		j=i;
		if(a[i]<b[L]) continue;
		int cnt=0;
		while(j<=n&&a[j]>=b[L]) cnt+=(a[j]<=b[R]),++j;
		ret+=min( cnt ,max(0, j-i-(k-1) ));
	}
	return ret>=Q;
}

void calc(int w)
{
	int l=w,r=n,cur=0;
	while(l<=r)
	{
		if(b[l]-b[w]>ans) return;
		int mid=l+r>>1;
		if(check(w,mid)) r=mid-1,cur=mid;
		else l=mid+1;
	}
	if(!cur) return; 
	ans=min(ans,b[cur]-b[w]);
}

int main()
{
	n=in(),k=in(),Q=in();
	rep(i,1,n) a[i]=in(),b[i]=a[i];
	sort(b+1,b+n+1);

	rep(i,1,n) calc(i);
	
	printf("%lld\n",ans);
	return 0;
}




Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,x,y;
   y=0;
 cin >> a >> b >> c;
for (x = a; x <= b; x++){
 if(c%x == 0){
    y++;
 };
};
 cout << y << endl;
return 0;
}

Measured memory_bytes: 3100
N, K = map(int, input().split())
x_list = []
y_list = []
xy_list = []
for _ in range(N):
    x, y = map(int, input().split())
    x_list.append(x)
    y_list.append(y)
    xy_list.append((x, y))
x_dict = {}
x_dict_rev = {}
y_dict = {}
y_dict_rev = {}
x_list.sort()
y_list.sort()
for i, xi in enumerate(x_list):
    x_dict[xi] = i
    x_dict_rev[i] = xi
for i, yi in enumerate(y_list):
    y_dict[yi] = i
    y_dict_rev[i] = yi
xy_c = [[0 for _ in range(N)] for _ in range(N)]
for x, y in xy_list:
    xy_c[x_dict[x]][y_dict[y]] = 1

cs = [[0 for _ in range(N+1)] for _ in range(N+1)]
for i in range(N):
    for j in range(N):
        cs[i+1][j+1] = cs[i+1][j] + cs[i][j+1] - cs[i][j] + xy_c[i][j]

ans = float('inf')
for x_min in range(1, N+1):
    for x_max in range(1, N+1):
        for y_min in range(1, N+1):
            for y_max in range(1, N+1):
                if cs[x_max][y_max] - cs[x_min-1][y_max] - cs[x_max][y_min-1] + cs[x_min-1][y_min-1] >= K:
                    ans = min(ans, (x_dict_rev[x_max-1] - x_dict_rev[x_min-1]) * (y_dict_rev[y_max-1] - y_dict_rev[y_min-1]))


print(ans)


Measured memory_bytes: 44268
#coding:utf-8

def main():
    N = int(input())
    H = list(map(int, input().split()))
    num = 0
    border = 0
    for i in range(N):
        if H[i] - border >= 0:
            num += 1
            border = H[i]

    print(num)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <ios>
#include <iostream>
#include <vector>

std::vector<std::vector<int> > adjlist;
std::vector<std::vector<int> > children;
bool vis[100005] = {};

void dfs(int x)
{
    for (std::vector<int>::iterator it = adjlist[x].begin(); it != adjlist[x].end(); it++)
    {
        if (!vis[*it])
        {
            vis[*it] = true;
            children[x].push_back(*it);
            dfs(*it);
        }
    }
}

int nim(int x)
{
    if (children[x].size() == 0)
        return 0;
    else if (children[x].size() == 1)
        return nim(*children[x].begin())+1;
    else
    {
        int nm = 0;
        for (std::vector<int>::iterator it = children[x].begin(); it != children[x].end(); it++)
            nm ^= nim(*it)+1;
        return nm;
    }
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);
    int n, x, y;
    std::cin >> n;
    adjlist.resize(n+5);
    children.resize(n+5);
    for (int i = 0; i < n-1; i++)
    {
        std::cin >> x >> y;
        x--; y--;
        adjlist[x].push_back(y);
        adjlist[y].push_back(x);
    }
    vis[0] = true;
    dfs(0);
    std::cout << (nim(0) == 0 ? "Bob" : "Alice") << '\n';
}


Measured memory_bytes: 14464
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll a[200010], sum[200010], ans = 1e18;

int main() {
	ios_base::sync_with_stdio(0);
	int n; cin >> n;
	for (int i=1;i<=n;i++) {
		cin >> a[i];
		sum[i] = sum[i-1] + a[i];
	}
	for (int i=1;i<n;i++) ans = min(ans, abs(2*sum[i]-sum[n]));
	cout << ans << endl;
}

Measured memory_bytes: 3328
import sys
input = sys.stdin.readline
from collections import *

def f(x):
    return 2*D*x+X-K*D

X, K, D = map(int, input().split())

if f(0)==0 or f(K)==0:
    print(0)
    exit()

if f(0)>0:
    print(f(0))
elif f(K)<0:
    print(abs(f(K)))
else:
    m = (K*D-X)//(2*D)
    ans = 10**18
    
    for i in range(m-100, m+100):
        if 0<=i<=K:
            ans = min(ans, abs(f(i)))
    
    print(ans)

Measured memory_bytes: 65128