akhauriyash/Code-Regression huggingface dataset:
import sys
from heapq import heappush, heappop
n,q=map(int,input().split())
a=sorted(((s-x, t-x, x) for _ in range(n) for s, t, x in (map(int, sys.stdin.readline().split()),)), reverse=True)
heap=[]
ans=[]
z=list(map(int,sys.stdin))
for d in z:
  while a and a[-1][0]<=d:
    e=a.pop()
    heappush(heap,(e[2],e[1]))
  while heap and heap[0][1]<=d:
    heappop(heap)
  if heap:
    ans.append(heap[0][0])
  else:
    ans.append(-1)

print(*ans, sep='\n')



Measured memory_bytes: 62568
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;


int main() {
  ll a, b, m; cin >> a >> b >> m;
  vector<ll> aa(a), bb(b);
  rep(i, a) cin >> aa[i];
  rep(i, b) cin >> bb[i];
  ll ans = INF;
  rep(i, m) {
    ll x, y, c; cin >> x >> y >> c;
    chmin(ans, aa[x-1] + bb[y-1] - c);
  }
  sort(all(aa));
  sort(all(bb));
  chmin(ans, aa[0] + bb[0]);
  cout << ans << endl;
}


Measured memory_bytes: 1792
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

h,n=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
S=sum(A)
if h<=S:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 60400
from collections import deque
N, K = map(int, input().split())
S = deque(input())
T = []
P = []
pre = S[0]
cnt = 0
while S:
  s = S.popleft()
  cnt += 1
  if pre != s:
    cnt -= 1
    T += [cnt]
    P += [pre]
    pre = s
    cnt = 1
T += [cnt]
P += [pre]

cum_T = T[:]
for i in range(len(T)-1):
  cum_T[i+1] = cum_T[i] + T[i+1]

cum_T += [0]
l = len(P)
ans = 0
for i in range(l):
  if P[i] == '1':
    r = min(l-1, i+2*K)
    ans = max(ans,-cum_T[i-1]+cum_T[r] )
  else:
    r = min(l-1, i+2*K-1)
    ans = max(ans, -cum_T[i-1]+cum_T[r])
print(ans)

Measured memory_bytes: 60016
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <stack>
using namespace std;
typedef pair<char,char> pcc;
int W, H;
int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1};
pcc s1, s2, g1, g2;
bool R1[50][50], R2[50][50], memo[50][50][50][50];

bool dfs(pcc p1, pcc p2){
  stack< pair<pcc,pcc> > st;
  st.push(make_pair(p1,p2));
  while(!st.empty()){
    p1 = st.top().first, p2 = st.top().second;
    st.pop();
    for(int i = 0; i < 4; ++i){
      //int x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
      pcc p1_ = p1, p2_ = p2;
      if(p1_.first + dx[i] < H && p1_.first + dx[i] >= 0 &&
         p1_.second + dy[i] < W && p1_.second + dy[i] >= 0 &&
         R1[p1_.first + dx[i]][p1_.second + dy[i]]){
        p1_.first += dx[i];
        p1_.second += dy[i];
      }
      if(p2_.first + dx[i] < H && p2_.first + dx[i] >= 0 &&
         p2_.second - dy[i] < W && p2_.second - dy[i] >= 0 &&
         R2[p2_.first + dx[i]][p2_.second - dy[i]]){
        p2_.first += dx[i];
        p2_.second -= dy[i];
      }
      if(p1_ == g1 || p2_ == g2){
        memo[p1_.first][p1_.second][p2_.first][p2_.second] = true;
      }else if((!memo[p1_.first][p1_.second][p2_.first][p2_.second]) && (!memo[p1_.first][p1_.second][p2_.first][p2_.second])){
        memo[p1_.first][p1_.second][p2_.first][p2_.second] = true;
        st.push(make_pair(p1_,p2_));
      }
    }
  }
  return memo[g1.first][g1.second][g2.first][g2.second];
}

int main(){
  while(cin >> W >> H, W){
    string r1,r2;
    for(int i = 0; i < H; ++i){
      cin >> r1 >> r2;
      for(int j = 0; j < W; ++j){
        if(r1[j] == 'L'){
          s1.first = i;
          s1.second = j;
        }
        if(r2[j] == 'R'){
          s2.first = i;
          s2.second = j;
        }
        if(r1[j] == '%'){
          g1.first = i;
          g1.second = j;
        }
        if(r2[j] == '%'){
          g2.first = i;
          g2.second = j;
        }
        if(r1[j] != '#') R1[i][j] = true;
        else R1[i][j] = false;
        if(r2[j] != '#') R2[i][j] = true;
        else R2[i][j] = false;
      }
    }
    for(int i = 0; i < H; ++i){
      for(int j = 0; j < W; ++j){
        for(int k = 0; k < H; ++k){
          for(int l = 0; l < W; ++l){
            memo[i][j][k][l] = false;
          }
        }
      }
    }

    if(dfs(s1,s2)) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

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

int main()
{
  int N;
  cin>>N;
  int V[N][3];
  
  for(int i=0;i<N;i++)
  {
    cin>>V[i][0]>>V[i][1]>>V[i][2];
  }
  
  int Ans[N][3];
  Ans[N-1][0]=V[N-1][0];
  Ans[N-1][1]=V[N-1][1];
  Ans[N-1][2]=V[N-1][2];
  
  for(int i=N-2;i>=0;i--)
  {
    Ans[i][0]=V[i][0]+max(Ans[i+1][1],Ans[i+1][2]);
    Ans[i][1]=V[i][1]+max(Ans[i+1][0],Ans[i+1][2]);
    Ans[i][2]=V[i][2]+max(Ans[i+1][0],Ans[i+1][1]);
  }
  int m1=max(Ans[0][0],Ans[0][1]);
  m1=max(m1,Ans[0][2]);
  cout<<m1<<endl;
}

Measured memory_bytes: 5948
N = int(input())
s = list(map(int, input().split()))
hp1 = 0
for i in range(N):
    for j in range(N):
        if  i != j:
            hp1 += s[i]*s[j]
        else:
            hp1 += 0
hp2 = hp1/2
print(int(hp2))


Measured memory_bytes: 2940
N = int(input())
h = list(map(int,input().split()))

INF = float('inf')
dp = [INF] * N
dp[0] = 0
for i in range(1,N):
  dp[i] = min(dp[i], dp[i-1]+abs(h[i]-h[i-1]))
  if i > 1:
    dp[i] = min(dp[i], dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])


Measured memory_bytes: 13980
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //d
  int n;
  cin >> n;
  vector<long long> a(n);
  long long x = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i % 2 == 0) x += a[i];
    else x -= a[i];
  }
  vector<long long> ans(n);
  ans[0] = x;
  cout << ans[0];
  for (int i = 1; i < n; i++) {
    ans[i] = (a[i - 1] - ans[i - 1] / 2) * 2;
    cout << " " <<  ans[i];
  }
  cout << endl;
  return 0;
}

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

using namespace std;

vector<pair<int, int>> counter(vector<int> xs) {
    sort(xs.begin(), xs.end());
    vector<pair<int, int>> res;
    for (int i = 0; i < (int) xs.size(); ++i) {
        int j = i;
        while (j + 1 < (int) xs.size() && xs[j + 1] == xs[i]) {
            ++j;
        }
        res.push_back(make_pair(xs[i], j - i + 1));
        i = j;
    }
    sort(res.begin(), res.end(), [&](auto& p1, auto& p2) { return p1.second > p2.second; });
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> as(n/2), bs(n/2);
    for (int i = 0; i < n/2; ++i) {
        cin >> as[i] >> bs[i];
    }
    auto cs = counter(as), ds = counter(bs);
    if (cs[0].first != ds[0].first) {
        cout << (n - cs[0].second - ds[0].second) << endl;
    } else {
        if (cs.size() == 1) {
            cs.push_back(make_pair(-1, 0));
        }
        if (ds.size() == 1) {
            ds.push_back(make_pair(-1, 0));
        }
        int best = max(cs[0].second + ds[1].second, cs[1].second + ds[0].second);
        cout << (n - best) << endl;
    }
    return 0;
}


Measured memory_bytes: 1972
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long K,A,B;
  cin >> K >> A >> B;
  bool a = false;
  
  for(int i = A; i <= B; i++){
    if(i%K==0) a = true;
  }
  
  if(a){
    cout << "OK" << endl;
  }else{
    cout << "NG" << endl;
  }
}

Measured memory_bytes: 3620
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define rall(x) x.rbegin() , x.rend()
#define all(x) x.begin() , x.end()
#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 = ;
const ll m = 1e9 + 7;
#define singleCase
// #define multipleCase
ll n,freq[500];
string s;

ll subs(ll a , ll b) {
   return (((a % m) - (b % m)) + m) % m;
}

void work() {
   cin >> n;
   cin >> s;
   for (ll i = 0 ; i < n ; i++) {
      freq[s[i]]++;
   }
   ll sol = 1;
   for (char i = 'a' ; i <= 'z' ; i++) {
      (sol *= (freq[i] + 1)) %= m;
   }
   sol = subs(sol , 1);
   printf("%lld\n" , sol);
   return;
}

int main() {
   #ifdef multipleCase
      ll nQ; in(nQ);
      while (nQ--)
         work();
   #endif
   #ifdef singleCase
      work();
   #endif
   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: 3832
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int N;
    cin>>N;
    vector<int> a;
    map<int,int> mp;
    rep(i,N){
        int t;
        cin>>t;
        t /=400;
        if(t>=8){
            t=8;
        }
        a.push_back(t);
    }
    rep(i,N){
        if(mp.count(a[i])){
            mp[a[i]]++;
        }else{
            mp[a[i]]=1;
        }
    }
    int base=0;
    for(int i=0;i<=7;i++){
        if(mp[i]>0){
            base++;
        }
    }
    int ansmin=base;
    int ansmax=base;
    
    //最小を求める、base=0ならば答えは1,base!=0ならば答えはbase
    if(ansmin==0){
        ansmin=1;
    }

    //最大を求める、答えはbase+mp[8]
    ansmax+=mp[8];
    cout << ansmin << " " << ansmax << endl;
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
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; }
const ll INF = 1e18;

ll h,w,k;
ll X1,Y1,X2,Y2;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> h >> w >> k;
    cin >> X1 >> Y1 >> X2 >> Y2;
    X1--;Y1--;X2--;Y2--;
    vector<vector<char> >field(h+1,vector<char>(w+1));
    vector<vector<ll> > dist(h+1,vector<ll>(w+1));
    rep(i,h){
        rep(j,w){
            cin >> field[i][j];
            dist[i][j]=-1;
        }
    }
    queue<pair<ll,ll> >que;
    dist[X1][Y1]=0;
    int dx[4] = {1,0,-1,0};
    int dy[4] = {0,1,0,-1};
    que.push({X1,Y1});
    while(!que.empty()){
        ll xnow = que.front().first;
        ll ynow = que.front().second;
        que.pop();
        rep(dir,4){
            rep(i,k){//進めるマスは1~k
                ll xnx = xnow + dx[dir]*(i+1);
                ll ynx = ynow + dy[dir]*(i+1);
                if(xnx<0||xnx>=h)break;
                if(ynx<0||ynx>=w)break;
                if(field[xnx][ynx]=='@'){
                    break;
                }
                if(dist[xnx][ynx]!=-1&&(dist[xnx][ynx]<=dist[xnow][ynow]))break;
                if(dist[xnx][ynx]!=-1)continue;
                dist[xnx][ynx]=dist[xnow][ynow]+1;
                que.push({xnx,ynx});
            }
        }
    }
    cout << dist[X2][Y2] << endl;
    return 0;
}


Measured memory_bytes: 28528
import java.util.*;

class Main{
    static long MOD=1000000007;
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        final long n=sc.nextLong(), m=sc.nextLong(), k=sc.nextLong();
        sc.close();
        long inv3=modinv(3);
        long inv2=modinv(2);
        long[] ey={n-1, n, n+1, inv3, m, m};
        long[] ex={m-1, m, m+1, inv3, n, n};
        long Y=m(ey), X=m(ex);
        long C=comb(n*m-2, k-2);
        long[] ea={X+Y, C, inv2};
        long ans=m(ea);
        System.out.println(ans);
    }
    public static long m(long[] e){
        long res=1;
        for(long el:e) res=(res*el)%MOD;
        return res;
    }
    public static long modinv(long a){
        long b=MOD, u=1, v=0;
        long tmp;
        while(b>=1){
            long t=a/b;
            a-=t*b;
            tmp=a; a=b; b=tmp;
            u-=t*v;
            tmp=u; u=v; v=tmp;
        }
        u%=MOD;
        return u>=0?u:u+MOD;
    }
    public static long comb(long n, long r){
        if(n<r) return 0;
        r=Math.min(r, n-r);
        long res=1;
        for(int d=1;d<=r;d++){
            res*=n;
            res%=MOD;
            n--;
            res*=modinv(d);
            res%=MOD;
        }
        return res;
    }
}

Measured memory_bytes: 21844
m,d = map(int,input().split())

res = 0
for j in range(1,m+1):
    for i in range(1,d+1):
        d1 = i%10
        d2 = i//10
        if d1 >= 2 and d2 >= 2 and d1*d2 == j:
            res += 1
print(res)



Measured memory_bytes: 2940
#include<stdio.h>
int main(){
 int x1,x2,x3,x4;
 int g1,g2,g3,g4;
 int hit=0,blow=0;
 while(scanf("%d%d%d%d",&x1,&x2,&x3,&x4)!=EOF){
    scanf("%d%d%d%d",&g1,&g2,&g3,&g4);
	if(x1==g1)
	  hit++;
	if(x2==g2)
	  hit++;
	if(x3==g3)
	  hit++;
	if(x4==g4)
	  hit++;
	 if((g1!=x1)&&(g1==x2||g1==x3||g1==x4))
	   blow++;
	 if((g2!=x2)&&(g2==x1||g2==x3||g2==x4))
	   blow++;
	 if((g3!=x3)&&(g3==x1||g3==x2||g3==x4))
	   blow++;
	 if((g4!=x4)&&(g4==x1||g4==x3||g4==x3))
	   blow++;
	printf("%d %d\n",hit,blow);
	hit=0;
	blow=0;
	}
	return 0;
	}
	  

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

int main(){
    int N, M, A, B, C;
    string s1, s2;
    cin >> N;
    vector<pair<string, int>> res(N);
    rep(i, N){
        cin >> s1 >> A;
        res[i] = make_pair(s1, A * -1);
    }
    auto res_sorted = res;
    sort(all(res_sorted));
    for(auto x:res_sorted){
        rep(i, N){
            if(res[i].first == x.first && res[i].second == x.second) cout << i + 1 << endl;
        }
    }
} 

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
    int n, k;
    string s;
    int flag = 1;
    int count=0;
    cin >> n >> k >> s;





    vint a(1);
    rep(i, n){
        if(s[i]=='1'){
            if(flag==1){
                a[count]++;
            }
            else{
                a.push_back(0);
                flag=1;
                count++;
                a[count]++;
            }
        }
        else {
            if(flag==0){
                a[count]++;
            }
            else{
                a.push_back(0);
                flag =0;
                count++;
                a[count]++;
            }
        }
    }
    if(s.back()=='0') a.push_back(0);
    vint r(a.size()+1);
    r[0] = 0;
    for(int i = 1; i < a.size()+1; i++){
        r[i] = r[i-1] + a[i-1];
    }

    int max = 0;
loop:
    for(int i = 1; i+k*2<r.size() ; i +=2){
        if(max < r[i+k*2]-r[i-1])
            max = r[i+k*2]-r[i-1];

    }
    if(1+k*2>=r.size()){
        k--;
        goto loop; 
    }


    cout << max << endl;

    return 0;
}


Measured memory_bytes: 1272
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    a.sort(reverse=True)
    s = a[0]
    for i in range(n-2):
        s += a[(i>>1)+1]
    print(s)
    return

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


Measured memory_bytes: 92184
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int N,M; cin >> N >> M;
  int A = 100 * N + 1800 * M;
  cout << A * pow(2,M) << endl;
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    string s;
    cin>>s;
    vector<pair<string,int>>t;
    t.PB(MP("dream",5));   
    t.PB(MP("erase",5));
    t.PB(MP("eraser",6));
    t.PB(MP("dreamer",7));
    while(s.size()>0){
        int a=s.size();
        rep(i,4){
            if(s.substr(a-t[i].S)==t[i].F){
                s.erase(a-t[i].S);
                break;
            }
        }
        if(a==s.size()){cout<<"NO";return 0;}
    }
    if(s.size()==0){
         cout<<"YES";
         return 0;
    }
}

Measured memory_bytes: 512
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var ABC = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            Console.WriteLine(ABC[0] + ABC[1] >= ABC[2] ? "Yes" : "No");
        }
    }
}


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


public class Main{
    static long MOD = 1000000007;
    static long dp[] = new long[1 << 21];
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));

        // Start writing your solution here. -------------------------------------
        long MOD = 1000000007;
        //int t = sc.nextInt();
        int t = 1;
        while(t -- > 0)
        {
            int n = sc.nextInt(), m = sc.nextInt(), res = 0, sum = 0;
            int [] a = new int[n];
            for(int i = 0; i < n; i++) {
                a[i] = sc.nextInt();
                sum += a[i];
            }
            for(int aa : a)
                if(4 * m * aa >= sum)
                    res++;
            if(res >= m) out.println("Yes");
            else out.println("No");
            //for(int ii = 0; ii <= n; ii++) System.out.println(Arrays.toString(dp[ii]));
        }
        out.close();
    }
    public static int solve(int x, int[] a){
        int max = 0, n = a.length - 1;
        for(int i = 1; i <= n; i++)
            if(a[i] > max) max = a[i];
        return 0;
    }
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    //--------------------------------------------------------
}

Measured memory_bytes: 41684
function Main(num) {
    var paid = num * 800;
    var counter = 0;
    for (num; num >= 15; num -= 15) {
        counter += 1
    }
    var returned = (counter * 200);
    console.log(paid - returned);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for(const auto& e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void yn(bool j){cout << (j ? "Yes" : "No") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> long long bcount(T1 v, T2 a){return upper_index(v, a) - lower_index(v, a);} 
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> void sortTwoVecter(vector<T1> &f, vector<T2> &s, bool isReverse = false){
    vector<pair<T1, T2>> p;
    rep(i, f.size()) p.emplace_back(make_pair(f[i], s[i]));
    if (!isReverse) sort(p.begin(), p.end());
    else sort(p.rbegin(), p.rend());
    rep(i, f.size()) tie(f[i], s[i]) = p[i];
    return;
}

int main(){
    string S; cin >> S;
    ll N = S.size();
    ll ans = (N * (N + 1)) / 2 + 1;
    vector<ll> cnt(26, 0);
    rep(i, N) cnt[S[i] - 'a']++;
    rep(i, 26) ans -= (cnt[i] * (cnt[i] + 1)) / 2;
    pt(ans);
}

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

pair<int, int> rp[3009][3009];
int d[3009][3009];
string s1, s2;

void dp(int a, int b)
{
	if (d[a][b] != -1)
		return;
	if (a == 0 || b == 0) {
		d[a][b] = 0; rp[a][b] = make_pair(0, 0);
		return;
	}
	dp(a - 1, b); dp(a, b - 1);
	d[a][b] = d[a - 1][b]; rp[a][b] = rp[a - 1][b];
	if (d[a][b - 1] > d[a][b]) {
		d[a][b] = d[a][b - 1]; rp[a][b] = rp[a][b - 1];
	}
	if (s1[a - 1] == s2[b - 1] && d[a][b] < d[a - 1][b - 1] + 1) {
		d[a][b] = d[a - 1][b - 1] + 1; rp[a][b] = make_pair(a, b);
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> s1 >> s2;
	for (int i = 0; i <= s1.length(); i++)
		for (int j = 0; j <= s2.length(); j++)
			d[i][j] = -1;
	d[0][0] = 0;
	dp(s1.length(), s2.length());
	pair<int, int> p = rp[s1.length()][s2.length()];
	string ans = "";
	while (p.first != 0 && p.second != 0) {
		ans = s1[p.first - 1] + ans;
		p = rp[p.first - 1][p.second - 1];
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 106624
def up(x):
  return x + (10 - x % 10) if x%10!=0 else x
def key(x):
  return 10 if x%10 == 0 else x%10
ans = 0
a = sorted([int(input()) for i in range(5)], key=key)
print(a[0] + sum(list(map(up, a[1:]))))

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

int main(){
  int x;
  cin>> x;
  while(1){
    bool ok =true;
    for(int i=2;i<x;i++){
      if(x%i==0){
        ok=false;
        break;
      }
    }
    if(ok) break;
    x++;
  }
  cout<<x<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

class Graph{
	private:
	int n;
	vector<vector<pair<int,double>>> g;
	public:
	vd DIJ(int s){
		priority_queue<pair<double,int>> q;
		vd d(n,inf);
		d[s]=0;
		q.push(make_pair(0,s));
		while(!q.empty()){
			auto p=q.top();
			q.pop();
			int v=p.second;
			if(d[v]<-p.first) continue;
			for(auto i:g[v]){
				int u=i.first;
				double D=d[v]+i.second;
				if(d[u]>D){
					d[u]=D;
					q.push({-D,u});
				}
			}
		}
		return d;
	}
	Graph(int v){
		n=v;
		g=vector<vector<pair<int,double>>>(v);
	}
	void add_edge(int s,int t,double c){
//		cout<<s<<' '<<t<<' '<<syosu(9)<<c<<endl;
		g[s].push_back(make_pair(t,c));
	}
};

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	while(1){
		int n;
		cin>>n;
		if(n==0) break;
		vs a(n);
		for(auto &i:a) cin>>i;
		vs a_;
		for(int i=0;i<n;i++){
			bool B=1;
			int m1=a[i].size();
			for(int j=0;j<n;j++) if(j!=i&&a[j].size()>=m1){
				int m2=a[j].size();
				for(int k=0;k<m2;k++) if(a[j].substr(k,m1)==a[i]) B=0;
			}
			if(B) a_.push_back(a[i]);
		}
		a=a_;
		n=a.size();
		int N=1<<n;
		vvi dp(N,vi(n,inf));
		vvi b(n,vi(n));
		for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(i!=j){
			int m1=a[i].size(),m2=a[j].size();
			b[i][j]=m2;
			for(int k=m1-1;k>=0;k--) if(a[i].substr(k,m1-k)==a[j].substr(0,m1-k)){
				b[i][j]=m2-m1+k;
			}
		}
/*		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++) cout<<b[i][j]<<' ';
			cout<<endl;
		}*/
//		for(auto i:a) cout<<i<<endl;
		for(int i=0;i<n;i++) dp[1<<i][i]=a[i].size();
		for(int i=0;i<N;i++) for(int j=0;j<n;j++) if(dp[i][j]<inf){
			for(int k=0;k<n;k++) if(!(i&1<<k)){
				int I=i+(1<<k);
				dp[I][k]=min(dp[I][k],dp[i][j]+b[j][k]);
//				if(dp[i][j]+b[j][k]==18) cout<<i<<' '<<j<<' '<<k<<endl;
			}
		}
		int res=inf;
		for(int i=0;i<n;i++){
			res=min(res,dp[N-1][i]);
		}
		cout<<res<<endl;
/*		for(int i=0;i<N;i++){
			for(auto j:dp[i]) cout<<j<<' ';
			cout<<endl;
		}*/
	}
}


Measured memory_bytes: 4372
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#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)))
#define absl(v) labs((v))
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,tmp;
  int a[LIMIT2]={0};
  char s[LIMIT1];
  ll dp[LIMIT1][2];
  
  scanf("%lld",&n);
  rep(i,n) scanf("%d",&a[i]);
  dp[0][0]=0;
  dp[1][0]=(ll)a[0];
  for(i=2;i<n;i++){
    dp[i][0]=gcd(dp[i-1][0],(ll)a[i-1]);
  }
  dp[n-2][1]=(ll)a[n-1];
  dp[n-1][1]=0;
  for(i=n-3;i>=0;i--){
    dp[i][1]=gcd(dp[i+1][1],(ll)a[i+1]);
  }
  /*
  rep(i,n) printf("%lld ",dp[i][0]);
  printf("\n");
  rep(i,n) printf("%lld ",dp[i][1]);*/
  rep(i,n){
    if(dp[i][0]==0) tmp=dp[i][1];
    else if(dp[i][1]==0) tmp=dp[i][0];
    else tmp=gcd(dp[i][0],dp[i][1]);
    result = max(tmp,result);
  }
  printf("%lld",result);
  return 0;
}

Measured memory_bytes: 4608
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn main() {
    let h: u64 = input();
    let mut div = 1;
    while h / div > 1 {
        div *= 2;
    }
    println!("{}", div * 2 - 1);
}


Measured memory_bytes: 4352
/*|-----------|
  | templatka |
  |  Tomasz   |
  |   Zyla    |
  |-----------|*/

#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define f first
#define s second

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tiii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef set<int> si;
typedef set<ll> sll;
typedef list<int> li;
typedef list<ll> lll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef map<string,int> msi;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;
typedef unordered_map<string,int> umsi;
typedef queue<int> qi;
typedef queue<ll> qll;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pqll;

int tab[3];

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	
	int n; cin >> n;
	
	for(int i = 0; i < n; i ++) {
		int x; cin >> x;
		if (x % 2 == 0 && x % 3 != 0 && x % 5 != 0) {
			cout << "DENIED\n";
			return 0;
		}
	}
	cout << "APPROVED\n";
	return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
h=list(map(int,input().split()))
h.insert(0,0)
dp=[[float("inf")]*(n-k+1) for _ in range(n+1)]
dp[0][0]=0
for i in range(1,n+1):
    for j in range(1,n-k+1):
        now=float("inf")
        for l in range(i):
            now=min(dp[l][j-1]+max(0,h[i]-h[l]),now)
        dp[i][j]=now

ans=float("inf")
for i in range(1,n+1):
    ans=min(ans,dp[i][n-k])

print(ans if n>k else 0)


Measured memory_bytes: 47324
#include<stdio.h>

#define N 1000000000

int main(){
  int x,n,i,a=-N,m=N;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&x);
    if(i>0 && a<x-m) a=x-m;
    if(i!=0 && m>x) m=x;
    if(i==0 && m>x) m=x;
    
 
  }
  printf("%d\n",a);
  return 0;
}


Measured memory_bytes: 2056
/*
https://atcoder.jp/contests/dp/tasks/dp_k
*/
#include<bits/stdc++.h>
using namespace std;


int main(){

    int n,k;  cin>>n>>k;
    int arr[n];

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

    int dp[k+1];

    memset(dp,0,sizeof(dp));

    /// dp[i] = 0 represents that ith posotion is loosing position and dp[i]=1 represents that its a winning position

    for(int i=1;i<=k;i++){
        for(auto pos:arr){
            if(pos <= i){
                if(dp[i-pos] == 0){
                    dp[i] = 1;
                }
            }
        }
    }

    if(dp[k] == 0) cout<<"Second"<<endl;
    else cout<<"First"<<endl;

return 0;
}


Measured memory_bytes: 3976
#include <iostream>
using namespace std;
using ll = long long;

int cnt = 1;
int k;

void f(int d,int d_now,int prev,ll sum){
  for(int i=prev-1;i<=prev+1;i++){
    if(0 <= i && i<10){
      //sumを求める
      ll s = i;
      for(int j=0;j<d-d_now;j++) s *= 10;
      ll n_sum = sum + s;

      if(d == d_now){
        if(cnt == k){
          cout << n_sum << endl;
        }
        cnt++;
//        cout << n_sum << " ";
      }else{
        f(d,d_now+1,i,n_sum);
      }
    }
  }
}

int main(){
  cin >> k;

  for(int i=1;i<=9;i++){
    if(cnt == k){
      cout << i << endl;
    }
    cnt++;
//    cout << i << " ";
  }
//  cout << endl;
  for(int i=2;i<=10;i++){
    for(int j=1;j<=9;j++){
      ll sum = j;
      for(int k=1;k<i;k++) sum *= 10;
      f(i,2,j,sum);
    }
  }
//  cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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 pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=55;
int n;
ll comb[N][N],dp[N][N][N],ret;
int main() {
	scanf("%d",&n);
	rep(i,0,n+1) {
		comb[i][0]=1;
		rep(j,1,i+1) comb[i][j]=(comb[i-1][j-1]+comb[i-1][j])%mod;
	}
	dp[0][0][0]=1;
	rep(k,0,n+1) rep(p0,0,k+1) rep(p1,0,k+1) if (dp[k][p0][p1]) {
		rep(p2,0,n-k+1) rep(p3,0,n-k-p2+1) if (p2-p1+p0>=0&&p3+p1-p0>=0&&p2+p3>0)
			(dp[k+p2+p3][p2-p1+p0][p3+p1-p0]+=dp[k][p0][p1]*comb[k+p2][k]%mod*comb[k+p2+p3][k+p2])%=mod;
	}
	printf("%lld\n",dp[n][1][0]);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, begin, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N, K;
    string S;
    cin >> N >> K >> S;
    if (S.at(K - 1) == 'A')
    {
        S.at(K - 1) = 'a';
    }
    else if (S.at(K - 1) == 'B')
    {
        S.at(K - 1) = 'b';
    }
    else
    {
        S.at(K - 1) = 'c';
    }
    cout << S << endl;
}

Measured memory_bytes: 256
N,M = map(int,input().split())

claims = []
for i in range(M):
  claims.append(list(map(int,input().split())))
  
claims.sort()

killed = 0
last_killed = [-1,-1]
for claim in claims:
  if (last_killed[1] < claim[0] or last_killed[0] >= claim[1]):
    last_killed = [claim[0],claim[1] -1]
    killed += 1
  last_killed = [max(last_killed[0],claim[0]),min(last_killed[1],claim[1] -1)]
print(killed)

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

#define MAX 1002
#define MAXX 5002
int n;


int val[MAX];

vector<int> v[MAX];

int dp[MAX][MAXX];  //white : i minumum black 

int white[MAX];  //black min
int black[MAX];  //white min

inline void dfs(int b){
	dp[b][0] = 0;
	if (v[b].size() == 0){
		white[b] = 0;
		black[b] = 0;
		return;
	}
	for (int k = 0; k < v[b].size(); k++){
		int go = v[b][k];
		dfs(go);
		for (int j = MAXX-1; j >= 0; j--){
			if (dp[b][j] == INT_MAX)continue;
			int su = dp[b][j];
			dp[b][j] = INT_MAX;
			if (white[go]!=INT_MAX&&j + val[go] < MAXX){
				dp[b][j + val[go]] = min(dp[b][j + val[go]], su + white[go]);
			}
			if (black[go]!=INT_MAX&&j + black[go] < MAXX){
				dp[b][j + black[go]] = min(dp[b][j + black[go]], su + val[go]);
			}
		}
	}
	white[b] = black[b] = INT_MAX;
	for (int k = 0; k < MAXX; k++){
		if (dp[b][k] != INT_MAX){
			if (dp[b][k] <= val[b]){
				black[b] = min(black[b],k);
			}
		}
		if (k <= val[b]){
			white[b] = min(white[b], dp[b][k]);
		}
	}
	if (black[b] == INT_MAX && white[b] == INT_MAX){
		puts("IMPOSSIBLE");
		exit(0);
	}
}
int main(){
	for (int i = 0; i < MAX; i++){
		for (int j = 0; j < 5002; j++){
			dp[i][j] = INT_MAX;
		}
	}
	cin >> n;
	for (int i = 1; i < n; i++){
		int p;
		scanf("%d", &p);
		p--;
		v[p].push_back(i);
	}
	for (int i = 0; i < n; i++){
		scanf("%d", &val[i]);
	}
	dfs(0);
	puts("POSSIBLE");
	return 0;
}

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

int dp[2001][2001];

int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  string s;
  while(cin >> s){
    int n = s.size();
    string r = s;
    reverse(all(r));

    //vector< vector<int> > dp(n+1,vector<int>(n+1,0));
    memset(dp,0,sizeof(dp));
    rep(i,n){
      rep(j,n){
	if(s[i] == r[j])dp[i+1][j+1] = dp[i][j]+1;
	else dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
      }
    }

    int m = (dp[n][n]+1)/2;
    string pal;
    int a = n, b = n;
    while(a!=0 && b!=0 && (int)pal.size()<m){
      if(a>0 && b>0 && dp[a][b] == dp[a-1][b-1]+1 && s[a-1]==r[b-1]){
	pal += s[a-1]; a--; b--;
      }else if(a>0 && dp[a][b] == dp[a-1][b]){
	a--;
      }else if(b>0 && dp[a][b] == dp[a][b-1]){
	b--;
      }else{
	exit(1);
      }
    }
    
    for(int i=dp[n][n]/2-1;i>=0;i--)pal += pal[i];
    cout << pal << endl;
  }
}

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

int main()
{
	int n;
	cin>>n;
	int a[n];
	int b[n] = {};
	for (int i = 0; i < n; ++i)
	{
		/* code */
		cin>>a[i];
		b[a[i]-1]++;
	}
	long long int count = 0;
	for (int i = 0; i < n; ++i)
	{
		/* code */
		long long int k = b[i];
		count += k*(k-1)/2;
	}
	for (int i = 0; i < n; ++i)
	{
		/* code */
		cout<<count-b[a[i]-1]+1<<endl;
	}
}

Measured memory_bytes: 4096
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1e5+5;
char s[maxn];
vector<int>G[maxn];
int last,len;
void dfs(int rt,int size){
	if (last==len) return;
	last++;
	if (s[size-1]=='1'){
		G[last].push_back(rt);
		dfs(last,size+1);
	}else{
		G[rt].push_back(last);
		dfs(rt,size+1);
	}
}
void dfs1(int rt){
	for (auto i:G[rt]){
		cout << rt << ' ' << i << '\n';
		dfs1(i);
	}
}
int main(){
	scanf("%s",&s);
	len=strlen(s);
	if (s[len-1]=='1'||s[0]=='0'||s[len-2]=='0'){
		cout << -1;
		return 0;
	}
	for (int i=1;i<len-2;i++){
		if (s[i]!=s[len-2-i]){
			cout << -1;
			return 0;
		}
	}
	last=2;
	G[2].push_back(1);
	dfs(2,2);
	dfs1(last);
}

Measured memory_bytes: 13184
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {
      Scanner scanner = new Scanner(System.in);
      String str = scanner.next();
      
      String result = "Yes";
      for (int i = 0; i < str.length(); i++) {
        char input = str.charAt(i);
        if (input == 'U' || input == 'D') continue;
        
        char c = 'R';
        if (i % 2 == 1) c = 'L';
      	if (input != c) {
          result = "No";
          break;
        }
      }
      System.out.println(result);
    }
}


Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn = new Scanner(System.in);
		int x = scn.nextInt();
		int y = scn.nextInt();
		int p = x * 2;
		int q = x * 4;
		if ((y >= p) && (y <= q) && ((y % 2) == 0)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 27076
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
	int N; cin >> N;
	
	int B[N-1]; F0R(i, N-1) cin >> B[i];
	
	int A[N]; F0R(i, N-1) A[i] = B[i];
	A[N-1] = MX;
	
	F0R(i, N-1) A[i+1] = min(A[i+1], B[i]);
	
	int sum = 0;
	F0R(i, N) {
		sum += A[i];
	}
	
	cout << sum << endl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
 	long int n = 0;
  	int c = cin.get();
  	while (c >= '0' && c <= '9')
    {
     	n += c - '0'; 
      	c = cin.get();
    }
  if (n % 9 == 0) cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 3620
n = gets.to_i

c = 0

for d in 3..(n.to_s.length) do
  [7, 5, 3].repeated_permutation(d).to_a.uniq() do |num|
    c += 1 if num.include?(3) && num.include?(5) && num.include?(7) && num.join.to_i <= n

  end
end

p c

Measured memory_bytes: 7164
using System;
using System.IO;
using System.Linq;
using System.Runtime;
using System.Reflection;
using System.Diagnostics;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

class P
{
    static void Main()
    {
        string s = Console.ReadLine();
        //対称である必要があって、下から攻めてく感じ 10^5なので、えー
        //作ることができないを作りたい
        //HLみたいな感じで木の枝を上一本だと見てあげる
        //端の0からやっていくにはそうしかない ないので
        List<Tuple<int, int>> vectors = new List<Tuple<int, int>>();
        if (s[0] != s[s.Length - 2] || s[0] == '0' || s[s.Length - 1] == '1') goto end;
        vectors.Add(new Tuple<int, int>(1, 2));
        int lastPoint = 2;
        for (int i = 1; i < s.Length / 2; i++)
        {
            if (s[i] != s[s.Length - i - 2]) goto end;
            vectors.Add(new Tuple<int, int>(lastPoint, i + 2));
            if (s[i] == '1') lastPoint = i + 2;
        }
        for (int i = s.Length / 2 + 2; i <= s.Length; i++)
        {
            vectors.Add(new Tuple<int, int>(lastPoint, i));
        }
        Console.WriteLine(string.Join("\n", vectors.Select(x => $"{x.Item1} {x.Item2}")));
        return;
        //真ん中の辺みたいなのがあって、そこで2つのシーケンスを繋げるとかしないと駄目
        //全部必要部分は構築したらあとはウニでいいかも?
        end:;
        Console.WriteLine("-1");
    }
}

Measured memory_bytes: 31952
import math
a,b,x=map(int,input().split())
if x==pow(a,2)*b/2:
  print(45)
elif x>pow(a,2)*b/2:
  print(math.degrees(math.atan(2*(b/a-x/pow(a,3)))))
else:
  print(math.degrees(math.atan((a*pow(b,2))/(2*x))))

Measured memory_bytes: 3188
#include<stdio.h>
int main()
{
    int a,b,x;
    scanf("%d %d %d",&a,&b,&x);
    if(a>x)
    {
        printf("NO");
    }
    else
    {
        if((a+b)>=x)
        {
            printf("YES");
        }
        else
        {
            printf("NO");
        }
    }
return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int dp[3010][3010];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    rep(i, N + 1) dp[i][0] = 1;
    rep(i, M + 1) dp[0][i] = 1;
    int S[3010], T[3010];
    rep(i, N) cin >> S[i];
    rep(i, M) cin >> T[i];
    rep(i, N) {
        rep(j, M) {
            if(S[i] == T[j]) {
                dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % mod;
            } else {
                dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1] - dp[i][j] + mod) % mod;
            }
        }
    }
    cout << dp[N][M] << endl;


    return 0;
}


Measured memory_bytes: 42876
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
//#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M=1000000007;
const ll MM=998244353;
ll begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";

 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  if(a<=0)return 0;
  a%=m;
  if(!b)return 1;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}




const ll N=5e5+5;





int main()
{ 

IOS;

ll n,a,b;

cin>>n>>a>>b;

if((b-a)%2==0){
  cout<<(b-a)/2<<endl;
  return 0;
}

ll a1=min(n-b,a-1)+(b-a+1)/2;

cout<<min({a1,n-a,b-1});

//end_routine();

return 0;
 
}


Measured memory_bytes: 3640