akhauriyash/Code-Regression huggingface dataset:
INF = 2**60 # 無限大を表す値
H, N = map(int, input().split())
AB = [map(int, input().split()) for i in range(N)]
dp = [INF] * (H + 1)
dp[0] = 0
for A, B in AB:
    for j in range(H+1):
        dp[j] = min(dp[j], dp[max(j-A, 0)] + B)
print(dp[H])

Measured memory_bytes: 73996
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
kind=Hash.new(0)
N.times do
    kind[gets.chomp]+=1
end
puts "AC x #{kind["AC"]}"
puts "WA x #{kind["WA"]}"
puts "TLE x #{kind["TLE"]}"
puts "RE x #{kind["RE"]}"

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

const int MAXN = 2002;

int main() {
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20);
	ll n, a, b;
	cin >> n >> a >> b;
	if (a > b) {
		cout << 0 << endl;
		return 0;
	}
	if (n == 1) {
		if (a != b) {cout << 0 << endl; return 0;}
	}
	cout << (n - 2) * (b - a) + 1ll;
	return 0;
}

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

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

using namespace std;

int main() {
    int N;
    cin >> N;
    int A,B;
    cin >> A >> B;
    cout << min(N*A,B) << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main() {

    int N, K; cin >> N >> K;
    vector<int> a(N); rep(i,N) cin >> a[i];
    Sort(a);
    int ans = 0;
    rep(i,K) {
        ans += a[i];
    }
    cout << ans << endl;




    return 0;
}









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

int main(void) {
    int n,a,b;
    cin >> n;
    if(n==2) {
        cin >> a >> b;
        cout << a + b << endl;
    } else {
        cout << "Hello World\n" << endl;
    }

    return 0;
}


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

int N;
bool m;
string S;

void check(int ans){
    if(m)N*=-1;
    int val=0;
    int d=10;
    for(int i=0;i<7;i++){
        int x=ans/d%10;
        if(i&1)val-=x*d/10;
        else val+=x*d/10;
    }
    if(val!=N)cout<<N<<endl;
}

void solve(){
    if(N<0)m=true;
    else m=false;
    N=abs(N);
    stringstream ss;ss<<N;ss>>S;
    reverse(S.begin(),S.end());
    vector<int>a(20,0);
    for(int i=0;i<S.size();i++){
        if(m){
            if(i&1){
                a[i]+=S[i]-'0';
            }
            else{
                a[i+1]++;
                a[i]+=10-(S[i]-'0');
            }
        }
        else{
            if(i&1){
                a[i+1]++;
                a[i]+=10-(S[i]-'0');
            }
            else{
                a[i]+=S[i]-'0';
            }
        }
    }


    for(int i=0;i<a.size()-1;i++){
        if(a[i]<0){
            int val=10+a[i];
            a[i+1]++;
            a[i]=val;
        }
        else{
            int val=a[i]/10;
            a[i]%=10;
            a[i+1]-=val;
        }
    }

    reverse(a.begin(),a.end());
    long long ans=0;
    for(int i=0;i<a.size();i++){
        ans=ans*10+a[i];
    }

    cout<<ans<<endl;
}


int main(){
    while(cin>>N,N)solve();
}

Measured memory_bytes: 1224
/**
*    author:  y_takano
*    created: 18.06.2020 15:02:44
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  int i;
  cin >> i;

  cout << i*i*i << "\n";

  return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  map<int, int> mp;
  rep (i, m) {
    int tmp;
    cin >> tmp;
    mp[tmp] = 1;
  }
  int ans;
  int cost = 0;
  rep (i, x) {
    auto itr = mp.find(i);
    if (itr != mp.end()) cost++;
  }
  ans = cost;
  cost = 0;
  for (int i = x; i <= n; i++) {
    auto itr = mp.find(i);
    if (itr != mp.end()) cost++;
  }
  P(min(ans, cost));



  return 0;
}



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

#define int long long

vector<int> g[200001];
auto main() -> signed {
    int n, m;
    cin >> n >> m;

    for(int i=0; i<m; ++i) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
    }

    int ans = false;
    for(int i=0; i<g[1].size(); ++i) {
        int t = g[1][i];
        if(find(g[t].begin(), g[t].end(), n)!=g[t].end()) {
            ans = true;
            break;
        }
    }
    if(ans) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}



Measured memory_bytes: 8832
import sys
from collections import deque
def input(): return sys.stdin.readline().strip()


def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        A.append(list(map(int, input().split())))
    B = []
    for _ in range(H):
        B.append(list(map(int, input().split())))
    
    """
    明らかなdp臭。
        dp[i][j] = (マス(0, 0)から(i, j)に進むときの偏りとしてありうるものの集合)
    とおく。(0<=i<=H-1, 0<=j<=W-1, 0<=d<=80)

    残念ながらPypyだとsetでdp値を保持しているとTLEするので、setではなくビットで偏りの値を管理する
    ただし-diffの方向にビットシフトするとき0桁目以下が切り捨てられてしまうので、最初から適当に
    offsetで桁の水増しをしておく
    """

    offset = 80 * 164

    dp = [[0] * W for _ in range(H)]
    dp[0][0] |= 1 << (A[0][0] - B[0][0] + offset)
    dp[0][0] |= 1 << (B[0][0] - A[0][0] + offset)
    for i in range(1, H):
        diff = abs(A[i][0] - B[i][0])
        dp[i][0] |= dp[i - 1][0] << diff
        dp[i][0] |= dp[i - 1][0] >> diff
    for j in range(1, W):
        diff = abs(A[0][j] - B[0][j])
        dp[0][j] |= dp[0][j - 1] << diff
        dp[0][j] |= dp[0][j - 1] >> diff

    for i in range(1, H):
        for j in range(1, W):
            diff = abs(A[i][j] - B[i][j])
            dp[i][j] |= dp[i - 1][j] << diff
            dp[i][j] |= dp[i - 1][j] >> diff
            dp[i][j] |= dp[i][j - 1] << diff
            dp[i][j] |= dp[i][j - 1] >> diff
    
    ans1 = offset
    while not (dp[H - 1][W - 1] & (1 << ans1)):
        ans1 += 1
    ans2 = offset
    while not (dp[H - 1][W - 1] & (1 << ans2)):
        ans2 -= 1
    print(min(ans1 - offset, offset - ans2))


if __name__ == "__main__":
    main()


Measured memory_bytes: 57180
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"sort"
	"strconv"
)

func main() {
	k, n := readInt(), readInt()
	a := make([]int, n)
	for i := range a {
		a[i] = readInt()
	}
	sort.Ints(a)

	mx := 0
	for i := range a[1:] {
		mx = max(mx, a[i+1]-a[i])
	}
	mx = max(mx, a[0]+k-a[n-1])
	fmt.Println(k - mx)
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <functional>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define mk make_pair

template <class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod = 1e9 + 7;

/*
    if you have any question about any part of my code,
    please don't shy to ask anytime :)
*/

void solve()
{
    ll n;
    cin>>n;
    unordered_map<ll,ll>h, h1;  
    vector<ll>x(n);
    unordered_set<ll>s;
    ll maxi=0;
    for(int i=0;i<n;i++)
    {
        cin>>x[i];
        h[x[i]]++; 
        maxi = max(x[i], maxi);   
    }

    for(int i=0;i<n;i++)
    {
        if(h1[x[i]]==0)
        {
            h1[x[i]] = 1;
            for(int j=x[i]*2;j<=maxi;j+=x[i])
            {
                h1[j] = 2;
            }
        }
    }



    ll ans=0;
    
    for(int i=0;i<n;i++)
    {
        if(h[x[i]]==1 && h1[x[i]]==1)
        {
            //cout<<x[i]<<endl;
            ans++;
        }
    }
    cout<<ans<<endl;
}

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

    // ll t;
    // cin >> t;

    // while (t--)
    // {
    //     solve();
    // }
    solve();
    return 0;
}

Measured memory_bytes: 50580
def func(N):
    tmp=N
    arr=[]
    for i in range(2,int((N**0.5//1))+1):
        if tmp%i==0:
            cnt=0
            while tmp%i==0:
                cnt+=1
                tmp//=i
            arr.append([i,cnt])
            
    if tmp!=1:
        arr.append([tmp, 1])
    if arr==[]:
        arr.append([tmp,1])
   
    return arr

N=int(input())
a=func(N)
ans=0
if a[0][0]==1:
        print(0)
        exit()
        
b=[1,3,6,10,15,21,28,36,45]
for i in a:
    for j in range(len(b)):
       if  i[1]<b[j]:
          ans+=j
          break
print(ans)
    
            

Measured memory_bytes: 9476
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#define rip(i,n) for(int i=0;i<n;i++)
#define ll long long
#define ld long double
#define set setprecision　//小数点以下何位まで知りたいか
#define mod 1000000007
#define pi 3.14159265
#include<numeric>
using namespace std;
int gcd(int a, int b)//最大公約数
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
int lcm(int a, int b)//最小公倍数
{
	return a * b / gcd(a, b);
}
ll pow(ll a, ll b) {
	ll k = b % 30000, h = b / 30000, s = 1;
	rip(i, 30000)s = (s * a) % mod; ll j = 1;
	if (h != 0)rip(i, h)j = j * s % mod;
	if (k != 0)rip(i, k)j = j * a % mod;
	return(j);
}
int  main() {
	ll n;
	cin >> n;
	vector<ll>a(n);
	vector<ll>b(n+1, 0);
	rip(i, n) {
		cin >> a[i];
		b[a[i]]++;
	}
	ll sum = 0;
	for (int i = 1; i <= n; i++) {
		sum += b[i] * (b[i]-1) / 2;
	}
	ll k;
	rip(i, n) {
		k = b[a[i]];
		if (b[a[i]] == 1)cout << sum << endl;
		else cout << sum - (b[a[i]] - 1) << endl;
	}
}


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

int n;
vector<int> G[100005];
vector<int> color(100005, -1);
vector<bool> seen(100005, false);

void dfs(int now, int id){
    seen[now] = true;
    color[now] = id;

    for(int i=0; i<G[now].size(); ++i){
        int to = G[now][i];
        if(!seen[to]) dfs(to, id);
    }
}

int main(){
    
    int m; cin >> n >> m;
    for(int i=0; i<m; ++i){
        int a,b; cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int id = 0;
    for(int i=0; i<n; ++i){
        if(!seen[i]){
            ++id;
            dfs(i, id);
        }
    }

    int q; cin >> q;
    for(int i=0; i<q; ++i){
        int s, t; cin >> s >> t;
        if(color[s] == color[t]) printf("yes\n");
        else printf("no\n");
    }

    return 0;
}


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


template<typename T>
T gcd(T a,T b){
    if(b==0)return a;
    return gcd(b,a%b);
}

template<typename T>
T lcm(T a,T b){
    T d=gcd(a,b);
    return (a/d)*b;
}

using namespace std;
using ll = long long;

int main() {
    ll x;
    cin>>x;
    ll ans;
    cout<<lcm(x,360)/x<<endl;
    return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define res register int
#define N 100005
using namespace std;
int n,d[N],tot,a[N],ans,k,f[N];
inline int read(){
	res X=0,w=0;register char ch=0;
	while(!isdigit(ch)){w|ch=='-';ch=getchar();}
	while(isdigit(ch)){X=(X<<1)+(X<<3)+(ch^48);ch=getchar();}
	return w?-X:X;
}
struct papa{
	int to,next;
}e[N];
inline void add(res x,res y){
	e[++tot].to=y;
	e[tot].next=d[x];
	d[x]=tot;
}
inline void dfs(res now){
	f[now]=0;
	for(res i=d[now];i;i=e[i].next){
		res x=e[i].to;
		dfs(x);
		f[now]=max(f[now],f[x]+1);
	}
	if(f[now]==k-1&&a[now]!=1){
		ans++;
		f[now]=-1;
	}
}
int main(){
	n=read(),k=read();
	a[1]=read();
	for(res i=2;i<=n;i++){
		a[i]=read();
		add(a[i],i);
	}
	if(a[1]!=1){
		ans++;
		a[1]=1;
	}
	dfs(1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4096
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N = II()
    A = []
    X = []
    Y = []
    testimony = []
    for i in range(N):
        testimony.append(XLMIIS(II()))

    def check(history):
        if len(history) < N:
            return max(check(history+[0]),check(history+[1]))
        
        for i,h in enumerate(history):
            if h == 1:
                for x,y in testimony[i]:
                    if history[x-1] != y:
                        return -1
        
        return sum(history)
        
    print(max(check([0]),check([1])))




if __name__ == '__main__':
    main()


Measured memory_bytes: 52696
#include<bits/stdc++.h>
#define int long long int
using namespace std;
#define pb push_back
#define MAX 200005
int par[MAX];
int sz[MAX];
void init()
{
	for(int i=0;i<MAX;i++){
		par[i]=i;
		sz[i]=1;
	}
}
int parent(int x)
{
	if(par[x]==x)	return x;
	par[x]=parent(par[x]);
	return par[x];
}
void unionxy(int x,int y)
{
	int px=parent(x);
	int py=parent(y);
	if(px==py)	return;
	par[py]=px;
	sz[px]+=sz[py];
}


int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	int n,m;
	cin >> n >> m;
	int t=m;
	init();
	while(t--){
		int x,y;
		cin >> x >> y;
		unionxy(x,y);
	}
	int ans=1;
	for(int i=1;i<=n;i++){
		if(i==parent(i)){
			ans=max(ans,sz[i]);
		}
	}
	cout << ans << endl;



	return 0;
}


Measured memory_bytes: 7496
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	vector<vector<ll>>V;
	vector<ll>a(3,0);
	vector<ll>b(3,0);
	rep(i,3){
		vector<ll>v;
		rep(j,3){
			ll t;
			cin>>t;
			v.push_back(t);
		}
		V.push_back(v);
	}
	for(int i=0;i<=2;i++){
		a[0]=i;
		b[0]=V[0][0]-a[0];
		b[1]=V[0][1]-a[0];
		b[2]=V[0][2]-a[0];
		a[1]=V[1][0]-b[0];
		a[2]=V[2][0]-b[0];
		if(V[0][0]==a[0]+b[0]&&V[0][1]==a[0]+b[1]&&V[0][2]==a[0]+b[2]
			&&V[1][0]==a[1]+b[0]&&V[1][1]==a[1]+b[1]&&V[1][2]==a[1]+b[2]
			&&V[2][0]==a[2]+b[0]&&V[2][1]==a[2]+b[1]&&V[2][2]==a[2]+b[2]
		){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}

Measured memory_bytes: 256
n,x=map(int,input().split())
a=list(input().split())
count=0
d=0
i=0

while d<=x:
    if i==0:
        d=0
        count=1
        i+=1
    elif count<=n+1 and i<n+1:
        d=d+int(a[i-1])
        if d<=x:
            count+=1
            i+=1
        else:
            break;
    else:  
        break;
print(count)

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

int main(){
    long long a=1000,b,n,p,x,ans=1000;
    scanf("%lld",&n);
    for (long long i=1;i<100001;i++) {
        if (n%i==0) {
            a=1;
            b=1;
            p=max(i,n/i);
            for (long long j=1;j<12;j++)  {
                if (p/b>0) a=j;
                b*=10;
            }
            ans=min(ans,a);
        }
    }
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std;

int main()
{
  	int N;
  	cin >> N;
  
  	int nWatch = 0;
  	vector<int> Hotels;
  	for(int i = 0; i < N; ++ i)
    {
      	bool canWatch = true;
      	int nHigh;
      	cin >> nHigh;
      
      	for( int j = 0; j < i; ++ j)
        {
        	if(nHigh < Hotels[j])
            {
            	canWatch = false;
              	break;
            }
        }
      
      	if(canWatch)
          ++nWatch;
      	
      	Hotels.push_back(nHigh);
    }
  
  	cout << nWatch;
	return 0;
}

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

using namespace std;
using ll = long long;
using pii = std::pair<int, int>;

#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb push_back
const int mn = 1e6 + 5;
int n, k;
int a[mn];
ll s[mn];
vector<ll> b;

int main() {
#ifdef trote
    freopen("../1.txt", "r", stdin);
#endif
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]), s[i] = s[i - 1] + a[i];
    for (int l = 0; l <= n; l++) {
        for (int r = l + 1; r <= n; r++) {
            b.pb(s[r] - s[l]);
        }
    }
    //printf("%d\n", sz(b));
    ll ans = 0;
    for (int i = 50; i >= 0; i--) {
        vector<ll> t;
        for (auto &v:b) {
            if (v & (1ll << i)) {
                t.pb(v);
            }
        }
        if (sz(t) >= k) {
            swap(b, t);
            ans |= (1ll << i);
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 8432
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N, K;
	in >> N >> K;
	std::vector<LL>A(N);
	rep(i, N) in >> A[i];

	LL ans = 0;
	rep(i, N) ans += K ^ A[i];
	rep(i, 61)
	{
		if (K&(1LL << i))
		{
			LL res = 0;
			std::bitset<60>X = K;
			X[i] = 0;
			for (LL j = i - 1; j >= 0; --j)
			{
				LL cnt = 0;
				rep(k, N)
				{
					if (A[k] & (1LL << j)) ++cnt;
				}
				if (cnt < N - cnt) X[j] = 1;
				else X[j] = 0;
			}
			rep(j, N) res += X.to_ullong() ^ A[j];
			ans = std::max(ans, res);
		}
	}

	out << ans << std::endl;
}


Measured memory_bytes: 1024
def main():
    H, N = map(int, input().split())
    A = [0] * N
    B = [0] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())

    dp = [float('inf')] * (H + 5)
    dp[0] = 0
    for i in range(H+1):
        for j in range(N):
            if i + A[j] >= H:
                dp[H] = min(dp[H], dp[i] + B[j])
            else:    
                dp[i + A[j]] = min(dp[i + A[j]], dp[i] + B[j])
    ans = dp[H]

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 42716
#include<bits/stdc++.h>
using namespace std;
int main(){
	//freopen("input.txt","r",stdin);
	ios_base::sync_with_stdio(false); cin.tie(NULL);
     long a; string b;
     cin>>a>>b;
     long ans=0;
     if(a%2==0){
     	for(int i=0; i<a/2; i++){
     		if(b[i]==b[i+a/2]){
     			
			}else{
				ans++;
			}
		}
     	
     	if(ans==0){
     		cout<<"Yes";
		}else{
      cout<<"No";
    }
     	
     	
	}else{
		cout<<"No";
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

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; }
const ll INF = 1e9;
const long long INFL = 1LL<<60;


int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  ll n_odd = 0;
  rep(i, n) {
    cin >> a[i];
    if (a[i] % 2 != 0) n_odd++;
  }

  if (n_odd != 0) {
    cout << "first" << endl;
  } else {
    cout << "second" << endl;
  }

  return 0;
}


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

def main():
    s = input().strip()

    ok = True
    for i in range(len(s)):
        if i&1:
            if s[i] == "R":
                ok = False
                break
        else:
            if s[i] == "L":
                ok = False
                break
    
    if ok:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func readFloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	k := readInt()
	sum := 0
	for a := 1; a <= k; a++ {
		for b := 1; b <= k; b++ {
			for c := 1; c <= k; c++ {
				sum += gcd(gcd(a, b), c)
			}
		}
	}
	fmt.Println(sum)
}

func gcd(a, b int) int {
	if b > a {
		b, a = a, b
	}
	r := a % b
	for r != 0 {
		a = b
		b = r
		r = a % b
	}
	return b
}


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

double line(double x,double x1,double y1,double x2,double y2){
	return (y1-y2)/(x1-x2)*(x-x1)+y1;
}

int main(){
	double x1,x2,y1,y2,x3,y3,x4,y4;

	while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4)!=EOF){
		if((line(x2,x1,y1,x3,y3)-y2)*(line(x4,x1,y1,x3,y3)-y4)>0 || (line(x1,x2,y2,x4,y4)-y1)*(line(x3,x2,y2,x4,y4)-y3)>0){
			cout<<"NO"<<endl;
		}else{
			cout<<"YES"<<endl;
		}
	}

	return 0;
}

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

using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n); i > 0; i--)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl

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

    ll n;
    cin >> n;
    vector<ll> a(n), b(n+1);
    rep(i,n){
        cin >> a[i];
        b[a[i]]++;
    }
    ll sum = 0;
    rep(i,n+1) if(b[i]>=2) sum += b[i] * (b[i]-1) / 2;
    ll ans;
    rep(i,n){
        ans = sum;
        if(b[a[i]] >= 2) ans -= b[a[i]]-1;
        print(ans);
    }
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long int64;
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;

int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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 (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

void solve() {
		int n; cin >> n;
		vector<double> a(n);
		rep (i, n) {
			cin >> a[i];
		}
		double sum = 0.0;
		rep (i, n) {
			sum += (1 / a[i]);
		}
		double ans = (1 / sum);
		printf("%.15f\n", ans);
    return;
}

int main() {
    solve();
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define rep(n) for(int i=0; i<n; i++)
#define v(n) vector<n>
using namespace std;
signed main(){
    string s; cin>>s;
    v(bool) al(26,false);
    rep(s.size()){
        if(al.at(s.at(i)-'a')){
            cout<<"no"<<endl; return 0;
        }else{
            al.at(s.at(i)-'a')=true;
        }
    }
    cout<<"yes"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
  long long x , y;
  int count = 1;
  cin >> x >> y;
  while(true){
    x *= 2;
    if(x <= y){
      count +=1;
    } else {
      break;
    }
  }
  cout  << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=105;
int a[N];
priority_queue<int,vector <int>,greater<int>  > que;
int vis[N];

int main()
{
    int n,sk;
    scanf("%d%d",&n,&sk);
    for(int i=1; i<=n; i++)
        scanf("%d",&a[i]);

    int ans=0;
    for(int i=0; i<=sk; i++)
    {
        for(int j=0; j<=sk; j++)
        {
            if(i+j==0)
                continue;
            if(i+j>sk)
                continue;
            if(i+j<sk-i-j)
                continue;
            memset(vis,0,sizeof(vis));

            int k=1;
            int tmp=i;
            while(tmp--&&k<=n)
            {
                if(vis[k]==1)
                    break;
                vis[k]=1;
                que.push(a[k]);
                k++;
            }

            k=n;
            tmp=j;
            while(tmp--&&k>=1)
            {
                if(vis[k]==1)
                    break;
                vis[k]=1;
                que.push(a[k]);
                k--;

            }
            //printf("+%d %d %d\n",sk , i ,j);
            int res=sk-i-j;
            while(!que.empty()&&res--&&que.top()<0)
                que.pop();
            int dh=0;
            while(!que.empty())
            {
                //printf("%d\n",que.top());
                dh+=que.top();
                que.pop();
            }
            ans=max(dh,ans);
            //printf("ans=%d %d %d %d\n",ans,i,j,sk-i-j);
        }
    }
    printf("%d\n",ans);
    //cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
const ll INF = 1LL << 60;

int main(){
	int a, b, c; cin >> a >> b >> c;
	if(b-a == c-b) puts("YES");
	else puts("NO");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
string s;
int main()
{
	cin>>s;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='?')s[i]='D';
	}
	cout<<s<<endl;
	return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL s;
set<LL> se;

int main() {
	cin >> s;
	
	while(true) {
		if(se.count(s) != 0) {  cout << se.size() + 1 << endl; return 0; }
		
		se.insert(s);
		s = (s % 2 == 0 ? s / 2 : 3 * s + 1);
	}
	
}


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

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N, b, A[3][3];
	bool ans = false, f[3][3];

	rep(i, 3) rep(j, 3) f[i][j] = false;
	rep(i, 3) rep(j, 3) cin >> A[i][j];

	cin >> N;
	rep(loop, N) {
		cin >> b;
		rep(i, 3) rep(j, 3) {
			if (A[i][j] == b) f[i][j] = true;
		}
	}

	rep(i, 3) {
		if (f[i][0] && f[i][1] && f[i][2]) ans = true;
		if (f[0][i] && f[1][i] && f[2][i]) ans = true;
	}

	if (f[0][0] && f[1][1] && f[2][2]) ans = true;
	if (f[0][2] && f[1][1] && f[2][0]) ans = true;

	cout << (ans ? "Yes" : "No") << endl;

	return 0;
}


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

int main() {
    int n;
    long long count = 0;
    cin >> n;
    for ( int i = 1; i <= n; i++) {
        if (i % 3 == 0 || i % 5 == 0);
        else count += i;
    }
    cout << count << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include<iomanip>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <queue>
#include <stack>
using namespace std;

const int NN=1e5+10;

int n;
int a[NN];
int b[NN];
int ans[NN];



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

    int flagg=0;
    long long ans1=0;
    long long sum1=0;
    long long ans2=0;
    long long sum2=0;


    if(a[0]>0){
        ans2=ans2+abs(b[0]+1);
        b[0]=-1;
    }
    else if(a[0]==0){
        a[0]+=1;
        ans1+=1;

        b[0]-=1;
        ans2+=1;
    }
    else{
        ans1=ans1+abs(1-a[0]);
        a[0]=1;
    }
    sum1+=a[0];
    sum2+=b[0];

        bool flag=true;
        //flag=true >0
        //flag=false <0
        for(int i=1;i<n;i++){
            sum1+=a[i];
            if(flag){
                if(sum1>0){
                    ans1+=abs(-1-sum1);
                    sum1=-1;
                }
                else if(sum1==0){
                    sum1=sum1-1;
                    ans1=ans1+1;
                }
            }
            else{//<0
                if(sum1<0){
                    ans1+=abs(1-sum1);
                    sum1=1;
                }
                else if(sum1==0){
                    sum1=1;
                    ans1+=1;
                }
            }
            flag=!flag;
        }

        flag=false;
        for(int i=1;i<n;i++){
            sum2+=b[i];
            if(flag){
                if(sum2>0){
                    ans2+=abs(-1-sum2);
                    sum2=-1;
                }
                else if(sum2==0){
                    sum2=sum2-1;
                    ans2=ans2+1;
                }
            }
            else{//<0
                if(sum2<0){
                    ans2+=abs(1-sum2);
                    sum2=1;
                }
                else if(sum2==0){
                    sum2=1;
                    ans2+=1;
                }
            }
            flag=!flag;
        }

    printf("%lld\n",min(ans1,ans2));
}





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

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		long X = Long.parseLong(strArr[0]);
		double n = Math.floor((Math.sqrt(1 + 8 * X) - 1.0) / 2);
		long ans = (long) n;
		for (; ans * (ans + 1) / 2 < X;) {
			ans++;
		}
		System.out.println(ans);

		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}
}


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

using namespace std;

long long ans=0,N;

long long dfs(long long n,int san,int go,int nana){
    if(N<n){
        return 0;
    }else{
        if(san&&go&&nana){
            ans++;
        }
        dfs(n*10+3,1,go,nana);
        dfs(n*10+5,san,1,nana);
        dfs(n*10+7,san,go,1);
    }
    return 0;
}

int main(){
    cin >> N;
    dfs(0,0,0,0);
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main implements Runnable { //Runnableを実装する
    public static void main(String[] args) {
        new Thread(null, new Main(), "", 16 * 1024 * 1024).start(); //16MBスタックを確保して実行
    }

    public void run() {
        //ここに処理を書く
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int[]s = {a,b,c};
        Arrays.sort(s);
        System.out.println(s[2]*10+s[1]+s[0]);
    }
}


Measured memory_bytes: 22996
#include<iostream>
#include<algorithm>
using namespace std;
static const int N = 100;


int main() {
	int n;
	cin >> n;
	int p[N],m[N+1][N+1];
	for (int i = 1;i <= n;i++) {
		cin >> p[i - 1] >> p[i];
	}
	for (int i = 0;i <= n;i++) {
		m[i][i] = 0;
	}
	for (int l = 2;l <= n;l++) {
		for (int i = 1;i <= n - l + 1;i++) {
			int j = i + l - 1;
			m[i][j] = (1 << 21);
			for (int k = i;k <= j - 1;k++) {
				m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}
	cout << m[1][n] << endl;
	return 0;
}



Measured memory_bytes: 3144
using System;
using System.Linq;

namespace AtCoder3005
{
	class Program
	{
		static void Main(string[] args)
		{
			A();
		}

		static void A()
		{
			var ints = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList();
			var h1 = ints[0];
			var m1 = ints[1];
			var h2 = ints[2];
			var m2 = ints[3];
			var k = ints[4];

			var start = 60 * h1 + m1;
			var end = 60 * h2 + m2;
			if (end < start)
				end += 1440;

			var diff = end - start;
			Console.WriteLine(diff - k);
		}
	}
}


Measured memory_bytes: 28308
/*  ---------------  Copyrighted With ciphereck -----------------*/

#include<bits/stdc++.h>
using namespace std;

/* ----------------------------- START of Template ---------------*/
#pragma GCC optimize ("-ffloat-store")  // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop") // to pop argument of function as soon as it returns
#define ll long long
#define pb push_back
#define fs first
#define se second
#define rd(x) scanf("%lld", &x)
#define all(v) v.begin(),v.end()
#define pr(i, j) pair< i , j >
#define mp(i, j) map< i , j >
#define rep(i, a, b) for(ll i=a; i<b; ++i)
#define repe(i, a, b) for(ll i=a; i<=b; ++i)
#define jrep(i, a, b, c) for(ll i=a; i<b; i+=c)
#define jrepe(i, a, b, c) for(ll i=a;i<=b; i+=c)
#define inp(i, n, a) for(ll i=0;i<n;i++) cin>>a[i];
ll dx[4]={-1, 0, 0, +1};
ll dy[4]={0, -1, +1, 0};
const ll LINF = 1e18;
const ll INF = 1e9;
const ll MOD = 1e9+7;

ll strtoll(string s) { stringstream str(s); ll number=0; str>>number; return number; }

string lltostr(ll n){ stringstream ss; ss<<n; return ss.str(); }


ll llsqrt(ll x){ if(x==0 || x==1) return x; ll start=1, end=x/2, ans; while(start<=end) { ll mid=(start+end)/2; if(mid*mid==x) return mid;
        else if(mid <= x/mid) ans=mid,start=mid+1; else end=mid-1; }  return ans; }

vector<ll> spf;
void sieve(ll size) { spf.resize(size+1); for(ll i=1;i<=size; ++i) spf[i]=i; for(ll i=4;i<=size; i+=2) spf[i]=2;
    for(ll i=3;i*i<=size; ++i) { if(spf[i]==i) { for(ll j=i*i; j<=size; j+=i) if(spf[j]==j) spf[j]=i; } } }

ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m); t=(t*t)%m; if(b&1)t=(t*a)%m; return t;}


ll modInverse(ll a, ll m) { return power(a, m-2, m); }

void fastscan(ll &number){ bool negative = false; register ll c; number = 0; c = getchar(); if (c=='-') { negative = true; c = getchar(); }
    for (; (c>47 && c<58); c=getchar()) number = number *10 + c - 48; if (negative)  number *= -1;   }


/* ----------------------          End Of Template --------------------------------*/



int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
   clock_t tStart = clock();

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

   ll n;
   cin>>n;
   ll x=(n+998)/999;
   if(n>999) cout<<"ABD";
   else cout<<"ABC";

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

   // printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func permutation(n int, k int) int {
	v := 1
	if 0 < k && k <= n {
		for i := 0; i < k; i++ {
			v *= (n - i)
		}
	} else if k > n {
		v = 0
	}
	return v
}

func factorial(n int) int {
	return permutation(n, n-1)
}

func main() {
	// Code for C - Average Length
	var N int
	fmt.Scanf("%d", &N)

	x := make([]int, N)
	y := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d %d", &x[i], &y[i])
	}

	a := make([]int, 0)
	for i := 0; i < N; i++ {
		a = append(a, i+1)
	}

	var ans float64
	for i := 0; i < N-1; i++ {
		ans += math.Sqrt(float64((x[a[i+1]-1]-x[a[i]-1])*(x[a[i+1]-1]-x[a[i]-1])) + float64((y[a[i+1]-1]-y[a[i]-1])*(y[a[i+1]-1]-y[a[i]-1])))
	}

	var n = len(a) - 1
	var i, j int
	for count := 2; count <= factorial(len(a)); count++ {
		i = n - 1
		j = n
		for a[i] > a[i+1] {
			i--
		}
		for a[j] < a[i] {
			j--
		}
		a[i], a[j] = a[j], a[i]
		j = n
		i++
		for i < j {
			a[i], a[j] = a[j], a[i]
			i++
			j--
		}

		//---start
		for k := 0; k < N-1; k++ {
			ans += math.Sqrt(float64((x[a[k+1]-1]-x[a[k]-1])*(x[a[k+1]-1]-x[a[k]-1])) + float64((y[a[k+1]-1]-y[a[k]-1])*(y[a[k+1]-1]-y[a[k]-1])))
		}
		//---end
	}

	fmt.Println(ans / float64(factorial(len(a))))
}


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

typedef long long ll;

int main() {
    ll x,y;cin>>x>>y;
    ll ans = 0;
    ll xa = abs(x);
    ll ya = abs(y);
    
    ans += abs(ya - xa);
    
    if(x >= 0 && y >= 0 && x < y)ans+=0;
    else if(x > 0 && y > 0 && x > y)ans+=2;
    else if(x < 0 && y <= 0 && x < y)ans+=0;
    else if(x < 0 && y < 0 && x > y)ans+=2;
    else ans+=1;
    
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define N 100

int v[N + 1][N + 1];

int main()
{
    int n;
    std::cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= n; ++j)
        {
            v[i][j] = 0;
        }
    }
    for (int i = 0; i < n; ++i)
    {
        int u, k;
        std::cin >> u >> k;
        for (int j = 0; j < k; ++j)
        {
            int t;
            std::cin >> t;
            v[u][t] = 1;
        }
    }
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= n; ++j)
        {
            if (j > 1)
            {
                std::cout<<' ';
            }
            std::cout << v[i][j];
        }
        std::cout << "\n";
    }
}


Measured memory_bytes: 3096
import sys
input = sys.stdin.readline
ri = lambda: int(input())
#rl = lambda: [int(x) if x.isdecimal() else x for x in input().split()]
#rl = lambda: list(input().split()))
rl = lambda: map(int,input().split())
rr = lambda N: [list(l) for l in zip(*[rl() for _ in range(N)])]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD = 10**9+7

S=input()
ans = 1
for i in range(3):
    if S[i] == S[i+1]:
        ans = 0
a = ['Bad','Good']
print(a[ans])

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

int main() {
	string Sa, Sb, Sc;
	cin >> Sa >> Sb >> Sc;

	int lena = Sa.length();
	int lenb = Sb.length();
	int lenc = Sc.length();
	
	int cnta = 0, cntb = 0, cntc = 0;

	char nextp = 'a';

	while (1) {
		if (nextp == 'a') {
			if (cnta >= lena) { cout << "A" << endl; return 0; }
			nextp = Sa[cnta];
			cnta++;
		}
		else if (nextp == 'b') {
			if (cntb >= lenb) { cout << "B" << endl; return 0; }
			nextp = Sb[cntb];
			cntb++;
		}
		else if (nextp == 'c') {
			if (cntc >= lenc) { cout << "C" << endl; return 0; }
			nextp = Sc[cntc];
			cntc++;
		}

		
	}

	return 0;
}

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

const int INF = 1 << 30;

int main() {
    // Debug::set_INF(INF);
    int S, W;  cin >> S >> W;
    // DUMP(S, W);
    cout << (S <= W ? "unsafe" : "safe") << endl;
}


Measured memory_bytes: 3636
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

c = []
m = 0
ans = 0
for i in range(n):
    if a[i] < b[i]:
        m += b[i] - a[i]
        ans += 1
    elif a[i] > b[i]:
        c.append(a[i] - b[i])

if m == 0:
    print(0)
    exit()

c.sort(reverse = True)
# print(m, c)
tol = 0
for i in range(len(c)):
    tol += c[i]
    ans += 1
    if m <= tol:
        print(ans)
        break
else:
    print(-1)

Measured memory_bytes: 18708
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

import numpy as np

def solve():
    n = II()
    A = np.array(LI())
    # print([bin(a) for a in A])
    mod = 1000000007
    ans = 0
    for i in range(0, 61):
        # i桁目が1の個数を数える
        x = np.count_nonzero((A >> i) & 1)
        y = n - x       # i桁目が0の個数
        # print(i, x, y)
        # XORなので x*y 通りの組み合わせ
        ans = ans + pow(2, i) * x * y % mod
        # A = A >> 1
    print(ans % mod)



if __name__ == '__main__':
    solve()


Measured memory_bytes: 48860
#include <cstdio>
using namespace std;

#define REP(i, stop) for (int i = 0, i##_len = stop; i < i##_len; ++i)

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getc() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int read() {
	int r = 0;
	if (ci - cn + 16 > cm) while ((ct = getc()) & 16) r = r * 10 + ct - '0';
	else while ((ct = *ci++) & 16) r = r * 10 + ct - '0';
	return r;
}

// x shoud be greater than or equal to zero
inline void write(int x) {
	char d[6];
	int i = 0;
	while (true) {
		d[i] = x % 10 + 48;
		x /= 10;
		++i;
		if (x <= 0) break;
	}
	while (i--) {
		putchar(d[i]);
	}
}

int A[200000];
signed main() {
	int n = read();
	int m0 = 0;
	int m1 = 0;
	REP(i, n) {
		int a = read();
		if (a > m0) {
			m1 = m0;
			m0 = a;
		} else if (a > m1) {
			m1 = a;
		}
		A[i] = a;
	}
	REP(i, n) {
		int a = A[i];
		if (a == m0) {
			write(m1);
		} else {
			write(m0);
		}
		putchar('\n');
	}
}


Measured memory_bytes: 2432
x, y = map(int, input().split())
c = [0] * 206
c[1] = 300000
c[2] = 200000
c[3] = 100000
ans = c[x] + c[y]
if x == 1 and y == 1:
    print(ans + 400000)
else:
    print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

vector<ll> divisor_list(ll n){
    vector<ll> ans;
    for(ll i=1; i*i<=n; i++){
        if(n%i==0){
            ll tmp = n/i;
            ans.push_back(tmp);
            ans.push_back(i);
        }
    }

    return ans;
}


int main() {
    ll n;
    cin >> n;
    vector<ll> res = divisor_list(n);
    int m = res.size();
    int ans = to_string(res[m-2]).length();
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256