akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int mod =  1000000007;
const int LIM = 100005;
#define int long long
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(a) a.begin() , a.end()
#define vvi vector<vector<int>>
//#define double long double
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define endl '\n'
#define pb push_back
#define sp <<" "<<
#define ss second
#define ff first
int power(int x, int n){
    int res = 1;
    while(n){
          if(n&1){
                res = res * x % mod;
          }
          x = x * x % mod;
          n>>=1;
    }
    return res;
}

int32_t main()
{     //IOS;
      int tt=1,n,k,x,y,z,i,j;
      //cin>>tt;
      while(tt--)
      {int d;
        cin>>n>>d;
        int cnt=0;
        while(n--)
        {
          cin>>x>>y;
          if(x*x + y*y <=d*d)
          cnt++;
        }
        cout<<cnt;
      }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> D(N), A(N);
  for(auto& i: D) cin >> i;
  for(auto& i: A) cin >> i;

  vector<map<vector<int>, int>> dp(N);
  dp[0][{0}] = 0;
  for(int i = 0; i < N - 1; ++i) {
    for(const auto& data: dp[i]) {
      auto S = get<0>(data);
      auto cost = get<1>(data);
      for(int pos = 0; pos <= S.size(); ++pos) {
        auto T = S;
        T.insert(begin(T) + pos, i + 1);
        auto add = 0;
        for(int j = 0; j < T.size(); ++j) {
          if(j < pos) if(T[pos] - T[j] <= D[T[j]])   add += A[T[j]];
          if(pos < j) if(T[pos] - T[j] <= D[T[pos]]) add += A[T[pos]];
        }
        if(7 < T.size()) T.erase(min_element(begin(T), end(T)));
        dp[i + 1][T] = max(dp[i + 1][T], cost + add);
      }
    }
  }
  cout << get<1>(*max_element(begin(dp.back()), end(dp.back()), [](const auto& lhs, const auto& rhs){return get<1>(lhs) < get<1>(rhs);})) << endl;
}

Measured memory_bytes: 62412
#include <bits/stdc++.h>
using namespace std;
using Vb = vector<bool>;
using G = vector<Vb>;
#define rep(i, ss, ee) for (int i = (ss); i < (ee); ++i)

void solve() {
  int N, M;
  cin >> N >> M;

  G g(N, Vb(N, false));

  rep(i, 0, M) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g[u][v] = true;
    g[v][u] = true;
  }

  vector<int> p(N);
  rep(i, 0, N) p[i] = i;

  int ans = 0;
  do {
    if (p[0] != 0) break;
    bool ok = true;
    rep(i, 1, N) {
      if (!g[p[i - 1]][p[i]]) {
        ok = false;
        break;
      }
    }

    if (ok) ans++;
    // if (ok) {
    //   rep(i, 0, N) cout << p[i] << " ";
    //   cout << endl;
    // }
    
  } while (next_permutation(p.begin(), p.end()));

  cout << ans << endl;
}

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

Measured memory_bytes: 3656
def examA():
    N, A, B = LI()
    ans = inf
    if abs(A-B)%2==0:
        ans = abs(A-B)//2
    cur = min((A+B-1)//2,(2*N-A-B+1)//2)
    ans = min(ans,cur)
    print(ans)
    return

def examB():
    return

def examC():
    return

def examD():
    return

def examE():
    return

def examF():
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examA()


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

using namespace std;
typedef long long lint;
typedef long double ldb;
typedef unsigned long long uli;

#define X first
#define Y second
#define F(i, l, r) for(auto i = l; i != r; i++)
#define Df(i, l, r) for(auto i = l; i != r; i--)
#define I(i, a) for(auto i : a)
#define pb push_back
#define rs resize
#define mk make_pair
#define asg assign
#define all(x) x.begin(),x.end()
#define ret return
#define cont continue
#define brk break
#define ins insert
#define era erase
#define fi0(x) memset(x, 0, sizeof(x))
#define y1 adjf

int n;
string s, t;

int main(){
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> s >> t;
	int com = 0;
	F(i, 1, n + 1){
		if(s.substr((int)s.length() - i) == t.substr(0, i))com = i;
	}
	string ans = s;
	string left = t.substr(com);
	ans += left;
	cout << ans.length() << endl;
	ret 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, x;
  cin >> a >> b;
  if ((a + b) % 2 == 0) {
    x = (a + b) / 2;
  } else {
    x = (a + b) / 2 + 1;
  }
  cout << x << endl;
  
}

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


using namespace std;

const int MAXN = 100 * 1000 + 13;






int n, a[MAXN], ans;
set<int> s[2];


int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i], s[i & 1].insert(a[i]);
	sort(a, a + n);
	for (int i = 0; i < n; i++)
		if (s[i & 1].find(a[i]) == s[i & 1].end())
			ans++;
	cout << (ans >> 1) << endl;
	return 0;
}

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

int main()
{
  long n, s = 0;
  cin >> n;
  vector<long> a(n + 1), b(n);
  for (long i = 0; i < n + 1; i++) cin >> a.at(i);
  for (long i = 0; i < n; i++) cin >> b.at(i);
  for (long i = 0; i < n; i++) {
    long m = min(a.at(i), b.at(i));
    b.at(i) -= m;
    s += m;
    long m2 = min(a.at(i + 1), b.at(i));
    a.at(i + 1) -= m2;
    s += m2;
  }
  cout << s << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define INF 1e18
using namespace std;

int main() {
	int n, w;
	cin >> n >> w;
	vector<long long int> weight(n), value(n);
	long long int sum_val = 0;
	for(int i = 0; i < n; i++){
		cin >> weight[i] >> value[i];
		sum_val += value[i];
	}
	vector<long long int> dp(sum_val + 1, INF);
	dp[0] = 0;
	for(int i = 0; i < n; i++){
		for(int j = sum_val - value[i]; j >= 0; --j){
			dp[j + value[i]] = min(dp[j + value[i]], dp[j] + weight[i]);
		}
	}
	long long int ans = 0;
	for(int i = 0; i <= sum_val; i++){
		if(dp[i] <= w)
			ans = max(ans, (1LL)*i);
	}
	cout << ans << "\n";
	return 0;
}

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

int main() {
  int H,A;
  cin >> H >> A;
  if (H % A == 0) {
    cout << H / A << endl;
  } else {
    cout << H / A + 1 << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

bool is_prime(int64_t x) {
  for(int64_t i = 2; i * i <= x; i++) {
    if(x % i == 0) return false;
  }
  return true;
}

int main(void) {
    int X;
    cin >> X;
    for(int i=X; ; i++) {
        if(is_prime(i)) {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

vvl G;
vl c;
vl d;
ll id = 0;

void dfs(ll v, ll p = -1) {
    // 行きの処理はこのへんに書く
    d[v] = c[id];
    id++;
    for(auto u : G[v]) {
        if(u == p) {
            continue;
        }
        dfs(u, v);
        // 帰りの処理はこのへんに書く
    }
}

int main() {
    ll n;
    cin >> n;    

    G.resize(n);
    rep(i, n-1) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].pb(b);
        G[b].pb(a);
    }

    c.resize(n);
    rep(i, n) {
        cin >> c[i];
    }
    sort(rall(c));

    ll M = 0;
    exrep(i, 1, n-1) {
        M += c[i];
    }

    out(M);
    
    d.resize(n);
    dfs(0);

    for(auto x : d) {
        cout << x << " ";
    }

    cout << endl;
    re0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        sc.close();

        if(Math.abs(a-x) < Math.abs(b-x)) {
            System.out.println("A");
        } else {
            System.out.println("B");
        }
    }
}


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

int main(){
  ll N;cin >> N;
  vector<ll> A(N), B(N), C(N);
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  for(int i = 0; i < N; i++){
    cin >> B[i];
  }
  for(int i = 0; i < N; i++){
    cin >> C[i];
  }
  sort(A.begin(), A.end());
  sort(C.begin(), C.end());
  ll ans = 0;
  for(int i = 0; i < N; i++){
    ll x = 1;
    x *= N - (upper_bound(C.begin(), C.end(), B[i]) - C.begin());
    x *= lower_bound(A.begin(), A.end(), B[i]) - A.begin();
    ans += x;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2688
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		for(;scanner.hasNext();)
		{
			int c = scanner.nextInt() + scanner.nextInt();
			int s = 0;
			for(; c>0; c/=10, s++);
			
			System.out.println(s+"");
		}
	}
}

Measured memory_bytes: 26348
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000000000
using namespace std;
typedef long long ll;

int main(){
  int n;  cin >> n;
  vector<map<char, int>> vec(n);
  string alph = "abcdefghijklmnopqrstuvwxyz";
  string s="";
  rep(i, 0, n){
    string tmp; cin >> tmp;
    for(auto c:tmp){
      vec[i][c]++;
    }
  }
  for(auto c:alph){
    int m = 100100100;
    rep(i, 0, n){
      m = min(m, vec[i][c]);
    }
    rep(i, 0, m)  s+=c;
  }
  sort(all(s));
  cout << s << endl;
  return 0;
}

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

#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}

int main(void){
    int h,w;
    cin>>h>>w;
    vector<vector<char>> g(h,vector<char>(w));
    vector<vector<int>> cnt(h,vector<int>(w));
    queue<pair<int,int>> q;
    vector<vector<bool>> visited(h,vector<bool>(w));
    rep(i,0,h){
        rep(j,0,w){
            cin>>g[i][j];
            if(g[i][j]=='#'){
                q.push(make_pair(i,j));
                visited[i][j]=true;
            }
        }
    }
    int dx[4]={0,1,0,-1};
    int dy[4]={-1,0,1,0};
    while(!q.empty()){
        pair<int,int> pos=q.front();q.pop();
        for(int i=0;i<4;i++){
            int nx=pos.first+dx[i];
            int ny=pos.second+dy[i];
            if(nx<0||ny<0||nx>=h||ny>=w || visited[nx][ny])continue;
            visited[nx][ny]=true;
            q.push(make_pair(nx,ny));
            cnt[nx][ny]=cnt[pos.first][pos.second]+1;
        }
    }
    int ans=0;
    rep(i,0,h){
        rep(j,0,w){
            ans=max(ans,cnt[i][j]);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
  string s;
  cin>>s;
  int ans=0;
  for(int i=0;i<s.length()-1;i++)
    if(s[i]!=s[i+1])
     ans++;
  cout<<ans<<"\n";
  return 0;
}


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

struct cmp {
	int mod;
	cmp(int x) :mod(x) {}
	bool operator()(const int& a, const int& b)const {
		return a % mod < b % mod;
	}
};

int main() {
	int n; cin >> n;
	vector<int>a(n), b(n); for (auto&& x : a)cin >> x; for (auto&& x : b)cin >> x;

	int ans = 0;
	for (int i = 0; i < 30; i++) {
		sort(b.begin(), b.end(), cmp(1 << i));
		bool btoggle = false;
		for (int j = 0; j < n; j++) {
			btoggle ^= (b[j] >> i) & 1;
		}
		for (int j = 0; j < n; j++) {
			int v = (1 << i) - (a[j] % (1 << i)) - 1;
			int pos = upper_bound(b.begin(), b.end(), v, cmp(1 << i)) - b.begin();
			int pv = (a[j] >> i) & 1;
			bool toggle = (pv ? pos & 1 : (n - pos) & 1);
			toggle ^= btoggle;
			if (toggle)ans ^= (1 << i);
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long N;
    cin >>N;
    string S[300];
    long long res=0;
    bool ok=true;
    bool ha=true;
    for (int i = 0; i < N; i++) {
        cin >>S[i];
    }
    for (int i = 1; i < N; i++) {
        ha= ha && S[i]==S[i-1];
    }
    if(ha){
        std::cout << N*N << std::endl;
        return 0;
    }
    for (int i = 0; i < N; i++) {
        ok=true;
        for (int j = 0; j < N; j++) {
            for (int l = 0; l < N; l++) {
                if(j!=l){
                    if(S[(j+i)%N][l]!=S[(l+i)%N][j]){
                        ok=false;
                    }
                }
            }
        }
        if(ok){
            res+=N;
        }
    }
    std::cout << res << std::endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
    using namespace std;
    int main(){
    string s;
    cin >> s;
    if(s =="SUN") cout<<"7"<<endl;
    if(s =="MON") cout<<"6"<<endl;
    if(s =="TUE") cout<<"5"<<endl;
    if(s =="WED") cout<<"4"<<endl;
    if(s =="THU") cout<<"3"<<endl;
    if(s =="FRI") cout<<"2"<<endl;
    if(s =="SAT") cout<<"1"<<endl;
    return 0;
    }

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

#define ll long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

int main(){
	fastio
	ll n;
	cin >> n;
	ll arr[n];
	ll zero = 0;
	for(int i = 0;i < n;i++){
		cin >> arr[i];
		if(arr[i]==0) zero++;
	}
	if(zero!=0){
		cout << 0 << "\n";
		return 0;
	}
	ll prod = 1;
	for(auto x : arr){
		if(x<=((ll)1e18)/prod){
			prod *= x;
		}else{
			cout << -1 << "\n";
			return 0;
		}
	}
	cout << prod << "\n";
}

Measured memory_bytes: 4404
class BinaryIndexedTree:
    def __init__(self, size=10**7):
        self.size = size
        self.data = [0]*(size+1)

    def add(self, index, x):
        while index <= self.size:
            self.data[index] += x
            index += index & -index

    def prefix_sum(self, index):
        res = 0
        while index >= 1:
            res += self.data[index]
            index -= index & -index
        return res
    
    def interval_sum(self, left, right):
        return self.prefix_sum(right) - self.prefix_sum(left-1)

    def __getitem__(self, index):
        return self.sum(index) - self.sum(index-1)

    # def __setitem__(self, index, x):
    #     before = self.__getitem__(index)
    #     self.add(index, -before)
    #     self.add(index, x)

def main():
    from sys import stdin
    input = lambda: stdin.readline()
    LMIIS = lambda: list(map(int,input().split()))


    N,Q = LMIIS()
    # 1-indexedにするためリストの先頭に0を追加
    C = [0] + LMIIS()
    queries = []

    # 順番と一緒にクエリを保存
    for i in range(Q):
        l,r = map(int,input().split())
        queries.append((i,l,r))
    
    # rについてクエリをソート
    queries.sort(key=lambda x: x[2])

    # 玉の種類 -> 良い玉の場所
    good_ball_places = [0] * (N+1)

    # 場所 -> 良い玉が存在するなら1,しないなら0
    good_ball_exists = BinaryIndexedTree(N)

    #　玉の更新済み範囲
    k = 0
    # クエリの回答
    out = [0] * Q
    for order,l,r in queries:
        for i in range(k+1,r+1):
            # 位置iの玉の色
            color = C[i]
            # 色colorの良い玉の前の位置
            before = good_ball_places[color]
            # 色colorが既出なら、前の位置での存在を消去
            if 0 < before:
                good_ball_exists.add(before,-1)
            # 色colorの良い玉の位置はi
            good_ball_places[color] = i
            # 位置iに良い玉が存在
            good_ball_exists.add(i,1)
        # 良い玉を更新した範囲
        k = r
        # [l,r]に存在する良い玉の数の合計
        out[order] = good_ball_exists.interval_sum(l,r)
    print('\n'.join(map(str,out)))


        








    
main()

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

int jump(int ind, vector<int> &stone, vector<int> &dp, int k) {

	if (ind <= 0) {
		return 0;
	}

	if (dp[ind] != -1) {
		return dp[ind];
	}

	long low = abs(stone[ind] - stone[ind - 1]) + jump(ind - 1, stone, dp, k);
	long high = INT_MAX;

	for (int j = 2; j <= k; j++) {

		if (ind - j >= 0) {
			long temp = abs(stone[ind] - stone[ind - j]) + jump(ind - j, stone, dp, k);
			high = min(high, temp);
		}
	}

	dp[ind] = min(low, high);

	return dp[ind];
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k;
	cin >> n >> k;

	vector<int>stone(n);
	vector<int>dp(n, -1);

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

	int answer = jump(n - 1, stone, dp, k);

	cout << answer << endl;

	return 0;
}

Measured memory_bytes: 13452
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;

int main(){
  string S;
  ll K;
  cin>>S>>K;
  ll n=S.size();
  int N;
  if(n>K){
    N=K;
  }else{
    N=n;
  }
  char ans='1';
  for(int i=0;i<N;i++){
    if(S.at(i)!='1'){
      ans=S.at(i);
      break;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))
mod2 = [i for i in a if i % 2 == 0]
mod4 = [i for i in mod2 if i % 4 == 0]
m2len = len(mod2)
m4len = len(mod4)
if (N-m2len+m4len+(1 if (m2len-m4len) > 0 else 0))//2 <= m4len:
    print('Yes')
else:
    print('No')

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

int L, sz = 0;
struct Edge { int u, v, w; };
vector<Edge>E;

int main() {
	cin >> L; L--;
	if (L == 1) {
		cout << "2 2" << endl << "1 2 1" << endl << "1 2 0" << endl;
		return 0;
	}
	while ((1 << sz) <= L)sz++;
	int S = 1, T = sz;
	for (int i = 1; i < sz; i++) {
		E.push_back({ i,i + 1,1 << (sz - i - 1) });
		E.push_back({ i,i + 1,0 });
	}
	int w = 0;
	w = 1 << (sz - 1);
	for (int p = sz - 2, i = 1; p >= 0; p--, i++) {
		if (L >> p & 1) {
			E.push_back({ S,i + 1,w });
			w += 1 << p;
		}
	}
	E.push_back({ S,T,L });
	cout << sz << ' ' << E.size() << endl;
	for (auto&& t : E)cout << t.u << ' ' << t.v << ' ' << t.w << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
 
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	String str = sc.nextLine();
	String[] data = str.split(" ");
	int a = Integer.parseInt(data[0]);
	int b = Integer.parseInt(data[1]);
	System.out.println(a * b + " " + (a + b) * 2);
    }
 
}


Measured memory_bytes: 26116
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        StringBuilder sb = new StringBuilder(str);
        int count = sc.nextInt();

        for(int i=0; i < count; i++){
        	String op = sc.next();
        	int a = sc.nextInt();
        	int b = sc.nextInt() + 1;

        	if(op.equals("print")){
         		System.out.println(sb.substring(a, b));
        	}
        	if(op.equals("replace")){
        		String tmp = sc.next();
        		sb.replace(a, b, tmp);
        	}
        	if(op.equals("reverse")){
        		StringBuilder nwsb = new StringBuilder(sb.substring(a, b));
        		nwsb.reverse();
        		String nstr = nwsb.toString();
        		sb.replace(a, b, nstr);
        	}
        }
    }
}



Measured memory_bytes: 28968
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

const ll MAX = 1000000000000000000;

// 素因数分解
vector<pair<long long, int>> factorize(long long N)
{
  vector<pair<long long, int>> res;
  for (long long i = 2; i * i <= N; i++)
  {
    if (N % i != 0)
      continue;
    res.emplace_back(i, 0);
    while (N % i == 0)
    {
      N /= i;
      res.back().second++;
    }
  }
  if (N != 1)
    res.emplace_back(N, 1);
  return res;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  vector<pair<ll, int>> fac = factorize(N);
  int ans = 0;
  for (int i = 0; i < fac.size(); i++)
  {
    int tmp = 1;
    while (true)
    {
      if (fac[i].second >= tmp)
      {
        fac[i].second -= tmp;
        tmp++;
        ans++;
      }
      else
        break;
    }
  }
  cout << ans << endl;
  return 0;
}


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

long long n;
vector<long long> a;

long long solve();

int main() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0;
  for (int i = 1; i < n; ++i)
    if (a[i] > a[i - 1] + 1) return -1;
  if (a[0] != 0) return -1;
  for (int i = 1; i < n; ++i)
    if (a[i] - 1 == a[i - 1])
      ++res;
    else
      res += a[i];
  return res;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include<limits.h>
#include<stdio.h>
#include<cstring>
#include<string>
using namespace  std;
typedef long long ll;
typedef long double ld;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define fi first
#define se second
#define rsz(a,n) a.resize(n)
#define test(t) ll t;cin>>t;while(t--)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define fillv(a,k) memset(a,k,sizeof(a))
#define leadzero(a) __builtin_clz(a) //count leading zeros
#define trailzero(a) __builtin_ctz(a) //count trailing zeros
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln cout<<"\n"
// #define sp cout<<" "
#define spaceprint(a,i,s,n) {forsn(i,s,n) { cout<<a[i]; sp;}}
#define lineprint(a,i,s,n) {forsn(i,s,n) {cout<<a[i]; ln;}}
#define maxe(a) *max_element(a.begin(),a.end())
#define maxi(a) max_element(a.begin(),a.end())-a.begin()
#define mine(a) *min_element(a.begin(),a.end())
#define mini(a) min_element(a.begin(),a.end())-a.begin()
#define all(c) c.begin(),c.end()
#define trav(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element)  (find(all(container),element) != container.end())// check the presence of element
//copy(from_begin, from_end, to_begin); copy function
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<string> vs;
typedef vector<int> v32;
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
typedef map<ll,ll> m64;
const int LIM = 1e5+5, MOD =  1e9;
#define sumv(v) accumulate(all(v),ll(0))
#define productv(v) accumulate(all(v), ll(1), multiplies< ll >())
ll gcd(ll a, ll b) { if(b == 0) return a; return gcd(b, a % b); }
ll fastpowMOD(ll a, ll p,ll MOD){ if(p==0) return 1; ll z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }


bool compare (string s1,string s2)
{
	return s1.length()<s2.length();
}

vp64 v[100004];
ll dis[100004];
void dfs (ll i,ll p)
{
	if (i==1)
	{
		dis[1]=0;
	}
	else
	{
		ll cost;
		for (auto x:v[p])
		{
			if (x.fi==i)
			{
				cost=x.se;
				break;
			}
		}
		if (dis[p]==0&&cost&1)
			dis[i]=1;
		else if (dis[p]==0&&(cost&1)==0)
			dis[i]=0;
		else if ((dis[p]==1&&(cost&1)==1))
			dis[i]=0;
		else
			dis[i]=1;
	}
	for (auto x:v[i])
	{
		if (x.fi==p)
			continue;
		dfs(x.fi,i);
	}
}
int main()
{
	fast;
	ll n;
	cin>>n;
	for (ll i=0;i<n-1;i++)
	{
		ll x,y,z;
		cin>>x>>y>>z;
		v[x].pb({y,z});
		v[y].pb({x,z});
	}
	dfs(1,0);
	for (ll i=1;i<=n;i++)
		cout<<dis[i]<<endl;
	

}

Measured memory_bytes: 10240
n,m=map(int,input().split())
l=[-1]*n
check=False

for i in range(m):
    s,c=map(int,input().split())
    if n!=1 and s==1 and c==0:
        break
    if l[s-1]==-1 or l[s-1]==c:
        l[s-1]=c
    else:
        break
    if i==m-1:
        check=True
if n!=1 and l[0]==-1:
    l[0]=1

if m!=0 and check:
    for num in l:
        if num==-1:
            print(0,end='')
        else:
            print(num,end='')
elif n==1 and m==0:
    print(0)
elif m==0:
    print(10**(n-1))
else:
    print('-1')

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise fixed(cout);cout<<setprecision(16);
#define vb vector<bool>
using namespace std;

ostream& operator << (ostream &out, vector<int> &v) { for(auto a:v) out << a<<" "; out<<endl; }

const int maxn=100005;
vi G[maxn];
bool visited[maxn];
ll dp[maxn];

int dfs(int src)
{
    if(dp[src]) return dp[src];
    if(G[src].empty()) return dp[src]= 0;

    int len=0;

    for(auto v: G[src])
    {
        len = max( len , 1 + dfs(v) );
    }
    return dp [src] = len;
}

int main()
{
    fast_cin
    int n,m;

    cin>>n>>m;
    for(int i = 1 ; i <= m ; i++)
    {
        int u,v;
        cin >> u >> v;
        G[u].pb(v);
    }
    int lmax=0;
    for(int i=1;i<=n;i++)
    {
        lmax=max(lmax,dfs(i));
    }
    cout << lmax << endl;
}


Measured memory_bytes: 8576
import copy
import math
import time
import statistics
import math
import itertools
import bisect
from decimal import *


# a = get_int()
def get_int():
    return int(input())


# a = get_string()
def get_string():
    return input()


# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]


# a_list = get_string_list():
def get_string_list():
    return input().split()


# a, b = get_int_multi()
def get_int_multi():
    return map(int, input().split())


# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))


# print("{} {}".format(a, b))
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''


def main():
    start = time.time()

    n, k = get_int_multi()
    p = get_int_list()
    c = get_int_list()

    kaisuu = [-1] * n
    score = [0] * n
    score_max = [0] * n

    for i in range(n):
        wk = 0
        wk2 = 0
        ichi = i
        for ii in range(n):
            ichi = p[ichi] - 1
            wk += c[ichi]
            wk2 = max(wk2, wk)
            if i == ichi:
                kaisuu[i] = ii + 1
                score[i] = wk
                score_max[i] = wk2
                break

    wk = 0
    ans = - 10 ** 20
    for i in range(n):
        ichi = p[i] - 1
        wk = c[ichi]
        wk2 = c[ichi]
        idx = 0
        while idx < k - 1:
            ichi = p[ichi] - 1
            wk += c[ichi]

            wk2 = max(wk2, wk)
            idx += 1

            # ループするならメモを使って減らす
            if (k - 1 - idx > kaisuu[ichi] * 2) and kaisuu[ichi] > 0:
                roopsuu = ((k - 1 - idx) // kaisuu[ichi]) - 1
                wk += roopsuu * score[ichi]
                idx += roopsuu * kaisuu[ichi]
                wk2 = max(wk2, max(wk, score_max[ichi]))

        ans = max(ans, wk2)
    print(ans)


if __name__ == '__main__':
    main()



Measured memory_bytes: 79696
import math

convex_hull_list = []

def isRight_from_gaiseki(p,q,r):
    area = (q[0]-p[0])*(r[1]-p[1]) - (q[1]-p[1])*(r[0]-p[0])
    return area

if __name__ == '__main__':
    N_vertex = int(input())

    point_pairs = [(0,0)]*N_vertex

    # ue to sita de tukuru
    convex_hull = [(10001,10001)]*(2*N_vertex)

    # tengun wo point_pairs he irete iku
    for i in range(N_vertex):
        x,y = map(int, input().split())
        point_pairs[i] = (x,y)
    point_pairs = sorted(point_pairs, key=lambda x:(x[1],x[0]))
    if(N_vertex == 3):
        print(N_vertex)
        if(isRight_from_gaiseki(point_pairs[0],point_pairs[1],point_pairs[2]) == 0):
            point_pairs = sorted(point_pairs, key=lambda x:(x[0],x[1]))
            print("{0} {1}".format(point_pairs[0][0],point_pairs[0][1]))
            print("{0} {1}".format(point_pairs[1][0],point_pairs[1][1]))
            print("{0} {1}".format(point_pairs[2][0],point_pairs[2][1]))
        else:
            print("{0} {1}".format(point_pairs[0][0],point_pairs[0][1]))
            print("{0} {1}".format(point_pairs[1][0],point_pairs[1][1]))
            print("{0} {1}".format(point_pairs[2][0],point_pairs[2][1]))
    else:
        k = 0

        # gaiseki kara tugi no lower convex_hull youso sagasite ikuzo
        for i in range(0,N_vertex):
            while(k >= 2 and isRight_from_gaiseki(convex_hull[k-2],convex_hull[k-1],point_pairs[i])<0):
                k = k - 1
            convex_hull[k] = point_pairs[i]
            k = k + 1

        t = k + 1
        # gaiseki kara tugi no upper convex_hull youso sagasite ikuzo
        for i in range(N_vertex-1, 0, -1):
            #t = k + 1
            while(k >= t and isRight_from_gaiseki(convex_hull[k-2],convex_hull[k-1],point_pairs[i-1])<0):
                k = k - 1
            #k = k + 1
            convex_hull[k] = point_pairs[i-1]
            k = k + 1
        convex_hull_valid_num = k - 1
        print(convex_hull_valid_num)
        # result
        for i in range(0,convex_hull_valid_num):
            print("{0} {1}".format(convex_hull[i][0],convex_hull[i][1]))



Measured memory_bytes: 29264
program prob3
    implicit none
    integer(8) :: n, a, b, ans
    read(*,*) n,a,b
    if(mod(a+b, 2) == 0) then
        ans = (b-a) / 2
    else
        ans = min(2*n - (a+b) + 1, a+b-1)
        ans = ans / 2
    end if
    write(*,*) ans
    stop
contains
end program prob3

Measured memory_bytes: 2832
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define alpha_size 26

string s;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);    

    cin >> s;
    int ret = 0;
    int n = s.size();
    for (int i = 0; i < n / 2; i++){
      ret += s[i] != s[n - i - 1];
    }
    cout << ret << endl;
} 

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <queue>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a[LIMIT2]={0};
  char s[LIMIT1];
  queue<int> que;
  
  scanf("%s",s);
  n = strlen(s);
  rep(i,n-1){
    if(s[i]=='R'){
      que.push(i);
      if(s[i+1]=='L'){
        while(!que.empty()){
          j = que.front();
          que.pop();
          if(i%2==j%2) a[i]++;
          else a[i+1]++;
        }
      }
    }
  }
  per(i,n-1){
    if(s[i+1]=='L'){
      que.push(i+1);
      if(s[i]=='R'){
        while(!que.empty()){
          j = que.front();
          que.pop();
          if(i%2==j%2) a[i]++;
          else a[i+1]++;
        }
      }
    }
  }
  rep(i,n) cout << a[i] << (i==n-1 ? "\n" : " ");
  return 0;
}

Measured memory_bytes: 5832
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

h,w = inm()
c = [0]*26
for i in range(h):
    s = ins()
    for j in range(w):
        c[ord(s[j])-ord('a')] += 1
n1 = len([x for x in c if x%2==1])
n2 = len([x for x in c if x%4==2])

ddprint(c)
ddprint(n1)
ddprint(n2)

if h%2==0 and w%2==0:
    print('No' if n1>0 or n2>0 else 'Yes')
elif h%2==1 and w%2==1:
    k = w//2 + h//2
    print('No' if n1!=1 or n2>k else 'Yes')
else:
    k = 0
    if h%2==1:
        k = w//2
    if w%2==1:
        k += h//2
    print('No' if n1!=0 or n2>k else 'Yes')


Measured memory_bytes: 38640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;

  ll cnt = 0;

  while(b <= a) {
    b *= 2;
    cnt++;
  }
  while(c <= b) {
    c *= 2;
    cnt++;
  }

  if (cnt <= k) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3632
use proconio::input;

fn gcd(n: u64, m: u64) -> u64 {
    if n < m {
        gcd(m, n)
    } else if m == 0 {
        n
    } else {
        gcd(m, n % m)
    }
}

fn main() {
    input! {
        n: usize,
        x_start: u64,
        mut x: [u64; n],
    };
    if n == 1 {
        println!(
            "{}",
            if x[0] > x_start {
                x[0] - x_start
            } else {
                x_start - x[0]
            }
        );
        return;
    }
    x.sort();
    let mut d = x[1] - x[0];
    let mut p = x[0];
    for &x_i in x.iter() {
        d = gcd(d, x_i - p);
        p = x_i;
    }
    let ans = if x_start < x[0] {
        gcd(d, x[0] - x_start)
    } else if *x.last().unwrap() < x_start {
        gcd(d, x_start - x.last().unwrap())
    } else {
        let mut res = None;
        for (x_i0, x_i1) in x.windows(2).map(|w| match w {
            &[x_i0, x_i1] => (x_i0, x_i1),
            _ => unreachable!(),
        }) {
            if (x_i0..=x_i1).contains(&x_start) {
                res = Some(std::cmp::max(
                    gcd(d, x_i1 - x_start),
                    gcd(d, x_start - x_i0),
                ));
            }
        }
        res.unwrap()
    };
    println!("{}", ans);
}


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



int main() {
    string s; cin >> s;
    vector<ll> vec(s.size()+1, 0);
    ll m = 1;
    for (int i = s.size()-1; i >= 0; i--) {
        vec[i] = (vec[i+1] + m * (s[i] - '0')) % 2019;
        m *= 10;
        m %= 2019;
    }
    //for (int i = 0; i < s.size() + 1; i++) cout << vec[i] << " ";
    //cout << endl;
    sort(vec.begin(), vec.end());
    //for (int i = 0; i < s.size() + 1; i++) cout << vec[i] << " ";
    //cout << endl;
    ll tmp = vec[0], memo = 1, ans = 0;
    for (int i = 1; i < s.size() + 1; i++) {
        if (vec[i] == tmp) memo++;
        else {
            ans += memo * (memo-1) / 2;
            memo = 1;
            tmp = vec[i];
        }
    }
    ans += memo * (memo-1) / 2;
    cout << ans << endl;
}


Measured memory_bytes: 5228
import math

N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
cnt = 0

for i in range(N - 1):
    for j in range(i + 1, N):
        tmp = 0
        for k in range(D):
            tmp += ((X[i][k] - X[j][k])** 2)
        tmp = math.sqrt(tmp)
        if tmp.is_integer():
            cnt += 1

print(cnt)


Measured memory_bytes: 9048
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    while(true) {
        int n, m;
        cin >> n >> m;
        if(n == 0 && m == 0) {
            return 0;
        }
        vector<int> c(m), x(n);
        for(int i = 0; i < m; i++) {
            cin >> c[i];
        }
        for(int i = 0; i < n; i++) {
            cin >> x[i];
        }
        vector<vector<ll> > dp(n + 1, vector<ll>(256, LLONG_MAX / 3));
        dp[0][128] = 0;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < 256; j++) {
                for(int l = 0; l < m; l++) {
                    ll next = min(max(j + c[l], 0), 255);
                    dp[i + 1][next] =
                        min(dp[i + 1][next],
                            dp[i][j] + (next - x[i]) * (next - x[i]));
                }
            }
        }
        // cout << dp[1][132] << endl;
        cout << *min_element(all(dp[n])) << endl;
    }
}



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

int main(){
    int n, m; cin >> n >> m;
    vector<pair<long long, int>> shop(n);
    for(int i = 0; i < n; i++){
        cin >> shop.at(i).first >> shop.at(i).second;
    }
    sort(shop.begin(), shop.end());
    long long ans = 0;
    for(auto x : shop){
        long long price = x.first; int num = x.second;
        if(m >= num){
            ans += price * num;
            m -= num;
        }
        else{
            ans += price * m;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
from itertools import accumulate

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

a.sort()

b = list(accumulate(a))

point = 0

for i in range(n-1):
    if b[i]*2 >= a[i+1]:
        point += 1
    else:
        point = 0

print(point+1)

Measured memory_bytes: 20504
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int main(){

    int N;cin>>N;
    LL A[N];REP(i,N)cin>>A[i];
    LL ans=0;
    LL mm = 0;
    REP(i,N){
        ans+=A[i]/(mm+1);
        if(A[i]%(mm+1)==0)ans--;
        if(mm+1==A[i])mm++;
        if(i==0)mm=1;
    }
    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
signed main(){
int a,b;
  cin>>a>>b;
  vector<int> c(a);
  vector<bool> d(a,0);
  rep(i,a)
    cin>>c[i];
  double t=0;
  rep(i,a){
  t+=c[i];
  }
  double e=t/4/b;
  rep(i,a){
  if(c[i]>=e)
    d[i]=1;
  }
  int f=0;
  rep(i,a){
  if(d[i])
    f++;
  }
  if(f>=b)
    cout<<"Yes";
  else
    cout<<"No";
}

Measured memory_bytes: 256
#include <stdio.h>

int N, M, A[1123], B[1123];
int vote[1123], ans;

int main(void) {
	scanf("%d%d", &N, &M);
	for (int i = 0; i < N; ++i) { scanf("%d", &A[i]); }
	for (int i = 0; i < M; ++i) { scanf("%d", &B[i]); }

	for (int i = 0; i < M; ++i) {
		for (int j = 0; j < N; ++j) {
			if (A[j] <= B[i]) {
				vote[j]++;
				break;
			}
		}
	}
	for (int i = 0; i < N; ++i) {
		if (i == 0) { ans = i; }
		if (vote[ans] < vote[i]) { ans = i; }
	}

	printf("%d\n", ans + 1);
	return 0;
}

Measured memory_bytes: 2700
n = gets.strip.split.map(&:to_i).first

rests = []
n.times do |i|
  r = gets.strip.split
  rests << {
    id: i + 1,
    name: r[0],
    score: r[1].to_i
  }
end

puts rests.sort_by { |r| [r[:name], -r[:score]] }.map { |r| r[:id] }.join("\n")

Measured memory_bytes: 1788
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

typedef long long ll;

const ll mod=1e9+7;

#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define rc(x)  return cout<<x<<"\n",0
#define sz(s)  (int) s.size()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;

ll t,n,m,deg[100007],dist[100007],ans;
vector<int>v[100007]; 
bool viz[100007];

void dfs(int a) {
	viz[a]=true;
	for (int b: v[a]) {
		dist[b]=max(dist[b],dist[a]+1);
		deg[b]--;
		if (deg[b]==0) {
			dfs(b);
		}
	}
}

int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> m;


	for (int i=1; i<=m; i++) {
		ll x,y;
		cin >> x >>y;
		v[x].push_back(y);
		deg[y]++;
		
	}
	for (int i=1; i<=n; i++) {
		if (!viz[i] && deg[i]==0) {
			dfs(i);
		}
	}
	
	for (int i=1; i<=n; i++) {
		ans=max(ans,dist[i]);
	}
	cout << ans;

}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

string S, T, U;
int A, B;

int main(void){
	cin >> S >> T;
	cin >> A >> B;
	cin >> U;

	if(S == U) A--;
	if(T == U) B--;

	cout << A << ' ' << B << '\n';

	return 0;
}

Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        a: usize,
        b: usize,
        h: usize,
    }
    println!("{}", (a+b)*h/2);
}


Measured memory_bytes: 2124
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

long long pow_mod(long long n, long long p, long long m)
{
    if (p == 0) {
        return 1;
    }

    if (p % 2 == 0) {
        long long t = pow_mod(n, p / 2, m);
        return t * t % m;
    }
    return n * pow_mod(n, p - 1, m) % mod;
}

long long nCr_mod(long long n, long long r)
{
    long long x = 1;
    for (long long i = n - r + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }

    long long a = 1;
    for (long long i = 1; i <= r; i++) {
        a *= i;
        a %= mod;
    }

    long long y = pow_mod(a, mod - 2, mod) % mod;

    return x * y % mod;
}

bool is_prime(long long n)
{
    if (n == 1) {
        return false;
    }

    for (long long i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return false;
        }
    }

    return true;
}

int main()
{
    long long a, b;
    std::cin >> a >> b;

    std::cout << (a + b - 1) / b << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	char str[50];
	scanf("%s", str);
	int l = strlen(str);
	char ans = str[0];
	for (int i = 1; i < l && ans == str[0]; i++) {
		if (str[i] > str[i-1]) ans++;
		else if (str[i] < str[i-1]) break;
	}
	for (int i = 0; i < l; i++) {
		printf("%c", ans);
	}
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int num = 0;

    char c;
    char c0;
    // 整数の入力
//    scanf("%d", &n);
    c0 = getchar();
    while((c = getchar()) != EOF) {
        if (c0 == c) {
            num++;
            if (c == '0') {
                c0 = '1';
            }
            else {
                c0 = '0';
            }
        }
        else {
            c0 = c;
        }
    }
    
    // スペース区切りの整数の入力
//    scanf("%d %d",&b,&c);
    // 文字列の入力
//    scanf("%s",s);

    // 出力
    printf("%d\n", num);
//    printf("%d %s\n",a+b+c,s);
    return 0;
}



Measured memory_bytes: 128
N,K,*A=map(int,open(0).read().split())
a=0
b=0
for i in range(N):
    for j in range(N):
        if A[j]>A[i]:
            a+=1
            if j<i:
                b+=1
print((b*K+a*K*(K-1)//2)%(10**9+7))


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

int main() {
  int N;
  cin >> N;
  
   vector<vector<int>> data(2, vector<int>(N));
 
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < N; j++) {
      cin >> data.at(i).at(j);
    }
  }
  
  vector<int>A(N,0);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i > j){
        A.at(i) += data.at(0).at(j);
      }
      else if (i == j){
        A.at(i) += data.at(0).at(j) + data.at(1).at(j);
      }
      else if (i < j){
        A.at(i) += data.at(1).at(j);
      }
    }
  }
  sort(A.begin(), A.end());
  cout << A.at(N-1) << endl;
}
  



Measured memory_bytes: 3632