akhauriyash/Code-Regression huggingface dataset:
n,k=map(int,input().split())
P=list(map(int,input().split()))
K=[]

DP=[0]*1001
for i in P:
    if DP[i]==0:
        DP[i]=(i*(i+1)//2)/i
    K.append(DP[i])

K.append(0)
ans=sum(K[:k])
score=sum(K[:k])
for i in range(n-k+1):
    score -=K[i]
    score +=K[i+k]
    ans=max(ans,score)
print(ans)

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

#define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (long long )(9e18)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii >

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){
    cerr << name << " = " << arg1 << endl;
}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args){
    const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);
}
template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2> &q){ 
    in >> q.F >> q.S; return in;
}
template<typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> &q){
    out << q.F << " " << q.S; return out;
}
template< typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F+p2.F, p1.S+p2.S};
}
template< typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F-p2.F, p1.S-p2.S};
}

void solve() {
    double a, b, pi = acos(-1);
    cin >> a >> b;
    double h, m;
    cin >> h >> m;
    m = h*60+m;
    double ra = m/2;
    double rb = m*6;
    while(ra > 360)ra -= 360;
    while(rb > 360)rb -= 360;
    double ang = abs(ra-rb);
    ang = cos(ang*pi/180.0);
    cout << pow(a*a+b*b-2*ang*a*b, 0.5);
}

signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   

    int t = 1;
    start = clock(); 

    cout << fixed << setprecision(20);

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin); 
    // freopen("output.txt", "w", stdout);
    // freopen("error.txt", "w", stderr);
    // #endif
   
    //cin >> t;
    
    for(int i = 1; i <= t; ++i){
        //cout << "Case #" << i << ": "; 
        solve();
        //cout << endl;
    }
    //cerr << time(start);
    return 0;
}


Measured memory_bytes: 4372
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    if n < 1000:
        return 'ABC'

    return 'ABD'


print(main())



Measured memory_bytes: 7876
import java.util.Scanner;

public class Main {

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

        StringBuffer sb = new StringBuffer();
        for (int i=X-K+1;i<X+K;i++) {
            sb.append(i);
            if (i != X+K-1) sb.append(" ");
        }
        String ans = sb.toString();
        System.out.println(ans);
    }
}


Measured memory_bytes: 23892
n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
mod = int(1e9) + 7
S = 0
for i in range(n):
  S += (2*i+1-n)*x[i]
  S %= mod
T = 0
for j in range(m):
  T += (2*j+1-m)*y[j]
  T %= mod
print(S*T%mod)

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

int main(){
  char ans[32];
  int n;
  cin >> n;

  for(int i = 0; i < 32; i++){
    int rem = n % 2;
    if(rem == 0){
      ans[31-i] = '0';
    }
    else if(rem < 0){
      ans[31-i] = '1';
      n -= 1;
    }
    else{
      ans[31-i] = '1';
      n -= 1;
    }
    n /= -2;
  }

  int f = 0;
  for(int i = 0; i < 32; i++){
    if(i == 31 && ans[i] != '1' && !f){
      cout << '0' << endl;
      return 0;
    }
    if(ans[i] == '1'){
      cout << ans[i];
      f = 1;
    }
    else if(f){
      cout << ans[i];
    }
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
using namespace std;
map < int , int > mp;
vector < int > all;
int N;
int main() {
	cin >> N;
	for(int i = 0 ; i < N; ++i)
	{
		int x;
		cin >> x;
		if(mp.find(x)!=mp.end())
		{
			mp[x]+=1;
		}else{
			mp[x]=1;
			all.push_back(x);
		}
	}
	int ret=0;
	for(int i =0 ;i < all.size(); ++i)
	{
		int x = all[i];
		int cnt = mp[x];
		if(cnt < x)
		ret+=cnt;
		else if(cnt > x)
			ret+=(cnt-x);
	}
	cout << ret << endl;
	// your code goes here
	return 0;
}

Measured memory_bytes: 5112
from collections import Counter


N, M = [int(elem) for elem in input().split(' ')]
A_list = [int(elem) % M for elem in input().split(' ')]
assert len(A_list) == N

cuml_A_list = [0] * N
current_sum = 0
for i, A in enumerate(A_list):
    current_sum += A
    current_sum %= M
    cuml_A_list[i] = current_sum

counter = Counter(cuml_A_list)
total_count = 0
for key, value in counter.items():
    if key == 0:
        total_count += value * (value - 1) // 2 + value
    else:
        total_count += value * (value - 1) // 2

print(total_count)


Measured memory_bytes: 16596
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int h,w;

    cin >> h >> w;
    string s[55];
    for (int i = 0; i < h; i++){
        cin >> s[i];
    }

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

    bool can = true;
    for (int i = 0; i < h; i++){
        for (int k = 0; k < w; k++){
            if (s[i][k] != '#'){
                continue;
            }
            int cnt = 0;
            bool found = false;
            for (int p = 0; p < 4; p++){
                const int x = k + dx[p];
                const int y = i + dy[p];
                if (x >= 0 && x < w && y >= 0 && y < h){
                    if (s[y][x] == '#'){
                        found = true;
                    }
                }
            }
            if (found != true){
                cout << "No" << endl;
                exit(0);
            }
        }
    }

    cout << "Yes" << endl;
    /*if (can) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    */
}


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

int main(){
  int n,m,l,r,lmax=0,rmin=1e5;cin>>n>>m;
  REP(i,m){
    cin>>l>>r;
    lmax=max(lmax,l);
    rmin=min(rmin,r);
  }
  cout<<max(0,rmin-lmax+1);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    int x, y; std::cin >> x >> y;
    if( (y-2*x)%2==0 && (4*x-y)%2==0 && (y-2*x)>=0 && (4*x-y)>=0 ){
        std::cout << "Yes";
    }else{
        std::cout << "No";
    }
    return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll w,h;
    cin >> w >> h;
    ll tate = h + 1;
    ll yoko = w + 1;
    vector<pair<ll,ll>> pq;
    rep(i,w){
        ll p;
        cin >> p;
        pq.emplace_back(p, 0);
    }
    rep(i,h){
        ll q;
        cin >> q;
        pq.emplace_back(q, 1);
    }
    sort(all(pq));
    ll spare = (h + 1)*(w + 1) - 1;
    ll ans = 0;
    i = 0;
    while(spare){
        auto x = pq.at(i);
        ll num = x.first;
        ll flag = x.second;
        if(flag == 0){
            ans += num*tate;
            --yoko;
            spare -= tate;
        }else{
            ans += num*yoko;
            --tate;
            spare -= yoko;
        }
        ++i;
    }
    cout << ans << endl;

    return 0;
}

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

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

using namespace std;

int main(){
	int n; scanf("%d",&n);
	set<string> S;
	rep(i,n){
		string s; cin>>s;
		S.emplace(s);
	}
	cout<<S.size()<<'\n';
	return 0;
}


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

typedef long long ll;
const int mod = 1e9 + 7;

ll fastpow(ll b,ll e)
{
	if (e == 0)return 1;
	ll x = fastpow(b, e / 2);
	x = x * x % mod;
	if (e % 2)x =x*b%mod;
	return x;
}


int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	ll ans = fastpow(2, n) - 1;
	ll ret = 1;
	for (int i = 0; i < a; i++) {
		ret *= 1LL*(n - i) * fastpow(i + 1, mod - 2) % mod;
		ret %= mod;
	}
	ans -= ret;
	ret = 1;
	for (int i = 0; i < b; i++) {
		ret *= 1LL*(n - i) * fastpow(i + 1, mod - 2) % mod;
		ret %= mod;
	}
	ans -= ret;
	ans = (ans % mod + mod) % mod;
	cout << ans;

}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    var fiveCount = 0
    var sevenCount = 0

    for (i in 0..2) {
        val value = scanner.nextInt()
        if (value == 5) {
            fiveCount++;
        } else if (value == 7) {
            sevenCount++
        } else {
            print("NO")
            return
        }
    }
    if (fiveCount == 2 && sevenCount == 1) {
        print("YES")
    } else {
        print("NO")
    }
}

Measured memory_bytes: 36324
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
const int mod = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vl t(n);
    cin >> t;
    ll ans = 1;
    rep(i,n) ans = ans/::gcd(ans,t[i])*t[i];
    cout << ans << endl;
}


Measured memory_bytes: 256
x,k,d = map(int,input().split())
if x == 0:
    if k%2 == 0:
        print(0)
    else:
        print(d)
elif x > 0:
    n = x//d
    if k <= n:
        print(abs(x-k*d))
    else:
        if k%2 == n%2:
            print(abs(x-n*d))
        else:
            print(abs(x-(n+1)*d))
else:
    n = abs(x)//d
    if k <= n:
        print(abs(x+k*d))
    else:
        if k%2 == n%2:
            print((abs(x+n*d)))
        else:
            print(abs(x+(n+1)*d))
        

Measured memory_bytes: 9204
#include <iostream>
#include <vector>
#include <string>
#include <memory.h>
using namespace std;
const int N = 510;
#define mod 1000000007
int dp[N][N], n, arr[N],arr2[N], c , cur[N][N];

int calc(int i, int j) {
	if (i == n)
		return (j == 0);
	int &ret = dp[i][j];
	if (ret != -1)
		return ret;
	ret = 0;
	for (int k = j; k >= 0; k--) {
		ret += (long long)cur[i][j-k] * calc(i + 1, k) % mod;
		ret %= mod;
	}
	return ret;
}

int fastpower(int num, int po) {
	if (po == 0) return 1;
	int cur = fastpower(num, po >> 1);
	cur = (long long)cur * cur % mod;
	if (po & 1) cur = (long long)cur * num % mod;
	return cur;
}

int main() {
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	scanf("%d%d", &n,&c);
	for (int i = 0; i < n; i++)
		scanf("%d", &arr[i]);
	for (int i = 0; i < n; i++) {
		scanf("%d", &arr2[i]);
		for (int k = 0; k <= c;k++) {
			for (int j = arr[i]; j <= arr2[i]; j++) {
				cur[i][k] += fastpower(j, k);
				cur[i][k] %= mod;
			}
		}
	}
	memset(dp, -1, sizeof(dp));
	cout << calc(0, c) << endl;
	return 0;
}

Measured memory_bytes: 2048
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	input := scanIntNum()
	inputs := scanString()
	fmt.Println(echo(input, inputs))
}

// example
func echo(num int, s string) (result string) {
	a := s[:num/2]
	b := s[num/2:]
	if a == b {
		result = "Yes"
	} else {
		result = "No"
	}
	return
}

func scanIntNum() (num int) {
	sc.Scan()

	num, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return num
}

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

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main() {
    string S;
    cin>>S;
    int dp[S.size()][2];
    // 未満フラグ : 1 -> 未満, 0 -> ぴったり
    dp[0][0] = S[0] - '0';
    dp[0][1] = S[0] - '1';
    for(int i=1;i<S.size();++i){
        dp[i][0] = dp[i-1][0] + S[i] - '0';
        dp[i][1] = max(dp[i-1][1] + 9, dp[i-1][0] + (S[i] - '1'));
    }
    /**
    for(int i=0;i<S.size();++i){
        cout<<dp[i][0]<<" ";
    }
    cout<<endl;
    for(int i=0;i<S.size();++i){
        cout<<dp[i][1]<<" ";
    }
    cout<<endl;
    **/
    cout<<max(dp[S.size()-1][0], dp[S.size()-1][1])<<endl;
}


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

#define ll long long
#define f first
#define se second
#define pb push_back
#define mp make_pair
#define boost cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0)
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>

using namespace std;

const int N = 1e5 + 100, mod = 1e9, inf = 1e9 + 7;
int a[N], n, dp[N];

ll bin_pow(int x, int y){
    if(y == 0)
        return 1;
    if(y == 1)
        return x;
    if(y % 2 == 0){
        ll z = bin_pow(x, y / 2);
        return (z * z) % mod;
    }
    return (bin_pow(x, y - 1) * x) % mod;
}


int main(){
    boost;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    int ans = 0;
    dp[2] = abs(a[1] - a[2]);
    for(int i = 3; i <= n; i++){
        dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
    }
    cout << dp[n];
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    cout << A * B / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> answerNum(N, 0);
    // 正解数をカウント
    for (int i = 0; i < Q; ++i)
    {
        int answer;
        cin >> answer;
        ++answerNum[answer - 1];
    }
    // 問題数ー正解数だけポイントを減らし，
    // ポイントが０以下だったら敗退
    for (int i = 0; i < N; ++i)
    {
        if (K - (Q - answerNum[i]) > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main()
{
    char S1[10], S2[10], S3[10];
    scanf("%s %s %s",&S1, &S2, &S3);

    S1[0]=S1[0]-32;
    S2[0]=S2[0]-32;
    S3[0]=S3[0]-32;

    printf("%c%c%c", S1[0], S2[0], S3[0]);

    return 0;
}

Measured memory_bytes: 1716
#include <iostream>
//#include <iomanip>

using namespace std;
//#define

int main() {
	int a, b, answer;
	char op;

	while(1){
		cin >> a >> op >> b;
		if(op == '?') break;
		if(op == '+'){
			answer = a + b;
		} else if(op == '-'){
			answer = a - b;
		} else if(op == '*'){
			answer = a * b;
		} else if(op == '/'){
			answer = a / b;
		}
		cout << answer << "\n";
	}


	return 0;
}

Measured memory_bytes: 1160
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

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

    vector<int> a(N);
    vector<int> sum(N+1);
    REP(i, N) {
        cin >> a[i];
        sum[i + 1] = sum[i] + a[i];
    }

    vector<int> v;
    REP(l, N) {
        FOR(r, l + 1, N) {
            v.push_back(sum[r] - sum[l]);
        }
    }

    int ans = 0;
    REV(i, 50, 0) {
        int tmp = ans | (1LL << i);

        int k = 0;
        REP(j, v.size()) {
            if ((v[j] & tmp) == tmp) {
                k++;
            }
        }
        if (k >= K) {
            ans = tmp;
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 6516
#include<iostream>
using namespace std;
int main(){
int h1,m1,s1,h2,m2,s2,h,m,s,a,b,c;
for(int i=1;i<=3;i++){
cin>>h1>>m1>>s1>>h2>>m2>>s2;
s=s2-s1;
m=m2-m1;
h=h2-h1;

if(s<0){
m=m-1;
c=60+s;
}
else{
m=m;
c=s;
}

if(m<0){
b=60+m;
a=h-1;
}
else{
b=m;
a=h;
}
cout<<a<<' '<<b<<' '<<c<<'\n';
a=0;b=0;c=0;
}

return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int S,W;

signed main(){
	cin>>S>>W;
	if(S<=W){
		cout<<"unsafe"<<endl;
	}
	else{
		cout<<"safe"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#define ll long long

using namespace std;
typedef pair<int, int> P;

int main()
{
    int x;
    cin >> x;
    if (x >= 30)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#define swap(type, x, y) do{ type t = x; x = y; y = t; }while(0)

void quick(float array[], int left, int right){
  int pl = left, pr = right;
  float x = array[(left + right) / 2];
  do{
    while(array[pl] < x) pl++;
    while(array[pr] > x) pr--;
    if(pl <= pr){
      swap(float, array[pl], array[pr]);
      pl++, pr--;
    }
  }while(pl <= pr);
  if(pl < right) quick(array, pl, right);
  if(pr > left) quick(array, left, pr);
}

int main(){
  int n;  scanf("%d", &n);
  float v[52];
  for(int i=0; i<n; i++)  scanf("%f", &v[i]);

  while(n > 1){
    quick(v, 0, n-1);
    v[0] = (v[0] + v[1]) / 2;
    v[1] = v[n-1];
    n = n - 1;
  }
  printf("%f\n", v[0]);
  return 0;
}


Measured memory_bytes: 128
///  author:Kissheart  ///
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
#define gcd(a,b) __gcd(a,b)
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );
int a,b,c;
int main()
{
    scanf("%d%d%d",&a,&b,&c);
    int x=b/a;
    if(x>=c) printf("%d\n",c);
    else printf("%d\n",x);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int data[128] = {0};
	int max = 0;

	int i;

	while(scanf("%d", &i) != EOF) {
		data[i]++;

		if(data[i] > max)
			max = data[i];
	}

	for(i = 0; i < 101; i++)  {
		if(data[i] == max)
			printf("%d\n", i);
	}

	return 0;
}

Measured memory_bytes: 596
from sys import stdin, stdout
input = stdin.readline
print = stdout.write

n, k = map(int, input().split())
arr = [int(i) for i in input().split()]

bit = [0] * 44
for i in arr:
    for j, b in enumerate(bin(i)[2:].zfill(44)):
        bit[j] += (ord(b) - ord('0'))

#print(bit)
res = 0
for i in range(44):
    val = 2 ** (43 - i)
    if (n - bit[i]) > bit[i] and k >= val:
        res += (n - bit[i]) * val
        k -= val
    else:
        res += bit[i] * val
print(str(res))


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

int main() {
	int row, column, num;	// 行, 列, 地雷の数
	string s_row[50], out[50];

	cin >> row >> column;
	for (int i = 0; i < row; i++) {
		cin >> s_row[i];
  		out[i] = s_row[i];
    }

	for (int i = 0; i < row; i++) {
		for (int l = 0; l < column; l++) {
			if (s_row[i].at(l) == '#')
				continue;

			num = 48;
			for (int j = -1; j <= 1; j++) {
				for (int k = -1; k <= 1; k++) {
					if (j != 0 || k != 0) {
						int r = i + j, c = l + k;
						if (r < 0 || r >= row || c < 0 || c >= column)
							continue;
						if (s_row[r].at(c) == '#')
							num++;
					}
				}
			}
			out[i].at(l) = num;
		}
	}
	for (int i = 0; i < row; i++)
		cout << out[i] << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        var nmk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nmk[0];
        var m = nmk[1];
        var k = nmk[2];
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int aCount;
        int aSum = 0;
        for (aCount = 0; true; aCount++)
        {
            if (aCount >= a.Length || aSum + a[aCount] > k) break;
            aSum += a[aCount];
        }
        var res = aCount;
        var b = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var curSum = 0;
        for (int i = 0; i < b.Length; i++)
        {
            curSum += b[i];
            if (curSum > k) break;
            while (aSum + curSum > k)
            {
                aCount--;
                aSum -= a[aCount];
            }
            res = Max(res, aCount + i + 1);
        }
        Console.WriteLine(res);
    }
}


Measured memory_bytes: 68480
// abc045_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int a, b, h;
    cin >> a >> b >> h;

    int ans = (a + b) * h / 2;
    print(ans);

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int num;
int a[200];

int main(void)
{
    int j;
    int min=100;

    scanf("%d", &num);

    for(j=0;j<num;j++) {
        int a;
        scanf("%d", &a);
        int iCnt=0;
        while(0 == a%2) {
            a /= 2;
            iCnt++;
        }
        if(min>iCnt) {
            min = iCnt;
        }
    }

    printf("%d\n", min);
    return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

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

const int INF = 1000000000;
const int MOD = 1000000007;
const double eps = 1e-9;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    string w;
    cin >> w;

    if (w.size() % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }

    vector<int> alp(26, 0);
    rep(i, w.size()) {
        alp[w[i] - 'a']++;
    }

    bool check = true;
    rep(i, 26) {
        if (alp[i] % 2 == 1) check = false;
    }
    if (check) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

using namespace std;

int main(){
    string a;
    cin >> a;
    sort (a.begin(),a.end());
    
    int f=0,g=a.length();
    for(int i=0;i<g-1;i++){
        if(a[i] == a[i+1] && f == 0){
            cout << "no" << endl;
            f=1;
        }
    }
    if(f == 0){
        cout <<"yes"<<endl;
    }
    
return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll

// 有向グラフ上のトポロジカルソート
vector<ll> topo_sort(vvl &graph){
    queue<ll> que;
    vector<ll> ans;
    ll v = graph.size();
    vector<ll> in(v);
    for(auto &vec : graph){
        for(auto &to : vec)in[to]++;
    }
    rep(i,v)if(in[i] == 0){
        que.emplace(i);
        ans.emplace_back(i);
    }
    while(!que.empty()) {
        auto f = que.front();que.pop();
        for(auto &to : graph[f]) {
            in[to]--;
            if(!in[to]) {
                ans.emplace_back(to);
                que.emplace(to);
            }
        }
    }

    return ans;
};

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll v,e; cin >> v >> e;
    vvl graph(v);
    vector<ll> in(v);
    rep(i,e){
        ll f,t; cin >> f >> t;
        // f--;t--;
        graph[f].emplace_back(t);
        in[t]++;
    }
    auto ans = topo_sort(graph);

    for(auto &i : ans){
        cout << i;
        if(&i != &ans.back())cout << "\n";
    }
    cout << endl;
}


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

void Cal(int a, int b) {
    int area = 0, perim = 0;
    area = a * b;
    perim = a * 2 + b * 2;
    cout << area << " " << perim << endl;
}

int main() {
    int a, b = 0;
    cin >> a >> b;
    Cal(a, b);
    return 0;
}


Measured memory_bytes: 3016
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define all(var) var.begin(), var.end()
#define input freopen("input", "r", stdin)
#define output freopen("output", "w", stdout)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int const MOD = 1e9+7;
typedef long long ll;
using namespace std;
 
int main(){
    int n; cin >> n;
    int arr[n+1] = {0};
    for(int i = 0; i < n-1; i++){
        int x; cin >> x;
        arr[x]++;
    }
    for(int i = 1; i <= n; i++) cout << arr[i] << endl;;
}


Measured memory_bytes: 4420
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
 
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;


int main(){
    int n;
    std::cin >> n;
    VEC(ll,a,n);
    ll ans=a[0]/2;
    a[0]%=2;
    rrep(i,1,n){
        //if(a[i-1])a[i]++;
        if(a[i]!=0)a[i]+=a[i-1];
        ans+=a[i]/2;
        a[i]%=2;
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 1024
n,m = gets.split(" ").map(&:to_i)
a = gets.split(" ").map(&:to_i)
a.sort!
b = [a.pop / 2]
(m-1).times do
  if a.empty? || b.first > a.last
    b << (b.shift / 2)
  elsif b.first <= a.last
    b << (a.pop / 2)
  end
end
sum = 0
a.each { |i| sum += i } if !a.empty?
b.each { |i| sum += i }
puts sum

Measured memory_bytes: 9552
#include <bits/stdc++.h>
 
#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))
 
using namespace std;
 
typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;
 
template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
 
template<typename T>
ostream& operator << (ostream& os, vector<T> v)
{
  os << "(";
  each (i, v) os << i << ",";
  os << ")";
  return os;
}
 
template<typename T>
class BIT {
public:
  BIT(int n_)
  {
    n = n_;
    bit.resize(n + 1, 0);
  }
  T sum (int i)
  {
    return _sum(i + 1);
  }
  void add(int i, T x)
  {
    return _add(i + 1, x);
  }
private:
  vector<T> bit;
  int n;
  T _sum(int i)
  {
    T s = 0;
    while (i > 0) {
      s += bit[i];
      i -= i & -i;
    }
    return s;
  }
  void _add(int i, T x)
  {
    while (i <= n) {
      bit[i] += x;
      i += i & -i;
    }
    return ;
  }
};
 
// https://codeforces.com/blog/entry/18879
lli subsequence_median(vector<int> v, int b)
{
  each (i, v) {
    if (i < b) i = -1;
    else i = +1;
  }
  v.insert(v.begin(), 0);

  for (int i = 1; i < v.size(); ++i) {
    v[i] += v[i - 1];
  }
 
  vector<int> ord;
  for (int i = 0; i < v.size(); ++i) {
    ord.push_back(i);
  }
  stable_sort(ord.begin(), ord.end(), [&] (int a, int b) { return v[a] < v[b]; });
 
  BIT<lli> bit(v.size());
  lli sum = 0;
  for (int i = 0; i < v.size(); ++i) {
    sum += bit.sum(ord[i]);
    bit.add(ord[i], 1);
  }

  return sum;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  lli n;
  while (cin >> n) {
    vector<int> a(n);
    each (i, a) cin >> i;
 
    vector<int> b = a;
    sort(b.begin(), b.end());
    b.erase(unique(b.begin(), b.end()), b.end());
 
    int small = 0;
    int large = b.size();
    while (small + 1 < large) {
      int mid = (small + large) / 2;
      if ((n * (n - 1) / 2 + n + 1) / 2 <= subsequence_median(a, b[mid])) small = mid;
      else large = mid;
    }
 
    cout << b[small] << endl;
  }
  return 0;
}


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

int n;

int main()
{
    cin >> n;

    int sum = 0, tmp = n;
    while(tmp)
    {
        sum += tmp % 10;
        tmp /= 10;
    }

    if(n % sum == 0)
        cout << "Yes" << '\n';
    else cout << "No" << '\n';

    return 0;
}


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

using namespace std;

template<typename T> bool chmax( T &a, const T b ) { if ( a <= b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, const T b ) { if ( a >= b ) { a = b; return ( true ); } else { return ( false ); } }

using ll = long long;
using Pint = pair<int, int>;
using Pll  = pair<ll, ll>;

#define eb emplace_back
#define pb push_back
#define mp make_pair

#define F first
#define S second

#define popcnt __builtin_popcountll

#define rep( i, n ) for ( ll i = 0; i < (ll)( n ); ++i )
#define reps( i, n ) for ( ll i = 1; i <= (ll)( n ); ++i )
#define rrep( i, n ) for ( ll i = (ll)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( ll i = (ll)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

template<typename T = ll> constexpr T MAX = numeric_limits<T>::max();
template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }
template<typename T> T lcm( const T a, const T b ) { return ( a / gcd( a, b ) * b ); }


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

	constexpr ll inf = 1e18;
	vector<vector<ll>> dp( n + 1, vector<ll>( 10, -inf ) );
	rep( i, 3 ) if ( i < n ) dp[i][i] = a[i];
	rep( i, n )
	{
		rep( j, 3 )
		{
			for ( ll d = 0; j + d < 3; ++d )
			{
				ll pre = i - 2 - d;
				if ( pre < 0 ) continue;
				chmax( dp[i][j + d], dp[pre][j] + a[i] );
			}
		}
	}

	ll ans = -inf;
	ll dd = n % 2 + 1;
	rep( d, dd + 1 )
	{
		ll i = n - 1 - d;
		if ( i >= 0 ) chmax( ans, dp[i][dd - d] );
	}

	cout << ans << endl;

	return ( 0 );
}


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

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if(A+B+C<22) cout << "win" << endl;
	else cout << "bust" << endl;
	return 0;
}

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



/* ABC 157B*/
int A[3][3];
int B[10];
bool appear[3][3];
int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N;
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			cin >> A[i][j];
		}
	}
	cin >> N;
	for (int k = 0; k < N; k++)
	{
		cin >> B[k];
	}
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			appear[i][j] = 0;
			for (int k = 0; k < N; k++)
			{
				if (A[i][j] == B[k])appear[i][j] = 1;
			}
		}
	}
	string flag = "No";
	for (int i = 0; i < 3; i++) {
		if (appear[i][0] and appear[i][1] and appear[i][2]) flag = "Yes";
		
	}
	 for (int i = 0; i < 3; i++) {
		 if (appear[0][i] and appear[1][i] and appear[2][i]) flag = "Yes";
		
	}
	 if (appear[0][0] and appear[1][1] and appear[2][2]) flag = "Yes";
	 if (appear[0][2] and appear[1][1] and appear[2][0]) flag = "Yes";
	 cout << flag << '\n';

	return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

from collections import deque
INF = 1001001001
N, X, Y = map(int, input().split())
X -= 1; Y -= 1

ans = [0] * N
for sv in range(N):
    dist = [INF] * N
    q = deque()
    def push(v, d):
        if dist[v] != INF: return
        dist[v] = d
        q.append(v)
    push(sv, 0)
    while q:
        v = q.popleft()
        d = dist[v]
        if v-1 >= 0: push(v-1, d+1)
        if v+1 < N:  push(v+1, d+1)
        if v==X:     push(Y,   d+1)
        if v==Y:     push(X,   d+1)
    for i in range(N):
        ans[dist[i]] += 1

for i in range(1,N):
    print(ans[i]//2)


Measured memory_bytes: 52828
from copy import deepcopy
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter
import itertools
import copy


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n, m = map(int, input().split())
#print('m', m)
tmp = [None]*n
for i in range(n):
    tmp[i] = [None]*2
for i in range(n):
    tmp[i] = readints()
# print(tmp)
tmp_so = sorted(tmp, key=lambda x: x[0])
# print(tmp_so)
cnt = 0
cost = 0
for i in range(n):
    if tmp_so[i][1] <= m:
        m -= tmp_so[i][1]

        cost += tmp_so[i][1]*tmp_so[i][0]
    elif m <= tmp_so[i][1]:

        cost += m*tmp_so[i][0]
        m = 0
print(cost)


Measured memory_bytes: 104724
package main

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

type long int64
type float float32
type double float64

// io
type Scanner struct {
    reader *bufio.Reader
    buffer []string
    pointer int
}

func NewScanner() *Scanner {
    return &Scanner{
        reader: bufio.NewReaderSize(os.Stdin,4096),
        pointer: 0,
    }
}

func (self *Scanner) NextLine () string {
    var buffer []byte
    for {
        line,isPrefix,_ := self.reader.ReadLine()

        buffer = append(buffer, line...)
        if !isPrefix {
            break
        }
    }
    return string(buffer)
} 

func (self *Scanner) Next () string {
    if self.pointer >= len(self.buffer) {
        line := self.NextLine()
        self.buffer = strings.Fields(line)
        self.pointer = 0
    }
    self.pointer++
    return self.buffer[self.pointer-1]
}

func (self *Scanner) NextInt () int {
    s := self.Next()
    i,_ := strconv.ParseInt(s,10,32)
    return int(i)
}

func (self *Scanner) NextLong () long {
    s := self.Next()
    l,_ := strconv.ParseInt(s,10,64)
    return long(l)
}

func (self *Scanner) NextFloat () float {
    s := self.Next()
    f,_ := strconv.ParseFloat(s,32)
    return float(f)
}

func (self *Scanner) NextDouble () double {
    s := self.Next()
    d,_ := strconv.ParseFloat(s,64)
    return double(d)
}
// math
// func Max (a,b int) int { if a < b { return b } else { return a } }
// func Max (a,b long) long { if a < b { return b } else { return a } }
func Min (a,b int) int { if a < b { return a } else { return b } }

func main () {
	cin := NewScanner()
	
	S := cin.Next()
	T := cin.Next()

	N := len(S)
	M := len(T)

	for i := N-M; i >= 0; i-- {
		flag := true
		for j := 0;j < M; j++ {
			if S[i+j] != T[j] && S[i+j] != '?' {
				flag = false
				break
			}
		}

		if flag {
			for j := 0;j < N; j++ {
				if i <= j && j < i+M {
					fmt.Print(string(T[j-i]))
				} else if S[j] == '?' {
					fmt.Print("a")
				} else {
					fmt.Print(string(S[j]))
				}
			}
			fmt.Println()
			return
		}
	}

	fmt.Println("UNRESTORABLE")
}

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

const int MAXN = 3e5+10;

int bit[MAXN];
int par[MAXN];
int parent(int i) {
  return par[i] < 0 ? i: (par[i]=parent(par[i]));
}

bool merge(int a, int b) {
  int x = parent(a);
  int y = parent(b);
  if (x==y) {
    if (bit[x]) return false;
    else return bit[x] = 1;
  }
  if (bit[x] && bit[y]) return false;
  bit[x]+=bit[y];
  par[y] = x;
  return 1;
}

int gc=0;
map<pair<int,int>, int> m;
int gid(int r, int c) {
  auto p = make_pair(r,c);
  if (m.count(p)) {
    return m[p];
  }
  else {
    return  m[p] = gc++;
  }
}

int n, h, w;

int main(){
  cin.tie(0); ios_base::sync_with_stdio(0);
  cin >> n >> h >> w;
  memset(par, -1,sizeof par);
  vector<vector<int>> v;
  for(int i=0;i<n;i++) {
    int r, c, w;
    cin >> r >> c >> w;
    v.push_back({w,r,c});
  }
  sort(v.rbegin(), v.rend());
  ll ans = 0;
  for(auto p: v) {
    if (merge(gid(p[1],0), gid(p[2],1))){
      ans+=p[0];
      //cerr << "ADDING " << p[1] << " " << p[2] << " " << p[0] <<endl;
    }
    //else //cerr << "NOT ADDING " << p[1] << " " << p[2] << " " << p[0] <<endl;
  }
  cout << ans <<endl;
}


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

int main()
{
	int a, b;
	cin >> a >> b;
	int ans[3];
	ans[0] = a + a - 1;
	ans[1] = a + b;
	ans[2] = b + b - 1;
	sort(ans, ans+3);
	cout << ans[2] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <sstream>
#include <map>
#include <cstring>
#include <vector>
#include <queue>
#include <iomanip>
#include <stack>
#include <unordered_set>

using namespace std;
typedef long long ll;

ll ans, mx, sum, mn = 1e14, flag,cnt;

ll check(ll arr[],ll n,ll key){ 
    ll left = 0; 
    ll right = n - 1;
    ll count = 0; 
    while (left <= right) { 
        ll mid = (right + left) / 2;
        if (arr[mid] < key) { 
            count = mid + 1; 
            left = mid + 1; 
        }
        else
            right = mid - 1; 
    } 
    return count; 
} 



int main(){
	ll n,m;
	cin>>n>>m;
	ll a[n];
	for(ll i=0; i<n; i++){
		cin>>a[i];
	}
	
	vector<pair<ll,ll>> v;
	for(ll i=0; i<m; i++){
		ll a,b;
		cin>>a>>b;
		v.push_back(make_pair(b,a));
	}
	sort(a,a+n);
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	
	map<ll,ll> mp;
	
	for(ll i=0; i<m; i++){
		ll h=check(a,n,v[i].first);
		mp[v[i].first]=h;
	}
	for(ll i=0; i<n; i++){
		if(a[i]>=v[0].first) sum+=a[i];
	}
	for(ll i=0; i<m; i++){
		ll g= mp[v[i].first]-cnt;
		ll k=min(v[i].second,g);
		ll f=max(k,0ll);
		cnt+=f;
		sum+=v[i].first*f;
	}
	for(ll i=cnt; i<mp[v[0].first]; i++){
		sum+=a[i];
	}
	cout<<sum;
}


Measured memory_bytes: 11948
#include<iostream>
#include<set>
using namespace std;
#define MAX 101

int t = 1, used[MAX];
pair<int,int> ans[MAX];
set<int> G[MAX];

void dfs(int id){
	if(used[id] == true) return ;
	else used[id] = true;
	ans[id].first = t++;
	
	for(int y : G[id]){
		dfs(y);
	}
	ans[id].second = t++;
}

int main(){
	int n, u, k, v, A[MAX][MAX] = {};
	
	cin>>n;
	
	for(int i = 0; i < n; i++){
		cin>>u>>k;
		for(int j = 0; j < k; j++){
			cin>>v;
			G[u].insert(v);
		}
	}
	
	for(int i = 1; i <= n; i++){
		dfs(i);
	}
	
	for(int i = 1; i <= n; i++){
		cout<<i<<" "<<ans[i].first<<" "<<ans[i].second<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3144
n=int(input())
a=[]
for _ in range(n):
  a+=[int(input())]
max_a=0
max_2=0
max_i=[]
for i in range(n):
  if a[i]>=max_a:
    max_2=max_a
    max_a=a[i]
    max_i=[i]
  elif a[i]>max_2:
      max_2=a[i]
for i in range(n):
  if i==max_i[0]:
    print(max_2)
  else:
    print(max_a)

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

int main(){
int n,m,c;
cin >> n >> m >> c;
int a[n][m];
int ans =0;
vector<int>aa(m);
for(int i=0;i<m;i++){
    cin >> aa.at(i);
}
for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
        cin >> a[i][j];
    }
}

for(int i=0;i<n;i++){
    int che =0;
    for(int j=0;j<m;j++){
        che+=a[i][j]*aa.at(j);
        if(j==m-1&&che+c>0){
            ans++;
        }
    }
}
cout << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int N,W;
    while(cin >> N >> W){
        int dp[105][10005] = {0};
        range(i,1,N+1){
            int v, w;
            cin >> v >> w;
            range(j,1,W+1){
                if(j - w >= 0)
                    dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w] + v);
                else
                    dp[i][j] = dp[i - 1][j];
            }
        }
        cout << dp[N][W] << endl;
    }
}

Measured memory_bytes: 5272