akhauriyash/Code-Regression huggingface dataset:
//package solution;

import java.io.*;
import java.util.*;
import java.math.*;
import java.text.*;
import java.awt.Point;

public final class Main {
    BufferedReader br;
    StringTokenizer stk;

    public static void main(String[] args) throws Exception {
        //new Thread(null, new Runnable() {
            //@Override
            //public void run() {
                //try {
                    new Main().run();
                //} catch(Exception ex) {ex.printStackTrace();}
            //}
        //}, "solution", 1<<26).start();
    }
    
    {
        stk = null;
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    
    //long mod = 1000000007L;
    void run() throws Exception {
        int n = ni(), x = ni(), y = ni();
        HashSet<Integer>[] g = new HashSet[n];
        for(int i=0; i<n; i++) g[i] = new HashSet<>();
        for(int i=1; i<n; i++) {
            g[i-1].add(i); g[i].add(i-1);
        }
        g[x-1].add(y-1);
        g[y-1].add(x-1);
        
        HashMap<Integer, Integer> map = new HashMap<>();
        for(int i=0; i<n; i++) {
            int[] sp = shortestPath(i, g);
            for(int num : sp) {
                if(num == 0 || num == 9999999) continue;
                if(!map.containsKey(num))
                    map.put(num, 0);
                map.put(num, map.get(num) + 1);
            }
        }
        
        for(int i=1; i<n; i++) {
            if(map.containsKey(i)) {
                pl(map.get(i) >> 1);
            } else {
                pl("0");
            }
        }
    }
    
    int[] shortestPath(int src, HashSet<Integer>[] g) {
        Queue<Integer> queue = new LinkedList<>();
        HashSet<Integer> visited = new HashSet<>();
        queue.add(src);
        int[] cost = new int[g.length];
        Arrays.fill(cost, 9999999);
        cost[src] = 0;
        while(!queue.isEmpty()) {
            int cur = queue.remove();
            if(visited.contains(cur)) continue;
            visited.add(cur);
            for(int adj : g[cur]) {
                cost[adj] = Math.min(cost[adj], cost[cur] + 1);
                queue.add(adj);
            }
        }
        return cost;
    }
    
    //Reader & Writer
    String nextToken() throws Exception {
        if (stk == null || !stk.hasMoreTokens()) {
            stk = new StringTokenizer(br.readLine(), " ");
        }
        return stk.nextToken();
    }

    String nt() throws Exception {
        return nextToken();
    }

    String ns() throws Exception {
        return br.readLine();
    }

    int ni() throws Exception {
        return Integer.parseInt(nextToken());
    }

    long nl() throws Exception {
        return Long.parseLong(nextToken());
    }

    double nd() throws Exception {
        return Double.parseDouble(nextToken());
    }

    void p(Object o) {
        System.out.print(o);
    }

    void pl(Object o) {
        System.out.println(o);
    }
}

Measured memory_bytes: 278216
// D - Widespread

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

ll N, A, B;
ll h[100000];

bool is_ok(ll k) {
	ll d = A - B;
	ll t = B * k;

	ll cnt = 0;
	for (int i=0; i<N; i++) {
		if (h[i] - t > 0) {
			cnt += (h[i] - t - 1) / d + 1;
		}
	}

	// **** debug ****
	/*
	cout << cnt << endl;
	cout << "k=" << k << " ";
	if (cnt <= k) cout << "ok" << endl;
	else cout << "ng" << endl;
	*/

	if (cnt <= k) return true;
	else return false;
}

ll find_lower_limit(ll lower, ll upper) {
	if (!is_ok(upper - 1)) return -1; // 存在しない

	ll ok = upper - 1;
	ll ng = lower - 1;

	while(ok - ng > 1) {
		ll trying = (ok + ng) / 2;

		if (is_ok(trying)) {
			ok = trying;
		} else {
			ng = trying;
		}
	}

	return ok;
}

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

	for (int i=0; i<N; i++) {
		cin >> h[i];
	}

	ll ans = find_lower_limit(0, 1000000001);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;

struct UnionFind {
  vector<int> par;  // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

  UnionFind(int N) : par(N) {  //最初は全てが根であるとして初期化
    for (int i = 0; i < N; i++) par[i] = i;
  }

  int root(int x) {  // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {  // xとyの木を併合
    int rx = root(x);         // xの根をrx
    int ry = root(y);         // yの根をry
    if (rx == ry) return;  // xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] =
        ry;  // xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

  bool same(int x, int y) {  // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  int ma = 0;
  for (int i = 0; i < n; i++) {
    int count = 0;
    for (int j = 0; j < n; j++) {
      if (j < i)
        count += a[j];
      else if (j == i)
        count += a[j] + b[j];
      else
        count += b[j];
    }
    ma = max(ma, count);
  }
  cout << ma << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 //Compiler version g++ 6.3.0

 int main()
 {
 	string n;
 	cin >> n;
 	if(n<="2019/04/30"){
 		cout << "Heisei" << endl;
 	}else{
 		cout << "TBD" << endl;
 	}
 }

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int x;
bool f;
int main()
{
    f = 0;
    scanf("%d",&x);
    while(x)
    {
        if(x%10 == 9)
        {
            printf("Yes\n");
            f = 1;
            break;
        }
        x/=10;
    }
    if(!f)
        printf("No\n");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define endl '\n'
#define inf 9223372036854775807
#define maxn 3000001
#define mod (ll)(1e9+7)
#define int ll
 
using namespace std;
 
void io(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}

int n,ar[maxn];
int dp[maxn];
int sum=0;


void __solve(){
		cin>>n;
		for(int i=1;i<=n;i++){
			cin>>ar[i];
		}
		dp[1]=0;
		sum=ar[1];
		for(int i=2;i<=n;i++){
			dp[i]=dp[i-1]+sum*ar[i];
			dp[i]%=mod;
			sum+=ar[i];
			sum%=mod;
		}
		cout<<dp[n]<<endl;
		
}


int32_t main(){
io();
IOS;    
			int t=1;
			// cin>>t;
			while(t--){
				__solve();
			}
		
		



        

        


        
    
        
        
                


 
        
 
 
 
        
 
 
 
 
        
        
 
        
        
 
    
    
    
    
 
 
       
 
 
 
 
      
   
 
 
 
 
}

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

using namespace std;

int a[5];

int main() {
	for (int i = 0; i < 5; i++) scanf("%d", &a[i]);
	
	for (int i = 0; i < 5; i++) {
		if (a[i] == 0) return 0 * printf("%d\n", i + 1);
	}
}


Measured memory_bytes: 3808
#include<iostream>
using namespace std;
const long long INF = 1LL << 60;

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

    long long a[N];

    for (int i = 0; i < N; ++i) { 
        cin >> a[i];
    }
    long long s[N+1]={};
    for (int i = 1; i < N+1; ++i) { 
        s[i]=s[i-1]+a[i-1];
    }

    long long dp[N][N]={};

    for (int i = 0; i < N-1; ++i) { 
        dp[i][i+1]=a[i]+a[i+1];
    }

    
    for (int j = 2; j < N; ++j) { 
        for (int i = 0; i < N-j; ++i) { 
            dp[i][i+j]=s[i+j+1]-s[i];
            long long M=INF;
            for (int k = 1; k < j+1; ++k) { 
                if (M > dp[i][i+j-k]+dp[i+j+1-k][i+j]){M=dp[i][i+j-k]+dp[i+j+1-k][i+j];}
            }
            dp[i][i+j]+=M;
        }
    }


    cout << dp[0][N-1] << endl;
    return 0;

}

Measured memory_bytes: 1536
class Edge():
    def __init__(self, src, to, weight):
        self.src = src
        self.to = to
        self.weight = weight

class NegativeWeightDirectedGraph():
    def __init__(self, V):
        self.V = V
        self.Edges = []
        self.INF = 10**10

    def append(self, src, to, weight):
        self.Edges.append(Edge(src, to, weight))

    def bellmanFord(self, s):
        D = [self.INF] * self.V
        D[s] = 0
        for _ in range(self.V-1):
            for e in self.Edges:
                if D[e.src] != self.INF:
                    w = D[e.src] + e.weight
                    D[e.to] = min(D[e.to], w)
        # check
        for e in self.Edges:
            if D[e.src] == self.INF:
                continue
            if D[e.src] + e.weight < D[e.to]:
                return None
        return D


V,E,r = map(int, raw_input().split())
G = NegativeWeightDirectedGraph(V)
for i in range(E):
    s,t,d = map(int, raw_input().split())
    G.append(s,t,d)

ans = G.bellmanFord(r)
if ans == None:
    print "NEGATIVE CYCLE"
else:
    for d in ans:
        if d == G.INF:
            print "INF"
        else:
            print d


Measured memory_bytes: 5420
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string s;
    cin >> s;
    char a,b;
    a = s[0];
    for (int i = 1; i < s.length(); ++i)
    {
        if (s[i] == s[i-1])
        {
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
    return 0;
}


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

using namespace std;

int main() {
  string sa,sb,sc;
  char ch;
  cin >> sa >> sb >> sc;
  
  for(;;) {
    Loopa:
    if(sa.size() == 0) {
      cout << "A" << endl;
      return 0;
    }
    ch = sa[0];
    sa.erase(0,1);
    if(ch == 'a') goto Loopa;
    if(ch == 'b') goto Loopb;
    if(ch == 'c') goto Loopc;
  }
  for(;;) {
    Loopb:
    if(sb.size() == 0) {
      cout << "B" << endl;
      return 0; 
    }
    ch = sb[0];
    sb.erase(0,1);
    if(ch == 'a') goto Loopa;
    if(ch == 'b') goto Loopb;
    if(ch == 'c') goto Loopc;
  }
  for(;;) {
    Loopc:
    if(sc.size() == 0) {
      cout << "C" << endl;
      return 0; 
    }
    ch = sc[0];
    sc.erase(0,1);
    if(ch == 'a') goto Loopa;
    if(ch == 'b') goto Loopb;
    if(ch == 'c') goto Loopc;
  }
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);ios::sync_with_stdio(false);

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

    ll res=((a-1)/b)*2*b;
    

    res+=f(b,a%b);

    return res;
}

signed main(){
    ll n,x,ans=0;cin>>n>>x;
    ans+=n+f(max(x,n-x),min(x,n-x));

    cout<<ans<<endl;
}


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

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

  vector<int> m(N);

  int m_min = INT_MAX;
  int total = 0;

  for(int i=0;i<N;i++){
    cin >> m.at(i);
    total += m.at(i);
    m_min = min(m_min, m.at(i));
  }

  cout << N + (X - total) / m_min << endl;
}


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


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

struct edge {int to; ll cost; };

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

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

ll LCM(ll a, ll b){
  if(a<b) swap(a,b);
  return a/GCD(a,b)*b;
}
 
int main(){
  set<int> st;
  for(int i=0; i<3; i++){
    int a;
    cin >> a;
    st.insert(a);
  }
  if(st.size()==2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3620
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;

int main() {

	long H, W, N; cin >> H >> W >> N;
	long B[10009] = {};
	long A[109][109];
    long C[10009] = {};
    long index = 0;
    
	for (int i = 0; i < N; i++) cin >> B[i];
    
    for (int i = 0; i < N; i++) while(B[i]--) {C[index] = i + 1; index++; }

	for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) {
		long k = (i % 2 == 0) ? j : W - j - 1;
		A[i][j] = C[i * W + k];
	}

	for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) cout << A[i][j] << endl;
}

Measured memory_bytes: 512
#include "stdio.h"

int main(void) {

    char s[4];
    int count=0;

    scanf("%s",s);

    if ('R' == s[0]) {
        count++;
    }

    if (s[1] == 'R') {
        count++;
        if (s[2] == 'R') {
            count++;
        }

    } else if ((s[2] == 'R') && (s[0] == 'S')) {
        count++;
    }

    printf("%d",count);

    return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################

signed main(){
	int h,w;
	
	cin >> h >> w;
	int a[h][w];
	int dist[10][10];
	rep(i,10)rep(j,10)cin >> dist[i][j];
	rep(i,10)rep(j,10)rep(k,10)dist[j][k] = min(dist[j][k],dist[j][i] + dist[i][k]);
	rep(i,h)rep(j,w)cin >> a[i][j];
	int ret = 0;
	rep(i,h)rep(j,w){
		if(a[i][j] == -1)continue;
		ret += dist[a[i][j]][1];
	}
	cout << ret << endl;
	
	return 0;
}

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

int main()
{
    int n,m,j,i;
    scanf("%d",&n);
    int a[n];
    for(j=0; j<n; j++){
        a[j]=0;
    }

    for(int i=1;i<n;i++)
    {
        scanf("%d",&m);

            a[m-1]++;

    }
    for(j=0; j<n; j++){
        printf("%d\n",a[j]);
    }
    return 0;

}


Measured memory_bytes: 4564
n,c,k=map(int,input().split())
x=[0]*2
ans=0
l=[]
for i in range(n):
    n=int(input())
    l.append(n)
l.sort()


for n in l:
    if x[0]==0 and c>1:
        x=[n,1]
    elif x[0]==0:
        ans+=1
    elif n>x[0]+k:
        ans+=1
        x=[n,1]
    elif x[1]+1<c:
        x[1]+=1
    else:
        ans+=1
        x=[0,0]
print(ans+[0,1][x[0]>0])


Measured memory_bytes: 50520
n,m=map(int,input().split())
A=[int(i) for i in input().split()]
if 2 in A and 3 in A:
  A.remove(2)
if 3 in A and 5 in A:
  A.remove(3)
if 2 in A and 5 in A:
  A.remove(2)
if 6 in A and 9 in A:
  A.remove(6)
m=len(A)
D={}
D[1]=2
D[2]=5
D[3]=5
D[4]=4
D[5]=5
D[6]=6
D[7]=3
D[8]=7
D[9]=6
DP=[-float("inf")]*(n+1)
DP[0]=0
for i in range(n):
  for j in range(m):
    if D[A[j]]<=i+1 and DP[i+1-D[A[j]]]!=float("inf") and DP[i+1-D[A[j]]]+1>=DP[i+1]:
      DP[i+1]=DP[i+1-D[A[j]]]+1
A.sort(reverse=True)
k=DP[n]
ans=""
cur=n
for _ in range(k):
  for j in range(m):
    if cur>=D[A[j]] and DP[cur-D[A[j]]]==DP[cur]-1:
      ans+=str(A[j])
      cur-=D[A[j]]
      break
print(ans)

Measured memory_bytes: 3404
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
//      String[] nyu=sc.nextLine().split(" ");
String[] data=new String[2];
data[0]="2019/04/30";

  //   String nyu=sc.nextLine();
data[1]=sc.nextLine();
//int[] num=new int[6];
Arrays.sort(data);
//int A=Integer.parseInt(nyu[0]);
//int B=Integer.parseInt(nyu[1]);
//int C=Integer.parseInt(nyu[2]);



//int A=Integer.parseInt(nyu[0]);
//int B=Integer.parseInt(nyu[1]);

if(data[1].equals("2019/04/30")){

System.out.println("Heisei") ;
}else{
System.out.println("TBD") ;

}
	}
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;

/* --------------------------------------------------- */

int main() {
    int n, k;
    string s;
    cin >> n >> s >> k;
    char key = s[k - 1];
    rep(i, n) {
        if(s[i] != key) s[i] = '*';
    }
    cout << s << endl;
    
    return 0;
}

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


using namespace std;

int main() {

	int K, X;
	cin >> K >> X;
	if (K * 500 >= X) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;




}

Measured memory_bytes: 256
abcd = input()
for i in range(8):
    bit = format(i,"03b")
    ans = int(abcd[0])
    for j in range(3):
        if bit[j] == "1":
            ans += int(abcd[j+1])
        else:
            ans -= int(abcd[j+1])
    if ans == 7:
        Ans = bit
        break
temp = abcd[0]

for i in range(3):
    if Ans[i] == "1":
        temp += "+"+abcd[i+1]
    else:
        temp += "-"+abcd[i+1]
temp += "=7"
print(temp)

Measured memory_bytes: 3064
def dec(day):
    ret = 0
    for i in range(26):
        ret += c[i]*(day-last[i])
    return ret


d = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(d)]
last = [0]*26

ans = 0
for i in range(d):
    t = int(input())
    ans += s[i][t-1]
    last[t-1] = i+1
    ans -= dec(i+1)
    print(ans)

Measured memory_bytes: 9400
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
	Scanner scanner = new Scanner(System.in);
	
	int num = 1;
	
	while(true) {
		int a = scanner.nextInt();
	
		
		if( a == 0) {
			
			break;
		
		}else {
			
			System.out.println("Case " + num++ +  ": " + a);
		}
		}
	
	}

}


Measured memory_bytes: 41356
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <string>
#include <functional>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
    ios_base::sync_with_stdio(false);
    ll n, a, b;
    cin >> n >> a >> b;
    vector<ll> h(n);
    int i;
    for(i = 0; i < n; i++) {
		cin >> h[i];
	}
	ll low = 1, high = 1e9;
	ll last = -1;
	while(low <= high) {
		ll mid = low + (high - low) / 2;
		//bool poss = true;
		ll req = 0;
		for(i = 0; i < n; i++) {
			if(h[i] > mid * b) {
				req += ((h[i] - mid * b) / (a - b));
				if((h[i] - mid * b) % (a - b) != 0) {
					req++;
				}
				
			}
		}
		if(req <= mid) {
			last = mid;
			high = mid - 1;
		}
		else {
			low = mid + 1;
		}
	}
	cout << last;

    return 0;
}



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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int W,A,B;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>W>>A>>B;
	if(A>B) swap(A,B);
	cout<<max(0,B-(A+W))<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 1111116
#define next nxt

int n,x[N],y[N],next[N],p[N],f[N],size[N],d[N];
long long ans;
char s[N];

void travel(int x){
	size[x]=(s[x]=='1');
	for (int t=p[x];t;t=next[t])
		if (y[t]!=f[x]){
			f[y[t]]=x;travel(y[t]);
			size[x]+=size[y[t]];
			d[x]=max(d[x],d[y[t]]+1);
		}
}

void solve(int x,int mx){
	int mn=(s[x]=='0')<<30,nx=0;
	if (size[x]!=size[1]) mn=min(mn,mx);
	for (int t=p[x];t;t=next[t])
		if (y[t]!=f[x]){
			nx=max(nx,d[y[t]]+1);
			if (nx>mx) swap(nx,mx);
			if (size[y[t]]) mn=min(mn,d[y[t]]+1);
		}
	ans+=max(min(mx-1,nx+1)-mn+1,0);
	for (int t=p[x];t;t=next[t])
		if (y[t]!=f[x])
		solve(y[t],(d[y[t]]+1!=mx)?(mx+1):(nx+1));
}

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-')  f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();
	for (int i=1;i<=n-1;i++){
		x[2*i-1]=y[2*i]=read();
		y[2*i-1]=x[2*i]=read();
		next[2*i-1]=p[x[2*i-1]];p[x[2*i-1]]=2*i-1;
		next[2*i]=p[x[2*i]];p[x[2*i]]=2*i;
	}
	scanf(" %s",s+1);
	travel(1);solve(1,0);
	printf("%lld\n",ans+1);
	return 0;
}

Measured memory_bytes: 28800
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long n, m;
    scanf("%ld%ld", &n, &m);

    printf("%ld\n", (n-1)*(m-1));

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
static const int MAX = 100;


struct Card { char suit, value; };
void bubble(struct Card A[], int N);
void selection(struct Card A[], int N);
void print(struct Card A[],int N);
bool isStable(struct Card C1[], struct Card C2[], int N);
int main()
{
    Card C1[MAX], C2[MAX];
    int N;
    
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> C1[i].suit >> C1[i].value;
    }
    
    
    for(int i=0; i<N; i++) C2[i] = C1[i];
    
    bubble(C1, N);
    selection(C2,N);
    
    print(C1, N);
    cout << "\n";
    cout << "Stable"<<endl;
    
    print(C2, N);
    cout <<"\n";
    
    if ( isStable(C1, C2, N)){
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }
    
    return 0;
}





void bubble(struct Card A[], int N){
    
    for(int i=0; i<N; i++){
      
        
       for(int j =N-1; j>=i+1; j--){
            
            if(A[j].value < A[j-1].value ){
                
                Card t = A[j];
               A[j] = A[j-1];
                A[j-1] = t;
            }
        }
    }
    
    
}




void selection(struct Card A[], int N){
    
    for(int i=0; i<N; i++){
        
        int minj = i;
        for(int j=i; j<N; j++){
            
            if(A[j].value < A[minj].value) minj=j;
        }
        Card t = A[i];
        A[i] = A[minj];
        A[minj] = t;
    }
    
    
    
}



void print(struct Card A[], int N){
     for(int i=0; i<N; i++){
        if(i>0) cout << " ";
        cout << A[i].suit << A[i].value;
    }
}




bool isStable(struct Card C1[], struct Card C2[], int N){
    
    for(int i = 0; i<N; i++){
        if(C1[i].suit != C2[i].suit) return false;
     }
      return true;
}








Measured memory_bytes: 3104
a,b,c=map(int,input().split())
if any([a%2==1,b%2==1,c%2==1])==True:
    print(0)
else:
    if len(set({a,b,c}))==1:
        print(-1)
    else:
        res=0
        while all([a%2==0,b%2==0,c%2==0]):
            a,b,c=(b+c)//2,(a+c)//2,(a+b)//2
            res+=1
        print(res)

Measured memory_bytes: 3064
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;

ll MOD = 10000;

// ModInt begin

ll mod_pow(ll x, ll n, ll mod=MOD) {
    ll ret = 1;
    x %= MOD;
    for(; n; n>>=1) {
        if(n & 1) (ret *= x) %= mod;
        (x *= x) %= mod;
    }
    return ret;
}

struct ModInt {
    ll v;
    ModInt(ll a = 0) : v(((a%MOD) + MOD) % MOD) {}
    ModInt  operator+ ( const ModInt& b ) const {return (v + b.v) % MOD;}
    ModInt  operator- ( const ModInt& b ) const {return (v - b.v + MOD) % MOD;}
    ModInt  operator* ( const ModInt& b ) const {return (v * b.v) % MOD;}
    ModInt  operator/ ( const ModInt& b ) const {return (v * mod_pow(b.v, MOD-2)) % MOD;}
};

bool    operator==(ModInt  a, ModInt b) {return a.v == b.v;}
ModInt& operator+=(ModInt& a, ModInt b) {return a = a + b;}
ModInt& operator-=(ModInt& a, ModInt b) {return a = a - b;}
ModInt& operator*=(ModInt& a, ModInt b) {return a = a * b;}
ModInt& operator/=(ModInt& a, ModInt b) {return a = a / b;}
ostream& operator<<(ostream& out, ModInt  a) {return out << a.v;}
istream& operator>>(istream& in,  ModInt& a) {
    ll v; in >> v;
    a = ModInt(v);
    return in;
}

// ModInt end

ModInt dp[3010][3010], ways[3010];
ModInt fact[3010], inv[3010];

ModInt comb(int N, int K) {
    ModInt ans = fact[N] * inv[N-K] * inv[K];
    return ans;
}
 
signed main() {
    int N; cin >> N >> MOD;

    fact[0] = ModInt(1);
    for(int i=1; i<=N; i++) {
        fact[i] = fact[i-1] * i;
    }
    inv[N] = ModInt(mod_pow(fact[N].v, MOD-2));
    for(int i=N-1; i>=0; i--) {
        inv[i] = inv[i+1] * (i+1);
    }

    for(int i=0; i<=N; i++) {
        dp[i][0] = 1;
        for(int j=1; j<=i; j++) {
            dp[i][j] = dp[i-1][j-1] + dp[i-1][j] * (j+1);
        }
    }

    for(int i=0; i<=N; i++) {
        for(int j=0; j<=i; j++) {
            ways[i] += dp[i][j] * mod_pow(2, (N-i)*j);
        }
        ways[i] *= mod_pow(2, mod_pow(2, N-i, MOD-1));
    }

    ModInt ans = 0;
    for(int i=0; i<=N; i++) {
        ModInt val = comb(N, i) * ways[i];
        if(i % 2 == 1) ans -= val;
        if(i % 2 == 0) ans += val;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 71040
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    ans = float("inf")
    for i in range(n+1):
        m = 0
        k = i
        while k > 0:
            m += k%6
            k //= 6
        k = n-i
        while k > 0:
            m += k%9
            k //= 9
        if m < ans:
            ans = m
    print(ans)
    return

#B
def B():
    n = I()
    x = [None for i in range(n)]
    y = [None for i in range(n)]
    h = [None for i in range(n)]
    for i in range(n):
        x[i],y[i],h[i] = LI()
    if n == 1:
        print(x[0],y[0],h[0])
        quit()
    for cy in range(101):
        for cx in range(101):
            for i in range(n):
                if h[i] > 0:break
            ch = h[i]+abs(x[i]-cx)+abs(y[i]-cy)
            f = 1
            for i in range(n):
                if max(ch-abs(x[i]-cx)-abs(y[i]-cy),0) != h[i]:f = 0
            if f:
                print(cx,cy,ch)
                quit()
    return

#C
def C():
    def dfs(m,k):
        if m == n:
            lis.append(k)
        else:
            for i in range(4):
                dfs(m+1,k+[i])
    n,a,b,c = LI()
    an = [a,b,c]
    l = IR(n)
    lis = []
    dfs(0,[])
    ans = float("inf")
    for k in lis:
        s = [0,0,0,0]
        d = [0,0,0,0]
        for i in range(n):
            s[k[i]] += l[i]
            d[k[i]] += 1
        m = 0
        for i in range(3):
            m += 10*max(0,d[i]-1)
            if s[i] == 0:
                m = float("inf")
                break
            m += abs(an[i]-s[i])
        if m < ans:
            ans = m
    print(ans)
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    C()


Measured memory_bytes: 60252
def main():
    import sys
    readline = sys.stdin.readline
    # readlines = sys.stdin.readlines
    
    N, W = map(int, input().split())
    item = [tuple(map(int, readline().split())) for _ in range(N)]
    INF = float('inf')
    dp = [-INF] * (W + 1)
    dp[0] = 0
    for i in range(N):
        v, w = item[i]
        for j in range(W + 1 - w):
            dp[j + w] = max(dp[j] + v, dp[j + w])
    
    print(max(dp))


if __name__ == "__main__":
    main()



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

int main() {
  int h, w;
  cin >> h >> w;

  vector<string> a(h);
  for (int i=0; i<h; i++) {
    cin >> a.at(i);
  }

  vector<bool> row(h,false);
  vector<bool> column(w,false);

  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      if (a.at(i).at(j) == '#') {
        row[i] = true;
        column[j] = true;
      }
    }
  }

  for (int i=0; i<h; i++) {
    if (row[i] == true) {
      for (int j=0; j<w; j++) {
         if (column[j] == true) {
           cout << a[i][j];
         }
      }
      cout << endl;
    }
  }

}


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

using namespace std;

int main() {


    int N;

    cin >> N;

    vector<int> v;

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

    int minimum = min(v[0], v[1]);
    int maximum = max(v[0], v[1]);

    for (int i = 2; i < N; i++) {
        maximum = max(maximum, v[i]);
        minimum = min(minimum, v[i]);
    }

    int result = maximum - minimum;

    cout << result << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <cstdlib>
#define rep(i, n) for (int i = 0; i<n; i++)

using namespace std;
typedef long long ll;

int main() {
    vector<int> c1(3), c2(3), c3(3);
    rep(i, 3) cin >> c1[i];
    rep(i, 3) cin >> c2[i];
    rep(i, 3) cin >> c3[i];
    //cout << c1[0] << c2[1] << c3[2] << endl;
    int cnt = 0;
    for(int a1 = 0; a1 < 100; a1++){
        int b1 = c1[0] - a1;
        int b2 = c1[1] - a1;
        int b3 = c1[2] - a1;
        int a2 = c2[0] - b1;
        int a3 = c3[0] - b1;
        if (a2 + b2 == c2[1] && a2 + b3 == c2[2] && a3 + b2 == c3[1] && a3 + b3 == c3[2]){
            cnt++;
            break;
        }
    }
    if (cnt != 0) puts("Yes");
    else puts("No");

}

Measured memory_bytes: 256
#include<stdio.h>

    int main(){
    	int A=0,B=0,C=0,D=0,left=0,right=0;

    	scanf("%d %d %d %d",&A,&B,&C,&D);

    	left=A+B;
    	right=C+D;
    	if(left>right){
                printf("Left\n");
        }
    	else if(left==right){
                printf("Balanced\n");
        }
    	else{
                printf("Right\n");
        }

    	return 0;
    }


Measured memory_bytes: 128
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();
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < k; i++) {
            int d = sc.nextInt();
            for (int j = 0; j < d; j++) {
                int a = sc.nextInt();
                set.add(a);
            }
        }
        System.out.println(n - set.size());
        sc.close();

    }

}


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

int A, B;

int main() {
    cin >> A >> B;
    cout << (A - 1) * (B - 1) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	long long int min = 1000000, max = -1000000, sum = 0;
	int i, n, input;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &input);
		if (input <= min) min = input;
		if (input >= max) max = input;
		sum += input;
	}
	printf("%lld %lld %lld\n", min, max, sum);
	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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

	int n;
	cin >> n;

	vector<int> a(n + 2);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	int sum = 0;
	for (int i = 0; i < a.size() - 1; i++) {
		sum += abs(a[i] - a[i + 1]);
	}

	for (int i = 1; i <= n; i++) {
		int ans = sum
			- abs(a[i - 1] - a[i])
			- abs(a[i] - a[i + 1])
			+ abs(a[i - 1] - a[i + 1]);

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


Measured memory_bytes: 1664
import bisect

N, Q = map(int, input().split())
S = input()
P = [list(map(int, input().split())) for _ in range(Q)]

ss = S.split('AC')
a = []
q = 0
for s in ss:
    q += len(s)
    a.append(q)
    q += 2
a = a[:-1]
if a:
    for q in P:
        p1 = bisect.bisect_left(a, q[0] - 1)
        p2 = bisect.bisect_right(a, q[1] - 2)
        print(p2 - p1)
else:
    for q in P:
        print(0)

Measured memory_bytes: 30724
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
string V="Vacant",Ma="Male",Fe="Female";

int main(){
  int N;cin >> N;
  int U=0,L=N;
  vector<int> T(N+1,0);
  cout << 0 << endl;
  string S;
  cin >> S;
  if(S==V){
    return 0;
  }else if(S==Ma){
    T[0] = 1;
    T[N] = 1;
  }else{
    T[0] = 2;
    T[N] = 2;
  }
  while(true){
    int M = (U+L)/2;
    cout << M << endl;
    cin >> S;
    if(S==V){
      return 0;
    }else if(S==Ma){
      T[M] = 1;
    }else{
      T[M] = 2;
    }
    if((T[U]==T[M]&&(M-U)%2==1)||(T[U]!=T[M]&&(M-U)%2==0)){
      L=M;
    }else{
      U=M;
    }
  }
}

Measured memory_bytes: 1236
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

map<ll,ll> M;
int main(){
  ll N,D[200007],X;
  cin >> N;
  rep(i,N){
    cin >> D[i];
    M[D[i]]++;
  }
  cin >> X;
  rep(i,X){
    ll Y;
    cin >> Y;
    M[Y]--;
    if(M[Y]<0){
      cNO;
      return 0;
    }
  }
  cYES;
}

Measured memory_bytes: 14336
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)


class UnionFind(object):

    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}



N, M = map(int, readline().split())
P = list(map(int, readline().split()))

uf = UnionFind(N)

for _ in range(M):
    x, y = map(int, readline().split())
    x -= 1
    y -= 1
    if uf.find(x) != uf.find(y):
        uf.unite(x, y)

cnt = 0

for i in range(N):
    if uf.find(i) == uf.find(P[i]-1):
        cnt += 1

print(cnt)


Measured memory_bytes: 12512
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#define ll long long
#define fr(i,k,N) for(decltype(N+k) i=k; i<N;i++)
#define rep(i,N) for(decltype(N) i=0; i<N;i++)
#define ALL(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}}
template <class X> void prrr(X test){int f=0;for(auto it:test){cout<<(f++!=0?" ":"")<<it;}cout<<endl;}
template<typename X>
istream&operator>>(istream&i,vector<X>&v){for(X&x:v)i>>x;return i;}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(l, r); // 0 <= l, r <= n-1
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

// return 約数unordered_set 1 <= x <= n
auto divv = [](auto n) {
  unordered_set<decltype(n)> v;
  for(decltype(n) i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.insert(i);
      if(i*i != n) v.insert(n/i);
    }
  }
  return v;
};

// check prime (and n>=2) or not
auto isPrime = [](auto n){
  if(n <= 1) return false;
  for(decltype(n) i = 2; i <= sqrt(n); ++i) {
      if(n % i == 0) {
          return false;
      }
  }
  return true;
};

int main() {
    string s;
    cin>>s;
    if(s == "SUN") pr(7);
    if(s == "MON") pr(6);
    if(s == "TUE") pr(5);
    if(s == "WED") pr(4);
    if(s == "THU") pr(3);
    if(s == "FRI") pr(2);
    if(s == "SAT") pr(1);

}


Measured memory_bytes: 256
import math
        
def combination(n, k):
    return math.factorial(n) // math.factorial(k) // math.factorial(n - k)
            
import collections  
    
n,a,b = map(int,input().split())

t = list(map(int,input().split()))

c = collections.Counter(t)

c = sorted(c.items(), key=lambda x:-x[0])

memo = 0

for k,i in enumerate(c):
    #print(k,i[0],i[1])
    memo += i[1]
    if a<=memo:
        ans = 0
        memo2 = 0
        for j in range(k+1):
            if j != k:
                memo2 += c[j][1]
                ans += c[j][0]*c[j][1]
            else:
                ans += c[j][0]*(a-memo2)
        print(ans/a)
        break
if c[0][1] <= a:  
    print(combination(c[j][1],a-memo2))
else:
    ans1=0
    for l in range(a,min(c[0][1],b)+1):
        ans1 += combination(c[j][1],l)
    print(ans1)

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

using namespace std;

int main () {

  int K;
  cin >> K;

  if (K % 2 == 0) {
    cout << pow(K / 2, 2) << endl;
  } else {
    cout << (K / 2) * ((K / 2) + 1) << endl;
  }
  

  return 0;
}

Measured memory_bytes: 256
//include,namespace
 #include<bits/stdc++.h>
 #include<iostream> 
#include<bitset>
 using namespace std;
//REPmacro
 #define all(x) (x).begin(),(x).end()             //ソート
 #define FOR(i,x,n)for(int i=(x);i<(n);i++)
 #define FOR_R(i,x,n) for(int i=(n-1);i>=(x);i--)
 #define REP(i, n) FOR(i, 0, n)
 #define REP_R(i, n) FOR_R(i, 0, n)
//long long(define)
 using ll = long long;
 typedef long long ll;
 typedef long long int64;
 typedef long long lint;
 typedef long long lli;
////////////////いろいろあるよ//////////////////////////////////
 
int main(){
  int A;
  cin >> A;
  REP(i,A){
    int a;
    cin >> a;
    if(a%2==0&&(a%3!=0&&a%5!=0)){
      cout << "DENIED" << endl;
      return 0;
      }
  }

  
  cout << "APPROVED"<<endl;
  
  
}

Measured memory_bytes: 256
from statistics import mean, median,variance,stdev
import sys
import math
import fractions
def j(a):
    if a==1: print("Yes")
    else :print("No")


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())

x = ip()                              #入力整数1つ
#x,y = (int(i) for i in input().split())      #入力整数横2つ
#x,y,z = (int(i) for i in input().split())    #入力整数横3つ
#a,b,c,k = (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
num = 1
max = 1
for i in range(1,x+1):
    for j in range(2,x+1):
        l = pow(i,j)
        if l>x: break
        elif l > max: max = l
print(max)

Measured memory_bytes: 5084
n = int(input())
li = list(map(int,input().split()))

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

ans = [0]*n
lileft = [0]*(n+1)
liright = [0]*(n+1)
for i in range(n):
  lileft[i+1] = gcd(lileft[i],li[i])
for i in range(n):
  liright[i+1] = gcd(liright[i],li[n-i-1])
for i in range(n):
  ans[i] = gcd(lileft[i],liright[n-i-1])
print(max(ans))

Measured memory_bytes: 14436
n,m=map(int,input().split())
A=[2,5,5,4,5,6,3,7,6]
B=list(map(int,input().split()))
B=sorted(B,reverse=True)
C=[]
for i in range(m):
  C.append(A[B[i]-1])
C=set(C)
C=sorted(list(C))
dp=[-10**10]*(n+10)
dp[0]=0
for i in range(1,n+1):
  for j in range(len(C)):
    if dp[i]<dp[i-C[j]]+1:
      dp[i]=dp[i-C[j]]+1
S=[]
for i in range(dp[n]):
  for j in range(len(B)):
    if dp[n-A[B[j]-1]]==dp[n]-1:
      n=n-A[B[j]-1]
      S.append(B[j])
      break
for i in range(len(S)):
  print(S[i],end="")
print()

Measured memory_bytes: 4300
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

set<ll> divisor(ll n){
    set<ll> s;
    for(ll i = 1; i*i <= n; i++){
        if(n % i == 0){
            s.insert(i);
            s.insert(n/i);
        }
    }
    return s;
}

int main(){
    ll N; cin >> N;
    set<ll> div = divisor(N);
    ll ans = LINF;
    for(ll u : div){
        ans = min(ans,u+N/u-2);
    }
    cout << ans << endl;
}



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

// @author : sam000013

#define int long long

#define PI 3.14159265
#define pb(x) push_back(x)
#define all(v) v.begin(), v.end()
#define endl cout<<"\n" 
#define dbg(x) cout<<#x<<" "<<x;endl;
#define bye endl;return
#define uni 1.000000
using namespace std;

const int mod = 1000000007;
template<typename T>

void debug(vector<T> x){
for(auto e:x){
    cout<<e<<" ";
}
cout<<"\n";
}
/*


*/

void solve(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ans = INT64_MIN;
    ans = max(a*c, ans);
    ans = max(a*d, ans);
    ans = max(b*c, ans);
    ans = max(b*d, ans);
    cout<<ans;bye;
}


signed main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t = 1;
    //cin>>t;
    for(int i=1; i<=t; i++){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3648