akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main()
{
   int n,k,a,cnt=0;
   cin>>n>>k;

   for(int i=0;i<n;i++)
   {
       cin>>a;
       if(a>=k)cnt++;

   }
   cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int in1,in2,in3;
    int step1,step2;
    
    scanf("%d %d %d",&in1,&in2,&in3);
    
    if(in1 > in2){
        step1 = in1;
        in1 = in2;
        in2 = step1;
    }
    if(in1 > in3){
        step1 = in1;
        in1 = in3;
        in3 = step1;
    }
    if(in2 > in3){
        step1 = in2;
        in2 = in3;
        in3 = step1;
    }
    
    step1 = (in2-in1)/2;
    step2 = (in3-in2);
    
    if(step1*2 != (in2-in1)){
        step2 += 2;
    }
    
    printf("%d\n",step1+step2);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N,K; cin>>N>>K;
	int R,S,P; cin>>R>>S>>P;
	string T; cin>>T;
	string TT = T;
	ll ans = 0;
	rp(i,0,T.size()){
		if(T[i]=='r'){TT[i] = 'p';ans += P;}
		else if(T[i]=='s'){TT[i] = 'r';ans += R;}
		else {TT[i] = 's';ans += S;}//p
	}

	rp(i,K,T.size()){
		if(TT[i-K]==TT[i]){
			if(TT[i]=='r'){
				ans -= R;
			}
			else if(TT[i]=='s'){
				ans -= S;
			}
			else {
				ans -= P;
			}//p

			TT[i] = T[i];
			if(i+K>=T.size()) continue;
			if(TT[i]==TT[i+K]){
				if(TT[i]=='r'){
					TT[i] = 's';
				}
				else if(TT[i]=='s'){
					TT[i] = 'p';
				}
				else {
					TT[i] = 'r';
				}//p
			}
		}
	}

	ote(ans);
}


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

#define whole(f, x, ...)                                 \
  ([&](decltype((x)) whole) {                            \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
  })(x)

using namespace std;
using ll = long long;

void solve() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  if (a > k) {
    cout << k << endl;
    return;
  }
  if (a + b >= k) {
    cout << a << endl;
    return;
  }
  cout << a - (k - a - b) << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


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

void makeAns(string *ans, string *str)
{
    //cout << "l1 " << *ans << endl;
    //cout << "l1 " << *str << endl;
    int ansSize = ans->size();
    vector<char> deleteChar;
    for(int i = 0; i < ansSize; ++i)
    {
        char c = ans->at(i);
        
        if(str->find(c) != -1)
        {
            int pos = str->find(c);
            str->erase(str->begin() + pos);
            //cout << *str << endl;
        }
        else
        {
            deleteChar.push_back(c);
        }
    }
    
    int s = deleteChar.size();
    
    for(int i = 0; i < s; ++i)
    {
        char c = deleteChar.at(i);
        int pos = ans->find(c);
        ans->erase(ans->begin() + pos);
    }
    
}

int main()
{
    int n;
    string str;
    string ans;
    cin >> n;
    for(int i = 0; i < n; ++i)
    {
        cin >> str;
        sort(str.begin(), str.end());
        if(i == 0)
        {
            ans = str;
            continue;
        }
        makeAns(&ans, &str);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
using ll = long long;
using ii = pair <ll , ll>;
void in(ll &x);
const ll N = 105;
const ll V = 1e5 + 10;
const ll INF = 1e9;
ll dp[N][V], weight[N], val[N];
ll n, w;

ll f(ll cur , ll rem) {
  if (cur > n) return rem == 0 ? 0 : INF;
  ll &sol = dp[cur][rem];
  if (sol != -1) return sol;
  sol = f(cur + 1 , rem);
  if (rem >= val[cur]) {
    sol = min(sol , f(cur + 1 , rem - val[cur]) + weight[cur]);
  }
  return sol;
}

int main() {
  in(n); in(w);
  int sum = 0;
  for (ll i = 1 ; i <= n ; i++) {
    in(weight[i]); in(val[i]);
    sum += val[i];
  }
  memset (dp , -1 , sizeof dp);
  ll sol = -1;
  for (ll i = 1 ; i <= sum ; i++) {
    ll minWeight = f(1 , i);
    if (minWeight <= w) {
      sol = i;
    }
  }
  printf("%lld\n" , sol);
  return 0;
}

void in(ll &x){
	bool neg = false;
	register ll c;
	x = 0;
	c = getchar();
	if(c == '-'){
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


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

using namespace std;
using ll = long long;
//a^n
ll pow(int a, int n){
    if (n == 0) return 1;
    ll x = pow(a, n/2);
    x *= x;
    if (n%2 == 1) x *= a;
    return x;
}
int take_bit(int bits, int i, int n){
    int b;
    b = bits & pow(2, n - i);
    b >>= (n - i);
    return b;
}

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> s_list;
    for (int i = 0; i < m; i++){
        int k;
        cin >> k;
        vector<int> ss;
        for (int j = 0; j < k; j++){
            int s;
            cin >> s;
            ss.push_back(s);
        }
        s_list.push_back(ss);
    }
    vector<int> p_list;
    for (int i = 0; i < m; i++){
        int p;
        cin >> p;
        p_list.push_back(p);
    }
    int max = 0;
    for (int i = 0; i < n; i++){
        max += pow(2, i);
    }
    int ans = 0;
    int bits = 0;
    for (int j = 0; j < max + 1; j++){
        bits += j;
        int flag = 0;
        for (int i = 0; i < m; i++){
            int sum = 0;
            for (int s : s_list[i]){
                sum += take_bit(bits, s, n);
            }
            if (sum % 2 != p_list[i]){
                flag = 1;
                break;
            }
        }
        if (flag == 0){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

type plan struct {
	t, x, y int
}

func main() {
	n := 0
	fmt.Scan(&n)

	plans := make([]plan, n+1)
	for i := 1; i <= n; i++ { // スタート地点(0, 0)を含めてみました
		fmt.Scan(&plans[i].t, &plans[i].x, &plans[i].y)
	}

	for i, p := range plans {
		if i == 0 {
			continue
		}

		diffT := p.t - plans[i-1].t
		distance := abs(p.x-plans[i-1].x) + abs(p.y-plans[i-1].y)
		if diffT%2 != (distance)%2 || diffT < (distance) {
			fmt.Println("No")
			return
		}
	}

	fmt.Println("Yes")
}

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


Measured memory_bytes: 5888
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;
 
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int main(){
	int n;cin>>n;
	string s;
	cin>>s;
	if(int(s.size())%2==0 and s.substr(0,s.size()/2)==s.substr(s.size()/2,s.size()/2))
		puts("Yes");
	else
		puts("No");
	return 0;
}

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

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  
  int dis_a, dis_b;
  
  if (x > a)
    dis_a = x - a;
  else
    dis_a = a - x;
  
  if (x > b)
    dis_b = x - b;
  else
    dis_b = b - x;
  
  if (dis_a < dis_b)
    cout << "A" << endl;
  else
    cout << "B" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main(void)
{
	double x1, y1, x2, y2, kyo;

	scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
	
	kyo	= ((x1 - x2)*(x1 - x2)) + ((y1 - y2)*(y1 - y2));
	kyo = sqrt(kyo);//平方根の計算

	printf("%f", kyo);

	return 0;
}



Measured memory_bytes: 2104
import bisect


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

a.sort()
b.sort()
c.sort()
ans = 0
for i in range(n):
    num = b[i]
    x = bisect.bisect_left(a, num)
    y = bisect.bisect_right(c, num)
    ans += x * (n - y)

print(ans)

Measured memory_bytes: 23232
import java.util.Scanner;
class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力

		

		int a = sc.nextInt();
		int p = sc.nextInt();
		
		System.out.println((a*3+p)/2);
		

		
		
	}
	
	static void allsum(int[] A){
		long ans = 0;
		for(int i = 0;i < A.length;i++){
//			System.out.println(A[i]);
			ans += A[i];
		}
		System.out.print(ans);
	}


	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}





}



class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return  otherpair.end - end;
	}
}




Measured memory_bytes: 21844
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
    ll d, n, ans = 1;
    cin >> d >> n;
    while(d--) {
        ans *= 100;
    }
    if (n == 100) {
        ans *= 101;
    } else {
        ans *= n;
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 256
#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; }

// ---- ----

int n, k, s[100000], t[100000], c[100000];
int d[30][200001];

int main() {
	cin >> n >> k;
	inc(i, n) { cin >> s[i] >> t[i] >> c[i]; }
	
	inc(i, n) { s[i] = s[i] * 2 - 1; t[i] *= 2; c[i]--; }
	inc(i, n) {
		d[c[i]][s[i]]++;
		d[c[i]][t[i]]--;
	}
	inc(i, k) {
		inc1(j, 200000) { d[i][j] += d[i][j - 1]; }
		inc1(j, 200000) { setmin(d[i][j], 1); }
	}
	
	int ans = 0;
	inc1(j, 200000) {
		int m = 0;
		inc(i, k) { m += d[i][j]; }
		setmax(ans, m);
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 24832
#include<iostream>
#include<algorithm>
#include<map>
#include<cstdio>
#define ll long long
#define lson (rt<< 1)
#define rson (rt<< 1 | 1)
#define gmid ((l+r)>> 1 )
using namespace std;

const int maxn=20000050;
int main()
{
	double d,t,s;
	cin>>d>>t>>s;
	if(d/s>t) cout<<"No"<<endl;
	else cout<<"Yes"<<endl; 
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
	int n;
	cin >> n;
	if (n % 2 == 0) cout << n << endl;
	else cout << 2 * n << endl;

}

Measured memory_bytes: 256
import math
n=int(input())
a=[int(i) for i in input().split()]
odd=0
two=0
four=0
for i in a:
    if i%2==0:
        i=i//2
        if i%2==0:
            four+=1
        else:
            two+=1
    else:
        odd+=1
res=False
if two==0:
    if odd<=four+1:
        res=True
elif odd<=four:
    res=True
print("Yes" if res else "No")

Measured memory_bytes: 14252
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	char c;
	cin >> c;
	if(c == 'A')cout << 'T' << endl;
	if(c == 'T')cout << 'A' << endl;
	if(c == 'C')cout << 'G' << endl;
	if(c == 'G')cout << 'C' << endl;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

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

int main() {
  ll n;
  cin >> n;
  vector<ll> v(5);
  for (int i = 0; i < 5; i++) cin >> v[i];
  ll m = *min_element(v.begin(), v.end());
  cout << ((n <= m) ? 5 : 4 + (n + m - 1) / m) << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <ctime>
#include <iostream>
#include <functional>
#include <complex>
#include <stdlib.h>
#include <random>
#pragma comment(linker, "/STACK:836777216")

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> p3i;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<p3i> v3i;
typedef vector<vii> vvii;
typedef vector<p3i> vp3i;
typedef long double ld;
typedef vector<ld> vld;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rv(v) reverse(all(v))
#define CL(v, val) memset((v), (val), sizeof((v)))
#define SORT(a) sort(all(a))
#define un(v) SORT(v), (v).resize(unique(all(v)) - (v).begin())
#define eps 1.0e-9
#define X first
#define Y second
#define bit(n) (1 << (n))
#define bit64(n) (ll(1) << (n))
#define sqr(x) ((x) * (x))

int main(void) {
	ll n, k;
	scanf("%lld%lld", &n, &k);
	ll ost = n % k;
	ll ans = min(ost, k - ost);
	printf("%lld\n", ans);
	scanf("%d", &n);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

int main() {
	string s;
	cin >> s;

	int n = s.size();

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

	vector<int> sum(200005, 0);

	vector<int> a(200005);
	int keta = 1;
	rep (i, n) {
		a[i] = ((s[i] - '0') * keta) % 2019;
		keta = (keta * 10) % 2019;
	}

	for (int i = 1; i <= n; i++) {
		sum[i] += sum[i-1] + a[i-1];
		sum[i] %= 2019;
	}

	map<int, int> mp;
	for (int i = 0; i <= n; i++) {
		mp[sum[i]]++;
	}

	ll ans = 0;
	for (auto x: mp) {
		if (x.second) ans += x.second * (x.second-1) / 2;
	}

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

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

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

#define dump(x) cerr << #x << " = " <<(x)<<endl;
#define debug(x) cerr << #x << " = " <<(x) << "(L" << __LINE__ << ")" << __FILE__ << endl;

#define BIT_ON(x,b) ((x)|=(b))
#define BIT_OFF(x,b) ((x)&=~(b))
#define BIT_IS_ON(x,b) (((x)&(b))==(b))


using namespace std;

int main(void){
  int i,n,count;
  count = 0;
  cin >> n;
  vector<int> v(n+1);
  FOR(i,1,n+1) scanf("%d", &v[i]);
  FOR(i,1,n+1) if(i == v[v[i]]) count++;
  cout << count/2 << endl;
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
int main(){
      ll n;
      cin>>n;
      ll i,j,k,ar[n];
      for(i=0;i<n;i++){
          cin>>ar[i];
      }
      ll ans=0;
    for(i=0;i<n;i++){
        cin>>ar[i];
    }
    for(i=0;i<n;i++){
        while(ar[i]%2==0){
            ar[i]/=2;
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
t = int(input())
for _ in range(t):
    n,k = map(int,input().split())
    houses=list(map(int,input().split()))
    if n<=k:
        print(0)
        continue
    sa = [houses[i+1] - houses[i] for i in range(n-1)]
    sa.sort()
    res = houses[-1] - houses[0]
    for i in range(k-1):
        res -= sa.pop()
    print(res)
    


Measured memory_bytes: 21404
def solve():
    import sys
    input = sys.stdin.readline

    class BIT:
        def __init__(self, n):
            self.n = n
            self.data = [0] * n

        def sum(self, i):
            s = 0
            while i > 0:
                s += self.data[i - 1]
                i &= i - 1
            return s

        def update(self, i, x):
            while i < self.n:
                self.data[i] += x
                i |= i + 1

    n, q = map(int, input().split())
    c = list(map(int, input().split()))
    odr_r = [[] for _ in range(n + 1)]
    for i in range(q):
        l, r = map(int, input().split())
        odr_r[r].append((l - 1, i))

    b = BIT(n)
    diff = 0
    ans = [-1] * q
    last = [-1] * (n + 1)

    for i, v in enumerate(c):
        if last[v] != -1:
            b.update(last[v], -1)
        else:
            diff += 1

        b.update(i, 1)
        last[v] = i

        for l, j in odr_r[i + 1]:
            ans[j] = diff - b.sum(l)
    print("\n".join(map(str, ans)))
    return


solve()


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

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  if(A.at(A.size()-1) == B.at(0) && B.at(B.size()-1) == C.at(0)) {
    cout << "YES";
  }
  else {
    cout << "NO";
  }
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
	char str[5005];
	int k;
	int len;
	char dict[25005][6] = {};
	int cnt;
	int ans_indx;

	scanf("%s", str);
	scanf("%d", &k);

	len = strlen(str);

	cnt = 0;
	for (int i = 0; i < k; i++) {
		for (int j = 0; j + i < len; j++) {

			for (int ii = j; ii <= j + i; ii++) {
				dict[cnt][ii - j] = str[ii];
			}
			cnt++;

		}
	}

	qsort(*dict, cnt, 6, (int (*)(const void *, const void *))strcmp);

	ans_indx = -1;
	int ccnt = 0;
	while (ccnt < k) {
		if (strcmp(dict[ans_indx], dict[ans_indx + 1])) { 
			ccnt++;
		}

		ans_indx++;
	}

	printf("%s\n", dict[ans_indx]);

	return 0;
}


Measured memory_bytes: 508
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
#print(l)
for i in range(n):
    for j in range(i+1,n):
        val = l[i]+l[j]
        ng = n
        ok = j
        while abs(ok - ng) > 1:
            mid = (ok+ng)//2
            if val > l[mid]:
                ok = mid
            else:
                ng = mid


        #print(i,j,ok,ng)

        ans += ok - j


print(ans)

Measured memory_bytes: 41948
N = int(input())
ans = 0
def dfs(n, f1, f2, f3):
    if n > N:
        return
    elif f1 and f2 and f3:
        global ans
        ans += 1

    dfs(n*10+7, True, f2, f3)
    dfs(n*10+5, f1, True, f3)
    dfs(n*10+3, f1, f2, True)

dfs(0, False, False, False)
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

int cmpAsc(const void* a, const void* b){
    lld x = *(lld*)a, y = *(lld*)b;
    if(x > y){
        return 1;
    }
    if(x < y){
        return -1;
    }
    return 0;
}

int main(){
    int n;
    scanf("%d", &n);
    lld a[n];
    rep(i, 0, n){
        scanf("%lld", &a[i]);
    }
    qsort(a, n, sizeof(lld), cmpAsc);
    lld p[n/2], q[n/2];
    rep(i, 0, n/2){
        p[i] = a[i];
        q[i] = a[i + ((n+1)/2)];
    }
    int i_p = 0, i_q = 0;
    lld buf_1 = 0, buf_2 = 0;
    rep(i, 0, n/2*2-1){
        buf_1 += q[i_q] - p[i_p];
        if(i%2){
            i_p++;
        }else{
            i_q++;
        }
    }
    i_p = 0; i_q = 0;
    rep(i, 0, n/2*2-1){
        buf_2 += q[i_q] - p[i_p];
        if(i%2){
            i_q++;
        }else{
            i_p++;
        }
    }
    if(n%2){
        lld r = a[n/2];
        buf_1 += (q[0] - r) > (r - p[n/2-1]) ? (q[0] - r) : (r - p[n/2-1]);
        buf_2 += (q[n/2-1] - r) > (r - p[0]) ? (q[n/2-1] - r) : (r - p[0]);
    }
    lld ans = buf_1 > buf_2 ? buf_1 : buf_2;
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 1788
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()

int SURP = 1000000007;

int main(){
	int M;
	cin >> M;
	int ret = 48 - M;
	cout << ret << endl;
	return 0;

}


Measured memory_bytes: 256
def q2():
    N, L = (int(i) for i in input().split())
    aji = [L+i for i in range(N)]
    aji_min_i = 999
    aji_min = 999
    for i, a in enumerate(aji):
        if abs(a) < aji_min:
            aji_min = abs(a)
            aji_min_i = i
    aji.pop(aji_min_i)
    print(sum(aji))

if __name__ == '__main__':
    q2()

Measured memory_bytes: 38384
#include<iostream>
#include<string>
using namespace std;
int n, cnt, ans;
string s;
int main(){
	cin >> n >> s;
	for(int i = 0;i < n;i++){
		if(s[i] == 'I'){
			cnt++;
		} else {
			cnt--;
		}
		ans = max(ans, cnt);
	} 
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1e9+5;
int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    ll arr[n+1];
    ll sum = 0;
    for (int i=1; i<=n; i++) {
        cin >> arr[i];
        sum += arr[i];
    }
    ll dp[n+1][n+1];
    for (int gap = 0; gap<n; ++gap) {
        for (int i=1, j=gap+1; j<=n; ++i, ++j) {
            ll x = ((i + 2) <= j) ? dp[i + 2][j] : 0; 
            ll y = ((i + 1) <= (j - 1)) ? dp[i + 1][j - 1] : 0; 
            ll z = (i <= (j - 2)) ? dp[i][j - 2] : 0;
            dp[i][j] = max(arr[i] + min(x, y), arr[j] + min(y,z));
            //cout << dp[i][j] << " ";
        }
        //cout << endl;
    }
    ll ans = dp[1][n]-(sum-dp[1][n]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 70528
#include <cstdlib>
#include <iterator>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <functional>
using namespace std;

int main() {
    int x, y;
    cin >> x >> y;
    cout << x + y / 2 << endl; 
}


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

int main() {
    int n, m;
    while (cin >> n >> m, n || m) {
        vector<int> s1(n), s2(m);
        for (auto& i : s1) cin >> i;
        for (auto& i : s2) cin >> i;

        int sum1 = 0, sum2 = 0;
        for (auto i : s1) sum1 += i;
        for (auto i : s2) sum2 += i;

        int sum = 1 << 28;
        int I = 1000, J = 1000;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (sum1 - s1[i] + s2[j] == sum2 - s2[j] + s1[i] && I + J > s1[i] + s2[j]) {
                    I = s1[i];
                    J = s2[j];
                }
            }
        }

        if (I < 1000) cout << I << " " << J << endl;
        else cout << -1 << endl;
    }

    return 0;
}



Measured memory_bytes: 2992
import math


def lem(A, B):
    AB = A * B
    while B != 0:
        A, B = B, A % B
    return AB // A


a, b, c, d = map(int, input().split())


bsep = (b // c) + (b // d) - (b // lem(c, d))
asep = (a-1) // c + (a-1) // d - (a-1) // lem(c, d)

ans = b - a+1 - bsep + asep
print(ans)


Measured memory_bytes: 3060
#include <algorithm>
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;

int main(){
    int A ,B,C;
    cin >> A >> B >> C;
    if(B/A >= C){
        cout << C;
    }else{
        cout << B/A;
    }
    return 0;
}

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

using namespace std;

#define ll long long

#define DEBUG (0)

int main()
{
  int S = 0;
  int W = 0;

  cin >> S >> W;

  if(S > W){
    cout << "safe" << "\n";
  }else{
    cout << "unsafe" << "\n";
  }
}


Measured memory_bytes: 3568
#include<iostream>
using namespace std;
int ans=0;
int dfs(int n,int a[],int num,int now){
  if(now==2)
    return 1;
  if(num==n){
    cout<<-1<<endl;
    return 0;
  }
  ans++;
  dfs(n,a,num+1,a[now]);
}
int main(){
  int N;
  cin>>N;
  int a[N+1];
  for(int i=1;i<=N;i++)
    cin>>a[i];
  if(dfs(N,a,0,1))
    cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>


using namespace std;


int main()
{
	int n, m, l;

	cin >> n >> m >> l;

	int **A = new int*[n];
	for(int i = 0; i < n; i++)
		A[i] = new int[m];

	int **B = new int*[m];
	for(int i = 0; i < m; i++)
		B[i] = new int[l];

	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			cin >> A[i][j];

	for(int i = 0; i < m; i++)
		for(int j = 0; j < l; j++)
			cin >> B[i][j];

	// 計算結果の表示
	for(int i = 0; i < n; i++){
		for(int j = 0; j < l; j++){
			long long int sum = 0;

			for(int k = 0; k < m; k++)
				sum += A[i][k] * B[k][j];

			cout << sum;
			if(j != l - 1)
				cout << " ";
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3176
#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
LL i,j,k,m,n,a[100005];
string s;
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>i>>j>>k;
	cout<<k<<' '<<i<<' '<<j;
}

Measured memory_bytes: 256
n,m,x = map(int,input().split())
a = [int(s) for s in input().split()]
cost = []
count = 0

for i in range(x,n):
    if a.count(i) == 1:
        count += 1
cost.append(count)
count = 0
c = range(0,x)
for i in reversed(c):
    if a.count(i) == 1:
        count += 1
cost.append(count)
print(min(cost))

Measured memory_bytes: 9096
#!/usr/bin/perl

use strict;
use warnings;
use 5.010;

use Data::Dumper;

my @INPUT;
while (<>) {
    chomp;
    push @INPUT, $_;
}

my ( $N, $K ) = split " ", shift @INPUT;


my %len;
$len{0} = 1;
sub len {
    my $l = shift;
    if ($len{$l}) {
        return $len{$l};
    }
    if ($l == 0) {
        return 1;
    }
    $len{$l} = 2 * len($l-1) + 3;
    return $len{$l};
}

my %eat;

sub eat {
    my ( $n, $x ) = @_;
    if ( $x > $len{$n} ) {
        $x = $len{$n};
    }
    #say "n: $n, x: $x";
    if ( $n == 0 && $x >= 1 ) {
        return 1;
    }
    if ( $x == 0 ) {
        return 0;
    }
    if ( $x <= $len{$n - 1} + 1 ) {
        #say "p1";
        $eat{($n-1) . ":" . ($x - 1)} //= eat( $n - 1, $x - 1 );
        return $eat{($n-1) . ":" . ($x - 1)};
    }
    elsif ( $x == $len{$n - 1} + 2 ) {
        #say "p2";
        $eat{($n-1) . ":" . ($x - 1)} //= eat( $n - 1, $x - 1 );
        return $eat{($n-1) . ":" . ($x - 1)} + 1;
    }
    else {
        #say "p3";
        $eat{($n - 1) . ":" . $len{$n - 1}} //= eat($n - 1, $len{$n - 1});
        $eat{($n - 1) . ":" . ($x - 2 - $len{$n - 1})} //= eat( $n - 1, $x - 2 - $len{ $n - 1 } );
        return $eat{($n-1) . ":" . ($len{$n - 1})} + $eat{($n-1) . ":" . ($x - 2 - $len{$n - 1})} + 1;
    }
}


len($N);
#say $len{$N};
say eat($N, $K);


Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int INF=1e9;
const ll MOD=1e9+7;

ll gcd(ll x,ll y){
    if(y==0) return 0;
    return gcd(y,x%y);
}

int dis2(int x1,int y1,int x2,int y2){
    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}

double cut(int r,int n,int i){
    double res=r*r-(r-r*(double)i/(double)n)*(r-r*(double)i/(double)n);
    return pow(res,0.5)*2;
}

int main(){
    int n;cin>>n;
    string s;cin>>s;
    int r=0,b=0;
    for(int i=0;i<(int)s.size();i++){
        if(s[i]=='R') r++;
        else b++;
    }
    cout<<(r>b?"Yes":"No")<<endl;
    return 0;
}

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

using namespace std;

#define ll long long
#define vi vector<int>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

int c[5][5], a[3], b[3], buff, min_v = 100;

bool check(){
    bool flag = true;
    rep(i,3){
        rep(j,3)
            if(c[i][j] != a[i] + b[j]) flag = false;
    }
    return flag;
}

void solve(){
    rep(i,3) rep(j,3) c[i][j] -= min_v;

    rep(i,3)
        a[i] = min(min(c[i][0], c[i][1]), c[i][2]);
    rep(j,3)
        b[j] = min(min(c[0][j], c[1][j]), c[2][j]);

    if(check()) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main(){
    rep(i,3){
        rep(j,3){
            cin >> buff;
            c[i][j] = buff;
            min_v = min(buff, min_v);
        }
    }
    solve();
}


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

using namespace std;

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

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = INT_MAX;
const ll linf = 3e18;
const double eps = 1e-9;

struct RMQ { // segtree
    int n;
    vi seg;

    void init(int n_)
    {
        n = 1;
        while (n < n_) n *= 2;
        seg.resize(2 * n - 1);
        for (int i = 0; i < 2 * n - 1; ++i) {
            seg[i] = inf;
        }
    }

    void update(int k, int a)
    {
        k += n - 1;
        seg[k] = a;

        while (k > 0) {
            k = (k - 1) / 2;
            seg[k] = min(seg[k * 2 + 1], seg[k * 2 + 2]);
        }
    }

    int query(int a, int b, int k, int l, int r)
    {
        if (r <= a || b <= l) return inf;
        if (a <= l && r <= b) return seg[k];
        int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
        int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return min(vl, vr);
    }

    int query(int a, int b) {
        return query(a, b, 0, 0, n);
    }
} rmq;

signed main()
{
    int N, Q;
    scanf("%d %d", &N, &Q);

    rmq.init(N);

    rep(i, Q) {
        int c, x, y;
        scanf("%d %d %d", &c, &x, &y);

        if (c == 0) {
            rmq.update(x, y);
        } else {
            int v = rmq.query(x, y + 1);
            cout << v << endl;
        }
    }
}

Measured memory_bytes: 2060
#include<stdio.h>
#include<ctype.h>
int main(void){
   char ta[101];
   char ha[101];
   int n,c;
   int t,h;
   int i;

   t=0;
   h=0;
   scanf("%d",&n);
   for(i=0;i<n;i++){
      scanf("%s%s",ta,ha);
      c = strcmp(ta,ha);
      if(c>0)t+=3;
      else if(c==0){
         t+=1;
         h+=1;
      }
      else if(c<0)h+=3;
   }
   printf("%d %d\n",t,h);
   return 0;
}

Measured memory_bytes: 604
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N, M, Q = list(map(int, sys.stdin.buffer.readline().split()))
LR = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]
PQ = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(Q)]

counts = np.zeros((N + 1, N + 1), dtype=int)
for l, r in LR:
    counts[l, r] += 1
cum = counts.cumsum(axis=1).cumsum(axis=0)

for p, q in PQ:
    ans = cum[q, q] - cum[p - 1, q] - cum[q, p - 1] + cum[p - 1, p - 1]
    print(ans)


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

int main() {
  long n, k;
  cin >> n >> k;

  long num = n, amari = 0, ans = 0;

  while(num > 0){
    amari = num % k; 
    num /= k;
    ans ++ ;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
answer = [0] * N

totalRain = sum(A)

answer[0] = totalRain
for i in range(1,N-1,2):
    answer[0]-=A[i]*2


for i in range(N-1):
    if i+1 != N:
        answer[i+1] = (A[i]*2) - answer[i]

print(answer[0], end="")
for i in range(1, N):
    print("",answer[i], end="")

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

int main() {
    int n, r;
    while (cin >> n >> r) {
        cout << r + 100 * max(0, 10-n) << endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main() {
    int n; cin >> n;
    bool ok = true;
    for (int i = 0; i < n; i++) {
        int tmp; cin >> tmp;
        if (tmp % 2 == 0) {
            if (tmp % 3 != 0 && tmp % 5 != 0) {
                ok = false;
                break;
            }
        }
    }
    if (ok) cout << "APPROVED\n";
    else cout << "DENIED\n";
}

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

typedef long long LL;
const int N = 1e5;

int n,q;
LL li[N+5];
LL pso[N+5];
LL ps[N+5];

int main(){
   scanf("%d%d",&n,&q);
   for(int i=1;i<=n;i++) scanf("%lld",&li[i]),ps[i]=ps[i-1]+li[i];
   for(int i=2;i<=n;i+=2) pso[i] = pso[i-2]+li[i];
   while(q--){
      int x;
      scanf("%d",&x);
      int l = 1;
      int r = n;
      int id = 0;
      while(l<=r){
         int mid = (l+r)/2;
         if(li[mid] > x){
            r = mid-1;
         } else {
            id = mid;
            l = mid+1;
         }
      }
//      cout << ">>> " << id << endl;
      l = min(n,max(id,n/2));
      r = n;
      int ans = l-1;
      while(l<=r){
         int mid = (l+r)/2;
//         cout << "mid = " << mid << endl;
         int tmp = n-mid;
         int ud = mid-id;
         int sisa = tmp-ud;
         int idd = id-sisa+1;
         idd = min(id,idd);
         int dif = x-li[idd+1];
         if(dif <= abs(li[mid+1]-x)){
            ans = mid;
            r = mid-1;
         } else {
            l = mid+1;
         }
      }
//      cout << ">> " << ans << endl;
      LL jaw = ps[n] - ps[ans];
      int tmp = n-ans;
      int idd = max(0,ans-tmp);
      if(idd%2==0) jaw+=pso[idd];
      else jaw+=ps[idd]-pso[idd-1];
      printf("%lld\n",jaw);
   }
	return 0;
}


Measured memory_bytes: 4096
#include<iostream>
int main()
{
	std::string s;
  	std::cin >> s;
  	if(s[0] == s[1] && s[1] == s[2])
    {
      std::cout << "No\n";
    }
  	else
    {
      std::cout << "Yes\n";
    }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int64_t,int64_t> pll;
typedef vector<int64_t> vl;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
const long double PI = acos(-1);
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define ALL(a) begin(a),end(a)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

void solve() 
{
    int n;cin>>n;
    map<string,int>s;int t[n];
    REP(i,n){
        string ss;int tt;cin>>ss>>tt;
        s[ss]=i;t[i]=tt;
    }
    string x;cin>>x;
    int j=s[x];
    j++;int ans=0;
    for(;j<n;j++){
        ans+=t[j];
    }cout<<ans<<endl;
}
int main()
{
    cin.tie(0);
	ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
money=1000
stock=0

for i in range(n-1):
    if A[i]<A[i+1]:
        stock+=money//A[i]
        money=money%A[i]
    elif A[i]>A[i+1]:
        money+=stock*A[i]
        stock=0
print(money+stock*A[n-1])

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N;
  cin >>N;
    int ans = 0;
    for (int i = 1; i < N+1; i++) {
        if (1 <= i and i <= 9) ans++;
        else if (100 <= i and i <= 999) ans++;
        else if (10000 <= i and i <= 99999) ans++;
    }
  cout << ans <<endl;
 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    string s,t;cin>>s>>t;
    int a,b;cin>>a>>b;
    string u;cin>>u;
    if(s==u) a--;
    else b--;
    cout<<a<<' '<<b<<endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

vector<ll> points;
vector<int> where;

ll point(int num) {
    return points[where[num]];
}

int main() {
    while (true) {
        int n, m, h, k;
        cin >> n >> m >> h >> k;
        if (n == 0)break;

        points = vector<ll>(n);
        for (int i = 0; i < n; i++)cin >> points[i];

        vector<vector<int>> bars(h);
        for (int i = 0; i < m; i++) {
            int a, b;
            cin >> a >> b;
            bars[b].push_back(a - 1);
        }

        vector<int> order(n);
        for (int i = 0; i < n; i++)order[i] = i;
        vector<vector<int>> change(n);
        for (int i = 0; i < h; i++) {
            for (auto bar:bars[i]) {
                auto l = order[bar];
                auto r = order[bar + 1];

                swap(order[bar], order[bar + 1]);
                change[l].push_back(r);
                change[r].push_back(l);
            }
        }

        where = vector<int>(n);
        for (int i = 0; i < n; i++) where[order[i]] = i;


        ll sum = 0;
        for (int i = 0; i < k; i++)sum += point(i);

        ll ret = sum;
        for (int i = 0; i < k; i++) {
            for (auto x:change[i]) {
                if (0 <= x && x < k)continue;

                ll tmp = sum + point(x) - point(i);
                ret = min(ret, tmp);
            }
        }

        cout << ret << endl;
    }
    return 0;
}


Measured memory_bytes: 4500
import java.util.*;

public class Main {
	static class TriTree {
		Node root = new Node();
		
		class Node {
			ArrayList<Node> child = new ArrayList<>();
			char c;
			long depth;
			public void add(Node node) {
				child.add(node);
			}
			public Node() {
				
			}
			public Node(char c, long depth) {
				this.c = c;
				this.depth = depth;
			}
			public long xorGrundy() {
				long xor=0;
				for(Node node : child)
					xor ^= node.xorGrundy();
				if(child.size()==1)
					xor ^= grundy(L - depth);
				return xor;
			}
		}
		
		public void addLeaf(String s) {
			Node cur = root;
			for(int i=0; i<s.length(); i++) {
				boolean found = false;
				for(Node child : cur.child) {
					if(child.c==s.charAt(i)) {
						cur = child;
						found = true;
						break;
					}
				}
				if(!found) {
					Node next = new Node(s.charAt(i), i+1);
					cur.add(next);
					cur = next;
				}
			}
		}
		
		public long xorGrundy() {
			return root.xorGrundy();
		}
	}
	
	static long L;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		L = sc.nextLong();
		TriTree tree = new TriTree();
		for(int i=0; i<N; i++)
			tree.addLeaf(sc.next());

		System.out.println(tree.xorGrundy()==0 ? "Bob" : "Alice");
		sc.close();
	}
	
	static long grundy(long n) {
		long ans=1;
		while(n%ans==0)
			ans<<=1;
		return ans;
	}
	
}


Measured memory_bytes: 70676
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long b[100] = { 0 }, b1[100] = { 0 };
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		long long a, co = 1;
		cin >> a;
		bitset<61>bs(a);
		for (int j = 0; j < 61; j++) {
			if (bs[j]) {
				b1[j]++;
			}
			else {
				b[j]++;
			}
		}
	}
	long long ans = 0, two = 1;
	for (int k = 0; k < 61; k++) {
		ans += b[k] * b1[k] % 1000000007 * two % 1000000007;
		two = two * 2 % 1000000007;
		ans = ans % 1000000007;
	}
	cout << ans % 1000000007 << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int a,b,c;

int main()
{
    cin >> a >> b >> c;
    
    if(a < b && b < c)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<long> A(N+1,0); 
    map<long,long> mp; mp[0]++;
    for(int i=1;i<=N;i++) cin >> A[i],A[i] += A[i-1],mp[A[i]]++;
    long ans = 0;
    for(auto p : mp) ans += p.second * (p.second-1L) / 2L;
    cout << ans << endl;
}

Measured memory_bytes: 14336
import collections

n = int(input())
s = [input() for i in range(n)]
c = collections.Counter(s)
m = c.most_common()

maxn = m[0][1]
ans = []

ans.append(m[0][0])
for i in range(len(m)-1):
    if m[i+1][1] == maxn:
        ans.append(m[i+1][0])
    else:
        break
for i in sorted(ans):
    print(i)


Measured memory_bytes: 49176
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------


int N, K;
//4 3
void _main() {
	cin >> N >>K;
	//4回の操作の内、操作を分割して考え、それぞれで小さくなるものを選ぶ
	int ans = 1;
	rep(i, 0, N) {
		if (ans * 2 < ans + K) {
			ans *= 2;
		}
		else {
			ans += K;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    string s, t;
    cin >> s >> t;
    vector<ll> cs(26, 0), ct(26, 0); 
    rep(i, 0, s.size()){
        cs[s[i]-'a']++; 
        ct[t[i]-'a']++;
    }
    sort(cs.begin(),cs.end());
    sort(ct.begin(),ct.end());
    rep(i, 0, 26){
        if(cs[i] != ct[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 776
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	long long k, q;
	cin >> k >> q;

	vector<long long> dlist(k, 0);
	for (int i = 0; i < k; i++)
	{
		cin >> dlist[i];
	}

	for (int i = 0; i < q; i++)
	{
		long long n, x, m;
		cin >> n >> x >> m;

		long long period_k_count = (n - 1) / k;
		long long remain_sum = 0;

		for (int j = 0; j < k; j++)
		{
			if (dlist[j] % m == 0)
			{
				remain_sum += m;
			}
			else
			{
				remain_sum += dlist[j] % m;
			}
		}

		remain_sum = x % m + remain_sum * period_k_count;

		for (int j = 0; j < (n - 1) % k; j++)
		{
			if (dlist[j] % m == 0)
			{
				remain_sum += m;
			}
			else
			{
				remain_sum += dlist[j] % m;
			}
		}

		cout << (n - 1) - remain_sum / m << "\n";
	}
	
	return 0;
}

Measured memory_bytes: 384
class Node
  attr_accessor :parent, :rank

  def initialize
    @parent = -1
    @rank = 0
  end
end

class UnionFindTree
  def initialize(n)
    @nodes = (0..n).to_a.map { |i| Node.new }
  end

  def find(x)
    return @nodes[x].parent < 0 ? x : @nodes[x].parent = find(@nodes[x].parent)
  end

  def unite(a, b)
    a = find(a)
    b = find(b)
    return if a == b

    if @nodes[a].rank < @nodes[b].rank
      # p [@nodes[a].parent , @nodes[b].parent]
      @nodes[b].parent += @nodes[a].parent
      @nodes[a].parent = b
    else
      # p [@nodes[a].parent , @nodes[b].parent]
      @nodes[a].parent += @nodes[b].parent
      @nodes[b].parent = a
      @nodes[a].rank += 1 if @nodes[a].rank == @nodes[b].rank
    end
  end

  def same?(a, b)
    find(a) == find(b)
  end
  
  def size(a)
    -@nodes[find(a)].parent
  end

  # 確認用。アルゴリズムとは関係無い
  def parents
    @nodes.map(&:parent)
  end
end

# n, q = gets.split.map(&:to_i)

# uft = UnionFindTree.new(n)
# q.times do |i|
  
#   com, x, y = gets.split.map(&:to_i)
  
#   if com == 0
#     uft.unite(x, y)
#   else
#     puts uft.same?(x, y) ? "Yes" : "No"
#     p [uft.size(x), uft.size(y)]
#   end
# end


N, M = gets.split.map(&:to_i)

class Bridge
  attr_accessor :first, :second

  def initialize
    @first = nil
    @second = nil
  end
  
  def nodes=(a)
    a[0], a[1] = a[1], a[0] if a[0] > a[1]
    @first = a[0]
    @second = a[1]
  end
  
end

bridges = (0...M).to_a.map { Bridge.new }

M.times do |i|
  tmp = gets.split.map(&:to_i)
  a = tmp[0]
  b = tmp[1]
  a -= 1
  b -= 1
  a, b = b, a if a > b
  bridges[i].nodes = [a,b]
end
# p bridges

f = Array.new(N, N)
ans = Array.new(M, 0)

inco = N * ( N - 1 ) / 2 # inconvenience
# p ["inco", inco]

n = N
q = M

uft = UnionFindTree.new(n)
# p [uft.find(0), uft.find(1), uft.find(2), uft.find(3)]

q.times do |i|
  
  j = (M-1)-i
  ans[j] = inco
  
  x, y = bridges[j].first, bridges[j].second
  
  # p uft.same?(x, y)

  if !uft.same?(x, y)
    
    # p q = uft.find(x)
    # p r = uft.find(y)
    
    inco -= uft.size(x) * uft.size(y)
  
  end
  
  break if inco == 0
  
  uft.unite(x, y)
  
end

puts ans


Measured memory_bytes: 20220