akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

std::string solve(std::string S) {
  int N_count = 0, S_count = 0, E_count = 0, W_count = 0; //count
  for(int i = 0; i < S.size(); i++) {
    if(S[i] == 'N') N_count = N_count + 1;
    if(S[i] == 'S') S_count = S_count + 1;
    if(S[i] == 'E') E_count = E_count + 1;
    if(S[i] == 'W') W_count = W_count + 1;
  }
  
  if((N_count > 0 && S_count == 0) || (S_count > 0 && N_count == 0)
  || (E_count > 0 && W_count == 0) || (W_count > 0 && E_count == 0)) {
    return "No";
  } else {
    return "Yes";
  }
}

int main(void) {
  //input
  std::string S;
  std::cin >> S;

  std::string O;
  O = solve(S);
  
  //output
  std::cout << O <<std::endl;
  
  return 0;
}

Measured memory_bytes: 256
N, X = map(int, input().split())
x_list = list(map(int, input().split()))
x_cumsum = [0]*N

cum = 0
for i in range(N):
    cum += x_list[i]
    x_cumsum[i] = cum
    
res = cum*5 + 2*N*X
for n in range(1, N):
    res_temp = (N+n)*X
    
    for i in range(N // n):
        if i == 0:
            c = 5
        else:
            c = 2*i+3
        if N-1-(i+1)*n == -1:
            res_temp += c * x_cumsum[N-1-i*n]
        else:
            res_temp += c * (x_cumsum[N-1-i*n] - x_cumsum[N-1-(i+1)*n])
    i = N // n
    c = 2*i+3
    if N % n != 0:
        res_temp += c * x_cumsum[N % n - 1]
    res = min(res, res_temp)
    
print(res)

Measured memory_bytes: 89424
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
typedef long long ll;
using namespace std;

int main(void){
  static int n,i,d[100010];

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

  sort(d,d+n);

  if(d[n/2]==d[n/2-1]){
    cout<<0<<endl;
  }
  else{
    cout<<d[n/2]-d[n/2-1]<<endl;
  }
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a>=b && a>=c && (b>=c|| c>=b))
       {
           printf("%d\n",a*10+b+c);
        }
    
    else if(b>=a && b>=c &&( a>=c||c>=a))
    {
        printf("%d\n",b*10+a+c);
    }
    else if(c>=a && c>=b && (b>=a || a>=b) )
    {
        printf("%d\n",c*10+a+b);
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>

typedef long long ll;

#define rep(i,n) for(int i = 0; i < n; i++)
#define rrep(i,j,n) for(int i = j; i <= n; i++)
#define debug(x) cerr << #x << ": " << x << "\n";

using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;

int main(){
  int n,m,q;
  cin >> n >> m >> q;
  vector<int> a(q),b(q),c(q),d(q);
  rep(i,q)cin >> a[i] >> b[i] >> c[i] >> d[i];

  int ans = 0;
  rrep(j,1,m){
    rrep(k,j,m){
      rrep(l,k,m){
	rrep(o,l,m){
	  rrep(p,o,m){
	    rrep(r,p,m){
	      rrep(s,r,m){
		rrep(t,s,m){
		  rrep(u,t,m){
		    rrep(v,u,m){
		      int tmp = 0;
		      vector<int> A = {0,j,k,l,o,p,r,s,t,u,v};		      
		      rep(i,q){
			if(A[b[i]]-A[a[i]] == c[i]) tmp += d[i];
		      }
		      ans = max(ans,tmp);
		    }
		  }
		}
	      }
	    }
	  }
	}
      }
    }
  }
  cout << ans << endl;
}
      


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

#define int long long

using namespace std;

int a[200010];
map <int,int> m;

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

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

	int ans = 0;

	for(auto i:m)
		ans += (i.second*(i.second-1))/2;

	for(int i=0;i<n;i++)
	{
		cout << ans - m[a[i]] + 1 << "\n";
	}
}

Measured memory_bytes: 11008
// Winners don't quit and Quitters don't win
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mod 998244353
#define MAX 100005
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int r;
    float f;
    cin>>r;
    f=(2*3.14159*float(r));
    printf("%.10f",f);
}

Measured memory_bytes: 3772
use std::io::{BufRead, Write};
use std::io;

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut s = String::new();
    input.read_line(&mut s).unwrap();
    let mut split = s.split_whitespace();
    let n = split.next().unwrap().parse::<usize>().unwrap();
    let m = split.next().unwrap().parse::<usize>().unwrap();
    let ab = (0..m)
        .map(|_| {
                 let mut s = String::new();
                 input.read_line(&mut s).unwrap();
                 let mut split = s.split_whitespace();
                 let a = split.next().unwrap().parse::<usize>().unwrap();
                 let b = split.next().unwrap().parse::<usize>().unwrap();
                 (a, b)
             })
        .collect::<Vec<_>>();
    let mut count = vec![0usize;n];
    for &(a, b) in &ab {
        count[a - 1] += 1;
        count[b - 1] += 1;
    }
    writeln!(output,
             "{}",
             if count.iter().all(|&x| x % 2 == 0) {
                 "YES"
             } else {
                 "NO"
             })
            .unwrap();
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v = Vec::<u8>::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }
    #[test]
    fn case1() {
        test("4 4
1 2
2 4
1 3
3 4\n",
             "YES\n");
    }
    #[test]
    fn case2() {
        test("5 5
1 2
3 5
5 1
3 4
2 3\n",
             "NO\n");
    }
}



Measured memory_bytes: 6396
/******Old School******/
#include<bits/stdc++.h>
using namespace std;
#define lld               long long int
#define ld                long double
#define pb                push_back
#define ppb               pop_back
#define mp                make_pair
#define nl                '\n'
#define all(c)            (c).begin(),(c).end()
#define rall(c)           (c).rbegin(),(c).rend()
#define sz(c)             (c).size()
#define tr(x,a)           for(auto &a : x)
#define psnt(x,a)         (x).find(a)!=(x).end()
#define vpsnt(x,a)        find(all(x),a)!=(x).end()
#define lexichar(x,y)     lexicographical_compare(x,x+strlen(x),y,y+strlen(y)) //modify the ranges
#define lexistr(x,y)      lexicographical_compare(x.begin(),x.end(),y.begin(),y.end()) 
#define MOD               1000000007
#define pi                3.1415926536
#define tod               1e18
#define itr(i,a,b)        for(lld i=a;i<=b;i++)
#define itrn(i,a,b)       for(lld i=a;i>=b;i--)
#define iot(n)            for(lld i=0;i<n;i++)
#define pls(n,arr)        lld arr[n]; iot(n)  cin>>arr[i];
 
typedef pair<lld,lld>     pii;
typedef pair<string,lld>  psi;
template <typename T>
bool mycomp(T x,T y){ 
   return (x==y);  //give your condition here
}
bool paircomp(const pair<lld,lld> &x,const pair<lld,lld> &y){ 
return x.second<y.second;
}
 
int main(){
       ios_base::sync_with_stdio(false);
             cin.tie(0);
            cout.tie(0);
     lld n; cin>>n;
    vector<lld> v(300005);
iot(3*n)   cin>>v[i];
lld csum=0,l[300005],r[300005];
  priority_queue<lld> pq; //max heap
priority_queue<lld,vector<lld>,greater<lld> > pq2;// min  heap
iot(3*n){
csum+=v[i];
pq2.push(v[i]);
if(pq2.size()>n){
csum-=pq2.top();
pq2.pop();
}
if(pq2.size()==n)  l[i]=csum;
else l[i]=-tod;
}
csum=0;
itrn(i,3*n-1,0){
pq.push(v[i]);
csum+=v[i];
if(pq.size()>n){
csum-=pq.top();
pq.pop();
}
if(pq.size()==n) r[i]=csum;
else  r[i]=tod;
}
lld ans=-tod;
iot(3*n-1){
ans=max(ans,l[i]-r[i+1]);
}
cout<<ans;
}

Measured memory_bytes: 9588
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main() => new Program().Solve();

	void Solve()
	{
		var ab = ReadLongArray();
		Console.WriteLine(ab[0] * ab[1]);
	}

	/// <summary>最大公約数</summary>
	long gcd(long a, long b) => (a == 0) ? b : gcd(b % a, a);

	#region Console.Read 関係
	long[] ReadLongArray() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
	long ReadLong() => long.Parse(Console.ReadLine());
	#endregion
}


Measured memory_bytes: 27560
package main

import (
	"fmt"
)

func min(x, y int) int {
	if x <= y {
		return x
	}
	return y
}

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)

	ans := n / (a + b) * a
	mod := n % (a + b)
	ans += min(mod, a)
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define INF 1000000000
#define rep(i,a,b) for (int i=(a);i<(b);i++)
#define rev(i,a,b) for (int i=(a)-1;i>=b;i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef queue<int> qi;
typedef vector<int> vi;
typedef vector<string> vs;
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };

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

  int sum = 0;
  rep(i,0,5) {
    int a;
    cin >> a;
    sum += max(40, a);
  }
  cout << sum/5 << endl;

	return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[100000][3]={0},a[100000][3];

main()
{
	ll n,i,j;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	//dp[1]=max(max(a[0][0],a[0][1]),a[0][2]);
	for(i=1;i<n;i++)
	{
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i][1];
		dp[i][2]=max(dp[i-1][1],dp[i-1][0])+a[i][2];
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}



Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 100000001

int main(){
  int n;
  cin>>n;
  vector<int> t(n+1),v(n+2);
  rep(i,n) cin>>t[i];
  rep(i,n) cin>>v[i];

  vector<int> dp(105, -INF);
  dp[0] = 0;
  rep(i,n){
    rep(j,t[i]){
      vector<int> nxt(105, -INF);
      rep(k,v[i]){
        if(k>0) nxt[k] = max(nxt[k], dp[k-1] + 4*k-2);
        nxt[k] = max(nxt[k], dp[k] + 4*k+1);
        nxt[k] = max(nxt[k], dp[k+1] + 4*k+2);
      }
      nxt[v[i]] = max(dp[v[i]] + 4*v[i], dp[v[i]-1] + 4*v[i]-2);
      swap(dp, nxt);
    }
  }


  // vector<int> at(n+2,0);
  // rep(i,n+1) at[i+1] = t[i+1]+at[i];
  //
  // v[0] = 0;
  // v[n+1] = 0;
  // rep(i,1,n+1){
  //   int l=v[i], r=v[i];
  //   for(int j=i-1; j>=0; j--) l = min(l, v[j]+at[i-1]-at[j]);
  //   for(int j=i+1; j<=n+1; j++) r = min(r, v[j]+at[j-1]-at[i]);
  //   int lv = max(v[i]-l, 0);
  //   int rv = max(v[i]-r, 0);//dbg(l,r,lv,rv);
  //   if(lv+rv<=t[i]){
  //     ans += v[i]*t[i] - (lv*lv/2.0 + rv*rv/2.0);
  //   }
  //   else {
  //     int d = abs(l-r);
  //     ans += min(l,r)*t[i] + d*d/2.0 + (t[i]-d)*(t[i]-d)/4.0 + d*(t[i]-d);
  //   }
  // }

  printf("%.4f\n", dp[0]/4.0);

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,d;
  cin>>n>>d;
  int ans=0;
  for(int i=0; i<n; i++){
    int a,b;
    cin>>a>>b;
    double c=sqrt(pow(a,2)+pow(b,2));
    if(c<=d)ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    constexpr int MAX_A=10001;
    int N,K;
    cin>>N>>K;
    vector<int> a(N);
    REP(i, N) cin >> a[i];
    vector<bitset<MAX_A+1>> dpl(N+1),dpr(N+1);
    dpl[0]=1;
    dpr[N]=1;
    REP(i,N){
        dpl[i+1]=(dpl[i]<<a[i])|dpl[i];
        dpr[N-i-1]=(dpr[N-i]<<a[N-i-1])|dpr[N-i];
    }
    int ans=N;
    REP(i,N){
        if(a[i]>=K){
            ans--;
            continue;
        }
        int suml[MAX_A+1]={},sumr[MAX_A+1]={};
        REP(j,K){
            suml[j+1]=suml[j]+dpl[i][j];
            sumr[j+1]=sumr[j]+dpr[i+1][j];
        }
        REP(t,K) if(dpl[i][t]){
            if(t<K-a[i]){
                if(sumr[K-t]-sumr[K-t-a[i]]){
                    ans--;
                    break;
                }
            }
            else{
                ans--;
                break;
            }
        }
    }
    cout<<ans<<endl;
}


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

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

#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define forn(s, e) for(int i=s; i<e; ++i)
#define MOD 1000000007
#define F first
#define S second
#define all(v) v.begin(), v.end()

int main(){
    IO
    int n, a, b;
    cin >> n >> a >> b;

    vi q(n);
    forn(0, n)
        cin >> q[i];
    
    sort(all(q));
    int i=0, count = 0;
    vi done;
    done.assign(n, 0);
    bool f;
    for(int i=0; i<n; ++i){
        f = true;
        if(!done[i] && q[i] <= a){
            for(int j=i+1; j<n && f; ++j){
                if(!done[j] && q[j]>a && q[j]<=b){
                    for(int k=j+1; k<n && f; ++k){
                        if(!done[k] && q[k]>b){
                            done[i] = done[j] = done[k] = 1;
                            //cout << ">" << i << " "  << j << " " << k << endl;
                            ++count;
                            f= false;
                            break;
                        }
                    }
                }
            }
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main()
{
	string s;
	cin >> s;
	if (s == "Sunny") cout << "Cloudy" << endl;
	else if (s == "Cloudy") cout << "Rainy" << endl;
	else cout << "Sunny" << endl;
}

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

typedef struct {
	int zaihou;
	int bridge_max;
} island_t;

int qsort_comp(const void* x,const void* y) {
	const island_t* a=(const island_t*)x;
	const island_t* b=(const island_t*)y;
	if((a->bridge_max)>(b->bridge_max))return 1;
	if((a->bridge_max)<(b->bridge_max))return -1;
	if((a->zaihou)>(b->zaihou))return 1;
	if((a->zaihou)<(b->zaihou))return -1;
	return 0;
}

int island_max;
island_t islands[25];

int main(void) {
	int i;
	int now_zaihou;
	while(1) {
		scanf("%d",&island_max);
		if(island_max==0)break;
		for(i=0;i<island_max;i++) {
			scanf("%d%d",&islands[i].zaihou,&islands[i].bridge_max);
		}
		qsort(islands,island_max,sizeof(island_t),qsort_comp);
		for(i=0,now_zaihou=0;i<island_max;i++) {
			now_zaihou+=islands[i].zaihou;
			if(now_zaihou>islands[i].bridge_max)break;
		}
		puts(i>=island_max?"Yes":"No");
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j,v;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  for(i=1;i<=n;i++){
v = A[i];
j=i-1;
while(j>=0 && A[j]>v){
A[j+1] = A[j];
j--;
A[j+1] = v;
}
trace(A,n);
}

  return 0;
}

Measured memory_bytes: 604
#!/usr/bin/env python3
x, y = map(int, input().split())
ans = float('inf')
filt = lambda z: [ z, float('inf') ][ z < 0 ]
ans = min(ans, filt(   y  -    x )    )
ans = min(ans, filt(   y  - (- x)) + 1)
ans = min(ans, filt((- y) -    x ) + 1)
ans = min(ans, filt((- y) - (- x)) + 2)
print(ans)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    long long a[100005];
    for(int i=0; i<n; i++)
    {
        scanf("%lld",&a[i]);
    }
    int flag=0;
    long long t=0;
    for(int i=0; i<n; i++)
    {
        if(t-1>a[i])
        {
            flag=1;
            break;
        };
        t=max(t,a[i]);
    }
    if(flag)printf("No");
    else printf("Yes");
    return 0;
}



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

using namespace std;

int main(){
    int n, h, w, a, b, cnt = 0;
    cin >> n >> h >> w;
    for(int i = 1; i <= n && cin >> a >> b; cnt += ((h <= a) && (w <= b)), ++i);
    cout << cnt;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define F(i,a,n) for(int i=a; i<n; i++)

int max=0;
int n,m,q;
int *a,*b,*c,*d;
void max_sum(int *A){
  int sum=0;
  F(i,0,q){
    if(A[b[i]-1]-A[a[i]-1]==c[i]) sum+=d[i];
  }
  if(max<sum)max=sum;
}

void loop(int ai,int *A){
  int i=1;
  if(ai!=0) i=A[ai-1];
  for(;i<=m;i++){
    A[ai]=i;
    if(ai+1<n) loop(ai+1,A);
    else max_sum(A);
  }
}

int main(){
  scanf("%d%d%d",&n,&m,&q);
  a=(int*)malloc(sizeof(int)*q);
  b=(int*)malloc(sizeof(int)*q);
  c=(int*)malloc(sizeof(int)*q);
  d=(int*)malloc(sizeof(int)*q);
  F(i,0,q){
    scanf("%d%d%d%d",a+i,b+i,c+i,d+i);
  }
  int A[n];
  F(i,0,n)A[i]=0;
  loop(0,A);
  printf("%d\n",max);
  return 0;
}

Measured memory_bytes: 1708
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int arr[n+1];
  int flag=0;
  for(int i=1;i<=n;i++)
  {
    cin>>arr[i];
  }
  for(int i=1;i<=n;i++)
  {
    if(arr[i]%2==0 && (arr[i]%3!=0 && arr[i]%5!=0))
    {
      flag=1;
      break;
    }
  }
  if(flag==0)
      cout<<"APPROVED"<<endl;
  else
      cout<<"DENIED"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
int main(){
  int N,M;cin>>N>>M;
  UnionFind UF(N);
  map<int,int>mp;
  for(int X=0;X<M;X++){
    int A,B;cin>>A>>B;A--;B--;
    UF.merge(A,B);
  }
  for(int X=0;X<N;X++){
    mp[UF.root(X)]++;
  }
  cout<<mp.size()-1<<endl;
}

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

using namespace std;

int main()
{
   int K ,N;
   cin >> K >> N;
   int A[N];
   for (int i = 0; i < N; i++)
   {
       cin >> A[i];
   }
   sort(A, A+N);
   int max_dist = 0;
   for (int i = 0; i < N-1; i++)
   {
       max_dist = max(max_dist, abs(A[i]-A[i+1]));
   }
   max_dist = max(max_dist, abs(A[0]+(K-A[N-1])));
   cout << K - max_dist << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

int main(){
    ll N;
    cin>>N;
    v a(3*N);
    rep(i,0,3*N)cin>>a[i];
    sort(all(a));
    ll ans=0;
    rep(i,0,N)ans+=a[3*N-2*i-2];
    cout<<ans;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int ui;

typedef vector<ull> vull;
typedef vector<ll> vll;
typedef vector<ui> vui;
typedef vector<long> vl;
typedef vector<int> vi;

typedef pair<ull, ull> pull;
typedef pair<ll, ll> pll;
typedef pair<ui, ui> pui;
typedef pair<long, long> pl;
typedef pair<int, int> pi;

int dp[100][100];

int main() {
    int n, T; cin >> n >> T;
    vector<pi> vpi;
    vpi.resize(n);

    for (int i = 0; i < n; ++i) {
        int c, t; cin >> c >> t;
        vpi[i] = pi(c, t);
    }

    sort(vpi.begin(), vpi.end());

    int cost = 0;

    int mini = INT_MAX;

    for (int i = 0; i < n; ++i) {
        if (vpi[i].second <= T) {
            mini = min(mini, vpi[i].first);
        }
    }

    if (mini == INT_MAX) {
        cout << "TLE" << endl;
    } else {
        cout << mini << endl;
    }

    return 0;
}


Measured memory_bytes: 888
#include <iostream>

using namespace std;

int main() {
    int n, m, sum=0;
    cin >> n;
    m = n;

    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }

    if(m % sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . ___
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         ·ð×æ±£ÓÓ       ÓÀÎÞBUG
*/
//use readint!
#include<map>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<stdio.h>
#include<fstream>
#include<assert.h>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<string.h>
#define mp make_pair
#define ll long long
using namespace std;
const int INF=1e9;
inline int pt(int a[],int l,int r){
	int p,i,j;
	p=a[l];
	i=l;
	j=r+1;
	for(;;){
		while(a[++i]<p) if(i>=r) break;
		while(a[--j]>p) if(j<=l) break;
		if(i>=j) break;
		else swap(a[i],a[j]);
	}
	if(j==l) return j;
	swap(a[l],a[j]);
	return j;
}
inline void q_sort(int a[],int l,int r){
	int q;
	if(r>l){
		q=pt(a,l,r);
		q_sort(a,l,q-1);
		q_sort(a,q+1,r);
	}
}
inline int readint(){
    int x=0;
    int f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') ch=getchar();
	if(ch=='-'){
		f=-1;
		ch=getchar();
	}
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int rot[100005];
int fa[100005];
int a[100005];
inline int ffa(int x){
	int t[100005];
	int sz=1;
	while(fa[x]!=0){
		t[sz++]=x;
		x=fa[x];
	}
	for(int i=1;i<sz;i++) fa[t[i]]=x;
	return x;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,m,i,j,x,y;
	n=readint();
	m=readint();
	for(i=1;i<=n;i++) a[i]=readint();
	for(i=1;i<=m;i++){
		x=readint();
		y=readint();
		int fx,fy;
		fx=ffa(x);
		fy=ffa(y);
		if(fx!=fy) fa[fx]=fy;
	}
	for(i=1;i<=n;i++) rot[i]=ffa(i);
	int ans=0;
	for(i=1;i<=n;i++) ans+=(rot[i]==rot[a[i]]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
vector<int> mp[55];
int ans,low[55],dfn[55],vis[55],cnt;
struct node
{
	int x,y;
}a[55];
bool cmp(const node u,const node v)
{
	if(u.x==v.x)return u.y<v.y;
	else return u.x<v.x;
}
void Tarjan(int u,int fa)
{
	low[u]=dfn[u]=++cnt;
	vis[u]=1;
	for(int i=0;i<mp[u].size();i++)
	{
		int v=mp[u][i];
		if(!vis[v])
		{
			Tarjan(v,u);
			low[u]=min(low[u],low[v]);
			if(low[v]>dfn[u])
			{
				a[ans].x=u;
				a[ans].y=v;
				if(u>v)
				swap(a[ans].x,a[ans].y);
				ans++;
			}
		}
		else if(fa!=v)
		low[u]=min(low[u],dfn[v]);
	}
}
int n,m,u,v;
int main()
{
	scanf("%d%d",&n,&m);
	for( int i=1;i<=m;i++)
	{
		scanf("%d%d",&u,&v);
		mp[u].push_back(v);
		mp[v].push_back(u);
	}
	for( int i=1;i<=n;i++)
	if(!dfn[i]) Tarjan(i,-1);
	printf("%d\n",ans);
	return 0;
}

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

#define INF 0x3f3f3f3f
#define ll long long
#define rep(i, n) for(ll i=0;i<n;i++)
#define per(i, n) for(int i=n;i>=0;i--)
#define rep2(i, n) for(ll i=1;i<=n;i++)
#define pb(x) push_back(x)
#define clint(x, n) memset(x,n,sizeof(x))
#define mp make_pair
#define fi first
#define se second
#define IO std::ios::sync_with_stdio(false)
#define ull unsigned long long
#define ud long double
#define pii pair<int,int>
#define random(x) (rand()%x)
using namespace std;
const ll inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int MAX = 123123;
const int N = 555;
const double eps = 1e-6;

inline int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

inline ll read1() {
    ll x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

ll max(ll a, ll b) {
    if (a > b) return a;
    return b;
}

ll min(ll a, ll b) {
    if (a < b) return a;
    return b;
}

ll multi(ll a, ll b, ll p) {
    ll ans = 0;
    while (b) {
        if (b & 1ll) ans = (ans + a) % p;
        a = (a + a) % p;
        b >>= 1;
    }
    return ans;
}

ll pow_mod(ll a, ll b, ll p) {
    ll ans = 1;
    while (b) {
        if (b & 1ll) ans = multi(ans, a, p);
        a = multi(a, a, p);
        b >>= 1;
    }
    return ans;
}

int qpow(int a, int b) {
    int ans = 1, base = a;
    while (b != 0) {
        if ((b & 1) != 0)
            ans *= base;
        base *= base;
        b >>= 1;
    }
    return ans;
}

int lowbit(ll x) {
    return x & (-x);
}

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

bool cmp(int &a, int &b) {
    return a > b;
}

const int maxn = 1e5 + 10;

//**************************************

int main() {
    int a,b;
    cin>>a>>b;
    if(a>9||b>9) {
        cout<<-1<<endl;
    }
    else cout<<a*b<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int SIZE=5000;
int n,m;
int cnt=0;
int depth[SIZE+2]={0},low[SIZE+2];
struct edge{
	int x,y,nxt;
}edges[SIZE+2];
int sz=0,h[SIZE+2]={0};
void add_edge(int x,int y){
	sz++;
	edges[sz].x=x;
	edges[sz].y=y;
	edges[sz].nxt=h[x];
	h[x]=sz;
	return;
}
void dfs(int p,int x){
	low[x]=depth[x];
	for(int i=h[x];i;i=edges[i].nxt){
		int y=edges[i].y;
		if(y==p) continue;
		if(!depth[y]){
			depth[y]=depth[x]+1;
			dfs(x,y);
		}
		low[x]=min(low[x],low[y]);
	}
	if(low[x]==depth[x]&&x!=1) cnt++;
	return;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		add_edge(x,y);
		add_edge(y,x);
	}
	depth[1]=1;
	dfs(0,1);
	printf("%d\n",cnt);
	return 0;
} 
/*
7 7
1 3
3 4
4 5
4 6
5 6
6 7
7 2
*/

Measured memory_bytes: 3768
#include <iostream>

using namespace std;

bool isPrime(int x) {
	if (x <= 1) { return false; }

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

	return true;
}

int main() {
	while (1) {
		int n;
		cin >> n;

		if (n == 0) { break; }
		
		int count = 0;

		for (int i = n + 1; i <= 2 * n; ++i) {
			if (isPrime(i)) {
				++count;
			}
		}

		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

int main() {
	ll n, a, b, c, d; cin >> n >> a >> b >> c >> d;
	bool flag = false;
	for (int i = 0; i < n; ++i) {
		flag |= (-d*i + c*(n - 1 - i) <= b - a && b - a <= -c*i + d*(n - 1 - i));
	}
	if (flag) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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

int main() {
	int n, m, x; cin >> n >> m >> x;
	int a[100];
	for (int i = 0; i < m; i++) cin >> a[i];

	int cost_r = 0;
	int cost_l = 0;
	for (int i = 0; i < m; i++) {
		if (a[i] > x && a[i] < n) cost_r++;
		if (a[i] < x && a[i] > 0) cost_l++;
	}

	cout << min(cost_r, cost_l) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


int main() {
  int n, W; cin >> n >> W;
  V w(n), v(n);
  rep(i, n) cin >> w[i] >> v[i];

  map<int, int> dp;
  dp[0] = 0;

  rep(i, n) for (auto itr = rbegin(dp); itr != rend(dp); ++itr) {
    auto &e = *itr;
    if (e.first + w[i] <= W) chmax(dp[e.first + w[i]],  e.second + v[i]);
  }

  int ans = 0;
  for (auto &e : dp) chmax(ans, e.second);
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 384
#define _FORTIFY_SOURCE 0
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")

#include<bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define int long long
#define double long double
#define pref pref228
#define left left228
#define right right228
#define x1 x1228
#define y1 y1228
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
mt19937 rnd(time(0));

const int maxn = 3e5 + 7, mod = 1e9 + 7, inf = 1e18;
const double eps = 1e-9, pi = acos(-1);
int n, m; 
string have; 
vector<int> gr[maxn]; 
set<pii> kek; 

int A[maxn], B[maxn]; 

int use[maxn];
vector<int> path;

void dfs(int u) {
    use[u] = 1; 
    path.pb(u); 
    for (auto v : gr[u]) {
        if (!use[v]) dfs(v); 
    }
}

int use1[maxn]; 

bool bfs() {
    deque<int> q;   
    int d = 0; 
    for (auto v : path) {
        if (A[v] == 0 || B[v] == 0) { 
            q.pb(v);
            use1[v] = 1;                
            ++d;
        }
    }
    while (q.size()) {
        int v = q.front(); 
        q.pop_front();
        for (auto u : gr[v]) {
            if (have[v] == 'A') A[u]--; 
            else B[u]--; 

            if (!use1[u] && (B[u] == 0 || A[u] == 0)) {
                q.pb(u); 
                use1[u] = 1; 
                ++d;
            }
        }
    }
    if (d != path.size()) return true; 
    return false; 
}

void solve() {
    cin >> n >> m >> have; 
    for (int i = 0; i < m; ++i) {
        int a, b; cin >> a >> b;        
        --a, --b;
        if (a > b) swap(a, b); 
        if (kek.count(mp(a, b))) continue;
        kek.insert({a, b});
        gr[a].pb(b); 
        gr[b].pb(a); 
        if (have[b] == 'A') A[a]++;
        else B[a]++;

        if (have[a] == 'A') A[b]++; 
        else B[b]++; 
    }
    
    for (int i = 0; i < n; ++i) {
        if (!use[i]) {
            path.clear(); 
            dfs(i); 

            if (bfs()) {
                cout << "Yes";
                return; 
            } 
        }
    }        
    cout << "No";  
}                               

signed main() {
//  freopen("", "r", stdin);
//  freopen("", "w", stdout);
#ifdef offline_judge
    freopen("TASK.in", "r", stdin);
    freopen("TASK.out", "w", stdout);
#endif
    srand(time(0));
    cout.precision(10);
    cout << fixed;
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
} 

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

int main(){
  int N; cin>>N;

  int V[51],C[51];
  for(int i=0;i<N;i++) cin>>V[i];
  for(int i=0;i<N;i++) cin>>C[i];

  int X=0,Y=0;
  for(int i=0;i<N;i++){
    if(V[i]-C[i]>0){
      X+=V[i];
      Y+=C[i];
    }
  }

  cout<<X-Y;
}


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

#define int long long

int n;

int solve1(int a1, int a2, int b1, int b2, int c1, int c2){

    int ans = 0;
    for(int i = 0;i*a1 <= n;i++){
        int tmp = n - (i*a1);
        tmp = i*a2 + (tmp/b1)*b2 + tmp%b1;
        ans = max(ans, tmp%c2 + (tmp/c2)*c1);
    }

    return ans;
}

int solve2(int a1, int a2, int b1, int b2, int c1, int c2){

    int ans = 0;
    int nn = n % c1 + (n/c1)*c2;
    for(int i = 0;i*a1 <= nn;i++){
        int tmp = nn - i*a1;
        tmp = i*a2 + (tmp/b1)*b2+tmp%b1;
        ans = max(ans, tmp);
    }
    return ans;
}


signed main(){
    int a1, b1, c1;
    int a2, b2, c2;
    cin >> n;
    cin >> a1 >> b1 >> c1;
    cin >> a2 >> b2 >> c2;


    if(a1 >= a2 && b1 >= b2 && c1 >= c2){
        swap(a1, a2);
        swap(b1, b2);
        swap(c1, c2);
    }

    if(a1 <= a2 && b1 <= b2 && c1 <= c2){
        int ans = 0;
        for(int i = 0;i*a1 <= n;i++){
            for(int j = 0;j*b1+i*a1 <= n;j++){
                int tmp = n-(j*b1+i*a1);
                //int t2 = n-tmp;
                ans = max(ans, j*b2+i*a2+ (tmp%c1) + (tmp/c1)*c2);
            }
        }

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

    int cnt = 0;
    if(a1 <= a2){
        cnt++;
    }
    if(b1 <= b2){
        cnt++;
    }
    if(c1 <= c2){
        cnt++;
    }

    if(cnt == 2){
        if(a1 > a2){
            cout << solve1(b1, b2, c1, c2, a1, a2) << endl;
        }else if(b1 > b2){
            cout << solve1(a1, a2, c1, c2, b1, b2) << endl;
        }else{
            cout << solve1(b1, b2, a1, a2, c1, c2) << endl;
        }
    }else{
        if(a1 <= a2){
            cout << solve2(b2, b1, c2, c1, a1, a2) << endl;
        }else if(b1 <= b2){
            cout << solve2(a2, a1, c2, c1, b1, b2) << endl;
        }else{
            cout << solve2(b2, b1, a2, a1, c1, c2) << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(){
    int s,t,d;
    scanf("%d%d%d",&d,&t,&s);
    if(t*s<d){
        printf("No");
    }else
    printf("Yes");
    return 0;
}



Measured memory_bytes: 1732
# coding: utf-8

def main():
    N, M = map(int, input().split())
    imos = [0] * (N + 2)
    ans = 0

    for _ in range(M):
        l, r = map(int, input().split())
        imos[l] += 1
        imos[r + 1] -= 1

    for i in range(1, N + 2):
        imos[i] += imos[i - 1]
        if imos[i] == M and i != N + 1:
            ans += 1
    
    print(ans)

if __name__ == "__main__":
    main()


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

int main(){
    int N,M; cin >> N >> M;
    map<int,int> mp;
    vector<bool> ac(N,false);
    vector<bool> ac2(N,false);
    vector<vector<int>> ps(M);
    rep(i,M){
        int p,s;
        string S; cin >> p >> S;
        if(S == "AC") s = 1, ac[p-1] = true;
        else s = 0;
        ps[i] = {p-1,s};
    }
    int right = 0;
    rep(i,N) if(ac[i]) right++;
    int penalty = 0;
    rep(i,M){
        if(ps[i][1] == 1) ac2[ps[i][0]] = true;
        if(!ac2[ps[i][0]] && ac[ps[i][0]] && ps[i][1] == 0) penalty++;
    }
    cout << right << " " << penalty << endl;
}

Measured memory_bytes: 8832
import sys
import os


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

    N = int(sys.stdin.buffer.readline())
    S = sys.stdin.buffer.readline().decode().rstrip()

    ret = []
    for s in S:
        n = ord(s) + N
        if n > 90:
            ret.append(chr(n - 26))
        else:
            ret.append(chr(n))

    print("".join(ret), end="")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import java.util.Scanner;
import java.util.Arrays;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();
        long h[]=new long[n];
        for(int i=0; i<n; i++){
            h[i]=sc.nextInt();
        }
        Arrays.sort(h);
        long sum=0;
        for(int j=0; j<n-k; j++){
            sum+=h[j];
        }
        System.out.println(sum);
        sc.close();
    }
}

Measured memory_bytes: 87060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59

int main(){
    ll i,j;
    ll n;
    cin>>n;
    ll a[n],b[n];

    for(i=0;i<n;i++){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(a,a+n);
    ll M=a[n-1];
    ll m=a[n-2];

    for(i=0;i<n;i++){
        if(b[i]==M) cout<<m<<endl;
        else if(b[i]==m) cout<<M<<endl;
        else cout<<M<<endl;
    }
    return 0;
    
}

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

int main(){
    string s;
    cin>>s;
    int flg=1;
    int len=s.length();
    for(int i=0;i<len;i+=2){
        if(s[i]=='L') flg=0;
    }
    for(int i=1;i<len;i+=2){
        if(s[i]=='R') flg=0;
    }
    if(flg==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
          string[] Input = Console.ReadLine().Split(' ');
          long N = long.Parse(Input[0]);
          long K = long.Parse(Input[1]);
          long abs = 1000000000000000000;
          bool flag = false;
          do
          {
            if(N % K > 0)
            {
              N %= K;
            }
            if(K == 1 || N == K)
            {
              flag = true;
              abs = 0;
            }
            else if(abs > Math.Abs(N - K))
            {
          	abs = Math.Abs(N - K);
            N = Math.Abs(N - K);
            }
            else
            {
             flag = true; 
            }
          }while(!flag);
          Console.WriteLine(abs);
          
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

typedef long long ll;
ll mod = 998244353;

void solve() {
    ll n, k;
    cin >> n >> k;
    vector <vector<ll>> v;
    vector <ll> dp(n+1, 0);
    for(ll i = 0; i < k; i++) {
        ll x, y;
        cin >> x >> y;
        vector <ll> v1(2, 0);
        v1[0] = x;
        v1[1] = y;
        // for(ll j = x; j <= y; j++) v.push_back(j);
        v.push_back(v1);
    }
    sort(v.begin(), v.end());
    vector <ll> cdp(n+1, 0);
    cdp[1] = 1;
    // for(ll i = 0; i < v.size(); i++) cout << v[i] << " ";
    // cout << endl;
    dp[1] = 1;
    for(ll i = 2; i < n+1; i++) {
        // for(ll j = 0; j < v.size(); j++) {
        //     ll step = v[j];
        //     if(step > i-1) break;
        //     dp[i] = (dp[i] + dp[i-step])%mod;
        // }

        for(ll j = 0; j < k; j++) {
            ll x = v[j][0];
            ll y = v[j][1];
            if(x > i-1) continue;
            if(y <= i-1) {
                dp[i] = (dp[i] + (cdp[i-x]-cdp[i-y-1]+mod))%mod;
            }
            else {
                ll newx = x;
                ll newy = i-1;
                dp[i] = (dp[i] + ((cdp[i-newx]-cdp[i-newy-1]+mod)%mod))%mod;
            }
        }

        cdp[i] = (cdp[i-1] + dp[i])%mod;
    }
    // for(ll i = 0; i <= n; i++) cout << dp[i] << " ";
    // cout << endl;
    // for(ll i = 0; i <= n; i++) cout << cdp[i] << " ";
    // cout << endl;
    cout << dp[n] << endl;
}

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

    ll T = 1;

    while(T--) {
        solve();
    }
    return 0;
}

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

int main(void) {
    double a, b, c, d, e, f;
    double x, y;
    
    while(cin >> a >> b >> c >> d >> e >> f) {
        y = (c*d - a*f) / (b*d - a*e);
        x = (c - b * y) / a;
        
        printf("%.3lf %.3lf", x, y);
        cout << endl;
    }
}


Measured memory_bytes: 3172
n = int(input())
MOD = 10**9+7
a = list(map(int,input().split()))
if n == 1 and a[0] == 0:
    print(1)
    exit()
elif n == 1:
    print(0)
    exit()
if n == 2 and a[0] == 1 and a[1] == 1:
    print(1)
    exit()
elif n == 2:
    print(0)
    exit()
a.sort()
if n % 2 == 0:
    if a[0] != 1 or a[1] != 1 or a[2] == 1:
        print(0)
        exit()
    j = 3
    for i in range(2,n,2):
        if a[i] != j:
            print(0)
            exit()
        j += 2
    j = 3
    for i in range(3,n,2):
        if a[i] != j:
            print(0)
            exit()
        j+=2
if n % 2 != 0:
    if a[0] != 0 or a[1] == 0:
        print(0)
        exit()
    j = 2
    for i in range(1,n,2):
        if a[i] != j:
            print(0)
            exit()
        j += 2
    j = 2
    for i in range(2,n,2):
        if a[i] != j:
            print(0)
            exit()
        j+=2
print(pow(2,(n//2),MOD))

Measured memory_bytes: 14008
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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


int main() {
	
	ll n;
	cin >> n;
	vector<ll> a(n);

	rep(i, n) cin >> a[i];
	map<ll, ll> mp;
	bool is_exist = true;
	rep(i, n) {
		//if (n % 2 == 0 && a[i] % 2 == 0) is_exist = false;
		//if (n % 2 == 1 && a[i] % 2 == 1) is_exist = false;
		mp[a[i]]++;
	}
	for (auto x : mp) {
		ll fir = x.first, sec = x.second;
		if (n % 2 == 1) {
			if (fir == 0 && sec != 1) is_exist = false;
			else if(fir%2 != 0 && sec != 2) is_exist = false;
		}
		else {
			if (fir % 2 != 1 && sec != 2) is_exist = false;
		}
	}
	int ans = 1;
	rep(i, n/2) {
		ans *= 2;
		ans %= MOD;
	}
	if (!is_exist) cout << 0 << endl;
	else cout << ans << endl;
	return 0;
}


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

using namespace std;

const int N=200005;

int a[N],b[N];
int n;
long long btree[4*N];

void update(int node,int l,int r,int ind,long long val)
{
	if(ind<l||ind>r) return;
	if(l==r)
	{
		btree[node]=val;
		return;
	}
	int mid=(l+r)/2;
	update(node*2,l,mid,ind,val);
	update(node*2+1,mid+1,r,ind,val);
	btree[node]=max(btree[node*2],btree[node*2+1]);
}

long long query(int node,int l,int r,int ql,int qr)
{
	if(r<ql||qr<l) return 0;
	if(ql<=l&&r<=qr) return btree[node];
	int mid=(l+r)/2;
	return max(query(node*2,l,mid,ql,qr),query(node*2+1,mid+1,r,ql,qr));
}

int main()
{
	cin >> n;
	for(int i=0;i<n;i++) cin >> a[i];
	for(int i=0;i<n;i++) cin >> b[i];
	long long ans=0;
	for(int i=0;i<n;i++)
	{
		long long cur=b[i]+query(1,1,n,1,a[i]);
		update(1,1,n,a[i],cur);
		ans=max(ans,cur);
	}
	cout << ans << endl;
}

Measured memory_bytes: 7936
n = int(input())
l = list(map(int, input().split()))

lst = [0]*(2*10**5)
set = 0

for i in l:
    lst[i-1] += 1
for i in lst:
    if i>=2:
        set += i*(i-1)/2

for i in l:
    print(int(set - (lst[i-1]-1)))


Measured memory_bytes: 24748